Vydané zdroje
Stáhnout zdroje ZIP
CH-J SM Mobile
Procházejte adresáře a soubory konkrétního vydání aplikace.
CH-J / SM Mobile
175 souborů
sm-mobile-20261016T185235Z-8e93ecc1b59a
Přidáno: · Sestaveno:
1
import 'dart:async';2
import 'dart:io';3
import '../models/server_profile.dart';5
class ProbeResult {6
final List<String> addresses;7
final int tcpMs;8
// DNS lookup time and the address the TCP connection was made to.9
final int? dnsMs;10
final InternetAddress? connected;11
ProbeResult(this.addresses, this.tcpMs, {this.dnsMs, this.connected});12
}14
/// A probe that failed in a known stage, so the UI can say which test failed.15
class ProbeFailure implements Exception {16
final String stage; // 'dns' or 'tcp'17
final Object cause;18
final List<String> addresses;19
final int? dnsMs;20
const ProbeFailure(21
this.stage,22
this.cause, {23
this.addresses = const [],24
this.dnsMs,25
});26
@override27
String toString() => 'ProbeFailure($stage, $cause)';28
}30
class Diagnostics {31
Future<ProbeResult> probe(32
String host,33
int port, {34
InternetAddressType type = InternetAddressType.any,35
}) async {36
normalizeHost(host);37
final dnsWatch = Stopwatch()..start();38
final List<InternetAddress> addresses;39
try {40
addresses = await InternetAddress.lookup(41
host,42
type: type,43
).timeout(const Duration(seconds: 10));44
} catch (e) {45
throw ProbeFailure('dns', e);46
}47
final dnsMs = dnsWatch.elapsedMilliseconds;48
final names = addresses.map((a) => a.address).toList();49
final deadline = DateTime.now().add(const Duration(seconds: 10));50
Object lastError = const SocketException('No address for requested family');51
for (final address in addresses) {52
final remaining = deadline.difference(DateTime.now());53
if (remaining <= Duration.zero) {54
throw ProbeFailure(55
'tcp',56
TimeoutException('TCP'),57
addresses: names,58
dnsMs: dnsMs,59
);60
}61
final watch = Stopwatch()..start();62
try {63
final socket = await Socket.connect(address, port, timeout: remaining);64
socket.destroy();65
return ProbeResult(66
names,67
watch.elapsedMilliseconds,68
dnsMs: dnsMs,69
connected: address,70
);71
} catch (e) {72
lastError = e;73
}74
}75
throw ProbeFailure('tcp', lastError, addresses: names, dnsMs: dnsMs);76
}77
}SHA-256
acda431a087d8f7930f10c5bbb942f716f45f500ab851fe198123c4adaced02aCH-J Proprietary Software License 1.14 · Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.
SHA-256 archivu
46e427a43e87af091004f36145590bda8fe90086dfb0f631afeb5029fb0b5655