aboutsummaryrefslogtreecommitdiffstats
path: root/eth/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-24 20:40:32 +0800
committerobscuren <geffobscura@gmail.com>2015-04-24 20:40:32 +0800
commitb86e7526e12a5a49c1739ec02d3c1c5cc667dcb3 (patch)
tree5bbf718cd0bd4335b7b26e3bb320f1da7736c6da /eth/peer.go
parent9caf880ff93794f80122ee7272c050bf571efa61 (diff)
downloadgo-tangerine-b86e7526e12a5a49c1739ec02d3c1c5cc667dcb3.tar.gz
go-tangerine-b86e7526e12a5a49c1739ec02d3c1c5cc667dcb3.tar.zst
go-tangerine-b86e7526e12a5a49c1739ec02d3c1c5cc667dcb3.zip
eth, eth/downloader: moved peer selection to protocol handler
Diffstat (limited to 'eth/peer.go')
-rw-r--r--eth/peer.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/eth/peer.go b/eth/peer.go
index ec0c4b1f3..861efaaec 100644
--- a/eth/peer.go
+++ b/eth/peer.go
@@ -25,6 +25,16 @@ type getBlockHashesMsgData struct {
Amount uint64
}
+func getBestPeer(peers map[string]*peer) *peer {
+ var peer *peer
+ for _, cp := range peers {
+ if peer == nil || cp.td.Cmp(peer.td) > 0 {
+ peer = cp
+ }
+ }
+ return peer
+}
+
type peer struct {
*p2p.Peer
@@ -32,9 +42,9 @@ type peer struct {
protv, netid int
- currentHash common.Hash
- id string
- td *big.Int
+ recentHash common.Hash
+ id string
+ td *big.Int
genesis, ourHash common.Hash
ourTd *big.Int
@@ -43,14 +53,14 @@ type peer struct {
blockHashes *set.Set
}
-func newPeer(protv, netid int, genesis, currentHash common.Hash, td *big.Int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
+func newPeer(protv, netid int, genesis, recentHash common.Hash, td *big.Int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
id := p.ID()
return &peer{
Peer: p,
rw: rw,
genesis: genesis,
- ourHash: currentHash,
+ ourHash: recentHash,
ourTd: td,
protv: protv,
netid: netid,
@@ -145,7 +155,7 @@ func (p *peer) handleStatus() error {
// Set the total difficulty of the peer
p.td = status.TD
// set the best hash of the peer
- p.currentHash = status.CurrentBlock
+ p.recentHash = status.CurrentBlock
return <-errc
}