aboutsummaryrefslogtreecommitdiffstats
path: root/eth/peer.go
diff options
context:
space:
mode:
Diffstat (limited to 'eth/peer.go')
-rw-r--r--eth/peer.go28
1 files changed, 22 insertions, 6 deletions
diff --git a/eth/peer.go b/eth/peer.go
index 972880845..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,
@@ -86,6 +96,12 @@ func (p *peer) sendNewBlock(block *types.Block) error {
return p2p.Send(p.rw, NewBlockMsg, []interface{}{block, block.Td})
}
+func (p *peer) sendTransaction(tx *types.Transaction) error {
+ p.txHashes.Add(tx.Hash())
+
+ return p2p.Send(p.rw, TxMsg, []*types.Transaction{tx})
+}
+
func (p *peer) requestHashes(from common.Hash) error {
glog.V(logger.Debug).Infof("[%s] fetching hashes (%d) %x...\n", p.id, maxHashes, from[:4])
return p2p.Send(p.rw, GetBlockHashesMsg, getBlockHashesMsgData{from, maxHashes})
@@ -139,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
}