Skip to content

Commit

Permalink
Moved requestAndWait channel send to no-error case
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed May 8, 2024
1 parent 5bb5680 commit 1280499
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
12 changes: 10 additions & 2 deletions p2p/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ func (p *P2PNode) requestAndWait(peerID peer.ID, location common.Location, data

// Mark this peer as behaving well
p.peerManager.MarkResponsivePeer(peerID, location)
select {
case resultChan <- recvd:
// Data sent successfully
default:
// Optionally log the missed send or handle it in another way
log.Global.WithFields(log.Fields{
"peerId": peerID,
"message": "Channel is full, data not sent",
}).Warning("Missed data send")
}
} else {
log.Global.WithFields(log.Fields{
"peerId": peerID,
Expand All @@ -192,8 +202,6 @@ func (p *P2PNode) requestAndWait(peerID peer.ID, location common.Location, data
// Mark this peer as not responding
p.peerManager.MarkUnresponsivePeer(peerID, location)
}
// send the block to the result channel
resultChan <- recvd
}

// Request a data from the network for the specified slice
Expand Down
2 changes: 1 addition & 1 deletion p2p/node/p2p_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (p *P2PNode) requestFromPeer(peerID peer.ID, location common.Location, data
"peerId": peerID,
}).Warn("Peer did not respond in time")
p.peerManager.MarkUnresponsivePeer(peerID, location)
return nil, nil
return nil, errors.New("peer did not respond in time")
}

if recvdType == nil {
Expand Down
3 changes: 1 addition & 2 deletions p2p/node/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Returns the number of peers in the routing table, as well as how many active
// connections we currently have.
func (p *P2PNode) connectionStats() (int) {
func (p *P2PNode) connectionStats() int {
peers := p.peerManager.GetHost().Network().Peers()
numConnected := len(peers)

Expand All @@ -30,7 +30,6 @@ func (p *P2PNode) statsLoop() {
select {
case <-ticker.C:
peersConnected := p.connectionStats()

log.Global.Debugf("Number of peers connected: %d", peersConnected)
case <-p.ctx.Done():
log.Global.Warnf("Context cancelled. Stopping stats loop...")
Expand Down

0 comments on commit 1280499

Please sign in to comment.