@@ -225,7 +225,7 @@ Filter::~Filter() {
225
225
access_log->log (nullptr , nullptr , nullptr , getStreamInfo ());
226
226
}
227
227
228
- ASSERT (upstream_handle_ == nullptr );
228
+ ASSERT (generic_conn_pool_ == nullptr );
229
229
ASSERT (upstream_ == nullptr );
230
230
}
231
231
@@ -442,24 +442,17 @@ Network::FilterStatus Filter::initializeUpstreamConnection() {
442
442
443
443
bool Filter::maybeTunnel (const std::string& cluster_name) {
444
444
if (!config_->tunnelingConfig ()) {
445
- Tcp::ConnectionPool::Instance* conn_pool = cluster_manager_. tcpConnPoolForCluster (
446
- cluster_name, Upstream::ResourcePriority::Default , this );
447
- if (conn_pool ) {
445
+ generic_conn_pool_ =
446
+ std::make_unique<TcpConnPool>( cluster_name, cluster_manager_ , this , *upstream_callbacks_ );
447
+ if (generic_conn_pool_-> valid () ) {
448
448
connecting_ = true ;
449
449
connect_attempts_++;
450
-
451
- // Given this function is reentrant, make sure we only reset the upstream_handle_ if given a
452
- // valid connection handle. If newConnection fails inline it may result in attempting to
453
- // select a new host, and a recursive call to initializeUpstreamConnection. In this case the
454
- // first call to newConnection will return null and the inner call will persist.
455
- Tcp::ConnectionPool::Cancellable* handle = conn_pool->newConnection (*this );
456
- if (handle) {
457
- ASSERT (upstream_handle_.get () == nullptr );
458
- upstream_handle_ = std::make_shared<TcpConnectionHandle>(handle);
459
- }
450
+ generic_conn_pool_->newStream (this );
460
451
// Because we never return open connections to the pool, this either has a handle waiting on
461
452
// connection completion, or onPoolFailure has been invoked. Either way, stop iteration.
462
453
return true ;
454
+ } else {
455
+ generic_conn_pool_.reset ();
463
456
}
464
457
} else {
465
458
auto * cluster = cluster_manager_.get (cluster_name);
@@ -474,28 +467,23 @@ bool Filter::maybeTunnel(const std::string& cluster_name) {
474
467
" http2_protocol_options on the cluster." );
475
468
return false ;
476
469
}
477
- Http::ConnectionPool::Instance* conn_pool = cluster_manager_.httpConnPoolForCluster (
478
- cluster_name, Upstream::ResourcePriority::Default, absl::nullopt, this );
479
- if (conn_pool) {
480
- upstream_ = std::make_unique<HttpUpstream>(*upstream_callbacks_,
481
- config_->tunnelingConfig ()->hostname ());
482
- HttpUpstream* http_upstream = static_cast <HttpUpstream*>(upstream_.get ());
483
- Http::ConnectionPool::Cancellable* cancellable =
484
- conn_pool->newStream (http_upstream->responseDecoder (), *this );
485
- if (cancellable) {
486
- ASSERT (upstream_handle_.get () == nullptr );
487
- upstream_handle_ = std::make_shared<HttpConnectionHandle>(cancellable);
488
- }
470
+
471
+ generic_conn_pool_ = std::make_unique<HttpConnPool>(cluster_name, cluster_manager_, this ,
472
+ config_->tunnelingConfig ()->hostname (),
473
+ *upstream_callbacks_);
474
+ if (generic_conn_pool_->valid ()) {
475
+ generic_conn_pool_->newStream (this );
489
476
return true ;
477
+ } else {
478
+ generic_conn_pool_.reset ();
490
479
}
491
480
}
492
481
493
482
return false ;
494
483
}
495
- void Filter::onPoolFailure (ConnectionPool::PoolFailureReason reason,
496
- Upstream::HostDescriptionConstSharedPtr host) {
497
- upstream_handle_.reset ();
498
-
484
+ void Filter::onGenericPoolFailure (ConnectionPool::PoolFailureReason reason,
485
+ Upstream::HostDescriptionConstSharedPtr host) {
486
+ generic_conn_pool_.reset ();
499
487
read_callbacks_->upstreamHost (host);
500
488
getStreamInfo ().onUpstreamHostSelected (host);
501
489
@@ -518,44 +506,22 @@ void Filter::onPoolFailure(ConnectionPool::PoolFailureReason reason,
518
506
}
519
507
}
520
508
521
- void Filter::onPoolReadyBase (Upstream::HostDescriptionConstSharedPtr& host,
522
- const Network::Address::InstanceConstSharedPtr& local_address,
523
- Ssl::ConnectionInfoConstSharedPtr ssl_info) {
524
- upstream_handle_.reset ();
509
+ void Filter::onGenericPoolReady (StreamInfo::StreamInfo* info,
510
+ std::unique_ptr<GenericUpstream>&& upstream,
511
+ Upstream::HostDescriptionConstSharedPtr& host,
512
+ const Network::Address::InstanceConstSharedPtr& local_address,
513
+ Ssl::ConnectionInfoConstSharedPtr ssl_info) {
514
+ upstream_ = std::move (upstream);
515
+ generic_conn_pool_.reset ();
525
516
read_callbacks_->upstreamHost (host);
526
517
getStreamInfo ().onUpstreamHostSelected (host);
527
518
getStreamInfo ().setUpstreamLocalAddress (local_address);
528
519
getStreamInfo ().setUpstreamSslConnection (ssl_info);
529
520
onUpstreamConnection ();
530
521
read_callbacks_->continueReading ();
531
- }
532
-
533
- void Filter::onPoolReady (Tcp::ConnectionPool::ConnectionDataPtr&& conn_data,
534
- Upstream::HostDescriptionConstSharedPtr host) {
535
- Tcp::ConnectionPool::ConnectionData* latched_data = conn_data.get ();
536
-
537
- upstream_ = std::make_unique<TcpUpstream>(std::move (conn_data), *upstream_callbacks_);
538
- onPoolReadyBase (host, latched_data->connection ().localAddress (),
539
- latched_data->connection ().streamInfo ().downstreamSslConnection ());
540
- read_callbacks_->connection ().streamInfo ().setUpstreamFilterState (
541
- latched_data->connection ().streamInfo ().filterState ());
542
- }
543
-
544
- void Filter::onPoolFailure (ConnectionPool::PoolFailureReason failure, absl::string_view,
545
- Upstream::HostDescriptionConstSharedPtr host) {
546
- onPoolFailure (failure, host);
547
- }
548
-
549
- void Filter::onPoolReady (Http::RequestEncoder& request_encoder,
550
- Upstream::HostDescriptionConstSharedPtr host,
551
- const StreamInfo::StreamInfo& info) {
552
- Http::RequestEncoder* latched_encoder = &request_encoder;
553
- HttpUpstream* http_upstream = static_cast <HttpUpstream*>(upstream_.get ());
554
- http_upstream->setRequestEncoder (request_encoder,
555
- host->transportSocketFactory ().implementsSecureTransport ());
556
-
557
- onPoolReadyBase (host, latched_encoder->getStream ().connectionLocalAddress (),
558
- info.downstreamSslConnection ());
522
+ if (info) {
523
+ read_callbacks_->connection ().streamInfo ().setUpstreamFilterState (info->filterState ());
524
+ }
559
525
}
560
526
561
527
const Router::MetadataMatchCriteria* Filter::metadataMatchCriteria () {
@@ -624,12 +590,11 @@ void Filter::onDownstreamEvent(Network::ConnectionEvent event) {
624
590
disableIdleTimer ();
625
591
}
626
592
}
627
- if (upstream_handle_ ) {
593
+ if (generic_conn_pool_ ) {
628
594
if (event == Network::ConnectionEvent::LocalClose ||
629
595
event == Network::ConnectionEvent::RemoteClose) {
630
596
// Cancel the conn pool request and close any excess pending requests.
631
- upstream_handle_->cancel ();
632
- upstream_handle_.reset ();
597
+ generic_conn_pool_.reset ();
633
598
}
634
599
}
635
600
}
0 commit comments