|
|
@ -2,7 +2,6 @@ package eth |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"container/list" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"github.com/ethereum/eth-go/ethchain" |
|
|
|
"github.com/ethereum/eth-go/ethchain" |
|
|
|
"github.com/ethereum/eth-go/ethutil" |
|
|
|
"github.com/ethereum/eth-go/ethutil" |
|
|
@ -440,7 +439,7 @@ func (p *Peer) HandleInbound() { |
|
|
|
ethutil.Config.Log.Debugf("[PEER] Found canonical block, returning chain from: %x ", parent.Hash()) |
|
|
|
ethutil.Config.Log.Debugf("[PEER] Found canonical block, returning chain from: %x ", parent.Hash()) |
|
|
|
chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks) |
|
|
|
chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks) |
|
|
|
if len(chain) > 0 { |
|
|
|
if len(chain) > 0 { |
|
|
|
ethutil.Config.Log.Debugf("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash()) |
|
|
|
//ethutil.Config.Log.Debugf("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash())
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, chain)) |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, chain)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, []interface{}{})) |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, []interface{}{})) |
|
|
@ -450,10 +449,12 @@ func (p *Peer) HandleInbound() { |
|
|
|
//ethutil.Config.Log.Debugf("[PEER] Could not find a similar block")
|
|
|
|
//ethutil.Config.Log.Debugf("[PEER] Could not find a similar block")
|
|
|
|
// If no blocks are found we send back a reply with msg not in chain
|
|
|
|
// If no blocks are found we send back a reply with msg not in chain
|
|
|
|
// and the last hash from get chain
|
|
|
|
// and the last hash from get chain
|
|
|
|
|
|
|
|
if l > 0 { |
|
|
|
lastHash := msg.Data.Get(l - 1) |
|
|
|
lastHash := msg.Data.Get(l - 1) |
|
|
|
//log.Printf("Sending not in chain with hash %x\n", lastHash.AsRaw())
|
|
|
|
//log.Printf("Sending not in chain with hash %x\n", lastHash.AsRaw())
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()})) |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
case ethwire.MsgNotInChainTy: |
|
|
|
case ethwire.MsgNotInChainTy: |
|
|
|
ethutil.Config.Log.Debugf("Not in chain: %x\n", msg.Data.Get(0).Bytes()) |
|
|
|
ethutil.Config.Log.Debugf("Not in chain: %x\n", msg.Data.Get(0).Bytes()) |
|
|
|
if p.diverted == true { |
|
|
|
if p.diverted == true { |
|
|
@ -521,13 +522,7 @@ func (p *Peer) Stop() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Pre-emptively remove the peer; don't wait for reaping. We already know it's dead if we are here
|
|
|
|
// Pre-emptively remove the peer; don't wait for reaping. We already know it's dead if we are here
|
|
|
|
p.ethereum.peerMut.Lock() |
|
|
|
p.ethereum.RemovePeer(p) |
|
|
|
defer p.ethereum.peerMut.Unlock() |
|
|
|
|
|
|
|
eachPeer(p.ethereum.peers, func(peer *Peer, e *list.Element) { |
|
|
|
|
|
|
|
if peer == p { |
|
|
|
|
|
|
|
p.ethereum.peers.Remove(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p *Peer) pushHandshake() error { |
|
|
|
func (p *Peer) pushHandshake() error { |
|
|
|