#include <HappyConnOpener.h>

Inheritance diagram for HappyConnOpener:
Collaboration diagram for HappyConnOpener:


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...
void handleStopRequest ()
 process external request to terminate now (i.e. during this async call) More...
virtual void * toCbdata ()=0

Static Public Member Functions

static void Start (const Pointer &job)

Public Attributes

HappyAbsoluteTime primeStart = 0
 the start of the first connection attempt for the currentPeer More...
const InstanceId< AsyncJobid
 job identifier 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...
bool started_ = false
 Start() has finished successfully. More...
bool swanSang_ = false
 swanSong() was called 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 maybeOpenPrimeConnection ()
 starts a prime connection attempt if possible or does nothing otherwise More...
void maybeOpenSpareConnection ()
 if possible, starts a spare connection attempt 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 startConnecting (Attempt &, PeerConnectionPointer &)
 starts opening (or reusing) a connection to the given destination More...
void openFreshConnection (Attempt &, PeerConnectionPointer &)
bool reuseOldConnection (PeerConnectionPointer &)
void notePrimeConnectDone (const CommConnectCbParams &)
 Comm::ConnOpener callback for the prime connection attempt. More...
void noteSpareConnectDone (const CommConnectCbParams &)
 Comm::ConnOpener callback for the spare connection attempt. More...
void handleConnOpenerAnswer (Attempt &, const CommConnectCbParams &, const char *connDescription)
 prime/spare-agnostic processing of a Comm::ConnOpener result More...
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 PeerConnectionPointer &)
void sendSuccess (const PeerConnectionPointer &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...
void cancelAttempt (Attempt &, const char *reason)
 cancels the in-progress attempt, making its path a future candidate 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...
PeerConnectionPointer 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
const char * ranOutOfTimeOrAttemptsEarlier_ = nullptr
 Reason to ran out of time or attempts. More...


class HappyOrderEnforcer
std::ostream & operator<< (std::ostream &, const Attempt &)
 HappyConnOpener::Attempt printer for debugging. More...

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 102 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 329 of file HappyConnOpener.cc.

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

◆ ~HappyConnOpener()

HappyConnOpener::~HappyConnOpener ( )

Definition at line 344 of file HappyConnOpener.cc.

References host_, lastError, and safe_free.

Member Function Documentation

◆ allowPersistent()

void HappyConnOpener::allowPersistent ( bool  permitted)

Definition at line 135 of file HappyConnOpener.h.

References allowPconn_.

◆ callEnd()

void AsyncJob::callEnd ( )

◆ callException()

◆ callStart()

void AsyncJob::callStart ( AsyncCall call)

◆ canBeCalled()

bool AsyncJob::canBeCalled ( AsyncCall call) const

Definition at line 102 of file AsyncJob.cc.

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

◆ cancelAttempt()

void HappyConnOpener::cancelAttempt ( Attempt attempt,
const char *  reason 

◆ cancelSpareWait()


HappyConnOpener::CBDATA_CHILD ( HappyConnOpener  )

◆ checkForNewConnection()

void HappyConnOpener::checkForNewConnection ( )

Called when an external event changes initiator interest, destinations, prime, spare, or spareWaiting. Leaves HappyConnOpener in one of these mutually exclusive "stable" states:

  1. Processing a single peer: currentPeer && !done() 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 && !done()
  3. Terminating: done()

Definition at line 717 of file HappyConnOpener.cc.

References cancelSpareWait(), currentPeer, debugs, destinations, AsyncJob::done(), ResolvedPeers::doneWithPeer(), ResolvedPeers::doneWithSpares(), HappySpareWait::forNewPeer, gotSpareAllowance, ignoreSpareRestrictions, maybeOpenPrimeConnection(), maybeOpenSpareConnection(), Must, prime, ranOutOfTimeOrAttempts(), spare, and spareWaiting.

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

◆ deleteThis()

void AsyncJob::deleteThis ( const char *  aReason)

◆ done()

bool AsyncJob::done ( ) const

◆ doneAll()

bool HappyConnOpener::doneAll ( ) const

◆ futureAnswer()

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

Definition at line 485 of file HappyConnOpener.cc.

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

Referenced by sendFailure(), and sendSuccess().

◆ handleConnOpenerAnswer()

◆ handleStopRequest()

void AsyncJob::handleStopRequest ( )

Definition at line 71 of file AsyncJob.h.

References AsyncJob::mustStop().

◆ makeError()

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

Create "503 Service Unavailable" or "504 Gateway Timeout" error depending on whether this is a validation request.

RFC 9111 section 5.2.2 Cache-Control response directives

section must-revalidate " if a cache is disconnected, the cache MUST generate an error response rather than reuse the stale response. The generated status code SHOULD be 504 (Gateway Timeout) unless another error status code is more applicable."

section proxy-revalidate " analogous to must-revalidate "

section s-maxage " incorporates the semantics of the proxy-revalidate response directive "

Definition at line 476 of file HappyConnOpener.cc.

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

Referenced by handleConnOpenerAnswer(), and sendFailure().

◆ maybeGivePrimeItsChance()

void HappyConnOpener::maybeGivePrimeItsChance ( )

◆ maybeOpenPrimeConnection()

◆ maybeOpenSpareConnection()

◆ mustStop()

◆ noteCandidatesChange()

void HappyConnOpener::noteCandidatesChange ( )

◆ noteGavePrimeItsChance()

void HappyConnOpener::noteGavePrimeItsChance ( )

◆ notePrimeConnectDone()

void HappyConnOpener::notePrimeConnectDone ( const CommConnectCbParams params)

Definition at line 600 of file HappyConnOpener.cc.

References handleConnOpenerAnswer(), and prime.

◆ noteSpareAllowance()

◆ noteSpareConnectDone()

void HappyConnOpener::noteSpareConnectDone ( const CommConnectCbParams params)

◆ openFreshConnection()

◆ ranOutOfTimeOrAttempts()

bool HappyConnOpener::ranOutOfTimeOrAttempts ( ) const

◆ reuseOldConnection()

bool HappyConnOpener::reuseOldConnection ( PeerConnectionPointer dest)

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

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

Definition at line 560 of file HappyConnOpener.cc.

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

Referenced by startConnecting().

◆ sendFailure()

void HappyConnOpener::sendFailure ( )

◆ sendSuccess()

void HappyConnOpener::sendSuccess ( const PeerConnectionPointer conn,
bool  reused,
const char *  connKind 

Definition at line 499 of file HappyConnOpener.cc.

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

Referenced by handleConnOpenerAnswer(), and reuseOldConnection().

◆ setHost()

void HappyConnOpener::setHost ( const char *  h)

Definition at line 351 of file HappyConnOpener.cc.

References host_, safe_free, and xstrdup.

◆ setRetriable()

void HappyConnOpener::setRetriable ( bool  retriable)

Definition at line 138 of file HappyConnOpener.h.

References retriable_.

◆ start()

void HappyConnOpener::start ( )

Reimplemented from AsyncJob.

Definition at line 359 of file HappyConnOpener.cc.

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

◆ Start()

◆ startConnecting()

◆ status()

const char * HappyConnOpener::status ( ) const

for debugging, starts with space

Reimplemented from AsyncJob.

Definition at line 432 of file HappyConnOpener.cc.

References SBufStream::buf(), SBuf::c_str(), SBuf::clear(), destinations, n_tries, prime, spare, and AsyncJob::stopReason.

◆ stopGivingPrimeItsChance()

void HappyConnOpener::stopGivingPrimeItsChance ( )

◆ stopWaitingForSpareAllowance()

void HappyConnOpener::stopWaitingForSpareAllowance ( )

◆ swanSong()

◆ toCbdata()

virtual void * CbdataParent::toCbdata ( )
pure virtualinherited

◆ updateSpareWaitAfterPrimeFailure()

void HappyConnOpener::updateSpareWaitAfterPrimeFailure ( )

Friends And Related Function Documentation

◆ HappyOrderEnforcer

friend class HappyOrderEnforcer

Definition at line 236 of file HappyConnOpener.h.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Attempt attempt 

Definition at line 417 of file HappyConnOpener.cc.

Member Data Documentation

◆ ale

AccessLogEntryPointer HappyConnOpener::ale

Definition at line 238 of file HappyConnOpener.h.

Referenced by makeError().

◆ allowPconn_

bool HappyConnOpener::allowPconn_ = true

Definition at line 250 of file HappyConnOpener.h.

Referenced by allowPersistent(), reuseOldConnection(), and startConnecting().

◆ callback_

AsyncCall::Pointer HappyConnOpener::callback_

◆ cause

HttpRequestPointer HappyConnOpener::cause

Definition at line 259 of file HappyConnOpener.h.

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

◆ currentPeer

Comm::ConnectionPointer HappyConnOpener::currentPeer

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 232 of file HappyConnOpener.h.

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

◆ destinations

◆ fwdStart

const time_t HappyConnOpener::fwdStart

Definition at line 217 of file HappyConnOpener.h.

Referenced by openFreshConnection(), and ranOutOfTimeOrAttempts().

◆ gotSpareAllowance

bool HappyConnOpener::gotSpareAllowance = false

◆ host_

const char* HappyConnOpener::host_ = nullptr

◆ id

const InstanceId<AsyncJob> AsyncJob::id

Definition at line 73 of file AsyncJob.h.

◆ ignoreSpareRestrictions

bool HappyConnOpener::ignoreSpareRestrictions = false

◆ inCall

AsyncCall::Pointer AsyncJob::inCall

◆ lastError

ErrorState* HappyConnOpener::lastError = nullptr

Definition at line 240 of file HappyConnOpener.h.

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

◆ lastFailedConnection

PeerConnectionPointer HappyConnOpener::lastFailedConnection

Definition at line 241 of file HappyConnOpener.h.

Referenced by handleConnOpenerAnswer(), and sendFailure().

◆ n_tries

int HappyConnOpener::n_tries

number of our finished connection opening attempts (including pconn reuses) plus previously finished attempts supplied by the requestor

Definition at line 263 of file HappyConnOpener.h.

Referenced by futureAnswer(), handleConnOpenerAnswer(), ranOutOfTimeOrAttempts(), reuseOldConnection(), and status().

◆ prime

◆ primeStart

HappyAbsoluteTime HappyConnOpener::primeStart = 0

Definition at line 153 of file HappyConnOpener.h.

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

◆ ranOutOfTimeOrAttemptsEarlier_

const char* HappyConnOpener::ranOutOfTimeOrAttemptsEarlier_ = nullptr

Definition at line 266 of file HappyConnOpener.h.

Referenced by ranOutOfTimeOrAttempts().

◆ retriable_

bool HappyConnOpener::retriable_ = true

Definition at line 253 of file HappyConnOpener.h.

Referenced by reuseOldConnection(), and setRetriable().

◆ spare

◆ spareWaiting

◆ started_

bool AsyncJob::started_ = false

Definition at line 83 of file AsyncJob.h.

Referenced by AsyncJob::~AsyncJob(), AsyncJob::callEnd(), and AsyncJob::Start().

◆ stopReason

const char* AsyncJob::stopReason

◆ swanSang_

bool AsyncJob::swanSang_ = false

Definition at line 84 of file AsyncJob.h.

Referenced by AsyncJob::~AsyncJob(), and AsyncJob::callEnd().

◆ typeName

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






Web Site Translations