@@ -304,57 +304,10 @@ func serve(args []string) error {
304
304
// Register the Endorser server
305
305
pb .RegisterEndorserServer (peerServer .Server (), auth )
306
306
307
- // Initialize gossip component
308
- bootstrap := viper .GetStringSlice ("peer.gossip.bootstrap" )
309
-
310
307
policyMgr := peer .NewChannelPolicyManagerGetter ()
311
- messageCryptoService := peergossip .NewMCS (
312
- policyMgr ,
313
- localmsp .NewSigner (),
314
- mgmt .NewDeserializersManager ())
315
- secAdv := peergossip .NewSecurityAdvisor (mgmt .NewDeserializersManager ())
316
-
317
- // callback function for secure dial options for gossip service
318
- secureDialOpts := func () []grpc.DialOption {
319
- var dialOpts []grpc.DialOption
320
- // set max send/recv msg sizes
321
- dialOpts = append (
322
- dialOpts ,
323
- grpc .WithDefaultCallOptions (
324
- grpc .MaxCallRecvMsgSize (comm .MaxRecvMsgSize ),
325
- grpc .MaxCallSendMsgSize (comm .MaxSendMsgSize )))
326
- // set the keepalive options
327
- kaOpts := comm .DefaultKeepaliveOptions
328
- if viper .IsSet ("peer.keepalive.client.interval" ) {
329
- kaOpts .ClientInterval = viper .GetDuration ("peer.keepalive.client.interval" )
330
- }
331
- if viper .IsSet ("peer.keepalive.client.timeout" ) {
332
- kaOpts .ClientTimeout = viper .GetDuration ("peer.keepalive.client.timeout" )
333
- }
334
- dialOpts = append (dialOpts , comm .ClientKeepaliveOptions (kaOpts )... )
335
-
336
- if viper .GetBool ("peer.tls.enabled" ) {
337
- dialOpts = append (dialOpts , grpc .WithTransportCredentials (comm .GetCredentialSupport ().GetPeerCredentials ()))
338
- } else {
339
- dialOpts = append (dialOpts , grpc .WithInsecure ())
340
- }
341
- return dialOpts
342
- }
343
-
344
- var certs * gossipcommon.TLSCertificates
345
- if peerServer .TLSEnabled () {
346
- serverCert := peerServer .ServerCertificate ()
347
- clientCert , err := peer .GetClientCertificate ()
348
- if err != nil {
349
- return errors .Wrap (err , "failed obtaining client certificates" )
350
- }
351
- certs = & gossipcommon.TLSCertificates {}
352
- certs .TLSServerCert .Store (& serverCert )
353
- certs .TLSClientCert .Store (& clientCert )
354
- }
355
308
356
- err = service . InitGossipService ( serializedIdentity , peerEndpoint . Address , peerServer . Server (), certs ,
357
- messageCryptoService , secAdv , secureDialOpts , bootstrap ... )
309
+ // Initialize gossip component
310
+ err = initGossipService ( policyMgr , peerServer , serializedIdentity , peerEndpoint . Address )
358
311
if err != nil {
359
312
return err
360
313
}
@@ -713,3 +666,59 @@ func startAdminServer(peerListenAddr string, peerServer *grpc.Server) {
713
666
714
667
pb .RegisterAdminServer (gRPCService , admin .NewAdminServer (adminPolicy ))
715
668
}
669
+
670
+ // secureDialOpts is the callback function for secure dial options for gossip service
671
+ func secureDialOpts () []grpc.DialOption {
672
+ var dialOpts []grpc.DialOption
673
+ // set max send/recv msg sizes
674
+ dialOpts = append (
675
+ dialOpts ,
676
+ grpc .WithDefaultCallOptions (
677
+ grpc .MaxCallRecvMsgSize (comm .MaxRecvMsgSize ),
678
+ grpc .MaxCallSendMsgSize (comm .MaxSendMsgSize )))
679
+ // set the keepalive options
680
+ kaOpts := comm .DefaultKeepaliveOptions
681
+ if viper .IsSet ("peer.keepalive.client.interval" ) {
682
+ kaOpts .ClientInterval = viper .GetDuration ("peer.keepalive.client.interval" )
683
+ }
684
+ if viper .IsSet ("peer.keepalive.client.timeout" ) {
685
+ kaOpts .ClientTimeout = viper .GetDuration ("peer.keepalive.client.timeout" )
686
+ }
687
+ dialOpts = append (dialOpts , comm .ClientKeepaliveOptions (kaOpts )... )
688
+
689
+ if viper .GetBool ("peer.tls.enabled" ) {
690
+ dialOpts = append (dialOpts , grpc .WithTransportCredentials (comm .GetCredentialSupport ().GetPeerCredentials ()))
691
+ } else {
692
+ dialOpts = append (dialOpts , grpc .WithInsecure ())
693
+ }
694
+ return dialOpts
695
+ }
696
+
697
+ // initGossipService will initialize the gossip service by:
698
+ // 1. Enable TLS if configured;
699
+ // 2. Init the message crypto service;
700
+ // 3. Init the security advisor;
701
+ // 4. Init gossip related struct.
702
+ func initGossipService (policyMgr policies.ChannelPolicyManagerGetter , peerServer * comm.GRPCServer , serializedIdentity []byte , peerAddr string ) error {
703
+ var certs * gossipcommon.TLSCertificates
704
+ if peerServer .TLSEnabled () {
705
+ serverCert := peerServer .ServerCertificate ()
706
+ clientCert , err := peer .GetClientCertificate ()
707
+ if err != nil {
708
+ return errors .Wrap (err , "failed obtaining client certificates" )
709
+ }
710
+ certs = & gossipcommon.TLSCertificates {}
711
+ certs .TLSServerCert .Store (& serverCert )
712
+ certs .TLSClientCert .Store (& clientCert )
713
+ }
714
+
715
+ messageCryptoService := peergossip .NewMCS (
716
+ policyMgr ,
717
+ localmsp .NewSigner (),
718
+ mgmt .NewDeserializersManager ())
719
+ secAdv := peergossip .NewSecurityAdvisor (mgmt .NewDeserializersManager ())
720
+ bootstrap := viper .GetStringSlice ("peer.gossip.bootstrap" )
721
+
722
+ return service .InitGossipService (serializedIdentity , peerAddr , peerServer .Server (), certs ,
723
+ messageCryptoService , secAdv , secureDialOpts , bootstrap ... )
724
+ }
0 commit comments