Skip to content

Commit

Permalink
Gossip service setup TLS
Browse files Browse the repository at this point in the history
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 <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Dec 26, 2016
1 parent 43f4e57 commit c26669d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package service
import (
"sync"

peerComm "github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/core/committer"
"github.com/hyperledger/fabric/gossip/comm"
gossipCommon "github.com/hyperledger/fabric/gossip/common"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/hyperledger/fabric/gossip/state"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
"github.com/op/go-logging"
"google.golang.org/grpc"
)

Expand All @@ -55,10 +57,20 @@ type gossipServiceImpl struct {
lock sync.RWMutex
}

var logger = logging.MustGetLogger("gossipService")

// InitGossipService initialize gossip service
func InitGossipService(endpoint string, s *grpc.Server, bootPeers ...string) {
once.Do(func() {
gossip := integration.NewGossipComponent(endpoint, s, []grpc.DialOption{}, bootPeers...)
logger.Info("Initialize gossip with endpoint", endpoint, "and bootstrap set", bootPeers)
dialOpts := []grpc.DialOption{}
if peerComm.TLSEnabled() {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(peerComm.InitTLSForPeer()))
} else {
dialOpts = append(dialOpts, grpc.WithInsecure())
}

gossip := integration.NewGossipComponent(endpoint, s, dialOpts, bootPeers...)
gossipServiceInstance = &gossipServiceImpl{
gossip: gossip,
chains: make(map[string]state.GossipStateProvider),
Expand All @@ -85,6 +97,7 @@ func (g *gossipServiceImpl) JoinChannel(commiter committer.Committer, block *com
return err
} else {
// Initialize new state provider for given committer
logger.Debug("Creating state provider for chainID", chainID)
g.chains[chainID] = state.NewGossipStateProvider(g.gossip, commiter)
}

Expand Down

0 comments on commit c26669d

Please sign in to comment.