|
|
@ -122,6 +122,7 @@ type Peer struct { |
|
|
|
|
|
|
|
|
|
|
|
// Last received pong message
|
|
|
|
// Last received pong message
|
|
|
|
lastPong int64 |
|
|
|
lastPong int64 |
|
|
|
|
|
|
|
lastBlockReceived time.Time |
|
|
|
|
|
|
|
|
|
|
|
host []byte |
|
|
|
host []byte |
|
|
|
port uint16 |
|
|
|
port uint16 |
|
|
@ -408,10 +409,7 @@ func (p *Peer) HandleInbound() { |
|
|
|
for i := msg.Data.Len() - 1; i >= 0; i-- { |
|
|
|
for i := msg.Data.Len() - 1; i >= 0; i-- { |
|
|
|
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i)) |
|
|
|
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i)) |
|
|
|
|
|
|
|
|
|
|
|
//p.ethereum.StateManager().PrepareDefault(block)
|
|
|
|
|
|
|
|
//state := p.ethereum.StateManager().CurrentState()
|
|
|
|
|
|
|
|
err = p.ethereum.StateManager().Process(block, false) |
|
|
|
err = p.ethereum.StateManager().Process(block, false) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if ethutil.Config.Debug { |
|
|
|
if ethutil.Config.Debug { |
|
|
|
peerlogger.Infof("Block %x failed\n", block.Hash()) |
|
|
|
peerlogger.Infof("Block %x failed\n", block.Hash()) |
|
|
@ -422,6 +420,8 @@ func (p *Peer) HandleInbound() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
lastBlock = block |
|
|
|
lastBlock = block |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.lastBlockReceived = time.Now() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if msg.Data.Len() <= 1 { |
|
|
|
if msg.Data.Len() <= 1 { |
|
|
@ -561,6 +561,25 @@ func (p *Peer) HandleInbound() { |
|
|
|
p.Stop() |
|
|
|
p.Stop() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// General update method
|
|
|
|
|
|
|
|
func (self *Peer) update() { |
|
|
|
|
|
|
|
serviceTimer := time.NewTicker(5 * time.Second) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out: |
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
case <-serviceTimer.C: |
|
|
|
|
|
|
|
if time.Since(self.lastBlockReceived) > 10*time.Second { |
|
|
|
|
|
|
|
self.catchingUp = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case <-self.quit: |
|
|
|
|
|
|
|
break out |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serviceTimer.Stop() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p *Peer) Start() { |
|
|
|
func (p *Peer) Start() { |
|
|
|
peerHost, peerPort, _ := net.SplitHostPort(p.conn.LocalAddr().String()) |
|
|
|
peerHost, peerPort, _ := net.SplitHostPort(p.conn.LocalAddr().String()) |
|
|
|
servHost, servPort, _ := net.SplitHostPort(p.conn.RemoteAddr().String()) |
|
|
|
servHost, servPort, _ := net.SplitHostPort(p.conn.RemoteAddr().String()) |
|
|
@ -583,6 +602,8 @@ func (p *Peer) Start() { |
|
|
|
go p.HandleOutbound() |
|
|
|
go p.HandleOutbound() |
|
|
|
// Run the inbound handler in a new goroutine
|
|
|
|
// Run the inbound handler in a new goroutine
|
|
|
|
go p.HandleInbound() |
|
|
|
go p.HandleInbound() |
|
|
|
|
|
|
|
// Run the general update handler
|
|
|
|
|
|
|
|
go p.update() |
|
|
|
|
|
|
|
|
|
|
|
// Wait a few seconds for startup and then ask for an initial ping
|
|
|
|
// Wait a few seconds for startup and then ask for an initial ping
|
|
|
|
time.Sleep(2 * time.Second) |
|
|
|
time.Sleep(2 * time.Second) |
|
|
|