Skip to content

Commit

Permalink
subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
elenaf9 committed Sep 17, 2022
2 parents 41d39fb + 2025de3 commit 4c617a0
Show file tree
Hide file tree
Showing 43 changed files with 325 additions and 435 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@

# `libp2p` facade crate

# 0.49.0 - [unreleased]

- Update to [`libp2p-tcp` `v0.37.0`](transports/tcp/CHANGELOG.md#0370).

- Update to [`libp2p-swarm-derive` `v0.30.1`](swarm-derive/CHANGELOG.md#0301).

- Update to [`libp2p-metrics` `v0.10.0`](misc/metrics/CHANGELOG.md#0100).

- Update to [`libp2p-kad` `v0.41.0`](protocols/kad/CHANGELOG.md#0410).

# 0.48.0

- Update to [`libp2p-core` `v0.36.0`](core/CHANGELOG.md#0360).
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p"
edition = "2021"
rust-version = "1.60.0"
description = "Peer-to-peer networking library"
version = "0.48.0"
version = "0.49.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -87,18 +87,18 @@ libp2p-core = { version = "0.36.0", path = "core", default-features = false }
libp2p-dcutr = { version = "0.6.0", path = "protocols/dcutr", optional = true }
libp2p-floodsub = { version = "0.39.0", path = "protocols/floodsub", optional = true }
libp2p-identify = { version = "0.39.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.40.0", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.9.0", path = "misc/metrics", optional = true }
libp2p-kad = { version = "0.41.0", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.10.0", path = "misc/metrics", optional = true }
libp2p-mplex = { version = "0.36.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.39.0", path = "transports/noise", optional = true }
libp2p-noise = { version = "0.39.1", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.39.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.36.0", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.12.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.9.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.21.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.39.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.30.0", path = "swarm-derive" }
libp2p-swarm-derive = { version = "0.30.1", path = "swarm-derive" }
libp2p-uds = { version = "0.35.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.36.0", path = "transports/wasm-ext", default-features = false, optional = true }
libp2p-yamux = { version = "0.40.0", path = "muxers/yamux", optional = true }
Expand All @@ -113,7 +113,7 @@ libp2p-deflate = { version = "0.36.0", path = "transports/deflate", optional = t
libp2p-dns = { version = "0.36.0", path = "transports/dns", optional = true, default-features = false }
libp2p-mdns = { version = "0.40.0", path = "protocols/mdns", optional = true, default-features = false }
libp2p-quic = { version = "0.7.0", path = "transports/quic", optional = true }
libp2p-tcp = { version = "0.36.0", path = "transports/tcp", default-features = false, optional = true }
libp2p-tcp = { version = "0.37.0", path = "transports/tcp", default-features = false, optional = true }
libp2p-websocket = { version = "0.38.0", path = "transports/websocket", optional = true }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ring = { version = "0.16.9", features = ["alloc", "std"], default-features = fal
[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
base64 = "0.13.0"
criterion = "0.3"
criterion = "0.4"
libp2p-mplex = { path = "../muxers/mplex" }
libp2p-noise = { path = "../transports/noise" }
libp2p-tcp = { path = "../transports/tcp" }
Expand Down
10 changes: 2 additions & 8 deletions core/tests/transport_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ where
fn upgrade_pipeline() {
let listener_keys = identity::Keypair::generate_ed25519();
let listener_id = listener_keys.public().to_peer_id();
let listener_noise_keys = noise::Keypair::<noise::X25519Spec>::new()
.into_authentic(&listener_keys)
.unwrap();
let mut listener_transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(listener_noise_keys).into_authenticated())
.authenticate(noise::NoiseAuthenticated::xx(&listener_keys).unwrap())
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
Expand All @@ -93,12 +90,9 @@ fn upgrade_pipeline() {

let dialer_keys = identity::Keypair::generate_ed25519();
let dialer_id = dialer_keys.public().to_peer_id();
let dialer_noise_keys = noise::Keypair::<noise::X25519Spec>::new()
.into_authentic(&dialer_keys)
.unwrap();
let mut dialer_transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(dialer_noise_keys).into_authenticated())
.authenticate(noise::NoiseAuthenticated::xx(&dialer_keys).unwrap())
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
Expand Down
10 changes: 4 additions & 6 deletions examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
let peer_id = PeerId::from(id_keys.public());
println!("Local peer id: {:?}", peer_id);

// Create a keypair for authenticated encryption of the transport.
let noise_keys = noise::Keypair::<noise::X25519Spec>::new()
.into_authentic(&id_keys)
.expect("Signing libp2p-noise static DH keypair failed.");

// Create a tokio-based TCP transport use noise for authenticated
// encryption and Mplex for multiplexing of substreams on a TCP stream.
let transport = TokioTcpTransport::new(GenTcpConfig::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
.authenticate(
noise::NoiseAuthenticated::xx(&id_keys)
.expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(mplex::MplexConfig::new())
.boxed();

Expand Down
5 changes: 1 addition & 4 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ 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();
let noise_config = noise::NoiseConfig::xx(noise_keys).into_authenticated();
let noise_config = noise::NoiseAuthenticated::xx(&key_pair).unwrap();
let yamux_config = YamuxConfig::default();

let base_transport = TcpTransport::new(GenTcpConfig::default().nodelay(true));
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 @@
# 0.10.0 [unreleased]

- Update to `libp2p-kad` `v0.41.0`.

# 0.9.0

- Update to `libp2p-swarm` `v0.39.0`.
Expand Down
6 changes: 3 additions & 3 deletions misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-metrics"
edition = "2021"
rust-version = "1.56.1"
description = "Metrics for libp2p"
version = "0.9.0"
version = "0.10.0"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -22,7 +22,7 @@ dcutr = ["libp2p-dcutr"]
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
libp2p-dcutr = { version = "0.6.0", path = "../../protocols/dcutr", optional = true }
libp2p-identify = { version = "0.39.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.40.0", path = "../../protocols/kad", optional = true }
libp2p-kad = { version = "0.41.0", path = "../../protocols/kad", optional = true }
libp2p-ping = { version = "0.39.0", path = "../../protocols/ping", optional = true }
libp2p-relay = { version = "0.12.0", path = "../../protocols/relay", optional = true }
libp2p-swarm = { version = "0.39.0", path = "../../swarm" }
Expand All @@ -33,7 +33,7 @@ libp2p-gossipsub = { version = "0.41.0", path = "../../protocols/gossipsub", op

[dev-dependencies]
log = "0.4.0"
env_logger = "0.8.1"
env_logger = "0.9.0"
futures = "0.3.1"
libp2p = { path = "../../", default-features = false, features = ["metrics", "ping", "tcp-async-io", "dns-async-std", "websocket", "noise", "mplex", "yamux"] }
hyper = { version="0.14", features = ["server", "tcp", "http1"] }
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }

[dev-dependencies]
async-std = "1.7.0"
criterion = "0.3"
criterion = "0.4"
env_logger = "0.9"
futures = "0.3"
libp2p-tcp = { path = "../../transports/tcp" }
Expand Down
2 changes: 1 addition & 1 deletion protocols/dcutr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void = "1"
prost-build = "0.11"

[dev-dependencies]
env_logger = "0.8.3"
env_logger = "0.9.0"
libp2p = { path = "../..", default-features = false, features = ["dcutr", "relay", "plaintext", "identify", "tcp-async-io", "ping", "noise", "dns-async-std"] }
libp2p-identify = { path = "../identify" }
libp2p-plaintext = { path = "../../transports/plaintext" }
Expand Down
9 changes: 4 additions & 5 deletions protocols/dcutr/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ fn main() -> Result<(), Box<dyn Error>> {

let (relay_transport, client) = Client::new_transport_and_behaviour(local_peer_id);

let noise_keys = noise::Keypair::<noise::X25519Spec>::new()
.into_authentic(&local_key)
.expect("Signing libp2p-noise static DH keypair failed.");

let transport = OrTransport::new(
relay_transport,
block_on(DnsConfig::system(TcpTransport::new(
Expand All @@ -101,7 +97,10 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap(),
)
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(libp2p_yamux::YamuxConfig::default())
.boxed();

Expand Down
19 changes: 8 additions & 11 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ where
set.iter()
.filter(|p| {
self.explicit_peers.contains(*p)
|| !self.score_below_threshold(*p, |ts| ts.publish_threshold).0
|| !self.score_below_threshold(p, |ts| ts.publish_threshold).0
})
.cloned(),
);
Expand Down Expand Up @@ -946,14 +946,11 @@ where
);

// remove explicit peers, peers with negative scores, and backoffed peers
peers = peers
.into_iter()
.filter(|p| {
!self.explicit_peers.contains(p)
&& !self.score_below_threshold(p, |_| 0.0).0
&& !self.backoffs.is_backoff_with_slack(topic_hash, p)
})
.collect();
peers.retain(|p| {
!self.explicit_peers.contains(p)
&& !self.score_below_threshold(p, |_| 0.0).0
&& !self.backoffs.is_backoff_with_slack(topic_hash, p)
});

// Add up to mesh_n of them them to the mesh
// NOTE: These aren't randomly added, currently FIFO
Expand Down Expand Up @@ -1625,7 +1622,7 @@ where
//
//TODO: Once signed records are spec'd: Can we use peerInfo without any IDs if they have a
// signed peer record?
px = px.into_iter().filter(|p| p.peer_id.is_some()).collect();
px.retain(|p| p.peer_id.is_some());
if px.len() > n {
// only use at most prune_peers many random peers
let mut rng = thread_rng();
Expand Down Expand Up @@ -3204,7 +3201,7 @@ where
debug!("Peer disconnected: {}", peer_id);
{
let topics = match self.peer_topics.get(peer_id) {
Some(topics) => (topics),
Some(topics) => topics,
None => {
debug_assert!(
self.blacklisted_peers.contains(peer_id),
Expand Down
3 changes: 1 addition & 2 deletions protocols/gossipsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@
//!
//! // Set up an encrypted TCP Transport over the Mplex
//! // This is test transport (memory).
//! let noise_keys = libp2p_noise::Keypair::<libp2p_noise::X25519Spec>::new().into_authentic(&local_key).unwrap();
//! let transport = MemoryTransport::default()
//! .upgrade(libp2p_core::upgrade::Version::V1)
//! .authenticate(libp2p_noise::NoiseConfig::xx(noise_keys).into_authenticated())
//! .authenticate(libp2p_noise::NoiseAuthenticated::xx(&local_key).unwrap())
//! .multiplex(libp2p_mplex::MplexConfig::new())
//! .boxed();
//!
Expand Down
7 changes: 7 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.41.0 [unreleased]

- Remove deprecated `set_protocol_name()` from `KademliaConfig` & `KademliaProtocolConfig`.
Use `set_protocol_names()` instead. See [PR 2866].

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

# 0.40.0

- Add support for multiple protocol names. Update `Kademlia`, `KademliaConfig`,
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-kad"
edition = "2021"
rust-version = "1.56.1"
description = "Kademlia protocol for libp2p"
version = "0.40.0"
version = "0.41.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
10 changes: 0 additions & 10 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,6 @@ impl KademliaConfig {
self
}

/// Sets a custom protocol name.
///
/// Kademlia nodes only communicate with other nodes using the same protocol
/// name. Using a custom name therefore allows to segregate the DHT from
/// others, if that is desired.
#[deprecated(since = "0.40.0", note = "use `set_protocol_names()` instead")]
pub fn set_protocol_name(&mut self, name: impl Into<Cow<'static, [u8]>>) -> &mut Self {
self.set_protocol_names(std::iter::once(name.into()).collect())
}

/// Sets the timeout for a single query.
///
/// > **Note**: A single query usually comprises at least as many requests
Expand Down
5 changes: 1 addition & 4 deletions protocols/kad/src/behaviour/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ fn build_node() -> (Multiaddr, TestSwarm) {
fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) {
let local_key = identity::Keypair::generate_ed25519();
let local_public_key = local_key.public();
let noise_keys = noise::Keypair::<noise::X25519>::new()
.into_authentic(&local_key)
.unwrap();
let transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
18 changes: 2 additions & 16 deletions protocols/kad/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,7 @@ where
let pos = self
.inbound_substreams
.iter()
.position(|state| match state {
InboundSubstreamState::WaitingUser(ref conn_id, _)
if conn_id == &request_id.connec_unique_id =>
{
true
}
_ => false,
});
.position(|state| matches!(state, InboundSubstreamState::WaitingUser(ref conn_id, _) if conn_id == &request_id.connec_unique_id));

if let Some(pos) = pos {
let (conn_id, substream) = match self.inbound_substreams.remove(pos) {
Expand Down Expand Up @@ -737,14 +730,7 @@ where
let pos = self
.inbound_substreams
.iter()
.position(|state| match state {
InboundSubstreamState::WaitingUser(ref conn_id, _)
if conn_id == &request_id.connec_unique_id =>
{
true
}
_ => false,
});
.position(|state| matches!(state, InboundSubstreamState::WaitingUser(ref conn_id, _) if conn_id == &request_id.connec_unique_id));

if let Some(pos) = pos {
let (conn_id, substream) = match self.inbound_substreams.remove(pos) {
Expand Down
7 changes: 0 additions & 7 deletions protocols/kad/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ impl KademliaProtocolConfig {
self.protocol_names = names;
}

/// Sets single protocol name used on the wire. Can be used to create incompatibilities
/// between networks on purpose.
#[deprecated(since = "0.40.0", note = "use `set_protocol_names()` instead")]
pub fn set_protocol_name(&mut self, name: impl Into<Cow<'static, [u8]>>) {
self.set_protocol_names(std::iter::once(name.into()).collect());
}

/// Modifies the maximum allowed size of a single Kademlia packet.
pub fn set_max_packet_size(&mut self, size: usize) {
self.max_packet_size = size;
Expand Down
4 changes: 2 additions & 2 deletions protocols/mdns/src/behaviour/iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
socket.bind(&SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 5353).into())?;
socket.set_multicast_loop_v4(true)?;
socket.set_multicast_ttl_v4(255)?;
socket.join_multicast_v4(&*crate::IPV4_MDNS_MULTICAST_ADDRESS, &addr)?;
socket.join_multicast_v4(&crate::IPV4_MDNS_MULTICAST_ADDRESS, &addr)?;
U::from_std(UdpSocket::from(socket))?
}
IpAddr::V6(_) => {
Expand All @@ -96,7 +96,7 @@ where
socket.bind(&SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 5353).into())?;
socket.set_multicast_loop_v6(true)?;
// TODO: find interface matching addr.
socket.join_multicast_v6(&*crate::IPV6_MDNS_MULTICAST_ADDRESS, 0)?;
socket.join_multicast_v6(&crate::IPV6_MDNS_MULTICAST_ADDRESS, 0)?;
U::from_std(UdpSocket::from(socket))?
}
};
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/src/behaviour/iface/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn query_response_packet(id: u16, peer_id: &[u8], records: &[Vec<u8>], ttl: u32)
fn duration_to_secs(duration: Duration) -> u32 {
let secs = duration
.as_secs()
.saturating_add(if duration.subsec_nanos() > 0 { 1 } else { 0 });
.saturating_add(u64::from(duration.subsec_nanos() > 0));
cmp::min(secs, From::from(u32::max_value())) as u32
}

Expand Down
Loading

0 comments on commit 4c617a0

Please sign in to comment.