-
Notifications
You must be signed in to change notification settings - Fork 327
feat: expose known remote addrs #3752
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
Open
Frando
wants to merge
7
commits into
feat-multipath
Choose a base branch
from
Frando/remote-addrs
base: feat-multipath
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7461b64
feat: expose known remote addrs
Frando d4e8c12
refactor: renames and docs
Frando 299d985
fix: doclink
Frando d488d3e
docs
Frando 245ed6a
refactor: reduce API surface, address review
Frando 88fe2b5
Merge remote-tracking branch 'origin/feat-multipath' into Frando/remo…
Frando 2aa1a10
fixup
Frando File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| use std::collections::BTreeSet; | ||
|
|
||
| use iroh_base::{EndpointAddr, EndpointId, TransportAddr}; | ||
| use n0_future::time::Instant; | ||
|
|
||
| use crate::endpoint::Source; | ||
|
|
||
| /// Information about a remote endpoint. | ||
flub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[derive(Debug, Clone)] | ||
| pub struct RemoteInfo { | ||
| pub(super) endpoint_id: EndpointId, | ||
| pub(super) addrs: Vec<TransportAddrInfo>, | ||
| } | ||
|
|
||
| impl RemoteInfo { | ||
| /// Returns the remote's endpoint id. | ||
| pub fn id(&self) -> EndpointId { | ||
| self.endpoint_id | ||
| } | ||
|
|
||
| /// Returns an iterator over known all addresses for this remote. | ||
| /// | ||
| /// Note that this may include outdated or unusable addresses. | ||
| pub fn addrs(&self) -> impl Iterator<Item = &TransportAddrInfo> { | ||
| self.addrs.iter() | ||
| } | ||
|
|
||
| /// Converts into an iterator over known all addresses for this remote. | ||
| /// | ||
| /// Note that this may include outdated or unusable addresses. | ||
| pub fn into_addrs(self) -> impl Iterator<Item = TransportAddrInfo> { | ||
| self.addrs.into_iter() | ||
| } | ||
|
|
||
| /// Returns a [`EndpointAddr`] that includes all addresses that are not [`TransportAddrUsage::Unusable`]. | ||
| pub fn into_endpoint_addr(self) -> EndpointAddr { | ||
| let addrs = self | ||
| .addrs | ||
| .into_iter() | ||
| .filter(|a| !matches!(a.usage(), TransportAddrUsage::Unusable)) | ||
| .map(|a| a.addr); | ||
|
|
||
| EndpointAddr { | ||
| id: self.endpoint_id, | ||
| addrs: BTreeSet::from_iter(addrs), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Address of a remote with some metadata | ||
| #[derive(Debug, Clone)] | ||
| pub struct TransportAddrInfo { | ||
| pub(super) addr: TransportAddr, | ||
| pub(super) usage: TransportAddrUsage, | ||
| pub(super) most_recent_source: Source, | ||
| } | ||
|
|
||
| impl TransportAddrInfo { | ||
| /// Returns the [`TransportAddr`]. | ||
| pub fn addr(&self) -> &TransportAddr { | ||
| &self.addr | ||
| } | ||
|
|
||
| /// Converts into [`TransportAddr`]. | ||
| pub fn into_addr(self) -> TransportAddr { | ||
| self.addr | ||
| } | ||
|
|
||
| /// Returns information how this address is used. | ||
| pub fn usage(&self) -> TransportAddrUsage { | ||
| self.usage | ||
| } | ||
|
|
||
| /// Returns the most recent source of this address. | ||
| /// | ||
| /// We may learn about new addresses from multiple sources. This returns the most recent source | ||
| /// that told us about this address. | ||
| pub fn most_recent_source(&self) -> &Source { | ||
| &self.most_recent_source | ||
| } | ||
flub marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Information how a transport address is used. | ||
| #[derive(Debug, Copy, Clone)] | ||
| pub enum TransportAddrUsage { | ||
| /// The address is in active use. | ||
| Active, | ||
| /// The address was used, but is not currently. | ||
| Inactive { | ||
| /// Time when this address was last used. | ||
| last_used: Instant, | ||
flub marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| /// We tried to use this address, but failed. | ||
| Unusable, | ||
flub marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// We have not tried to use this address. | ||
| Unknown, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.