Skip to content

Commit

Permalink
refactor(iroh): move rpc handling into its own module (#2078)
Browse files Browse the repository at this point in the history
And some more minor node cleanups.
  • Loading branch information
dignifiedquire authored Mar 16, 2024
1 parent 8d86ffc commit e7690b9
Show file tree
Hide file tree
Showing 5 changed files with 1,087 additions and 1,087 deletions.
13 changes: 9 additions & 4 deletions iroh-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::rpc::RpcStatus;

const DEFAULT_RPC_PORT: u16 = 0x1337;
const MAX_RPC_CONNECTIONS: u32 = 16;
const MAX_RPC_STREAMS: u64 = 1024;
const MAX_RPC_STREAMS: u32 = 1024;

/// Whether to stop the node after running a command or run forever until stopped.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -254,12 +254,17 @@ async fn make_rpc_endpoint(
iroh_data_root: &Path,
) -> Result<impl ServiceEndpoint<ProviderService>> {
let rpc_addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, rpc_port);
let server_config = iroh::node::make_server_config(
let mut transport_config = quinn::TransportConfig::default();
transport_config
.max_concurrent_bidi_streams(MAX_RPC_STREAMS.into())
.max_concurrent_uni_streams(0u32.into());
let mut server_config = iroh::net::magic_endpoint::make_server_config(
secret_key,
MAX_RPC_STREAMS,
MAX_RPC_CONNECTIONS,
vec![RPC_ALPN.to_vec()],
Some(transport_config),
false,
)?;
server_config.concurrent_connections(MAX_RPC_CONNECTIONS);

let rpc_quinn_endpoint = quinn::Endpoint::server(server_config.clone(), rpc_addr.into());
let rpc_quinn_endpoint = match rpc_quinn_endpoint {
Expand Down
4 changes: 3 additions & 1 deletion iroh-net/src/magic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ impl MagicEndpointBuilder {
}
}

fn make_server_config(
/// Create a [`quinn::ServerConfig`] with the given secret key and limits.
pub fn make_server_config(
secret_key: &SecretKey,
alpn_protocols: Vec<Vec<u8>>,
transport_config: Option<quinn::TransportConfig>,
Expand All @@ -186,6 +187,7 @@ fn make_server_config(
let tls_server_config = tls::make_server_config(secret_key, alpn_protocols, keylog)?;
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(tls_server_config));
server_config.transport_config(Arc::new(transport_config.unwrap_or_default()));

Ok(server_config)
}

Expand Down
12 changes: 9 additions & 3 deletions iroh/examples/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ fn make_rpc_endpoint(
secret_key: &SecretKey,
) -> anyhow::Result<impl ServiceEndpoint<ProviderService>> {
let rpc_addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, DEFAULT_RPC_PORT));
let rpc_quinn_endpoint = quinn::Endpoint::server(
iroh::node::make_server_config(secret_key, 8, 1024, vec![RPC_ALPN.to_vec()])?,
rpc_addr,
let mut transport_config = quinn::TransportConfig::default();
transport_config.max_concurrent_bidi_streams(8u32.into());
let mut config = iroh_net::magic_endpoint::make_server_config(
secret_key,
vec![RPC_ALPN.to_vec()],
Some(transport_config),
false,
)?;
config.concurrent_connections(1024);
let rpc_quinn_endpoint = quinn::Endpoint::server(config, rpc_addr)?;
let rpc_endpoint =
QuinnServerEndpoint::<ProviderRequest, ProviderResponse>::new(rpc_quinn_endpoint)?;
Ok(rpc_endpoint)
Expand Down
Loading

0 comments on commit e7690b9

Please sign in to comment.