@@ -60,23 +60,24 @@ type EventHub struct {
6060 // Factory that creates EventsClient
6161 eventsClientFactory eventClientFactory
6262 // FabricClient
63- provider fab.ProviderContext
64- identity fab.IdentityContext
65- kap keepalive.ClientParameters
66- failFast bool
63+ provider fab.ProviderContext
64+ identity fab.IdentityContext
65+ kap keepalive.ClientParameters
66+ failFast bool
67+ allowInsecure bool
6768}
6869
6970// eventClientFactory creates an EventsClient instance
7071type eventClientFactory interface {
71- newEventsClient (provider fab.ProviderContext , identity fab.IdentityContext , peerAddress string , certificate * x509.Certificate , serverHostOverride string , regTimeout time.Duration , adapter cnsmr.EventAdapter , kap keepalive.ClientParameters , failFast bool ) (fab.EventsClient , error )
72+ newEventsClient (provider fab.ProviderContext , identity fab.IdentityContext , peerAddress string , certificate * x509.Certificate , serverHostOverride string , regTimeout time.Duration , adapter cnsmr.EventAdapter , kap keepalive.ClientParameters , failFast bool , allowInsecure bool ) (fab.EventsClient , error )
7273}
7374
7475// consumerClientFactory is the default implementation oif the eventClientFactory
7576type consumerClientFactory struct {}
7677
7778func (ccf * consumerClientFactory ) newEventsClient (provider fab.ProviderContext , identity fab.IdentityContext , peerAddress string , certificate * x509.Certificate , serverHostOverride string ,
78- regTimeout time.Duration , adapter cnsmr.EventAdapter , kap keepalive.ClientParameters , failFast bool ) (fab.EventsClient , error ) {
79- return consumer .NewEventsClient (provider , identity , peerAddress , certificate , serverHostOverride , regTimeout , adapter , kap , failFast )
79+ regTimeout time.Duration , adapter cnsmr.EventAdapter , kap keepalive.ClientParameters , failFast bool , allowInsecure bool ) (fab.EventsClient , error ) {
80+ return consumer .NewEventsClient (provider , identity , peerAddress , certificate , serverHostOverride , regTimeout , adapter , kap , failFast , allowInsecure )
8081}
8182
8283// Context holds the providers and services needed to create an EventHub.
@@ -126,6 +127,8 @@ func FromConfig(ctx Context, peerCfg *apiconfig.PeerConfig) (*EventHub, error) {
126127 eventHub .peerTLSServerHostOverride = serverHostOverride
127128 eventHub .kap = getKeepAliveOptions (peerCfg )
128129 eventHub .failFast = getFailFast (peerCfg )
130+ eventHub .allowInsecure = isInsecureConnectionAllowed (peerCfg )
131+
129132 return eventHub , nil
130133}
131134
@@ -278,10 +281,12 @@ func (eventHub *EventHub) removeChaincodeInterest(ChaincodeID string, EventName
278281// peeraddr peer url
279282// peerTLSCertificate peer tls certificate
280283// peerTLSServerHostOverride tls serverhostoverride
281- func (eventHub * EventHub ) SetPeerAddr (peerURL string , peerTLSCertificate * x509.Certificate , peerTLSServerHostOverride string ) {
284+ // inSecure option enables grpc retry when grpcs fails (only when no protocol provided in peerURL)
285+ func (eventHub * EventHub ) SetPeerAddr (peerURL string , peerTLSCertificate * x509.Certificate , peerTLSServerHostOverride string , allowInsecure bool ) {
282286 eventHub .peerAddr = peerURL
283287 eventHub .peerTLSCertificate = peerTLSCertificate
284288 eventHub .peerTLSServerHostOverride = peerTLSServerHostOverride
289+ eventHub .allowInsecure = allowInsecure && ! urlutil .HasProtocol (peerURL )
285290}
286291
287292// IsConnected gets connected state of eventhub
@@ -312,7 +317,7 @@ func (eventHub *EventHub) Connect() error {
312317 if eventHub .grpcClient == nil {
313318 eventsClient , _ := eventHub .eventsClientFactory .newEventsClient (eventHub .provider , eventHub .identity ,
314319 eventHub .peerAddr , eventHub .peerTLSCertificate , eventHub .peerTLSServerHostOverride ,
315- eventHub .provider .Config ().TimeoutOrDefault (apiconfig .EventReg ), eventHub , eventHub .kap , eventHub .failFast )
320+ eventHub .provider .Config ().TimeoutOrDefault (apiconfig .EventReg ), eventHub , eventHub .kap , eventHub .failFast , eventHub . allowInsecure )
316321 eventHub .grpcClient = eventsClient
317322 }
318323
@@ -602,3 +607,13 @@ func (eventHub *EventHub) notifyChaincodeRegistrants(channelID string, ccEvent *
602607 }
603608 }
604609}
610+
611+ func isInsecureConnectionAllowed (peerCfg * apiconfig.PeerConfig ) bool {
612+ //allowInsecure used only when protocol is missing from URL
613+ allowInsecure := ! urlutil .HasProtocol (peerCfg .URL )
614+ boolVal , ok := peerCfg .GRPCOptions ["allow-insecure" ].(bool )
615+ if ok {
616+ return allowInsecure && boolVal
617+ }
618+ return false
619+ }
0 commit comments