Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Oct 18, 2024
1 parent 85bd8b7 commit 033e7f4
Show file tree
Hide file tree
Showing 9 changed files with 518 additions and 486 deletions.
899 changes: 447 additions & 452 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 @@ -22,8 +22,8 @@ pub use iroh_docs::engine::{Origin, SyncEvent, SyncReason};
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 @@ -35,10 +35,10 @@ use super::{blobs, flatten, RpcClient};
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,
},
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
52 changes: 30 additions & 22 deletions iroh/src/node/rpc/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ use iroh_base::rpc::RpcResult;
use iroh_blobs::{store::Store as BaoStore, BlobFormat};
use iroh_docs::{Author, DocTicket, NamespaceSecret};

use crate::{
client::docs::ShareMode,
node::DocsEngine,
rpc_protocol::{
authors::{
CreateRequest, CreateResponse, DeleteRequest, DeleteResponse, ExportRequest,
ExportResponse, GetDefaultRequest, GetDefaultResponse, ImportRequest, ImportResponse,
ListRequest as AuthorListRequest, ListResponse as AuthorListResponse,
SetDefaultRequest, SetDefaultResponse,
},
docs::{
CloseRequest, CloseResponse, CreateRequest as DocCreateRequest,
CreateResponse as DocCreateResponse, DelRequest, DelResponse, DocListRequest,
DocSubscribeRequest, DocSubscribeResponse, DropRequest, DropResponse,
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,
SetRequest, SetResponse, ShareRequest, ShareResponse, StartSyncRequest,
StartSyncResponse, StatusRequest, StatusResponse,
},
use crate::client::docs::ShareMode;
use crate::node::DocsEngine;

use crate::rpc_protocol::{
authors::{
CreateRequest, CreateResponse, DeleteRequest, DeleteResponse, ExportRequest,
ExportResponse, GetDefaultRequest, GetDefaultResponse, ImportRequest, ImportResponse,
ListRequest as AuthorListRequest, ListResponse as AuthorListResponse, SetDefaultRequest,
SetDefaultResponse,
},
docs::{
CloseRequest, CloseResponse, CreateRequest as DocCreateRequest,
CreateResponse as DocCreateResponse, DelRequest, DelResponse, DocListRequest,
DocSubscribeRequest, DocSubscribeResponse, DropRequest, DropResponse,
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,
SetRequest, SetResponse, ShareRequest, ShareResponse, StartSyncRequest, StartSyncResponse,
StatusRequest, StatusResponse,
},
};

Expand Down Expand Up @@ -307,4 +307,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 })
}
}
21 changes: 19 additions & 2 deletions iroh/src/rpc_protocol/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use iroh_docs::{
actor::OpenState,
engine::LiveEvent,
store::{DownloadPolicy, Query},
AuthorId, Capability, CapabilityKind, DocTicket, Entry, NamespaceId, PeerIdBytes, SignedEntry,
AuthorId, Capability, CapabilityKind, DocTicket, Entry, NamespaceId, NamespaceSecret,
PeerIdBytes, SignedEntry,
};
use iroh_net::NodeAddr;
use nested_enum_utils::enum_conversions;
Expand Down Expand Up @@ -38,6 +39,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 @@ -96,6 +99,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 @@ -237,6 +241,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 @@ -268,7 +285,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 033e7f4

Please sign in to comment.