Browse Source

fix bug, peer may be nil

pull/43/merge
Jae Kwon 10 years ago
parent
commit
938eda979b
1 changed files with 4 additions and 5 deletions
  1. +4
    -5
      blockchain/reactor.go

+ 4
- 5
blockchain/reactor.go View File

@ -112,11 +112,10 @@ func (bcR *BlockchainReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte)
log.Warn("Error decoding message", "error", err) log.Warn("Error decoding message", "error", err)
return return
} }
log.Info("BlockchainReactor received message", "msg", msg_)
log.Debug("BlockchainReactor received message", "msg", msg_)
switch msg := msg_.(type) { switch msg := msg_.(type) {
case BlockRequestMessage: case BlockRequestMessage:
log.Debug("Got BlockRequest", "msg", msg)
// Got a request for a block. Respond with block if we have it. // Got a request for a block. Respond with block if we have it.
block := bcR.store.LoadBlock(msg.Height) block := bcR.store.LoadBlock(msg.Height)
if block != nil { if block != nil {
@ -129,11 +128,9 @@ func (bcR *BlockchainReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte)
// TODO peer is asking for things we don't have. // TODO peer is asking for things we don't have.
} }
case BlockResponseMessage: case BlockResponseMessage:
log.Debug("Got BlockResponse", "msg", msg)
// Got a block. // Got a block.
bcR.pool.AddBlock(msg.Block, src.Key) bcR.pool.AddBlock(msg.Block, src.Key)
case PeerStatusMessage: case PeerStatusMessage:
log.Debug("Got PeerStatus", "msg", msg)
// Got a peer status. // Got a peer status.
bcR.pool.SetPeerHeight(src.Key, msg.Height) bcR.pool.SetPeerHeight(src.Key, msg.Height)
default: default:
@ -165,7 +162,9 @@ FOR_LOOP:
case peerId := <-bcR.timeoutsCh: // chan string case peerId := <-bcR.timeoutsCh: // chan string
// Peer timed out. // Peer timed out.
peer := bcR.sw.Peers().Get(peerId) peer := bcR.sw.Peers().Get(peerId)
bcR.sw.StopPeerForError(peer, errors.New("BlockchainReactor Timeout"))
if peer != nil {
bcR.sw.StopPeerForError(peer, errors.New("BlockchainReactor Timeout"))
}
case _ = <-trySyncTicker.C: // chan time case _ = <-trySyncTicker.C: // chan time
var lastValidatedBlock *types.Block var lastValidatedBlock *types.Block
SYNC_LOOP: SYNC_LOOP:


Loading…
Cancel
Save