CH-J SM MobileSerververwaltung über SSH
Menü
Veröffentlichte Quellen

CH-J SM Mobile

Durchsuchen Sie Verzeichnisse und Dateien einer bestimmten Anwendungsausgabe.

Quellen als ZIP herunterladen
CH-J / SM Mobile 175 Dateien
sm-mobile-20261016T185235Z-8e93ecc1b59a Hinzugefügt: · Erstellt:
diagnostics.dart Hinzugefügt: Datum nicht erfasst 2,2 KB · 77 Zeilen
Code Datei herunterladen
1import 'dart:async';
2import 'dart:io';
3import '../models/server_profile.dart';
5class 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});
14/// A probe that failed in a known stage, so the UI can say which test failed.
15class 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 @override
27 String toString() => 'ProbeFailure($stage, $cause)';
30class 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 }
SHA-256acda431a087d8f7930f10c5bbb942f716f45f500ab851fe198123c4adaced02a

CH-J Proprietary Software License 1.14 · Die Quellen werden unter der CH-J Proprietary Software License 1.14 bereitgestellt. Ihre Verfügbarkeit ändert die Lizenzbedingungen nicht und gewährt keine zusätzlichen Rechte.

SHA-256 des Archivs46e427a43e87af091004f36145590bda8fe90086dfb0f631afeb5029fb0b5655
Dateien