(blkNum uint32)
| 434 | } |
| 435 | |
| 436 | func (self *PeerSyncer) requestBlock(blkNum uint32) (*Block, error) { |
| 437 | msg := self.server.constructBlockFetchMsg(blkNum) |
| 438 | self.server.msgSendC <- &SendMsgEvent{ |
| 439 | ToPeer: self.peerIdx, |
| 440 | Msg: msg, |
| 441 | } |
| 442 | |
| 443 | t := time.NewTimer(makeProposalTimeout * 2) |
| 444 | defer t.Stop() |
| 445 | |
| 446 | select { |
| 447 | case msg := <-self.msgC: |
| 448 | if msg == nil { |
| 449 | return nil, fmt.Errorf("nil block fetch rsp msg received") |
| 450 | } |
| 451 | switch msg.Type() { |
| 452 | case BlockFetchRespMessage: |
| 453 | pMsg, ok := msg.(*BlockFetchRespMsg) |
| 454 | if !ok { |
| 455 | // log error |
| 456 | } |
| 457 | return pMsg.BlockData, nil |
| 458 | } |
| 459 | case <-t.C: |
| 460 | return nil, fmt.Errorf("timeout fetch block %d from peer %d", blkNum, self.peerIdx) |
| 461 | case <-self.server.quitC: |
| 462 | return nil, fmt.Errorf("peer syncing %d quit, failed fetching Block %d", self.peerIdx, blkNum) |
| 463 | } |
| 464 | return nil, fmt.Errorf("failed to get Block %d from peer %d", blkNum, self.peerIdx) |
| 465 | } |
| 466 | |
| 467 | func (self *PeerSyncer) requestBlockInfo(startBlkNum uint32) ([]*BlockInfo_, error) { |
| 468 | msg := self.server.constructBlockInfoFetchMsg(startBlkNum) |
no test coverage detected