mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
new: jump serevr (#190)
This commit is contained in:
@@ -27,6 +27,10 @@ class ServerPrivateInfo {
|
||||
@HiveField(8)
|
||||
final bool? autoConnect;
|
||||
|
||||
/// [id] of the jump server
|
||||
@HiveField(9)
|
||||
final String? jumpId;
|
||||
|
||||
final String id;
|
||||
|
||||
const ServerPrivateInfo({
|
||||
@@ -39,9 +43,9 @@ class ServerPrivateInfo {
|
||||
this.tags,
|
||||
this.alterUrl,
|
||||
this.autoConnect,
|
||||
this.jumpId,
|
||||
}) : id = '$user@$ip:$port';
|
||||
|
||||
/// TODO: if any field is changed, remember to update [id] [name]
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json)
|
||||
: ip = json["ip"].toString(),
|
||||
port = json["port"] ?? 22,
|
||||
@@ -54,7 +58,8 @@ class ServerPrivateInfo {
|
||||
pubKeyId = json["pubKeyId"]?.toString(),
|
||||
tags = json["tags"]?.cast<String>(),
|
||||
alterUrl = json["alterUrl"]?.toString(),
|
||||
autoConnect = json["autoConnect"];
|
||||
autoConnect = json["autoConnect"],
|
||||
jumpId = json["jumpId"];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
@@ -67,16 +72,19 @@ class ServerPrivateInfo {
|
||||
data["tags"] = tags;
|
||||
data["alterUrl"] = alterUrl;
|
||||
data["autoConnect"] = autoConnect;
|
||||
data["jumpId"] = jumpId;
|
||||
return data;
|
||||
}
|
||||
|
||||
Server? get server => Pros.server.pick(spi: this);
|
||||
Server? get jumpServer => Pros.server.pick(id: jumpId);
|
||||
|
||||
bool shouldReconnect(ServerPrivateInfo old) {
|
||||
return id != old.id ||
|
||||
pwd != old.pwd ||
|
||||
pubKeyId != old.pubKeyId ||
|
||||
alterUrl != old.alterUrl;
|
||||
alterUrl != old.alterUrl ||
|
||||
jumpId != old.jumpId;
|
||||
}
|
||||
|
||||
_IpPort fromStringUrl() {
|
||||
|
||||
@@ -26,13 +26,14 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
tags: (fields[6] as List?)?.cast<String>(),
|
||||
alterUrl: fields[7] as String?,
|
||||
autoConnect: fields[8] as bool?,
|
||||
jumpId: fields[9] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerPrivateInfo obj) {
|
||||
writer
|
||||
..writeByte(9)
|
||||
..writeByte(10)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
@@ -50,7 +51,9 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
..writeByte(7)
|
||||
..write(obj.alterUrl)
|
||||
..writeByte(8)
|
||||
..write(obj.autoConnect);
|
||||
..write(obj.autoConnect)
|
||||
..writeByte(9)
|
||||
..write(obj.jumpId);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -117,7 +117,8 @@ class ServerProvider extends ChangeNotifier {
|
||||
await _getData(spi);
|
||||
return;
|
||||
}
|
||||
await Future.wait(_servers.values.map((s) async {
|
||||
|
||||
Future<void> connectFn(Server s) async {
|
||||
if (onlyFailed) {
|
||||
if (s.state != ServerState.failed) return;
|
||||
_limiter.reset(s.spi.id);
|
||||
@@ -133,7 +134,19 @@ class ServerProvider extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
return await _getData(s.spi);
|
||||
}));
|
||||
}
|
||||
|
||||
final directServers = <Server>[];
|
||||
final proxyServers = <Server>[];
|
||||
for (final s in _servers.values) {
|
||||
if (s.spi.jumpId == null) {
|
||||
directServers.add(s);
|
||||
} else {
|
||||
proxyServers.add(s);
|
||||
}
|
||||
}
|
||||
await Future.wait(directServers.map(connectFn));
|
||||
await Future.wait(proxyServers.map(connectFn));
|
||||
}
|
||||
|
||||
Future<void> startAutoRefresh() async {
|
||||
@@ -223,10 +236,6 @@ class ServerProvider extends ChangeNotifier {
|
||||
|
||||
// Only reconnect if neccessary
|
||||
if (newSpi.shouldReconnect(old)) {
|
||||
_servers[newSpi.id]?.client = await genClient(
|
||||
newSpi,
|
||||
timeout: Stores.setting.timeoutD,
|
||||
);
|
||||
refreshData(spi: newSpi);
|
||||
}
|
||||
|
||||
@@ -262,6 +271,7 @@ class ServerProvider extends ChangeNotifier {
|
||||
s.client = await genClient(
|
||||
spi,
|
||||
timeout: Stores.setting.timeoutD,
|
||||
jumpSpi: spi.jumpId == null ? null : Stores.server.box.get(spi.jumpId),
|
||||
);
|
||||
} catch (e) {
|
||||
_limiter.inc(sid);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 603;
|
||||
static const int build = 606;
|
||||
static const String engine = "3.13.7";
|
||||
static const String buildAt = "2023-10-18 20:37:38";
|
||||
static const int modifications = 7;
|
||||
static const String buildAt = "2023-10-21 19:26:34";
|
||||
static const int modifications = 4;
|
||||
static const int script = 22;
|
||||
}
|
||||
|
||||
@@ -39,5 +39,7 @@ class GithubIds {
|
||||
'fanzhebufan1',
|
||||
'wcbing',
|
||||
'balh55y',
|
||||
'wc7086',
|
||||
'michaelsara'
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user