Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gossipsub v1.1 #1720

Merged
merged 141 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
aeba523
Gossipsub message signing
AgeManning May 19, 2020
573e4b6
Update ipfs-private example
AgeManning May 19, 2020
d2babd4
Add optimisation to prevent key calculation each message
AgeManning May 22, 2020
8353474
Support multiple versions
AgeManning May 22, 2020
b7db121
Initial porting of peer_scoring from go-libp2p
AgeManning May 22, 2020
ac3c977
Handle forwarding of signed messages and reviewers comments
AgeManning May 25, 2020
f3ff66b
Merge latest gossipsub signing
AgeManning May 25, 2020
c8335cc
Progress to porting scoring functions
AgeManning May 25, 2020
e9afd95
Merge branch 'master' into gossipsub-signing
AgeManning May 27, 2020
984a662
Finish first port of score params
AgeManning May 27, 2020
80ea7df
Add defaults to scoring
AgeManning May 27, 2020
58f61b4
Generalise topic hashing
AgeManning May 27, 2020
238e305
Update topic hashing structure
AgeManning May 27, 2020
fec112a
Update v1.1 tests
AgeManning May 27, 2020
bc09eb7
Add more unit tests
AgeManning May 27, 2020
3d1a025
protocols/gossipsub/src/protocol: Use quickcheck to test signing (#31)
mxinden Jun 1, 2020
31b6849
Shift signing into behaviour
AgeManning Jun 1, 2020
a8cec0b
Merge latest master
AgeManning Jul 1, 2020
2b38112
Address reviewers suggestions
AgeManning Jul 1, 2020
7d678f5
Send subscriptions to all peers
AgeManning Jul 1, 2020
dc050dd
Update examples
AgeManning Jul 1, 2020
5bf1cfc
Shift signing option into the behaviour
AgeManning Jul 1, 2020
4ffe728
Revert changes to core/
AgeManning Jul 9, 2020
24b738c
Reviewers suggestion
AgeManning Jul 9, 2020
a2e4bf0
Merge remote-tracking branch 'origin/master' into gossipsub-signing
AgeManning Jul 9, 2020
2f20571
Merge latest master
AgeManning Jul 23, 2020
2c50ba2
Revert changes to core/
AgeManning Jul 23, 2020
4de878e
Switch gossipsub state to use sets instead of vectors
rklaehn Jul 23, 2020
e43f0a0
Make tests pass
rklaehn Jul 23, 2020
57f07aa
Some clippy
rklaehn Jul 23, 2020
b6eeb3c
Prevent duplicate finding during JOIN
AgeManning Jul 24, 2020
0d5bde4
Merge #1675
AgeManning Jul 24, 2020
aec51e0
Update tests, improve logging
AgeManning Jul 24, 2020
759a5ad
Update the default d_lo constant
AgeManning Jul 24, 2020
495ffe4
Handle errors correctly
AgeManning Jul 24, 2020
1ea2dd9
Add privacy and validation options in the config
AgeManning Jul 24, 2020
8e69465
Merge branch 'master' into gossipsub-v1.1
blacktemplar Jul 24, 2020
1f73ded
A few improvements (#32)
rklaehn Jul 24, 2020
7b76c8f
Improve signing validation logic
AgeManning Jul 24, 2020
f5d32b2
Change the gossipsub rpc protocol to use bytes for message ids (#34)
rklaehn Jul 25, 2020
c3a7757
Add optional privacy and validation settings
AgeManning Jul 26, 2020
0c43ed4
Correct doc link
AgeManning Jul 27, 2020
efa40e3
Prevent invalid messages from being gossiped
AgeManning Jul 27, 2020
a514c60
Remove unvalidated messages from gossip. Reintroduce duplicate cache
AgeManning Jul 27, 2020
b257025
Send grafts when subscriptions are added to the mesh
AgeManning Jul 28, 2020
b20771b
Merge latest master
AgeManning Jul 28, 2020
cacadc0
Merge gossipsub-signing
AgeManning Jul 28, 2020
6566925
implement explicit peers
blacktemplar Jul 28, 2020
81338d5
Merge branch 'gossipsub-v1.1' into gossipsub-v1.1-explicit-peers
blacktemplar Jul 28, 2020
ecb2d8b
Fix ipfs-kad example
AgeManning Jul 28, 2020
2a830b9
Merge branch 'gossipsub-v1.1' into gossipsub-v1.1-explicit-peers
blacktemplar Jul 28, 2020
b78d771
finish merging + rustfmt
blacktemplar Jul 28, 2020
8bffa91
undo changes in ipfs-private
blacktemplar Jul 28, 2020
2f4a50a
Only add messages to memcache if not duplicates
AgeManning Jul 28, 2020
99a37bb
Merge latest signing
AgeManning Jul 28, 2020
284bf1c
Merge pull request #36 from blacktemplar/gossipsub-v1.1-explicit-peers
blacktemplar Jul 28, 2020
be7c9e2
Add mesh maintenance tests and remove excess peers from mesh
AgeManning Jul 29, 2020
e049ff7
Apply reviewers suggestions
AgeManning Jul 29, 2020
74d2779
Merge latest master
AgeManning Jul 29, 2020
81fca56
Merge latest gossipsub-signing
AgeManning Jul 29, 2020
6bac865
Wrap comments
AgeManning Jul 29, 2020
6e0a6b3
implement px and prune backoff + simplify tests for explicit peers
blacktemplar Jul 29, 2020
1257639
Merge pull request #37 from sigp/gossipsub-v1.1-prune-backoff-and-px
blacktemplar Jul 29, 2020
6c77022
improved data structure for storing backoffs + adding configurable sl…
blacktemplar Jul 30, 2020
8b17725
Merge pull request #38 from sigp/gossipsub-v1.1-prune-backoff-and-px
blacktemplar Jul 30, 2020
2518f9f
allow flood publishing (on by default)
blacktemplar Jul 30, 2020
1994c88
Merge pull request #39 from sigp/gossipsub-v1.1-flood-publishing
blacktemplar Jul 30, 2020
dbe0a84
implement adaptive gossip dissemination + complete config debug output
blacktemplar Jul 30, 2020
7155f5c
Merge pull request #40 from sigp/gossipsub-v1.1-adaptive-gossip-disse…
blacktemplar Jul 31, 2020
da34368
fix bug in backoff storage data structure
blacktemplar Jul 31, 2020
66730dd
make GossipsubConfig fields private + add getters + improve validatio…
blacktemplar Jul 31, 2020
8a0b278
implements a configurable minimum number of mesh peers that are outbound
blacktemplar Jul 31, 2020
4e1375a
Merge pull request #41 from sigp/gossipsub-v1.1-outbound-mesh-quota
blacktemplar Aug 1, 2020
94469cf
Ensure sequence number is sent
AgeManning Aug 2, 2020
60f8a1e
Merge latest master
AgeManning Aug 2, 2020
fef66dd
Maintain the debug trait
AgeManning Aug 2, 2020
799137c
use the score module in the behaviour, calling the score update metho…
blacktemplar Aug 6, 2020
efb59ac
Merge pull request #42 from sigp/gossipsub-v1.1-score-wiring
blacktemplar Aug 6, 2020
b6fbf05
implement opportunistic grafting
blacktemplar Aug 6, 2020
189ffc4
remove done TODO
blacktemplar Aug 6, 2020
f405d2a
remove done TODO
blacktemplar Aug 6, 2020
6fe395a
cargo fmt
blacktemplar Aug 6, 2020
47855d6
Merge branch 'gossipsub-v1.1' into gossip-v1.1-opportunistic-grafting
blacktemplar Aug 6, 2020
5954403
ignore grafts in unknown topics
blacktemplar Aug 6, 2020
a228f3b
Merge pull request #43 from sigp/gossip-v1.1-opportunistic-grafting
blacktemplar Aug 6, 2020
3d69944
Merge branch 'gossipsub-v1.1' into gossipsub-v1.1-spam-protection-mea…
blacktemplar Aug 6, 2020
afba384
cap the number of gossipsub retransmission for the iwants of the same…
blacktemplar Aug 6, 2020
223f0d8
cap the number of processed ihaves per peer per heartbeat, plus the m…
blacktemplar Aug 7, 2020
1ced56e
Replace lru cache with custom duplicatecache
AgeManning Aug 7, 2020
27ac942
track iwant messages we send and penalize peers not responding to them
blacktemplar Aug 7, 2020
04d3e2f
removes todo
blacktemplar Aug 7, 2020
5c52843
Improve stream management and error handling
AgeManning Aug 7, 2020
a135fc0
Merge pull request #44 from sigp/gossipsub-v1.1-spam-protection-measures
blacktemplar Aug 7, 2020
d9ee8e4
Merge remote-tracking branch 'origin/gossipsub-signing' into gossipsu…
blacktemplar Aug 7, 2020
714fee3
Merge branch 'master' into gossipsub-v1.1
blacktemplar Aug 7, 2020
7f7fd17
cargo fmt
blacktemplar Aug 7, 2020
ee7dd71
Gossipsub v1.1 check fmt (#45)
blacktemplar Aug 7, 2020
5109fe7
Merge duplicate cache
AgeManning Aug 10, 2020
b748618
Merge substream updates
AgeManning Aug 10, 2020
7bdb378
Propagate signature verification and peer kinds to behaviour (#46)
AgeManning Aug 12, 2020
83280db
treat peers that do not support the protocol as disconnected (#48)
blacktemplar Aug 12, 2020
5d93c0a
Gossipsub v1.1 various improvements (#49)
blacktemplar Aug 17, 2020
3206da5
Gossipsub 1.1 ammendments (#50)
AgeManning Aug 24, 2020
59034e2
Complete porting of go scoring tests (#51)
AgeManning Aug 25, 2020
521ecdb
Add peer blacklisting (#52)
AgeManning Aug 25, 2020
261f78e
Estimate message size (#53)
AgeManning Aug 26, 2020
f71a1bb
Message fragmentation (#54)
AgeManning Aug 27, 2020
c762d6c
Correct tests and merge latest master (#55)
AgeManning Aug 27, 2020
8ec6b66
Merge latest master
AgeManning Aug 27, 2020
4f92599
Remove github workflow
AgeManning Aug 27, 2020
618334a
Cleanup code add logs (#56)
AgeManning Aug 28, 2020
9a03f94
Further improve logging (#57)
AgeManning Aug 28, 2020
e031bce
Remove lru_time_cache_dep (#58)
AgeManning Aug 30, 2020
c7f0716
Various improvements (#60)
blacktemplar Sep 25, 2020
9da2af7
Cache published message ids (#61)
blacktemplar Oct 2, 2020
464c4da
use generic type for message data + cache message ids (#67)
blacktemplar Oct 8, 2020
88ee95e
Adds a fast message id function and an additional cache for it (#68)
blacktemplar Oct 9, 2020
238e5cf
Merge branch 'master' into gossipsub-v1.1
blacktemplar Oct 9, 2020
6ee2c5f
export FastMessageId
blacktemplar Oct 9, 2020
4c95f86
Gossipsub v1.1 bug fixes (#71)
blacktemplar Oct 14, 2020
c2c4a26
add subscription filters + some useful default filters + refactor tes…
blacktemplar Oct 14, 2020
201d533
remove support for multi-topic messages (#73)
blacktemplar Oct 20, 2020
87633a3
also consider allow self origin when using a published message ids di…
blacktemplar Oct 21, 2020
0e28cba
fix clippy warnings (#83)
blacktemplar Oct 21, 2020
9ba9b8a
Merge branch 'master' into gossipsub-v1.1
blacktemplar Oct 22, 2020
6bb58ec
Merge latest master
AgeManning Nov 3, 2020
7a316e8
Merge latest master
AgeManning Nov 6, 2020
d306455
Address reviewers comments (#88)
AgeManning Nov 8, 2020
2d1170b
implement as_ref and as_static_ref to get a &str from PeerKind (#91)
blacktemplar Nov 16, 2020
8bdc378
Merge latest master
AgeManning Nov 17, 2020
34f58fb
Update to latest master
AgeManning Nov 17, 2020
5157e70
only respond to IWANT if message got already validated (#96)
blacktemplar Nov 26, 2020
82be02d
protocols/gossipsub: Review (#93)
mxinden Dec 7, 2020
ffee445
Merge latest master
AgeManning Dec 7, 2020
23d7d04
Add optional compression to gossipsub (#100)
AgeManning Dec 16, 2020
1b5a35e
Remove feature gating from gossipsub
AgeManning Dec 16, 2020
1b19338
Merge latest master
AgeManning Dec 17, 2020
a15b246
Remove compression in favour of a more general data transform
AgeManning Dec 17, 2020
4cca4d3
Loosen trait bounds on gossipsub
AgeManning Dec 18, 2020
88ed4e5
Merge latest master
AgeManning Jan 6, 2021
f47ae78
Fix doclinks
AgeManning Jan 6, 2021
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
53 changes: 36 additions & 17 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//! cargo run --example gossipsub-chat
//! ```
//!
//! It will print the PeerId and the listening address, e.g. `Listening on
//! It will print the [`PeerId`] and the listening address, e.g. `Listening on
//! "/ip4/0.0.0.0/tcp/24915"`
//!
//! In the second terminal window, start a new instance of the example with:
Expand All @@ -49,8 +49,10 @@
use async_std::{io, task};
use env_logger::{Builder, Env};
use futures::prelude::*;
use libp2p::gossipsub::protocol::MessageId;
use libp2p::gossipsub::{GossipsubEvent, GossipsubMessage, MessageAuthenticity, Topic};
use libp2p::gossipsub::MessageId;
use libp2p::gossipsub::{
GossipsubEvent, GossipsubMessage, IdentTopic as Topic, MessageAuthenticity, ValidationMode,
};
use libp2p::{gossipsub, identity, PeerId};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
Expand All @@ -72,30 +74,43 @@ fn main() -> Result<(), Box<dyn Error>> {
let transport = libp2p::build_development_transport(local_key.clone())?;

// Create a Gossipsub topic
let topic = Topic::new("test-net".into());
let topic = Topic::new("test-net");

// Create a Swarm to manage peers and events
let mut swarm = {
// to set default parameters for gossipsub use:
// let gossipsub_config = gossipsub::GossipsubConfig::default();

// To content-address message, we can take the hash of message and use it as an ID.
let message_id_fn = |message: &GossipsubMessage| {
let mut s = DefaultHasher::new();
message.data.hash(&mut s);
MessageId::from(s.finish().to_string())
};

// set custom gossipsub
let gossipsub_config = gossipsub::GossipsubConfigBuilder::new()
.heartbeat_interval(Duration::from_secs(10))
// Set a custom gossipsub
let gossipsub_config = gossipsub::GossipsubConfigBuilder::default()
.heartbeat_interval(Duration::from_secs(10)) // This is set to aid debugging by not cluttering the log space
.validation_mode(ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message signing)
.message_id_fn(message_id_fn) // content-address messages. No two messages of the
//same content will be propagated.
.build();
// same content will be propagated.
.build()
.expect("Valid config");
// build a gossipsub network behaviour
let mut gossipsub =
gossipsub::Gossipsub::new(MessageAuthenticity::Signed(local_key), gossipsub_config);
gossipsub.subscribe(topic.clone());
let mut gossipsub: gossipsub::Gossipsub =
gossipsub::Gossipsub::new(MessageAuthenticity::Signed(local_key), gossipsub_config)
.expect("Correct configuration");

// subscribes to our topic
gossipsub.subscribe(&topic).unwrap();

// add an explicit peer if one was provided
if let Some(explicit) = std::env::args().nth(2) {
let explicit = explicit.clone();
match explicit.parse() {
Ok(id) => gossipsub.add_explicit_peer(&id),
Err(err) => println!("Failed to parse explicit peer id: {:?}", err),
}
}

// build the swarm
libp2p::Swarm::new(transport, gossipsub, local_peer_id)
};

Expand All @@ -122,7 +137,7 @@ fn main() -> Result<(), Box<dyn Error>> {
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
if let Err(e) = match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => swarm.publish(&topic, line.as_bytes()),
Poll::Ready(Some(line)) => swarm.publish(topic.clone(), line.as_bytes()),
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break,
} {
Expand All @@ -133,7 +148,11 @@ fn main() -> Result<(), Box<dyn Error>> {
loop {
match swarm.poll_next_unpin(cx) {
Poll::Ready(Some(gossip_event)) => match gossip_event {
GossipsubEvent::Message(peer_id, id, message) => println!(
GossipsubEvent::Message {
propagation_source: peer_id,
message_id: id,
message,
} => println!(
"Got message: {} with id: {} from peer: {:?}",
String::from_utf8_lossy(&message.data),
id,
Expand Down
40 changes: 26 additions & 14 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@
use async_std::{io, task};
use futures::{future, prelude::*};
use libp2p::{
core::{either::EitherTransport, transport, transport::upgrade::Version, muxing::StreamMuxerBox},
core::{
either::EitherTransport, muxing::StreamMuxerBox, transport, transport::upgrade::Version,
},
gossipsub::{self, Gossipsub, GossipsubConfigBuilder, GossipsubEvent, MessageAuthenticity},
identify::{Identify, IdentifyEvent},
identity,
multiaddr::Protocol,
noise,
ping::{self, Ping, PingConfig, PingEvent},
pnet::{PnetConfig, PreSharedKey},
noise,
swarm::NetworkBehaviourEventProcess,
tcp::TcpConfig,
yamux::YamuxConfig,
Expand All @@ -61,9 +63,10 @@ use std::{
pub fn build_transport(
key_pair: identity::Keypair,
psk: Option<PreSharedKey>,
) -> transport::Boxed<(PeerId, StreamMuxerBox)>
{
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&key_pair).unwrap();
) -> transport::Boxed<(PeerId, StreamMuxerBox)> {
let noise_keys = noise::Keypair::<noise::X25519Spec>::new()
.into_authentic(&key_pair)
.unwrap();
let noise_config = noise::NoiseConfig::xx(noise_keys).into_authenticated();
let yamux_config = YamuxConfig::default();

Expand Down Expand Up @@ -157,7 +160,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let transport = build_transport(local_key.clone(), psk);

// Create a Gosspipsub topic
let gossipsub_topic = gossipsub::Topic::new("chat".into());
let gossipsub_topic = gossipsub::IdentTopic::new("chat");

// We create a custom network behaviour that combines gossipsub, ping and identify.
#[derive(NetworkBehaviour)]
Expand All @@ -178,7 +181,11 @@ fn main() -> Result<(), Box<dyn Error>> {
// Called when `gossipsub` produces an event.
fn inject_event(&mut self, event: GossipsubEvent) {
match event {
GossipsubEvent::Message(peer_id, id, message) => println!(
GossipsubEvent::Message {
propagation_source: peer_id,
message_id: id,
message,
} => println!(
"Got message: {} with id: {} from peer: {:?}",
String::from_utf8_lossy(&message.data),
id,
Expand Down Expand Up @@ -228,11 +235,16 @@ fn main() -> Result<(), Box<dyn Error>> {

// Create a Swarm to manage peers and events
let mut swarm = {
let gossipsub_config = GossipsubConfigBuilder::new()
let gossipsub_config = GossipsubConfigBuilder::default()
.max_transmit_size(262144)
.build();
.build()
.expect("valid config");
let mut behaviour = MyBehaviour {
gossipsub: Gossipsub::new(MessageAuthenticity::Signed(local_key.clone()), gossipsub_config),
gossipsub: Gossipsub::new(
MessageAuthenticity::Signed(local_key.clone()),
gossipsub_config,
)
.expect("Valid configuration"),
identify: Identify::new(
"/ipfs/0.1.0".into(),
"rust-ipfs-example".into(),
Expand All @@ -242,7 +254,7 @@ fn main() -> Result<(), Box<dyn Error>> {
};

println!("Subscribing to {:?}", gossipsub_topic);
behaviour.gossipsub.subscribe(gossipsub_topic.clone());
behaviour.gossipsub.subscribe(&gossipsub_topic).unwrap();
Swarm::new(transport, behaviour, local_peer_id.clone())
};

Expand All @@ -264,9 +276,9 @@ fn main() -> Result<(), Box<dyn Error>> {
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
if let Err(e) = match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => {
swarm.gossipsub.publish(&gossipsub_topic, line.as_bytes())
}
Poll::Ready(Some(line)) => swarm
.gossipsub
.publish(gossipsub_topic.clone(), line.as_bytes()),
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break,
} {
Expand Down
25 changes: 14 additions & 11 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,32 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
libp2p-swarm = { version = "0.26.0", path = "../../swarm" }
libp2p-core = { version = "0.26.0", path = "../../core" }
bytes = "0.5.4"
byteorder = "1.3.2"
fnv = "1.0.6"
futures = "0.3.1"
bytes = "0.5.6"
byteorder = "1.3.4"
fnv = "1.0.7"
futures = "0.3.5"
rand = "0.7.3"
futures_codec = "0.4.0"
futures_codec = "0.4.1"
wasm-timer = "0.2.4"
unsigned-varint = { version = "0.5", features = ["futures-codec"] }
log = "0.4.8"
unsigned-varint = { version = "0.5.0", features = ["futures-codec"] }
log = "0.4.11"
sha2 = "0.9.1"
base64 = "0.13.0"
smallvec = "1.1.0"
smallvec = "1.4.2"
prost = "0.6.1"
hex_fmt = "0.3.0"
lru_time_cache = "0.11.0"
regex = "1.4.0"

[dev-dependencies]
async-std = "1.6.2"
async-std = "1.6.3"
env_logger = "0.8.1"
libp2p-plaintext = { path = "../plaintext" }
libp2p-yamux = { path = "../../muxers/yamux" }
libp2p-mplex = { path = "../../muxers/mplex" }
libp2p-noise = { path = "../../protocols/noise" }
quickcheck = "0.9.2"
hex = "0.4.2"
derive_builder = "0.9.0"

[build-dependencies]
prost-build = "0.6"
prost-build = "0.6.1"
2 changes: 1 addition & 1 deletion protocols/gossipsub/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
// DEALINGS IN THE SOFTWARE.

fn main() {
prost_build::compile_protos(&["src/rpc.proto"], &["src"]).unwrap();
prost_build::compile_protos(&["src/rpc.proto", "src/compat.proto"], &["src"]).unwrap();
}
Loading