From 7d30af44d6db1d229c89bb3f56ac41646a185782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Thu, 15 Jan 2026 10:10:21 +0800 Subject: [PATCH] fix --- lib/core/utils/server.dart | 43 +++++++++++------------ lib/view/page/server/edit/jump_chain.dart | 6 ++-- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/core/utils/server.dart b/lib/core/utils/server.dart index 1a4fbc98..8c149ee5 100644 --- a/lib/core/utils/server.dart +++ b/lib/core/utils/server.dart @@ -480,40 +480,34 @@ Future ensureKnownHostKey( Duration timeout = const Duration(seconds: 5), SSHUserInfoRequestHandler? onKeyboardInteractive, }) async { - return _ensureKnownHostKeyInternal( + var cache = _loadKnownHostFingerprints(); + + final hops = resolveMergedJumpChain(spi); + for (final hop in hops) { + cache = await _ensureKnownHostKeyForSingle( + hop, + cache: cache, + timeout: timeout, + onKeyboardInteractive: onKeyboardInteractive, + ); + } + + await _ensureKnownHostKeyForSingle( spi, + cache: cache, timeout: timeout, onKeyboardInteractive: onKeyboardInteractive, - visited: {}, ); } -Future _ensureKnownHostKeyInternal( +Future> _ensureKnownHostKeyForSingle( Spi spi, { + required Map cache, Duration timeout = const Duration(seconds: 5), SSHUserInfoRequestHandler? onKeyboardInteractive, - required Set visited, }) async { - final identifier = _hostIdentifier(spi); - if (!visited.add(identifier)) { - throw SSHErr(type: SSHErrType.connect, message: 'Jump loop detected at ${spi.name} ($identifier)'); - } - - final cache = _loadKnownHostFingerprints(); if (_hasKnownHostFingerprintForSpi(spi, cache)) { - return; - } - - final jumpSpi = spi.jumpId != null ? Stores.server.box.get(spi.jumpId) : null; - if (jumpSpi != null && !_hasKnownHostFingerprintForSpi(jumpSpi, cache)) { - await _ensureKnownHostKeyInternal( - jumpSpi, - timeout: timeout, - onKeyboardInteractive: onKeyboardInteractive, - visited: visited, - ); - cache.addAll(_loadKnownHostFingerprints()); - if (_hasKnownHostFingerprintForSpi(spi, cache)) return; + return cache; } final client = await genClient( @@ -528,6 +522,9 @@ Future _ensureKnownHostKeyInternal( } finally { client.close(); } + + cache.addAll(_loadKnownHostFingerprints()); + return cache; } bool _hasKnownHostFingerprintForSpi(Spi spi, Map cache) { diff --git a/lib/view/page/server/edit/jump_chain.dart b/lib/view/page/server/edit/jump_chain.dart index 3423c808..7cea42ae 100644 --- a/lib/view/page/server/edit/jump_chain.dart +++ b/lib/view/page/server/edit/jump_chain.dart @@ -35,16 +35,16 @@ extension _JumpChain on _ServerEditPageState { } bool containsCycleWithCandidate(String candidateId) { - final visited = {selfId}; final queue = [..._jumpChain.value, candidateId]; + final directVisited = {selfId}; for (final hopId in queue) { if (hopId == selfId) return true; - if (!visited.add(hopId)) return true; + if (!directVisited.add(hopId)) return true; } for (final hopId in queue) { - final extra = flattenHopIds(hopId, visited: visited); + final extra = flattenHopIds(hopId, visited: {selfId}); for (final id in extra) { if (id == selfId) return true; }