feat(overlay): 覆盖网络线序①–⑮ 代码与测试产物入库
覆盖网络线累积产物(此前只在工作区、未入版本库):
- 新增 relay 子系统 src/net/relay/**(wire/duplex/server/client/dialer/switcher/directory/identity/keys/placement/network/addr-override/main/index)
- 新增 src/worker/relay-tunnel.ts、src/web/routes/overlay.ts
- 新增观测/演练脚本 overlay-probe、overlay-failover-drill、overlay-keyring、overlay-holepunch、overlay-jitter、overlay-wan、overlay-relaykey-add、relay-mem-calibrate
- 新增测试 12 个(relay / relay-failover / remote-spawner / instance-port / overlay-{network,auth,bootstrap,identity} / remote-user-fs 等)
验收基线:npm test = 162 pass / 0 fail / 1 skip;--scene all = 12 PASS / 0 SKIP / 0 FAIL;overlay-probe = 12/12
This commit is contained in:
1 parent
640813e84e
commit
146c3d25ef
53 files changed
+16187
-63
No files matched your search
+23
-9
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
import { VIA_LOCAL, VIA_MANAGER_SSH, type Reachability } from './reachability.js'
|
||||
import { parseLogicalName } from './relay/network.js'
|
||||
|
||||
export interface Rendezvous {
|
||||
/** 实现 id —— `Reachability.via` 指向它。 */
|
||||
@@ -29,14 +30,23 @@ export interface Rendezvous {
|
||||
dialTarget(): string
|
||||
/**
|
||||
* 解析某台 worker 的可达性。
|
||||
*
|
||||
* ⚠️ **入参是逻辑名 `<network_id>/<hostId>`**(P0-3)—— 不是裸 `hostId`。
|
||||
* 地址是**网内**语义:两张网各有一台 `w-1` 时,只给 `hostId` 的解析**必然有歧义**,
|
||||
* 而歧义会以"打到另一张网的同名节点"这种最贵的形态暴露。裸 `hostId` 仍兼容(⇒ 落 `ops`),
|
||||
* 但**调用方不许自己拼网络段** —— 名字由 `logicalName()` 产出。
|
||||
*
|
||||
* ⚠️ **本实现管不到 ⇒ 回 `undefined`,不抛** —— 由调用方决定回退哪种实现
|
||||
* (抛错会让"多实现并存"的过渡期没法跑)。
|
||||
*/
|
||||
resolve(hostId: string): Promise<Reachability | undefined>
|
||||
resolve(name: string): Promise<Reachability | undefined>
|
||||
}
|
||||
|
||||
/** 由调用方提供"hostId → `host:port`"的查表函数(会合实现不直接连 DB)。 */
|
||||
export type AddressLookup = (hostId: string) => string | undefined
|
||||
/**
|
||||
* 由调用方提供"**逻辑名** → `host:port`"的查表函数(会合实现不直接连 DB)。
|
||||
* 键是逻辑名(P0-3):查表这一层也必须带网络维度,否则同名 host 两张网互相覆盖。
|
||||
*/
|
||||
export type AddressLookup = (name: string) => string | undefined
|
||||
|
||||
/** 同机直连:Manager 能直接连到 worker 的端口,不经任何中转(`w-47` 就是这一类)。 */
|
||||
export class LocalRendezvous implements Rendezvous {
|
||||
@@ -48,9 +58,11 @@ export class LocalRendezvous implements Rendezvous {
|
||||
return '(direct)'
|
||||
}
|
||||
|
||||
async resolve(hostId: string): Promise<Reachability | undefined> {
|
||||
const address = this.addressOf(hostId)
|
||||
return address === undefined ? undefined : { hostId, via: this.id, address, scheme: 'http' }
|
||||
async resolve(name: string): Promise<Reachability | undefined> {
|
||||
const address = this.addressOf(name)
|
||||
if (address === undefined) return undefined
|
||||
const { network, hostId } = parseLogicalName(name)
|
||||
return { hostId, networkId: network, via: this.id, address, scheme: 'http' }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,9 +91,11 @@ export class ManagerSshRendezvous implements Rendezvous {
|
||||
return this.opts.target
|
||||
}
|
||||
|
||||
async resolve(hostId: string): Promise<Reachability | undefined> {
|
||||
const address = this.opts.addressOf(hostId)
|
||||
return address === undefined ? undefined : { hostId, via: this.id, address, scheme: 'http' }
|
||||
async resolve(name: string): Promise<Reachability | undefined> {
|
||||
const address = this.opts.addressOf(name)
|
||||
if (address === undefined) return undefined
|
||||
const { network, hostId } = parseLogicalName(name)
|
||||
return { hostId, networkId: network, via: this.id, address, scheme: 'http' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user