Skip to content

Commit

Permalink
Send subscriptions to all peers
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Jul 1, 2020
1 parent 2b38112 commit 7d678f5
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,17 @@ impl Gossipsub {
return false;
}

// send subscription request to all peers in the topic
if let Some(peer_list) = self.topic_peers.get(&topic_hash) {
let mut fixed_event = None; // initialise the event once if needed
if fixed_event.is_none() {
fixed_event = Some(Arc::new(GossipsubRpc {
messages: Vec::new(),
subscriptions: vec![GossipsubSubscription {
topic_hash: topic_hash.clone(),
action: GossipsubSubscriptionAction::Subscribe,
}],
control_msgs: Vec::new(),
}));
}

let event = fixed_event.expect("event has been initialised");
// send subscription request to all peers
let peer_list = self.peer_topics.keys().collect::<Vec<_>>();
if !peer_list.is_empty() {
let event = Arc::new(GossipsubRpc {
messages: Vec::new(),
subscriptions: vec![GossipsubSubscription {
topic_hash: topic_hash.clone(),
action: GossipsubSubscriptionAction::Subscribe,
}],
control_msgs: Vec::new(),
});

for peer in peer_list {
debug!("Sending SUBSCRIBE to peer: {:?}", peer);
Expand Down Expand Up @@ -194,21 +190,17 @@ impl Gossipsub {
return false;
}

// announce to all peers in the topic
let mut fixed_event = None; // initialise the event once if needed
if let Some(peer_list) = self.topic_peers.get(topic_hash) {
if fixed_event.is_none() {
fixed_event = Some(Arc::new(GossipsubRpc {
messages: Vec::new(),
subscriptions: vec![GossipsubSubscription {
topic_hash: topic_hash.clone(),
action: GossipsubSubscriptionAction::Unsubscribe,
}],
control_msgs: Vec::new(),
}));
}

let event = fixed_event.expect("event has been initialised");
// announce to all peers
let peer_list = self.peer_topics.keys().collect::<Vec<_>>();
if !peer_list.is_empty() {
let event = Arc::new(GossipsubRpc {
messages: Vec::new(),
subscriptions: vec![GossipsubSubscription {
topic_hash: topic_hash.clone(),
action: GossipsubSubscriptionAction::Unsubscribe,
}],
control_msgs: Vec::new(),
});

for peer in peer_list {
debug!("Sending UNSUBSCRIBE to peer: {:?}", peer);
Expand Down

0 comments on commit 7d678f5

Please sign in to comment.