Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Mar 21, 2022
1 parent 2fd8c61 commit 7d64b92
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dot/network/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ func (s *Service) sendData(peer peer.ID, hs Handshake, info *notificationsProtoc
}, peer)
}

var errPeerDisconnected = errors.New("peer disconnected")

func (s *Service) sendHandshake(peer peer.ID, hs Handshake, info *notificationsProtocol) (libp2pnetwork.Stream, error) {
// multiple processes could each call this upcoming section, opening multiple streams and
// sending multiple handshakes. thus, we need to have a per-peer and per-protocol lock
Expand All @@ -294,7 +296,9 @@ func (s *Service) sendHandshake(peer peer.ID, hs Handshake, info *notificationsP
// from the map
peerMutex := info.peersData.getMutex(peer)
if peerMutex == nil {
return nil, fmt.Errorf("got a nil mutex for peer id %s (TODO)", peer)
// Note: the only place the mutex is deleted is when the peer disconnects.
// If it doesn't exist, the peer never connected either.
return nil, fmt.Errorf("%w: peer id %s", errPeerDisconnected, peer)
}

peerMutex.Lock()
Expand Down

0 comments on commit 7d64b92

Please sign in to comment.