Skip to content

Commit c26669d

Browse files
committed
Gossip service setup TLS
While initializing gossip component/service this commit checks whenever TLS is enabled and setup dial options accordingly. Change-Id: I6aa48a3c7b31f7fb66b19a21a698127aae5e7e9e Signed-off-by: Artem Barger <[email protected]>
1 parent 43f4e57 commit c26669d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

gossip/service/gossip_service.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package service
1919
import (
2020
"sync"
2121

22+
peerComm "github.com/hyperledger/fabric/core/comm"
2223
"github.com/hyperledger/fabric/core/committer"
2324
"github.com/hyperledger/fabric/gossip/comm"
2425
gossipCommon "github.com/hyperledger/fabric/gossip/common"
@@ -29,6 +30,7 @@ import (
2930
"github.com/hyperledger/fabric/gossip/state"
3031
"github.com/hyperledger/fabric/protos/common"
3132
"github.com/hyperledger/fabric/protos/utils"
33+
"github.com/op/go-logging"
3234
"google.golang.org/grpc"
3335
)
3436

@@ -55,10 +57,20 @@ type gossipServiceImpl struct {
5557
lock sync.RWMutex
5658
}
5759

60+
var logger = logging.MustGetLogger("gossipService")
61+
5862
// InitGossipService initialize gossip service
5963
func InitGossipService(endpoint string, s *grpc.Server, bootPeers ...string) {
6064
once.Do(func() {
61-
gossip := integration.NewGossipComponent(endpoint, s, []grpc.DialOption{}, bootPeers...)
65+
logger.Info("Initialize gossip with endpoint", endpoint, "and bootstrap set", bootPeers)
66+
dialOpts := []grpc.DialOption{}
67+
if peerComm.TLSEnabled() {
68+
dialOpts = append(dialOpts, grpc.WithTransportCredentials(peerComm.InitTLSForPeer()))
69+
} else {
70+
dialOpts = append(dialOpts, grpc.WithInsecure())
71+
}
72+
73+
gossip := integration.NewGossipComponent(endpoint, s, dialOpts, bootPeers...)
6274
gossipServiceInstance = &gossipServiceImpl{
6375
gossip: gossip,
6476
chains: make(map[string]state.GossipStateProvider),
@@ -85,6 +97,7 @@ func (g *gossipServiceImpl) JoinChannel(commiter committer.Committer, block *com
8597
return err
8698
} else {
8799
// Initialize new state provider for given committer
100+
logger.Debug("Creating state provider for chainID", chainID)
88101
g.chains[chainID] = state.NewGossipStateProvider(g.gossip, commiter)
89102
}
90103

0 commit comments

Comments
 (0)