mirror of
https://github.com/n0-computer/iroh.git
synced 2026-11-29 08:01:13 +00:00
refactor(iroh): make use of quic-rpc-derive macros to prettify the rpc declarations (#2508)
## Description Make use of quic-rpc-derive macros to make the rpc declarations nicer to read. With this, you can clearly see the kind of interaction and the response type for each rpc message type in one place. Under the hood, this does the exact same thing as before. ## Breaking Changes None ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [x] 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. - [x] ~~Tests if relevant.~~ - [x] ~~All breaking changes documented.~~
This commit is contained in:
Generated
+13
@@ -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"
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<ListResponse>)]
|
||||
List(ListRequest),
|
||||
#[rpc(response = RpcResult<CreateResponse>)]
|
||||
Create(CreateRequest),
|
||||
#[rpc(response = RpcResult<GetDefaultResponse>)]
|
||||
GetDefault(GetDefaultRequest),
|
||||
#[rpc(response = RpcResult<SetDefaultResponse>)]
|
||||
SetDefault(SetDefaultRequest),
|
||||
#[rpc(response = RpcResult<ImportResponse>)]
|
||||
Import(ImportRequest),
|
||||
#[rpc(response = RpcResult<ExportResponse>)]
|
||||
Export(ExportRequest),
|
||||
#[rpc(response = RpcResult<DeleteResponse>)]
|
||||
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<ListResponse>),
|
||||
Create(RpcResult<CreateResponse>),
|
||||
@@ -35,14 +44,6 @@ pub enum Response {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ListRequest {}
|
||||
|
||||
impl Msg<RpcService> for ListRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ListRequest {
|
||||
type Response = RpcResult<ListResponse>;
|
||||
}
|
||||
|
||||
/// 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<RpcService> for CreateRequest {
|
||||
type Response = RpcResult<CreateResponse>;
|
||||
}
|
||||
|
||||
/// 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<RpcService> for GetDefaultRequest {
|
||||
type Response = RpcResult<GetDefaultResponse>;
|
||||
}
|
||||
|
||||
/// Response for [`GetDefaultRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetDefaultResponse {
|
||||
@@ -86,10 +79,6 @@ pub struct SetDefaultRequest {
|
||||
pub author_id: AuthorId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for SetDefaultRequest {
|
||||
type Response = RpcResult<SetDefaultResponse>;
|
||||
}
|
||||
|
||||
/// Response for [`GetDefaultRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SetDefaultResponse;
|
||||
@@ -101,10 +90,6 @@ pub struct DeleteRequest {
|
||||
pub author: AuthorId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for DeleteRequest {
|
||||
type Response = RpcResult<DeleteResponse>;
|
||||
}
|
||||
|
||||
/// Response for [`DeleteRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DeleteResponse;
|
||||
@@ -116,10 +101,6 @@ pub struct ExportRequest {
|
||||
pub author: AuthorId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for ExportRequest {
|
||||
type Response = RpcResult<ExportResponse>;
|
||||
}
|
||||
|
||||
/// Response for [`ExportRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ExportResponse {
|
||||
@@ -134,10 +115,6 @@ pub struct ImportRequest {
|
||||
pub author: Author,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for ImportRequest {
|
||||
type Response = RpcResult<ImportResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`ImportRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ImportResponse {
|
||||
|
||||
@@ -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<ReadAtResponse>)]
|
||||
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<BlobInfo>)]
|
||||
List(ListRequest),
|
||||
#[server_streaming(response = RpcResult<IncompleteBlobInfo>)]
|
||||
ListIncomplete(ListIncompleteRequest),
|
||||
#[rpc(response = RpcResult<()>)]
|
||||
Delete(DeleteRequest),
|
||||
#[server_streaming(response = ValidateProgress)]
|
||||
Validate(ValidateRequest),
|
||||
#[server_streaming(response = ConsistencyCheckProgress)]
|
||||
Fsck(ConsistencyCheckRequest),
|
||||
#[rpc(response = RpcResult<CreateCollectionResponse>)]
|
||||
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<ReadAtResponse>),
|
||||
AddStream(AddStreamResponse),
|
||||
@@ -76,14 +87,6 @@ pub struct AddPathRequest {
|
||||
pub wrap: WrapOption,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for AddPathRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for DownloadRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for ExportRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for ConsistencyCheckRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for ValidateRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ValidateRequest {
|
||||
type Response = ValidateProgress;
|
||||
}
|
||||
|
||||
/// List all blobs, including collections
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ListRequest;
|
||||
|
||||
impl Msg<RpcService> for ListRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ListRequest {
|
||||
type Response = RpcResult<BlobInfo>;
|
||||
}
|
||||
|
||||
/// List all blobs, including collections
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ListIncompleteRequest;
|
||||
|
||||
impl Msg<RpcService> for ListIncompleteRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ListIncompleteRequest {
|
||||
type Response = RpcResult<IncompleteBlobInfo>;
|
||||
}
|
||||
|
||||
/// Get the bytes for a hash
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ReadAtRequest {
|
||||
@@ -217,14 +172,6 @@ pub struct ReadAtRequest {
|
||||
pub len: Option<usize>,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for ReadAtRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ReadAtRequest {
|
||||
type Response = RpcResult<ReadAtResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`ReadAtRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum ReadAtResponse {
|
||||
@@ -258,15 +205,6 @@ pub enum AddStreamUpdate {
|
||||
Abort,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for AddStreamRequest {
|
||||
type Pattern = BidiStreaming;
|
||||
}
|
||||
|
||||
impl BidiStreamingMsg<RpcService> 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<RpcService> 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<RpcService> for CreateCollectionRequest {
|
||||
type Response = RpcResult<CreateCollectionResponse>;
|
||||
}
|
||||
|
||||
+27
-113
@@ -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<OpenResponse>)]
|
||||
Open(OpenRequest),
|
||||
#[rpc(response = RpcResult<CloseResponse>)]
|
||||
Close(CloseRequest),
|
||||
#[rpc(response = RpcResult<StatusResponse>)]
|
||||
Status(StatusRequest),
|
||||
#[server_streaming(response = RpcResult<ListResponse>)]
|
||||
List(DocListRequest),
|
||||
#[rpc(response = RpcResult<CreateResponse>)]
|
||||
Create(CreateRequest),
|
||||
#[rpc(response = RpcResult<DropResponse>)]
|
||||
Drop(DropRequest),
|
||||
#[rpc(response = RpcResult<ImportResponse>)]
|
||||
Import(ImportRequest),
|
||||
#[rpc(response = RpcResult<SetResponse>)]
|
||||
Set(SetRequest),
|
||||
#[rpc(response = RpcResult<SetHashResponse>)]
|
||||
SetHash(SetHashRequest),
|
||||
#[server_streaming(response = RpcResult<GetManyResponse>)]
|
||||
Get(GetManyRequest),
|
||||
#[rpc(response = RpcResult<GetExactResponse>)]
|
||||
GetExact(GetExactRequest),
|
||||
#[server_streaming(response = ImportFileResponse)]
|
||||
ImportFile(ImportFileRequest),
|
||||
#[server_streaming(response = ExportFileResponse)]
|
||||
ExportFile(ExportFileRequest),
|
||||
#[rpc(response = RpcResult<DelResponse>)]
|
||||
Del(DelRequest),
|
||||
#[rpc(response = RpcResult<StartSyncResponse>)]
|
||||
StartSync(StartSyncRequest),
|
||||
#[rpc(response = RpcResult<LeaveResponse>)]
|
||||
Leave(LeaveRequest),
|
||||
#[rpc(response = RpcResult<ShareResponse>)]
|
||||
Share(ShareRequest),
|
||||
#[try_server_streaming(create_error = RpcError, item_error = RpcError, item = DocSubscribeResponse)]
|
||||
Subscribe(DocSubscribeRequest),
|
||||
#[rpc(response = RpcResult<GetDownloadPolicyResponse>)]
|
||||
GetDownloadPolicy(GetDownloadPolicyRequest),
|
||||
#[rpc(response = RpcResult<SetDownloadPolicyResponse>)]
|
||||
SetDownloadPolicy(SetDownloadPolicyRequest),
|
||||
#[rpc(response = RpcResult<GetSyncPeersResponse>)]
|
||||
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<OpenResponse>),
|
||||
Close(RpcResult<CloseResponse>),
|
||||
@@ -83,16 +103,6 @@ pub struct DocSubscribeRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for DocSubscribeRequest {
|
||||
type Pattern = TryServerStreaming;
|
||||
}
|
||||
|
||||
impl TryServerStreamingMsg<RpcService> 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<RpcService> for DocListRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for DocListRequest {
|
||||
type Response = RpcResult<ListResponse>;
|
||||
}
|
||||
|
||||
/// 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<RpcService> for CreateRequest {
|
||||
type Response = RpcResult<CreateResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`CreateRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CreateResponse {
|
||||
@@ -143,10 +141,6 @@ pub struct ImportRequest {
|
||||
pub capability: Capability,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for ImportRequest {
|
||||
type Response = RpcResult<ImportResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`ImportRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ImportResponse {
|
||||
@@ -165,10 +159,6 @@ pub struct ShareRequest {
|
||||
pub addr_options: AddrInfoOptions,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for ShareRequest {
|
||||
type Response = RpcResult<ShareResponse>;
|
||||
}
|
||||
|
||||
/// 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<RpcService> for StatusRequest {
|
||||
type Response = RpcResult<StatusResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`StatusRequest`]
|
||||
// TODO: actually provide info
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -199,10 +185,6 @@ pub struct OpenRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for OpenRequest {
|
||||
type Response = RpcResult<OpenResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`OpenRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct OpenResponse {}
|
||||
@@ -214,10 +196,6 @@ pub struct CloseRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for CloseRequest {
|
||||
type Response = RpcResult<CloseResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`CloseRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CloseResponse {}
|
||||
@@ -231,10 +209,6 @@ pub struct StartSyncRequest {
|
||||
pub peers: Vec<NodeAddr>,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for StartSyncRequest {
|
||||
type Response = RpcResult<StartSyncResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`StartSyncRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct StartSyncResponse {}
|
||||
@@ -246,10 +220,6 @@ pub struct LeaveRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for LeaveRequest {
|
||||
type Response = RpcResult<LeaveResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`LeaveRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct LeaveResponse {}
|
||||
@@ -261,10 +231,6 @@ pub struct DropRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for DropRequest {
|
||||
type Response = RpcResult<DropResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`DropRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DropResponse {}
|
||||
@@ -284,10 +250,6 @@ pub struct SetRequest {
|
||||
pub value: Bytes,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for SetRequest {
|
||||
type Response = RpcResult<SetResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`SetRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SetResponse {
|
||||
@@ -317,14 +279,6 @@ pub struct ImportFileRequest {
|
||||
pub in_place: bool,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for ImportFileRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for ExportFileRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for DelRequest {
|
||||
type Response = RpcResult<DelResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`DelRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DelResponse {
|
||||
@@ -399,10 +341,6 @@ pub struct SetHashRequest {
|
||||
pub size: u64,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for SetHashRequest {
|
||||
type Response = RpcResult<SetHashResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`SetHashRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SetHashResponse {}
|
||||
@@ -416,14 +354,6 @@ pub struct GetManyRequest {
|
||||
pub query: Query,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for GetManyRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for GetManyRequest {
|
||||
type Response = RpcResult<GetManyResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`GetManyRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetManyResponse {
|
||||
@@ -444,10 +374,6 @@ pub struct GetExactRequest {
|
||||
pub include_empty: bool,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for GetExactRequest {
|
||||
type Response = RpcResult<GetExactResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`GetExactRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetExactResponse {
|
||||
@@ -464,10 +390,6 @@ pub struct SetDownloadPolicyRequest {
|
||||
pub policy: DownloadPolicy,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for SetDownloadPolicyRequest {
|
||||
type Response = RpcResult<SetDownloadPolicyResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`SetDownloadPolicyRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SetDownloadPolicyResponse {}
|
||||
@@ -479,10 +401,6 @@ pub struct GetDownloadPolicyRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for GetDownloadPolicyRequest {
|
||||
type Response = RpcResult<GetDownloadPolicyResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`GetDownloadPolicyRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetDownloadPolicyResponse {
|
||||
@@ -497,10 +415,6 @@ pub struct GetSyncPeersRequest {
|
||||
pub doc_id: NamespaceId,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for GetSyncPeersRequest {
|
||||
type Response = RpcResult<GetSyncPeersResponse>;
|
||||
}
|
||||
|
||||
/// Response to [`GetSyncPeersRequest`]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetSyncPeersResponse {
|
||||
|
||||
@@ -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<SubscribeResponse>)]
|
||||
Subscribe(SubscribeRequest),
|
||||
Update(SubscribeUpdate),
|
||||
}
|
||||
@@ -39,12 +41,3 @@ pub struct SubscribeRequest {
|
||||
/// The capacity of the subscription
|
||||
pub subscription_capacity: usize,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for SubscribeRequest {
|
||||
type Pattern = BidiStreaming;
|
||||
}
|
||||
|
||||
impl BidiStreamingMsg<RpcService> for SubscribeRequest {
|
||||
type Update = SubscribeUpdate;
|
||||
type Response = RpcResult<SubscribeResponse>;
|
||||
}
|
||||
|
||||
@@ -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<NodeStatus>)]
|
||||
Status(StatusRequest),
|
||||
#[rpc(response = RpcResult<NodeId>)]
|
||||
Id(IdRequest),
|
||||
#[rpc(response = RpcResult<NodeAddr>)]
|
||||
Addr(AddrRequest),
|
||||
#[rpc(response = RpcResult<()>)]
|
||||
AddAddr(AddAddrRequest),
|
||||
#[rpc(response = RpcResult<Option<RelayUrl>>)]
|
||||
Relay(RelayRequest),
|
||||
#[rpc(response = RpcResult<StatsResponse>)]
|
||||
Stats(StatsRequest),
|
||||
#[rpc(response = ())]
|
||||
Shutdown(ShutdownRequest),
|
||||
#[server_streaming(response = RpcResult<ConnectionsResponse>)]
|
||||
Connections(ConnectionsRequest),
|
||||
#[rpc(response = RpcResult<ConnectionInfoResponse>)]
|
||||
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<NodeStatus>),
|
||||
Id(RpcResult<NodeId>),
|
||||
@@ -54,14 +66,6 @@ pub struct ConnectionsResponse {
|
||||
pub conn_info: ConnectionInfo,
|
||||
}
|
||||
|
||||
impl Msg<RpcService> for ConnectionsRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ConnectionsRequest {
|
||||
type Response = RpcResult<ConnectionsResponse>;
|
||||
}
|
||||
|
||||
/// 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<ConnectionInfo>,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for ConnectionInfoRequest {
|
||||
type Response = RpcResult<ConnectionInfoResponse>;
|
||||
}
|
||||
|
||||
/// 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<RpcService> for ShutdownRequest {
|
||||
type Response = ();
|
||||
}
|
||||
|
||||
/// A request to get information about the status of the node.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct StatusRequest;
|
||||
|
||||
impl RpcMsg<RpcService> for StatusRequest {
|
||||
type Response = RpcResult<NodeStatus>;
|
||||
}
|
||||
|
||||
/// A request to get information the identity of the node.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct IdRequest;
|
||||
|
||||
impl RpcMsg<RpcService> for IdRequest {
|
||||
type Response = RpcResult<NodeId>;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct AddrRequest;
|
||||
|
||||
impl RpcMsg<RpcService> for AddrRequest {
|
||||
type Response = RpcResult<NodeAddr>;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct AddAddrRequest {
|
||||
pub addr: NodeAddr,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for AddAddrRequest {
|
||||
type Response = RpcResult<()>;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct RelayRequest;
|
||||
|
||||
impl RpcMsg<RpcService> for RelayRequest {
|
||||
type Response = RpcResult<Option<RelayUrl>>;
|
||||
}
|
||||
|
||||
/// A request to watch for the node status
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct NodeWatchRequest;
|
||||
|
||||
impl Msg<RpcService> for NodeWatchRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> 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<RpcService> for StatsRequest {
|
||||
type Response = RpcResult<StatsResponse>;
|
||||
}
|
||||
|
||||
/// Counter stats
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CounterStats {
|
||||
|
||||
@@ -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<RpcService> for ListRequest {
|
||||
type Pattern = ServerStreaming;
|
||||
}
|
||||
|
||||
impl ServerStreamingMsg<RpcService> for ListRequest {
|
||||
type Response = TagInfo;
|
||||
}
|
||||
|
||||
/// Delete a tag
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DeleteRequest {
|
||||
/// Name of the tag
|
||||
pub name: Tag,
|
||||
}
|
||||
|
||||
impl RpcMsg<RpcService> for DeleteRequest {
|
||||
type Response = RpcResult<()>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user