Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.50.0

- Implement gossipsub 1.3 extensions control message.
See [PR 6119](https://github.com/libp2p/rust-libp2p/pull/6119)

- Remove peer penalty for duplicate messages.
See [PR 6112](https://github.com/libp2p/rust-libp2p/pull/6112)

Expand Down
1 change: 1 addition & 0 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ categories = ["network-programming", "asynchronous"]
[features]
wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"]
metrics = ["prometheus-client"]
test-extension = []

[dependencies]
async-channel = "2.3.1"
Expand Down
46 changes: 43 additions & 3 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ use crate::{
topic::{Hasher, Topic, TopicHash},
transform::{DataTransform, IdentityTransform},
types::{
ControlAction, Graft, IDontWant, IHave, IWant, Message, MessageAcceptance, MessageId,
PeerDetails, PeerInfo, PeerKind, Prune, RawMessage, RpcOut, Subscription,
ControlAction, Extensions, Graft, IDontWant, IHave, IWant, Message, MessageAcceptance,
MessageId, PeerDetails, PeerInfo, PeerKind, Prune, RawMessage, RpcOut, Subscription,
SubscriptionAction,
},
FailedMessages, PublishError, SubscriptionError, TopicScoreParams, ValidationError,
Expand Down Expand Up @@ -1521,6 +1521,33 @@ where
tracing::debug!(peer=%peer_id, "Completed GRAFT handling for peer");
}

fn handle_extensions(&mut self, peer_id: &PeerId, extensions: Extensions) {
let Some(peer) = self.connected_peers.get_mut(peer_id) else {
tracing::error!(
peer=%peer_id,
"Extensions by unknown peer"
);
return;
};

if peer.extensions.is_some() {
tracing::debug!(
peer=%peer_id,
"Peer had already sent us extensions message"
);
return;
}

peer.extensions = Some(extensions);

#[cfg(feature = "test-extension")]
if extensions.test_extension.unwrap_or(false)
&& matches!(peer.kind, PeerKind::Gossipsubv1_3)
{
self.send_message(*peer_id, RpcOut::TestExtension);
}
}

/// Removes the specified peer from the mesh, returning true if it was present.
fn remove_peer_from_mesh(
&mut self,
Expand Down Expand Up @@ -2898,7 +2925,9 @@ where
RpcOut::Graft(_)
| RpcOut::Prune(_)
| RpcOut::Subscribe(_)
| RpcOut::Unsubscribe(_) => {
| RpcOut::Unsubscribe(_)
| RpcOut::Extensions(_)
| RpcOut::TestExtension => {
unreachable!("Channel for highpriority control messages is unbounded and should always be open.")
}
}
Expand Down Expand Up @@ -3132,6 +3161,7 @@ where
sender: Sender::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
extensions: None,
});
// Add the new connection
connected_peer.connections.push(connection_id);
Expand Down Expand Up @@ -3159,6 +3189,7 @@ where
sender: Sender::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
extensions: None,
});
// Add the new connection
connected_peer.connections.push(connection_id);
Expand Down Expand Up @@ -3351,6 +3382,11 @@ where
}
}
}
ControlAction::Extensions(extensions) => {
if let Some(extensions) = extensions {
self.handle_extensions(&propagation_source, extensions);
}
}
}
}
if !ihave_msgs.is_empty() {
Expand All @@ -3362,6 +3398,10 @@ where
if !prune_msgs.is_empty() {
self.handle_prune(&propagation_source, prune_msgs);
}

if let Some(_extension) = rpc.test_extension {
tracing::debug!("Received Test Extension");
}
}
}
}
Expand Down
Loading
Loading