@@ -17,6 +17,7 @@ limitations under the License.
17
17
package integration
18
18
19
19
import (
20
+ "crypto/tls"
20
21
"strconv"
21
22
"strings"
22
23
"time"
@@ -30,29 +31,53 @@ import (
30
31
"google.golang.org/grpc"
31
32
)
32
33
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
+ }
34
49
35
50
func newConfig (selfEndpoint string , bootPeers ... string ) * gossip.Config {
36
51
port , err := strconv .ParseInt (strings .Split (selfEndpoint , ":" )[1 ], 10 , 64 )
37
52
if err != nil {
38
53
panic (err )
39
54
}
40
55
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
+
41
64
return & gossip.Config {
42
65
BindPort : int (port ),
43
66
BootstrapPeers : bootPeers ,
44
67
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 ) ,
52
75
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 ,
56
81
}
57
82
}
58
83
@@ -66,7 +91,7 @@ func NewGossipComponent(identity []byte, endpoint string, s *grpc.Server, dialOp
66
91
cryptSvc := mcs .NewMessageCryptoService ()
67
92
secAdv := sa .NewSecurityAdvisor ()
68
93
69
- if viper .GetBool ("peer.gossip.ignoresecurity " ) {
94
+ if viper .GetBool ("peer.gossip.ignoreSecurity " ) {
70
95
sec := & secImpl {[]byte (endpoint )}
71
96
cryptSvc = sec
72
97
secAdv = sec
0 commit comments