Skip to content

feat: add support for listen addresses and filtering#136

Merged
varex83 merged 55 commits into
mainfrom
bohdan/finish-p2p
Feb 15, 2026
Merged

feat: add support for listen addresses and filtering#136
varex83 merged 55 commits into
mainfrom
bohdan/finish-p2p

Conversation

@varex83
Copy link
Copy Markdown
Collaborator

@varex83 varex83 commented Jan 26, 2026

Closes #137
Closes #138

This PR implements missing functionality in charon-p2p/p2p:

  • Adds ability to specify listen addresses via p2p config
  • Filters private peers
  • Ports multiaddr/net from go (since Rust doesn't support this). It creates trait Manet which is implemented for libp2p::multiaddr::Multiaddr, so it works like native function after importing. Original implementation could be found here also tests
  • Enables AutoNAT (small addition to PlutoBehaviour)

@varex83 varex83 self-assigned this Jan 26, 2026
@varex83 varex83 linked an issue Jan 26, 2026 that may be closed by this pull request
@varex83 varex83 changed the title feat: finish charon-p2p/p2p feat: add support for listen addresses and filtering Jan 26, 2026
@varex83 varex83 linked an issue Jan 26, 2026 that may be closed by this pull request
@emlautarom1
Copy link
Copy Markdown
Collaborator

question: Do you thing this is required for the MVP? If not, let's leave for now and focus on the current features, in particular those used by the example executables.

@varex83
Copy link
Copy Markdown
Collaborator Author

varex83 commented Jan 28, 2026

question: Do you thing this is required for the MVP? If not, let's leave for now and focus on the current features, in particular those used by the example executables.

No, as I said this PR is optional for MVP. But it's important for finishing p2p part

Base automatically changed from bohdan/p2p-peerinfo-polish to main January 30, 2026 13:14
Comment thread crates/p2p/src/p2p.rs Outdated
let filtered_addrs =
utils::filter_advertised_addresses(addrs, external_addrs, filter_private_addrs)?;

for addr in filtered_addrs {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread crates/p2p/src/utils.rs
Comment on lines +98 to +99
external_addrs.dedup();
internal_addrs.dedup();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The requirement for dedup is sorted array

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment thread crates/p2p/src/p2p.rs Outdated
}

let filtered_addrs =
utils::filter_advertised_addresses(addrs, external_addrs, filter_private_addrs)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the order seem wrong ?

The function is

pub(crate) fn filter_advertised_addresses(
    mut external_addrs: Vec<Multiaddr>,
    mut internal_addrs: Vec<Multiaddr>,
    exclude_interval_private: bool,
) -> crate::p2p::Result<Vec<Multiaddr>> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment thread crates/p2p/src/utils.rs Outdated
pub(crate) fn filter_advertised_addresses(
mut external_addrs: Vec<Multiaddr>,
mut internal_addrs: Vec<Multiaddr>,
exclude_interval_private: bool,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

exclude_internal_private

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 left a comment

Choose a reason for hiding this comment

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

A few small things before merging

  • I would look to reduce some duplication when constructing nodes with TPC/QUIC and Relay.
  • We could use some tests for the standalone functions in crates/p2p/src/utils.rs
  • Other small comments

Comment thread crates/p2p/src/behaviours/pluto.rs Outdated
Comment thread crates/p2p/src/manet.rs
Comment thread crates/p2p/src/utils.rs
Comment thread crates/p2p/src/utils.rs
Comment on lines +91 to +93
pub(crate) struct ExternalAddresses(pub Vec<Multiaddr>);

pub(crate) struct InternalAddresses(pub Vec<Multiaddr>);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't see the point on having these wrappers: we don't perform any checks so we could still mix them uo

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Since we have the same types in the function arguments, it's easy to mix them. In the meantime having those wrappers adds additional compiler check for the type.

Comment thread crates/p2p/src/utils.rs

/// Returns the default swarm configuration.
pub(crate) fn default_swarm_config(cfg: libp2p::swarm::Config) -> libp2p::swarm::Config {
cfg.with_idle_connection_timeout(Duration::from_secs(300))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From where are we getting these 5 minutes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was pretty old issue, the libp2p was dropping connections (though they were active) and by setting the idle_connection_timeout to 5 minutes solved this issue. I don't know whether we can use smaller amount, but I think since we are in a private network of validators it should be okay.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

First time hearing about it. Do you have any links/references to this issue? Is it from libp2p directly or our own code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I can't really find the discussion I was referring to, but you can take a look on this

Comment thread crates/p2p/src/utils.rs Outdated
Comment thread crates/p2p/src/p2p.rs
@varex83 varex83 merged commit e8b996e into main Feb 15, 2026
5 checks passed
@varex83 varex83 deleted the bohdan/finish-p2p branch February 15, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable autonat Add support for listen addresses and private address filtering

3 participants