Skip to content

Commit d93a5ab

Browse files
authored
protocols/gossipsub: Handle unsupported peers (#2241)
Previously, peers that did not support gossipsub were removed from the connection-id mappings. This can cause the connection_id mappings to go out of sync with those managed by the swarm. This PR corrects this and adds an extra event that can inform the user that a peer that does not support the protocol has connected. The user can then optionally handle peers that don't support the protocol.
1 parent c860f5a commit d93a5ab

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

protocols/gossipsub/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 0.33.0 [unreleased]
22

3+
- Add an event to register peers that do not support the gossipsub protocol
4+
[PR 2241](https://github.com/libp2p/rust-libp2p/pull/2241)
5+
36
- Make default features of `libp2p-core` optional.
47
[PR 2181](https://github.com/libp2p/rust-libp2p/pull/2181)
58

protocols/gossipsub/src/behaviour.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ pub enum GossipsubEvent {
139139
/// The topic it has subscribed from.
140140
topic: TopicHash,
141141
},
142+
/// A peer that does not support gossipsub has connected.
143+
GossipsubNotSupported { peer_id: PeerId },
142144
}
143145

144146
/// A data structure for storing configuration for publishing messages. See [`MessageAuthenticity`]
@@ -2995,9 +2997,7 @@ where
29952997
.connections
29962998
.iter()
29972999
.position(|v| v == connection_id)
2998-
.expect(
2999-
"Previously established connection to a non-black-listed peer to be present",
3000-
);
3000+
.expect("Previously established connection to peer must be present");
30013001
connections.connections.remove(index);
30023002

30033003
// If there are more connections and this peer is in a mesh, inform the first connection
@@ -3066,8 +3066,11 @@ where
30663066
"Peer does not support gossipsub protocols. {}",
30673067
propagation_source
30683068
);
3069-
// We treat this peer as disconnected
3070-
self.inject_disconnected(&propagation_source);
3069+
self.events.push_back(NetworkBehaviourAction::GenerateEvent(
3070+
GossipsubEvent::GossipsubNotSupported {
3071+
peer_id: propagation_source,
3072+
},
3073+
));
30713074
} else if let Some(conn) = self.connected_peers.get_mut(&propagation_source) {
30723075
// Only change the value if the old value is Floodsub (the default set in
30733076
// inject_connected). All other PeerKind changes are ignored.

0 commit comments

Comments
 (0)