-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dot/network): check if peer supports protocol #1617
Changes from 2 commits
b54a59d
b79fc86
4c27f72
c475501
d71cd28
fce59fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,17 @@ func (h *host) peers() []peer.ID { | |
return h.h.Network().Peers() | ||
} | ||
|
||
// getPeerProtocols returns all the supported protocols to one peer | ||
// returns an error if could not get peer protocols | ||
func (h *host) supportsProtocol(peerID peer.ID, protocol protocol.ID) (bool, error) { | ||
peerProtocols, err := h.h.Network().Peerstore().SupportsProtocols(peerID, string(protocol)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can directly do |
||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return len(peerProtocols) > 0, nil | ||
} | ||
|
||
// peerCount returns the number of connected peers | ||
func (h *host) peerCount() int { | ||
peers := h.h.Network().Peers() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,11 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol, | |
} | ||
|
||
func (s *Service) sendData(peer peer.ID, hs Handshake, info *notificationsProtocol, msg NotificationsMessage) { | ||
if support, err := s.host.supportsProtocol(peer, info.protocolID); err != nil || !support { | ||
logger.Warn("the peer does not supports the protocol", "protocol", info.protocolID, "peer", peer, "err", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be set at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
return | ||
} | ||
|
||
hsData, has := info.getHandshakeData(peer, false) | ||
if has && !hsData.validated { | ||
// peer has sent us an invalid handshake in the past, ignore | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPeerProtocols
->supportsProtocol
supportsProtocol
doesn't return all the supported protocols.supportsProtocol
checks ifprotocol
is supported bypeerID
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!