freezed
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'veilid_stub.dart'
|
||||
if (dart.library.io) 'veilid_ffi.dart'
|
||||
if (dart.library.js) 'veilid_js.dart';
|
||||
@@ -56,64 +59,61 @@ List<T> Function(dynamic) jsonListConstructor<T>(
|
||||
//////////////////////////////////////
|
||||
/// VeilidVersion
|
||||
|
||||
class VeilidVersion {
|
||||
@immutable
|
||||
class VeilidVersion extends Equatable {
|
||||
final int major;
|
||||
final int minor;
|
||||
final int patch;
|
||||
@override
|
||||
List<Object> get props => [major, minor, patch];
|
||||
|
||||
VeilidVersion(this.major, this.minor, this.patch);
|
||||
const VeilidVersion(this.major, this.minor, this.patch);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// Timestamp
|
||||
class Timestamp {
|
||||
@immutable
|
||||
class Timestamp extends Equatable {
|
||||
final BigInt value;
|
||||
Timestamp({required this.value});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
|
||||
const Timestamp({required this.value});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
String toString() => value.toString();
|
||||
factory Timestamp.fromString(String s) => Timestamp(value: BigInt.parse(s));
|
||||
|
||||
Timestamp.fromString(String s) : value = BigInt.parse(s);
|
||||
String toJson() => toString();
|
||||
factory Timestamp.fromJson(dynamic json) =>
|
||||
Timestamp.fromString(json as String);
|
||||
|
||||
Timestamp.fromJson(dynamic json) : this.fromString(json as String);
|
||||
String toJson() {
|
||||
return toString();
|
||||
}
|
||||
TimestampDuration diff(Timestamp other) =>
|
||||
TimestampDuration(value: value - other.value);
|
||||
|
||||
TimestampDuration diff(Timestamp other) {
|
||||
return TimestampDuration(value: value - other.value);
|
||||
}
|
||||
|
||||
Timestamp offset(TimestampDuration dur) {
|
||||
return Timestamp(value: value + dur.value);
|
||||
}
|
||||
Timestamp offset(TimestampDuration dur) =>
|
||||
Timestamp(value: value + dur.value);
|
||||
}
|
||||
|
||||
class TimestampDuration {
|
||||
@immutable
|
||||
class TimestampDuration extends Equatable {
|
||||
final BigInt value;
|
||||
TimestampDuration({required this.value});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
|
||||
const TimestampDuration({required this.value});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
String toString() => value.toString();
|
||||
factory TimestampDuration.fromString(String s) =>
|
||||
TimestampDuration(value: BigInt.parse(s));
|
||||
|
||||
TimestampDuration.fromString(String s) : value = BigInt.parse(s);
|
||||
String toJson() => toString();
|
||||
factory TimestampDuration.fromJson(dynamic json) =>
|
||||
TimestampDuration.fromString(json as String);
|
||||
|
||||
TimestampDuration.fromJson(dynamic json) : this.fromString(json as String);
|
||||
String toJson() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
int toMillis() {
|
||||
return (value ~/ BigInt.from(1000)).toInt();
|
||||
}
|
||||
|
||||
BigInt toMicros(Timestamp other) {
|
||||
return value;
|
||||
}
|
||||
int toMillis() => (value ~/ BigInt.from(1000)).toInt();
|
||||
BigInt toMicros() => value;
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
//////////////////////////////////////
|
||||
/// VeilidAPIException
|
||||
|
||||
@immutable
|
||||
abstract class VeilidAPIException implements Exception {
|
||||
factory VeilidAPIException.fromJson(dynamic json) {
|
||||
switch (json["kind"]) {
|
||||
@@ -73,6 +76,7 @@ abstract class VeilidAPIException implements Exception {
|
||||
String toDisplayError();
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionNotInitialized implements VeilidAPIException {
|
||||
@override
|
||||
String toString() {
|
||||
@@ -85,6 +89,7 @@ class VeilidAPIExceptionNotInitialized implements VeilidAPIException {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionAlreadyInitialized implements VeilidAPIException {
|
||||
@override
|
||||
String toString() {
|
||||
@@ -97,6 +102,7 @@ class VeilidAPIExceptionAlreadyInitialized implements VeilidAPIException {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionTimeout implements VeilidAPIException {
|
||||
@override
|
||||
String toString() {
|
||||
@@ -109,6 +115,7 @@ class VeilidAPIExceptionTimeout implements VeilidAPIException {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionTryAgain implements VeilidAPIException {
|
||||
@override
|
||||
String toString() {
|
||||
@@ -121,6 +128,7 @@ class VeilidAPIExceptionTryAgain implements VeilidAPIException {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionShutdown implements VeilidAPIException {
|
||||
@override
|
||||
String toString() {
|
||||
@@ -133,6 +141,7 @@ class VeilidAPIExceptionShutdown implements VeilidAPIException {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionInvalidTarget implements VeilidAPIException {
|
||||
@override
|
||||
String toString() {
|
||||
@@ -145,9 +154,9 @@ class VeilidAPIExceptionInvalidTarget implements VeilidAPIException {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionNoConnection implements VeilidAPIException {
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "VeilidAPIException: NoConnection (message: $message)";
|
||||
@@ -159,12 +168,12 @@ class VeilidAPIExceptionNoConnection implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionNoConnection(this.message);
|
||||
const VeilidAPIExceptionNoConnection(this.message);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionKeyNotFound implements VeilidAPIException {
|
||||
final String key;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "VeilidAPIException: KeyNotFound (key: $key)";
|
||||
@@ -176,9 +185,10 @@ class VeilidAPIExceptionKeyNotFound implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionKeyNotFound(this.key);
|
||||
const VeilidAPIExceptionKeyNotFound(this.key);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionInternal implements VeilidAPIException {
|
||||
final String message;
|
||||
|
||||
@@ -193,9 +203,10 @@ class VeilidAPIExceptionInternal implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionInternal(this.message);
|
||||
const VeilidAPIExceptionInternal(this.message);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionUnimplemented implements VeilidAPIException {
|
||||
final String message;
|
||||
|
||||
@@ -210,9 +221,10 @@ class VeilidAPIExceptionUnimplemented implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionUnimplemented(this.message);
|
||||
const VeilidAPIExceptionUnimplemented(this.message);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionParseError implements VeilidAPIException {
|
||||
final String message;
|
||||
final String value;
|
||||
@@ -228,9 +240,10 @@ class VeilidAPIExceptionParseError implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionParseError(this.message, this.value);
|
||||
const VeilidAPIExceptionParseError(this.message, this.value);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionInvalidArgument implements VeilidAPIException {
|
||||
final String context;
|
||||
final String argument;
|
||||
@@ -247,9 +260,11 @@ class VeilidAPIExceptionInvalidArgument implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionInvalidArgument(this.context, this.argument, this.value);
|
||||
const VeilidAPIExceptionInvalidArgument(
|
||||
this.context, this.argument, this.value);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionMissingArgument implements VeilidAPIException {
|
||||
final String context;
|
||||
final String argument;
|
||||
@@ -265,9 +280,10 @@ class VeilidAPIExceptionMissingArgument implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionMissingArgument(this.context, this.argument);
|
||||
const VeilidAPIExceptionMissingArgument(this.context, this.argument);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VeilidAPIExceptionGeneric implements VeilidAPIException {
|
||||
final String message;
|
||||
|
||||
@@ -282,5 +298,5 @@ class VeilidAPIExceptionGeneric implements VeilidAPIException {
|
||||
}
|
||||
|
||||
//
|
||||
VeilidAPIExceptionGeneric(this.message);
|
||||
const VeilidAPIExceptionGeneric(this.message);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,550 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'veilid_config.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$_VeilidFFIConfigLoggingTerminal _$$_VeilidFFIConfigLoggingTerminalFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidFFIConfigLoggingTerminal(
|
||||
enabled: json['enabled'] as bool,
|
||||
level: VeilidConfigLogLevel.fromJson(json['level']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidFFIConfigLoggingTerminalToJson(
|
||||
_$_VeilidFFIConfigLoggingTerminal instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'level': instance.level.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidFFIConfigLoggingOtlp _$$_VeilidFFIConfigLoggingOtlpFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidFFIConfigLoggingOtlp(
|
||||
enabled: json['enabled'] as bool,
|
||||
level: VeilidConfigLogLevel.fromJson(json['level']),
|
||||
grpcEndpoint: json['grpc_endpoint'] as String,
|
||||
serviceName: json['service_name'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidFFIConfigLoggingOtlpToJson(
|
||||
_$_VeilidFFIConfigLoggingOtlp instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'level': instance.level.toJson(),
|
||||
'grpc_endpoint': instance.grpcEndpoint,
|
||||
'service_name': instance.serviceName,
|
||||
};
|
||||
|
||||
_$_VeilidFFIConfigLoggingApi _$$_VeilidFFIConfigLoggingApiFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidFFIConfigLoggingApi(
|
||||
enabled: json['enabled'] as bool,
|
||||
level: VeilidConfigLogLevel.fromJson(json['level']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidFFIConfigLoggingApiToJson(
|
||||
_$_VeilidFFIConfigLoggingApi instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'level': instance.level.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidFFIConfigLogging _$$_VeilidFFIConfigLoggingFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidFFIConfigLogging(
|
||||
terminal: VeilidFFIConfigLoggingTerminal.fromJson(
|
||||
json['terminal'] as Map<String, dynamic>),
|
||||
otlp: VeilidFFIConfigLoggingOtlp.fromJson(
|
||||
json['otlp'] as Map<String, dynamic>),
|
||||
api: VeilidFFIConfigLoggingApi.fromJson(
|
||||
json['api'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidFFIConfigLoggingToJson(
|
||||
_$_VeilidFFIConfigLogging instance) =>
|
||||
<String, dynamic>{
|
||||
'terminal': instance.terminal.toJson(),
|
||||
'otlp': instance.otlp.toJson(),
|
||||
'api': instance.api.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidFFIConfig _$$_VeilidFFIConfigFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidFFIConfig(
|
||||
logging: VeilidFFIConfigLogging.fromJson(
|
||||
json['logging'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidFFIConfigToJson(_$_VeilidFFIConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'logging': instance.logging.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidWASMConfigLoggingPerformance
|
||||
_$$_VeilidWASMConfigLoggingPerformanceFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidWASMConfigLoggingPerformance(
|
||||
enabled: json['enabled'] as bool,
|
||||
level: VeilidConfigLogLevel.fromJson(json['level']),
|
||||
logsInTimings: json['logs_in_timings'] as bool,
|
||||
logsInConsole: json['logs_in_console'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidWASMConfigLoggingPerformanceToJson(
|
||||
_$_VeilidWASMConfigLoggingPerformance instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'level': instance.level.toJson(),
|
||||
'logs_in_timings': instance.logsInTimings,
|
||||
'logs_in_console': instance.logsInConsole,
|
||||
};
|
||||
|
||||
_$_VeilidWASMConfigLoggingApi _$$_VeilidWASMConfigLoggingApiFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidWASMConfigLoggingApi(
|
||||
enabled: json['enabled'] as bool,
|
||||
level: VeilidConfigLogLevel.fromJson(json['level']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidWASMConfigLoggingApiToJson(
|
||||
_$_VeilidWASMConfigLoggingApi instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'level': instance.level.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidWASMConfigLogging _$$_VeilidWASMConfigLoggingFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidWASMConfigLogging(
|
||||
performance: VeilidWASMConfigLoggingPerformance.fromJson(
|
||||
json['performance'] as Map<String, dynamic>),
|
||||
api: VeilidWASMConfigLoggingApi.fromJson(
|
||||
json['api'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidWASMConfigLoggingToJson(
|
||||
_$_VeilidWASMConfigLogging instance) =>
|
||||
<String, dynamic>{
|
||||
'performance': instance.performance.toJson(),
|
||||
'api': instance.api.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidWASMConfig _$$_VeilidWASMConfigFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidWASMConfig(
|
||||
logging: VeilidWASMConfigLogging.fromJson(
|
||||
json['logging'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidWASMConfigToJson(_$_VeilidWASMConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'logging': instance.logging.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidConfigHTTPS _$$_VeilidConfigHTTPSFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigHTTPS(
|
||||
enabled: json['enabled'] as bool,
|
||||
listenAddress: json['listen_address'] as String,
|
||||
path: json['path'] as String,
|
||||
url: json['url'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigHTTPSToJson(
|
||||
_$_VeilidConfigHTTPS instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'listen_address': instance.listenAddress,
|
||||
'path': instance.path,
|
||||
'url': instance.url,
|
||||
};
|
||||
|
||||
_$_VeilidConfigHTTP _$$_VeilidConfigHTTPFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigHTTP(
|
||||
enabled: json['enabled'] as bool,
|
||||
listenAddress: json['listen_address'] as String,
|
||||
path: json['path'] as String,
|
||||
url: json['url'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigHTTPToJson(_$_VeilidConfigHTTP instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'listen_address': instance.listenAddress,
|
||||
'path': instance.path,
|
||||
'url': instance.url,
|
||||
};
|
||||
|
||||
_$_VeilidConfigApplication _$$_VeilidConfigApplicationFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigApplication(
|
||||
https: VeilidConfigHTTPS.fromJson(json['https'] as Map<String, dynamic>),
|
||||
http: VeilidConfigHTTP.fromJson(json['http'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigApplicationToJson(
|
||||
_$_VeilidConfigApplication instance) =>
|
||||
<String, dynamic>{
|
||||
'https': instance.https.toJson(),
|
||||
'http': instance.http.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidConfigUDP _$$_VeilidConfigUDPFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigUDP(
|
||||
enabled: json['enabled'] as bool,
|
||||
socketPoolSize: json['socket_pool_size'] as int,
|
||||
listenAddress: json['listen_address'] as String,
|
||||
publicAddress: json['public_address'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigUDPToJson(_$_VeilidConfigUDP instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'socket_pool_size': instance.socketPoolSize,
|
||||
'listen_address': instance.listenAddress,
|
||||
'public_address': instance.publicAddress,
|
||||
};
|
||||
|
||||
_$_VeilidConfigTCP _$$_VeilidConfigTCPFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigTCP(
|
||||
connect: json['connect'] as bool,
|
||||
listen: json['listen'] as bool,
|
||||
maxConnections: json['max_connections'] as int,
|
||||
listenAddress: json['listen_address'] as String,
|
||||
publicAddress: json['public_address'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigTCPToJson(_$_VeilidConfigTCP instance) =>
|
||||
<String, dynamic>{
|
||||
'connect': instance.connect,
|
||||
'listen': instance.listen,
|
||||
'max_connections': instance.maxConnections,
|
||||
'listen_address': instance.listenAddress,
|
||||
'public_address': instance.publicAddress,
|
||||
};
|
||||
|
||||
_$_VeilidConfigWS _$$_VeilidConfigWSFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigWS(
|
||||
connect: json['connect'] as bool,
|
||||
listen: json['listen'] as bool,
|
||||
maxConnections: json['max_connections'] as int,
|
||||
listenAddress: json['listen_address'] as String,
|
||||
path: json['path'] as String,
|
||||
url: json['url'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigWSToJson(_$_VeilidConfigWS instance) =>
|
||||
<String, dynamic>{
|
||||
'connect': instance.connect,
|
||||
'listen': instance.listen,
|
||||
'max_connections': instance.maxConnections,
|
||||
'listen_address': instance.listenAddress,
|
||||
'path': instance.path,
|
||||
'url': instance.url,
|
||||
};
|
||||
|
||||
_$_VeilidConfigWSS _$$_VeilidConfigWSSFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigWSS(
|
||||
connect: json['connect'] as bool,
|
||||
listen: json['listen'] as bool,
|
||||
maxConnections: json['max_connections'] as int,
|
||||
listenAddress: json['listen_address'] as String,
|
||||
path: json['path'] as String,
|
||||
url: json['url'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigWSSToJson(_$_VeilidConfigWSS instance) =>
|
||||
<String, dynamic>{
|
||||
'connect': instance.connect,
|
||||
'listen': instance.listen,
|
||||
'max_connections': instance.maxConnections,
|
||||
'listen_address': instance.listenAddress,
|
||||
'path': instance.path,
|
||||
'url': instance.url,
|
||||
};
|
||||
|
||||
_$_VeilidConfigProtocol _$$_VeilidConfigProtocolFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigProtocol(
|
||||
udp: VeilidConfigUDP.fromJson(json['udp'] as Map<String, dynamic>),
|
||||
tcp: VeilidConfigTCP.fromJson(json['tcp'] as Map<String, dynamic>),
|
||||
ws: VeilidConfigWS.fromJson(json['ws'] as Map<String, dynamic>),
|
||||
wss: VeilidConfigWSS.fromJson(json['wss'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigProtocolToJson(
|
||||
_$_VeilidConfigProtocol instance) =>
|
||||
<String, dynamic>{
|
||||
'udp': instance.udp.toJson(),
|
||||
'tcp': instance.tcp.toJson(),
|
||||
'ws': instance.ws.toJson(),
|
||||
'wss': instance.wss.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidConfigTLS _$$_VeilidConfigTLSFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigTLS(
|
||||
certificatePath: json['certificate_path'] as String,
|
||||
privateKeyPath: json['private_key_path'] as String,
|
||||
connectionInitialTimeoutMs: json['connection_initial_timeout_ms'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigTLSToJson(_$_VeilidConfigTLS instance) =>
|
||||
<String, dynamic>{
|
||||
'certificate_path': instance.certificatePath,
|
||||
'private_key_path': instance.privateKeyPath,
|
||||
'connection_initial_timeout_ms': instance.connectionInitialTimeoutMs,
|
||||
};
|
||||
|
||||
_$_VeilidConfigDHT _$$_VeilidConfigDHTFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigDHT(
|
||||
resolveNodeTimeoutMs: json['resolve_node_timeout_ms'] as int,
|
||||
resolveNodeCount: json['resolve_node_count'] as int,
|
||||
resolveNodeFanout: json['resolve_node_fanout'] as int,
|
||||
maxFindNodeCount: json['max_find_node_count'] as int,
|
||||
getValueTimeoutMs: json['get_value_timeout_ms'] as int,
|
||||
getValueCount: json['get_value_count'] as int,
|
||||
getValueFanout: json['get_value_fanout'] as int,
|
||||
setValueTimeoutMs: json['set_value_timeout_ms'] as int,
|
||||
setValueCount: json['set_value_count'] as int,
|
||||
setValueFanout: json['set_value_fanout'] as int,
|
||||
minPeerCount: json['min_peer_count'] as int,
|
||||
minPeerRefreshTimeMs: json['min_peer_refresh_time_ms'] as int,
|
||||
validateDialInfoReceiptTimeMs:
|
||||
json['validate_dial_info_receipt_time_ms'] as int,
|
||||
localSubkeyCacheSize: json['local_subkey_cache_size'] as int,
|
||||
localMaxSubkeyCacheMemoryMb:
|
||||
json['local_max_subkey_cache_memory_mb'] as int,
|
||||
remoteSubkeyCacheSize: json['remote_subkey_cache_size'] as int,
|
||||
remoteMaxRecords: json['remote_max_records'] as int,
|
||||
remoteMaxSubkeyCacheMemoryMb:
|
||||
json['remote_max_subkey_cache_memory_mb'] as int,
|
||||
remoteMaxStorageSpaceMb: json['remote_max_storage_space_mb'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigDHTToJson(_$_VeilidConfigDHT instance) =>
|
||||
<String, dynamic>{
|
||||
'resolve_node_timeout_ms': instance.resolveNodeTimeoutMs,
|
||||
'resolve_node_count': instance.resolveNodeCount,
|
||||
'resolve_node_fanout': instance.resolveNodeFanout,
|
||||
'max_find_node_count': instance.maxFindNodeCount,
|
||||
'get_value_timeout_ms': instance.getValueTimeoutMs,
|
||||
'get_value_count': instance.getValueCount,
|
||||
'get_value_fanout': instance.getValueFanout,
|
||||
'set_value_timeout_ms': instance.setValueTimeoutMs,
|
||||
'set_value_count': instance.setValueCount,
|
||||
'set_value_fanout': instance.setValueFanout,
|
||||
'min_peer_count': instance.minPeerCount,
|
||||
'min_peer_refresh_time_ms': instance.minPeerRefreshTimeMs,
|
||||
'validate_dial_info_receipt_time_ms':
|
||||
instance.validateDialInfoReceiptTimeMs,
|
||||
'local_subkey_cache_size': instance.localSubkeyCacheSize,
|
||||
'local_max_subkey_cache_memory_mb': instance.localMaxSubkeyCacheMemoryMb,
|
||||
'remote_subkey_cache_size': instance.remoteSubkeyCacheSize,
|
||||
'remote_max_records': instance.remoteMaxRecords,
|
||||
'remote_max_subkey_cache_memory_mb':
|
||||
instance.remoteMaxSubkeyCacheMemoryMb,
|
||||
'remote_max_storage_space_mb': instance.remoteMaxStorageSpaceMb,
|
||||
};
|
||||
|
||||
_$_VeilidConfigRPC _$$_VeilidConfigRPCFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigRPC(
|
||||
concurrency: json['concurrency'] as int,
|
||||
queueSize: json['queue_size'] as int,
|
||||
maxTimestampBehindMs: json['max_timestamp_behind_ms'] as int?,
|
||||
maxTimestampAheadMs: json['max_timestamp_ahead_ms'] as int?,
|
||||
timeoutMs: json['timeout_ms'] as int,
|
||||
maxRouteHopCount: json['max_route_hop_count'] as int,
|
||||
defaultRouteHopCount: json['default_route_hop_count'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigRPCToJson(_$_VeilidConfigRPC instance) =>
|
||||
<String, dynamic>{
|
||||
'concurrency': instance.concurrency,
|
||||
'queue_size': instance.queueSize,
|
||||
'max_timestamp_behind_ms': instance.maxTimestampBehindMs,
|
||||
'max_timestamp_ahead_ms': instance.maxTimestampAheadMs,
|
||||
'timeout_ms': instance.timeoutMs,
|
||||
'max_route_hop_count': instance.maxRouteHopCount,
|
||||
'default_route_hop_count': instance.defaultRouteHopCount,
|
||||
};
|
||||
|
||||
_$_VeilidConfigRoutingTable _$$_VeilidConfigRoutingTableFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigRoutingTable(
|
||||
nodeId: (json['node_id'] as List<dynamic>)
|
||||
.map(Typed<FixedEncodedString43>.fromJson)
|
||||
.toList(),
|
||||
nodeIdSecret: (json['node_id_secret'] as List<dynamic>)
|
||||
.map(Typed<FixedEncodedString43>.fromJson)
|
||||
.toList(),
|
||||
bootstrap:
|
||||
(json['bootstrap'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
limitOverAttached: json['limit_over_attached'] as int,
|
||||
limitFullyAttached: json['limit_fully_attached'] as int,
|
||||
limitAttachedStrong: json['limit_attached_strong'] as int,
|
||||
limitAttachedGood: json['limit_attached_good'] as int,
|
||||
limitAttachedWeak: json['limit_attached_weak'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigRoutingTableToJson(
|
||||
_$_VeilidConfigRoutingTable instance) =>
|
||||
<String, dynamic>{
|
||||
'node_id': instance.nodeId.map((e) => e.toJson()).toList(),
|
||||
'node_id_secret': instance.nodeIdSecret.map((e) => e.toJson()).toList(),
|
||||
'bootstrap': instance.bootstrap,
|
||||
'limit_over_attached': instance.limitOverAttached,
|
||||
'limit_fully_attached': instance.limitFullyAttached,
|
||||
'limit_attached_strong': instance.limitAttachedStrong,
|
||||
'limit_attached_good': instance.limitAttachedGood,
|
||||
'limit_attached_weak': instance.limitAttachedWeak,
|
||||
};
|
||||
|
||||
_$_VeilidConfigNetwork _$$_VeilidConfigNetworkFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigNetwork(
|
||||
connectionInitialTimeoutMs: json['connection_initial_timeout_ms'] as int,
|
||||
connectionInactivityTimeoutMs:
|
||||
json['connection_inactivity_timeout_ms'] as int,
|
||||
maxConnectionsPerIp4: json['max_connections_per_ip4'] as int,
|
||||
maxConnectionsPerIp6Prefix: json['max_connections_per_ip6_prefix'] as int,
|
||||
maxConnectionsPerIp6PrefixSize:
|
||||
json['max_connections_per_ip6_prefix_size'] as int,
|
||||
maxConnectionFrequencyPerMin:
|
||||
json['max_connection_frequency_per_min'] as int,
|
||||
clientWhitelistTimeoutMs: json['client_whitelist_timeout_ms'] as int,
|
||||
reverseConnectionReceiptTimeMs:
|
||||
json['reverse_connection_receipt_time_ms'] as int,
|
||||
holePunchReceiptTimeMs: json['hole_punch_receipt_time_ms'] as int,
|
||||
networkKeyPassword: json['network_key_password'] as String?,
|
||||
routingTable: VeilidConfigRoutingTable.fromJson(
|
||||
json['routing_table'] as Map<String, dynamic>),
|
||||
rpc: VeilidConfigRPC.fromJson(json['rpc'] as Map<String, dynamic>),
|
||||
dht: VeilidConfigDHT.fromJson(json['dht'] as Map<String, dynamic>),
|
||||
upnp: json['upnp'] as bool,
|
||||
detectAddressChanges: json['detect_address_changes'] as bool,
|
||||
restrictedNatRetries: json['restricted_nat_retries'] as int,
|
||||
tls: VeilidConfigTLS.fromJson(json['tls'] as Map<String, dynamic>),
|
||||
application: VeilidConfigApplication.fromJson(
|
||||
json['application'] as Map<String, dynamic>),
|
||||
protocol: VeilidConfigProtocol.fromJson(
|
||||
json['protocol'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigNetworkToJson(
|
||||
_$_VeilidConfigNetwork instance) =>
|
||||
<String, dynamic>{
|
||||
'connection_initial_timeout_ms': instance.connectionInitialTimeoutMs,
|
||||
'connection_inactivity_timeout_ms':
|
||||
instance.connectionInactivityTimeoutMs,
|
||||
'max_connections_per_ip4': instance.maxConnectionsPerIp4,
|
||||
'max_connections_per_ip6_prefix': instance.maxConnectionsPerIp6Prefix,
|
||||
'max_connections_per_ip6_prefix_size':
|
||||
instance.maxConnectionsPerIp6PrefixSize,
|
||||
'max_connection_frequency_per_min': instance.maxConnectionFrequencyPerMin,
|
||||
'client_whitelist_timeout_ms': instance.clientWhitelistTimeoutMs,
|
||||
'reverse_connection_receipt_time_ms':
|
||||
instance.reverseConnectionReceiptTimeMs,
|
||||
'hole_punch_receipt_time_ms': instance.holePunchReceiptTimeMs,
|
||||
'network_key_password': instance.networkKeyPassword,
|
||||
'routing_table': instance.routingTable.toJson(),
|
||||
'rpc': instance.rpc.toJson(),
|
||||
'dht': instance.dht.toJson(),
|
||||
'upnp': instance.upnp,
|
||||
'detect_address_changes': instance.detectAddressChanges,
|
||||
'restricted_nat_retries': instance.restrictedNatRetries,
|
||||
'tls': instance.tls.toJson(),
|
||||
'application': instance.application.toJson(),
|
||||
'protocol': instance.protocol.toJson(),
|
||||
};
|
||||
|
||||
_$_VeilidConfigTableStore _$$_VeilidConfigTableStoreFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigTableStore(
|
||||
directory: json['directory'] as String,
|
||||
delete: json['delete'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigTableStoreToJson(
|
||||
_$_VeilidConfigTableStore instance) =>
|
||||
<String, dynamic>{
|
||||
'directory': instance.directory,
|
||||
'delete': instance.delete,
|
||||
};
|
||||
|
||||
_$_VeilidConfigBlockStore _$$_VeilidConfigBlockStoreFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigBlockStore(
|
||||
directory: json['directory'] as String,
|
||||
delete: json['delete'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigBlockStoreToJson(
|
||||
_$_VeilidConfigBlockStore instance) =>
|
||||
<String, dynamic>{
|
||||
'directory': instance.directory,
|
||||
'delete': instance.delete,
|
||||
};
|
||||
|
||||
_$_VeilidConfigProtectedStore _$$_VeilidConfigProtectedStoreFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigProtectedStore(
|
||||
allowInsecureFallback: json['allow_insecure_fallback'] as bool,
|
||||
alwaysUseInsecureStorage: json['always_use_insecure_storage'] as bool,
|
||||
directory: json['directory'] as String,
|
||||
delete: json['delete'] as bool,
|
||||
deviceEncryptionKeyPassword:
|
||||
json['device_encryption_key_password'] as String,
|
||||
newDeviceEncryptionKeyPassword:
|
||||
json['new_device_encryption_key_password'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigProtectedStoreToJson(
|
||||
_$_VeilidConfigProtectedStore instance) =>
|
||||
<String, dynamic>{
|
||||
'allow_insecure_fallback': instance.allowInsecureFallback,
|
||||
'always_use_insecure_storage': instance.alwaysUseInsecureStorage,
|
||||
'directory': instance.directory,
|
||||
'delete': instance.delete,
|
||||
'device_encryption_key_password': instance.deviceEncryptionKeyPassword,
|
||||
'new_device_encryption_key_password':
|
||||
instance.newDeviceEncryptionKeyPassword,
|
||||
};
|
||||
|
||||
_$_VeilidConfigCapabilities _$$_VeilidConfigCapabilitiesFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_VeilidConfigCapabilities(
|
||||
disable:
|
||||
(json['disable'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigCapabilitiesToJson(
|
||||
_$_VeilidConfigCapabilities instance) =>
|
||||
<String, dynamic>{
|
||||
'disable': instance.disable,
|
||||
};
|
||||
|
||||
_$_VeilidConfig _$$_VeilidConfigFromJson(Map<String, dynamic> json) =>
|
||||
_$_VeilidConfig(
|
||||
programName: json['program_name'] as String,
|
||||
namespace: json['namespace'] as String,
|
||||
capabilities: VeilidConfigCapabilities.fromJson(
|
||||
json['capabilities'] as Map<String, dynamic>),
|
||||
protectedStore: VeilidConfigProtectedStore.fromJson(
|
||||
json['protected_store'] as Map<String, dynamic>),
|
||||
tableStore: VeilidConfigTableStore.fromJson(
|
||||
json['table_store'] as Map<String, dynamic>),
|
||||
blockStore: VeilidConfigBlockStore.fromJson(
|
||||
json['block_store'] as Map<String, dynamic>),
|
||||
network:
|
||||
VeilidConfigNetwork.fromJson(json['network'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_VeilidConfigToJson(_$_VeilidConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'program_name': instance.programName,
|
||||
'namespace': instance.namespace,
|
||||
'capabilities': instance.capabilities.toJson(),
|
||||
'protected_store': instance.protectedStore.toJson(),
|
||||
'table_store': instance.tableStore.toJson(),
|
||||
'block_store': instance.blockStore.toJson(),
|
||||
'network': instance.network.toJson(),
|
||||
};
|
||||
@@ -2,6 +2,8 @@ import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:charcode/charcode.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'veilid_encoding.dart';
|
||||
import 'veilid.dart';
|
||||
@@ -33,92 +35,96 @@ CryptoKind cryptoKindFromString(String s) {
|
||||
//////////////////////////////////////
|
||||
/// Types
|
||||
|
||||
class Typed<V extends EncodedString> {
|
||||
late CryptoKind kind;
|
||||
late V value;
|
||||
Typed({required this.kind, required this.value});
|
||||
@immutable
|
||||
class Typed<V extends EncodedString> extends Equatable {
|
||||
final CryptoKind kind;
|
||||
final V value;
|
||||
@override
|
||||
List<Object> get props => [kind, value];
|
||||
|
||||
const Typed({required this.kind, required this.value});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "${cryptoKindToString(kind)}:$value";
|
||||
}
|
||||
|
||||
Typed.fromString(String s) {
|
||||
var parts = s.split(":");
|
||||
factory Typed.fromString(String s) {
|
||||
final parts = s.split(":");
|
||||
if (parts.length < 2 || parts[0].codeUnits.length != 4) {
|
||||
throw const FormatException("malformed string");
|
||||
}
|
||||
kind = parts[0].codeUnits[0] |
|
||||
parts[0].codeUnits[1] << 8 |
|
||||
parts[0].codeUnits[2] << 16 |
|
||||
parts[0].codeUnits[3] << 24;
|
||||
value = EncodedString.fromString<V>(parts.sublist(1).join(":"));
|
||||
final kind = cryptoKindFromString(parts[0]);
|
||||
final value = EncodedString.fromString<V>(parts.sublist(1).join(":"));
|
||||
return Typed(kind: kind, value: value);
|
||||
}
|
||||
|
||||
String toJson() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
Typed.fromJson(dynamic json) : this.fromString(json as String);
|
||||
String toJson() => toString();
|
||||
factory Typed.fromJson(dynamic json) => Typed.fromString(json as String);
|
||||
}
|
||||
|
||||
class KeyPair {
|
||||
late PublicKey key;
|
||||
late PublicKey secret;
|
||||
KeyPair({required this.key, required this.secret});
|
||||
@immutable
|
||||
class KeyPair extends Equatable {
|
||||
final PublicKey key;
|
||||
final PublicKey secret;
|
||||
@override
|
||||
List<Object> get props => [key, secret];
|
||||
|
||||
const KeyPair({required this.key, required this.secret});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "${key.toString()}:${secret.toString()}";
|
||||
}
|
||||
|
||||
KeyPair.fromString(String s) {
|
||||
var parts = s.split(":");
|
||||
factory KeyPair.fromString(String s) {
|
||||
final parts = s.split(":");
|
||||
if (parts.length != 2 ||
|
||||
parts[0].codeUnits.length != 43 ||
|
||||
parts[1].codeUnits.length != 43) {
|
||||
throw const FormatException("malformed string");
|
||||
}
|
||||
key = PublicKey(parts[0]);
|
||||
secret = PublicKey(parts[1]);
|
||||
final key = PublicKey.fromString(parts[0]);
|
||||
final secret = PublicKey.fromString(parts[1]);
|
||||
return KeyPair(key: key, secret: secret);
|
||||
}
|
||||
|
||||
String toJson() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
KeyPair.fromJson(dynamic json) : this.fromString(json as String);
|
||||
String toJson() => toString();
|
||||
factory KeyPair.fromJson(dynamic json) => KeyPair.fromString(json as String);
|
||||
}
|
||||
|
||||
class TypedKeyPair {
|
||||
late CryptoKind kind;
|
||||
late PublicKey key;
|
||||
late PublicKey secret;
|
||||
TypedKeyPair({required this.kind, required this.key, required this.secret});
|
||||
@immutable
|
||||
class TypedKeyPair extends Equatable {
|
||||
final CryptoKind kind;
|
||||
final PublicKey key;
|
||||
final PublicKey secret;
|
||||
@override
|
||||
List<Object> get props => [kind, key, secret];
|
||||
|
||||
const TypedKeyPair(
|
||||
{required this.kind, required this.key, required this.secret});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "${cryptoKindToString(kind)}:${key.toString()}:${secret.toString()}";
|
||||
}
|
||||
String toString() =>
|
||||
"${cryptoKindToString(kind)}:${key.toString()}:${secret.toString()}";
|
||||
|
||||
TypedKeyPair.fromString(String s) {
|
||||
var parts = s.split(":");
|
||||
factory TypedKeyPair.fromString(String s) {
|
||||
final parts = s.split(":");
|
||||
if (parts.length != 3 ||
|
||||
parts[0].codeUnits.length != 4 ||
|
||||
parts[1].codeUnits.length != 43 ||
|
||||
parts[2].codeUnits.length != 43) {
|
||||
throw VeilidAPIExceptionInvalidArgument("malformed string", "s", s);
|
||||
}
|
||||
kind = cryptoKindFromString(parts[0]);
|
||||
key = PublicKey(parts[1]);
|
||||
secret = PublicKey(parts[2]);
|
||||
final kind = cryptoKindFromString(parts[0]);
|
||||
final key = PublicKey.fromString(parts[1]);
|
||||
final secret = PublicKey.fromString(parts[2]);
|
||||
return TypedKeyPair(kind: kind, key: key, secret: secret);
|
||||
}
|
||||
|
||||
String toJson() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
TypedKeyPair.fromJson(dynamic json) : this.fromString(json as String);
|
||||
String toJson() => toString();
|
||||
factory TypedKeyPair.fromJson(dynamic json) =>
|
||||
TypedKeyPair.fromString(json as String);
|
||||
}
|
||||
|
||||
typedef CryptoKey = FixedEncodedString43;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
String base64UrlNoPadEncode(List<int> bytes) {
|
||||
var x = base64Url.encode(bytes);
|
||||
while (x.endsWith('=')) {
|
||||
@@ -20,97 +23,91 @@ Uint8List base64UrlNoPadDecodeDynamic(dynamic source) {
|
||||
return base64.decode(source);
|
||||
}
|
||||
|
||||
abstract class EncodedString {
|
||||
late String contents;
|
||||
EncodedString(String s) {
|
||||
validate(s);
|
||||
contents = s;
|
||||
}
|
||||
EncodedString.encode(List<int> b) {
|
||||
var s = base64UrlNoPadEncode(b);
|
||||
validate(s);
|
||||
contents = s;
|
||||
}
|
||||
@immutable
|
||||
abstract class EncodedString extends Equatable {
|
||||
final String contents;
|
||||
@override
|
||||
List<Object> get props => [contents];
|
||||
|
||||
int encodedLength();
|
||||
int decodedLength();
|
||||
void validate(String s) {
|
||||
var d = base64UrlNoPadDecode(s);
|
||||
if (d.length != decodedLength()) {
|
||||
throw Exception("length ${s.length} should be ${encodedLength()}");
|
||||
}
|
||||
}
|
||||
const EncodedString(String s) : contents = s;
|
||||
|
||||
Uint8List decode() {
|
||||
return base64UrlNoPadDecode(contents);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return contents;
|
||||
}
|
||||
String toString() => contents;
|
||||
|
||||
static T fromString<T extends EncodedString>(String s) {
|
||||
switch (T) {
|
||||
case FixedEncodedString32:
|
||||
return FixedEncodedString32(s) as T;
|
||||
return FixedEncodedString32.fromString(s) as T;
|
||||
case FixedEncodedString43:
|
||||
return FixedEncodedString43(s) as T;
|
||||
return FixedEncodedString43.fromString(s) as T;
|
||||
case FixedEncodedString86:
|
||||
return FixedEncodedString86(s) as T;
|
||||
return FixedEncodedString86.fromString(s) as T;
|
||||
default:
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class FixedEncodedString32 extends EncodedString {
|
||||
FixedEncodedString32(String s) : super(s);
|
||||
@override
|
||||
int encodedLength() {
|
||||
const FixedEncodedString32._(String s) : super(s);
|
||||
static int encodedLength() {
|
||||
return 32;
|
||||
}
|
||||
|
||||
@override
|
||||
int decodedLength() {
|
||||
static int decodedLength() {
|
||||
return 24;
|
||||
}
|
||||
|
||||
String toJson() {
|
||||
return toString();
|
||||
factory FixedEncodedString32.fromString(String s) {
|
||||
var d = base64UrlNoPadDecode(s);
|
||||
if (d.length != decodedLength()) {
|
||||
throw Exception("length ${s.length} should be ${encodedLength()}");
|
||||
}
|
||||
return FixedEncodedString32._(s);
|
||||
}
|
||||
|
||||
FixedEncodedString32.fromJson(dynamic json) : this(json as String);
|
||||
String toJson() => toString();
|
||||
factory FixedEncodedString32.fromJson(dynamic json) =>
|
||||
FixedEncodedString32.fromString(json as String);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class FixedEncodedString43 extends EncodedString {
|
||||
FixedEncodedString43(String s) : super(s);
|
||||
@override
|
||||
int encodedLength() {
|
||||
const FixedEncodedString43._(String s) : super(s);
|
||||
static int encodedLength() {
|
||||
return 43;
|
||||
}
|
||||
|
||||
@override
|
||||
int decodedLength() {
|
||||
static int decodedLength() {
|
||||
return 32;
|
||||
}
|
||||
|
||||
String toJson() {
|
||||
return toString();
|
||||
factory FixedEncodedString43.fromString(String s) {
|
||||
var d = base64UrlNoPadDecode(s);
|
||||
if (d.length != decodedLength()) {
|
||||
throw Exception("length ${s.length} should be ${encodedLength()}");
|
||||
}
|
||||
return FixedEncodedString43._(s);
|
||||
}
|
||||
|
||||
FixedEncodedString43.fromJson(dynamic json) : this(json as String);
|
||||
String toJson() => toString();
|
||||
factory FixedEncodedString43.fromJson(dynamic json) =>
|
||||
FixedEncodedString43.fromString(json as String);
|
||||
}
|
||||
|
||||
@immutable
|
||||
class FixedEncodedString86 extends EncodedString {
|
||||
FixedEncodedString86(String s) : super(s);
|
||||
@override
|
||||
int encodedLength() {
|
||||
const FixedEncodedString86._(String s) : super(s);
|
||||
static int encodedLength() {
|
||||
return 86;
|
||||
}
|
||||
|
||||
@override
|
||||
int decodedLength() {
|
||||
static int decodedLength() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@@ -118,5 +115,14 @@ class FixedEncodedString86 extends EncodedString {
|
||||
return toString();
|
||||
}
|
||||
|
||||
FixedEncodedString86.fromJson(dynamic json) : this(json as String);
|
||||
factory FixedEncodedString86.fromString(String s) {
|
||||
var d = base64UrlNoPadDecode(s);
|
||||
if (d.length != decodedLength()) {
|
||||
throw Exception("length ${s.length} should be ${encodedLength()}");
|
||||
}
|
||||
return FixedEncodedString86._(s);
|
||||
}
|
||||
|
||||
factory FixedEncodedString86.fromJson(dynamic json) =>
|
||||
FixedEncodedString86.fromString(json as String);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:change_case/change_case.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'veilid_encoding.dart';
|
||||
import 'veilid.dart';
|
||||
|
||||
part 'veilid_state.freezed.dart';
|
||||
part 'veilid_state.g.dart';
|
||||
|
||||
//////////////////////////////////////
|
||||
/// AttachmentState
|
||||
|
||||
@@ -18,13 +22,9 @@ enum AttachmentState {
|
||||
overAttached,
|
||||
detaching;
|
||||
|
||||
String toJson() {
|
||||
return name.toPascalCase();
|
||||
}
|
||||
|
||||
factory AttachmentState.fromJson(String j) {
|
||||
return AttachmentState.values.byName(j.toCamelCase());
|
||||
}
|
||||
String toJson() => name.toPascalCase();
|
||||
factory AttachmentState.fromJson(String j) =>
|
||||
AttachmentState.values.byName(j.toCamelCase());
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@@ -37,208 +37,99 @@ enum VeilidLogLevel {
|
||||
debug,
|
||||
trace;
|
||||
|
||||
String toJson() {
|
||||
return name.toPascalCase();
|
||||
}
|
||||
|
||||
factory VeilidLogLevel.fromJson(String j) {
|
||||
return VeilidLogLevel.values.byName(j.toCamelCase());
|
||||
}
|
||||
String toJson() => name.toPascalCase();
|
||||
factory VeilidLogLevel.fromJson(String j) =>
|
||||
VeilidLogLevel.values.byName(j.toCamelCase());
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class LatencyStats {
|
||||
TimestampDuration fastest;
|
||||
TimestampDuration average;
|
||||
TimestampDuration slowest;
|
||||
@freezed
|
||||
class LatencyStats with _$LatencyStats {
|
||||
const factory LatencyStats({
|
||||
required TimestampDuration fastest,
|
||||
required TimestampDuration average,
|
||||
required TimestampDuration slowest,
|
||||
}) = _LatencyStats;
|
||||
|
||||
LatencyStats({
|
||||
required this.fastest,
|
||||
required this.average,
|
||||
required this.slowest,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'fastest': fastest.toJson(),
|
||||
'average': average.toJson(),
|
||||
'slowest': slowest.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
LatencyStats.fromJson(dynamic json)
|
||||
: fastest = TimestampDuration.fromJson(json['fastest']),
|
||||
average = TimestampDuration.fromJson(json['average']),
|
||||
slowest = TimestampDuration.fromJson(json['slowest']);
|
||||
factory LatencyStats.fromJson(Map<String, Object?> json) =>
|
||||
_$LatencyStatsFromJson(json);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class TransferStats {
|
||||
BigInt total;
|
||||
BigInt maximum;
|
||||
BigInt average;
|
||||
BigInt minimum;
|
||||
@freezed
|
||||
class TransferStats with _$TransferStats {
|
||||
const factory TransferStats({
|
||||
required BigInt total,
|
||||
required BigInt maximum,
|
||||
required BigInt average,
|
||||
required BigInt minimum,
|
||||
}) = _TransferStats;
|
||||
|
||||
TransferStats({
|
||||
required this.total,
|
||||
required this.maximum,
|
||||
required this.average,
|
||||
required this.minimum,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'total': total.toString(),
|
||||
'maximum': maximum.toString(),
|
||||
'average': average.toString(),
|
||||
'minimum': minimum.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
TransferStats.fromJson(dynamic json)
|
||||
: total = BigInt.parse(json['total']),
|
||||
maximum = BigInt.parse(json['maximum']),
|
||||
average = BigInt.parse(json['average']),
|
||||
minimum = BigInt.parse(json['minimum']);
|
||||
factory TransferStats.fromJson(Map<String, Object?> json) =>
|
||||
_$TransferStatsFromJson(json);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class TransferStatsDownUp {
|
||||
TransferStats down;
|
||||
TransferStats up;
|
||||
@freezed
|
||||
class TransferStatsDownUp with _$TransferStatsDownUp {
|
||||
const factory TransferStatsDownUp({
|
||||
required TransferStats down,
|
||||
required TransferStats up,
|
||||
}) = _TransferStatsDownUp;
|
||||
|
||||
TransferStatsDownUp({
|
||||
required this.down,
|
||||
required this.up,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'down': down.toJson(),
|
||||
'up': up.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
TransferStatsDownUp.fromJson(dynamic json)
|
||||
: down = TransferStats.fromJson(json['down']),
|
||||
up = TransferStats.fromJson(json['up']);
|
||||
factory TransferStatsDownUp.fromJson(Map<String, Object?> json) =>
|
||||
_$TransferStatsDownUpFromJson(json);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class RPCStats {
|
||||
int messagesSent;
|
||||
int messagesRcvd;
|
||||
int questionsInFlight;
|
||||
Timestamp? lastQuestion;
|
||||
Timestamp? lastSeenTs;
|
||||
Timestamp? firstConsecutiveSeenTs;
|
||||
int recentLostAnswers;
|
||||
int failedToSend;
|
||||
@freezed
|
||||
class RPCStats with _$RPCStats {
|
||||
const factory RPCStats({
|
||||
required int messagesSent,
|
||||
required int messagesRcvd,
|
||||
required int questionsInFlight,
|
||||
required Timestamp? lastQuestion,
|
||||
required Timestamp? lastSeenTs,
|
||||
required Timestamp? firstConsecutiveSeenTs,
|
||||
required int recentLostAnswers,
|
||||
required int failedToSend,
|
||||
}) = _RPCStats;
|
||||
|
||||
RPCStats({
|
||||
required this.messagesSent,
|
||||
required this.messagesRcvd,
|
||||
required this.questionsInFlight,
|
||||
required this.lastQuestion,
|
||||
required this.lastSeenTs,
|
||||
required this.firstConsecutiveSeenTs,
|
||||
required this.recentLostAnswers,
|
||||
required this.failedToSend,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'messages_sent': messagesSent,
|
||||
'messages_rcvd': messagesRcvd,
|
||||
'questions_in_flight': questionsInFlight,
|
||||
'last_question': lastQuestion?.toJson(),
|
||||
'last_seen_ts': lastSeenTs?.toJson(),
|
||||
'first_consecutive_seen_ts': firstConsecutiveSeenTs?.toJson(),
|
||||
'recent_lost_answers': recentLostAnswers,
|
||||
'failed_to_send': failedToSend,
|
||||
};
|
||||
}
|
||||
|
||||
RPCStats.fromJson(dynamic json)
|
||||
: messagesSent = json['messages_sent'],
|
||||
messagesRcvd = json['messages_rcvd'],
|
||||
questionsInFlight = json['questions_in_flight'],
|
||||
lastQuestion = json['last_question'] != null
|
||||
? Timestamp.fromJson(json['last_question'])
|
||||
: null,
|
||||
lastSeenTs = json['last_seen_ts'] != null
|
||||
? Timestamp.fromJson(json['last_seen_ts'])
|
||||
: null,
|
||||
firstConsecutiveSeenTs = json['first_consecutive_seen_ts'] != null
|
||||
? Timestamp.fromJson(json['first_consecutive_seen_ts'])
|
||||
: null,
|
||||
recentLostAnswers = json['recent_lost_answers'],
|
||||
failedToSend = json['failed_to_send'];
|
||||
factory RPCStats.fromJson(Map<String, Object?> json) =>
|
||||
_$RPCStatsFromJson(json);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class PeerStats {
|
||||
Timestamp timeAdded;
|
||||
RPCStats rpcStats;
|
||||
LatencyStats? latency;
|
||||
TransferStatsDownUp transfer;
|
||||
@freezed
|
||||
class PeerStats with _$PeerStats {
|
||||
const factory PeerStats({
|
||||
required Timestamp timeAdded,
|
||||
required RPCStats rpcStats,
|
||||
LatencyStats? latency,
|
||||
required TransferStatsDownUp transfer,
|
||||
}) = _PeerStats;
|
||||
|
||||
PeerStats({
|
||||
required this.timeAdded,
|
||||
required this.rpcStats,
|
||||
required this.latency,
|
||||
required this.transfer,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'time_added': timeAdded.toJson(),
|
||||
'rpc_stats': rpcStats.toJson(),
|
||||
'latency': latency?.toJson(),
|
||||
'transfer': transfer.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
PeerStats.fromJson(dynamic json)
|
||||
: timeAdded = Timestamp.fromJson(json['time_added']),
|
||||
rpcStats = RPCStats.fromJson(json['rpc_stats']),
|
||||
latency = json['latency'] != null
|
||||
? LatencyStats.fromJson(json['latency'])
|
||||
: null,
|
||||
transfer = TransferStatsDownUp.fromJson(json['transfer']);
|
||||
factory PeerStats.fromJson(Map<String, Object?> json) =>
|
||||
_$PeerStatsFromJson(json);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class PeerTableData {
|
||||
List<TypedKey> nodeIds;
|
||||
String peerAddress;
|
||||
PeerStats peerStats;
|
||||
@freezed
|
||||
class PeerTableData with _$PeerTableData {
|
||||
const factory PeerTableData({
|
||||
required List<TypedKey> nodeIds,
|
||||
required String peerAddress,
|
||||
required PeerStats peerStats,
|
||||
}) = _PeerTableData;
|
||||
|
||||
PeerTableData({
|
||||
required this.nodeIds,
|
||||
required this.peerAddress,
|
||||
required this.peerStats,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'node_ids': nodeIds.map((p) => p.toJson()).toList(),
|
||||
'peer_address': peerAddress,
|
||||
'peer_stats': peerStats.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
PeerTableData.fromJson(dynamic json)
|
||||
: nodeIds = List<TypedKey>.from(
|
||||
json['node_ids'].map((j) => TypedKey.fromJson(j))),
|
||||
peerAddress = json['peer_address'],
|
||||
peerStats = PeerStats.fromJson(json['peer_stats']);
|
||||
factory PeerTableData.fromJson(Map<String, Object?> json) =>
|
||||
_$PeerTableDataFromJson(json);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,114 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'veilid_state.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$_LatencyStats _$$_LatencyStatsFromJson(Map<String, dynamic> json) =>
|
||||
_$_LatencyStats(
|
||||
fastest: TimestampDuration.fromJson(json['fastest']),
|
||||
average: TimestampDuration.fromJson(json['average']),
|
||||
slowest: TimestampDuration.fromJson(json['slowest']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_LatencyStatsToJson(_$_LatencyStats instance) =>
|
||||
<String, dynamic>{
|
||||
'fastest': instance.fastest.toJson(),
|
||||
'average': instance.average.toJson(),
|
||||
'slowest': instance.slowest.toJson(),
|
||||
};
|
||||
|
||||
_$_TransferStats _$$_TransferStatsFromJson(Map<String, dynamic> json) =>
|
||||
_$_TransferStats(
|
||||
total: BigInt.parse(json['total'] as String),
|
||||
maximum: BigInt.parse(json['maximum'] as String),
|
||||
average: BigInt.parse(json['average'] as String),
|
||||
minimum: BigInt.parse(json['minimum'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_TransferStatsToJson(_$_TransferStats instance) =>
|
||||
<String, dynamic>{
|
||||
'total': instance.total.toString(),
|
||||
'maximum': instance.maximum.toString(),
|
||||
'average': instance.average.toString(),
|
||||
'minimum': instance.minimum.toString(),
|
||||
};
|
||||
|
||||
_$_TransferStatsDownUp _$$_TransferStatsDownUpFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$_TransferStatsDownUp(
|
||||
down: TransferStats.fromJson(json['down'] as Map<String, dynamic>),
|
||||
up: TransferStats.fromJson(json['up'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_TransferStatsDownUpToJson(
|
||||
_$_TransferStatsDownUp instance) =>
|
||||
<String, dynamic>{
|
||||
'down': instance.down.toJson(),
|
||||
'up': instance.up.toJson(),
|
||||
};
|
||||
|
||||
_$_RPCStats _$$_RPCStatsFromJson(Map<String, dynamic> json) => _$_RPCStats(
|
||||
messagesSent: json['messages_sent'] as int,
|
||||
messagesRcvd: json['messages_rcvd'] as int,
|
||||
questionsInFlight: json['questions_in_flight'] as int,
|
||||
lastQuestion: json['last_question'] == null
|
||||
? null
|
||||
: Timestamp.fromJson(json['last_question']),
|
||||
lastSeenTs: json['last_seen_ts'] == null
|
||||
? null
|
||||
: Timestamp.fromJson(json['last_seen_ts']),
|
||||
firstConsecutiveSeenTs: json['first_consecutive_seen_ts'] == null
|
||||
? null
|
||||
: Timestamp.fromJson(json['first_consecutive_seen_ts']),
|
||||
recentLostAnswers: json['recent_lost_answers'] as int,
|
||||
failedToSend: json['failed_to_send'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_RPCStatsToJson(_$_RPCStats instance) =>
|
||||
<String, dynamic>{
|
||||
'messages_sent': instance.messagesSent,
|
||||
'messages_rcvd': instance.messagesRcvd,
|
||||
'questions_in_flight': instance.questionsInFlight,
|
||||
'last_question': instance.lastQuestion?.toJson(),
|
||||
'last_seen_ts': instance.lastSeenTs?.toJson(),
|
||||
'first_consecutive_seen_ts': instance.firstConsecutiveSeenTs?.toJson(),
|
||||
'recent_lost_answers': instance.recentLostAnswers,
|
||||
'failed_to_send': instance.failedToSend,
|
||||
};
|
||||
|
||||
_$_PeerStats _$$_PeerStatsFromJson(Map<String, dynamic> json) => _$_PeerStats(
|
||||
timeAdded: Timestamp.fromJson(json['time_added']),
|
||||
rpcStats: RPCStats.fromJson(json['rpc_stats'] as Map<String, dynamic>),
|
||||
latency: json['latency'] == null
|
||||
? null
|
||||
: LatencyStats.fromJson(json['latency'] as Map<String, dynamic>),
|
||||
transfer: TransferStatsDownUp.fromJson(
|
||||
json['transfer'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_PeerStatsToJson(_$_PeerStats instance) =>
|
||||
<String, dynamic>{
|
||||
'time_added': instance.timeAdded.toJson(),
|
||||
'rpc_stats': instance.rpcStats.toJson(),
|
||||
'latency': instance.latency?.toJson(),
|
||||
'transfer': instance.transfer.toJson(),
|
||||
};
|
||||
|
||||
_$_PeerTableData _$$_PeerTableDataFromJson(Map<String, dynamic> json) =>
|
||||
_$_PeerTableData(
|
||||
nodeIds: (json['node_ids'] as List<dynamic>)
|
||||
.map(Typed<FixedEncodedString43>.fromJson)
|
||||
.toList(),
|
||||
peerAddress: json['peer_address'] as String,
|
||||
peerStats: PeerStats.fromJson(json['peer_stats'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$_PeerTableDataToJson(_$_PeerTableData instance) =>
|
||||
<String, dynamic>{
|
||||
'node_ids': instance.nodeIds.map((e) => e.toJson()).toList(),
|
||||
'peer_address': instance.peerAddress,
|
||||
'peer_stats': instance.peerStats.toJson(),
|
||||
};
|
||||
Reference in New Issue
Block a user