record work

This commit is contained in:
John Smith
2023-04-25 21:52:53 -04:00
parent 8368ca461a
commit 36cb0687cb
13 changed files with 231 additions and 177 deletions

View File

@@ -203,7 +203,7 @@ impl RoutingContext {
&self,
kind: CryptoKind,
schema: DHTSchema,
) -> Result<TypedKey, VeilidAPIError> {
) -> Result<DHTRecordDescriptor, VeilidAPIError> {
let storage_manager = self.api.storage_manager()?;
storage_manager
.create_record(kind, schema, self.unlocked_inner.safety_selection)
@@ -216,7 +216,7 @@ impl RoutingContext {
pub async fn open_dht_record(
&self,
key: TypedKey,
secret: Option<SecretKey>,
writer: Option<KeyPair>,
) -> Result<DHTRecordDescriptor, VeilidAPIError> {
let storage_manager = self.api.storage_manager()?;
storage_manager
@@ -232,7 +232,7 @@ impl RoutingContext {
}
/// Deletes a DHT record at a specific key. If the record is opened, it must be closed before it is deleted.
/// Deleting a record does not delete it from the network immediately, but will remove the storage of the record
/// Deleting a record does not delete it from the network, but will remove the storage of the record
/// locally, and will prevent its value from being refreshed on the network by this node.
pub async fn delete_dht_record(&self, key: TypedKey) -> Result<(), VeilidAPIError> {
let storage_manager = self.api.storage_manager()?;

View File

@@ -16,19 +16,40 @@ use super::*;
)]
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct DHTRecordDescriptor {
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
key: TypedKey,
/// The public key of the owner
owner: PublicKey,
/// If this key is being created: Some(the secret key of the owner)
/// If this key is just being opened: None
owner_secret: Option<SecretKey>,
/// The schema in use associated with the key
schema: DHTSchema,
}
impl DHTRecordDescriptor {
pub fn new(owner: PublicKey, schema: DHTSchema) -> Self {
Self { owner, schema }
pub fn new(
key: TypedKey,
owner: PublicKey,
owner_secret: Option<SecretKey>,
schema: DHTSchema,
) -> Self {
Self {
key,
owner,
owner_secret,
schema,
}
}
pub fn owner(&self) -> &PublicKey {
&self.owner
}
pub fn owner_secret(&self) -> Option<&SecretKey> {
self.owner_secret.as_ref()
}
pub fn schema(&self) -> &DHTSchema {
&self.schema
}