Skip to content

Commit

Permalink
Remove is_local
Browse files Browse the repository at this point in the history
  • Loading branch information
umgefahren committed Dec 30, 2023
1 parent 8a135ea commit fac1196
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 261 deletions.
1 change: 0 additions & 1 deletion protocols/autonat/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use libp2p_swarm::StreamProtocol;

pub mod client;
mod generated;
mod global_only;
pub(crate) mod protocol;
pub mod server;

Expand Down
16 changes: 3 additions & 13 deletions protocols/autonat/src/v2/client/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use either::Either;
use futures::FutureExt;
use futures_timer::Delay;
use libp2p_core::{multiaddr::Protocol, transport::PortUse, Endpoint, Multiaddr};
use libp2p_core::{transport::PortUse, Endpoint, Multiaddr};
use libp2p_identity::PeerId;
use libp2p_swarm::{
behaviour::ConnectionEstablished, ConnectionClosed, ConnectionDenied, ConnectionHandler,
Expand All @@ -17,7 +17,7 @@ use rand::prelude::*;
use rand_core::OsRng;
use std::fmt::{Debug, Display, Formatter};

use crate::v2::{global_only::IpExt, protocol::DialRequest, Nonce};
use crate::v2::{protocol::DialRequest, Nonce};

use super::handler::{dial_back, dial_request};

Expand Down Expand Up @@ -112,15 +112,14 @@ where
FromSwarm::ConnectionEstablished(ConnectionEstablished {
peer_id,
connection_id,
endpoint,
endpoint: _,
..
}) => {
self.peer_info.insert(
connection_id,
ConnectionInfo {
peer_id,
supports_autonat: false,
is_local: addr_is_local(endpoint.get_remote_address()),
},
);
}
Expand Down Expand Up @@ -392,18 +391,9 @@ pub struct Event {
pub result: Result<(), Error>,
}

fn addr_is_local(addr: &Multiaddr) -> bool {
addr.iter().any(|c| match c {
Protocol::Ip4(ip) => !IpExt::is_global(&ip),
Protocol::Ip6(ip) => !IpExt::is_global(&ip),
_ => false,
})
}

struct ConnectionInfo {
peer_id: PeerId,
supports_autonat: bool,
is_local: bool,
}

#[derive(Copy, Clone, Default)]
Expand Down
247 changes: 0 additions & 247 deletions protocols/autonat/src/v2/global_only.rs

This file was deleted.

0 comments on commit fac1196

Please sign in to comment.