enable full safety selection through api
This commit is contained in:
@@ -28,7 +28,7 @@ abstract class DHTSchema {
|
||||
default:
|
||||
{
|
||||
throw VeilidAPIExceptionInternal(
|
||||
"Invalid VeilidAPIException type: ${json['kind']}");
|
||||
"Invalid DHTSchema type: ${json['kind']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,7 @@ class ValueData {
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// Stability
|
||||
|
||||
enum Stability {
|
||||
@@ -228,6 +229,80 @@ enum Sequencing {
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// SafetySelection
|
||||
|
||||
abstract class SafetySelection {
|
||||
factory SafetySelection.fromJson(dynamic json) {
|
||||
var m = json as Map<String, dynamic>;
|
||||
if (m.containsKey("Unsafe")) {
|
||||
return SafetySelectionUnsafe(
|
||||
sequencing: Sequencing.fromJson(m["Unsafe"]));
|
||||
} else if (m.containsKey("Safe")) {
|
||||
return SafetySelectionSafe(safetySpec: SafetySpec.fromJson(m["Safe"]));
|
||||
} else {
|
||||
throw VeilidAPIExceptionInternal("Invalid SafetySelection");
|
||||
}
|
||||
}
|
||||
Map<String, dynamic> toJson();
|
||||
}
|
||||
|
||||
class SafetySelectionUnsafe implements SafetySelection {
|
||||
final Sequencing sequencing;
|
||||
//
|
||||
SafetySelectionUnsafe({
|
||||
required this.sequencing,
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'Unsafe': sequencing.toJson()};
|
||||
}
|
||||
}
|
||||
|
||||
class SafetySelectionSafe implements SafetySelection {
|
||||
final SafetySpec safetySpec;
|
||||
//
|
||||
SafetySelectionSafe({
|
||||
required this.safetySpec,
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'Safe': safetySpec.toJson()};
|
||||
}
|
||||
}
|
||||
|
||||
/// Options for safety routes (sender privacy)
|
||||
class SafetySpec {
|
||||
final String? preferredRoute;
|
||||
final int hopCount;
|
||||
final Stability stability;
|
||||
final Sequencing sequencing;
|
||||
//
|
||||
SafetySpec({
|
||||
this.preferredRoute,
|
||||
required this.hopCount,
|
||||
required this.stability,
|
||||
required this.sequencing,
|
||||
});
|
||||
|
||||
SafetySpec.fromJson(dynamic json)
|
||||
: preferredRoute = json['preferred_route'],
|
||||
hopCount = json['hop_count'],
|
||||
stability = Stability.fromJson(json['stability']),
|
||||
sequencing = Sequencing.fromJson(json['sequencing']);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'preferred_route': preferredRoute,
|
||||
'hop_count': hopCount,
|
||||
'stability': stability.toJson(),
|
||||
'sequencing': sequencing.toJson()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// RouteBlob
|
||||
class RouteBlob {
|
||||
@@ -251,7 +326,7 @@ class RouteBlob {
|
||||
abstract class VeilidRoutingContext {
|
||||
// Modifiers
|
||||
VeilidRoutingContext withPrivacy();
|
||||
VeilidRoutingContext withCustomPrivacy(Stability stability);
|
||||
VeilidRoutingContext withCustomPrivacy(SafetySelection safetySelection);
|
||||
VeilidRoutingContext withSequencing(Sequencing sequencing);
|
||||
|
||||
// App call/message
|
||||
|
@@ -595,9 +595,9 @@ class VeilidRoutingContextFFI implements VeilidRoutingContext {
|
||||
}
|
||||
|
||||
@override
|
||||
VeilidRoutingContextFFI withCustomPrivacy(Stability stability) {
|
||||
VeilidRoutingContextFFI withCustomPrivacy(SafetySelection safetySelection) {
|
||||
final newId = _ctx.ffi._routingContextWithCustomPrivacy(
|
||||
_ctx.id, jsonEncode(stability).toNativeUtf8());
|
||||
_ctx.id, jsonEncode(safetySelection).toNativeUtf8());
|
||||
return VeilidRoutingContextFFI._(_Ctx(newId, _ctx.ffi));
|
||||
}
|
||||
|
||||
|
@@ -45,11 +45,11 @@ class VeilidRoutingContextJS implements VeilidRoutingContext {
|
||||
}
|
||||
|
||||
@override
|
||||
VeilidRoutingContextJS withCustomPrivacy(Stability stability) {
|
||||
VeilidRoutingContextJS withCustomPrivacy(SafetySelection safetySelection) {
|
||||
final newId = js_util.callMethod(
|
||||
wasm,
|
||||
"routing_context_with_custom_privacy",
|
||||
[_ctx.id, jsonEncode(stability)]);
|
||||
[_ctx.id, jsonEncode(safetySelection)]);
|
||||
|
||||
return VeilidRoutingContextJS._(_Ctx(newId, _ctx.js));
|
||||
}
|
||||
|
Reference in New Issue
Block a user