2020-07-27 20:43:58 +00:00
|
|
|
import 'package:mobile_nebula/models/Certificate.dart';
|
|
|
|
|
|
|
|
class HostInfo {
|
|
|
|
String vpnIp;
|
|
|
|
int localIndex;
|
|
|
|
int remoteIndex;
|
|
|
|
List<UDPAddress> remoteAddresses;
|
|
|
|
int cachedPackets;
|
2022-09-21 20:27:35 +00:00
|
|
|
Certificate? cert;
|
|
|
|
UDPAddress? currentRemote;
|
2020-07-27 20:43:58 +00:00
|
|
|
int messageCounter;
|
|
|
|
|
2022-09-21 20:27:35 +00:00
|
|
|
HostInfo({
|
|
|
|
required this.vpnIp,
|
|
|
|
required this.localIndex,
|
|
|
|
required this.remoteIndex,
|
|
|
|
required this.remoteAddresses,
|
|
|
|
required this.cachedPackets,
|
|
|
|
required this.messageCounter,
|
|
|
|
this.cert,
|
|
|
|
this.currentRemote,
|
|
|
|
});
|
2020-07-27 20:43:58 +00:00
|
|
|
|
2022-09-21 20:27:35 +00:00
|
|
|
factory HostInfo.fromJson(Map<String, dynamic> json) {
|
|
|
|
UDPAddress? currentRemote;
|
2020-07-27 20:43:58 +00:00
|
|
|
if (json['currentRemote'] != null) {
|
|
|
|
currentRemote = UDPAddress.fromJson(json['currentRemote']);
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:27:35 +00:00
|
|
|
Certificate? cert;
|
2020-07-27 20:43:58 +00:00
|
|
|
if (json['cert'] != null) {
|
|
|
|
cert = Certificate.fromJson(json['cert']);
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:31:58 +00:00
|
|
|
List<dynamic>? addrs = json['remoteAddrs'];
|
2022-09-21 20:27:35 +00:00
|
|
|
List<UDPAddress> remoteAddresses = [];
|
2022-11-21 19:31:58 +00:00
|
|
|
addrs?.forEach((val) {
|
2020-07-27 20:43:58 +00:00
|
|
|
remoteAddresses.add(UDPAddress.fromJson(val));
|
|
|
|
});
|
|
|
|
|
2022-09-21 20:27:35 +00:00
|
|
|
return HostInfo(
|
|
|
|
vpnIp: json['vpnIp'],
|
|
|
|
localIndex: json['localIndex'],
|
|
|
|
remoteIndex: json['remoteIndex'],
|
|
|
|
remoteAddresses: remoteAddresses,
|
|
|
|
cachedPackets: json['cachedPackets'],
|
|
|
|
messageCounter: json['messageCounter'],
|
|
|
|
cert: cert,
|
|
|
|
currentRemote: currentRemote,
|
|
|
|
);
|
2020-07-27 20:43:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UDPAddress {
|
|
|
|
String ip;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
2021-04-23 21:23:06 +00:00
|
|
|
// Simple check on if nebula told us about a v4 or v6 ip address
|
|
|
|
if (ip.contains(':')) {
|
|
|
|
return '[$ip]:$port';
|
|
|
|
}
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
return '$ip:$port';
|
|
|
|
}
|
|
|
|
|
|
|
|
UDPAddress.fromJson(Map<String, dynamic> json)
|
2021-04-23 21:23:06 +00:00
|
|
|
: ip = json['ip'],
|
|
|
|
port = json['port'];
|
2020-07-27 20:43:58 +00:00
|
|
|
}
|