refactor create dht value
This commit is contained in:
@@ -234,8 +234,8 @@ abstract class VeilidRoutingContext {
|
||||
Future<void> appMessage(String target, Uint8List message);
|
||||
|
||||
// DHT Operations
|
||||
Future<DHTRecordDescriptor> createDHTRecord(
|
||||
CryptoKind kind, DHTSchema schema);
|
||||
Future<DHTRecordDescriptor> createDHTRecord(DHTSchema schema,
|
||||
{CryptoKind kind = 0});
|
||||
Future<DHTRecordDescriptor> openDHTRecord(TypedKey key, KeyPair? writer);
|
||||
Future<void> closeDHTRecord(TypedKey key);
|
||||
Future<void> deleteDHTRecord(TypedKey key);
|
||||
|
||||
@@ -78,9 +78,9 @@ typedef _RoutingContextAppMessageDart = void Function(
|
||||
int, int, Pointer<Utf8>, Pointer<Utf8>);
|
||||
// fn routing_context_create_dht_record(port: i64, id: u32, kind: u32, schema: FfiStr)
|
||||
typedef _RoutingContextCreateDHTRecordC = Void Function(
|
||||
Int64, Uint32, Uint32, Pointer<Utf8>);
|
||||
Int64, Uint32, Pointer<Utf8>, Uint32);
|
||||
typedef _RoutingContextCreateDHTRecordDart = void Function(
|
||||
int, int, int, Pointer<Utf8>);
|
||||
int, int, Pointer<Utf8>, int);
|
||||
// fn routing_context_open_dht_record(port: i64, id: u32, key: FfiStr, writer: FfiStr)
|
||||
typedef _RoutingContextOpenDHTRecordC = Void Function(
|
||||
Int64, Uint32, Pointer<Utf8>, Pointer<Utf8>);
|
||||
@@ -634,13 +634,13 @@ class VeilidRoutingContextFFI implements VeilidRoutingContext {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DHTRecordDescriptor> createDHTRecord(
|
||||
CryptoKind kind, DHTSchema schema) async {
|
||||
Future<DHTRecordDescriptor> createDHTRecord(DHTSchema schema,
|
||||
{CryptoKind kind = 0}) async {
|
||||
final nativeSchema = jsonEncode(schema).toNativeUtf8();
|
||||
final recvPort = ReceivePort("routing_context_create_dht_record");
|
||||
final sendPort = recvPort.sendPort;
|
||||
_ctx.ffi._routingContextCreateDHTRecord(
|
||||
sendPort.nativePort, _ctx.id, kind, nativeSchema);
|
||||
sendPort.nativePort, _ctx.id, nativeSchema, kind);
|
||||
final dhtRecordDescriptor =
|
||||
await processFutureJson(DHTRecordDescriptor.fromJson, recvPort.first);
|
||||
return dhtRecordDescriptor;
|
||||
|
||||
@@ -78,11 +78,11 @@ class VeilidRoutingContextJS implements VeilidRoutingContext {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DHTRecordDescriptor> createDHTRecord(
|
||||
CryptoKind kind, DHTSchema schema) async {
|
||||
Future<DHTRecordDescriptor> createDHTRecord(DHTSchema schema,
|
||||
{CryptoKind kind = 0}) async {
|
||||
return DHTRecordDescriptor.fromJson(jsonDecode(await _wrapApiPromise(js_util
|
||||
.callMethod(wasm, "routing_context_create_dht_record",
|
||||
[_ctx.id, kind, jsonEncode(schema)]))));
|
||||
[_ctx.id, jsonEncode(schema), kind]))));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -492,8 +492,12 @@ pub extern "C" fn routing_context_app_message(port: i64, id: u32, target: FfiStr
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn routing_context_create_dht_record(port: i64, id: u32, kind: u32, schema: FfiStr) {
|
||||
let crypto_kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind);
|
||||
pub extern "C" fn routing_context_create_dht_record(port: i64, id: u32, schema: FfiStr, kind: u32) {
|
||||
let crypto_kind = if kind == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(veilid_core::FourCC::from(kind))
|
||||
};
|
||||
let schema: veilid_core::DHTSchema = veilid_core::deserialize_opt_json(schema.into_opt_string()).unwrap();
|
||||
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
@@ -505,7 +509,7 @@ pub extern "C" fn routing_context_create_dht_record(port: i64, id: u32, kind: u3
|
||||
routing_context.clone()
|
||||
};
|
||||
|
||||
let dht_record_descriptor = routing_context.create_dht_record(crypto_kind, schema).await?;
|
||||
let dht_record_descriptor = routing_context.create_dht_record(schema, crypto_kind).await?;
|
||||
APIResult::Ok(dht_record_descriptor)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user