mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 19:02:13 +00:00
Update connected peers' topics on NodeEvent (#638)
* Update connected peers' topics on NodeEvent After a peer connects they send us the list of the topics they're subscribed to. This causes a NodeEvent to be emitted. This PR makes sure we update the subscription info we have on the newly connected peer. * Formatting * Update protocols/floodsub/src/layer.rs Co-Authored-By: dvdplm <dvdplm@gmail.com> * whiespace
This commit is contained in:
parent
24ccefbbc6
commit
37e2ec38a7
@ -218,6 +218,25 @@ where
|
|||||||
propagation_source: PeerId,
|
propagation_source: PeerId,
|
||||||
event: FloodsubRpc,
|
event: FloodsubRpc,
|
||||||
) {
|
) {
|
||||||
|
// Update connected peers topics
|
||||||
|
for subscription in event.subscriptions {
|
||||||
|
let mut remote_peer_topics = self.connected_peers
|
||||||
|
.get_mut(&propagation_source)
|
||||||
|
.expect("connected_peers is kept in sync with the peers we are connected to; we are guaranteed to only receive events from connected peers ; qed");
|
||||||
|
match subscription.action {
|
||||||
|
FloodsubSubscriptionAction::Subscribe => {
|
||||||
|
if !remote_peer_topics.contains(&subscription.topic) {
|
||||||
|
remote_peer_topics.push(subscription.topic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FloodsubSubscriptionAction::Unsubscribe => {
|
||||||
|
if let Some(pos) = remote_peer_topics.iter().position(|t| t == &subscription.topic ) {
|
||||||
|
remote_peer_topics.remove(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// List of messages we're going to propagate on the network.
|
// List of messages we're going to propagate on the network.
|
||||||
let mut rpcs_to_dispatch: Vec<(PeerId, FloodsubRpc)> = Vec::new();
|
let mut rpcs_to_dispatch: Vec<(PeerId, FloodsubRpc)> = Vec::new();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user