-
Notifications
You must be signed in to change notification settings - Fork 327
feat: improve RelayMap and RelayMode configuration #3734
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
base: feat-multipath
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1260,6 +1260,24 @@ impl RelayMode { | |
| RelayMode::Custom(relay_map) => relay_map.clone(), | ||
| } | ||
| } | ||
|
|
||
| /// Create a custom relay mode from a list of [`RelayUrl`]s. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ``` | ||
| /// # fn main() -> n0_error::Result<()> { | ||
| /// # use iroh::RelayMode; | ||
| /// RelayMode::custom([ | ||
| /// "https://use1-1.relay.n0.iroh-canary.iroh.link.".parse()?, | ||
| /// "https://euw-1.relay.n0.iroh-canary.iroh.link.".parse()?, | ||
| /// ]); | ||
| /// # Ok(()) } | ||
| /// ``` | ||
| pub fn custom(map: impl IntoIterator<Item = RelayUrl>) -> Self { | ||
| let m = RelayMap::from_iter(map); | ||
| Self::Custom(m) | ||
| } | ||
| } | ||
|
|
||
| /// Environment variable to force the use of staging relays. | ||
|
|
@@ -1294,9 +1312,12 @@ fn is_cgi() -> bool { | |
| // https://github.com/n0-computer/iroh/issues/1183 | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::time::{Duration, Instant}; | ||
| use std::{ | ||
| str::FromStr, | ||
| time::{Duration, Instant}, | ||
| }; | ||
|
|
||
| use iroh_base::{EndpointAddr, EndpointId, SecretKey, TransportAddr}; | ||
| use iroh_base::{EndpointAddr, EndpointId, RelayUrl, SecretKey, TransportAddr}; | ||
| use n0_error::{AnyError as Error, Result, StdResultExt}; | ||
| use n0_future::{BufferedStreamExt, StreamExt, stream, time}; | ||
| use n0_watcher::Watcher; | ||
|
|
@@ -2450,4 +2471,23 @@ mod tests { | |
| assert!(dt0 / dt1 < 20.0, "First round: {dt0}s, second round {dt1}s"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_custom_relay() -> Result { | ||
| let _ep = Endpoint::empty_builder(RelayMode::custom([RelayUrl::from_str( | ||
| "https://use1-1.relay.n0.iroh-canary.iroh.link.", | ||
| )?])) | ||
| .bind() | ||
| .await?; | ||
|
|
||
| let relays = RelayMap::try_from_iter([ | ||
| "https://use1-1.relay.n0.iroh.iroh.link/", | ||
| "https://euc1-1.relay.n0.iroh.iroh.link/", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are still inconsistent with our usage of We should be sticking to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should stick to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And of course, defaults.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not an example but a test, I a actually want to make sure that it also works without
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, wasn't super clear from that. I thought you wanted to do the same thing in 2 ways ie empty builder and pass it in from an iter. |
||
| ])?; | ||
| let _ep = Endpoint::empty_builder(RelayMode::Custom(relays)) | ||
| .bind() | ||
| .await?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
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.
doc comment should probably point out that a default RelayConfig is used and that this means we'll assume the relay URL has QAD running on port 7842 or whatever relevant.
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.
done