rdsh-gateway 0.11.2 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/direct.js CHANGED
@@ -29,6 +29,9 @@ export async function startDirect(opts) {
29
29
  actualPort,
30
30
  candidates: () => lanCandidates(actualPort),
31
31
  stop: async () => {
32
+ // 先强制断开所有连接(含 keep-alive):否则有活跃连接时 server.close() 的回调
33
+ // 永不触发,面板「断开」的 RPC 会一直挂住、按钮卡在 loading。
34
+ gateway.server.closeAllConnections();
32
35
  await new Promise((resolve) => gateway.server.close(() => resolve()));
33
36
  gateway.dispose();
34
37
  },
package/dist/index.d.ts CHANGED
@@ -23,13 +23,14 @@ export { loginPageHtml } from "./login-page.ts";
23
23
  export { installService, uninstallService, serviceStatus, startService, stopService, restartService, systemdUnit, launchdPlist, SERVICE_NAME, JOIN_SERVICE_NAME, HOST_SERVICE_NAME, HUB_SERVICE_NAME } from "./service.ts";
24
24
  export type { ServiceSpec } from "./service.ts";
25
25
  export declare const NAME = "rdsh-gateway";
26
- export { join, startJoin, registerJoin, detectInsecure, selfRevoke, patchLoopbackJs } from "./join.ts";
26
+ export { join, startJoin, registerJoin, detectInsecure, selfRevoke, patchLoopbackJs, hubRequest } from "./join.ts";
27
27
  export type { JoinOptions, RegisterOutcome, JoinState, JoinHooks, StartJoinOptions, JoinHandle } from "./join.ts";
28
28
  export { startDirect, lanCandidates, isPrivateIpv4 } from "./direct.ts";
29
29
  export type { DirectOptions, DirectHandle } from "./direct.ts";
30
30
  export { createDirectTicketManager } from "./direct-ticket.ts";
31
31
  export type { DirectTicketManager } from "./direct-ticket.ts";
32
32
  export { loadOrCreateDirectSecret, directSecretPath } from "./direct-secret.ts";
33
- export { readPersistedToken, clearPersistedToken } from "./token-store.ts";
33
+ export { readPersistedToken, persistToken, clearPersistedToken } from "./token-store.ts";
34
34
  export { acquireJoinLock, releaseJoinLock, readJoinLock, JOIN_LOCK_PATH } from "./lock.ts";
35
35
  export type { JoinLock, JoinLockRole } from "./lock.ts";
36
+ export { loadOrCreateE2eeKeyPair, e2eeKeyFilePath } from "./e2ee-key-store.ts";
package/dist/index.js CHANGED
@@ -15,10 +15,11 @@ export { loadTls } from "./tls.js";
15
15
  export { loginPageHtml } from "./login-page.js";
16
16
  export { installService, uninstallService, serviceStatus, startService, stopService, restartService, systemdUnit, launchdPlist, SERVICE_NAME, JOIN_SERVICE_NAME, HOST_SERVICE_NAME, HUB_SERVICE_NAME } from "./service.js";
17
17
  export const NAME = "rdsh-gateway";
18
- export { join, startJoin, registerJoin, detectInsecure, selfRevoke, patchLoopbackJs } from "./join.js";
18
+ export { join, startJoin, registerJoin, detectInsecure, selfRevoke, patchLoopbackJs, hubRequest } from "./join.js";
19
19
  export { startDirect, lanCandidates, isPrivateIpv4 } from "./direct.js";
20
20
  export { createDirectTicketManager } from "./direct-ticket.js";
21
21
  export { loadOrCreateDirectSecret, directSecretPath } from "./direct-secret.js";
22
- export { readPersistedToken, clearPersistedToken } from "./token-store.js";
22
+ export { readPersistedToken, persistToken, clearPersistedToken } from "./token-store.js";
23
23
  export { acquireJoinLock, releaseJoinLock, readJoinLock, JOIN_LOCK_PATH } from "./lock.js";
24
+ export { loadOrCreateE2eeKeyPair, e2eeKeyFilePath } from "./e2ee-key-store.js";
24
25
  //# sourceMappingURL=index.js.map
package/dist/join.d.ts CHANGED
@@ -111,6 +111,16 @@ export interface JoinHandle {
111
111
  }
112
112
  /** 探测 hub 是否需 insecure:以严格校验握手一次;证书错误 → true(需 insecure)。 */
113
113
  export declare function detectInsecure(hubUrl: string): Promise<boolean>;
114
+ /** hub HTTP 调用(node:https 支持自签跳过校验 —— undici fetch 不受 NODE_TLS_REJECT_UNAUTHORIZED 影响)。 */
115
+ export declare function hubRequest(baseUrl: string, path: string, opts: {
116
+ method: string;
117
+ insecure: boolean;
118
+ body?: unknown;
119
+ }): Promise<{
120
+ ok: boolean;
121
+ status: number;
122
+ body: Record<string, unknown>;
123
+ }>;
114
124
  /** 调用 hub self-revoke 注销本机(host 持自己的 host token)。`rdsh host leave` 使用。 */
115
125
  export declare function selfRevoke(hubUrl: string, token: string, insecure: boolean): Promise<void>;
116
126
  /** 解析 host token(--token 注册 > 持久化复用)+ 自动检测证书;供 CLI 配置命令与 join() 复用。 */
package/dist/join.js CHANGED
@@ -64,7 +64,7 @@ const PONG_TIMEOUT_MS = 10_000;
64
64
  const RECONNECT_BASE_MS = 1_000;
65
65
  const RECONNECT_MAX_MS = 60_000;
66
66
  /** hub HTTP 调用(node:https 支持自签跳过校验 —— undici fetch 不受 NODE_TLS_REJECT_UNAUTHORIZED 影响)。 */
67
- function hubRequest(baseUrl, path, opts) {
67
+ export function hubRequest(baseUrl, path, opts) {
68
68
  const url = new URL(baseUrl + path);
69
69
  const lib = url.protocol === "https:" ? httpsRequest : httpRequest;
70
70
  return new Promise((resolve, reject) => {
@@ -954,8 +954,15 @@ export function startJoin(opts) {
954
954
  client.terminate();
955
955
  return;
956
956
  }
957
- for (const frame of frames)
958
- handleFrame(frame);
957
+ for (const frame of frames) {
958
+ // 单帧处理异常不能崩宿主进程:对端(含旧版客户端)可能发来不完整/不兼容的帧。
959
+ try {
960
+ handleFrame(frame);
961
+ }
962
+ catch (err) {
963
+ log("error", `frame handling failed: ${err instanceof Error ? err.message : String(err)}`);
964
+ }
965
+ }
959
966
  });
960
967
  client.on("close", () => {
961
968
  cleanupStreams();
@@ -974,7 +981,15 @@ export function startJoin(opts) {
974
981
  }
975
982
  setState("reconnecting", { delayMs: reconnectDelay });
976
983
  log("info", `tunnel lost — reconnecting in ${Math.round(reconnectDelay / 1000)}s...`);
977
- setTimeout(connect, reconnectDelay + Math.random() * 500);
984
+ // 定时器里的异常不会被上层捕获 —— 必须自己兜住,否则一次重连失败就崩掉宿主进程。
985
+ setTimeout(() => {
986
+ try {
987
+ connect();
988
+ }
989
+ catch (err) {
990
+ log("error", `reconnect failed: ${err instanceof Error ? err.message : String(err)}`);
991
+ }
992
+ }, reconnectDelay + Math.random() * 500);
978
993
  reconnectDelay = Math.min(reconnectDelay * 2, RECONNECT_MAX_MS);
979
994
  });
980
995
  client.on("error", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rdsh-gateway",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "rdsh host-side component: LAN auth gateway + outbound tunnel endpoint (spawns dsh web)",
5
5
  "license": "MIT",
6
6
  "type": "module",