diff --git a/Cargo.lock b/Cargo.lock index 147fd0f40f..3e42d41260 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2474,6 +2474,7 @@ dependencies = [ "postcard", "proptest", "quic-rpc", + "quic-rpc-derive", "rand", "rand_chacha", "ref-cast", @@ -4151,6 +4152,18 @@ dependencies = [ "tracing", ] +[[package]] +name = "quic-rpc-derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b02c2d3637609d07aa2560f178588dce09cf2f4f5cdcc9b0caac0063a188a898" +dependencies = [ + "proc-macro2", + "quic-rpc", + "quote", + "syn 1.0.109", +] + [[package]] name = "quick-error" version = "1.2.3" diff --git a/iroh/Cargo.toml b/iroh/Cargo.toml index 8256150f05..a8309b6a3f 100644 --- a/iroh/Cargo.toml +++ b/iroh/Cargo.toml @@ -39,6 +39,7 @@ iroh-gossip = { version = "0.20.0", path = "../iroh-gossip" } parking_lot = "0.12.1" postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] } quic-rpc = { version = "0.11", default-features = false, features = ["flume-transport", "quinn-transport"] } +quic-rpc-derive = { version = "0.11" } quinn = { package = "iroh-quinn", version = "0.10" } rand = "0.8" serde = { version = "1", features = ["derive"] } diff --git a/iroh/src/rpc_protocol.rs b/iroh/src/rpc_protocol.rs index bac8d577b2..59227dadca 100644 --- a/iroh/src/rpc_protocol.rs +++ b/iroh/src/rpc_protocol.rs @@ -1,12 +1,20 @@ //! This defines the RPC protocol used for communication between a CLI and an iroh node. //! -//! RPC using the [`quic-rpc`](https://docs.rs/quic-rpc) crate. +//! RPC is done using the [`quic-rpc`](https://docs.rs/quic-rpc) crate. //! -//! This file contains request messages, response messages and definitions of -//! the interaction pattern. Some requests like version and shutdown have a single -//! response, while others like provide have a stream of responses. +//! The RPC protocol is split into subsystems. In each subsystem, there is an +//! enum for the requests and an enum for the responses. The top level request +//! and response enums have a variant for each subsystem. //! -//! Note that this is subject to change. The RPC protocol is not yet stable. +//! Request and response enums for each subsystem derive conversions to the +//! top level enums using the +//! [`enum_conversions``](https://docs.rs/nested_enum_utils/0.1.0/nested_enum_utils/attr.enum_conversions.html) +//! macro. +//! +//! For each rpc request, the quic-rpc interaction pattern is defined using +//! attributes provided by the +//! [`rpc_requests`](https://docs.rs/quic-rpc-derive/latest/quic_rpc_derive/attr.rpc_requests.html) +//! macro. use serde::{Deserialize, Serialize}; pub mod authors; diff --git a/iroh/src/rpc_protocol/authors.rs b/iroh/src/rpc_protocol/authors.rs index ccf538340f..fec3b93ddb 100644 --- a/iroh/src/rpc_protocol/authors.rs +++ b/iroh/src/rpc_protocol/authors.rs @@ -1,26 +1,35 @@ use iroh_base::rpc::RpcResult; use iroh_docs::{Author, AuthorId}; -use quic_rpc::message::{Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}; +use nested_enum_utils::enum_conversions; +use quic_rpc_derive::rpc_requests; use serde::{Deserialize, Serialize}; use super::RpcService; #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Request)] +#[enum_conversions(super::Request)] +#[rpc_requests(RpcService)] pub enum Request { + #[server_streaming(response = RpcResult)] List(ListRequest), + #[rpc(response = RpcResult)] Create(CreateRequest), + #[rpc(response = RpcResult)] GetDefault(GetDefaultRequest), + #[rpc(response = RpcResult)] SetDefault(SetDefaultRequest), + #[rpc(response = RpcResult)] Import(ImportRequest), + #[rpc(response = RpcResult)] Export(ExportRequest), + #[rpc(response = RpcResult)] Delete(DeleteRequest), } #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Response)] +#[enum_conversions(super::Response)] pub enum Response { List(RpcResult), Create(RpcResult), @@ -35,14 +44,6 @@ pub enum Response { #[derive(Serialize, Deserialize, Debug)] pub struct ListRequest {} -impl Msg for ListRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ListRequest { - type Response = RpcResult; -} - /// Response for [`ListRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct ListResponse { @@ -54,10 +55,6 @@ pub struct ListResponse { #[derive(Serialize, Deserialize, Debug)] pub struct CreateRequest; -impl RpcMsg for CreateRequest { - type Response = RpcResult; -} - /// Response for [`CreateRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct CreateResponse { @@ -69,10 +66,6 @@ pub struct CreateResponse { #[derive(Serialize, Deserialize, Debug)] pub struct GetDefaultRequest; -impl RpcMsg for GetDefaultRequest { - type Response = RpcResult; -} - /// Response for [`GetDefaultRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct GetDefaultResponse { @@ -86,10 +79,6 @@ pub struct SetDefaultRequest { pub author_id: AuthorId, } -impl RpcMsg for SetDefaultRequest { - type Response = RpcResult; -} - /// Response for [`GetDefaultRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct SetDefaultResponse; @@ -101,10 +90,6 @@ pub struct DeleteRequest { pub author: AuthorId, } -impl RpcMsg for DeleteRequest { - type Response = RpcResult; -} - /// Response for [`DeleteRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct DeleteResponse; @@ -116,10 +101,6 @@ pub struct ExportRequest { pub author: AuthorId, } -impl RpcMsg for ExportRequest { - type Response = RpcResult; -} - /// Response for [`ExportRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct ExportResponse { @@ -134,10 +115,6 @@ pub struct ImportRequest { pub author: Author, } -impl RpcMsg for ImportRequest { - type Response = RpcResult; -} - /// Response to [`ImportRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct ImportResponse { diff --git a/iroh/src/rpc_protocol/blobs.rs b/iroh/src/rpc_protocol/blobs.rs index 36cbb54305..a24523a066 100644 --- a/iroh/src/rpc_protocol/blobs.rs +++ b/iroh/src/rpc_protocol/blobs.rs @@ -13,9 +13,8 @@ use iroh_blobs::{ BlobFormat, Tag, }; use iroh_net::NodeAddr; -use quic_rpc::message::{ - BidiStreaming, BidiStreamingMsg, Msg, RpcMsg, ServerStreaming, ServerStreamingMsg, -}; +use nested_enum_utils::enum_conversions; +use quic_rpc_derive::rpc_requests; use serde::{Deserialize, Serialize}; use crate::client::blobs::{BlobInfo, DownloadMode, IncompleteBlobInfo, WrapOption}; @@ -24,25 +23,37 @@ use super::RpcService; #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Request)] +#[enum_conversions(super::Request)] +#[rpc_requests(RpcService)] pub enum Request { + #[server_streaming(response = RpcResult)] ReadAt(ReadAtRequest), + #[bidi_streaming(update = AddStreamUpdate, response = AddStreamResponse)] AddStream(AddStreamRequest), AddStreamUpdate(AddStreamUpdate), + #[server_streaming(response = AddPathResponse)] AddPath(AddPathRequest), + #[server_streaming(response = DownloadResponse)] Download(DownloadRequest), + #[server_streaming(response = ExportResponse)] Export(ExportRequest), + #[server_streaming(response = RpcResult)] List(ListRequest), + #[server_streaming(response = RpcResult)] ListIncomplete(ListIncompleteRequest), + #[rpc(response = RpcResult<()>)] Delete(DeleteRequest), + #[server_streaming(response = ValidateProgress)] Validate(ValidateRequest), + #[server_streaming(response = ConsistencyCheckProgress)] Fsck(ConsistencyCheckRequest), + #[rpc(response = RpcResult)] CreateCollection(CreateCollectionRequest), } #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Response)] +#[enum_conversions(super::Response)] pub enum Response { ReadAt(RpcResult), AddStream(AddStreamResponse), @@ -76,14 +87,6 @@ pub struct AddPathRequest { pub wrap: WrapOption, } -impl Msg for AddPathRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for AddPathRequest { - type Response = AddPathResponse; -} - /// Wrapper around [`AddProgress`]. #[derive(Debug, Serialize, Deserialize, derive_more::Into)] pub struct AddPathResponse(pub AddProgress); @@ -109,14 +112,6 @@ pub struct DownloadRequest { pub mode: DownloadMode, } -impl Msg for DownloadRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for DownloadRequest { - type Response = DownloadResponse; -} - /// Progress response for [`DownloadRequest`] #[derive(Debug, Clone, Serialize, Deserialize, derive_more::From, derive_more::Into)] pub struct DownloadResponse(pub DownloadProgress); @@ -140,14 +135,6 @@ pub struct ExportRequest { pub mode: ExportMode, } -impl Msg for ExportRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ExportRequest { - type Response = ExportResponse; -} - /// Progress response for [`ExportRequest`] #[derive(Debug, Clone, Serialize, Deserialize, derive_more::From, derive_more::Into)] pub struct ExportResponse(pub ExportProgress); @@ -159,14 +146,6 @@ pub struct ConsistencyCheckRequest { pub repair: bool, } -impl Msg for ConsistencyCheckRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ConsistencyCheckRequest { - type Response = ConsistencyCheckProgress; -} - /// A request to the node to validate the integrity of all provided data #[derive(Debug, Serialize, Deserialize)] pub struct ValidateRequest { @@ -174,38 +153,14 @@ pub struct ValidateRequest { pub repair: bool, } -impl Msg for ValidateRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ValidateRequest { - type Response = ValidateProgress; -} - /// List all blobs, including collections #[derive(Debug, Serialize, Deserialize)] pub struct ListRequest; -impl Msg for ListRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ListRequest { - type Response = RpcResult; -} - /// List all blobs, including collections #[derive(Debug, Serialize, Deserialize)] pub struct ListIncompleteRequest; -impl Msg for ListIncompleteRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ListIncompleteRequest { - type Response = RpcResult; -} - /// Get the bytes for a hash #[derive(Serialize, Deserialize, Debug)] pub struct ReadAtRequest { @@ -217,14 +172,6 @@ pub struct ReadAtRequest { pub len: Option, } -impl Msg for ReadAtRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ReadAtRequest { - type Response = RpcResult; -} - /// Response to [`ReadAtRequest`] #[derive(Serialize, Deserialize, Debug)] pub enum ReadAtResponse { @@ -258,15 +205,6 @@ pub enum AddStreamUpdate { Abort, } -impl Msg for AddStreamRequest { - type Pattern = BidiStreaming; -} - -impl BidiStreamingMsg for AddStreamRequest { - type Update = AddStreamUpdate; - type Response = AddStreamResponse; -} - /// Wrapper around [`AddProgress`]. #[derive(Debug, Serialize, Deserialize, derive_more::Into)] pub struct AddStreamResponse(pub AddProgress); @@ -278,10 +216,6 @@ pub struct DeleteRequest { pub hash: Hash, } -impl RpcMsg for DeleteRequest { - type Response = RpcResult<()>; -} - /// Create a collection. #[derive(Debug, Serialize, Deserialize)] pub struct CreateCollectionRequest { @@ -301,7 +235,3 @@ pub struct CreateCollectionResponse { /// The resulting tag. pub tag: Tag, } - -impl RpcMsg for CreateCollectionRequest { - type Response = RpcResult; -} diff --git a/iroh/src/rpc_protocol/docs.rs b/iroh/src/rpc_protocol/docs.rs index db43d9e2dc..71ffe777cd 100644 --- a/iroh/src/rpc_protocol/docs.rs +++ b/iroh/src/rpc_protocol/docs.rs @@ -11,11 +11,9 @@ use iroh_docs::{ CapabilityKind, DocTicket, Entry, NamespaceId, PeerIdBytes, SignedEntry, }; use iroh_net::NodeAddr; -use quic_rpc::{ - message::{Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}, - pattern::try_server_streaming::StreamCreated, - pattern::try_server_streaming::{TryServerStreaming, TryServerStreamingMsg}, -}; +use nested_enum_utils::enum_conversions; +use quic_rpc::pattern::try_server_streaming::StreamCreated; +use quic_rpc_derive::rpc_requests; use serde::{Deserialize, Serialize}; use super::RpcService; @@ -23,34 +21,56 @@ use crate::client::docs::{ImportProgress, ShareMode}; #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Request)] +#[enum_conversions(super::Request)] +#[rpc_requests(RpcService)] pub enum Request { + #[rpc(response = RpcResult)] Open(OpenRequest), + #[rpc(response = RpcResult)] Close(CloseRequest), + #[rpc(response = RpcResult)] Status(StatusRequest), + #[server_streaming(response = RpcResult)] List(DocListRequest), + #[rpc(response = RpcResult)] Create(CreateRequest), + #[rpc(response = RpcResult)] Drop(DropRequest), + #[rpc(response = RpcResult)] Import(ImportRequest), + #[rpc(response = RpcResult)] Set(SetRequest), + #[rpc(response = RpcResult)] SetHash(SetHashRequest), + #[server_streaming(response = RpcResult)] Get(GetManyRequest), + #[rpc(response = RpcResult)] GetExact(GetExactRequest), + #[server_streaming(response = ImportFileResponse)] ImportFile(ImportFileRequest), + #[server_streaming(response = ExportFileResponse)] ExportFile(ExportFileRequest), + #[rpc(response = RpcResult)] Del(DelRequest), + #[rpc(response = RpcResult)] StartSync(StartSyncRequest), + #[rpc(response = RpcResult)] Leave(LeaveRequest), + #[rpc(response = RpcResult)] Share(ShareRequest), + #[try_server_streaming(create_error = RpcError, item_error = RpcError, item = DocSubscribeResponse)] Subscribe(DocSubscribeRequest), + #[rpc(response = RpcResult)] GetDownloadPolicy(GetDownloadPolicyRequest), + #[rpc(response = RpcResult)] SetDownloadPolicy(SetDownloadPolicyRequest), + #[rpc(response = RpcResult)] GetSyncPeers(GetSyncPeersRequest), } #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Response)] +#[enum_conversions(super::Response)] pub enum Response { Open(RpcResult), Close(RpcResult), @@ -83,16 +103,6 @@ pub struct DocSubscribeRequest { pub doc_id: NamespaceId, } -impl Msg for DocSubscribeRequest { - type Pattern = TryServerStreaming; -} - -impl TryServerStreamingMsg for DocSubscribeRequest { - type Item = DocSubscribeResponse; - type ItemError = RpcError; - type CreateError = RpcError; -} - /// Response to [`DocSubscribeRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct DocSubscribeResponse { @@ -104,14 +114,6 @@ pub struct DocSubscribeResponse { #[derive(Serialize, Deserialize, Debug)] pub struct DocListRequest {} -impl Msg for DocListRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for DocListRequest { - type Response = RpcResult; -} - /// Response to [`DocListRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct ListResponse { @@ -125,10 +127,6 @@ pub struct ListResponse { #[derive(Serialize, Deserialize, Debug)] pub struct CreateRequest {} -impl RpcMsg for CreateRequest { - type Response = RpcResult; -} - /// Response to [`CreateRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct CreateResponse { @@ -143,10 +141,6 @@ pub struct ImportRequest { pub capability: Capability, } -impl RpcMsg for ImportRequest { - type Response = RpcResult; -} - /// Response to [`ImportRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct ImportResponse { @@ -165,10 +159,6 @@ pub struct ShareRequest { pub addr_options: AddrInfoOptions, } -impl RpcMsg for ShareRequest { - type Response = RpcResult; -} - /// The response to [`ShareRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct ShareResponse(pub DocTicket); @@ -180,10 +170,6 @@ pub struct StatusRequest { pub doc_id: NamespaceId, } -impl RpcMsg for StatusRequest { - type Response = RpcResult; -} - /// Response to [`StatusRequest`] // TODO: actually provide info #[derive(Serialize, Deserialize, Debug)] @@ -199,10 +185,6 @@ pub struct OpenRequest { pub doc_id: NamespaceId, } -impl RpcMsg for OpenRequest { - type Response = RpcResult; -} - /// Response to [`OpenRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct OpenResponse {} @@ -214,10 +196,6 @@ pub struct CloseRequest { pub doc_id: NamespaceId, } -impl RpcMsg for CloseRequest { - type Response = RpcResult; -} - /// Response to [`CloseRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct CloseResponse {} @@ -231,10 +209,6 @@ pub struct StartSyncRequest { pub peers: Vec, } -impl RpcMsg for StartSyncRequest { - type Response = RpcResult; -} - /// Response to [`StartSyncRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct StartSyncResponse {} @@ -246,10 +220,6 @@ pub struct LeaveRequest { pub doc_id: NamespaceId, } -impl RpcMsg for LeaveRequest { - type Response = RpcResult; -} - /// Response to [`LeaveRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct LeaveResponse {} @@ -261,10 +231,6 @@ pub struct DropRequest { pub doc_id: NamespaceId, } -impl RpcMsg for DropRequest { - type Response = RpcResult; -} - /// Response to [`DropRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct DropResponse {} @@ -284,10 +250,6 @@ pub struct SetRequest { pub value: Bytes, } -impl RpcMsg for SetRequest { - type Response = RpcResult; -} - /// Response to [`SetRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct SetResponse { @@ -317,14 +279,6 @@ pub struct ImportFileRequest { pub in_place: bool, } -impl Msg for ImportFileRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ImportFileRequest { - type Response = ImportFileResponse; -} - /// Wrapper around [`ImportProgress`]. #[derive(Debug, Serialize, Deserialize, derive_more::Into)] pub struct ImportFileResponse(pub ImportProgress); @@ -347,14 +301,6 @@ pub struct ExportFileRequest { pub mode: ExportMode, } -impl Msg for ExportFileRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ExportFileRequest { - type Response = ExportFileResponse; -} - /// Progress messages for an doc export operation /// /// An export operation involves reading the entry from the database ans saving the entry to the @@ -373,10 +319,6 @@ pub struct DelRequest { pub prefix: Bytes, } -impl RpcMsg for DelRequest { - type Response = RpcResult; -} - /// Response to [`DelRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct DelResponse { @@ -399,10 +341,6 @@ pub struct SetHashRequest { pub size: u64, } -impl RpcMsg for SetHashRequest { - type Response = RpcResult; -} - /// Response to [`SetHashRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct SetHashResponse {} @@ -416,14 +354,6 @@ pub struct GetManyRequest { pub query: Query, } -impl Msg for GetManyRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for GetManyRequest { - type Response = RpcResult; -} - /// Response to [`GetManyRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct GetManyResponse { @@ -444,10 +374,6 @@ pub struct GetExactRequest { pub include_empty: bool, } -impl RpcMsg for GetExactRequest { - type Response = RpcResult; -} - /// Response to [`GetExactRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct GetExactResponse { @@ -464,10 +390,6 @@ pub struct SetDownloadPolicyRequest { pub policy: DownloadPolicy, } -impl RpcMsg for SetDownloadPolicyRequest { - type Response = RpcResult; -} - /// Response to [`SetDownloadPolicyRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct SetDownloadPolicyResponse {} @@ -479,10 +401,6 @@ pub struct GetDownloadPolicyRequest { pub doc_id: NamespaceId, } -impl RpcMsg for GetDownloadPolicyRequest { - type Response = RpcResult; -} - /// Response to [`GetDownloadPolicyRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct GetDownloadPolicyResponse { @@ -497,10 +415,6 @@ pub struct GetSyncPeersRequest { pub doc_id: NamespaceId, } -impl RpcMsg for GetSyncPeersRequest { - type Response = RpcResult; -} - /// Response to [`GetSyncPeersRequest`] #[derive(Serialize, Deserialize, Debug)] pub struct GetSyncPeersResponse { diff --git a/iroh/src/rpc_protocol/gossip.rs b/iroh/src/rpc_protocol/gossip.rs index b2a589ea0e..f9a64dda5b 100644 --- a/iroh/src/rpc_protocol/gossip.rs +++ b/iroh/src/rpc_protocol/gossip.rs @@ -4,7 +4,7 @@ use iroh_base::rpc::RpcResult; use iroh_gossip::proto::TopicId; use iroh_net::NodeId; use nested_enum_utils::enum_conversions; -use quic_rpc::message::{BidiStreaming, BidiStreamingMsg, Msg}; +use quic_rpc_derive::rpc_requests; use serde::{Deserialize, Serialize}; use super::RpcService; @@ -15,7 +15,9 @@ pub use iroh_gossip::dispatcher::Event as SubscribeResponse; #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] #[enum_conversions(super::Request)] +#[rpc_requests(RpcService)] pub enum Request { + #[bidi_streaming(update = SubscribeUpdate, response = RpcResult)] Subscribe(SubscribeRequest), Update(SubscribeUpdate), } @@ -39,12 +41,3 @@ pub struct SubscribeRequest { /// The capacity of the subscription pub subscription_capacity: usize, } - -impl Msg for SubscribeRequest { - type Pattern = BidiStreaming; -} - -impl BidiStreamingMsg for SubscribeRequest { - type Update = SubscribeUpdate; - type Response = RpcResult; -} diff --git a/iroh/src/rpc_protocol/node.rs b/iroh/src/rpc_protocol/node.rs index c3a65f1933..8b61dbaed3 100644 --- a/iroh/src/rpc_protocol/node.rs +++ b/iroh/src/rpc_protocol/node.rs @@ -2,7 +2,8 @@ use std::collections::BTreeMap; use iroh_base::rpc::RpcResult; use iroh_net::{endpoint::ConnectionInfo, key::PublicKey, relay::RelayUrl, NodeAddr, NodeId}; -use quic_rpc::message::{Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}; +use nested_enum_utils::enum_conversions; +use quic_rpc_derive::rpc_requests; use serde::{Deserialize, Serialize}; use crate::client::NodeStatus; @@ -11,23 +12,34 @@ use super::RpcService; #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Request)] +#[enum_conversions(super::Request)] +#[rpc_requests(RpcService)] pub enum Request { + #[rpc(response = RpcResult)] Status(StatusRequest), + #[rpc(response = RpcResult)] Id(IdRequest), + #[rpc(response = RpcResult)] Addr(AddrRequest), + #[rpc(response = RpcResult<()>)] AddAddr(AddAddrRequest), + #[rpc(response = RpcResult>)] Relay(RelayRequest), + #[rpc(response = RpcResult)] Stats(StatsRequest), + #[rpc(response = ())] Shutdown(ShutdownRequest), + #[server_streaming(response = RpcResult)] Connections(ConnectionsRequest), + #[rpc(response = RpcResult)] ConnectionInfo(ConnectionInfoRequest), + #[server_streaming(response = WatchResponse)] Watch(NodeWatchRequest), } #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Response)] +#[enum_conversions(super::Response)] pub enum Response { Status(RpcResult), Id(RpcResult), @@ -54,14 +66,6 @@ pub struct ConnectionsResponse { pub conn_info: ConnectionInfo, } -impl Msg for ConnectionsRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ConnectionsRequest { - type Response = RpcResult; -} - /// Get connection information about a specific node #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ConnectionInfoRequest { @@ -76,10 +80,6 @@ pub struct ConnectionInfoResponse { pub conn_info: Option, } -impl RpcMsg for ConnectionInfoRequest { - type Response = RpcResult; -} - /// A request to shutdown the node #[derive(Serialize, Deserialize, Debug)] pub struct ShutdownRequest { @@ -87,61 +87,29 @@ pub struct ShutdownRequest { pub force: bool, } -impl RpcMsg for ShutdownRequest { - type Response = (); -} - /// A request to get information about the status of the node. #[derive(Serialize, Deserialize, Debug)] pub struct StatusRequest; -impl RpcMsg for StatusRequest { - type Response = RpcResult; -} - /// A request to get information the identity of the node. #[derive(Serialize, Deserialize, Debug)] pub struct IdRequest; -impl RpcMsg for IdRequest { - type Response = RpcResult; -} - #[derive(Serialize, Deserialize, Debug)] pub struct AddrRequest; -impl RpcMsg for AddrRequest { - type Response = RpcResult; -} - #[derive(Serialize, Deserialize, Debug)] pub struct AddAddrRequest { pub addr: NodeAddr, } -impl RpcMsg for AddAddrRequest { - type Response = RpcResult<()>; -} - #[derive(Serialize, Deserialize, Debug)] pub struct RelayRequest; -impl RpcMsg for RelayRequest { - type Response = RpcResult>; -} - /// A request to watch for the node status #[derive(Serialize, Deserialize, Debug)] pub struct NodeWatchRequest; -impl Msg for NodeWatchRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for NodeWatchRequest { - type Response = WatchResponse; -} - /// The response to a watch request #[derive(Serialize, Deserialize, Debug)] pub struct WatchResponse { @@ -160,10 +128,6 @@ pub struct VersionResponse { #[derive(Serialize, Deserialize, Debug)] pub struct StatsRequest {} -impl RpcMsg for StatsRequest { - type Response = RpcResult; -} - /// Counter stats #[derive(Serialize, Deserialize, Debug)] pub struct CounterStats { diff --git a/iroh/src/rpc_protocol/tags.rs b/iroh/src/rpc_protocol/tags.rs index 3aeab6bb53..bd7f1a016e 100644 --- a/iroh/src/rpc_protocol/tags.rs +++ b/iroh/src/rpc_protocol/tags.rs @@ -1,6 +1,7 @@ use iroh_base::rpc::RpcResult; use iroh_blobs::Tag; -use quic_rpc::message::{Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}; +use nested_enum_utils::enum_conversions; +use quic_rpc_derive::rpc_requests; use serde::{Deserialize, Serialize}; use crate::client::tags::TagInfo; @@ -9,15 +10,18 @@ use super::RpcService; #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Request)] +#[enum_conversions(super::Request)] +#[rpc_requests(RpcService)] pub enum Request { + #[rpc(response = RpcResult<()>)] DeleteTag(DeleteRequest), + #[server_streaming(response = TagInfo)] ListTags(ListRequest), } #[allow(missing_docs)] #[derive(strum::Display, Debug, Serialize, Deserialize)] -#[nested_enum_utils::enum_conversions(super::Response)] +#[enum_conversions(super::Response)] pub enum Response { ListTags(TagInfo), DeleteTag(RpcResult<()>), @@ -60,21 +64,9 @@ impl ListRequest { } } -impl Msg for ListRequest { - type Pattern = ServerStreaming; -} - -impl ServerStreamingMsg for ListRequest { - type Response = TagInfo; -} - /// Delete a tag #[derive(Debug, Serialize, Deserialize)] pub struct DeleteRequest { /// Name of the tag pub name: Tag, } - -impl RpcMsg for DeleteRequest { - type Response = RpcResult<()>; -}