#include <HappyConnOpener.h>

Inheritance diagram for HappyConnOpener:
Collaboration diagram for HappyConnOpener:

Classes

class  Attempt
 a connection opening attempt in progress (or falsy) More...
 
class  CbDialer
 AsyncCall dialer for our callback. Gives us access to callback Answer. More...
 

Public Types

typedef HappyConnOpenerAnswer Answer
 
typedef CbcPointer< AsyncJobPointer
 

Public Member Functions

 HappyConnOpener (const ResolvedPeersPointer &, const AsyncCall::Pointer &, HttpRequestPointer &, const time_t aFwdStart, int tries, const AccessLogEntryPointer &al)
 
virtual ~HappyConnOpener () override
 
void allowPersistent (bool permitted)
 configures reuse of old connections More...
 
void setRetriable (bool retriable)
 configures whether the request may be retried later if things go wrong More...
 
void setHost (const char *)
 configures the origin server domain name More...
 
void noteCandidatesChange ()
 reacts to changes in the destinations list More...
 
void noteGavePrimeItsChance ()
 reacts to expired happy_eyeballs_connect_timeout More...
 
void noteSpareAllowance ()
 reacts to satisfying happy_eyeballs_connect_gap and happy_eyeballs_connect_limit More...
 
bool canBeCalled (AsyncCall &call) const
 whether we can be called More...
 
void callStart (AsyncCall &call)
 
virtual void callEnd ()
 called right after the called job method More...
 
virtual void callException (const std::exception &e)
 called when the job throws during an async call More...
 
virtual void * toCbdata ()=0
 

Static Public Member Functions

static Pointer Start (AsyncJob *job)
 starts a freshly created job (i.e., makes the job asynchronous) More...
 

Public Attributes

HappyAbsoluteTime primeStart = 0
 the start of the first connection attempt for the currentPeer More...
 

Protected Member Functions

void deleteThis (const char *aReason)
 
void mustStop (const char *aReason)
 
bool done () const
 the job is destroyed in callEnd() when done() More...
 

Protected Attributes

const char * stopReason
 reason for forcing done() to be true More...
 
const char * typeName
 kid (leaf) class name, for debugging More...
 
AsyncCall::Pointer inCall
 the asynchronous call being handled, if any More...
 
const InstanceId< AsyncJobid
 job identifier More...
 

Private Member Functions

 CBDATA_CHILD (HappyConnOpener)
 
virtual void start () override
 called by AsyncStart; do not call directly More...
 
virtual bool doneAll () const override
 whether positive goal has been reached More...
 
virtual void swanSong () override
 
virtual const char * status () const override
 internal cleanup; do not call directly More...
 
void maybeOpenAnotherPrimeConnection ()
 starts a prime connection attempt if possible or does nothing otherwise More...
 
void maybeGivePrimeItsChance ()
 
void stopGivingPrimeItsChance ()
 called when the prime attempt has used up its chance for a solo victory More...
 
void stopWaitingForSpareAllowance ()
 called when the spare attempt should no longer obey spare connection limits More...
 
void maybeOpenSpareConnection ()
 if possible, starts a spare connection attempt More...
 
void startConnecting (Attempt &, Comm::ConnectionPointer &)
 starts opening (or reusing) a connection to the given destination More...
 
void openFreshConnection (Attempt &, Comm::ConnectionPointer &)
 
bool reuseOldConnection (const Comm::ConnectionPointer &)
 
void connectDone (const CommConnectCbParams &)
 
void checkForNewConnection ()
 
void updateSpareWaitAfterPrimeFailure ()
 reacts to a prime attempt failure More...
 
void cancelSpareWait (const char *reason)
 stops waiting for the right conditions to open a spare connection More...
 
bool ranOutOfTimeOrAttempts () const
 Check for maximum connection tries and forwarding time restrictions. More...
 
ErrorStatemakeError (const err_type type) const
 
AnswerfutureAnswer (const Comm::ConnectionPointer &)
 
void sendSuccess (const Comm::ConnectionPointer &conn, bool reused, const char *connKind)
 send a successful result to the initiator (if it still needs an answer) More...
 
void sendFailure ()
 inform the initiator about our failure to connect (if needed) More...
 

Private Attributes

const time_t fwdStart
 requestor start time More...
 
AsyncCall::Pointer callback_
 handler to be called on connection completion. More...
 
ResolvedPeersPointer destinations
 Candidate paths. Shared with the initiator. May not be finalized yet. More...
 
Attempt prime
 current connection opening attempt on the prime track (if any) More...
 
Attempt spare
 current connection opening attempt on the spare track (if any) More...
 
Comm::ConnectionPointer currentPeer
 
HappySpareWait spareWaiting
 preconditions for an attempt to open a spare connection More...
 
AccessLogEntryPointer ale
 transaction details More...
 
ErrorStatelastError = nullptr
 last problem details (or nil) More...
 
Comm::ConnectionPointer lastFailedConnection
 nil if none has failed More...
 
bool ignoreSpareRestrictions = false
 whether spare connection attempts disregard happy_eyeballs_* settings More...
 
bool gotSpareAllowance = false
 whether we have received a permission to open a spare while spares are limited More...
 
bool allowPconn_ = true
 whether persistent connections are allowed More...
 
bool retriable_ = true
 whether we are opening connections for a request that may be resent More...
 
const char * host_ = nullptr
 origin server domain name (or equivalent) More...
 
HttpRequestPointer cause
 the request that needs a to-server connection More...
 
int n_tries
 number of connection opening attempts, including those in the requestor More...
 
const char * ranOutOfTimeOrAttemptsEarlier_ = nullptr
 Reason to ran out of time or attempts. More...
 

Friends

class HappyOrderEnforcer
 

Detailed Description

A TCP connection opening algorithm based on Happy Eyeballs (RFC 8305). Maintains two concurrent connection opening tracks: prime and spare. Shares ResolvedPeers list with the job initiator.

Definition at line 100 of file HappyConnOpener.h.

Member Typedef Documentation

◆ Answer

◆ Pointer

Definition at line 34 of file AsyncJob.h.

Constructor & Destructor Documentation

◆ HappyConnOpener()

HappyConnOpener::HappyConnOpener ( const ResolvedPeersPointer dests,
const AsyncCall::Pointer aCall,
HttpRequestPointer request,
const time_t  aFwdStart,
int  tries,
const AccessLogEntryPointer al 
)

Definition at line 326 of file HappyConnOpener.cc.

References assert, callback_, destinations, and AsyncCall::getDialer().

◆ ~HappyConnOpener()

HappyConnOpener::~HappyConnOpener ( )
overridevirtual

Definition at line 339 of file HappyConnOpener.cc.

References host_, lastError, and safe_free.

Member Function Documentation

◆ allowPersistent()

void HappyConnOpener::allowPersistent ( bool  permitted)
inline

Definition at line 133 of file HappyConnOpener.h.

◆ callEnd()

void AsyncJob::callEnd ( )
virtualinherited

◆ callException()

◆ callStart()

void AsyncJob::callStart ( AsyncCall call)
inherited

◆ canBeCalled()

bool AsyncJob::canBeCalled ( AsyncCall call) const
inherited

Definition at line 101 of file AsyncJob.cc.

References AsyncCall::cancel(), debugs, HERE(), AsyncJob::inCall, and NULL.

Referenced by AsyncJob::swanSong().

◆ cancelSpareWait()

◆ CBDATA_CHILD()

HappyConnOpener::CBDATA_CHILD ( HappyConnOpener  )
private

◆ checkForNewConnection()

void HappyConnOpener::checkForNewConnection ( )
private

Called when an external event changes initiator interest, destinations, prime, spare, or spareWaiting. Leaves HappyConnOpener in one of these (mutually exclusive beyond the exceptional state #0) "stable" states:

0. Exceptional termination: done()

  1. Processing a single peer: currentPeer 1.1. Connecting: prime || spare 1.2. Waiting for spare gap and/or paths: !prime && !spare
  2. Waiting for a new peer: destinations->empty() && !destinations->destinationsFinalized && !currentPeer
  3. Finished: destinations->empty() && destinations->destinationsFinalized && !currentPeer

Definition at line 678 of file HappyConnOpener.cc.

References cancelSpareWait(), current_dtime, currentPeer, debugs, destinations, ResolvedPeers::destinationsFinalized, AsyncJob::done(), doneAll(), ResolvedPeers::doneWithPeer(), ResolvedPeers::doneWithSpares(), ResolvedPeers::empty(), ResolvedPeers::extractFront(), HappySpareWait::forNewPeer, gotSpareAllowance, ignoreSpareRestrictions, maybeGivePrimeItsChance(), maybeOpenAnotherPrimeConnection(), maybeOpenSpareConnection(), Must, prime, primeStart, ranOutOfTimeOrAttempts(), spare, spareWaiting, and startConnecting().

Referenced by connectDone(), noteCandidatesChange(), noteGavePrimeItsChance(), and start().

◆ connectDone()

◆ deleteThis()

void AsyncJob::deleteThis ( const char *  aReason)
protectedinherited

◆ done()

◆ doneAll()

bool HappyConnOpener::doneAll ( ) const
overrideprivatevirtual

◆ futureAnswer()

HappyConnOpener::Answer * HappyConnOpener::futureAnswer ( const Comm::ConnectionPointer conn)
private
Returns
pre-filled Answer if the initiator needs an answer (or nil)

Definition at line 459 of file HappyConnOpener.cc.

References assert, callback_, AsyncCall::canceled(), conn, AsyncCall::getDialer(), and n_tries.

Referenced by sendFailure(), and sendSuccess().

◆ makeError()

ErrorState * HappyConnOpener::makeError ( const err_type  type) const
private

Create "503 Service Unavailable" or "504 Gateway Timeout" error depending on whether this is a validation request. RFC 7234 section 5.2.2 says that we MUST reply with "504 Gateway Timeout" if validation fails and cached reply has proxy-revalidate, must-revalidate or s-maxage Cache-Control directive.

Definition at line 450 of file HappyConnOpener.cc.

References ale, cause, HttpRequest::flags, RefCount< C >::getRaw(), RequestFlags::needValidation, Http::scGatewayTimeout, and Http::scServiceUnavailable.

Referenced by connectDone(), and sendFailure().

◆ maybeGivePrimeItsChance()

void HappyConnOpener::maybeGivePrimeItsChance ( )
private

◆ maybeOpenAnotherPrimeConnection()

void HappyConnOpener::maybeOpenAnotherPrimeConnection ( )
private

◆ maybeOpenSpareConnection()

◆ mustStop()

void AsyncJob::mustStop ( const char *  aReason)
protectedinherited

Definition at line 69 of file AsyncJob.cc.

References debugs, AsyncJob::inCall, Must, NULL, AsyncJob::stopReason, and AsyncJob::typeName.

Referenced by HttpStateData::abortAll(), Ftp::Client::abortAll(), Comm::TcpAcceptor::acceptOne(), Adaptation::Ecap::XactionRep::adaptationAborted(), Adaptation::AccessCheck::callBack(), AsyncJob::callException(), Security::PeerConnector::connectionClosed(), HttpStateData::continueAfterParsingHeader(), Ftp::Client::ctrlClosed(), Adaptation::Iterator::handleAdaptationBlock(), Adaptation::Iterator::handleAdaptationError(), Log::TcpLogger::handleClosure(), Adaptation::Icap::Xaction::handleCommClosed(), Http::Tunneler::handleConnectionClosure(), Mgr::Forwarder::handleError(), Ipc::Forwarder::handleError(), Ipc::Forwarder::handleException(), Ipc::Inquirer::handleException(), HttpStateData::handleMoreRequestBodyAvailable(), Ipc::Inquirer::handleRemoteAck(), Ipc::Forwarder::handleTimeout(), HttpStateData::httpStateConnClosed(), HttpStateData::httpTimeout(), Comm::ConnOpener::noteAbort(), Adaptation::Icap::ModXact::noteBodyConsumerAborted(), Snmp::Forwarder::noteCommClosed(), Snmp::Inquirer::noteCommClosed(), Mgr::Inquirer::noteCommClosed(), Mgr::Forwarder::noteCommClosed(), Mgr::StoreToCommWriter::noteCommClosed(), Adaptation::Icap::Xaction::noteCommRead(), Rock::HeaderUpdater::noteDoneReading(), Adaptation::Iterator::noteInitiatorAborted(), Adaptation::Icap::Xaction::noteInitiatorAborted(), Adaptation::Ecap::XactionRep::noteInitiatorAborted(), HttpStateData::readReply(), Comm::ConnOpener::sendAnswer(), Rock::Rebuild::start(), Security::PeerConnector::start(), HttpStateData::start(), Ipc::UdsSender::timedout(), and HttpStateData::wroteLast().

◆ noteCandidatesChange()

void HappyConnOpener::noteCandidatesChange ( )

◆ noteGavePrimeItsChance()

void HappyConnOpener::noteGavePrimeItsChance ( )

◆ noteSpareAllowance()

◆ openFreshConnection()

◆ ranOutOfTimeOrAttempts()

bool HappyConnOpener::ranOutOfTimeOrAttempts ( ) const
private

◆ reuseOldConnection()

bool HappyConnOpener::reuseOldConnection ( const Comm::ConnectionPointer dest)
private

reuses a persistent connection to the given destination (if possible)

Returns
true if and only if reuse was possible must be called via startConnecting()

Definition at line 525 of file HappyConnOpener.cc.

References allowPconn_, assert, fwdPconnPool, host_, n_tries, PconnPool::pop(), retriable_, and sendSuccess().

Referenced by startConnecting().

◆ sendFailure()

void HappyConnOpener::sendFailure ( )
private

◆ sendSuccess()

void HappyConnOpener::sendSuccess ( const Comm::ConnectionPointer conn,
bool  reused,
const char *  connKind 
)
private

Definition at line 473 of file HappyConnOpener.cc.

References assert, callback_, debugs, futureAnswer(), and ScheduleCallHere.

Referenced by connectDone(), and reuseOldConnection().

◆ setHost()

void HappyConnOpener::setHost ( const char *  h)

Definition at line 346 of file HappyConnOpener.cc.

References host_, safe_free, and xstrdup.

◆ setRetriable()

void HappyConnOpener::setRetriable ( bool  retriable)
inline

Definition at line 136 of file HappyConnOpener.h.

◆ Start()

◆ start()

void HappyConnOpener::start ( )
overrideprivatevirtual

Reimplemented from AsyncJob.

Definition at line 354 of file HappyConnOpener.cc.

References checkForNewConnection(), destinations, and ResolvedPeers::notificationPending.

◆ startConnecting()

◆ status()

◆ stopGivingPrimeItsChance()

void HappyConnOpener::stopGivingPrimeItsChance ( )
private

◆ stopWaitingForSpareAllowance()

void HappyConnOpener::stopWaitingForSpareAllowance ( )
private

◆ swanSong()

◆ toCbdata()

virtual void* CbdataParent::toCbdata ( )
pure virtualinherited

◆ updateSpareWaitAfterPrimeFailure()

void HappyConnOpener::updateSpareWaitAfterPrimeFailure ( )
private

Friends And Related Function Documentation

◆ HappyOrderEnforcer

friend class HappyOrderEnforcer
friend

Definition at line 215 of file HappyConnOpener.h.

Member Data Documentation

◆ ale

AccessLogEntryPointer HappyConnOpener::ale
private

Definition at line 217 of file HappyConnOpener.h.

Referenced by makeError().

◆ allowPconn_

bool HappyConnOpener::allowPconn_ = true
private

Definition at line 229 of file HappyConnOpener.h.

Referenced by reuseOldConnection(), and startConnecting().

◆ callback_

AsyncCall::Pointer HappyConnOpener::callback_
private

◆ cause

HttpRequestPointer HappyConnOpener::cause
private

Definition at line 238 of file HappyConnOpener.h.

Referenced by makeError(), openFreshConnection(), and startConnecting().

◆ currentPeer

Comm::ConnectionPointer HappyConnOpener::currentPeer
private

CachePeer and IP address family of the peer we are trying to connect to now (or, if we are just waiting for paths to a new peer, nil)

Definition at line 211 of file HappyConnOpener.h.

Referenced by checkForNewConnection(), maybeGivePrimeItsChance(), maybeOpenAnotherPrimeConnection(), maybeOpenSpareConnection(), noteSpareAllowance(), and updateSpareWaitAfterPrimeFailure().

◆ destinations

◆ fwdStart

const time_t HappyConnOpener::fwdStart
private

Definition at line 196 of file HappyConnOpener.h.

Referenced by openFreshConnection(), and ranOutOfTimeOrAttempts().

◆ gotSpareAllowance

bool HappyConnOpener::gotSpareAllowance = false
private

◆ host_

const char* HappyConnOpener::host_ = nullptr
private

◆ id

const InstanceId<AsyncJob> AsyncJob::id
protectedinherited

Definition at line 72 of file AsyncJob.h.

◆ ignoreSpareRestrictions

bool HappyConnOpener::ignoreSpareRestrictions = false
private

◆ inCall

◆ lastError

ErrorState* HappyConnOpener::lastError = nullptr
private

Definition at line 219 of file HappyConnOpener.h.

Referenced by connectDone(), sendFailure(), and ~HappyConnOpener().

◆ lastFailedConnection

Comm::ConnectionPointer HappyConnOpener::lastFailedConnection
private

Definition at line 220 of file HappyConnOpener.h.

Referenced by connectDone(), and sendFailure().

◆ n_tries

int HappyConnOpener::n_tries
private

◆ prime

◆ primeStart

HappyAbsoluteTime HappyConnOpener::primeStart = 0

Definition at line 151 of file HappyConnOpener.h.

Referenced by checkForNewConnection(), and PrimeChanceGiver::readyNow().

◆ ranOutOfTimeOrAttemptsEarlier_

const char* HappyConnOpener::ranOutOfTimeOrAttemptsEarlier_ = nullptr
mutableprivate

Definition at line 244 of file HappyConnOpener.h.

Referenced by ranOutOfTimeOrAttempts().

◆ retriable_

bool HappyConnOpener::retriable_ = true
private

Definition at line 232 of file HappyConnOpener.h.

Referenced by reuseOldConnection().

◆ spare

◆ spareWaiting

◆ stopReason

const char* AsyncJob::stopReason
protectedinherited

◆ typeName


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors