|
|
@ -24,7 +24,7 @@ const ( |
|
|
|
// The size of the output buffer for writing messages
|
|
|
|
// The size of the output buffer for writing messages
|
|
|
|
outputBufferSize = 50 |
|
|
|
outputBufferSize = 50 |
|
|
|
// Current protocol version
|
|
|
|
// Current protocol version
|
|
|
|
ProtocolVersion = 47 |
|
|
|
ProtocolVersion = 48 |
|
|
|
// Current P2P version
|
|
|
|
// Current P2P version
|
|
|
|
P2PVersion = 2 |
|
|
|
P2PVersion = 2 |
|
|
|
// Ethereum network version
|
|
|
|
// Ethereum network version
|
|
|
@ -132,6 +132,8 @@ type Peer struct { |
|
|
|
lastPong int64 |
|
|
|
lastPong int64 |
|
|
|
lastBlockReceived time.Time |
|
|
|
lastBlockReceived time.Time |
|
|
|
doneFetchingHashes bool |
|
|
|
doneFetchingHashes bool |
|
|
|
|
|
|
|
lastHashAt time.Time |
|
|
|
|
|
|
|
lastHashRequestedAt time.Time |
|
|
|
|
|
|
|
|
|
|
|
host []byte |
|
|
|
host []byte |
|
|
|
port uint16 |
|
|
|
port uint16 |
|
|
@ -327,19 +329,16 @@ out: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch msg.Type { |
|
|
|
|
|
|
|
case wire.MsgGetBlockHashesTy: |
|
|
|
|
|
|
|
p.lastHashRequestedAt = time.Now() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p.writeMessage(msg) |
|
|
|
p.writeMessage(msg) |
|
|
|
p.lastSend = time.Now() |
|
|
|
p.lastSend = time.Now() |
|
|
|
|
|
|
|
|
|
|
|
// Ping timer
|
|
|
|
// Ping timer
|
|
|
|
case <-pingTimer.C: |
|
|
|
case <-pingTimer.C: |
|
|
|
/* |
|
|
|
|
|
|
|
timeSince := time.Since(time.Unix(p.lastPong, 0)) |
|
|
|
|
|
|
|
if !p.pingStartTime.IsZero() && p.lastPong != 0 && timeSince > (pingPongTimer+30*time.Second) { |
|
|
|
|
|
|
|
peerlogger.Infof("Peer did not respond to latest pong fast enough, it took %s, disconnecting.\n", timeSince) |
|
|
|
|
|
|
|
p.Stop() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
p.writeMessage(wire.NewMessage(wire.MsgPingTy, "")) |
|
|
|
p.writeMessage(wire.NewMessage(wire.MsgPingTy, "")) |
|
|
|
p.pingStartTime = time.Now() |
|
|
|
p.pingStartTime = time.Now() |
|
|
|
|
|
|
|
|
|
|
@ -462,18 +461,6 @@ func (p *Peer) HandleInbound() { |
|
|
|
// TMP
|
|
|
|
// TMP
|
|
|
|
if p.statusKnown { |
|
|
|
if p.statusKnown { |
|
|
|
switch msg.Type { |
|
|
|
switch msg.Type { |
|
|
|
/* |
|
|
|
|
|
|
|
case wire.MsgGetTxsTy: |
|
|
|
|
|
|
|
// Get the current transactions of the pool
|
|
|
|
|
|
|
|
txs := p.ethereum.TxPool().CurrentTransactions() |
|
|
|
|
|
|
|
// Get the RlpData values from the txs
|
|
|
|
|
|
|
|
txsInterface := make([]interface{}, len(txs)) |
|
|
|
|
|
|
|
for i, tx := range txs { |
|
|
|
|
|
|
|
txsInterface[i] = tx.RlpData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Broadcast it back to the peer
|
|
|
|
|
|
|
|
p.QueueMessage(wire.NewMessage(wire.MsgTxTy, txsInterface)) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case wire.MsgGetBlockHashesTy: |
|
|
|
case wire.MsgGetBlockHashesTy: |
|
|
|
if msg.Data.Len() < 2 { |
|
|
|
if msg.Data.Len() < 2 { |
|
|
@ -508,6 +495,7 @@ func (p *Peer) HandleInbound() { |
|
|
|
blockPool := p.ethereum.blockPool |
|
|
|
blockPool := p.ethereum.blockPool |
|
|
|
|
|
|
|
|
|
|
|
foundCommonHash := false |
|
|
|
foundCommonHash := false |
|
|
|
|
|
|
|
p.lastHashAt = time.Now() |
|
|
|
|
|
|
|
|
|
|
|
it := msg.Data.NewIterator() |
|
|
|
it := msg.Data.NewIterator() |
|
|
|
for it.Next() { |
|
|
|
for it.Next() { |
|
|
@ -524,9 +512,6 @@ func (p *Peer) HandleInbound() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !foundCommonHash { |
|
|
|
if !foundCommonHash { |
|
|
|
//if !p.FetchHashes() {
|
|
|
|
|
|
|
|
// p.doneFetchingHashes = true
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
p.FetchHashes() |
|
|
|
p.FetchHashes() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
peerlogger.Infof("Found common hash (%x...)\n", p.lastReceivedHash[0:4]) |
|
|
|
peerlogger.Infof("Found common hash (%x...)\n", p.lastReceivedHash[0:4]) |
|
|
|