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

Expose API for PublicAddresses #212

Merged
merged 33 commits into from
Sep 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8502645
identify: Expose API to inject listen addresses
lexnv Aug 20, 2024
e452745
tests: Check identify public addresses are propagated
lexnv Aug 20, 2024
0e42027
listen-addr: Add listen address struct to a separate module
lexnv Aug 28, 2024
890df79
listen-addr/tests: Check listen addr interface functionality
lexnv Aug 28, 2024
59668c9
listen-addr: Use a lock guard for custom iteration over the addresses
lexnv Aug 28, 2024
56ed02a
litep2p: Store shared listenAddresses on Litep2p object
lexnv Aug 28, 2024
a4bbf06
identify: Use the new interface of public addresses
lexnv Aug 28, 2024
f2a1c51
listen-addr: Check listen address contains p2p protocol
lexnv Aug 28, 2024
67b617d
Polish up the API
lexnv Aug 28, 2024
38d8ca3
listen-addr: Register lsiten addresses with adding the local peerID
lexnv Aug 28, 2024
2a45422
Adjust testing to the new interface
lexnv Aug 28, 2024
fc0c700
Use ListenAddresses everywhere
lexnv Aug 28, 2024
7f07e9d
listen-addr: Add better documentation
lexnv Aug 28, 2024
794eba5
listen-addr: Add contains and remove partial methods
lexnv Aug 29, 2024
5e9930a
Merge remote-tracking branch 'origin/master' into lexnv/indentify-con…
lexnv Aug 29, 2024
e11a996
Rename to ExternalAddresses for clarity
lexnv Aug 30, 2024
09b6fee
Refactor and adjust testing
lexnv Sep 2, 2024
c11f468
Merge remote-tracking branch 'origin/master' into lexnv/indentify-con…
lexnv Sep 2, 2024
68c76d2
Apply fmt
lexnv Sep 2, 2024
6161233
Fix cargo doc and clippy
lexnv Sep 2, 2024
dacd665
pub-addr: Rename API methods
lexnv Sep 3, 2024
1194a29
Introduce ListenAddresses object
lexnv Sep 3, 2024
ba6e198
Use listenAddresses added interface
lexnv Sep 3, 2024
e7a7d80
identify: Use user-provided, listen and public addresses
lexnv Sep 3, 2024
9ad762b
manager: Remove transport_manager::register_listen_address
lexnv Sep 3, 2024
d0ebcd2
Adjust testing
lexnv Sep 3, 2024
41c1e23
Fix documentation
lexnv Sep 3, 2024
fd23d15
address: Introduce insertion error for better reporting
lexnv Sep 3, 2024
be8d663
Remove ListenAddresses
lexnv Sep 3, 2024
af8fe60
Adjust testing
lexnv Sep 3, 2024
39153f1
Adjust testing
lexnv Sep 3, 2024
6b7b7b1
identify: Remove public addr from list config
lexnv Sep 4, 2024
a633b68
Merge branch 'master' into lexnv/indentify-confirmed-addresses
lexnv Sep 4, 2024
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
44 changes: 20 additions & 24 deletions src/protocol/libp2p/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
//! [`/ipfs/identify/1.0.0`](https://github.com/libp2p/specs/blob/master/identify/README.md) implementation.

use crate::{
addresses::{ListenAddresses, PublicAddresses},
codec::ProtocolCodec,
crypto::PublicKey,
error::{Error, SubstreamError},
protocol::{Direction, TransportEvent, TransportService},
addresses::PublicAddresses,
substream::Substream,
transport::Endpoint,
types::{protocol::ProtocolName, SubstreamId},
PeerId, DEFAULT_CHANNEL_SIZE,
};

use futures::{future::BoxFuture, stream::FuturesUnordered, Stream, StreamExt};
use multiaddr::{Multiaddr, Protocol};
use multiaddr::Multiaddr;
use prost::Message;
use tokio::sync::mpsc::{channel, Sender};
use tokio_stream::wrappers::ReceiverStream;
Expand Down Expand Up @@ -183,8 +183,14 @@ pub(crate) struct Identify {
/// User agent.
user_agent: String,

/// Listen addresses.
listen_addresses: ListenAddresses,

/// Public addresses.
listen_addresses: PublicAddresses,
public_addresses: PublicAddresses,

/// User provided list of addresses.
user_addresses: Vec<Vec<u8>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need one more place to specify public addresses. Getting public addresses via a handle from TransportManager should be enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki doki, have removed these thanks! 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably was not quite clear on this, but I meant we don't need to let user pass addresses directly to Identify config if we already have an API to notify litep2p about public addresses.


/// Protocols supported by the local node, filled by `Litep2p`.
protocols: Vec<String>,
Expand All @@ -202,30 +208,18 @@ pub(crate) struct Identify {
impl Identify {
/// Create new [`Identify`] protocol.
pub(crate) fn new(service: TransportService, config: Config) -> Self {
let listen_addresses = service.public_addresses();

let local_peer_id = service.local_peer_id();
let filtered_public_addr = config.public_addresses.into_iter().filter_map(|address| {
if address.is_empty() {
return None;
}
if let Some(peer_id) = PeerId::try_from_multiaddr(&address) {
if peer_id != local_peer_id {
return None;
}

return Some(address);
}

Some(address.with(Protocol::P2p(local_peer_id.into())))
});
listen_addresses.inner.write().extend(filtered_public_addr);
let listen_addresses = service.listen_addresses();
let public_addresses = service.public_addresses();
let user_addresses =
config.public_addresses.into_iter().map(|addr| addr.to_vec()).collect();

Self {
service,
tx: config.tx_event,
peers: HashMap::new(),
listen_addresses,
public_addresses,
user_addresses,
public: config.public.expect("public key to be supplied"),
protocol_version: config.protocol_version,
user_agent: config.user_agent.unwrap_or(DEFAULT_AGENT.to_string()),
Expand Down Expand Up @@ -281,13 +275,15 @@ impl Identify {
}
};

let listen_addrs =
self.listen_addresses.inner.read().iter().map(|addr| addr.to_vec()).collect();
let mut listen_addr: HashSet<_> = self.user_addresses.iter().cloned().collect();
listen_addr.extend(self.listen_addresses.inner.read().iter().map(|addr| addr.to_vec()));
listen_addr.extend(self.public_addresses.inner.read().iter().map(|addr| addr.to_vec()));

let identify = identify_schema::Identify {
protocol_version: Some(self.protocol_version.clone()),
agent_version: Some(self.user_agent.clone()),
public_key: Some(self.public.to_protobuf_encoding()),
listen_addrs,
listen_addrs: listen_addr.into_iter().collect(),
observed_addr,
protocols: self.protocols.clone(),
};
Expand Down