refactor create dht value

This commit is contained in:
Christien Rioux
2023-07-08 22:50:44 -04:00
parent 9f9feeb325
commit 19f384ab33
13 changed files with 53 additions and 40 deletions

View File

@@ -1068,22 +1068,24 @@ impl VeilidAPI {
let routing_table = netman.routing_table();
let crypto = self.crypto()?;
let csv = get_debug_argument_at(
&args,
1,
"debug_record_create",
"kind",
get_crypto_system_version(crypto.clone()),
)
.unwrap_or_else(|_| crypto.best());
let schema = get_debug_argument_at(
&args,
2,
1,
"debug_record_create",
"dht_schema",
get_dht_schema,
)
.unwrap_or_else(|_| DHTSchema::dflt(1));
let csv = get_debug_argument_at(
&args,
2,
"debug_record_create",
"kind",
get_crypto_system_version(crypto.clone()),
)
.unwrap_or_else(|_| crypto.best());
let ss = get_debug_argument_at(
&args,
3,
@@ -1106,7 +1108,7 @@ impl VeilidAPI {
};
// Do a record get
let record = match rc.create_dht_record(csv.kind(), schema).await {
let record = match rc.create_dht_record(schema, Some(csv.kind())).await {
Err(e) => return Ok(format!("Can't open DHT record: {}", e)),
Ok(v) => v,
};
@@ -1348,7 +1350,7 @@ route allocate [ord|*ord] [rel] [<count>] [in|out]
test <route>
record list <local|remote>
purge <local|remote> [bytes]
create <cryptokind> <dhtschema> <safety>
create <dhtschema> [<cryptokind> [<safety>]]
set <key>[+<safety>] <subkey> <writer> <data>
get <key>[+<safety>] <subkey> [force]
delete <key>

View File

@@ -277,10 +277,10 @@ impl JsonRequestProcessor {
),
}
}
RoutingContextRequestOp::CreateDhtRecord { kind, schema } => {
RoutingContextRequestOp::CreateDhtRecord { schema, kind } => {
RoutingContextResponseOp::CreateDhtRecord {
result: to_json_api_result(
routing_context.create_dht_record(kind, schema).await,
routing_context.create_dht_record(schema, kind).await,
),
}
}

View File

@@ -38,9 +38,9 @@ pub enum RoutingContextRequestOp {
message: Vec<u8>,
},
CreateDhtRecord {
#[schemars(with = "String")]
kind: CryptoKind,
schema: DHTSchema,
#[schemars(with = "Option<String>")]
kind: Option<CryptoKind>,
},
OpenDhtRecord {
#[schemars(with = "String")]

View File

@@ -195,9 +195,10 @@ impl RoutingContext {
/// Returns the newly allocated DHT record's key if successful. The records is considered 'open' after the create operation succeeds.
pub async fn create_dht_record(
&self,
kind: CryptoKind,
schema: DHTSchema,
kind: Option<CryptoKind>,
) -> VeilidAPIResult<DHTRecordDescriptor> {
let kind = kind.unwrap_or(best_crypto_kind());
let storage_manager = self.api.storage_manager()?;
storage_manager
.create_record(kind, schema, self.unlocked_inner.safety_selection)