diff --git a/iroh/src/client.rs b/iroh/src/client.rs index 5acc31eefb4..d4cf68eabec 100644 --- a/iroh/src/client.rs +++ b/iroh/src/client.rs @@ -25,7 +25,7 @@ use iroh_net::ticket::BlobTicket; use iroh_net::{key::PublicKey, magic_endpoint::ConnectionInfo, NodeAddr}; use iroh_sync::actor::OpenState; use iroh_sync::store::DownloadPolicy; -use iroh_sync::{store::Query, AuthorId, CapabilityKind, NamespaceId}; +use iroh_sync::{store::Query, AuthorId, CapabilityKind, NamespaceId, PeerIdBytes}; use iroh_sync::{ContentStatus, RecordIdentifier}; use quic_rpc::message::RpcMsg; use quic_rpc::{RpcClient, ServiceConnection}; @@ -34,22 +34,7 @@ use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf}; use tokio_util::io::{ReaderStream, StreamReader}; use tracing::warn; -use crate::rpc_protocol::{ - AuthorCreateRequest, AuthorListRequest, BlobAddPathRequest, BlobAddStreamRequest, - BlobAddStreamUpdate, BlobDeleteBlobRequest, BlobDownloadRequest, BlobGetCollectionRequest, - BlobGetCollectionResponse, BlobListCollectionsRequest, BlobListCollectionsResponse, - BlobListIncompleteRequest, BlobListIncompleteResponse, BlobListRequest, BlobListResponse, - BlobReadAtRequest, BlobReadAtResponse, BlobValidateRequest, CounterStats, - CreateCollectionRequest, CreateCollectionResponse, DeleteTagRequest, DocCloseRequest, - DocCreateRequest, DocDelRequest, DocDelResponse, DocDropRequest, DocExportFileRequest, - DocGetDownloadPolicyRequest, DocGetExactRequest, DocGetManyRequest, DocImportFileRequest, - DocImportProgress, DocImportRequest, DocLeaveRequest, DocListRequest, DocOpenRequest, - DocSetDownloadPolicyRequest, DocSetHashRequest, DocSetRequest, DocShareRequest, - DocStartSyncRequest, DocStatusRequest, DocSubscribeRequest, DocTicket, DownloadProgress, - ListTagsRequest, ListTagsResponse, NodeConnectionInfoRequest, NodeConnectionInfoResponse, - NodeConnectionsRequest, NodeShutdownRequest, NodeStatsRequest, NodeStatusRequest, - NodeStatusResponse, ProviderService, SetTagOption, ShareMode, WrapOption, -}; +use crate::rpc_protocol::{AuthorCreateRequest, AuthorListRequest, BlobAddPathRequest, BlobAddStreamRequest, BlobAddStreamUpdate, BlobDeleteBlobRequest, BlobDownloadRequest, BlobGetCollectionRequest, BlobGetCollectionResponse, BlobListCollectionsRequest, BlobListCollectionsResponse, BlobListIncompleteRequest, BlobListIncompleteResponse, BlobListRequest, BlobListResponse, BlobReadAtRequest, BlobReadAtResponse, BlobValidateRequest, CounterStats, CreateCollectionRequest, CreateCollectionResponse, DeleteTagRequest, DocCloseRequest, DocCreateRequest, DocDelRequest, DocDelResponse, DocDropRequest, DocExportFileRequest, DocGetDownloadPolicyRequest, DocGetExactRequest, DocGetManyRequest, DocGetSyncPeersRequest, DocImportFileRequest, DocImportProgress, DocImportRequest, DocLeaveRequest, DocListRequest, DocOpenRequest, DocSetDownloadPolicyRequest, DocSetHashRequest, DocSetRequest, DocShareRequest, DocStartSyncRequest, DocStatusRequest, DocSubscribeRequest, DocTicket, DownloadProgress, ListTagsRequest, ListTagsResponse, NodeConnectionInfoRequest, NodeConnectionInfoResponse, NodeConnectionsRequest, NodeShutdownRequest, NodeStatsRequest, NodeStatusRequest, NodeStatusResponse, ProviderService, SetTagOption, ShareMode, WrapOption}; use crate::sync_engine::SyncEvent; pub mod mem; @@ -1036,6 +1021,14 @@ where .await??; Ok(res.policy) } + + /// Get sync peersfor this document + pub async fn get_sync_peers(&self) -> Result>> { + let res = self + .rpc(DocGetSyncPeersRequest { doc_id: self.id() }) + .await??; + Ok(res.peers) + } } impl<'a, C: ServiceConnection> From<&'a Doc> diff --git a/iroh/src/node.rs b/iroh/src/node.rs index fd599e73554..1f6a2000a8d 100644 --- a/iroh/src/node.rs +++ b/iroh/src/node.rs @@ -1771,6 +1771,12 @@ fn handle_rpc_request>( }) .await } + DocGetSyncPeers(msg) => { + chan.rpc(msg, handler, |handler, req| async move { + handler.inner.sync.doc_get_sync_peers(req).await + }) + .await + } } }); } diff --git a/iroh/src/rpc_protocol.rs b/iroh/src/rpc_protocol.rs index 68915d80be3..381bdb1a766 100644 --- a/iroh/src/rpc_protocol.rs +++ b/iroh/src/rpc_protocol.rs @@ -21,7 +21,7 @@ use iroh_net::{ use iroh_sync::{ actor::OpenState, store::{DownloadPolicy, Query}, - {AuthorId, CapabilityKind, Entry, NamespaceId, SignedEntry}, + PeerIdBytes, {AuthorId, CapabilityKind, Entry, NamespaceId, SignedEntry}, }; use quic_rpc::{ message::{BidiStreaming, BidiStreamingMsg, Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}, @@ -930,6 +930,24 @@ pub struct DocGetDownloadPolicyResponse { pub policy: DownloadPolicy, } +/// Get peers for document +#[derive(Serialize, Deserialize, Debug)] +pub struct DocGetSyncPeersRequest { + /// The document id + pub doc_id: NamespaceId, +} + +impl RpcMsg for DocGetSyncPeersRequest { + type Response = RpcResult; +} + +/// Response to [`DocGetSyncPeersRequest`] +#[derive(Serialize, Deserialize, Debug)] +pub struct DocGetSyncPeersResponse { + /// The download policy + pub peers: Option>, +} + /// Get the bytes for a hash #[derive(Serialize, Deserialize, Debug)] pub struct BlobReadAtRequest { @@ -1070,6 +1088,7 @@ pub enum ProviderRequest { DocSubscribe(DocSubscribeRequest), DocGetDownloadPolicy(DocGetDownloadPolicyRequest), DocSetDownloadPolicy(DocSetDownloadPolicyRequest), + DocGetSyncPeers(DocGetSyncPeersRequest), AuthorList(AuthorListRequest), AuthorCreate(AuthorCreateRequest), @@ -1121,6 +1140,7 @@ pub enum ProviderResponse { DocSubscribe(RpcResult), DocGetDownloadPolicy(RpcResult), DocSetDownloadPolicy(RpcResult), + DocGetSyncPeers(RpcResult), AuthorList(RpcResult), AuthorCreate(RpcResult), diff --git a/iroh/src/sync_engine/rpc.rs b/iroh/src/sync_engine/rpc.rs index f11907504ca..4b3afffa3ce 100644 --- a/iroh/src/sync_engine/rpc.rs +++ b/iroh/src/sync_engine/rpc.rs @@ -6,6 +6,7 @@ use iroh_bytes::{store::Store as BaoStore, BlobFormat}; use iroh_sync::{Author, NamespaceSecret}; use tokio_stream::StreamExt; +use crate::rpc_protocol::{DocGetSyncPeersRequest, DocGetSyncPeersResponse}; use crate::{ rpc_protocol::{ AuthorCreateRequest, AuthorCreateResponse, AuthorListRequest, AuthorListResponse, @@ -258,4 +259,12 @@ impl SyncEngine { let policy = self.sync.get_download_policy(req.doc_id).await?; Ok(DocGetDownloadPolicyResponse { policy }) } + + pub async fn doc_get_sync_peers( + &self, + req: DocGetSyncPeersRequest, + ) -> RpcResult { + let peers = self.sync.get_sync_peers(req.doc_id).await?; + Ok(DocGetSyncPeersResponse { peers }) + } }