@ -26,6 +26,8 @@
# include "src/core/ext/xds/xds_certificate_provider.h"
# include "src/core/ext/xds/xds_certificate_provider.h"
# include "src/core/ext/xds/xds_channel_stack_modifier.h"
# include "src/core/ext/xds/xds_channel_stack_modifier.h"
# include "src/core/ext/xds/xds_client.h"
# include "src/core/ext/xds/xds_client.h"
# include "src/core/ext/xds/xds_listener.h"
# include "src/core/ext/xds/xds_route_config.h"
# include "src/core/ext/xds/xds_routing.h"
# include "src/core/ext/xds/xds_routing.h"
# include "src/core/lib/address_utils/sockaddr_utils.h"
# include "src/core/lib/address_utils/sockaddr_utils.h"
# include "src/core/lib/channel/channel_args.h"
# include "src/core/lib/channel/channel_args.h"
@ -86,7 +88,7 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher {
// update received was a fatal error (resource does not exist), the server
// update received was a fatal error (resource does not exist), the server
// listener is made to stop listening.
// listener is made to stop listening.
class XdsServerConfigFetcher : : ListenerWatcher
class XdsServerConfigFetcher : : ListenerWatcher
: public XdsClient : : Listener WatcherInterface {
: public XdsListenerResourceType : : WatcherInterface {
public :
public :
ListenerWatcher ( RefCountedPtr < XdsClient > xds_client ,
ListenerWatcher ( RefCountedPtr < XdsClient > xds_client ,
std : : unique_ptr < grpc_server_config_fetcher : : WatcherInterface >
std : : unique_ptr < grpc_server_config_fetcher : : WatcherInterface >
@ -217,7 +219,7 @@ class XdsServerConfigFetcher::ListenerWatcher::FilterChainMatchManager
// with the latest updates and new connections do not need to wait for the RDS
// with the latest updates and new connections do not need to wait for the RDS
// resources to be fetched.
// resources to be fetched.
class XdsServerConfigFetcher : : ListenerWatcher : : FilterChainMatchManager : :
class XdsServerConfigFetcher : : ListenerWatcher : : FilterChainMatchManager : :
RouteConfigWatcher : public XdsClient : : RouteConfig WatcherInterface {
RouteConfigWatcher : public XdsRouteConfigResourceType : : WatcherInterface {
public :
public :
RouteConfigWatcher (
RouteConfigWatcher (
std : : string resource_name ,
std : : string resource_name ,
@ -381,7 +383,7 @@ class XdsServerConfigFetcher::ListenerWatcher::FilterChainMatchManager::
// DynamicXdsServerConfigSelectorProvider
// DynamicXdsServerConfigSelectorProvider
class XdsServerConfigFetcher : : ListenerWatcher : : FilterChainMatchManager : :
class XdsServerConfigFetcher : : ListenerWatcher : : FilterChainMatchManager : :
DynamicXdsServerConfigSelectorProvider : : RouteConfigWatcher
DynamicXdsServerConfigSelectorProvider : : RouteConfigWatcher
: public XdsClient : : RouteConfig WatcherInterface {
: public XdsRouteConfigResourceType : : WatcherInterface {
public :
public :
explicit RouteConfigWatcher (
explicit RouteConfigWatcher (
RefCountedPtr < DynamicXdsServerConfigSelectorProvider > parent )
RefCountedPtr < DynamicXdsServerConfigSelectorProvider > parent )
@ -418,7 +420,8 @@ void XdsServerConfigFetcher::StartWatch(
xds_client_ , std : : move ( watcher ) , serving_status_notifier_ ,
xds_client_ , std : : move ( watcher ) , serving_status_notifier_ ,
listening_address ) ;
listening_address ) ;
auto * listener_watcher_ptr = listener_watcher . get ( ) ;
auto * listener_watcher_ptr = listener_watcher . get ( ) ;
xds_client_ - > WatchListenerData (
XdsListenerResourceType : : StartWatch (
xds_client_ . get ( ) ,
absl : : StrReplaceAll (
absl : : StrReplaceAll (
xds_client_ - > bootstrap ( ) . server_listener_resource_name_template ( ) ,
xds_client_ - > bootstrap ( ) . server_listener_resource_name_template ( ) ,
{ { " %s " , listening_address } } ) ,
{ { " %s " , listening_address } } ) ,
@ -433,7 +436,8 @@ void XdsServerConfigFetcher::CancelWatch(
auto it = listener_watchers_ . find ( watcher ) ;
auto it = listener_watchers_ . find ( watcher ) ;
if ( it ! = listener_watchers_ . end ( ) ) {
if ( it ! = listener_watchers_ . end ( ) ) {
// Cancel the watch on the listener before erasing
// Cancel the watch on the listener before erasing
xds_client_ - > CancelListenerDataWatch (
XdsListenerResourceType : : CancelWatch (
xds_client_ . get ( ) ,
absl : : StrReplaceAll (
absl : : StrReplaceAll (
xds_client_ - > bootstrap ( ) . server_listener_resource_name_template ( ) ,
xds_client_ - > bootstrap ( ) . server_listener_resource_name_template ( ) ,
{ { " %s " , it - > second - > listening_address ( ) } } ) ,
{ { " %s " , it - > second - > listening_address ( ) } } ) ,
@ -618,8 +622,8 @@ void XdsServerConfigFetcher::ListenerWatcher::FilterChainMatchManager::
MakeRefCounted < RouteConfigWatcher > ( resource_name , WeakRef ( ) ) ;
MakeRefCounted < RouteConfigWatcher > ( resource_name , WeakRef ( ) ) ;
rds_map_ . emplace ( resource_name , RdsUpdateState { route_config_watcher . get ( ) ,
rds_map_ . emplace ( resource_name , RdsUpdateState { route_config_watcher . get ( ) ,
absl : : nullopt } ) ;
absl : : nullopt } ) ;
xds_client_ - > WatchRouteConfigData ( resource_name ,
XdsRouteConfigResourceType : : StartWatch ( xds_client_ . get ( ) , resource_name ,
std : : move ( route_config_watcher ) ) ;
std : : move ( route_config_watcher ) ) ;
}
}
if ( rds_resources_yet_to_fetch_ ! = 0 ) {
if ( rds_resources_yet_to_fetch_ ! = 0 ) {
listener_watcher_ = std : : move ( listener_watcher ) ;
listener_watcher_ = std : : move ( listener_watcher ) ;
@ -638,7 +642,8 @@ void XdsServerConfigFetcher::ListenerWatcher::FilterChainMatchManager::
MutexLock lock ( & mu_ ) ;
MutexLock lock ( & mu_ ) ;
// Cancel the RDS watches to clear up the weak refs
// Cancel the RDS watches to clear up the weak refs
for ( const auto & entry : rds_map_ ) {
for ( const auto & entry : rds_map_ ) {
xds_client_ - > CancelRouteConfigDataWatch ( entry . first , entry . second . watcher ,
XdsRouteConfigResourceType : : CancelWatch ( xds_client_ . get ( ) , entry . first ,
entry . second . watcher ,
false /* delay_unsubscription */ ) ;
false /* delay_unsubscription */ ) ;
}
}
// Also give up the ref on ListenerWatcher since it won't be needed anymore
// Also give up the ref on ListenerWatcher since it won't be needed anymore
@ -1159,8 +1164,8 @@ XdsServerConfigFetcher::ListenerWatcher::FilterChainMatchManager::
GPR_ASSERT ( ! resource_name_ . empty ( ) ) ;
GPR_ASSERT ( ! resource_name_ . empty ( ) ) ;
auto route_config_watcher = MakeRefCounted < RouteConfigWatcher > ( Ref ( ) ) ;
auto route_config_watcher = MakeRefCounted < RouteConfigWatcher > ( Ref ( ) ) ;
route_config_watcher_ = route_config_watcher . get ( ) ;
route_config_watcher_ = route_config_watcher . get ( ) ;
xds_client_ - > WatchRouteConfigData ( resource_name_ ,
XdsRouteConfigResourceType : : StartWatch ( xds_client_ . get ( ) , resource_name_ ,
std : : move ( route_config_watcher ) ) ;
std : : move ( route_config_watcher ) ) ;
}
}
absl : : StatusOr < RefCountedPtr < ServerConfigSelector > >
absl : : StatusOr < RefCountedPtr < ServerConfigSelector > >
@ -1184,7 +1189,8 @@ XdsServerConfigFetcher::ListenerWatcher::FilterChainMatchManager::
void XdsServerConfigFetcher : : ListenerWatcher : : FilterChainMatchManager : :
void XdsServerConfigFetcher : : ListenerWatcher : : FilterChainMatchManager : :
DynamicXdsServerConfigSelectorProvider : : CancelWatch ( ) {
DynamicXdsServerConfigSelectorProvider : : CancelWatch ( ) {
xds_client_ - > CancelRouteConfigDataWatch ( resource_name_ , route_config_watcher_ ,
XdsRouteConfigResourceType : : CancelWatch ( xds_client_ . get ( ) , resource_name_ ,
route_config_watcher_ ,
false /* delay_unsubscription */ ) ;
false /* delay_unsubscription */ ) ;
MutexLock lock ( & mu_ ) ;
MutexLock lock ( & mu_ ) ;
watcher_ . reset ( ) ;
watcher_ . reset ( ) ;