veilid-cli cleanup
This commit is contained in:
@@ -987,6 +987,243 @@ class VeilidConfig {
|
||||
network = VeilidConfigNetwork.fromJson(json['network']);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class LatencyStats {
|
||||
BigInt fastest;
|
||||
BigInt average;
|
||||
BigInt slowest;
|
||||
|
||||
LatencyStats({
|
||||
required this.fastest,
|
||||
required this.average,
|
||||
required this.slowest,
|
||||
});
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'fastest': fastest.toString(),
|
||||
'average': average.toString(),
|
||||
'slowest': slowest.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
LatencyStats.fromJson(Map<String, dynamic> json)
|
||||
: fastest = BigInt.parse(json['fastest']),
|
||||
average = BigInt.parse(json['average']),
|
||||
slowest = BigInt.parse(json['slowest']);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class TransferStats {
|
||||
BigInt total;
|
||||
BigInt fastest;
|
||||
BigInt average;
|
||||
BigInt slowest;
|
||||
|
||||
TransferStats({
|
||||
required this.total,
|
||||
required this.fastest,
|
||||
required this.average,
|
||||
required this.slowest,
|
||||
});
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'total': total.toString(),
|
||||
'fastest': fastest.toString(),
|
||||
'average': average.toString(),
|
||||
'slowest': slowest.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
TransferStats.fromJson(Map<String, dynamic> json)
|
||||
: total = BigInt.parse(json['fastest']),
|
||||
fastest = BigInt.parse(json['fastest']),
|
||||
average = BigInt.parse(json['average']),
|
||||
slowest = BigInt.parse(json['slowest']);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class TransferStatsDownUp {
|
||||
TransferStats down;
|
||||
TransferStats up;
|
||||
|
||||
TransferStatsDownUp({
|
||||
required this.down,
|
||||
required this.up,
|
||||
});
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'down': down.toString(),
|
||||
'up': up.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
TransferStatsDownUp.fromJson(Map<String, dynamic> json)
|
||||
: down = TransferStats.fromJson(json['down']),
|
||||
up = TransferStats.fromJson(json['up']);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class RPCStats {
|
||||
int messagesSent;
|
||||
int messagesRcvd;
|
||||
int questionsInFlight;
|
||||
BigInt? lastQuestion;
|
||||
BigInt? lastSeenTs;
|
||||
BigInt? firstConsecutiveSeenTs;
|
||||
int recentLostAnswers;
|
||||
int failedToSend;
|
||||
|
||||
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> get json {
|
||||
return {
|
||||
'messages_sent': messagesSent,
|
||||
'messages_rcvd': messagesRcvd,
|
||||
'questions_in_flight': questionsInFlight,
|
||||
'last_question': lastQuestion?.toString(),
|
||||
'last_seen_ts': lastSeenTs?.toString(),
|
||||
'first_consecutive_seen_ts': firstConsecutiveSeenTs?.toString(),
|
||||
'recent_lost_answers': recentLostAnswers,
|
||||
'failed_to_send': failedToSend,
|
||||
};
|
||||
}
|
||||
|
||||
RPCStats.fromJson(Map<String, dynamic> json)
|
||||
: messagesSent = json['messages_sent'],
|
||||
messagesRcvd = json['messages_rcvd'],
|
||||
questionsInFlight = json['questions_in_flight'],
|
||||
lastQuestion = json['last_question'] != null
|
||||
? BigInt.parse(json['last_question'])
|
||||
: null,
|
||||
lastSeenTs = json['last_seen_ts'] != null
|
||||
? BigInt.parse(json['last_seen_ts'])
|
||||
: null,
|
||||
firstConsecutiveSeenTs = json['first_consecutive_seen_ts'] != null
|
||||
? BigInt.parse(json['first_consecutive_seen_ts'])
|
||||
: null,
|
||||
recentLostAnswers = json['recent_lost_answers'],
|
||||
failedToSend = json['failed_to_send'];
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class PeerStats {
|
||||
BigInt timeAdded;
|
||||
RPCStats rpcStats;
|
||||
LatencyStats? latency;
|
||||
TransferStatsDownUp transfer;
|
||||
|
||||
PeerStats({
|
||||
required this.timeAdded,
|
||||
required this.rpcStats,
|
||||
required this.latency,
|
||||
required this.transfer,
|
||||
});
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'time_added': timeAdded.toString(),
|
||||
'rpc_stats': rpcStats.json,
|
||||
'latency': latency?.json,
|
||||
'transfer': transfer.json,
|
||||
};
|
||||
}
|
||||
|
||||
PeerStats.fromJson(Map<String, dynamic> json)
|
||||
: timeAdded = BigInt.parse(json['time_added']),
|
||||
rpcStats = RPCStats.fromJson(json['rpc_stats']),
|
||||
latency = json['latency'] != null
|
||||
? LatencyStats.fromJson(json['latency'])
|
||||
: null,
|
||||
transfer = TransferStatsDownUp.fromJson(json['transfer']);
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class PeerTableData {
|
||||
String nodeId;
|
||||
PeerAddress peerAddress;
|
||||
PeerStats peerStats;
|
||||
|
||||
PeerTableData({
|
||||
required this.nodeId,
|
||||
required this.peerAddress,
|
||||
required this.peerStats,
|
||||
});
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'node_id': nodeId,
|
||||
'peer_address': peerAddress.json,
|
||||
'peer_stats': peerStats.json,
|
||||
};
|
||||
}
|
||||
|
||||
PeerTableData.fromJson(Map<String, dynamic> json)
|
||||
: nodeId = json['node_id'],
|
||||
peerAddress = PeerAddress.fromJson(json['peer_address']),
|
||||
peerStats = PeerStats.fromJson(json['peer_stats']);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// AttachmentState
|
||||
|
||||
enum ProtocolType {
|
||||
udp,
|
||||
tcp,
|
||||
ws,
|
||||
wss,
|
||||
}
|
||||
|
||||
extension ProtocolTypeExt on ProtocolType {
|
||||
String get json {
|
||||
return name.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
ProtocolType protocolTypeFromJson(String j) {
|
||||
return ProtocolType.values.byName(j.toLowerCase());
|
||||
}
|
||||
|
||||
////////////
|
||||
|
||||
class PeerAddress {
|
||||
ProtocolType protocolType;
|
||||
String socketAddress;
|
||||
|
||||
PeerAddress({
|
||||
required this.protocolType,
|
||||
required this.socketAddress,
|
||||
});
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'protocol_type': protocolType.json,
|
||||
'socket_address': socketAddress,
|
||||
};
|
||||
}
|
||||
|
||||
PeerAddress.fromJson(Map<String, dynamic> json)
|
||||
: protocolType = protocolTypeFromJson(json['protocol_type']),
|
||||
socketAddress = json['socket_address'];
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// VeilidUpdate
|
||||
|
||||
@@ -996,16 +1233,17 @@ abstract class VeilidUpdate {
|
||||
case "Log":
|
||||
{
|
||||
return VeilidUpdateLog(
|
||||
veilidLogLevelFromJson(json["log_level"]), json["message"]);
|
||||
logLevel: veilidLogLevelFromJson(json["log_level"]),
|
||||
message: json["message"]);
|
||||
}
|
||||
case "Attachment":
|
||||
{
|
||||
return VeilidUpdateAttachment(attachmentStateFromJson(json["state"]));
|
||||
return VeilidUpdateAttachment(
|
||||
state: VeilidStateAttachment.fromJson(json));
|
||||
}
|
||||
case "Network":
|
||||
{
|
||||
return VeilidUpdateNetwork(
|
||||
json["started"], json["bps_up"], json["bps_down"]);
|
||||
return VeilidUpdateNetwork(state: VeilidStateNetwork.fromJson(json));
|
||||
}
|
||||
default:
|
||||
{
|
||||
@@ -1021,7 +1259,10 @@ class VeilidUpdateLog implements VeilidUpdate {
|
||||
final VeilidLogLevel logLevel;
|
||||
final String message;
|
||||
//
|
||||
VeilidUpdateLog(this.logLevel, this.message);
|
||||
VeilidUpdateLog({
|
||||
required this.logLevel,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get json {
|
||||
@@ -1034,34 +1275,28 @@ class VeilidUpdateLog implements VeilidUpdate {
|
||||
}
|
||||
|
||||
class VeilidUpdateAttachment implements VeilidUpdate {
|
||||
final AttachmentState state;
|
||||
final VeilidStateAttachment state;
|
||||
//
|
||||
VeilidUpdateAttachment(this.state);
|
||||
VeilidUpdateAttachment({required this.state});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'kind': "Attachment",
|
||||
'state': state.json,
|
||||
};
|
||||
var jsonRep = state.json;
|
||||
jsonRep['kind'] = "Attachment";
|
||||
return jsonRep;
|
||||
}
|
||||
}
|
||||
|
||||
class VeilidUpdateNetwork implements VeilidUpdate {
|
||||
final bool started;
|
||||
final int bpsDown;
|
||||
final int bpsUp;
|
||||
final VeilidStateNetwork state;
|
||||
//
|
||||
VeilidUpdateNetwork(this.started, this.bpsDown, this.bpsUp);
|
||||
VeilidUpdateNetwork({required this.state});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'kind': "Network",
|
||||
'started': started,
|
||||
'bps_down': bpsDown,
|
||||
'bps_up': bpsUp
|
||||
};
|
||||
var jsonRep = state.json;
|
||||
jsonRep['kind'] = "Network";
|
||||
return jsonRep;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1075,6 +1310,12 @@ class VeilidStateAttachment {
|
||||
|
||||
VeilidStateAttachment.fromJson(Map<String, dynamic> json)
|
||||
: state = attachmentStateFromJson(json['state']);
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'state': state.json,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@@ -1082,11 +1323,30 @@ class VeilidStateAttachment {
|
||||
|
||||
class VeilidStateNetwork {
|
||||
final bool started;
|
||||
final int bpsDown;
|
||||
final int bpsUp;
|
||||
final List<PeerTableData> peers;
|
||||
|
||||
VeilidStateNetwork(this.started);
|
||||
VeilidStateNetwork(
|
||||
{required this.started,
|
||||
required this.bpsDown,
|
||||
required this.bpsUp,
|
||||
required this.peers});
|
||||
|
||||
VeilidStateNetwork.fromJson(Map<String, dynamic> json)
|
||||
: started = json['started'];
|
||||
: started = json['started'],
|
||||
bpsDown = json['bps_down'],
|
||||
bpsUp = json['bps_up'],
|
||||
peers = json['peers'].map((j) => PeerTableData.fromJson(j)).toList();
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'started': started,
|
||||
'bps_down': bpsDown,
|
||||
'bps_up': bpsUp,
|
||||
'peers': peers.map((p) => p.json).toList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@@ -1096,11 +1356,13 @@ class VeilidState {
|
||||
final VeilidStateAttachment attachment;
|
||||
final VeilidStateNetwork network;
|
||||
|
||||
VeilidState(this.attachment, this.network);
|
||||
|
||||
VeilidState.fromJson(Map<String, dynamic> json)
|
||||
: attachment = VeilidStateAttachment.fromJson(json['attachment']),
|
||||
network = VeilidStateNetwork.fromJson(json['network']);
|
||||
|
||||
Map<String, dynamic> get json {
|
||||
return {'attachment': attachment.json, 'network': network.json};
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user