diff --git a/gossip/integration/integration.go b/gossip/integration/integration.go index b6655521605..a038cb0907b 100644 --- a/gossip/integration/integration.go +++ b/gossip/integration/integration.go @@ -17,6 +17,7 @@ limitations under the License. package integration import ( + "crypto/tls" "strconv" "strings" "time" @@ -30,7 +31,21 @@ import ( "google.golang.org/grpc" ) -// This file is used to bootstrap a gossip instance for integration/demo purposes ONLY +func getIntOrDefault(key string, defVal int) int { + if viper.GetInt(key) == 0 { + return defVal + } else { + return viper.GetInt(key) + } +} + +func getDurationOrDefault(key string, defVal time.Duration) time.Duration { + if viper.GetDuration(key) == 0 { + return defVal + } else { + return viper.GetDuration(key) + } +} func newConfig(selfEndpoint string, bootPeers ...string) *gossip.Config { port, err := strconv.ParseInt(strings.Split(selfEndpoint, ":")[1], 10, 64) @@ -38,21 +53,31 @@ func newConfig(selfEndpoint string, bootPeers ...string) *gossip.Config { panic(err) } + var cert *tls.Certificate + if viper.GetBool("peer.tls.enabled") { + *cert, err = tls.LoadX509KeyPair(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file")) + if err != nil { + panic(err) + } + } + return &gossip.Config{ BindPort: int(port), BootstrapPeers: bootPeers, ID: selfEndpoint, - MaxBlockCountToStore: 100, - MaxPropagationBurstLatency: time.Duration(10) * time.Millisecond, - MaxPropagationBurstSize: 10, - PropagateIterations: 1, - PropagatePeerNum: 3, - PullInterval: time.Duration(4) * time.Second, - PullPeerNum: 3, + MaxBlockCountToStore: getIntOrDefault("peer.gossip.maxBlockCountToStore", 100), + MaxPropagationBurstLatency: getDurationOrDefault("peer.gossip.maxPropagationBurstLatency", 10*time.Millisecond), + MaxPropagationBurstSize: getIntOrDefault("peer.gossip.maxPropagationBurstSize", 10), + PropagateIterations: getIntOrDefault("peer.gossip.propagateIterations", 1), + PropagatePeerNum: getIntOrDefault("peer.gossip.propagatePeerNum", 3), + PullInterval: getDurationOrDefault("peer.gossip.pullInterval", 4*time.Second), + PullPeerNum: getIntOrDefault("peer.gossip.pullPeerNum", 3), SelfEndpoint: selfEndpoint, - PublishCertPeriod: 10 * time.Second, - RequestStateInfoInterval: 4 * time.Second, - PublishStateInfoInterval: 4 * time.Second, + PublishCertPeriod: getDurationOrDefault("peer.gossip.publishCertPeriod", 10*time.Second), + RequestStateInfoInterval: getDurationOrDefault("peer.gossip.requestStateInfoInterval", 4*time.Second), + PublishStateInfoInterval: getDurationOrDefault("peer.gossip.publishStateInfoInterval", 4*time.Second), + SkipBlockVerification: viper.GetBool("peer.gossip.skipBlockVerification"), + TLSServerCert: cert, } } @@ -66,7 +91,7 @@ func NewGossipComponent(identity []byte, endpoint string, s *grpc.Server, dialOp cryptSvc := mcs.NewMessageCryptoService() secAdv := sa.NewSecurityAdvisor() - if viper.GetBool("peer.gossip.ignoresecurity") { + if viper.GetBool("peer.gossip.ignoreSecurity") { sec := &secImpl{[]byte(endpoint)} cryptSvc = sec secAdv = sec diff --git a/gossip/integration/integration_test.go b/gossip/integration/integration_test.go index 2e18f99c3cc..5245e47b837 100644 --- a/gossip/integration/integration_test.go +++ b/gossip/integration/integration_test.go @@ -19,15 +19,18 @@ package integration import ( "fmt" "net" + "strings" "testing" "time" "github.com/hyperledger/fabric/msp/mgmt" + "github.com/spf13/viper" "google.golang.org/grpc" ) // This is just a test that shows how to instantiate a gossip component func TestNewGossipCryptoService(t *testing.T) { + setupTestEnv() s1 := grpc.NewServer() s2 := grpc.NewServer() s3 := grpc.NewServer() @@ -56,3 +59,15 @@ func TestNewGossipCryptoService(t *testing.T) { fmt.Println(g3.Peers()) time.Sleep(time.Second) } + +func setupTestEnv() { + viper.SetConfigName("core") + viper.SetEnvPrefix("CORE") + viper.AddConfigPath("./../../peer") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() + err := viper.ReadInConfig() + if err != nil { // Handle errors reading the config file + panic(fmt.Errorf("Fatal error config file: %s \n", err)) + } +} diff --git a/peer/common/anchors.go b/peer/common/anchors.go index cb500624ada..cb71d167e30 100644 --- a/peer/common/anchors.go +++ b/peer/common/anchors.go @@ -128,7 +128,7 @@ func anchorPeerFromFile(filename string) (*peer.AnchorPeer, error) { Cert: identity, } - if viper.GetBool("peer.gossip.ignoresecurity") { + if viper.GetBool("peer.gossip.ignoreSecurity") { ap.Cert = []byte(fmt.Sprintf("%s:%d", ap.Host, ap.Port)) } diff --git a/peer/core.yaml b/peer/core.yaml index cd9ed936ade..94585acc85e 100644 --- a/peer/core.yaml +++ b/peer/core.yaml @@ -72,6 +72,34 @@ peer: bootstrap: 0.0.0.0:7051 # For debug - is peer is its org leader and should pass blocks from orderer to other peers in org orgLeader: true + # ID of this instance + endpoint: + # Maximum count of blocks we store in memory + maxBlockCountToStore: 100 + # Max time between consecutive message pushes(unit: millisecond) + maxPropagationBurstLatency: 10ms + # Max number of messages stored until it triggers a push to remote peers + maxPropagationBurstSize: 10 + # Number of times a message is pushed to remote peers + propagateIterations: 1 + # Number of peers selected to push messages to + propagatePeerNum: 3 + # Determines frequency of pull phases(unit: second) + pullInterval: 4s + # Number of peers to pull from + pullPeerNum: 3 + # Determines frequency of pulling state info messages from peers(unit: second) + requestStateInfoInterval: 4s + # Determines frequency of pushing state info messages to peers(unit: second) + publishStateInfoInterval: 4s + # Maximum time a stateInfo message is kept until expired + stateInfoRetentionInterval: + # Time from startup certificates are included in Alive messages(unit: second) + publishCertPeriod: 10s + # Should we skip verifying block messages or not + skipBlockVerification: false + # Should we ignore security or not + ignoreSecurity: false # Sync related configuration sync: