Skip to content

Commit

Permalink
publish to at least mesh_n peers
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Aug 29, 2024
1 parent ecf0105 commit c1a925e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ libp2p-core = { version = "0.42.0", path = "core" }
libp2p-dcutr = { version = "0.12.0", path = "protocols/dcutr" }
libp2p-dns = { version = "0.42.0", path = "transports/dns" }
libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" }
libp2p-gossipsub = { version = "0.47.0", path = "protocols/gossipsub" }
libp2p-gossipsub = { version = "0.47.1", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.45.0", path = "protocols/identify" }
libp2p-identity = { version = "0.2.9" }
libp2p-kad = { version = "0.46.0", path = "protocols/kad" }
Expand Down
5 changes: 5 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 0.47.0

- Attempt to publish to at least mesh_n peers when flood publish is disabled.
See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX).

## 0.47.0

<!-- Update to libp2p-swarm v0.45.0 -->
- Add ConnectionError to FromSwarm::ConnectionClosed.
See [PR 5485](https://github.com/libp2p/rust-libp2p/pull/5485).
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-gossipsub"
edition = "2021"
rust-version = { workspace = true }
description = "Gossipsub protocol for libp2p"
version = "0.47.0"
version = "0.47.1"
authors = ["Age Manning <Age@AgeManning.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
29 changes: 26 additions & 3 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,30 @@ where
match self.mesh.get(&topic_hash) {
// Mesh peers
Some(mesh_peers) => {
// We have a mesh set. We want to make sure to publish to at least `mesh_n`
// peers (if possible).
let needed_extra_peers = self.config.mesh_n().saturating_sub(mesh_peers.len());

if needed_extra_peers > 0 {
// We don't have `mesh_n` peers in our mesh, we will randomly select extras
// and publish to them.

// Get a random set of peers that are appropriate to send messages too.
let peer_list = get_random_peers(
&self.connected_peers,
&topic_hash,
needed_extra_peers,
|peer| {
!mesh_peers.contains(peer)
&& !self.explicit_peers.contains(peer)
&& !self
.score_below_threshold(peer, |pst| pst.publish_threshold)
.0
},
);
recipient_peers.extend(peer_list);
}

recipient_peers.extend(mesh_peers);
}
// Gossipsub peers
Expand Down Expand Up @@ -2118,10 +2142,9 @@ where
if outbound <= self.config.mesh_outbound_min() {
// do not remove anymore outbound peers
continue;
} else {
// an outbound peer gets removed
outbound -= 1;
}
// an outbound peer gets removed
outbound -= 1;
}

// remove the peer
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ fn test_publish_without_flood_publishing() {
let config: Config = Config::default();
assert_eq!(
publishes.len(),
config.mesh_n_low(),
"Should send a publish message to all known peers"
config.mesh_n(),
"Should send a publish message to at least mesh_n peers"
);

assert!(
Expand Down

0 comments on commit c1a925e

Please sign in to comment.