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

swarm/: Enable advanced dialing requests #2317

Merged
merged 31 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2fd729c
swarm/: Enable advanced dialing requests
mxinden Oct 13, 2021
09688c7
swarm/src/lib: Emit SwarmEvent::Dialing
mxinden Oct 29, 2021
85b6238
Merge branch 'libp2p/master' into advanced-dialing
mxinden Nov 3, 2021
147c533
swarm/src/lib: Fold condition check into first match
mxinden Nov 3, 2021
2bda3b3
protocols/kad: Adjust to API changes
mxinden Nov 3, 2021
ad083e9
swarm/src/lib: Wrap Opts in DialOpts
mxinden Nov 8, 2021
eea9e12
protocols/identify: Update to latest changes
mxinden Nov 8, 2021
26dedbe
swarm/src/lib: Allow WithPeerIdWithAddresses::condition
mxinden Nov 8, 2021
eb67288
protocols/floodsub: Adjust to latest changes
mxinden Nov 8, 2021
a04eaa3
protocols/req-resp: Adjust to latest changes
mxinden Nov 8, 2021
57f0648
protocols/relay/src/behaviour: Update to recent changes
mxinden Nov 8, 2021
770e3af
protocols/gossipsub: Adjust to latest changes
mxinden Nov 8, 2021
96ac37e
*: Adjust to latest changes
mxinden Nov 8, 2021
9f941fd
protocols/identify: Wait for connection to close before redialing
mxinden Nov 9, 2021
d4410bb
swarm/: Add documentation
mxinden Nov 9, 2021
163229c
swarm/src/lib: Deduplicate addresses
mxinden Nov 9, 2021
8334f36
swarm/CHANGELOG: Add entry
mxinden Nov 9, 2021
1e561e8
*: Bump versions
mxinden Nov 9, 2021
2f1ae01
Merge branch 'libp2p/master' into advanced-dialing
mxinden Nov 9, 2021
036cf24
swarm/src/lib: Move dial_opts to separate file
mxinden Nov 9, 2021
eab21a6
swarm/src/dial_opts: Remove outdated comment
mxinden Nov 9, 2021
5e3edb3
swarm/src/dial_opts: Implement From<Multiaddr> for DialOpts
mxinden Nov 14, 2021
fed72bf
Merge branch 'libp2p/master' into advanced-dialing
mxinden Nov 14, 2021
09293c4
swarm/src/dial_opts: Implement From<PeerId> for DialOpts
mxinden Nov 15, 2021
9a52b30
Merge branch 'master' into advanced-dialing
mxinden Nov 15, 2021
8d9b548
misc/metrics: Fix type inference
mxinden Nov 15, 2021
1562159
examples: Help type inference
mxinden Nov 15, 2021
d11a4ed
protocols/.*/examples: Run cargo fix
mxinden Nov 15, 2021
03ef106
*: Run cargo fmt
mxinden Nov 15, 2021
8415ba2
src/tutorial: Fix type inference
mxinden Nov 15, 2021
9ada868
swarm/src/lib: Help type inference
mxinden Nov 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature
instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature
lazy_static = "1.2"
libp2p-core = { version = "0.30.0", path = "core", default-features = false }
libp2p-floodsub = { version = "0.31.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.33.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.31.0", path = "protocols/identify", optional = true }
libp2p-floodsub = { version = "0.32.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.34.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.32.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.33.0", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.1.0", path = "misc/metrics", optional = true }
libp2p-metrics = { version = "0.2.0", path = "misc/metrics", optional = true }
libp2p-mplex = { version = "0.30.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.33.0", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.31.0", path = "protocols/ping", optional = true }
libp2p-ping = { version = "0.32.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.30.0", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.4.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.1.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.13.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.31.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.25.0", path = "swarm-derive" }
libp2p-relay = { version = "0.5.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.2.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.14.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.32.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.26.0", path = "swarm-derive" }
libp2p-uds = { version = "0.30.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.30.0", path = "transports/wasm-ext", default-features = false, optional = true }
libp2p-yamux = { version = "0.34.0", path = "muxers/yamux", optional = true }
Expand All @@ -99,7 +99,7 @@ smallvec = "1.6.1"
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.30.0", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.30.0", path = "transports/dns", optional = true, default-features = false }
libp2p-mdns = { version = "0.32.0", path = "protocols/mdns", optional = true }
libp2p-mdns = { version = "0.33.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.30.0", path = "transports/tcp", default-features = false, optional = true }
libp2p-websocket = { version = "0.32.0", path = "transports/websocket", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use libp2p::{
mdns::{Mdns, MdnsEvent},
mplex,
noise,
swarm::{NetworkBehaviourEventProcess, SwarmBuilder, SwarmEvent},
swarm::{dial_opts::DialOpts, NetworkBehaviourEventProcess, SwarmBuilder, SwarmEvent},
// `TokioTcpConfig` is available through the `tcp-tokio` feature.
tcp::TokioTcpConfig,
Multiaddr,
Expand Down Expand Up @@ -148,7 +148,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Reach out to another node if specified
if let Some(to_dial) = std::env::args().nth(1) {
let addr: Multiaddr = to_dial.parse()?;
swarm.dial_addr(addr)?;
swarm.dial(addr)?;
println!("Dialed {:?}", to_dial)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Reach out to another node if specified
if let Some(to_dial) = std::env::args().nth(1) {
let addr: Multiaddr = to_dial.parse()?;
swarm.dial_addr(addr)?;
swarm.dial(addr)?;
println!("Dialed {:?}", to_dial)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/file-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ mod network {
.add_address(&peer_id, peer_addr.clone());
match self
.swarm
.dial_addr(peer_addr.with(Protocol::P2p(peer_id.into())))
.dial(peer_addr.with(Protocol::P2p(peer_id.into())))
{
Ok(()) => {
self.pending_dial.insert(peer_id, sender);
Expand Down
15 changes: 6 additions & 9 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use libp2p::gossipsub::MessageId;
use libp2p::gossipsub::{
GossipsubEvent, GossipsubMessage, IdentTopic as Topic, MessageAuthenticity, ValidationMode,
};
use libp2p::{gossipsub, identity, swarm::SwarmEvent, PeerId};
use libp2p::{gossipsub, identity, swarm::SwarmEvent, Multiaddr, PeerId};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::time::Duration;
Expand Down Expand Up @@ -122,14 +122,11 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Reach out to another node if specified
if let Some(to_dial) = std::env::args().nth(1) {
let dialing = to_dial.clone();
match to_dial.parse() {
Ok(to_dial) => match swarm.dial_addr(to_dial) {
Ok(_) => println!("Dialed {:?}", dialing),
Err(e) => println!("Dial {:?} failed: {:?}", dialing, e),
},
Err(err) => println!("Failed to parse address to dial: {:?}", err),
}
let address: Multiaddr = to_dial.parse().expect("User to provide valid address.");
match swarm.dial(address.clone()) {
Ok(_) => println!("Dialed {:?}", address),
Err(e) => println!("Dial {:?} failed: {:?}", address, e),
};
}

// Read full lines from stdin
Expand Down
2 changes: 1 addition & 1 deletion examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Reach out to other nodes if specified
for to_dial in std::env::args().skip(1) {
let addr: Multiaddr = parse_legacy_multiaddr(&to_dial)?;
swarm.dial_addr(addr)?;
swarm.dial(addr)?;
println!("Dialed {:?}", to_dial)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
use futures::executor::block_on;
use futures::prelude::*;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::{identity, ping, PeerId};
use libp2p::{identity, ping, Multiaddr, PeerId};
use std::error::Error;
use std::task::Poll;

Expand All @@ -70,8 +70,8 @@ fn main() -> Result<(), Box<dyn Error>> {
// Dial the peer identified by the multi-address given as the second
// command-line argument, if any.
if let Some(addr) = std::env::args().nth(1) {
let remote = addr.parse()?;
swarm.dial_addr(remote)?;
let remote: Multiaddr = addr.parse()?;
swarm.dial(remote)?;
println!("Dialed {}", addr)
}

Expand Down
4 changes: 4 additions & 0 deletions misc/metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.2.0 [unreleased]

- Update dependencies.

## Version 0.1.0 [2021-11-01]

- Add initial version.
12 changes: 6 additions & 6 deletions misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-metrics"
edition = "2018"
description = "Metrics for libp2p"
version = "0.1.0"
version = "0.2.0"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -15,11 +15,11 @@ kad = ["libp2p-kad"]
ping = ["libp2p-ping"]

[dependencies]
libp2p-core= { version = "0.30.0", path = "../../core" }
libp2p-identify = { version = "0.31.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.33.0", path = "../../protocols/kad", optional = true }
libp2p-ping = { version = "0.31.0", path = "../../protocols/ping", optional = true }
libp2p-swarm = { version = "0.31.0", path = "../../swarm" }
libp2p-core = { version = "0.30.0", path = "../../core" }
libp2p-identify = { version = "0.32.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.33.0", path = "../../protocols/kad", optional = true }
libp2p-ping = { version = "0.32.0", path = "../../protocols/ping", optional = true }
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
open-metrics-client = "0.12.0"

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions misc/metrics/examples/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

use futures::executor::block_on;
use futures::stream::StreamExt;
use libp2p::core::Multiaddr;
use libp2p::metrics::{Metrics, Recorder};
use libp2p::ping::{Ping, PingConfig};
use libp2p::swarm::SwarmEvent;
Expand All @@ -74,8 +75,8 @@ fn main() -> Result<(), Box<dyn Error>> {
);
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
if let Some(addr) = std::env::args().nth(1) {
let remote = addr.parse()?;
swarm.dial_addr(remote)?;
let remote: Multiaddr = addr.parse()?;
swarm.dial(remote)?;
tide::log::info!("Dialed {}", addr)
}

Expand Down
4 changes: 4 additions & 0 deletions protocols/floodsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.32.0 [unreleased]

- Update dependencies.

# 0.31.0 [2021-11-01]

- Make default features of `libp2p-core` optional.
Expand Down
4 changes: 2 additions & 2 deletions protocols/floodsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-floodsub"
edition = "2018"
description = "Floodsub protocol for libp2p"
version = "0.31.0"
version = "0.32.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -14,7 +14,7 @@ cuckoofilter = "0.5.0"
fnv = "1.0"
futures = "0.3.1"
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
libp2p-swarm = { version = "0.31.0", path = "../../swarm" }
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
log = "0.4"
prost = "0.9"
rand = "0.7"
Expand Down
18 changes: 10 additions & 8 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use cuckoofilter::{CuckooError, CuckooFilter};
use fnv::FnvHashSet;
use libp2p_core::{connection::ConnectionId, PeerId};
use libp2p_swarm::{
DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, OneShotHandler,
PollParameters,
dial_opts::{self, DialOpts},
NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, OneShotHandler, PollParameters,
};
use log::warn;
use smallvec::SmallVec;
Expand Down Expand Up @@ -107,9 +107,10 @@ impl Floodsub {

if self.target_peers.insert(peer_id) {
let handler = self.new_handler();
self.events.push_back(NetworkBehaviourAction::DialPeer {
peer_id,
condition: DialPeerCondition::Disconnected,
self.events.push_back(NetworkBehaviourAction::Dial {
opts: DialOpts::peer_id(peer_id)
.condition(dial_opts::PeerCondition::Disconnected)
.build(),
handler,
});
}
Expand Down Expand Up @@ -310,9 +311,10 @@ impl NetworkBehaviour for Floodsub {
// try to reconnect.
if self.target_peers.contains(id) {
let handler = self.new_handler();
self.events.push_back(NetworkBehaviourAction::DialPeer {
peer_id: *id,
condition: DialPeerCondition::Disconnected,
self.events.push_back(NetworkBehaviourAction::Dial {
opts: DialOpts::peer_id(*id)
.condition(dial_opts::PeerCondition::Disconnected)
.build(),
handler,
});
}
Expand Down
4 changes: 3 additions & 1 deletion protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# 0.33.1 [unreleased]
# 0.34.0 [unreleased]

- Fix bug in internal peer's topics tracking (see [PR 2325]).

- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]).

- Update dependencies.

[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245
[PR 2325]: https://github.com/libp2p/rust-libp2p/pull/2325

Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
name = "libp2p-gossipsub"
edition = "2018"
description = "Gossipsub protocol for libp2p"
version = "0.33.1"
version = "0.34.0"
authors = ["Age Manning <Age@AgeManning.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
libp2p-swarm = { version = "0.31.0", path = "../../swarm" }
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
bytes = "1.0"
byteorder = "1.3.4"
Expand Down
18 changes: 10 additions & 8 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use libp2p_core::{
multiaddr::Protocol::Ip6, ConnectedPoint, Multiaddr, PeerId,
};
use libp2p_swarm::{
DialPeerCondition, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction,
NotifyHandler, PollParameters,
dial_opts::{self, DialOpts},
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
};

use crate::config::{GossipsubConfig, ValidationMode};
Expand Down Expand Up @@ -1046,9 +1046,10 @@ where
// Connect to peer
debug!("Connecting to explicit peer {:?}", peer_id);
let handler = self.new_handler();
self.events.push_back(NetworkBehaviourAction::DialPeer {
peer_id: *peer_id,
condition: DialPeerCondition::Disconnected,
self.events.push_back(NetworkBehaviourAction::Dial {
opts: DialOpts::peer_id(*peer_id)
.condition(dial_opts::PeerCondition::Disconnected)
.build(),
handler,
});
}
Expand Down Expand Up @@ -1502,9 +1503,10 @@ where

// dial peer
let handler = self.new_handler();
self.events.push_back(NetworkBehaviourAction::DialPeer {
peer_id,
condition: DialPeerCondition::Disconnected,
self.events.push_back(NetworkBehaviourAction::Dial {
opts: DialOpts::peer_id(peer_id)
.condition(dial_opts::PeerCondition::Disconnected)
.build(),
handler,
});
}
Expand Down