Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
with:
components: rustfmt, clippy
- uses: swatinem/rust-cache@v2
- name: cargo fmt
run: cargo fmt --all -- --check
- uses: taiki-e/install-action@cargo-make
- name: cargo clippy
run: cargo clippy --locked --workspace --all-targets --all-features
- run: cargo make format-check

test:
runs-on: ${{ matrix.target.os }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "irpc"
version = "0.12.0"
edition = "2021"
edition = "2024"
authors = ["Rüdiger Klaehn <rklaehn@protonmail.com>", "n0 team"]
keywords = ["api", "protocol", "network", "rpc"]
categories = ["network-programming"]
Expand Down
28 changes: 28 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use cargo-make to run tasks here: https://crates.io/crates/cargo-make

[tasks.format]
workspace = false
command = "cargo"
args = [
"fmt",
"--all",
"--",
"--config",
"unstable_features=true",
"--config",
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true,format_code_in_doc_comments=true",
]

[tasks.format-check]
workspace = false
command = "cargo"
args = [
"fmt",
"--all",
"--check",
"--",
"--config",
"unstable_features=true",
"--config",
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true,format_code_in_doc_comments=true",
]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ See the [module docs](https://docs.rs/irpc/latest/irpc/).
Properly building docs for this crate is quite complex. For all the gory details,
see [DOCS.md].

# Development

Run `cargo make format` before committing, it will run `cargo fmt` with the arguments expected by this project.

## License

Copyright 2025 N0, INC.
Expand Down
4 changes: 2 additions & 2 deletions examples/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::{
use anyhow::bail;
use futures_buffered::BufferedStreamExt;
use irpc::{
Client, Request, WithChannels,
channel::{mpsc, oneshot},
rpc::{listen, RemoteService},
rpc::{RemoteService, listen},
rpc_requests,
util::{make_client_endpoint, make_server_endpoint},
Client, Request, WithChannels,
};
use n0_future::{
stream::StreamExt,
Expand Down
2 changes: 1 addition & 1 deletion examples/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::{

use anyhow::{Context, Result};
use irpc::{
Client, WithChannels,
channel::{mpsc, oneshot},
rpc::RemoteService,
rpc_requests,
util::{make_client_endpoint, make_server_endpoint},
Client, WithChannels,
};
// Import the macro
use n0_future::task::{self, AbortOnDropHandle};
Expand Down
2 changes: 1 addition & 1 deletion examples/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::collections::BTreeMap;

use irpc::{channel::oneshot, rpc_requests, Client, WithChannels};
use irpc::{Client, WithChannels, channel::oneshot, rpc_requests};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions examples/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::{

use anyhow::bail;
use irpc::{
Channels, Client, Request, Service, WithChannels,
channel::{mpsc, none::NoReceiver, oneshot},
rpc::{listen, RemoteService},
rpc::{RemoteService, listen},
util::{make_client_endpoint, make_server_endpoint},
Channels, Client, Request, Service, WithChannels,
};
use n0_future::task::{self, AbortOnDropHandle};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion irpc-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "irpc-derive"
version = "0.9.0"
edition = "2021"
edition = "2024"
authors = ["Rüdiger Klaehn <rklaehn@protonmail.com>"]
keywords = ["api", "protocol", "network", "rpc", "macro"]
categories = ["network-programming"]
Expand Down
29 changes: 18 additions & 11 deletions irpc-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::collections::HashSet;

use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{quote, ToTokens};
use quote::{ToTokens, quote};
use syn::{
Attribute, Data, DeriveInput, Error, Fields, Ident, LitStr, Token, Type, Visibility,
parse::{Parse, ParseStream},
parse_macro_input,
punctuated::Punctuated,
spanned::Spanned,
token::Comma,
Attribute, Data, DeriveInput, Error, Fields, Ident, LitStr, Token, Type, Visibility,
};

/// Attribute on protocol enums and variants
Expand Down Expand Up @@ -40,7 +40,7 @@ pub fn rpc_requests(attr: TokenStream, item: TokenStream) -> TokenStream {
return error_tokens(
input.span(),
"The rpc_requests macro can only be applied to enums",
)
);
}
};

Expand Down Expand Up @@ -68,18 +68,25 @@ pub fn rpc_requests(attr: TokenStream, item: TokenStream) -> TokenStream {

let request_type = match rpc_attr.wrap {
None => match &mut variant.fields {
Fields::Unnamed(ref mut fields) if fields.unnamed.len() == 1 => {
Fields::Unnamed(fields) if fields.unnamed.len() == 1 => {
fields.unnamed[0].ty.clone()
}
_ => return error_tokens(
variant.span(),
"Each variant must either have exactly one unnamed field, or use the `wrap` argument in the `rpc` attribute.",
),
_ => {
return error_tokens(
variant.span(),
"Each variant must either have exactly one unnamed field, or use the `wrap` argument in the `rpc` attribute.",
);
}
},
Some(WrapArgs { ident, derive, vis }) => {
let vis = vis.as_ref().unwrap_or(&input.vis).clone();
let ty = type_from_ident(&ident);
let struc = struct_from_variant_fields(ident, variant.fields.clone(), variant.attrs.clone(), vis);
let struc = struct_from_variant_fields(
ident,
variant.fields.clone(),
variant.attrs.clone(),
vis,
);
wrapper_types.extend(quote! {
#[derive(::std::fmt::Debug, ::serde::Serialize, ::serde::Deserialize, #(#derive),* )]
#struc
Expand Down Expand Up @@ -543,8 +550,8 @@ fn single_unnamed_field(ty: Type) -> Fields {

fn set_fields_vis(fields: &mut Fields, vis: &Visibility) {
let inner = match fields {
Fields::Named(ref mut named) => named.named.iter_mut(),
Fields::Unnamed(ref mut unnamed) => unnamed.unnamed.iter_mut(),
Fields::Named(named) => named.named.iter_mut(),
Fields::Unnamed(unnamed) => unnamed.unnamed.iter_mut(),
Fields::Unit => return,
};
for field in inner {
Expand Down
2 changes: 1 addition & 1 deletion irpc-iroh/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "irpc-iroh"
version = "0.12.0"
edition = "2021"
edition = "2024"
authors = ["Rüdiger Klaehn <rklaehn@protonmail.com>", "n0 team"]
keywords = ["api", "protocol", "network", "rpc"]
categories = ["network-programming"]
Expand Down
8 changes: 5 additions & 3 deletions irpc-iroh/examples/0rtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::{
use anyhow::{Context, Result};
use clap::Parser;
use iroh::{
Endpoint, EndpointAddr, EndpointId, SecretKey,
endpoint::{AfterHandshakeOutcome, ConnectionInfo, EndpointHooks},
protocol::Router,
Endpoint, EndpointAddr, EndpointId, SecretKey,
};
use ping::EchoApi;

Expand Down Expand Up @@ -54,7 +54,9 @@ async fn main() -> Result<()> {
wait_for_ticket,
} => {
if !no_0rtt && !wait_for_ticket {
eprintln!("0-RTT is enabled but wait_for_ticket is not set. After 2 requests with 0rtt the 0rtt resumption tickets will be consumed and a connection will be done without 0rtt.");
eprintln!(
"0-RTT is enabled but wait_for_ticket is not set. After 2 requests with 0rtt the 0rtt resumption tickets will be consumed and a connection will be done without 0rtt."
);
}
let n = n
.iter()
Expand Down Expand Up @@ -226,7 +228,7 @@ mod cli {
mod ping {
use anyhow::{Context, Result};
use iroh::Endpoint;
use irpc::{channel::oneshot, rpc::RemoteService, rpc_requests, Client, WithChannels};
use irpc::{Client, WithChannels, channel::oneshot, rpc::RemoteService, rpc_requests};
use irpc_iroh::{
Iroh0RttProtocol, IrohProtocol, IrohRemoteConnection, IrohZrttRemoteConnection,
};
Expand Down
9 changes: 5 additions & 4 deletions irpc-iroh/examples/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! * Authenticating peers

use anyhow::Result;
use iroh::{protocol::Router, Endpoint};
use iroh::{Endpoint, protocol::Router};

use self::storage::{StorageClient, StorageServer};

Expand Down Expand Up @@ -67,16 +67,17 @@ mod storage {

use anyhow::Result;
use iroh::{
Endpoint,
endpoint::Connection,
protocol::{AcceptError, ProtocolHandler},
Endpoint,
};
use irpc::{
Client, WithChannels,
channel::{mpsc, oneshot},
rpc_requests, Client, WithChannels,
rpc_requests,
};
// Import the macro
use irpc_iroh::{read_request, IrohLazyRemoteConnection};
use irpc_iroh::{IrohLazyRemoteConnection, read_request};
use serde::{Deserialize, Serialize};
use tracing::info;

Expand Down
7 changes: 4 additions & 3 deletions irpc-iroh/examples/remote-and-local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! The [`StorageApi`] struct is only defined once and can be used both locally and as a remote client.

use anyhow::Result;
use iroh::{protocol::Router, Endpoint};
use iroh::{Endpoint, protocol::Router};

use self::storage::StorageApi;

Expand Down Expand Up @@ -71,11 +71,12 @@ mod storage {
use std::{collections::BTreeMap, sync::Arc};

use anyhow::{Context, Result};
use iroh::{protocol::ProtocolHandler, Endpoint};
use iroh::{Endpoint, protocol::ProtocolHandler};
use irpc::{
Client, WithChannels,
channel::{mpsc, oneshot},
rpc::RemoteService,
rpc_requests, Client, WithChannels,
rpc_requests,
};
// Import the macro
use irpc_iroh::{IrohLazyRemoteConnection, IrohProtocol};
Expand Down
6 changes: 3 additions & 3 deletions irpc-iroh/examples/server-actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod proto {
use std::collections::HashMap;

use anyhow::Result;
use iroh::{protocol::Router, Endpoint, EndpointId};
use irpc::{channel::oneshot, rpc_requests, Client, WithChannels};
use iroh::{Endpoint, EndpointId, protocol::Router};
use irpc::{Client, WithChannels, channel::oneshot, rpc_requests};
use irpc_iroh::IrohProtocol;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -90,7 +90,7 @@ mod cli {
use clap::Parser;
use iroh::EndpointId;

use crate::proto::{connect, listen, GetRequest, SetRequest};
use crate::proto::{GetRequest, SetRequest, connect, listen};

#[derive(Debug, Parser)]
enum Cli {
Expand Down
9 changes: 5 additions & 4 deletions irpc-iroh/examples/server-shared-state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! on the server side instead of with an actor loop.

use anyhow::Result;
use iroh::{protocol::Router, Endpoint};
use iroh::{Endpoint, protocol::Router};

use self::storage::{StorageClient, StorageServer};

Expand Down Expand Up @@ -54,16 +54,17 @@ mod storage {

use anyhow::Result;
use iroh::{
Endpoint,
endpoint::Connection,
protocol::{AcceptError, ProtocolHandler},
Endpoint,
};
use irpc::{
Client, WithChannels,
channel::{mpsc, oneshot},
rpc_requests, Client, WithChannels,
rpc_requests,
};
// Import the macro
use irpc_iroh::{read_request, IrohLazyRemoteConnection, IrohRemoteConnection};
use irpc_iroh::{IrohLazyRemoteConnection, IrohRemoteConnection, read_request};
use serde::{Deserialize, Serialize};
use tracing::info;

Expand Down
16 changes: 8 additions & 8 deletions irpc-iroh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ use std::{
fmt,
future::Future,
io,
sync::{atomic::AtomicU64, Arc},
sync::{Arc, atomic::AtomicU64},
};

use iroh::{
EndpointId,
endpoint::{
Accepting, Connection, ConnectionError, IncomingZeroRttConnection,
OutgoingZeroRttConnection, RecvStream, RemoteEndpointIdError, SendStream, VarInt,
ZeroRttStatus,
},
protocol::{AcceptError, ProtocolHandler},
EndpointId,
};
use irpc::{
LocalSender, RequestError,
channel::oneshot,
rpc::{
Handler, RemoteConnection, RemoteService, ERROR_CODE_MAX_MESSAGE_SIZE_EXCEEDED,
MAX_MESSAGE_SIZE,
ERROR_CODE_MAX_MESSAGE_SIZE_EXCEEDED, Handler, MAX_MESSAGE_SIZE, RemoteConnection,
RemoteService,
},
util::AsyncReadVarintExt,
LocalSender, RequestError,
};
use n0_error::{e, Result};
use n0_future::{future::Boxed as BoxFuture, TryFutureExt};
use n0_error::{Result, e};
use n0_future::{TryFutureExt, future::Boxed as BoxFuture};
use serde::de::DeserializeOwned;
use tracing::{debug, error_span, trace, trace_span, warn, Instrument};
use tracing::{Instrument, debug, error_span, trace, trace_span, warn};

/// Returns a client that connects to a irpc service using an [`iroh::Endpoint`].
pub fn client<S: irpc::Service>(
Expand Down
Loading
Loading