Skip to content

Commit 3eb56b8

Browse files
feat: upgrade to iroh 0.29 (#491)
iroh-net is now called just `iroh`, more details in a blog post that is coming in the next days
1 parent ba0bb88 commit 3eb56b8

15 files changed

Lines changed: 733 additions & 372 deletions

File tree

Cargo.lock

Lines changed: 600 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ maybe-owned = "0.3"
2929
parking_lot = "0.12"
3030
smallvec = "1.11"
3131
ustr = "0.10"
32-
iroh-net = "0.27"
32+
iroh = "0.29"
3333

3434
[profile.release]
3535
lto = true

framework_crates/bones_framework/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ postcard = { version = "1.0", features = ["alloc"] }
153153
rcgen = "0.12"
154154
rustls = { version = "0.21", features = ["dangerous_configuration", "quic"] }
155155
smallvec = "1.10"
156-
iroh-quinn = { version = "0.11" }
157156
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
158157
turborand = { version = "0.10.0", features = ["atomic"] }
159-
iroh-net = { workspace = true, features = ["discovery-local-network"] }
158+
iroh = { workspace = true, features = ["discovery-local-network"] }
160159

161160
directories = "5.0"
162161

framework_crates/bones_framework/src/networking.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,25 @@ impl<T: DenseInput + Debug> ggrs::Config for GgrsConfig<T> {
110110
}
111111

112112
/// The network endpoint used for all network communications.
113-
static NETWORK_ENDPOINT: tokio::sync::OnceCell<iroh_net::Endpoint> =
114-
tokio::sync::OnceCell::const_new();
113+
static NETWORK_ENDPOINT: tokio::sync::OnceCell<iroh::Endpoint> = tokio::sync::OnceCell::const_new();
115114

116115
/// Get the network endpoint used for all communications.
117-
pub async fn get_network_endpoint() -> &'static iroh_net::Endpoint {
116+
pub async fn get_network_endpoint() -> &'static iroh::Endpoint {
118117
NETWORK_ENDPOINT
119118
.get_or_init(|| async move {
120-
let secret_key = iroh_net::key::SecretKey::generate();
121-
iroh_net::Endpoint::builder()
119+
let secret_key = iroh::key::SecretKey::generate();
120+
iroh::Endpoint::builder()
122121
.alpns(vec![MATCH_ALPN.to_vec(), PLAY_ALPN.to_vec()])
123122
.discovery(Box::new(
124-
iroh_net::discovery::ConcurrentDiscovery::from_services(vec![
123+
iroh::discovery::ConcurrentDiscovery::from_services(vec![
125124
Box::new(
126-
iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery::new(
125+
iroh::discovery::local_swarm_discovery::LocalSwarmDiscovery::new(
127126
secret_key.public(),
128127
)
129128
.unwrap(),
130129
),
131-
Box::new(iroh_net::discovery::dns::DnsDiscovery::n0_dns()),
132-
Box::new(iroh_net::discovery::pkarr::PkarrPublisher::n0_dns(
130+
Box::new(iroh::discovery::dns::DnsDiscovery::n0_dns()),
131+
Box::new(iroh::discovery::pkarr::PkarrPublisher::n0_dns(
133132
secret_key.clone(),
134133
)),
135134
]),

framework_crates/bones_framework/src/networking/lan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use std::{net::IpAddr, time::Duration};
1414

15-
use iroh_net::{endpoint::get_remote_node_id, NodeAddr};
15+
use iroh::{endpoint::get_remote_node_id, NodeAddr};
1616
use mdns_sd::{ServiceDaemon, ServiceInfo};
1717
use smallvec::SmallVec;
1818
use tracing::warn;

framework_crates/bones_framework/src/networking/online.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use crate::{
99
pub use bones_matchmaker_proto::{
1010
GameID, LobbyId, LobbyInfo, LobbyListItem, MatchInfo, PlayerIdxAssignment, MATCH_ALPN,
1111
};
12-
use iroh_net::Endpoint;
13-
use iroh_net::NodeId;
14-
use iroh_quinn::Connection;
12+
use iroh::{endpoint::Connection, Endpoint, NodeId};
1513
use once_cell::sync::Lazy;
1614
use tracing::{info, warn};
1715

framework_crates/bones_framework/src/networking/socket.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use bones_matchmaker_proto::PLAY_ALPN;
55
use bytes::Bytes;
6-
use iroh_net::NodeAddr;
6+
use iroh::NodeAddr;
77
use tracing::{info, warn};
88

99
use crate::networking::get_network_endpoint;
@@ -13,7 +13,7 @@ use super::{GameMessage, NetworkSocket, SocketTarget, RUNTIME};
1313
/// The [`NetworkSocket`] implementation.
1414
#[derive(Debug, Clone)]
1515
pub struct Socket {
16-
pub connections: Vec<(u32, iroh_quinn::Connection)>,
16+
pub connections: Vec<(u32, iroh::endpoint::Connection)>,
1717
pub ggrs_receiver: async_channel::Receiver<(u32, GameMessage)>,
1818
pub reliable_receiver: async_channel::Receiver<(u32, Vec<u8>)>,
1919
pub player_idx: u32,
@@ -23,7 +23,7 @@ pub struct Socket {
2323
}
2424

2525
impl Socket {
26-
pub fn new(player_idx: u32, connections: Vec<(u32, iroh_quinn::Connection)>) -> Self {
26+
pub fn new(player_idx: u32, connections: Vec<(u32, iroh::endpoint::Connection)>) -> Self {
2727
let (ggrs_sender, ggrs_receiver) = async_channel::unbounded();
2828
let (reliable_sender, reliable_receiver) = async_channel::unbounded();
2929

@@ -129,7 +129,7 @@ impl Socket {
129129
}
130130
}
131131

132-
fn get_connection(&self, idx: u32) -> &iroh_quinn::Connection {
132+
fn get_connection(&self, idx: u32) -> &iroh::endpoint::Connection {
133133
debug_assert!(idx < self.player_count);
134134
// TODO: if this is too slow, optimize storage
135135
self.connections
@@ -217,8 +217,8 @@ pub(super) async fn establish_peer_connections(
217217
player_idx: u32,
218218
player_count: u32,
219219
peer_addrs: Vec<(u32, NodeAddr)>,
220-
conn: Option<iroh_quinn::Connection>,
221-
) -> anyhow::Result<Vec<(u32, iroh_quinn::Connection)>> {
220+
conn: Option<iroh::endpoint::Connection>,
221+
) -> anyhow::Result<Vec<(u32, iroh::endpoint::Connection)>> {
222222
let mut peer_connections = Vec::new();
223223
let had_og_conn = conn.is_some();
224224
if let Some(conn) = conn {

other_crates/bones_matchmaker/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ postcard = { version = "1.0", default-features = false, features =
2323
serde = { version = "1.0", features = ["derive"] }
2424
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2525
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
26-
iroh-net = { workspace = true, features = ["discovery-local-network"] }
27-
quinn = { version = "0.11", package = "iroh-quinn" }
26+
iroh = { workspace = true, features = ["discovery-local-network"] }
2827
blake3 = "1.5.3"

other_crates/bones_matchmaker/examples/matchmaker_client.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ async fn main() {
2323
}
2424

2525
async fn client() -> anyhow::Result<()> {
26-
let secret_key = iroh_net::key::SecretKey::generate();
27-
let endpoint = iroh_net::Endpoint::builder()
26+
let secret_key = iroh::key::SecretKey::generate();
27+
let endpoint = iroh::Endpoint::builder()
2828
.alpns(vec![MATCH_ALPN.to_vec(), PLAY_ALPN.to_vec()])
2929
.discovery(Box::new(
30-
iroh_net::discovery::ConcurrentDiscovery::from_services(vec![
30+
iroh::discovery::ConcurrentDiscovery::from_services(vec![
3131
Box::new(
32-
iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery::new(
32+
iroh::discovery::local_swarm_discovery::LocalSwarmDiscovery::new(
3333
secret_key.public(),
3434
)?,
3535
),
36-
Box::new(iroh_net::discovery::dns::DnsDiscovery::n0_dns()),
37-
Box::new(iroh_net::discovery::pkarr::PkarrPublisher::n0_dns(
36+
Box::new(iroh::discovery::dns::DnsDiscovery::n0_dns()),
37+
Box::new(iroh::discovery::pkarr::PkarrPublisher::n0_dns(
3838
secret_key.clone(),
3939
)),
4040
]),
@@ -48,8 +48,8 @@ async fn client() -> anyhow::Result<()> {
4848
let hello = Hello { i_am };
4949
println!("o Opened client ID: {}. {hello:?}", endpoint.node_id());
5050

51-
let server_id: iroh_net::NodeId = std::env::args().nth(3).expect("missing node id").parse()?;
52-
let server_addr = iroh_net::NodeAddr::new(server_id);
51+
let server_id: iroh::NodeId = std::env::args().nth(3).expect("missing node id").parse()?;
52+
let server_addr = iroh::NodeAddr::new(server_id);
5353

5454
// Connect to the server
5555
let conn = endpoint.connect(server_addr, MATCH_ALPN).await?;
@@ -178,7 +178,7 @@ async fn client() -> anyhow::Result<()> {
178178
}
179179

180180
// Shutdown the endpoint
181-
endpoint.close(0u8.into(), b"done").await?;
181+
endpoint.close().await?;
182182

183183
Ok(())
184184
}

other_crates/bones_matchmaker/src/lib.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
extern crate tracing;
77

88
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
9+
use std::sync::Arc;
910

1011
use bones_matchmaker_proto::MATCH_ALPN;
11-
use iroh_net::key::SecretKey;
12+
use iroh::key::SecretKey;
13+
use matchmaker::Matchmaker;
1214

1315
pub mod cli;
1416
mod helpers;
@@ -27,7 +29,7 @@ struct Config {
2729
print_secret_key: bool,
2830
/// Use this secret key for the node
2931
#[clap(short, long, env = "BONES_MATCHMAKER_SECRET_KEY")]
30-
secret_key: Option<iroh_net::key::SecretKey>,
32+
secret_key: Option<iroh::key::SecretKey>,
3133
}
3234

3335
async fn server(args: Config) -> anyhow::Result<()> {
@@ -48,17 +50,17 @@ async fn server(args: Config) -> anyhow::Result<()> {
4850
println!("Secret Key: {}", secret_key);
4951
}
5052

51-
let endpoint = iroh_net::Endpoint::builder()
53+
let endpoint = iroh::Endpoint::builder()
5254
.alpns(vec![MATCH_ALPN.to_vec()])
5355
.discovery(Box::new(
54-
iroh_net::discovery::ConcurrentDiscovery::from_services(vec![
56+
iroh::discovery::ConcurrentDiscovery::from_services(vec![
5557
Box::new(
56-
iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery::new(
58+
iroh::discovery::local_swarm_discovery::LocalSwarmDiscovery::new(
5759
secret_key.public(),
5860
)?,
5961
),
60-
Box::new(iroh_net::discovery::dns::DnsDiscovery::n0_dns()),
61-
Box::new(iroh_net::discovery::pkarr::PkarrPublisher::n0_dns(
62+
Box::new(iroh::discovery::dns::DnsDiscovery::n0_dns()),
63+
Box::new(iroh::discovery::pkarr::PkarrPublisher::n0_dns(
6264
secret_key.clone(),
6365
)),
6466
]),
@@ -74,24 +76,16 @@ async fn server(args: Config) -> anyhow::Result<()> {
7476

7577
println!("Node ID: {}", my_addr.node_id);
7678

77-
// Listen for incomming connections
78-
while let Some(connecting) = endpoint.accept().await {
79-
let connection = connecting.await;
80-
81-
match connection {
82-
Ok(conn) => {
83-
info!(
84-
connection_id = conn.stable_id(),
85-
addr = ?conn.remote_address(),
86-
"Accepted connection from client"
87-
);
88-
89-
// Spawn a task to handle the new connection
90-
tokio::task::spawn(matchmaker::handle_connection(endpoint.clone(), conn));
91-
}
92-
Err(e) => error!("Error opening client connection: {e:?}"),
93-
}
94-
}
79+
let matchmaker = Matchmaker::new(endpoint.clone());
80+
let router = iroh::protocol::Router::builder(endpoint)
81+
.accept(MATCH_ALPN, Arc::new(matchmaker))
82+
.spawn()
83+
.await?;
84+
85+
// wait for shutdown
86+
tokio::signal::ctrl_c().await?;
87+
88+
router.shutdown().await?;
9589

9690
info!("Server shutdown");
9791

0 commit comments

Comments
 (0)