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 message signing #1583

Merged
merged 43 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 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
ac3c977
Handle forwarding of signed messages and reviewers comments
AgeManning May 25, 2020
e9afd95
Merge branch 'master' into gossipsub-signing
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
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
2f4a50a
Only add messages to memcache if not duplicates
AgeManning 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
6bac865
Wrap comments
AgeManning Jul 29, 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
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
25 changes: 14 additions & 11 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ use async_std::{io, task};
use env_logger::{Builder, Env};
use futures::prelude::*;
use libp2p::gossipsub::protocol::MessageId;
use libp2p::gossipsub::{GossipsubEvent, GossipsubMessage, Topic};
use libp2p::{
gossipsub, identity,
PeerId,
};
use libp2p::gossipsub::{GossipsubEvent, GossipsubMessage, MessageAuthenticity, Topic};
use libp2p::{gossipsub, identity, PeerId};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::time::Duration;
use std::{error::Error, task::{Context, Poll}};
use std::{
error::Error,
task::{Context, Poll},
};

fn main() -> Result<(), Box<dyn Error>> {
Builder::from_env(Env::default().default_filter_or("info")).init();
Expand All @@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("Local peer id: {:?}", local_peer_id);

// Set up an encrypted TCP Transport over the Mplex and Yamux protocols
let transport = libp2p::build_development_transport(local_key)?;
let transport = libp2p::build_development_transport(local_key.clone())?;

// Create a Gossipsub topic
let topic = Topic::new("test-net".into());
Expand All @@ -83,7 +83,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let message_id_fn = |message: &GossipsubMessage| {
let mut s = DefaultHasher::new();
message.data.hash(&mut s);
MessageId(s.finish().to_string())
MessageId::from(s.finish().to_string())
};

// set custom gossipsub
Expand All @@ -93,7 +93,8 @@ fn main() -> Result<(), Box<dyn Error>> {
//same content will be propagated.
.build();
// build a gossipsub network behaviour
let mut gossipsub = gossipsub::Gossipsub::new(local_peer_id.clone(), gossipsub_config);
let mut gossipsub =
gossipsub::Gossipsub::new(MessageAuthenticity::Signed(local_key), gossipsub_config);
gossipsub.subscribe(topic.clone());
libp2p::Swarm::new(transport, gossipsub, local_peer_id)
};
Expand All @@ -120,11 +121,13 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut listening = false;
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
match stdin.try_poll_next_unpin(cx)? {
if let Err(e) = match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => swarm.publish(&topic, line.as_bytes()),
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break,
};
} {
println!("Publish error: {:?}", e);
}
}

loop {
Expand Down
24 changes: 10 additions & 14 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use async_std::{io, task};
use futures::{future, prelude::*};
use libp2p::{
core::{either::EitherTransport, transport::upgrade::Version, StreamMuxer},
gossipsub::{self, Gossipsub, GossipsubConfigBuilder, GossipsubEvent},
gossipsub::{self, Gossipsub, GossipsubConfigBuilder, GossipsubEvent, MessageAuthenticity},
identify::{Identify, IdentifyEvent},
identity,
multiaddr::Protocol,
Expand Down Expand Up @@ -178,18 +178,14 @@ fn main() -> Result<(), Box<dyn Error>> {
ping: Ping,
}

impl NetworkBehaviourEventProcess<IdentifyEvent>
for MyBehaviour
{
impl NetworkBehaviourEventProcess<IdentifyEvent> for MyBehaviour {
// Called when `identify` produces an event.
fn inject_event(&mut self, event: IdentifyEvent) {
println!("identify: {:?}", event);
}
}

impl NetworkBehaviourEventProcess<GossipsubEvent>
for MyBehaviour
{
impl NetworkBehaviourEventProcess<GossipsubEvent> for MyBehaviour {
// Called when `gossipsub` produces an event.
fn inject_event(&mut self, event: GossipsubEvent) {
match event {
Expand All @@ -204,9 +200,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}

impl NetworkBehaviourEventProcess<PingEvent>
for MyBehaviour
{
impl NetworkBehaviourEventProcess<PingEvent> for MyBehaviour {
// Called when `ping` produces an event.
fn inject_event(&mut self, event: PingEvent) {
use ping::handler::{PingFailure, PingSuccess};
Expand Down Expand Up @@ -245,11 +239,11 @@ fn main() -> Result<(), Box<dyn Error>> {

// Create a Swarm to manage peers and events
let mut swarm = {
let gossipsub_config = GossipsubConfigBuilder::default()
let gossipsub_config = GossipsubConfigBuilder::new()
.max_transmit_size(262144)
.build();
let mut behaviour = MyBehaviour {
gossipsub: Gossipsub::new(local_peer_id.clone(), gossipsub_config),
gossipsub: Gossipsub::new(MessageAuthenticity::Signed(local_key.clone()), gossipsub_config),
identify: Identify::new(
"/ipfs/0.1.0".into(),
"rust-ipfs-example".into(),
Expand Down Expand Up @@ -280,12 +274,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut listening = false;
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
match stdin.try_poll_next_unpin(cx)? {
if let Err(e) = match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => {
swarm.gossipsub.publish(&gossipsub_topic, line.as_bytes());
swarm.gossipsub.publish(&gossipsub_topic, line.as_bytes())
}
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break,
} {
println!("Publish error: {:?}", e);
}
}
loop {
Expand Down
4 changes: 3 additions & 1 deletion protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ unsigned-varint = { version = "0.4.0", features = ["futures-codec"] }
log = "0.4.8"
sha2 = "0.8.1"
base64 = "0.11.0"
lru = "0.4.3"
smallvec = "1.1.0"
prost = "0.6.1"
hex_fmt = "0.3.0"
lru_time_cache = "0.10.0"

[dev-dependencies]
async-std = "1.6.2"
env_logger = "0.7.1"
libp2p-plaintext = { path = "../plaintext" }
libp2p-yamux = { path = "../../muxers/yamux" }
quickcheck = "0.9.2"
hex = "0.4.2"

[build-dependencies]
prost-build = "0.6"
Loading