Skip to content

Commit a55529b

Browse files
authored
refactor(iroh)!: Remove gossip rpc types (#2834)
## Description Remove gossip rpc types. They live in iroh-gossip now under a feature flag. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions note: updates to quic-rpc 0.13 ## Change checklist - [ ] Self-review. - [ ] 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. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent fad3e24 commit a55529b

File tree

11 files changed

+65
-206
lines changed

11 files changed

+65
-206
lines changed

Cargo.lock

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

iroh-cli/src/commands/gossip.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use bao_tree::blake3;
77
use clap::{ArgGroup, Subcommand};
88
use futures_lite::StreamExt;
99
use futures_util::SinkExt;
10-
use iroh::{
11-
client::{gossip::SubscribeOpts, Iroh},
12-
net::NodeId,
13-
};
10+
use iroh::{client::Iroh, net::NodeId};
11+
use iroh_gossip::rpc::client::SubscribeOpts;
1412
use tokio::io::AsyncBufReadExt;
1513

1614
/// Commands to manage gossiping.

iroh/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ iroh-docs = { version = "0.27.0" }
3939
iroh-gossip = "0.27.0"
4040
parking_lot = "0.12.1"
4141
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
42-
quic-rpc = { version = "0.12", default-features = false, features = ["flume-transport", "quinn-transport"] }
43-
quic-rpc-derive = { version = "0.12" }
42+
quic-rpc = { version = "0.13", default-features = false, features = ["flume-transport", "quinn-transport"] }
43+
quic-rpc-derive = { version = "0.13" }
4444
quinn = { package = "iroh-quinn", version = "0.11" }
4545
rand = "0.8"
4646
serde = { version = "1", features = ["derive"] }

iroh/src/client.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::collections::BTreeMap;
66

77
use anyhow::Result;
88
use futures_lite::{Stream, StreamExt};
9+
use quic_rpc::client::BoxedServiceConnection;
910
use ref_cast::RefCast;
1011

1112
use crate::rpc_protocol::node::{CounterStats, ShutdownRequest, StatsRequest, StatusRequest};
@@ -20,18 +21,16 @@ pub use self::{docs::Doc, net::NodeStatus};
2021
pub mod authors;
2122
pub mod blobs;
2223
pub mod docs;
23-
pub mod gossip;
2424
pub mod net;
2525
pub mod tags;
2626

2727
/// Iroh rpc connection - boxed so that we can have a concrete type.
28-
pub(crate) type RpcConnection = quic_rpc::transport::boxed::Connection<RpcService>;
28+
pub(crate) type RpcConnection = BoxedServiceConnection<RpcService>;
2929

3030
// Keep this type exposed, otherwise every occurrence of `RpcClient` in the API
3131
// will show up as `RpcClient<RpcService, Connection<RpcService>>` in the docs.
3232
/// Iroh rpc client - boxed so that we can have a concrete type.
33-
pub type RpcClient =
34-
quic_rpc::RpcClient<RpcService, quic_rpc::transport::boxed::Connection<RpcService>>;
33+
pub type RpcClient = quic_rpc::RpcClient<RpcService>;
3534

3635
/// An iroh client.
3736
///
@@ -81,8 +80,9 @@ impl Iroh {
8180
}
8281

8382
/// Returns the gossip client.
84-
pub fn gossip(&self) -> &gossip::Client {
85-
gossip::Client::ref_cast(&self.rpc)
83+
pub fn gossip(&self) -> iroh_gossip::RpcClient<RpcService> {
84+
let channel = self.rpc.clone().map::<iroh_gossip::RpcService>();
85+
iroh_gossip::RpcClient::new(channel)
8686
}
8787

8888
/// Returns the net client.

iroh/src/client/gossip.rs

Lines changed: 0 additions & 111 deletions
This file was deleted.

iroh/src/client/quic.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ use anyhow::{bail, Context};
1111
use quic_rpc::transport::{boxed::Connection as BoxedConnection, quinn::QuinnConnection};
1212

1313
use super::{Iroh, RpcClient};
14-
use crate::{
15-
node::RpcStatus,
16-
rpc_protocol::{node::StatusRequest, RpcService},
17-
};
14+
use crate::{node::RpcStatus, rpc_protocol::node::StatusRequest};
1815

1916
/// ALPN used by irohs RPC mechanism.
2017
// TODO: Change to "/iroh-rpc/1"
@@ -46,7 +43,7 @@ pub(crate) async fn connect_raw(addr: SocketAddr) -> anyhow::Result<RpcClient> {
4643
let endpoint = create_quinn_client(bind_addr, vec![RPC_ALPN.to_vec()], false)?;
4744

4845
let server_name = "localhost".to_string();
49-
let connection = QuinnConnection::<RpcService>::new(endpoint, addr, server_name);
46+
let connection = QuinnConnection::new(endpoint, addr, server_name);
5047
let connection = BoxedConnection::new(connection);
5148
let client = RpcClient::new(connection);
5249
// Do a status request to check if the server is running.

iroh/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//! manage and share content-addressed blobs of data
5050
//! - [tags](crate::client::tags):
5151
//! tags to tell iroh what data is important
52-
//! - [gossip](crate::client::gossip):
52+
//! - [gossip](iroh_gossip::RpcClient):
5353
//! exchange data with other nodes via a gossip protocol
5454
//!
5555
//! - [authors](crate::client::authors):

iroh/src/node/builder.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ where
691691
.await?;
692692

693693
// Initialize the internal RPC connection.
694-
let (internal_rpc, controller) = quic_rpc::transport::flume::connection::<RpcService>(32);
694+
let (internal_rpc, controller) =
695+
quic_rpc::transport::flume::service_connection::<RpcService>(32);
695696
let internal_rpc = quic_rpc::transport::boxed::ServerEndpoint::new(internal_rpc);
696697
// box the controller. Boxing has a special case for the flume channel that avoids allocations,
697698
// so this has zero overhead.
@@ -951,7 +952,10 @@ pub const DEFAULT_RPC_ADDR: SocketAddr =
951952
fn make_rpc_endpoint(
952953
secret_key: &SecretKey,
953954
mut rpc_addr: SocketAddr,
954-
) -> Result<(QuinnServerEndpoint<RpcService>, u16)> {
955+
) -> Result<(
956+
QuinnServerEndpoint<crate::rpc_protocol::Request, crate::rpc_protocol::Response>,
957+
u16,
958+
)> {
955959
let mut transport_config = quinn::TransportConfig::default();
956960
transport_config
957961
.max_concurrent_bidi_streams(MAX_RPC_STREAMS.into())
@@ -982,7 +986,7 @@ fn make_rpc_endpoint(
982986
};
983987

984988
let actual_rpc_port = rpc_quinn_endpoint.local_addr()?.port();
985-
let rpc_endpoint = QuinnServerEndpoint::<RpcService>::new(rpc_quinn_endpoint)?;
989+
let rpc_endpoint = QuinnServerEndpoint::new(rpc_quinn_endpoint)?;
986990

987991
Ok((rpc_endpoint, actual_rpc_port))
988992
}

iroh/src/node/rpc.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ use crate::{
6060
ExportFileRequest, ExportFileResponse, ImportFileRequest, ImportFileResponse,
6161
Request as DocsRequest, SetHashRequest,
6262
},
63-
gossip,
6463
net::{
6564
self, AddAddrRequest, AddrRequest, IdRequest, NodeWatchRequest, RelayRequest,
6665
RemoteInfoRequest, RemoteInfoResponse, RemoteInfosIterRequest, RemoteInfosIterResponse,
@@ -245,31 +244,15 @@ impl<D: BaoStore> Handler<D> {
245244

246245
async fn handle_gossip_request(
247246
self,
248-
msg: gossip::Request,
247+
msg: iroh_gossip::RpcRequest,
249248
chan: RpcChannel<RpcService, IrohServerEndpoint>,
250249
) -> Result<(), RpcServerError<IrohServerEndpoint>> {
251-
use gossip::Request::*;
252-
match msg {
253-
Subscribe(msg) => {
254-
chan.bidi_streaming(msg, self, |handler, req, updates| {
255-
let stream = handler
256-
.router
257-
.get_protocol::<Gossip>(GOSSIP_ALPN)
258-
.expect("missing gossip")
259-
.join_with_stream(
260-
req.topic,
261-
iroh_gossip::net::JoinOptions {
262-
bootstrap: req.bootstrap,
263-
subscription_capacity: req.subscription_capacity,
264-
},
265-
Box::pin(updates),
266-
);
267-
futures_util::TryStreamExt::map_err(stream, |e| RpcError::new(&*e))
268-
})
269-
.await
270-
}
271-
Update(_msg) => Err(RpcServerError::UnexpectedUpdateMessage),
272-
}
250+
let gossip = self
251+
.router
252+
.get_protocol::<Gossip>(GOSSIP_ALPN)
253+
.expect("missing gossip");
254+
let chan = chan.map::<iroh_gossip::RpcService>();
255+
gossip.handle_rpc_request(msg, chan).await
273256
}
274257

275258
async fn handle_authors_request(

iroh/src/rpc_protocol.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use serde::{Deserialize, Serialize};
2020
pub mod authors;
2121
pub mod blobs;
2222
pub mod docs;
23-
pub mod gossip;
2423
pub mod net;
2524
pub mod node;
2625
pub mod tags;
@@ -40,7 +39,7 @@ pub enum Request {
4039
Docs(docs::Request),
4140
Tags(tags::Request),
4241
Authors(authors::Request),
43-
Gossip(gossip::Request),
42+
Gossip(iroh_gossip::RpcRequest),
4443
}
4544

4645
/// The response enum, listing all possible responses.
@@ -54,7 +53,7 @@ pub enum Response {
5453
Tags(tags::Response),
5554
Docs(docs::Response),
5655
Authors(authors::Response),
57-
Gossip(gossip::Response),
56+
Gossip(iroh_gossip::RpcResponse),
5857
}
5958

6059
impl quic_rpc::Service for RpcService {

0 commit comments

Comments
 (0)