@@ -83,6 +83,7 @@ interface ConfigParameters {
83
83
createConnectionInjector : ( credentials : ServerCredentials ) => ConnectionInjector ;
84
84
drainGraceTimeMs : number ;
85
85
listenerResourceNameTemplate : string ;
86
+ unregisterChannelzRef : ( ) => void ;
86
87
}
87
88
88
89
class FilterChainEntry {
@@ -159,22 +160,25 @@ class FilterChainEntry {
159
160
}
160
161
if ( credentials instanceof XdsServerCredentials ) {
161
162
if ( filterChain . transport_socket ) {
163
+ trace ( 'Using secure credentials' ) ;
162
164
const downstreamTlsContext = decodeSingleResource ( DOWNSTREAM_TLS_CONTEXT_TYPE_URL , filterChain . transport_socket . typed_config ! . value ) ;
163
165
const commonTlsContext = downstreamTlsContext . common_tls_context ! ;
164
166
const instanceCertificateProvider = configParameters . xdsClient . getCertificateProvider ( commonTlsContext . tls_certificate_provider_instance ! . instance_name ) ;
165
167
if ( ! instanceCertificateProvider ) {
166
168
throw new Error ( `Invalid TLS context detected: unrecognized certificate instance name: ${ commonTlsContext . tls_certificate_provider_instance ! . instance_name } ` ) ;
167
169
}
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
+ }
178
182
}
179
183
let caCertificateProvider : experimental . CertificateProvider | null = null ;
180
184
if ( validationContext ?. ca_certificate_provider_instance ) {
@@ -185,6 +189,7 @@ class FilterChainEntry {
185
189
}
186
190
credentials = experimental . createCertificateProviderServerCredentials ( instanceCertificateProvider , caCertificateProvider , downstreamTlsContext . require_client_certificate ?. value ?? false ) ;
187
191
} else {
192
+ trace ( 'Using fallback credentials' ) ;
188
193
credentials = credentials . getFallbackCredentials ( ) ;
189
194
}
190
195
}
@@ -287,6 +292,7 @@ class ListenerConfig {
287
292
handleConnection ( socket : net . Socket ) {
288
293
const matchingFilter = selectMostSpecificallyMatchingFilter ( this . filterChainEntries , socket ) ?? this . defaultFilterChain ;
289
294
if ( ! matchingFilter ) {
295
+ trace ( 'Rejecting connection from ' + socket . remoteAddress + ': No filter matched' ) ;
290
296
socket . destroy ( ) ;
291
297
return ;
292
298
}
@@ -449,12 +455,25 @@ class BoundPortEntry {
449
455
this . tcpServer . close ( ) ;
450
456
const resourceName = formatTemplateString ( this . configParameters . listenerResourceNameTemplate , this . boundAddress ) ;
451
457
ListenerResourceType . cancelWatch ( this . configParameters . xdsClient , resourceName , this . listenerWatcher ) ;
458
+ this . configParameters . unregisterChannelzRef ( ) ;
452
459
}
453
460
}
454
461
455
462
function normalizeFilterChainMatch ( filterChainMatch : FilterChainMatch__Output | null ) : NormalizedFilterChainMatch [ ] {
456
463
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
+ } ;
458
477
}
459
478
if ( filterChainMatch . destination_port ) {
460
479
return [ ] ;
@@ -613,11 +632,13 @@ export class XdsServer extends Server {
613
632
if ( ! hostPort || ! isValidIpPort ( hostPort ) ) {
614
633
throw new Error ( `Listening port string must have the format IP:port with non-zero port, got ${ port } ` ) ;
615
634
}
635
+ const channelzRef = this . experimentalRegisterListenerToChannelz ( { host : hostPort . host , port : hostPort . port ! } ) ;
616
636
const configParameters : ConfigParameters = {
617
- createConnectionInjector : ( credentials ) => this . createConnectionInjector ( credentials ) ,
637
+ createConnectionInjector : ( credentials ) => this . experimentalCreateConnectionInjectorWithChannelzRef ( credentials , channelzRef ) ,
618
638
drainGraceTimeMs : this . drainGraceTimeMs ,
619
639
listenerResourceNameTemplate : this . listenerResourceNameTemplate ,
620
- xdsClient : this . xdsClient
640
+ xdsClient : this . xdsClient ,
641
+ unregisterChannelzRef : ( ) => this . experimentalUnregisterListenerFromChannelz ( channelzRef )
621
642
} ;
622
643
const portEntry = new BoundPortEntry ( configParameters , port , creds ) ;
623
644
const servingStatusListener : ServingStatusListener = statusObject => {
0 commit comments