Skip to content

Commit

Permalink
Rename the type DirectAddr
Browse files Browse the repository at this point in the history
This is more in line with other Addrs, e.g. SocketAddr.
  • Loading branch information
flub committed Jun 17, 2024
1 parent 0f82f5c commit 32893e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
6 changes: 3 additions & 3 deletions iroh-gossip/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type ProtoMessage = proto::Message<PublicKey>;
#[derive(Debug, Clone)]
pub struct Gossip {
to_actor_tx: mpsc::Sender<ToActor>,
on_direct_addrs_tx: mpsc::Sender<Vec<iroh_net::endpoint::DirectAddress>>,
on_direct_addrs_tx: mpsc::Sender<Vec<iroh_net::endpoint::DirectAddr>>,
_actor_handle: Arc<JoinHandle<anyhow::Result<()>>>,
max_message_size: usize,
}
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Gossip {
/// This is only best effort, and will drop new events if backed up.
pub fn update_direct_addresses(
&self,
addrs: &[iroh_net::endpoint::DirectAddress],
addrs: &[iroh_net::endpoint::DirectAddr],
) -> anyhow::Result<()> {
let addrs = addrs.to_vec();
self.on_direct_addrs_tx
Expand Down Expand Up @@ -345,7 +345,7 @@ struct Actor {
/// Input events to the state (emitted from the connection loops)
in_event_rx: mpsc::Receiver<InEvent>,
/// Updates of discovered endpoint addresses
on_direct_addr_rx: mpsc::Receiver<Vec<iroh_net::endpoint::DirectAddress>>,
on_direct_addr_rx: mpsc::Receiver<Vec<iroh_net::endpoint::DirectAddr>>,
/// Queued timers
timers: Timers<Timer>,
/// Currently opened quinn connections to peers
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub use quinn::{
};

pub use super::magicsock::{
ConnectionInfo, ConnectionType, ConnectionTypeStream, ControlMsg, DirectAddrInfo,
DirectAddress, DirectAddressType, DirectAdressesStream,
ConnectionInfo, ConnectionType, ConnectionTypeStream, ControlMsg, DirectAddr, DirectAddrInfo,
DirectAddrType, DirectAdressesStream,
};

pub use iroh_base::node_addr::{AddrInfo, NodeAddr};
Expand Down
56 changes: 26 additions & 30 deletions iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ pub struct DirectAdressesStream {
}

impl Stream for DirectAdressesStream {
type Item = Vec<DirectAddress>;
type Item = Vec<DirectAddr>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = &mut *self;
Expand Down Expand Up @@ -1582,7 +1582,7 @@ enum DiscoBoxError {
type RelayRecvResult = Result<(PublicKey, quinn_udp::RecvMeta, Bytes), io::Error>;

/// Reports whether x and y represent the same set of endpoints. The order doesn't matter.
fn endpoint_sets_equal(xs: &[DirectAddress], ys: &[DirectAddress]) -> bool {
fn endpoint_sets_equal(xs: &[DirectAddr], ys: &[DirectAddr]) -> bool {
if xs.is_empty() && ys.is_empty() {
return true;
}
Expand All @@ -1598,7 +1598,7 @@ fn endpoint_sets_equal(xs: &[DirectAddress], ys: &[DirectAddress]) -> bool {
return true;
}
}
let mut m: HashMap<&DirectAddress, usize> = HashMap::new();
let mut m: HashMap<&DirectAddr, usize> = HashMap::new();
for x in xs {
*m.entry(x).or_default() |= 1;
}
Expand Down Expand Up @@ -1962,7 +1962,7 @@ impl Actor {
#[allow(clippy::map_entry)]
if !$already.contains_key(&$ipp) {
$already.insert($ipp, $et);
$eps.push(DirectAddress {
$eps.push(DirectAddr {
addr: $ipp,
typ: $et,
});
Expand All @@ -1973,13 +1973,13 @@ impl Actor {
let maybe_port_mapped = *portmap_watcher.borrow();

if let Some(portmap_ext) = maybe_port_mapped.map(SocketAddr::V4) {
add_addr!(already, eps, portmap_ext, DirectAddressType::Portmapped);
add_addr!(already, eps, portmap_ext, DirectAddrType::Portmapped);
self.set_net_info_have_port_map().await;
}

if let Some(nr) = nr {
if let Some(global_v4) = nr.global_v4 {
add_addr!(already, eps, global_v4.into(), DirectAddressType::Stun);
add_addr!(already, eps, global_v4.into(), DirectAddrType::Stun);

// If they're behind a hard NAT and are using a fixed
// port locally, assume they might've added a static
Expand All @@ -1989,11 +1989,11 @@ impl Actor {
if nr.mapping_varies_by_dest_ip.unwrap_or_default() && port != 0 {
let mut addr = global_v4;
addr.set_port(port);
add_addr!(already, eps, addr.into(), DirectAddressType::Stun4LocalPort);
add_addr!(already, eps, addr.into(), DirectAddrType::Stun4LocalPort);
}
}
if let Some(global_v6) = nr.global_v6 {
add_addr!(already, eps, global_v6.into(), DirectAddressType::Stun);
add_addr!(already, eps, global_v6.into(), DirectAddrType::Stun);
}
}
let local_addr_v4 = self.pconn4.local_addr().ok();
Expand Down Expand Up @@ -2051,7 +2051,7 @@ impl Actor {
already,
eps,
SocketAddr::new(ip, port),
DirectAddressType::Local
DirectAddrType::Local
);
}
}
Expand All @@ -2061,7 +2061,7 @@ impl Actor {
already,
eps,
SocketAddr::new(ip, port),
DirectAddressType::Local
DirectAddrType::Local
);
}
}
Expand All @@ -2073,15 +2073,15 @@ impl Actor {
if let Some(addr) = local_addr_v4 {
// Our local endpoint is bound to a particular address.
// Do not offer addresses on other local interfaces.
add_addr!(already, eps, addr, DirectAddressType::Local);
add_addr!(already, eps, addr, DirectAddrType::Local);
}
}

if !is_unspecified_v6 {
if let Some(addr) = local_addr_v6 {
// Our local endpoint is bound to a particular address.
// Do not offer addresses on other local interfaces.
add_addr!(already, eps, addr, DirectAddressType::Local);
add_addr!(already, eps, addr, DirectAddrType::Local);
}
}

Expand Down Expand Up @@ -2402,7 +2402,7 @@ fn bind(port: u16) -> Result<(UdpConn, Option<UdpConn>)> {
struct DiscoveredEndpoints {
/// Records the endpoints found during the previous
/// endpoint discovery. It's used to avoid duplicate endpoint change notifications.
last_endpoints: Vec<DirectAddress>,
last_endpoints: Vec<DirectAddr>,

/// The last time the endpoints were updated, even if there was no change.
last_endpoints_time: Option<Instant>,
Expand All @@ -2415,18 +2415,18 @@ impl PartialEq for DiscoveredEndpoints {
}

impl DiscoveredEndpoints {
fn new(endpoints: Vec<DirectAddress>) -> Self {
fn new(endpoints: Vec<DirectAddr>) -> Self {
Self {
last_endpoints: endpoints,
last_endpoints_time: Some(Instant::now()),
}
}

fn into_iter(self) -> impl Iterator<Item = DirectAddress> {
fn into_iter(self) -> impl Iterator<Item = DirectAddr> {
self.last_endpoints.into_iter()
}

fn iter(&self) -> impl Iterator<Item = &DirectAddress> + '_ {
fn iter(&self) -> impl Iterator<Item = &DirectAddr> + '_ {
self.last_endpoints.iter()
}

Expand Down Expand Up @@ -2592,19 +2592,19 @@ fn disco_message_sent(msg: &disco::Message) {
/// contacted. These can come from various sources depending on the network topology of the
/// iroh-net node, see [`DirectAddressType`] for the several kinds of sources.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct DirectAddress {
pub struct DirectAddr {
/// The address.
pub addr: SocketAddr,
/// The origin of this direct address.
pub typ: DirectAddressType,
pub typ: DirectAddrType,
}

/// The type of direct address.
///
/// These are the various sources or origins from which an iroh-net node might have found a
/// possible [`DirectAddress`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum DirectAddressType {
pub enum DirectAddrType {
/// Not yet determined..
Unknown,
/// A locally bound socket address.
Expand All @@ -2628,14 +2628,14 @@ pub enum DirectAddressType {
Stun4LocalPort,
}

impl Display for DirectAddressType {
impl Display for DirectAddrType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DirectAddressType::Unknown => write!(f, "?"),
DirectAddressType::Local => write!(f, "local"),
DirectAddressType::Stun => write!(f, "stun"),
DirectAddressType::Portmapped => write!(f, "portmap"),
DirectAddressType::Stun4LocalPort => write!(f, "stun4localport"),
DirectAddrType::Unknown => write!(f, "?"),
DirectAddrType::Local => write!(f, "local"),
DirectAddrType::Stun => write!(f, "stun"),
DirectAddrType::Portmapped => write!(f, "portmap"),
DirectAddrType::Stun4LocalPort => write!(f, "stun4localport"),
}
}
}
Expand Down Expand Up @@ -2773,11 +2773,7 @@ pub(crate) mod tests {
#[instrument(skip_all)]
async fn mesh_stacks(stacks: Vec<MagicStack>) -> Result<CallOnDrop> {
/// Registers endpoint addresses of a node to all other nodes.
fn update_direct_addrs(
stacks: &[MagicStack],
my_idx: usize,
new_addrs: Vec<DirectAddress>,
) {
fn update_direct_addrs(stacks: &[MagicStack], my_idx: usize, new_addrs: Vec<DirectAddr>) {
let me = &stacks[my_idx];
for (i, m) in stacks.iter().enumerate() {
if i == my_idx {
Expand Down

0 comments on commit 32893e8

Please sign in to comment.