#include <FwdState.h>

Inheritance diagram for FwdState:
Collaboration diagram for FwdState:

Public Types

typedef RefCount< FwdStatePointer
 

Public Member Functions

 ~FwdState () override
 
void useDestinations ()
 
void fail (ErrorState *err)
 
void unregister (Comm::ConnectionPointer &conn)
 
void unregister (int fd)
 
void complete ()
 
void markStoredReplyAsWhole (const char *whyWeAreSure)
 
void handleUnregisteredServerEnd ()
 
int reforward ()
 
void serverClosed ()
 
void connectStart ()
 
void connectDone (const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno)
 
bool checkRetry ()
 
bool checkRetriable ()
 Whether we may try sending this request again after a failure. More...
 
void dispatch ()
 
void pconnPush (Comm::ConnectionPointer &conn, const char *domain)
 
bool dontRetry ()
 
void dontRetry (bool val)
 
void closePendingConnection (const Comm::ConnectionPointer &conn, const char *reason)
 get rid of a to-server connection that failed to become serverConn More...
 
Comm::ConnectionPointer const & serverConnection () const
 
void startSelectingDestinations (HttpRequest *request, const AccessLogEntry::Pointer &ale, StoreEntry *entry)
 
virtual void * toCbdata ()=0
 

Static Public Member Functions

static void initModule ()
 
static void Start (const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
 Initiates request forwarding to a peer or origin server. More...
 
static void fwdStart (const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
 Same as Start() but no master xaction info (AccessLogEntry) available. More...
 
static time_t ForwardTimeout (const time_t fwdStart)
 time left to finish the whole forwarding process (which started at fwdStart) More...
 
static bool EnoughTimeToReForward (const time_t fwdStart)
 
static void HandleStoreAbort (FwdState *)
 called by Store if the entry is no longer usable More...
 

Public Attributes

StoreEntryentry
 
HttpRequestrequest
 
AccessLogEntryPointer al
 info for the future access.log entry More...
 
bool subscribed = false
 whether noteDestination() and noteDestinationsEnd() calls are allowed More...
 
bool connected_okay
 TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc. More...
 
bool dont_retry
 
bool forward_completed
 
bool destinationsFound
 at least one candidate path found More...
 

Private Types

enum  PconnRace {
  raceImpossible ,
  racePossible ,
  raceHappened
}
 possible pconn race states More...
 

Private Member Functions

 CBDATA_CHILD (FwdState)
 
 FwdState (const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
 
void start (Pointer aSelf)
 
void stopAndDestroy (const char *reason)
 ends forwarding; relies on refcounting so the effect may not be immediate More...
 
void noteDestination (Comm::ConnectionPointer conn) override
 called when a new unique destination has been found More...
 
void noteDestinationsEnd (ErrorState *selectionError) override
 
bool transporting () const
 
void noteConnection (HappyConnOpenerAnswer &)
 
void doneWithRetries ()
 
void completed ()
 
void retryOrBail ()
 
void usePinned ()
 send request on an existing connection dedicated to the requesting client More...
 
bool pinnedCanRetry () const
 
template<typename StepStart >
void advanceDestination (const char *stepDescription, const Comm::ConnectionPointer &conn, const StepStart &startStep)
 starts a preparation step for an established connection; retries on failures More...
 
ErrorStatemakeConnectingError (const err_type type) const
 
void connectedToPeer (Security::EncryptorAnswer &answer)
 called when all negotiations with the TLS-speaking peer have been completed More...
 
void establishTunnelThruProxy (const Comm::ConnectionPointer &)
 
void tunnelEstablishmentDone (Http::TunnelerAnswer &answer)
 resumes operations after the (possibly failed) HTTP CONNECT exchange More...
 
void secureConnectionToPeerIfNeeded (const Comm::ConnectionPointer &)
 handles an established TCP connection to peer (including origin servers) More...
 
void secureConnectionToPeer (const Comm::ConnectionPointer &)
 encrypts an established TCP connection to peer (including origin servers) More...
 
void successfullyConnectedToPeer (const Comm::ConnectionPointer &)
 called when all negotiations with the peer have been completed More...
 
void closeServerConnection (const char *reason)
 stops monitoring server connection for closure and updates pconn stats More...
 
void syncWithServerConn (const Comm::ConnectionPointer &server, const char *host, const bool reused)
 commits to using the given open to-peer connection More...
 
void syncHierNote (const Comm::ConnectionPointer &server, const char *host)
 
bool exhaustedTries () const
 whether we have used up all permitted forwarding attempts More...
 
void updateAttempts (int)
 sets n_tries to the given value (while keeping ALE, if any, in sync) More...
 
time_t connectingTimeout (const Comm::ConnectionPointer &conn) const
 
void cancelStep (const char *reason)
 
void notifyConnOpener ()
 makes sure connection opener knows that the destinations have changed More...
 
void reactToZeroSizeObject ()
 ERR_ZERO_SIZE_OBJECT requires special adjustments. More...
 
void updateAleWithFinalError ()
 updates ALE when we finalize the transaction error (if any) More...
 
virtual void finalizedInCbdataChild ()=0
 hack: ensure CBDATA_CHILD() after a toCbdata()-defining CBDATA_INTERMEDIATE() More...
 

Static Private Member Functions

static void logReplyStatus (int tries, const Http::StatusCode status)
 
static void RegisterWithCacheManager (void)
 

Private Attributes

Pointer self
 
ErrorStateerr
 
Comm::ConnectionPointer clientConn
 a possibly open connection to the client. More...
 
time_t start_t
 
int n_tries
 the number of forwarding attempts so far More...
 
struct {
   bool   connected_okay
 TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc. More...
 
   bool   dont_retry
 
   bool   forward_completed
 
   bool   destinationsFound
 at least one candidate path found More...
 
flags
 
JobWait< HappyConnOpenertransportWait
 waits for a transport connection to the peer to be established/opened More...
 
JobWait< Security::PeerConnectorencryptionWait
 waits for the established transport connection to be secured/encrypted More...
 
JobWait< Http::TunnelerpeerWait
 
bool waitingForDispatched
 whether we are waiting for the last dispatch()ed activity to end More...
 
ResolvedPeersPointer destinations
 paths for forwarding the request More...
 
Comm::ConnectionPointer serverConn
 a successfully opened connection to a server. More...
 
PeerConnectionPointer destinationReceipt
 peer selection result (or nil) More...
 
AsyncCall::Pointer closeHandler
 The serverConn close handler. More...
 
PconnRace pconnRace
 current pconn race state More...
 
const char * storedWholeReply_
 

Detailed Description

Definition at line 52 of file FwdState.h.

Member Typedef Documentation

◆ Pointer

Definition at line 57 of file FwdState.h.

Member Enumeration Documentation

◆ PconnRace

enum FwdState::PconnRace
private
Enumerator
raceImpossible 
racePossible 
raceHappened 

Definition at line 209 of file FwdState.h.

Constructor & Destructor Documentation

◆ ~FwdState()

◆ FwdState()

FwdState::FwdState ( const Comm::ConnectionPointer client,
StoreEntry e,
HttpRequest r,
const AccessLogEntryPointer alp 
)
private

Definition at line 120 of file FwdState.cc.

References debugs, flags, HTTPMSGLOCK(), StoreEntry::lock(), request, and StoreEntry::url().

Referenced by Start().

Member Function Documentation

◆ advanceDestination()

template<typename StepStart >
void FwdState::advanceDestination ( const char *  stepDescription,
const Comm::ConnectionPointer conn,
const StepStart &  startStep 
)
private

◆ cancelStep()

void FwdState::cancelStep ( const char *  reason)
private

Notify a pending subtask, if any, that we no longer need its help. We do not have to do this – the subtask job will eventually end – but ending it earlier reduces waste and may reduce DoS attack surface.

Definition at line 198 of file FwdState.cc.

References JobWaitBase::cancel(), encryptionWait, peerWait, and transportWait.

Referenced by ~FwdState(), and stopAndDestroy().

◆ CBDATA_CHILD()

FwdState::CBDATA_CHILD ( FwdState  )
private

◆ checkRetriable()

bool FwdState::checkRetriable ( )

◆ checkRetry()

◆ closePendingConnection()

void FwdState::closePendingConnection ( const Comm::ConnectionPointer conn,
const char *  reason 
)

◆ closeServerConnection()

void FwdState::closeServerConnection ( const char *  reason)
private

◆ complete()

void FwdState::complete ( )

FooClient modules call fwdComplete() when they are done downloading an object. Then, we either 1) re-forward the request somewhere else if needed, or 2) call storeComplete() to finish it off

Definition at line 531 of file FwdState.cc.

References MemObject::baseReply(), completed(), debugs, destinationReceipt, entry, Comm::IsConnOpen(), logReplyStatus(), StoreEntry::mem(), StoreEntry::mem_obj, n_tries, reforward(), StoreEntry::reset(), serverConn, serverConnection(), HttpReply::sline, Http::StatusLine::status(), stopAndDestroy(), storedWholeReply_, unregister(), StoreEntry::url(), useDestinations(), and waitingForDispatched.

Referenced by Client::completeForwarding(), connectedToPeer(), dispatch(), and WhoisState::readReply().

◆ completed()

◆ connectDone()

void FwdState::connectDone ( const Comm::ConnectionPointer conn,
Comm::Flag  status,
int  xerrno 
)

◆ connectedToPeer()

◆ connectingTimeout()

time_t FwdState::connectingTimeout ( const Comm::ConnectionPointer conn) const
private
Returns
the time left for this connection to become connected or 1 second if it is less than one second left

Definition at line 1439 of file FwdState.cc.

References conn, positiveTimeout(), and start_t.

Referenced by establishTunnelThruProxy(), and secureConnectionToPeer().

◆ connectStart()

void FwdState::connectStart ( )

◆ dispatch()

◆ doneWithRetries()

void FwdState::doneWithRetries ( )
private

Definition at line 797 of file FwdState.cc.

References Http::Message::body_pipe, BodyPipe::expectNoConsumption(), and request.

Referenced by ~FwdState(), and retryOrBail().

◆ dontRetry() [1/2]

◆ dontRetry() [2/2]

void FwdState::dontRetry ( bool  val)
inline

Definition at line 98 of file FwdState.h.

References flags.

◆ EnoughTimeToReForward()

bool FwdState::EnoughTimeToReForward ( const time_t  fwdStart)
static

Whether there is still time to re-try after a previous connection failure.

Parameters
fwdStartThe start time of the peer selection/connection process.

Definition at line 436 of file FwdState.cc.

References ForwardTimeout(), and fwdStart().

Referenced by checkRetry(), and TunnelStateData::checkRetry().

◆ establishTunnelThruProxy()

void FwdState::establishTunnelThruProxy ( const Comm::ConnectionPointer conn)
private

◆ exhaustedTries()

bool FwdState::exhaustedTries ( ) const
private

Definition at line 1411 of file FwdState.cc.

References Config, SquidConfig::forward_max_tries, and n_tries.

Referenced by checkRetry(), and reforward().

◆ fail()

◆ finalizedInCbdataChild()

virtual void CbdataParent::finalizedInCbdataChild ( )
privatepure virtualinherited

◆ ForwardTimeout()

time_t FwdState::ForwardTimeout ( const time_t  fwdStart)
static

◆ fwdStart()

void FwdState::fwdStart ( const Comm::ConnectionPointer client,
StoreEntry entry,
HttpRequest request 
)
static

◆ HandleStoreAbort()

void FwdState::HandleStoreAbort ( FwdState fwd)
static

Definition at line 83 of file FwdState.cc.

References closeServerConnection(), debugs, Comm::IsConnOpen(), serverConnection(), and stopAndDestroy().

Referenced by start().

◆ handleUnregisteredServerEnd()

void FwdState::handleUnregisteredServerEnd ( )

◆ initModule()

void FwdState::initModule ( )
static

Definition at line 1385 of file FwdState.cc.

References RegisterWithCacheManager().

Referenced by mainInitialize().

◆ logReplyStatus()

void FwdState::logReplyStatus ( int  tries,
const Http::StatusCode  status 
)
staticprivate

Definition at line 1397 of file FwdState.cc.

References assert, FwdReplyCodes, MAX_FWD_STATS_IDX, and Http::scInvalidHeader.

Referenced by complete().

◆ makeConnectingError()

ErrorState * FwdState::makeConnectingError ( const err_type  type) const
private

◆ markStoredReplyAsWhole()

void FwdState::markStoredReplyAsWhole ( const char *  whyWeAreSure)

Mark reply as written to Store in its entirety, including the header and any body. If the reply has a body, the entire body has to be stored.

Definition at line 580 of file FwdState.cc.

References debugs, EBIT_TEST, entry, ENTRY_ABORTED, StoreEntry::flags, and storedWholeReply_.

Referenced by Client::endAdaptedBodyConsumption(), Client::handleAdaptedHeader(), Client::markParsedVirginReplyAsWhole(), and WhoisState::readReply().

◆ noteConnection()

◆ noteDestination()

void FwdState::noteDestination ( Comm::ConnectionPointer  path)
overrideprivatevirtual

◆ noteDestinationsEnd()

void FwdState::noteDestinationsEnd ( ErrorState error)
overrideprivatevirtual

called when there will be no more noteDestination() calls

Parameters
erroris a possible reason why no destinations were found; it is guaranteed to be nil if there was at least one noteDestination() call

Implements PeerSelectionInitiator.

Definition at line 621 of file FwdState.cc.

References assert, debugs, destinations, ResolvedPeers::destinationsFinalized, err, fail(), flags, Must, notifyConnOpener(), stopAndDestroy(), PeerSelectionInitiator::subscribed, transporting(), and transportWait.

◆ notifyConnOpener()

void FwdState::notifyConnOpener ( )
private

◆ pconnPush()

void FwdState::pconnPush ( Comm::ConnectionPointer conn,
const char *  domain 
)

◆ pinnedCanRetry()

bool FwdState::pinnedCanRetry ( ) const
private

whether a pinned to-peer connection can be replaced with another one (in order to retry or reforward a failed request)

Definition at line 1417 of file FwdState.cc.

References assert, HttpRequest::flags, pconnRace, RequestFlags::pinned, raceHappened, request, and RequestFlags::sslBumped.

Referenced by checkRetry(), and reforward().

◆ reactToZeroSizeObject()

void FwdState::reactToZeroSizeObject ( )
private

◆ reforward()

◆ RegisterWithCacheManager()

void FwdState::RegisterWithCacheManager ( void  )
staticprivate

Definition at line 1391 of file FwdState.cc.

References fwdStats, and Mgr::RegisterAction().

Referenced by initModule().

◆ retryOrBail()

◆ secureConnectionToPeer()

◆ secureConnectionToPeerIfNeeded()

◆ serverClosed()

◆ serverConnection()

Comm::ConnectionPointer const & FwdState::serverConnection ( ) const
inline

return a ConnectionPointer to the current server connection (may or may not be open)

Definition at line 104 of file FwdState.h.

References serverConn.

Referenced by Ftp::Client::Client(), HttpStateData::HttpStateData(), complete(), dispatch(), HandleStoreAbort(), successfullyConnectedToPeer(), unregister(), and whoisStart().

◆ Start()

void FwdState::Start ( const Comm::ConnectionPointer clientConn,
StoreEntry entry,
HttpRequest request,
const AccessLogEntryPointer al 
)
static

This is the entry point for client-side to start forwarding a transaction. It is a static method that may or may not allocate a FwdState.

Note
client_addr == no_addr indicates this is an "internal" request from peer_digest.c, asn.c, netdb.c, etc and should always be allowed. yuck, I know.

Check if this host is allowed to fetch MISSES from us (miss_access). Intentionally replace the src_addr automatically selected by the checklist code we do NOT want the indirect client address to be tested here.

Definition at line 341 of file FwdState.cc.

References FwdState(), SquidConfig::accessList, aclGetDenyInfoPage(), AclMatchedName, ACLFilledChecklist::al, al, HttpRequest::client_addr, clientConn, Config, debugs, Acl::Answer::denied(), SquidConfig::denyInfoList, entry, ERR_FORWARDING_DENIED, ERR_NONE, ERR_SHUTTING_DOWN, errorAppendEntry(), ACLChecklist::fastCheck(), HttpRequest::flags, AnyP::Uri::getScheme(), RequestFlags::internal, internalStart(), Ip::Address::isNoAddr(), StoreEntry::mem_obj, SquidConfig::miss, AnyP::PROTO_URN, request, MemObject::request, Http::scForbidden, Http::scServiceUnavailable, shutting_down, ACLFilledChecklist::src_addr, start(), ACLFilledChecklist::syncAle(), HttpRequest::url, StoreEntry::url(), and urnStart().

Referenced by fwdStart(), ConnStateData::parseTlsHandshake(), clientReplyContext::processExpired(), clientReplyContext::processMiss(), UrnState::start(), and ConnStateData::startPeekAndSplice().

◆ start()

◆ startSelectingDestinations()

void PeerSelectionInitiator::startSelectingDestinations ( HttpRequest request,
const AccessLogEntry::Pointer ale,
StoreEntry entry 
)
inherited

Initiates asynchronous peer selection that eventually results in zero or more noteDestination() calls and exactly one noteDestinationsEnd() call.

Definition at line 335 of file peer_select.cc.

References peerSelect(), and PeerSelectionInitiator::subscribed.

Referenced by start(), and tunnelStart().

◆ stopAndDestroy()

void FwdState::stopAndDestroy ( const char *  reason)
private

◆ successfullyConnectedToPeer()

◆ syncHierNote()

void FwdState::syncHierNote ( const Comm::ConnectionPointer server,
const char *  host 
)
private

◆ syncWithServerConn()

void FwdState::syncWithServerConn ( const Comm::ConnectionPointer server,
const char *  host,
const bool  reused 
)
private

◆ toCbdata()

virtual void * CbdataParent::toCbdata ( )
pure virtualinherited

◆ transporting()

bool FwdState::transporting ( ) const
private

Whether a forwarding attempt to some selected destination X is in progress (after successfully opening/reusing a transport connection to X). See also: transportWait

Definition at line 574 of file FwdState.cc.

References encryptionWait, peerWait, and waitingForDispatched.

Referenced by connectStart(), noteDestination(), and noteDestinationsEnd().

◆ tunnelEstablishmentDone()

◆ unregister() [1/2]

◆ unregister() [2/2]

void FwdState::unregister ( int  fd)

Definition at line 517 of file FwdState.cc.

References assert, debugs, entry, serverConn, serverConnection(), unregister(), and StoreEntry::url().

◆ updateAleWithFinalError()

◆ updateAttempts()

void FwdState::updateAttempts ( int  newValue)
private

Definition at line 1096 of file FwdState.cc.

References al, Assure, debugs, n_tries, and AccessLogEntry::requestAttempts.

Referenced by noteConnection(), and usePinned().

◆ useDestinations()

void FwdState::useDestinations ( )

This is the real beginning of server connection. Call it whenever the forwarding server destination has changed and a new one needs to be opened. Produces the cannot-forward error on fail if no better error exists.

Definition at line 442 of file FwdState.cc.

References al, connectStart(), debugs, destinations, ResolvedPeers::empty(), entry, err, ERR_CANNOT_FORWARD, fail(), request, Http::scInternalServerError, stopAndDestroy(), PeerSelectionInitiator::subscribed, and StoreEntry::url().

Referenced by complete(), noteDestination(), and retryOrBail().

◆ usePinned()

Member Data Documentation

◆ al

◆ clientConn

Comm::ConnectionPointer FwdState::clientConn
private

Definition at line 178 of file FwdState.h.

Referenced by dispatch(), fwdStart(), secureConnectionToPeer(), and Start().

◆ closeHandler

AsyncCall::Pointer FwdState::closeHandler
private

◆ connected_okay

bool FwdState::connected_okay

Definition at line 183 of file FwdState.h.

◆ destinationReceipt

PeerConnectionPointer FwdState::destinationReceipt
private

◆ destinations

◆ destinationsFound

bool FwdState::destinationsFound

Definition at line 186 of file FwdState.h.

◆ dont_retry

bool FwdState::dont_retry

Definition at line 184 of file FwdState.h.

◆ encryptionWait

JobWait<Security::PeerConnector> FwdState::encryptionWait
private

Definition at line 193 of file FwdState.h.

Referenced by cancelStep(), connectedToPeer(), secureConnectionToPeer(), and transporting().

◆ entry

◆ err

◆ 

◆ forward_completed

bool FwdState::forward_completed

Definition at line 185 of file FwdState.h.

◆ n_tries

int FwdState::n_tries
private

◆ pconnRace

PconnRace FwdState::pconnRace
private

◆ peerWait

JobWait<Http::Tunneler> FwdState::peerWait
private

waits for an HTTP CONNECT tunnel through a cache_peer to be negotiated over the (encrypted, if needed) transport connection to that cache_peer

Definition at line 197 of file FwdState.h.

Referenced by cancelStep(), establishTunnelThruProxy(), transporting(), and tunnelEstablishmentDone().

◆ request

◆ self

Pointer FwdState::self
private

◆ serverConn

◆ start_t

time_t FwdState::start_t
private

Definition at line 179 of file FwdState.h.

Referenced by checkRetry(), connectingTimeout(), connectStart(), and retryOrBail().

◆ storedWholeReply_

const char* FwdState::storedWholeReply_
private

Whether the entire reply (including any body) was written to Store. The string literal value is only used for debugging.

Definition at line 214 of file FwdState.h.

Referenced by complete(), completed(), and markStoredReplyAsWhole().

◆ subscribed

◆ transportWait

JobWait<HappyConnOpener> FwdState::transportWait
private

◆ waitingForDispatched

bool FwdState::waitingForDispatched
private

The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors