Skip to content

Commit

Permalink
[FAB-1879]Make gossip integrate core.yaml
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1879

Change-Id: I43258092a273d4702f6ee394e52ab5b8ceda5104
Signed-off-by: grapebaba <[email protected]>
  • Loading branch information
GrapeBaBa committed Feb 8, 2017
1 parent 78fcca0 commit 26a72ac
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
49 changes: 37 additions & 12 deletions gossip/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package integration

import (
"crypto/tls"
"strconv"
"strings"
"time"
Expand All @@ -30,29 +31,53 @@ 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)
if err != nil {
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,
}
}

Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions gossip/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
}
2 changes: 1 addition & 1 deletion peer/common/anchors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
28 changes: 28 additions & 0 deletions peer/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 26a72ac

Please sign in to comment.