@@ -83,6 +83,7 @@ interface ConfigParameters {
8383 createConnectionInjector : ( credentials : ServerCredentials ) => ConnectionInjector ;
8484 drainGraceTimeMs : number ;
8585 listenerResourceNameTemplate : string ;
86+ unregisterChannelzRef : ( ) => void ;
8687}
8788
8889class FilterChainEntry {
@@ -159,22 +160,25 @@ class FilterChainEntry {
159160 }
160161 if ( credentials instanceof XdsServerCredentials ) {
161162 if ( filterChain . transport_socket ) {
163+ trace ( 'Using secure credentials' ) ;
162164 const downstreamTlsContext = decodeSingleResource ( DOWNSTREAM_TLS_CONTEXT_TYPE_URL , filterChain . transport_socket . typed_config ! . value ) ;
163165 const commonTlsContext = downstreamTlsContext . common_tls_context ! ;
164166 const instanceCertificateProvider = configParameters . xdsClient . getCertificateProvider ( commonTlsContext . tls_certificate_provider_instance ! . instance_name ) ;
165167 if ( ! instanceCertificateProvider ) {
166168 throw new Error ( `Invalid TLS context detected: unrecognized certificate instance name: ${ commonTlsContext . tls_certificate_provider_instance ! . instance_name } ` ) ;
167169 }
168- let validationContext : CertificateValidationContext__Output | null ;
169- switch ( commonTlsContext ?. validation_context_type ) {
170- case 'validation_context' :
171- validationContext = commonTlsContext . validation_context ! ;
172- break ;
173- case 'combined_validation_context' :
174- validationContext = commonTlsContext . combined_validation_context ! . default_validation_context ;
175- break ;
176- default :
177- throw new Error ( `Invalid TLS context detected: invalid validation_context_type: ${ commonTlsContext . validation_context_type } ` ) ;
170+ let validationContext : CertificateValidationContext__Output | null = null ;
171+ if ( commonTlsContext ?. validation_context_type ) {
172+ switch ( commonTlsContext ?. validation_context_type ) {
173+ case 'validation_context' :
174+ validationContext = commonTlsContext . validation_context ! ;
175+ break ;
176+ case 'combined_validation_context' :
177+ validationContext = commonTlsContext . combined_validation_context ! . default_validation_context ;
178+ break ;
179+ default :
180+ throw new Error ( `Invalid TLS context detected: invalid validation_context_type: ${ commonTlsContext . validation_context_type } ` ) ;
181+ }
178182 }
179183 let caCertificateProvider : experimental . CertificateProvider | null = null ;
180184 if ( validationContext ?. ca_certificate_provider_instance ) {
@@ -185,6 +189,7 @@ class FilterChainEntry {
185189 }
186190 credentials = experimental . createCertificateProviderServerCredentials ( instanceCertificateProvider , caCertificateProvider , downstreamTlsContext . require_client_certificate ?. value ?? false ) ;
187191 } else {
192+ trace ( 'Using fallback credentials' ) ;
188193 credentials = credentials . getFallbackCredentials ( ) ;
189194 }
190195 }
@@ -287,6 +292,7 @@ class ListenerConfig {
287292 handleConnection ( socket : net . Socket ) {
288293 const matchingFilter = selectMostSpecificallyMatchingFilter ( this . filterChainEntries , socket ) ?? this . defaultFilterChain ;
289294 if ( ! matchingFilter ) {
295+ trace ( 'Rejecting connection from ' + socket . remoteAddress + ': No filter matched' ) ;
290296 socket . destroy ( ) ;
291297 return ;
292298 }
@@ -449,12 +455,25 @@ class BoundPortEntry {
449455 this . tcpServer . close ( ) ;
450456 const resourceName = formatTemplateString ( this . configParameters . listenerResourceNameTemplate , this . boundAddress ) ;
451457 ListenerResourceType . cancelWatch ( this . configParameters . xdsClient , resourceName , this . listenerWatcher ) ;
458+ this . configParameters . unregisterChannelzRef ( ) ;
452459 }
453460}
454461
455462function normalizeFilterChainMatch ( filterChainMatch : FilterChainMatch__Output | null ) : NormalizedFilterChainMatch [ ] {
456463 if ( ! filterChainMatch ) {
457- return [ ] ;
464+ filterChainMatch = {
465+ address_suffix : '' ,
466+ application_protocols : [ ] ,
467+ destination_port : null ,
468+ direct_source_prefix_ranges : [ ] ,
469+ prefix_ranges : [ ] ,
470+ server_names : [ ] ,
471+ source_ports : [ ] ,
472+ source_prefix_ranges : [ ] ,
473+ source_type : 'ANY' ,
474+ suffix_len : null ,
475+ transport_protocol : 'raw_buffer'
476+ } ;
458477 }
459478 if ( filterChainMatch . destination_port ) {
460479 return [ ] ;
@@ -613,11 +632,13 @@ export class XdsServer extends Server {
613632 if ( ! hostPort || ! isValidIpPort ( hostPort ) ) {
614633 throw new Error ( `Listening port string must have the format IP:port with non-zero port, got ${ port } ` ) ;
615634 }
635+ const channelzRef = this . experimentalRegisterListenerToChannelz ( { host : hostPort . host , port : hostPort . port ! } ) ;
616636 const configParameters : ConfigParameters = {
617- createConnectionInjector : ( credentials ) => this . createConnectionInjector ( credentials ) ,
637+ createConnectionInjector : ( credentials ) => this . experimentalCreateConnectionInjectorWithChannelzRef ( credentials , channelzRef ) ,
618638 drainGraceTimeMs : this . drainGraceTimeMs ,
619639 listenerResourceNameTemplate : this . listenerResourceNameTemplate ,
620- xdsClient : this . xdsClient
640+ xdsClient : this . xdsClient ,
641+ unregisterChannelzRef : ( ) => this . experimentalUnregisterListenerFromChannelz ( channelzRef )
621642 } ;
622643 const portEntry = new BoundPortEntry ( configParameters , port , creds ) ;
623644 const servingStatusListener : ServingStatusListener = statusObject => {
0 commit comments