aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-24 20:16:04 +0800
committerobscuren <geffobscura@gmail.com>2014-07-24 20:16:04 +0800
commit702cf5a3e19e33616e7e98ec8ab7a00d56dd7e85 (patch)
treecf025478adbc2243a5b11d4c5e1dda7acf0d3086 /peer.go
parent92b16618edf6bbb6d98659050d8bf0d538285491 (diff)
parentdcf4fad97156f431612ed3915e167ce5a5314588 (diff)
downloadgo-tangerine-702cf5a3e19e33616e7e98ec8ab7a00d56dd7e85.tar.gz
go-tangerine-702cf5a3e19e33616e7e98ec8ab7a00d56dd7e85.tar.zst
go-tangerine-702cf5a3e19e33616e7e98ec8ab7a00d56dd7e85.zip
Merge branch 'feature/refactor_vm' into develop
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go64
1 files changed, 34 insertions, 30 deletions
diff --git a/peer.go b/peer.go
index 89032364e..c73617ed5 100644
--- a/peer.go
+++ b/peer.go
@@ -122,9 +122,6 @@ type Peer struct {
// Last received pong message
lastPong int64
- // Indicates whether a MsgGetPeersTy was requested of the peer
- // this to prevent receiving false peers.
- requestedPeerList bool
host []byte
port uint16
@@ -180,10 +177,9 @@ 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() {
- conn, err := net.DialTimeout("tcp", addr, 10*time.Second)
-
+ conn, err := p.Connect(addr)
if err != nil {
- peerlogger.Debugln("Connection to peer failed", err)
+ peerlogger.Debugln("Connection to peer failed. Giving up.", err)
p.Stop()
return
}
@@ -199,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()
@@ -463,30 +474,21 @@ func (p *Peer) HandleInbound() {
p.ethereum.TxPool().QueueTransaction(tx)
}
case ethwire.MsgGetPeersTy:
- // Flag this peer as a 'requested of new peers' this to
- // prevent malicious peers being forced.
- p.requestedPeerList = true
// Peer asked for list of connected peers
p.pushPeers()
case ethwire.MsgPeersTy:
// Received a list of peers (probably because MsgGetPeersTy was send)
- // Only act on message if we actually requested for a peers list
- if p.requestedPeerList {
- data := msg.Data
- // Create new list of possible peers for the ethereum to process
- peers := make([]string, data.Len())
- // Parse each possible peer
- for i := 0; i < data.Len(); i++ {
- value := data.Get(i)
- peers[i] = unpackAddr(value.Get(0), value.Get(1).Uint())
- }
-
- // Connect to the list of peers
- p.ethereum.ProcessPeerList(peers)
- // Mark unrequested again
- p.requestedPeerList = false
-
+ data := msg.Data
+ // Create new list of possible peers for the ethereum to process
+ peers := make([]string, data.Len())
+ // Parse each possible peer
+ for i := 0; i < data.Len(); i++ {
+ value := data.Get(i)
+ peers[i] = unpackAddr(value.Get(0), value.Get(1).Uint())
}
+
+ // Connect to the list of peers
+ p.ethereum.ProcessPeerList(peers)
case ethwire.MsgGetChainTy:
var parent *ethchain.Block
// Length minus one since the very last element in the array is a count
@@ -698,11 +700,13 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
ethlogger.Infof("Added peer (%s) %d / %d\n", p.conn.RemoteAddr(), p.ethereum.Peers().Len(), p.ethereum.MaxPeers)
- // Catch up with the connected peer
- if !p.ethereum.IsUpToDate() {
- peerlogger.Debugln("Already syncing up with a peer; sleeping")
- time.Sleep(10 * time.Second)
- }
+ /*
+ // Catch up with the connected peer
+ if !p.ethereum.IsUpToDate() {
+ peerlogger.Debugln("Already syncing up with a peer; sleeping")
+ time.Sleep(10 * time.Second)
+ }
+ */
p.SyncWithPeerToLastKnown()
peerlogger.Debugln(p)