Skip to content

Commit 2e61ff2

Browse files
authored
feat(iroh)!: Wrap the Connection struct so we own the type (#3110)
## Description This makes iroh own the Connection type. This is desirable because: - Some: upstream APIs don't work well for us, e.g. Connection::remote_address is not that meaningful. This allows us to remove those and replace them with more appropriate APIs. This has not yet been done in this PR however. - The connection type and changes are currently on the Endpoint, they also belong on the Connection. - Connection information, like which pats are used, the latencies of those paths etc, also belong on the Connection. - It is generally not great to expose types which you have no control over in your public API. For the 1.0 we do not want to have any such structs. This takes an important step in that direction. As part of this change Connection::remote_node_id replaces the get_remote_node_id function. Also Connection::alpn now exists. ## Breaking Changes ### iroh - `iroh::endpoint::get_remote_node_id` has been removed. Use `iroh::endpoint::Connection::remote_node_id` instead. ## Notes & open questions This does not yet clean up the existing methods in the Connection, preserving most of them as-is. It is easier to handle those separately as each one involves careful decisions about the API. Replaces #2768 ## Change checklist - [x] Self-review. - [x] 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. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent 2b92db4 commit 2e61ff2

File tree

7 files changed

+360
-47
lines changed

7 files changed

+360
-47
lines changed

iroh/examples/dht_discovery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::str::FromStr;
1212

1313
use clap::Parser;
14-
use iroh::{endpoint::get_remote_node_id, Endpoint, NodeId};
14+
use iroh::{Endpoint, NodeId};
1515
use tracing::warn;
1616
use url::Url;
1717

@@ -88,7 +88,7 @@ async fn chat_server(args: Args) -> anyhow::Result<()> {
8888
};
8989
tokio::spawn(async move {
9090
let connection = connecting.await?;
91-
let remote_node_id = get_remote_node_id(&connection)?;
91+
let remote_node_id = connection.remote_node_id()?;
9292
println!("got connection from {}", remote_node_id);
9393
// just leave the tasks hanging. this is just an example.
9494
let (mut writer, mut reader) = connection.accept_bi().await?;

iroh/examples/echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl ProtocolHandler for Echo {
7777
// Wait for the connection to be fully established.
7878
let connection = connecting.await?;
7979
// We can get the remote's node id from the connection.
80-
let node_id = iroh::endpoint::get_remote_node_id(&connection)?;
80+
let node_id = connection.remote_node_id()?;
8181
println!("accepted connection from {node_id}");
8282

8383
// Our protocol is a simple request-response protocol, so we expect the

iroh/examples/listen-unreliable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async fn main() -> anyhow::Result<()> {
6969
};
7070
let alpn = connecting.alpn().await?;
7171
let conn = connecting.await?;
72-
let node_id = iroh::endpoint::get_remote_node_id(&conn)?;
72+
let node_id = conn.remote_node_id()?;
7373
info!(
7474
"new (unreliable) connection from {node_id} with ALPN {} (coming from {})",
7575
String::from_utf8_lossy(&alpn),

iroh/examples/listen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async fn main() -> anyhow::Result<()> {
7070
};
7171
let alpn = connecting.alpn().await?;
7272
let conn = connecting.await?;
73-
let node_id = iroh::endpoint::get_remote_node_id(&conn)?;
73+
let node_id = conn.remote_node_id()?;
7474
info!(
7575
"new connection from {node_id} with ALPN {} (coming from {})",
7676
String::from_utf8_lossy(&alpn),

iroh/examples/search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use anyhow::Result;
3535
use clap::Parser;
3636
use futures_lite::future::Boxed as BoxedFuture;
3737
use iroh::{
38-
endpoint::{get_remote_node_id, Connecting},
38+
endpoint::Connecting,
3939
protocol::{ProtocolHandler, Router},
4040
Endpoint, NodeId,
4141
};
@@ -134,7 +134,7 @@ impl ProtocolHandler for BlobSearch {
134134
// Wait for the connection to be fully established.
135135
let connection = connecting.await?;
136136
// We can get the remote's node id from the connection.
137-
let node_id = get_remote_node_id(&connection)?;
137+
let node_id = connection.remote_node_id()?;
138138
println!("accepted connection from {node_id}");
139139

140140
// Our protocol is a simple request-response protocol, so we expect the

iroh/examples/transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async fn provide(
179179
}
180180
};
181181
let conn = connecting.await?;
182-
let node_id = iroh::endpoint::get_remote_node_id(&conn)?;
182+
let node_id = conn.remote_node_id()?;
183183
info!(
184184
"new connection from {node_id} with ALPN {} (coming from {})",
185185
String::from_utf8_lossy(TRANSFER_ALPN),

0 commit comments

Comments
 (0)