Solve ssh connect slow

This commit is contained in:
Junyuan Feng
2022-01-11 12:19:17 +08:00
parent 4d227c3f00
commit 340a7641e6
6 changed files with 52 additions and 10 deletions

View File

@@ -17,6 +17,7 @@ import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/model/server/server_status.dart';
import 'package:toolbox/data/model/server/snippet.dart';
import 'package:toolbox/data/model/server/tcp_status.dart';
import 'package:toolbox/data/store/private_key.dart';
import 'package:toolbox/data/store/server.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart';
@@ -24,8 +25,8 @@ import 'package:toolbox/locator.dart';
/// Must put this func out of any Class.
/// Because of this function is called by [compute] in [ServerProvider.genClient].
/// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure
List<SSHKeyPair> loadIndentity(Map<String, dynamic> auth) {
return SSHKeyPair.fromPem(auth['privateKey'], auth['passphrase']);
List<SSHKeyPair> loadIndentity(String key) {
return SSHKeyPair.fromPem(key);
}
class ServerProvider extends BusyProvider {
@@ -73,14 +74,14 @@ class ServerProvider extends BusyProvider {
Future<SSHClient> genClient(ServerPrivateInfo spi) async {
final socket = await SSHSocket.connect(spi.ip, spi.port);
if (spi.authorization is String) {
if (spi.pubKeyId == null) {
return SSHClient(socket,
username: spi.user,
onPasswordRequest: () => spi.authorization as String);
}
final auth = spi.authorization as Map<String, dynamic>;
final key = locator<PrivateKeyStore>().get(spi.pubKeyId!);
return SSHClient(socket,
username: spi.user, identities: await compute(loadIndentity, auth));
username: spi.user, identities: await compute(loadIndentity, key.privateKey));
}
Future<void> refreshData({int? idx}) async {

View File

@@ -3,7 +3,8 @@
class BuildData {
static const String name = "ToolBox";
static const int build = 79;
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (4 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const String engine =
"Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (4 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const String buildAt = "2022-01-10 16:04:12.547744";
static const int modifications = 0;
}

View File

@@ -15,6 +15,11 @@ class PrivateKeyStore extends PersistentStore {
json.decode(box.get('key', defaultValue: '[]')!));
}
PrivateKeyInfo get(String id) {
final ss = fetch();
return ss.firstWhere((e) => e.id == id);
}
void delete(PrivateKeyInfo s) {
final ss = fetch();
ss.removeAt(index(s));