diff --git a/blockmanager.go b/blockmanager.go index 8c7b23d9..3a709748 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -93,6 +93,8 @@ type blockManager struct { processingReqs bool syncPeer *peer msgChan chan interface{} + syncPeerRequest chan bool + syncPeerResult chan *peer wg sync.WaitGroup quit chan bool @@ -902,6 +904,10 @@ out: // bitch and whine. } + // Return the current sync peer. + case <-b.syncPeerRequest: + b.syncPeerResult <- b.syncPeer + case <-b.quit: break out } @@ -1104,6 +1110,12 @@ func (b *blockManager) Stop() error { return nil } +// SyncPeer returns the current sync peer. +func (b *blockManager) SyncPeer() *peer { + b.syncPeerRequest <- true + return <-b.syncPeerResult +} + // newBlockManager returns a new bitcoin block manager. // Use Start to begin processing asynchronous block and inv updates. func newBlockManager(s *server) (*blockManager, error) { @@ -1119,6 +1131,8 @@ func newBlockManager(s *server) (*blockManager, error) { requestedBlocks: make(map[btcwire.ShaHash]bool), lastBlockLogTime: time.Now(), msgChan: make(chan interface{}, cfg.MaxPeers*3), + syncPeerRequest: make(chan bool, 1), + syncPeerResult: make(chan *peer, 1), headerList: list.New(), quit: make(chan bool), } diff --git a/server.go b/server.go index b51e0413..fef6c9e7 100644 --- a/server.go +++ b/server.go @@ -314,11 +314,13 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) { msg.reply <- nconnected case getPeerInfoMsg: + syncPeer := s.blockManager.SyncPeer() infos := make([]*PeerInfo, 0, state.peers.Len()) state.forAllPeers(func(p *peer) { if !p.Connected() { return } + // A lot of this will make the race detector go mad, // however it is statistics for purely informational purposes // and we don't really care if they are raced to get the new @@ -336,7 +338,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) { Inbound: p.inbound, StartingHeight: p.lastBlock, BanScore: 0, - SyncNode: false, // TODO(oga) for now. bm knows this. + SyncNode: p == syncPeer, } p.pingStatsMtx.Lock() info.PingTime = p.lastPingMicros