Skip to content

Commit

Permalink
feat(network): enable dcutr
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Jan 7, 2025
1 parent 7af69db commit ecd4ce5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions ant-networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ hyper = { version = "0.14", features = [
itertools = "~0.12.1"
lazy_static = "~1.4.0"
libp2p = { version = "0.54.1", features = [
"dcutr",
"tokio",
"dns",
"kad",
Expand Down
2 changes: 2 additions & 0 deletions ant-networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ pub(super) struct NodeBehaviour {
pub(super) upnp: libp2p::swarm::behaviour::toggle::Toggle<libp2p::upnp::tokio::Behaviour>,
pub(super) relay_client: libp2p::relay::client::Behaviour,
pub(super) relay_server: libp2p::relay::Behaviour,
pub(super) dcutr: libp2p::dcutr::Behaviour,
pub(super) kademlia: kad::Behaviour<UnifiedRecordStore>,
pub(super) request_response: request_response::cbor::Behaviour<Request, Response>,
}
Expand Down Expand Up @@ -683,6 +684,7 @@ impl NetworkBuilder {
#[cfg(feature = "upnp")]
upnp,
request_response,
dcutr: libp2p::dcutr::Behaviour::new(peer_id),
kademlia,
identify,
#[cfg(feature = "local")]
Expand Down
7 changes: 7 additions & 0 deletions ant-networking/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ pub(super) enum NodeEvent {
#[cfg(feature = "local")]
Mdns(Box<mdns::Event>),
Identify(Box<libp2p::identify::Event>),
Dcutr(Box<libp2p::dcutr::Event>),
RelayClient(Box<libp2p::relay::client::Event>),
RelayServer(Box<libp2p::relay::Event>),
Void(void::Void),
}

impl From<libp2p::dcutr::Event> for NodeEvent {
fn from(event: libp2p::dcutr::Event) -> Self {
NodeEvent::Dcutr(Box::new(event))
}
}

#[cfg(feature = "upnp")]
impl From<libp2p::upnp::Event> for NodeEvent {
fn from(event: libp2p::upnp::Event) -> Self {
Expand Down
12 changes: 12 additions & 0 deletions ant-networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ impl SwarmDriver {
}
}
}
SwarmEvent::Behaviour(NodeEvent::Dcutr(event)) => {
#[cfg(feature = "open-metrics")]
if let Some(metrics) = &self.metrics_recorder {
metrics.record(&(*event));
}

event_string = "dcutr_event";
info!(
"Dcutr with remote peer: {:?} is: {:?}",
event.remote_peer_id, event.result
);
}
#[cfg(feature = "upnp")]
SwarmEvent::Behaviour(NodeEvent::Upnp(upnp_event)) => {
#[cfg(feature = "open-metrics")]
Expand Down
6 changes: 6 additions & 0 deletions ant-networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,9 @@ impl<T> Recorder<libp2p::swarm::SwarmEvent<T>> for NetworkMetricsRecorder {
self.libp2p_metrics.record(event);
}
}

impl Recorder<libp2p::dcutr::Event> for NetworkMetricsRecorder {
fn record(&self, event: &libp2p::dcutr::Event) {
self.libp2p_metrics.record(event)
}
}

0 comments on commit ecd4ce5

Please sign in to comment.