Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
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
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
32 changes: 16 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,11 @@ pub mod channel {
value: U,
) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>> {
Box::pin(async move {
if let Some(v) = (self.f)(value) {
match (self.f)(value) { Some(v) => {
self.sender.send(v).await
} else {
} _ => {
Ok(())
}
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird? :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh yeah, reran fmt, dunno what was going on there

})
}

Expand All @@ -1025,11 +1025,11 @@ pub mod channel {
value: U,
) -> Pin<Box<dyn Future<Output = Result<bool, SendError>> + Send + '_>> {
Box::pin(async move {
if let Some(v) = (self.f)(value) {
match (self.f)(value) { Some(v) => {
self.sender.try_send(v).await
} else {
} _ => {
Ok(true)
}
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too

})
}

Expand Down Expand Up @@ -1349,7 +1349,7 @@ impl<S: Service> Client<S> {
&self,
) -> impl Future<
Output = result::Result<Request<LocalSender<S>, rpc::RemoteSender<S>>, RequestError>,
> + 'static {
> + 'static + use<S> {
#[cfg(feature = "rpc")]
{
let cloned = match &self.0 {
Expand Down Expand Up @@ -1377,7 +1377,7 @@ impl<S: Service> Client<S> {
}

/// Performs a request for which the server returns a oneshot receiver.
pub fn rpc<Req, Res>(&self, msg: Req) -> impl Future<Output = Result<Res>> + Send + 'static
pub fn rpc<Req, Res>(&self, msg: Req) -> impl Future<Output = Result<Res>> + Send + 'static + use<Req, Res, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1410,7 +1410,7 @@ impl<S: Service> Client<S> {
&self,
msg: Req,
local_response_cap: usize,
) -> impl Future<Output = Result<mpsc::Receiver<Res>>> + Send + 'static
) -> impl Future<Output = Result<mpsc::Receiver<Res>>> + Send + 'static + use<Req, Res, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1442,7 +1442,7 @@ impl<S: Service> Client<S> {
&self,
msg: Req,
local_update_cap: usize,
) -> impl Future<Output = Result<(mpsc::Sender<Update>, oneshot::Receiver<Res>)>>
) -> impl Future<Output = Result<(mpsc::Sender<Update>, oneshot::Receiver<Res>)>> + use<Req, Update, Res, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1478,7 +1478,7 @@ impl<S: Service> Client<S> {
msg: Req,
local_update_cap: usize,
local_response_cap: usize,
) -> impl Future<Output = Result<(mpsc::Sender<Update>, mpsc::Receiver<Res>)>> + Send + 'static
) -> impl Future<Output = Result<(mpsc::Sender<Update>, mpsc::Receiver<Res>)>> + Send + 'static + use<Req, Update, Res, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1511,7 +1511,7 @@ impl<S: Service> Client<S> {
/// Performs a request for which the server returns nothing.
///
/// The returned future completes once the message is sent.
pub fn notify<Req>(&self, msg: Req) -> impl Future<Output = Result<()>> + Send + 'static
pub fn notify<Req>(&self, msg: Req) -> impl Future<Output = Result<()>> + Send + 'static + use<Req, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1541,7 +1541,7 @@ impl<S: Service> Client<S> {
/// Compared to [Self::notify], this variant takes a future that returns true
/// if 0rtt has been accepted. If not, the data is sent again via the same
/// remote channel. For local requests, the future is ignored.
pub fn notify_0rtt<Req>(&self, msg: Req) -> impl Future<Output = Result<()>> + Send + 'static
pub fn notify_0rtt<Req>(&self, msg: Req) -> impl Future<Output = Result<()>> + Send + 'static + use<Req, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1578,7 +1578,7 @@ impl<S: Service> Client<S> {
/// Compared to [Self::rpc], this variant takes a future that returns true
/// if 0rtt has been accepted. If not, the data is sent again via the same
/// remote channel. For local requests, the future is ignored.
pub fn rpc_0rtt<Req, Res>(&self, msg: Req) -> impl Future<Output = Result<Res>> + Send + 'static
pub fn rpc_0rtt<Req, Res>(&self, msg: Req) -> impl Future<Output = Result<Res>> + Send + 'static + use<Req, Res, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -1627,7 +1627,7 @@ impl<S: Service> Client<S> {
&self,
msg: Req,
local_response_cap: usize,
) -> impl Future<Output = Result<mpsc::Receiver<Res>>> + Send + 'static
) -> impl Future<Output = Result<mpsc::Receiver<Res>>> + Send + 'static + use<Req, Res, S>
where
S: From<Req>,
S::Message: From<WithChannels<Req, S>>,
Expand Down Expand Up @@ -2525,7 +2525,7 @@ impl<S: Service> LocalSender<S> {
pub fn send_raw(
&self,
value: S::Message,
) -> impl Future<Output = std::result::Result<(), SendError>> + Send + 'static {
) -> impl Future<Output = std::result::Result<(), SendError>> + Send + 'static + use<S> {
let x = self.0.clone();
async move { x.send(value).await }
}
Expand Down
Loading
Loading