-
Notifications
You must be signed in to change notification settings - Fork 140
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
feat(iroh-net): add MagicEndpoint::conn_type_stream
returns a stream that reports connection type changes for a node_id
#2161
Conversation
9b095c6
to
fe42335
Compare
MagicEndpoint::wait_until_direct_conn
MagicEndpoint::wait_until_direct_conn
async fn magic_endpoint_wait_for_direct_conn() { | ||
let _logging_guard = iroh_test::logging::setup(); | ||
let (relay_map, relay_url, _relay_guard) = run_relay_server().await.unwrap(); | ||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(42); |
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 is a very specific rng. I have no opinions on it, but would love to learn why?
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.
🤣 TBH, this was taken from another test & I didn't change it. I'm assuming it was originally 42 because 42 is the answer to life the universe and everything
iroh-net/src/magic_endpoint.rs
Outdated
eprintln!("node id 2 {ep2_nodeid}"); | ||
|
||
let res_ep1 = tokio::spawn(handle_direct_conn(ep1.clone(), ep2_nodeid)); | ||
let res_ep2 = tokio::spawn(handle_direct_conn(ep2.clone(), ep1_nodeid)); |
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.
if you want to be really careful you get an abort handle of these and put a call to them in a iroh_test::CallOnDrop
so that your tasks are always cleaned up.
/// It is possible we will never have a viable `best_addr`, in which case | ||
/// no alert will ever be issued. | ||
pub fn notify_has_best_addr(&mut self) -> oneshot::Receiver<()> { | ||
self.assign_best_addr_from_candidates_if_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.
Do you really want to call this from here? I'm kind of -1 because it is logic that influences how the magicsock behaves but is called from a place that's not in the normal flow. The magicsock will already call this from somewhere else when it thinks this is needed.
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.
good point. if we go back to that flow, I'll remove it.
sorry, meant to review this before you woke up but it got lost in an open tab... |
5dea7b2
to
4ad3c78
Compare
@@ -171,6 +174,7 @@ impl Endpoint { | |||
direct_addr_state: BTreeMap::new(), | |||
last_used: options.active.then(Instant::now), | |||
last_call_me_maybe: None, | |||
conn_type: Watchable::new(ConnectionType::None), |
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.
my biggest concern with this approach is how "heavy" it might be to have a Watchable
for each node_map::Endpoint
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.
It does acquire an additional RwLock
write handle for each time you set it. Same would be for a tokio Watch
. Though I think there would be very little contention for this, so it's probably fine?
4ad3c78
to
016aa09
Compare
@@ -171,6 +174,7 @@ impl Endpoint { | |||
direct_addr_state: BTreeMap::new(), | |||
last_used: options.active.then(Instant::now), | |||
last_call_me_maybe: None, | |||
conn_type: Watchable::new(ConnectionType::None), |
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.
It does acquire an additional RwLock
write handle for each time you set it. Same would be for a tokio Watch
. Though I think there would be very little contention for this, so it's probably fine?
This blocking method will return once a direct connection has been established between the endpoint and the node at `node_id`, or return in error if a timeout occurs. If no `Endpoint` exists for this `node_id` in the `NodeMap`, one will be created. This can be called before or after `connect`. If a direct connection already exists between the endpoint and the node at `node_id` when this method is called, it will immediately return.
…tils::run_relay_server`
… creating an `EndpointInfo`
b8f4e8e
to
eb6044d
Compare
MagicEndpoint::wait_until_direct_conn
MagicEndpoint::conn_type_stream
returns a stream that reports connection type changes for a node_id
0a08dd5
to
d4983e8
Compare
Description
MagicEndpoint::conn_type_stream
returns aStream
that reports changes for amagicsock::Endpoint
with a givennode_id
in amagicsock::NodeMap
.It will error if no address information for that
node_id
exists in theNodeMap
.This PR also adjusts the
Endpoint::info()
method to use the sameConnectionType
that gets reported to the stream.Change checklist