Skip to content

Commit

Permalink
move relay map and mode to iroh-net
Browse files Browse the repository at this point in the history
  • Loading branch information
divagant-martian committed Nov 8, 2024
1 parent 3457409 commit aef15fb
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 149 deletions.
3 changes: 1 addition & 2 deletions iroh-net/bench/src/iroh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use bytes::Bytes;
use futures_lite::StreamExt as _;
use iroh_net::{
endpoint::{Connection, ConnectionError, RecvStream, SendStream, TransportConfig},
Endpoint, NodeAddr,
Endpoint, NodeAddr, RelayMap, RelayMode, RelayUrl,
};
use iroh_relay::{RelayMap, RelayMode, RelayUrl};
use tracing::{trace, warn};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/examples/listen-unreliable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! $ cargo run --example listen-unreliable
use anyhow::Context;
use futures_lite::StreamExt;
use iroh_net::{key::SecretKey, relay::RelayMode, Endpoint};
use iroh_net::{key::SecretKey, Endpoint, RelayMode};
use tracing::{info, warn};

// An example ALPN that we are using to communicate over the `Endpoint`
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/examples/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::time::Duration;

use anyhow::Context;
use futures_lite::StreamExt;
use iroh_net::{endpoint::ConnectionError, key::SecretKey, relay::RelayMode, Endpoint};
use iroh_net::{endpoint::ConnectionError, key::SecretKey, Endpoint, RelayMode};
use tracing::{debug, info, warn};

// An example ALPN that we are using to communicate over the `Endpoint`
Expand Down
3 changes: 2 additions & 1 deletion iroh-net/src/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Default values used in [`iroh-net`][`crate`]

use iroh_relay::{RelayMap, RelayNode};
use url::Url;

use crate::{RelayMap, RelayNode};

/// The default STUN port used by the Relay server.
///
/// The STUN port as defined by [RFC
Expand Down
6 changes: 2 additions & 4 deletions iroh-net/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,12 @@ mod tests {
time::SystemTime,
};

use iroh_relay::RelayMode;
use parking_lot::Mutex;
use rand::Rng;
use tokio_util::task::AbortOnDropHandle;

use super::*;
use crate::key::SecretKey;
use crate::{key::SecretKey, RelayMode};

#[derive(Debug, Clone, Default)]
struct TestDiscoveryShared {
Expand Down Expand Up @@ -732,7 +731,6 @@ mod test_dns_pkarr {

use anyhow::Result;
use iroh_base::key::SecretKey;
use iroh_relay::{RelayMap, RelayMode};
use tokio_util::task::AbortOnDropHandle;

use crate::{
Expand All @@ -743,7 +741,7 @@ mod test_dns_pkarr {
pkarr_dns_state::State,
run_relay_server, DnsPkarrServer,
},
AddrInfo, Endpoint, NodeAddr,
AddrInfo, Endpoint, NodeAddr, RelayMap, RelayMode,
};

const PUBLISH_TIMEOUT: Duration = Duration::from_secs(10);
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 @@ -24,7 +24,7 @@ use std::{
use anyhow::{anyhow, bail, Context, Result};
use derive_more::Debug;
use futures_lite::{Stream, StreamExt};
use iroh_relay::{force_staging_infra, RelayMode, RelayUrl};
use iroh_relay::force_staging_infra;
use pin_project::pin_project;
use tokio_util::sync::{CancellationToken, WaitForCancellationFuture};
use tracing::{debug, instrument, trace, warn};
Expand All @@ -37,7 +37,7 @@ use crate::{
dns::{default_resolver, DnsResolver},
key::{PublicKey, SecretKey},
magicsock::{self, Handle, QuicMappedAddr},
tls, NodeId,
tls, NodeId, RelayMode, RelayUrl,
};

mod rtt_actor;
Expand Down
4 changes: 3 additions & 1 deletion iroh-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,16 @@ mod magicsock;
pub mod metrics;
pub mod netcheck;
pub mod ping;
mod relay_map;
pub mod ticket;
pub mod tls;

pub(crate) mod util;

pub use endpoint::{AddrInfo, Endpoint, NodeAddr};
pub use iroh_base::{key, key::NodeId};
pub use iroh_relay as relay;
pub use iroh_relay::{RelayMap, RelayMode, RelayNode, RelayUrl};
pub use relay_map::{RelayMap, RelayMode, RelayNode, RelayUrl};

#[cfg(any(test, feature = "test-utils"))]
#[cfg_attr(iroh_docsrs, doc(cfg(any(test, feature = "test-utils"))))]
Expand Down
7 changes: 3 additions & 4 deletions iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use futures_lite::{FutureExt, Stream, StreamExt};
use futures_util::stream::BoxStream;
use iroh_base::key::NodeId;
use iroh_metrics::{inc, inc_by};
use iroh_relay::{protos::stun, RelayMap, RelayUrl};
use iroh_relay::protos::stun;
use netwatch::{interfaces, ip::LocalAddresses, netmon};
use quinn::AsyncUdpSocket;
use rand::{seq::SliceRandom, Rng, SeedableRng};
Expand Down Expand Up @@ -66,7 +66,7 @@ use crate::{
dns::DnsResolver,
endpoint::NodeAddr,
key::{PublicKey, SecretKey, SharedSecret},
netcheck, AddrInfo,
netcheck, AddrInfo, RelayMap, RelayUrl,
};

mod metrics;
Expand Down Expand Up @@ -2778,13 +2778,12 @@ impl NetInfo {
#[cfg(test)]
mod tests {
use anyhow::Context;
use iroh_relay::RelayMode;
use iroh_test::CallOnDrop;
use rand::RngCore;
use tokio_util::task::AbortOnDropHandle;

use super::*;
use crate::{defaults::staging::EU_RELAY_HOSTNAME, tls, Endpoint};
use crate::{defaults::staging::EU_RELAY_HOSTNAME, tls, Endpoint, RelayMode};

const ALPN: &[u8] = b"n0/test/1";

Expand Down
6 changes: 4 additions & 2 deletions iroh-net/src/netcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use anyhow::{anyhow, Context as _, Result};
use bytes::Bytes;
use hickory_resolver::TokioAsyncResolver as DnsResolver;
use iroh_metrics::inc;
use iroh_relay::{protos::stun, RelayMap, RelayUrl};
use iroh_relay::protos::stun;
use netwatch::{IpFamily, UdpSocket};
use tokio::{
sync::{self, mpsc, oneshot},
Expand All @@ -26,6 +26,8 @@ use tokio::{
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
use tracing::{debug, error, info_span, trace, warn, Instrument};

use crate::{RelayMap, RelayUrl};

mod metrics;
mod reportgen;

Expand Down Expand Up @@ -772,14 +774,14 @@ mod tests {
use std::net::Ipv4Addr;

use bytes::BytesMut;
use iroh_relay::RelayNode;
use tokio::time;
use tracing::info;

use super::*;
use crate::{
defaults::{staging::EU_RELAY_HOSTNAME, DEFAULT_STUN_PORT},
ping::Pinger,
RelayNode,
};

mod stun_utils {
Expand Down
3 changes: 2 additions & 1 deletion iroh-net/src/netcheck/reportgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{

use anyhow::{anyhow, bail, Context, Result};
use iroh_metrics::inc;
use iroh_relay::{http::RELAY_PROBE_PATH, protos::stun, RelayMap, RelayNode, RelayUrl};
use iroh_relay::{http::RELAY_PROBE_PATH, protos::stun};
use netwatch::{interfaces, UdpSocket};
use rand::seq::IteratorRandom;
use tokio::{
Expand All @@ -45,6 +45,7 @@ use crate::{
netcheck::{self, Report},
ping::{PingError, Pinger},
util::MaybeFuture,
RelayMap, RelayNode, RelayUrl,
};

mod hairpin;
Expand Down
3 changes: 1 addition & 2 deletions iroh-net/src/netcheck/reportgen/probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
use std::{collections::BTreeSet, fmt, sync::Arc};

use anyhow::{ensure, Result};
use iroh_relay::{RelayMap, RelayNode, RelayUrl};
use netwatch::interfaces;
use tokio::time::Duration;

use crate::netcheck::Report;
use crate::{netcheck::Report, RelayMap, RelayNode, RelayUrl};

/// The retransmit interval used when netcheck first runs.
///
Expand Down
2 changes: 1 addition & 1 deletion iroh-relay/src/map.rs → iroh-net/src/relay_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use std::{collections::BTreeMap, fmt, sync::Arc};

use anyhow::{ensure, Result};
pub use iroh_relay::RelayUrl;
use serde::{Deserialize, Serialize};

use super::RelayUrl;
use crate::defaults::DEFAULT_STUN_PORT;

/// Configuration of the relay servers for an [`Endpoint`].
Expand Down
7 changes: 2 additions & 5 deletions iroh-net/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ use std::net::Ipv4Addr;
use anyhow::Result;
pub use dns_and_pkarr_servers::DnsPkarrServer;
pub use dns_server::create_dns_resolver;
use iroh_relay::{
server::{CertConfig, RelayConfig, Server, ServerConfig, StunConfig, TlsConfig},
RelayMap, RelayNode, RelayUrl,
};
use iroh_relay::server::{CertConfig, RelayConfig, Server, ServerConfig, StunConfig, TlsConfig};
use tokio::sync::oneshot;

use crate::defaults::DEFAULT_STUN_PORT;
use crate::{defaults::DEFAULT_STUN_PORT, RelayMap, RelayNode, RelayUrl};

/// A drop guard to clean up test infrastructure.
///
Expand Down
113 changes: 0 additions & 113 deletions iroh-relay/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,6 @@ pub const DEFAULT_HTTPS_PORT: u16 = 443;
/// The default metrics port used by the Relay server.
pub const DEFAULT_METRICS_PORT: u16 = 9090;

/// Production configuration.
pub mod prod {
use url::Url;

use super::*;
use crate::{RelayMap, RelayNode};

/// Hostname of the default NA relay.
pub const NA_RELAY_HOSTNAME: &str = "use1-1.relay.iroh.network.";
/// Hostname of the default EU relay.
pub const EU_RELAY_HOSTNAME: &str = "euw1-1.relay.iroh.network.";
/// Hostname of the default Asia-Pacific relay.
pub const AP_RELAY_HOSTNAME: &str = "aps1-1.relay.iroh.network.";

/// Get the default [`RelayMap`].
pub fn default_relay_map() -> RelayMap {
RelayMap::from_nodes([
default_na_relay_node(),
default_eu_relay_node(),
default_ap_relay_node(),
])
.expect("default nodes invalid")
}

/// Get the default [`RelayNode`] for NA.
pub fn default_na_relay_node() -> RelayNode {
// The default NA relay server run by number0.
let url: Url = format!("https://{NA_RELAY_HOSTNAME}")
.parse()
.expect("default url");
RelayNode {
url: url.into(),
stun_only: false,
stun_port: DEFAULT_STUN_PORT,
}
}

/// Get the default [`RelayNode`] for EU.
pub fn default_eu_relay_node() -> RelayNode {
// The default EU relay server run by number0.
let url: Url = format!("https://{EU_RELAY_HOSTNAME}")
.parse()
.expect("default_url");
RelayNode {
url: url.into(),
stun_only: false,
stun_port: DEFAULT_STUN_PORT,
}
}

/// Get the default [`RelayNode`] for Asia-Pacific
pub fn default_ap_relay_node() -> RelayNode {
// The default Asia-Pacific relay server run by number0.
let url: Url = format!("https://{AP_RELAY_HOSTNAME}")
.parse()
.expect("default_url");
RelayNode {
url: url.into(),
stun_only: false,
stun_port: DEFAULT_STUN_PORT,
}
}
}

/// Staging configuration.
///
/// Used by tests and might have incompatible changes deployed
///
/// Note: we have staging servers in EU and NA, but no corresponding staging server for AP at this time.
pub mod staging {
use url::Url;

use super::*;
use crate::{RelayMap, RelayNode};

/// Hostname of the default NA relay.
pub const NA_RELAY_HOSTNAME: &str = "staging-use1-1.relay.iroh.network.";
/// Hostname of the default EU relay.
pub const EU_RELAY_HOSTNAME: &str = "staging-euw1-1.relay.iroh.network.";

/// Get the default [`RelayMap`].
pub fn default_relay_map() -> RelayMap {
RelayMap::from_nodes([default_na_relay_node(), default_eu_relay_node()])
.expect("default nodes invalid")
}

/// Get the default [`RelayNode`] for NA.
pub fn default_na_relay_node() -> RelayNode {
// The default NA relay server run by number0.
let url: Url = format!("https://{NA_RELAY_HOSTNAME}")
.parse()
.expect("default url");
RelayNode {
url: url.into(),
stun_only: false,
stun_port: DEFAULT_STUN_PORT,
}
}

/// Get the default [`RelayNode`] for EU.
pub fn default_eu_relay_node() -> RelayNode {
// The default EU relay server run by number0.
let url: Url = format!("https://{EU_RELAY_HOSTNAME}")
.parse()
.expect("default_url");
RelayNode {
url: url.into(),
stun_only: false,
stun_port: DEFAULT_STUN_PORT,
}
}
}

/// Contains all timeouts that we use in `iroh-net`.
pub(crate) mod timeouts {
use std::time::Duration;
Expand Down
5 changes: 3 additions & 2 deletions iroh-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pub mod client;
pub mod defaults;
pub mod http;
mod map;
// mod map;
pub mod protos;
#[cfg(feature = "server")]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "server")))]
Expand All @@ -29,6 +29,7 @@ pub use iroh_base::node_addr::RelayUrl;
pub const ENV_FORCE_STAGING_RELAYS: &str = "IROH_FORCE_STAGING_RELAYS";

/// Returns `true` if the use of staging relays is forced.
// TODO(@divma): move
pub fn force_staging_infra() -> bool {
matches!(std::env::var(ENV_FORCE_STAGING_RELAYS), Ok(value) if !value.is_empty())
}
Expand All @@ -39,6 +40,6 @@ pub use self::{
Client as HttpClient, ClientBuilder as HttpClientBuilder, ClientError as HttpClientError,
ClientReceiver as HttpClientReceiver,
},
map::{RelayMap, RelayMode, RelayNode},
// map::{RelayMap, RelayMode, RelayNode},
protos::relay::MAX_PACKET_SIZE,
};
4 changes: 2 additions & 2 deletions iroh-relay/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ mod clients;
mod http_server;
mod metrics;
pub(crate) mod streams;
#[cfg(feature = "test-utils")]
pub mod testing;
// #[cfg(feature = "test-utils")]
// pub mod testing;
pub(crate) mod types;

pub use self::{
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use iroh_net::{
discovery::{dns::DnsDiscovery, pkarr::PkarrPublisher, ConcurrentDiscovery, Discovery},
dns::DnsResolver,
endpoint::TransportConfig,
Endpoint,
Endpoint, RelayMode,
};
use iroh_relay::{force_staging_infra, RelayMode};
use iroh_relay::force_staging_infra;
use iroh_router::{ProtocolHandler, RouterBuilder};
use quic_rpc::transport::{boxed::BoxableListener, quinn::QuinnListener};
use serde::{Deserialize, Serialize};
Expand Down
Loading

0 comments on commit aef15fb

Please sign in to comment.