|
|
@ -87,14 +87,13 @@ func newPeer(pc peerConn, nodeInfo NodeInfo, |
|
|
|
type PeerConfig struct { |
|
|
|
AuthEnc bool `mapstructure:"auth_enc"` // authenticated encryption
|
|
|
|
|
|
|
|
Dial func(addr *NetAddress, config *PeerConfig) (net.Conn, error) |
|
|
|
|
|
|
|
// times are in seconds
|
|
|
|
HandshakeTimeout time.Duration `mapstructure:"handshake_timeout"` |
|
|
|
DialTimeout time.Duration `mapstructure:"dial_timeout"` |
|
|
|
|
|
|
|
MConfig *tmconn.MConnConfig `mapstructure:"connection"` |
|
|
|
|
|
|
|
Fail bool `mapstructure:"fail"` // for testing
|
|
|
|
Fuzz bool `mapstructure:"fuzz"` // fuzz connection (for testing)
|
|
|
|
FuzzConfig *FuzzConnConfig `mapstructure:"fuzz_config"` |
|
|
|
} |
|
|
@ -103,10 +102,10 @@ type PeerConfig struct { |
|
|
|
func DefaultPeerConfig() *PeerConfig { |
|
|
|
return &PeerConfig{ |
|
|
|
AuthEnc: true, |
|
|
|
Dial: dial, |
|
|
|
HandshakeTimeout: 20, // * time.Second,
|
|
|
|
DialTimeout: 3, // * time.Second,
|
|
|
|
MConfig: tmconn.DefaultMConnConfig(), |
|
|
|
Fail: false, |
|
|
|
Fuzz: false, |
|
|
|
FuzzConfig: DefaultFuzzConnConfig(), |
|
|
|
} |
|
|
@ -115,7 +114,7 @@ func DefaultPeerConfig() *PeerConfig { |
|
|
|
func newOutboundPeerConn(addr *NetAddress, config *PeerConfig, persistent bool, ourNodePrivKey crypto.PrivKey) (peerConn, error) { |
|
|
|
var pc peerConn |
|
|
|
|
|
|
|
conn, err := config.Dial(addr, config) |
|
|
|
conn, err := dial(addr, config) |
|
|
|
if err != nil { |
|
|
|
return pc, errors.Wrap(err, "Error creating peer") |
|
|
|
} |
|
|
@ -347,7 +346,7 @@ func (p *peer) String() string { |
|
|
|
//------------------------------------------------------------------
|
|
|
|
// helper funcs
|
|
|
|
|
|
|
|
func dial(addr *NetAddress, config *PeerConfig) (net.Conn, error) { |
|
|
|
var dial = func(addr *NetAddress, config *PeerConfig) (net.Conn, error) { |
|
|
|
conn, err := addr.DialTimeout(config.DialTimeout * time.Second) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|