mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 02:21:21 +00:00
protocols/gossipsub: Fix minor lints and spelling (#2079)
This commit is contained in:
@ -24,7 +24,6 @@ use std::{
|
|||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
collections::{BTreeSet, HashMap},
|
collections::{BTreeSet, HashMap},
|
||||||
fmt,
|
fmt,
|
||||||
iter::FromIterator,
|
|
||||||
net::IpAddr,
|
net::IpAddr,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
@ -1246,7 +1245,7 @@ where
|
|||||||
if self.explicit_peers.contains(peer_id) {
|
if self.explicit_peers.contains(peer_id) {
|
||||||
warn!("GRAFT: ignoring request from direct peer {}", peer_id);
|
warn!("GRAFT: ignoring request from direct peer {}", peer_id);
|
||||||
// this is possibly a bug from non-reciprocal configuration; send a PRUNE for all topics
|
// this is possibly a bug from non-reciprocal configuration; send a PRUNE for all topics
|
||||||
to_prune_topics = HashSet::from_iter(topics.into_iter());
|
to_prune_topics = topics.into_iter().collect();
|
||||||
// but don't PX
|
// but don't PX
|
||||||
do_px = false
|
do_px = false
|
||||||
} else {
|
} else {
|
||||||
@ -1779,15 +1778,12 @@ where
|
|||||||
|
|
||||||
// if the mesh needs peers add the peer to the mesh
|
// if the mesh needs peers add the peer to the mesh
|
||||||
if !self.explicit_peers.contains(propagation_source)
|
if !self.explicit_peers.contains(propagation_source)
|
||||||
&& match self
|
&& matches!(
|
||||||
.connected_peers
|
self.connected_peers
|
||||||
.get(propagation_source)
|
.get(propagation_source)
|
||||||
.map(|v| &v.kind)
|
.map(|v| &v.kind),
|
||||||
{
|
Some(PeerKind::Gossipsubv1_1) | Some(PeerKind::Gossipsub)
|
||||||
Some(PeerKind::Gossipsubv1_1) => true,
|
)
|
||||||
Some(PeerKind::Gossipsub) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
&& !Self::score_below_threshold_from_scores(
|
&& !Self::score_below_threshold_from_scores(
|
||||||
&self.peer_score,
|
&self.peer_score,
|
||||||
propagation_source,
|
propagation_source,
|
||||||
@ -1860,7 +1856,7 @@ where
|
|||||||
let topics_joined = topics_to_graft.iter().collect::<Vec<_>>();
|
let topics_joined = topics_to_graft.iter().collect::<Vec<_>>();
|
||||||
if !topics_joined.is_empty() {
|
if !topics_joined.is_empty() {
|
||||||
peer_added_to_mesh(
|
peer_added_to_mesh(
|
||||||
propagation_source.clone(),
|
*propagation_source,
|
||||||
topics_joined,
|
topics_joined,
|
||||||
&self.mesh,
|
&self.mesh,
|
||||||
self.peer_topics.get(propagation_source),
|
self.peer_topics.get(propagation_source),
|
||||||
@ -2426,7 +2422,7 @@ where
|
|||||||
remaining_prunes.push(prune);
|
remaining_prunes.push(prune);
|
||||||
// inform the handler
|
// inform the handler
|
||||||
peer_removed_from_mesh(
|
peer_removed_from_mesh(
|
||||||
peer.clone(),
|
*peer,
|
||||||
topic_hash,
|
topic_hash,
|
||||||
&self.mesh,
|
&self.mesh,
|
||||||
self.peer_topics.get(&peer),
|
self.peer_topics.get(&peer),
|
||||||
@ -2647,7 +2643,7 @@ where
|
|||||||
// error and drop the message (all individual messages should be small enough to fit in the
|
// error and drop the message (all individual messages should be small enough to fit in the
|
||||||
// max_transmit_size)
|
// max_transmit_size)
|
||||||
|
|
||||||
let messages = self.fragment_message(message.into())?;
|
let messages = self.fragment_message(message)?;
|
||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
self.events
|
self.events
|
||||||
@ -2803,7 +2799,7 @@ where
|
|||||||
self.config.protocol_id_prefix().clone(),
|
self.config.protocol_id_prefix().clone(),
|
||||||
self.config.max_transmit_size(),
|
self.config.max_transmit_size(),
|
||||||
self.config.validation_mode().clone(),
|
self.config.validation_mode().clone(),
|
||||||
self.config.idle_timeout().clone(),
|
self.config.idle_timeout(),
|
||||||
self.config.support_floodsub(),
|
self.config.support_floodsub(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -3008,7 +3004,7 @@ where
|
|||||||
if mesh_peers.contains(peer_id) {
|
if mesh_peers.contains(peer_id) {
|
||||||
self.events
|
self.events
|
||||||
.push_back(NetworkBehaviourAction::NotifyHandler {
|
.push_back(NetworkBehaviourAction::NotifyHandler {
|
||||||
peer_id: peer_id.clone(),
|
peer_id: *peer_id,
|
||||||
event: Arc::new(GossipsubHandlerIn::JoinedMesh),
|
event: Arc::new(GossipsubHandlerIn::JoinedMesh),
|
||||||
handler: NotifyHandler::One(connections.connections[0]),
|
handler: NotifyHandler::One(connections.connections[0]),
|
||||||
});
|
});
|
||||||
|
@ -1833,9 +1833,11 @@ mod tests {
|
|||||||
assert_eq!(dials_set.len(), config.prune_peers());
|
assert_eq!(dials_set.len(), config.prune_peers());
|
||||||
|
|
||||||
//all dial peers must be in px
|
//all dial peers must be in px
|
||||||
assert!(dials_set.is_subset(&HashSet::from_iter(
|
assert!(dials_set.is_subset(
|
||||||
px.iter().map(|i| i.peer_id.as_ref().unwrap().clone())
|
&px.iter()
|
||||||
)));
|
.map(|i| i.peer_id.as_ref().unwrap().clone())
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -264,7 +264,7 @@ impl PeerScore {
|
|||||||
let p3 = deficit * deficit;
|
let p3 = deficit * deficit;
|
||||||
topic_score += p3 * topic_params.mesh_message_deliveries_weight;
|
topic_score += p3 * topic_params.mesh_message_deliveries_weight;
|
||||||
debug!(
|
debug!(
|
||||||
"The peer {} has a mesh message delivieries deficit of {} in topic\
|
"The peer {} has a mesh message deliveries deficit of {} in topic\
|
||||||
{} and will get penalized by {}",
|
{} and will get penalized by {}",
|
||||||
peer_id,
|
peer_id,
|
||||||
deficit,
|
deficit,
|
||||||
@ -726,7 +726,7 @@ impl PeerScore {
|
|||||||
match self.params.topics.entry(topic_hash.clone()) {
|
match self.params.topics.entry(topic_hash.clone()) {
|
||||||
Occupied(mut entry) => {
|
Occupied(mut entry) => {
|
||||||
let first_message_deliveries_cap = params.first_message_deliveries_cap;
|
let first_message_deliveries_cap = params.first_message_deliveries_cap;
|
||||||
let mesh_message_delivieries_cap = params.mesh_message_deliveries_cap;
|
let mesh_message_deliveries_cap = params.mesh_message_deliveries_cap;
|
||||||
let old_params = entry.insert(params);
|
let old_params = entry.insert(params);
|
||||||
|
|
||||||
if old_params.first_message_deliveries_cap > first_message_deliveries_cap {
|
if old_params.first_message_deliveries_cap > first_message_deliveries_cap {
|
||||||
@ -739,11 +739,11 @@ impl PeerScore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if old_params.mesh_message_deliveries_cap > mesh_message_delivieries_cap {
|
if old_params.mesh_message_deliveries_cap > mesh_message_deliveries_cap {
|
||||||
for stats in self.peer_stats.values_mut() {
|
for stats in self.peer_stats.values_mut() {
|
||||||
if let Some(tstats) = stats.topics.get_mut(&topic_hash) {
|
if let Some(tstats) = stats.topics.get_mut(&topic_hash) {
|
||||||
if tstats.mesh_message_deliveries > mesh_message_delivieries_cap {
|
if tstats.mesh_message_deliveries > mesh_message_deliveries_cap {
|
||||||
tstats.mesh_message_deliveries = mesh_message_delivieries_cap;
|
tstats.mesh_message_deliveries = mesh_message_deliveries_cap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user