-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cfg): make sure we use correct relays #2778
base: main
Are you sure you want to change the base?
Conversation
@@ -14,10 +14,14 @@ pub const N0_DNS_NODE_ORIGIN_PROD: &str = "dns.iroh.link"; | |||
/// The n0 testing DNS node origin, for testing. | |||
pub const N0_DNS_NODE_ORIGIN_STAGING: &str = "staging-dns.iroh.link"; | |||
/// Testing DNS node origin, must run server from [`crate::test_utils::DnsPkarrServer`]. | |||
#[cfg(any(test, feature = "test-utils"))] | |||
#[cfg_attr(iroh_docsrs, doc(cfg(any(test, feature = "test-utils"))))] | |||
#[cfg(test)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't take away the cfg_attr
on (public) items that have a cfg
!
#[cfg(test)] | |
#[cfg(test)] | |
#[cfg_attr(iroh_docsrs, doc(cfg(test)))] |
I know it's annoying you have to repeat the cfg inside the cfg_attr... Unfortunately that's the only way I could get this thing to work currently.
pub const TEST_DNS_NODE_ORIGIN: &str = "dns.iroh.test"; | ||
|
||
/// Environment variable to force the use of staging relays. | ||
#[cfg(not(test))] | ||
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cfg
needs to be repeated inside the cfg_attr
. The cfg
is what the compiler sees. And because things are still sad, we need to repeat this inside the cfg_attr for the docs to work:
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))] | |
#[cfg_attr(iroh_docsrs, doc(cfg(not(test)))] |
{ | ||
Self::new(TEST_DNS_NODE_ORIGIN.to_string()) | ||
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) { | ||
Ok(value) => value == "1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring a specific value here is a bit weird. UNIX has the custom of accepting any non-nil value for this kind of env var. Often people will use t
, sometimes on
.
Ok(value) => value == "1", | |
Ok(value) => !value.is_empty(), |
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) { | ||
Ok(value) => value == "1", | ||
Err(_) => false, | ||
}; | ||
match force_staging_relays { | ||
true => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()), | ||
false => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) { | |
Ok(value) => value == "1", | |
Err(_) => false, | |
}; | |
match force_staging_relays { | |
true => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()), | |
false => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()), | |
} | |
match std::env::var(ENV_FORCE_STAGING_RELAYS) { | |
Ok(value) if !value.is_empty() => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()), | |
_ => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()), | |
} | |
/// Environment variable to force the use of staging relays. | ||
#[cfg(not(test))] | ||
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))] | ||
const ENV_FORCE_STAGING_RELAYS: &str = "IROH_FORCE_STAGING_RELAYS"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're adding this to more than one file. Let's add it to src/relays.rs
and make it pub so we can document this as well.
@@ -321,9 +329,9 @@ impl PkarrResolver { | |||
/// | |||
/// [number 0]: https://n0.computer | |||
pub fn n0_dns() -> Self { | |||
#[cfg(not(any(test, feature = "test-utils")))] | |||
#[cfg(not(all(test, feature = "test-utils")))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't @matheus23 say this doesn't work for something?
@@ -58,8 +58,6 @@ pub use iroh_base::node_addr::{AddrInfo, NodeAddr}; | |||
const DISCOVERY_WAIT_PERIOD: Duration = Duration::from_millis(500); | |||
|
|||
/// Environment variable to force the use of staging relays. | |||
#[cfg(not(any(test, feature = "test-utils")))] | |||
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))] | |||
const ENV_FORCE_STAGING_RELAYS: &str = "IROH_FORCE_STAGING_RELAYS"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move this to one place as discussed.
@@ -1247,14 +1245,10 @@ fn proxy_url_from_env() -> Option<Url> { | |||
/// Otherwise, it will return `RelayMode::Default`. | |||
pub fn default_relay_mode() -> RelayMode { | |||
// Use staging in testing | |||
#[cfg(not(any(test, feature = "test-utils")))] | |||
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) { | |||
Ok(value) => value == "1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be any non-nil value. Maybe we can add a pub(crate)
function to read this variable and also put it in src/relay.rs
. Otherwise this behaviour gets to easily different between different call sites.
@@ -1247,14 +1245,10 @@ fn proxy_url_from_env() -> Option<Url> { | |||
/// Otherwise, it will return `RelayMode::Default`. | |||
pub fn default_relay_mode() -> RelayMode { | |||
// Use staging in testing | |||
#[cfg(not(any(test, feature = "test-utils")))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one does not have to stay at cfg(not(test))
?
@@ -231,9 +231,9 @@ fn mk_external_rpc() -> IrohServerEndpoint { | |||
impl Default for Builder<iroh_blobs::store::mem::Store> { | |||
fn default() -> Self { | |||
// Use staging in testing | |||
#[cfg(not(any(test, feature = "test-utils")))] | |||
#[cfg(not(all(test, feature = "test-utils")))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be just cfg(not(test))
? If someone is requesting test-utils
they can still enable test
themselves. Unless this breaks one of the benchmarks again...
Description
This takes us back to only relying on the env var for forcing staging relays. However for tests it should still remain active with the test/feature combo by default.
Breaking Changes
Notes & open questions
Change checklist