-
Notifications
You must be signed in to change notification settings - Fork 165
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
Conversation
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 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.
I don't think this is how it should be.
I agree with dig, we should drop the #[cfg(..)]
completely, and solely rely on std::env::var(FORCE_STAGING_RELAYS).is_ok()
.
There's two permutations of this idea that I'm on the fence about:
- we could require this env variable to be present at compile time, i.e. use
std::env!("IROH_FORCE_STAGING_RELAYS")
. This might be annoying if we try to test with, let's say, a pre-built iroh-doctor binary. - we could match on
cfg!(test) || std::env::var(FORCE_STAGING_RELAYS).is_ok()
. This way we make sure that any testing code always uses staging relays. This shouldn't be too bad. But also I still don't think this would be right to do. I want it to be possible to run the test env as similar to prod as possible, if I want to.
About insecure_skip_relay_cert_verify
: This should just be gated on #[cfg(feature = "test-utils")]
IMO.
But whether or not it's exposed is actually a concern outside of the scope of this PR, so this PR shouldn't change when this function actually is exposed.
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 match on Ok(value) = std::env::var(...) if !value.is_empty()
, but in the docs you write "if the ... env variable is set".
I think you should simply use std::env::var(ENV_FORCE_STAGING_RELAYS).is_ok()
.
If the env variable is not set, then std::env::var
returns Err(NotPresent)
, so checking for is_ok()
should be fine IMO.
With your current setup, this would not force staging relays:
$ IROH_FORCE_STAGING_RELAYS="" cargo run # ...
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2778/docs/iroh/ Last updated: 2024-10-21T10:59:45Z |
556f174
to
3b9044e
Compare
iroh-net/src/discovery/pkarr.rs
Outdated
let pkarr_relay = match std::env::var(ENV_FORCE_STAGING_RELAYS) { | ||
Ok(value) if !value.is_empty() => N0_DNS_PKARR_RELAY_STAGING, | ||
_ => N0_DNS_PKARR_RELAY_PROD, | ||
}; |
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 also do the cfg(test)
dance as the other things, do, right?
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.
@flub the N0_DNS_PKARR_RELAY_PROD
values are distinct from the dns records ie. have /pkarr
added. Do you want me to add a TEST_DNS_PKARR_RELAY similar to how it is on dns.rs
right now?
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.
Hmm no, I think TEST_DNS_NODE_ORIGIN
is a special case: It uses the .test
TLD which has special meaning in DNS resolvers!
We don't have any equivalent for any of the other infra identifiers.
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.
So from my recollection TEST_DNS_NODE_ORIGIN
was added so that it uses a special URL which will not be resolved by any normal resolvers and will only be resolved if you start a local resolver in the test using a helper function. This stops tests from hitting any external DNS server.
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.
IIRC we basically didn't have any requests and this was more a precaution when we were dealing with the relays as well. (Though in spirit I do agree with it)
iroh-net/src/discovery/pkarr.rs
Outdated
#[cfg(not(test))] | ||
let pkarr_relay = N0_DNS_PKARR_RELAY_PROD; | ||
#[cfg(any(test, feature = "test-utils"))] | ||
#[cfg(test)] | ||
let pkarr_relay = N0_DNS_PKARR_RELAY_STAGING; |
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.
We should probably also match on the env var here, right?
iroh-net/src/endpoint.rs
Outdated
match std::env::var(ENV_FORCE_STAGING_RELAYS) { | ||
Ok(value) if !value.is_empty() => RelayMode::Staging, | ||
_ => RelayMode::Default, |
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.
Err. I'm a little confused.
Do we want to match on both env vars and cfg(test)
now, or not?
Usage now seems somewhat inconsistent.
Perhaps we should just have a single fn use_staging_infra() -> bool
somewhere instead of the ENV_FORCE_STAGING_RELAYS
constant.
Then we can make sure our use is consistent.
iroh/src/node/builder.rs
Outdated
#[cfg(not(test))] | ||
let relay_mode = RelayMode::Default; | ||
#[cfg(any(test, feature = "test-utils"))] | ||
#[cfg(test)] | ||
let relay_mode = RelayMode::Staging; |
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.
IMO This should additionally test for the env variable here, too.
iroh/src/node/builder.rs
Outdated
#[cfg(not(test))] | ||
let relay_mode = RelayMode::Default; | ||
#[cfg(any(test, feature = "test-utils"))] | ||
#[cfg(test)] | ||
let relay_mode = RelayMode::Staging; |
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.
(same here)
|
||
/// Returns `true` if the use of staging relays is forced. | ||
pub fn force_staging_infra() -> bool { | ||
matches!(std::env::var(ENV_FORCE_STAGING_RELAYS), Ok(value) if !value.is_empty()) |
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.
We can now handle the cfg(test)
case here if we want to specifically. But as Frando mentioned, this only works in the tested crate.
Revamped the thing again. This is the "slim" version.
|
4ea7554
to
8d39c93
Compare
iroh-net/src/discovery/dns.rs
Outdated
match force_staging_infra() { | ||
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.
match force_staging_infra() { | |
true => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()), | |
false => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()), | |
if force_staging_infra() { | |
Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()) | |
} else { | |
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.
I guess it'd be unusual to see a match on booleans. But honestly, it's shorter, and I'd almost say the match reads better in this case? I'm somewhat undecided :D
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.
Yeah, I just followed like the others (where I let x = match ...
) but technically here it is a simple if else. Updated to that 🤷
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.
lol, I saw the other uses and was like "ah well, it's probably fine", but now we have it inconsistent 🙈
Anyhow, we can update another time.
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.
I'm happy with this :)
(Btw: I didn't know we already set the IROH_FORCE_STAGING_RELAYS
env var in testing CI! :D)
## 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 - `TEST_DNS_NODE_ORIGIN` is removed - iroh now defaults to using prod relays unless `IROH_FORCE_STAGING_RELAYS` is set to a non empty value ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
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
TEST_DNS_NODE_ORIGIN
is removedIROH_FORCE_STAGING_RELAYS
is set to a non empty valueNotes & open questions
Change checklist