Skip to content

Commit 26a72ac

Browse files
committed
[FAB-1879]Make gossip integrate core.yaml
https://jira.hyperledger.org/browse/FAB-1879 Change-Id: I43258092a273d4702f6ee394e52ab5b8ceda5104 Signed-off-by: grapebaba <[email protected]>
1 parent 78fcca0 commit 26a72ac

File tree

4 files changed

+81
-13
lines changed

4 files changed

+81
-13
lines changed

gossip/integration/integration.go

+37-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package integration
1818

1919
import (
20+
"crypto/tls"
2021
"strconv"
2122
"strings"
2223
"time"
@@ -30,29 +31,53 @@ import (
3031
"google.golang.org/grpc"
3132
)
3233

33-
// This file is used to bootstrap a gossip instance for integration/demo purposes ONLY
34+
func getIntOrDefault(key string, defVal int) int {
35+
if viper.GetInt(key) == 0 {
36+
return defVal
37+
} else {
38+
return viper.GetInt(key)
39+
}
40+
}
41+
42+
func getDurationOrDefault(key string, defVal time.Duration) time.Duration {
43+
if viper.GetDuration(key) == 0 {
44+
return defVal
45+
} else {
46+
return viper.GetDuration(key)
47+
}
48+
}
3449

3550
func newConfig(selfEndpoint string, bootPeers ...string) *gossip.Config {
3651
port, err := strconv.ParseInt(strings.Split(selfEndpoint, ":")[1], 10, 64)
3752
if err != nil {
3853
panic(err)
3954
}
4055

56+
var cert *tls.Certificate
57+
if viper.GetBool("peer.tls.enabled") {
58+
*cert, err = tls.LoadX509KeyPair(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
59+
if err != nil {
60+
panic(err)
61+
}
62+
}
63+
4164
return &gossip.Config{
4265
BindPort: int(port),
4366
BootstrapPeers: bootPeers,
4467
ID: selfEndpoint,
45-
MaxBlockCountToStore: 100,
46-
MaxPropagationBurstLatency: time.Duration(10) * time.Millisecond,
47-
MaxPropagationBurstSize: 10,
48-
PropagateIterations: 1,
49-
PropagatePeerNum: 3,
50-
PullInterval: time.Duration(4) * time.Second,
51-
PullPeerNum: 3,
68+
MaxBlockCountToStore: getIntOrDefault("peer.gossip.maxBlockCountToStore", 100),
69+
MaxPropagationBurstLatency: getDurationOrDefault("peer.gossip.maxPropagationBurstLatency", 10*time.Millisecond),
70+
MaxPropagationBurstSize: getIntOrDefault("peer.gossip.maxPropagationBurstSize", 10),
71+
PropagateIterations: getIntOrDefault("peer.gossip.propagateIterations", 1),
72+
PropagatePeerNum: getIntOrDefault("peer.gossip.propagatePeerNum", 3),
73+
PullInterval: getDurationOrDefault("peer.gossip.pullInterval", 4*time.Second),
74+
PullPeerNum: getIntOrDefault("peer.gossip.pullPeerNum", 3),
5275
SelfEndpoint: selfEndpoint,
53-
PublishCertPeriod: 10 * time.Second,
54-
RequestStateInfoInterval: 4 * time.Second,
55-
PublishStateInfoInterval: 4 * time.Second,
76+
PublishCertPeriod: getDurationOrDefault("peer.gossip.publishCertPeriod", 10*time.Second),
77+
RequestStateInfoInterval: getDurationOrDefault("peer.gossip.requestStateInfoInterval", 4*time.Second),
78+
PublishStateInfoInterval: getDurationOrDefault("peer.gossip.publishStateInfoInterval", 4*time.Second),
79+
SkipBlockVerification: viper.GetBool("peer.gossip.skipBlockVerification"),
80+
TLSServerCert: cert,
5681
}
5782
}
5883

@@ -66,7 +91,7 @@ func NewGossipComponent(identity []byte, endpoint string, s *grpc.Server, dialOp
6691
cryptSvc := mcs.NewMessageCryptoService()
6792
secAdv := sa.NewSecurityAdvisor()
6893

69-
if viper.GetBool("peer.gossip.ignoresecurity") {
94+
if viper.GetBool("peer.gossip.ignoreSecurity") {
7095
sec := &secImpl{[]byte(endpoint)}
7196
cryptSvc = sec
7297
secAdv = sec

gossip/integration/integration_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ package integration
1919
import (
2020
"fmt"
2121
"net"
22+
"strings"
2223
"testing"
2324
"time"
2425

2526
"github.com/hyperledger/fabric/msp/mgmt"
27+
"github.com/spf13/viper"
2628
"google.golang.org/grpc"
2729
)
2830

2931
// This is just a test that shows how to instantiate a gossip component
3032
func TestNewGossipCryptoService(t *testing.T) {
33+
setupTestEnv()
3134
s1 := grpc.NewServer()
3235
s2 := grpc.NewServer()
3336
s3 := grpc.NewServer()
@@ -56,3 +59,15 @@ func TestNewGossipCryptoService(t *testing.T) {
5659
fmt.Println(g3.Peers())
5760
time.Sleep(time.Second)
5861
}
62+
63+
func setupTestEnv() {
64+
viper.SetConfigName("core")
65+
viper.SetEnvPrefix("CORE")
66+
viper.AddConfigPath("./../../peer")
67+
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
68+
viper.AutomaticEnv()
69+
err := viper.ReadInConfig()
70+
if err != nil { // Handle errors reading the config file
71+
panic(fmt.Errorf("Fatal error config file: %s \n", err))
72+
}
73+
}

peer/common/anchors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func anchorPeerFromFile(filename string) (*peer.AnchorPeer, error) {
128128
Cert: identity,
129129
}
130130

131-
if viper.GetBool("peer.gossip.ignoresecurity") {
131+
if viper.GetBool("peer.gossip.ignoreSecurity") {
132132
ap.Cert = []byte(fmt.Sprintf("%s:%d", ap.Host, ap.Port))
133133
}
134134

peer/core.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,34 @@ peer:
7272
bootstrap: 0.0.0.0:7051
7373
# For debug - is peer is its org leader and should pass blocks from orderer to other peers in org
7474
orgLeader: true
75+
# ID of this instance
76+
endpoint:
77+
# Maximum count of blocks we store in memory
78+
maxBlockCountToStore: 100
79+
# Max time between consecutive message pushes(unit: millisecond)
80+
maxPropagationBurstLatency: 10ms
81+
# Max number of messages stored until it triggers a push to remote peers
82+
maxPropagationBurstSize: 10
83+
# Number of times a message is pushed to remote peers
84+
propagateIterations: 1
85+
# Number of peers selected to push messages to
86+
propagatePeerNum: 3
87+
# Determines frequency of pull phases(unit: second)
88+
pullInterval: 4s
89+
# Number of peers to pull from
90+
pullPeerNum: 3
91+
# Determines frequency of pulling state info messages from peers(unit: second)
92+
requestStateInfoInterval: 4s
93+
# Determines frequency of pushing state info messages to peers(unit: second)
94+
publishStateInfoInterval: 4s
95+
# Maximum time a stateInfo message is kept until expired
96+
stateInfoRetentionInterval:
97+
# Time from startup certificates are included in Alive messages(unit: second)
98+
publishCertPeriod: 10s
99+
# Should we skip verifying block messages or not
100+
skipBlockVerification: false
101+
# Should we ignore security or not
102+
ignoreSecurity: false
75103

76104
# Sync related configuration
77105
sync:

0 commit comments

Comments
 (0)