Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Oct 17, 2024
1 parent 39d4bd9 commit c8fe86e
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 494 deletions.
941 changes: 461 additions & 480 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion iroh-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ blake3 = { version = "1.4.5", package = "iroh-blake3", optional = true }
data-encoding = { version = "2.3.3", optional = true }
hex = "0.4.3"
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"], optional = true }
redb = { version = "2.0.0", optional = true }
redb = { version = "2.1.2", optional = true }
serde = { version = "1", features = ["derive"] }
serde-error = "0.1.2"
thiserror = "1"
Expand Down
2 changes: 1 addition & 1 deletion iroh-blobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ postcard = { version = "1", default-features = false, features = ["alloc", "use-
quinn = { package = "iroh-quinn", version = "0.11", features = ["ring"] }
rand = "0.8"
range-collections = "0.4.0"
redb = { version = "2.0.0", optional = true }
redb = { version = "2.1.2", optional = true }
redb_v1 = { package = "redb", version = "1.5.1", optional = true }
reflink-copy = { version = "0.1.8", optional = true }
self_cell = "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mainline = "2.0.1"
parking_lot = "0.12.1"
pkarr = { version = "2.2.0", features = [ "async", "relay", "dht"], default-features = false }
rcgen = "0.12.1"
redb = "2.0.0"
redb = "2.1.2"
regex = "1.10.3"
rustls = { version = "0.23", default-features = false, features = ["ring"] }
rustls-pemfile = { version = "2.1" }
Expand Down
2 changes: 1 addition & 1 deletion iroh-docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ num_enum = "0.7"
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
rand = "0.8.5"
rand_core = "0.6.4"
redb = { version = "2.0.0" }
redb = { version = "2.1.2" }
redb_v1 = { package = "redb", version = "1.5.1" }
self_cell = "1.0.3"
serde = { version = "1.0.164", features = ["derive"] }
Expand Down
18 changes: 12 additions & 6 deletions iroh/src/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use iroh_blobs::{export::ExportProgress, store::ExportMode, Hash};
use iroh_docs::{
actor::OpenState,
store::{DownloadPolicy, Query},
AuthorId, Capability, CapabilityKind, ContentStatus, DocTicket, NamespaceId, PeerIdBytes,
RecordIdentifier,
AuthorId, Capability, CapabilityKind, ContentStatus, DocTicket, NamespaceId, NamespaceSecret,
PeerIdBytes, RecordIdentifier,
};
use iroh_net::NodeAddr;
use portable_atomic::{AtomicBool, Ordering};
Expand All @@ -31,10 +31,10 @@ use serde::{Deserialize, Serialize};

use crate::rpc_protocol::docs::{
CloseRequest, CreateRequest, DelRequest, DelResponse, DocListRequest, DocSubscribeRequest,
DropRequest, ExportFileRequest, GetDownloadPolicyRequest, GetExactRequest, GetManyRequest,
GetSyncPeersRequest, ImportFileRequest, ImportRequest, LeaveRequest, OpenRequest,
SetDownloadPolicyRequest, SetHashRequest, SetRequest, ShareRequest, StartSyncRequest,
StatusRequest,
DropRequest, ExportFileRequest, ExportSecretKeyRequest, GetDownloadPolicyRequest,
GetExactRequest, GetManyRequest, GetSyncPeersRequest, ImportFileRequest, ImportRequest,
LeaveRequest, OpenRequest, SetDownloadPolicyRequest, SetHashRequest, SetRequest, ShareRequest,
StartSyncRequest, StatusRequest,
};
use crate::rpc_protocol::RpcService;

Expand Down Expand Up @@ -68,6 +68,12 @@ impl Client {
Ok(())
}

/// Export secret key
pub async fn export_secret_key(&self, doc_id: NamespaceId) -> Result<NamespaceSecret> {
let response = self.rpc.rpc(ExportSecretKeyRequest { doc_id }).await??;
Ok(response.secret)
}

/// Imports a document from a namespace capability.
///
/// This does not start sync automatically. Use [`Doc::start_sync`] to start sync.
Expand Down
6 changes: 6 additions & 0 deletions iroh/src/node/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ impl<D: BaoStore> Handler<D> {
})
.await
}
ExportSecretKey(msg) => {
chan.rpc(msg, self, |handler, req| {
handler.with_docs(|docs| async move { docs.export_secret_key(req).await })
})
.await
}
}
}

Expand Down
13 changes: 11 additions & 2 deletions iroh/src/node/rpc/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use crate::rpc_protocol::{
CloseRequest, CloseResponse, CreateRequest as DocCreateRequest,
CreateResponse as DocCreateResponse, DelRequest, DelResponse, DocListRequest,
DocSubscribeRequest, DocSubscribeResponse, DropRequest, DropResponse,
GetDownloadPolicyRequest, GetDownloadPolicyResponse, GetExactRequest, GetExactResponse,
GetManyRequest, GetManyResponse, GetSyncPeersRequest, GetSyncPeersResponse,
ExportSecretKeyRequest, ExportSecretKeyResponse, GetDownloadPolicyRequest,
GetDownloadPolicyResponse, GetExactRequest, GetExactResponse, GetManyRequest,
GetManyResponse, GetSyncPeersRequest, GetSyncPeersResponse,
ImportRequest as DocImportRequest, ImportResponse as DocImportResponse, LeaveRequest,
LeaveResponse, ListResponse as DocListResponse, OpenRequest, OpenResponse,
SetDownloadPolicyRequest, SetDownloadPolicyResponse, SetHashRequest, SetHashResponse,
Expand Down Expand Up @@ -305,4 +306,12 @@ impl DocsEngine {
let peers = self.sync.get_sync_peers(req.doc_id).await?;
Ok(GetSyncPeersResponse { peers })
}

pub async fn export_secret_key(
&self,
req: ExportSecretKeyRequest,
) -> RpcResult<ExportSecretKeyResponse> {
let secret = self.sync.export_secret_key(req.doc_id).await?;
Ok(ExportSecretKeyResponse { secret })
}
}
20 changes: 18 additions & 2 deletions iroh/src/rpc_protocol/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iroh_base::{
use iroh_blobs::{export::ExportProgress, store::ExportMode, Hash};
use iroh_docs::{
actor::OpenState, engine::LiveEvent, store::DownloadPolicy, store::Query, AuthorId, Capability,
CapabilityKind, DocTicket, Entry, NamespaceId, PeerIdBytes, SignedEntry,
CapabilityKind, DocTicket, Entry, NamespaceId, NamespaceSecret, PeerIdBytes, SignedEntry,
};
use iroh_net::NodeAddr;
use nested_enum_utils::enum_conversions;
Expand Down Expand Up @@ -36,6 +36,8 @@ pub enum Request {
Create(CreateRequest),
#[rpc(response = RpcResult<DropResponse>)]
Drop(DropRequest),
#[rpc(response = RpcResult<ExportSecretKeyResponse>)]
ExportSecretKey(ExportSecretKeyRequest),
#[rpc(response = RpcResult<ImportResponse>)]
Import(ImportRequest),
#[rpc(response = RpcResult<SetResponse>)]
Expand Down Expand Up @@ -94,6 +96,7 @@ pub enum Response {
SetDownloadPolicy(RpcResult<SetDownloadPolicyResponse>),
GetSyncPeers(RpcResult<GetSyncPeersResponse>),
StreamCreated(RpcResult<StreamCreated>),
ExportSecretKey(RpcResult<ExportSecretKeyResponse>),
}

/// Subscribe to events for a document.
Expand Down Expand Up @@ -235,6 +238,19 @@ pub struct DropRequest {
#[derive(Serialize, Deserialize, Debug)]
pub struct DropResponse {}

/// Get secret key
#[derive(Serialize, Deserialize, Debug)]
pub struct ExportSecretKeyRequest {
/// The document id
pub doc_id: NamespaceId,
}

/// Response to [`ExportSecretKeyRequest`]
#[derive(Serialize, Deserialize, Debug)]
pub struct ExportSecretKeyResponse {
pub(crate) secret: NamespaceSecret,
}

/// Set an entry in a document
#[derive(Serialize, Deserialize, Debug)]
pub struct SetRequest {
Expand Down Expand Up @@ -266,7 +282,7 @@ pub struct ImportFileRequest {
pub doc_id: NamespaceId,
/// Author of this entry.
pub author_id: AuthorId,
/// Key of this entry.
/// Key of this entry.ExportSecretKeyResponse
pub key: Bytes,
/// The filepath to the data
///
Expand Down

0 comments on commit c8fe86e

Please sign in to comment.