@@ -19,6 +19,7 @@ package comm
19
19
import (
20
20
"bytes"
21
21
"crypto/tls"
22
+ "errors"
22
23
"fmt"
23
24
"math/rand"
24
25
"net"
@@ -33,6 +34,7 @@ import (
33
34
"github.com/hyperledger/fabric/gossip/util"
34
35
proto "github.com/hyperledger/fabric/protos/gossip"
35
36
"github.com/op/go-logging"
37
+ "github.com/spf13/viper"
36
38
"golang.org/x/net/context"
37
39
"google.golang.org/grpc"
38
40
"google.golang.org/grpc/credentials"
@@ -47,16 +49,15 @@ const (
47
49
sendOverflowErr = "Send buffer overflow"
48
50
)
49
51
50
- var errSendOverflow = fmt .Errorf (sendOverflowErr )
51
- var dialTimeout = defDialTimeout
52
+ var errSendOverflow = errors .New (sendOverflowErr )
52
53
53
54
func init () {
54
55
rand .Seed (42 )
55
56
}
56
57
57
58
// SetDialTimeout sets the dial timeout
58
59
func SetDialTimeout (timeout time.Duration ) {
59
- dialTimeout = timeout
60
+ viper . Set ( "peer.gossip. dialTimeout" , timeout )
60
61
}
61
62
62
63
func (c * commImpl ) SetDialOpts (opts ... grpc.DialOption ) {
@@ -75,7 +76,7 @@ func NewCommInstanceWithServer(port int, idMapper identity.Mapper, peerIdentity
75
76
var certHash []byte
76
77
77
78
if len (dialOpts ) == 0 {
78
- dialOpts = []grpc.DialOption {grpc .WithTimeout (dialTimeout )}
79
+ dialOpts = []grpc.DialOption {grpc .WithTimeout (util . GetDurationOrDefault ( "peer.gossip. dialTimeout" , defDialTimeout ) )}
79
80
}
80
81
81
82
if port > 0 {
@@ -168,7 +169,7 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
168
169
defer c .logger .Debug ("Exiting" )
169
170
170
171
if c .isStopping () {
171
- return nil , fmt . Errorf ("Stopping" )
172
+ return nil , errors . New ("Stopping" )
172
173
}
173
174
cc , err = grpc .Dial (endpoint , append (c .opts , grpc .WithBlock ())... )
174
175
if err != nil {
@@ -188,7 +189,7 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
188
189
if expectedPKIID != nil && ! bytes .Equal (pkiID , expectedPKIID ) {
189
190
// PKIID is nil when we don't know the remote PKI id's
190
191
c .logger .Warning ("Remote endpoint claims to be a different peer, expected" , expectedPKIID , "but got" , pkiID )
191
- return nil , fmt . Errorf ("Authentication failure" )
192
+ return nil , errors . New ("Authentication failure" )
192
193
}
193
194
conn := newConnection (cl , cc , stream , nil )
194
195
conn .pkiID = pkiID
@@ -275,7 +276,7 @@ func (c *commImpl) Probe(remotePeer *RemotePeer) error {
275
276
endpoint := remotePeer .Endpoint
276
277
pkiID := remotePeer .PKIID
277
278
if c .isStopping () {
278
- return fmt . Errorf ("Stopping" )
279
+ return errors . New ("Stopping" )
279
280
}
280
281
c .logger .Debug ("Entering, endpoint:" , endpoint , "PKIID:" , pkiID )
281
282
cc , err := grpc .Dial (remotePeer .Endpoint , append (c .opts , grpc .WithBlock ())... )
@@ -407,15 +408,15 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (common.PKIidType, erro
407
408
408
409
c .logger .Debug ("Sending" , cMsg , "to" , remoteAddress )
409
410
stream .Send (cMsg )
410
- m := readWithTimeout (stream , defConnTimeout )
411
+ m := readWithTimeout (stream , util . GetDurationOrDefault ( "peer.gossip.connTimeout" , defConnTimeout ) )
411
412
if m == nil {
412
413
c .logger .Warning ("Timed out waiting for connection message from" , remoteAddress )
413
- return nil , fmt . Errorf ("Timed out" )
414
+ return nil , errors . New ("Timed out" )
414
415
}
415
416
receivedMsg := m .GetConn ()
416
417
if receivedMsg == nil {
417
418
c .logger .Warning ("Expected connection message but got" , receivedMsg )
418
- return nil , fmt . Errorf ("Wrong type" )
419
+ return nil , errors . New ("Wrong type" )
419
420
}
420
421
421
422
if receivedMsg .PkiID == nil {
@@ -425,7 +426,7 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (common.PKIidType, erro
425
426
426
427
if c .isPKIblackListed (receivedMsg .PkiID ) {
427
428
c .logger .Warning ("Connection attempt from" , remoteAddress , "but it is black-listed" )
428
- return nil , fmt . Errorf ("Black-listed" )
429
+ return nil , errors . New ("Black-listed" )
429
430
}
430
431
c .logger .Debug ("Received" , receivedMsg , "from" , remoteAddress )
431
432
err = c .idMapper .Put (receivedMsg .PkiID , receivedMsg .Cert )
@@ -456,7 +457,7 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (common.PKIidType, erro
456
457
457
458
func (c * commImpl ) GossipStream (stream proto.Gossip_GossipStreamServer ) error {
458
459
if c .isStopping () {
459
- return fmt . Errorf ("Shutting down" )
460
+ return errors . New ("Shutting down" )
460
461
}
461
462
PKIID , err := c .authenticateRemotePeer (stream )
462
463
if err != nil {
@@ -573,7 +574,7 @@ func createGRPCLayer(port int) (*grpc.Server, net.Listener, grpc.DialOption, []b
573
574
}
574
575
575
576
if len (cert .Certificate ) == 0 {
576
- panic (fmt . Errorf ("Certificate chain is nil" ))
577
+ panic (errors . New ("Certificate chain is nil" ))
577
578
}
578
579
579
580
returnedCertHash = certHashFromRawCert (cert .Certificate [0 ])
0 commit comments