Skip to content

Commit

Permalink
identify: emit when identified new peer; add changelog entries and ve…
Browse files Browse the repository at this point in the history
…rsions
  • Loading branch information
StemCll committed Dec 17, 2023
1 parent 88833e9 commit 5db6dec
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ asynchronous-codec = { version = "0.7.0" }
futures-bounded = { version = "0.2.3", path = "misc/futures-bounded" }
libp2p = { version = "0.53.2", path = "libp2p" }
libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" }
libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" }
libp2p-autonat = { version = "0.12.1", path = "protocols/autonat" }
libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" }
libp2p-core = { version = "0.41.2", path = "core" }
libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" }
libp2p-dns = { version = "0.41.1", path = "transports/dns" }
libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" }
libp2p-gossipsub = { version = "0.46.1", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.44.1", path = "protocols/identify" }
libp2p-identify = { version = "0.45.0", path = "protocols/identify" }
libp2p-identity = { version = "0.2.8" }
libp2p-kad = { version = "0.45.3", path = "protocols/kad" }
libp2p-mdns = { version = "0.45.1", path = "protocols/mdns" }
Expand All @@ -97,10 +97,10 @@ libp2p-pnet = { version = "0.24.0", path = "transports/pnet" }
libp2p-quic = { version = "0.10.2", path = "transports/quic" }
libp2p-relay = { version = "0.17.1", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" }
libp2p-request-response = { version = "0.26.1", path = "protocols/request-response" }
libp2p-request-response = { version = "0.27.0", path = "protocols/request-response" }
libp2p-server = { version = "0.12.5", path = "misc/server" }
libp2p-swarm = { version = "0.44.1", path = "swarm" }
libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
libp2p-swarm = { version = "0.44.2", path = "swarm" }
libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" }
libp2p-tcp = { version = "0.41.0", path = "transports/tcp" }
libp2p-tls = { version = "0.3.0", path = "transports/tls" }
Expand Down
5 changes: 5 additions & 0 deletions protocols/autonat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.12.1 - unreleased

- Allow temporary use of deprecated `libp2p_request_response::add_address`.
See [PR 4371](https://github.com/libp2p/rust-libp2p/pull/4371)

## 0.12.0

- Remove `Clone`, `PartialEq` and `Eq` implementations on `Event` and its sub-structs.
Expand Down
2 changes: 1 addition & 1 deletion protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "libp2p-autonat"
edition = "2021"
rust-version = { workspace = true }
description = "NAT and firewall detection for libp2p"
version = "0.12.0"
authors = ["David Craven <[email protected]>", "Elena Frank <[email protected]>"]
version = "0.12.1"
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
Expand Down
5 changes: 5 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.45.0 - unreleased

- Emit `ToSwarm::NewExternalAddrOfPeer` when identified new peer. `PeerCache` uses `libp2p_swarm::PeerAddresses`
See [PR 4371](https://github.com/libp2p/rust-libp2p/pull/4371)

## 0.44.1

- Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated.
Expand Down
2 changes: 1 addition & 1 deletion protocols/identify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-identify"
edition = "2021"
rust-version = { workspace = true }
description = "Nodes identifcation protocol for libp2p"
version = "0.44.1"
version = "0.45.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
74 changes: 73 additions & 1 deletion protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,19 @@ impl NetworkBehaviour for Behaviour {

let observed = info.observed_addr.clone();
self.events
.push_back(ToSwarm::GenerateEvent(Event::Received { peer_id, info }));
.push_back(ToSwarm::GenerateEvent(Event::Received {
peer_id,
info: info.clone(),
}));

filter_new_external_addrs(&self.discovered_peers.get(&peer_id), &info.listen_addrs)
.iter()
.for_each(|address| {
self.events.push_back(ToSwarm::NewExternalAddrOfPeer {
peer_id,
addr: address.clone(),
})
});

match self.our_observed_addresses.entry(id) {
Entry::Vacant(not_yet_observed) => {
Expand Down Expand Up @@ -444,6 +456,20 @@ fn multiaddr_matches_peer_id(addr: &Multiaddr, peer_id: &PeerId) -> bool {
true
}

fn filter_new_external_addrs(
cached_addrs: &[Multiaddr],
listen_addrs: &Vec<Multiaddr>,
) -> Vec<Multiaddr> {
let mut new_addresses = Vec::<Multiaddr>::new();

for address in listen_addrs {
if !cached_addrs.contains(address) {
new_addresses.push(address.clone());
}
}
new_addresses
}

struct PeerCache(Option<PeerAddresses>);

impl PeerCache {
Expand Down Expand Up @@ -495,4 +521,50 @@ mod tests {
));
assert!(multiaddr_matches_peer_id(&addr_without_peer_id, &peer_id));
}

#[test]
fn filter_new_external_addrs_leaves_new_addrs() {
let addr: Multiaddr = "/ip4/147.75.69.143/tcp/4001"
.parse()
.expect("failed to parse multiaddr");

let addr1: Multiaddr = "/ip4/147.75.69.143/tcp/4002"
.parse()
.expect("failed to parse multiaddr");

let old_addr: Multiaddr = "/memory/1234".parse().unwrap();
let old_addr1: Multiaddr = "/memory/1233".parse().unwrap();
let old_addr2: Multiaddr = "/memory/1235".parse().unwrap();

let old_addrs: Vec<Multiaddr> = [old_addr, old_addr1, old_addr2].to_vec();

let new_addrs = Vec::from([addr, addr1]);

assert_eq!(
filter_new_external_addrs(&old_addrs, &new_addrs),
new_addrs.clone(),
);
}

#[test]
fn filter_new_external_addrs_filter_duplicates() {
let addr: Multiaddr = "/ip4/147.75.69.143/tcp/4001"
.parse()
.expect("failed to parse multiaddr");

let addr1: Multiaddr = "/ip4/147.75.69.143/tcp/4002"
.parse()
.expect("failed to parse multiaddr");

let old_addr: Multiaddr = "/memory/1234".parse().unwrap();
let old_addr1: Multiaddr = "/memory/1233".parse().unwrap();
let old_addr2: Multiaddr = "/memory/1235".parse().unwrap();

let mut old_addrs: Vec<Multiaddr> = [old_addr, old_addr1, old_addr2].to_vec();

let new_addrs = Vec::from([addr.clone(), addr1.clone()]);
old_addrs.append(&mut new_addrs.clone());

assert_eq!(filter_new_external_addrs(&old_addrs, &new_addrs), [])
}
}
5 changes: 5 additions & 0 deletions protocols/request-response/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.27.0 - unreleased

- Deprecate `libp2p_request_response::add_address`. `Behaviour` `addresses` field uses `libp2p_swarm::PeerAddresses`.
See [PR 4371](https://github.com/libp2p/rust-libp2p/pull/4371)

## 0.26.1

- Derive `PartialOrd` and `Ord` for `{Out,In}boundRequestId`.
Expand Down
6 changes: 3 additions & 3 deletions protocols/request-response/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-request-response"
edition = "2021"
rust-version = { workspace = true }
description = "Generic Request/Response Protocols"
version = "0.26.1"
version = "0.27.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -19,7 +19,7 @@ libp2p-core = { workspace = true }
libp2p-swarm = { workspace = true }
libp2p-identity = { workspace = true }
rand = "0.8"
serde = { version = "1.0", optional = true}
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0.108", optional = true }
smallvec = "1.11.2"
tracing = "0.1.37"
Expand All @@ -40,7 +40,7 @@ libp2p-yamux = { workspace = true }
rand = "0.8"
libp2p-swarm-test = { path = "../../swarm-test" }
futures_ringbuf = "0.4.0"
serde = { version = "1.0", features = ["derive"]}
serde = { version = "1.0", features = ["derive"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# Passing arguments to the docsrs builder in order to properly document cfg's.
Expand Down
2 changes: 1 addition & 1 deletion swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-swarm"
edition = "2021"
rust-version = { workspace = true }
description = "The libp2p swarm"
version = "0.44.1"
version = "0.44.2"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down

0 comments on commit 5db6dec

Please sign in to comment.