diff options
author | obscuren <geffobscura@gmail.com> | 2014-07-24 18:30:04 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-07-24 18:30:04 +0800 |
commit | dcf4fad97156f431612ed3915e167ce5a5314588 (patch) | |
tree | cf025478adbc2243a5b11d4c5e1dda7acf0d3086 | |
parent | 6d69ca36a755ea44e7ce4ba7b135afb0b9dbff05 (diff) | |
download | dexon-dcf4fad97156f431612ed3915e167ce5a5314588.tar dexon-dcf4fad97156f431612ed3915e167ce5a5314588.tar.gz dexon-dcf4fad97156f431612ed3915e167ce5a5314588.tar.bz2 dexon-dcf4fad97156f431612ed3915e167ce5a5314588.tar.lz dexon-dcf4fad97156f431612ed3915e167ce5a5314588.tar.xz dexon-dcf4fad97156f431612ed3915e167ce5a5314588.tar.zst dexon-dcf4fad97156f431612ed3915e167ce5a5314588.zip |
Networking code
-rw-r--r-- | peer.go | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -177,18 +177,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer { // Set up the connection in another goroutine so we don't block the main thread go func() { - var ( - err error - conn net.Conn - ) - - for attempts := 0; attempts < 5; attempts++ { - conn, err = net.DialTimeout("tcp", addr, 10*time.Second) - if err != nil { - peerlogger.Debugf("Peer connection failed. Retrying (%d/5)\n", attempts+1) - } - } - + conn, err := p.Connect(addr) if err != nil { peerlogger.Debugln("Connection to peer failed. Giving up.", err) p.Stop() @@ -206,6 +195,21 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer { return p } +func (self *Peer) Connect(addr string) (conn net.Conn, err error) { + for attempts := 0; attempts < 5; attempts++ { + conn, err = net.DialTimeout("tcp", addr, 10*time.Second) + if err != nil { + peerlogger.Debugf("Peer connection failed. Retrying (%d/5)\n", attempts+1) + continue + } + + // Success + return + } + + return +} + // Getters func (p *Peer) PingTime() string { return p.pingTime.String() |