From 6d5fe4572d34b1e92dea600668548f36e4cc7004 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 5 Nov 2026 15:25:57 +0100 Subject: [PATCH] =?UTF-8?q?Placement=20seat:=20the=20tunnel=20found=20on?= =?UTF-8?q?=20a=20node=20is=20a=20typed=20record,=20not=20a=20free=20objec?= =?UTF-8?q?t=20(ADR=200634=20=C2=A71;=20issue=201966)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../go/seats/meshmoduleassigner/contract.go | 21 ++++++- .../seats/meshmoduleassigner/contract_test.go | 6 ++ .../mesh-module-assigner/fixtures/states.json | 22 ++++++++ .../seats/mesh-module-assigner/seat.json | 56 ++++++++++++++++++- .../ts/seats/meshmoduleassigner/src/index.ts | 21 ++++++- 5 files changed, 123 insertions(+), 3 deletions(-) diff --git a/placement/go/seats/meshmoduleassigner/contract.go b/placement/go/seats/meshmoduleassigner/contract.go index 85f9ec8..10de4c1 100644 --- a/placement/go/seats/meshmoduleassigner/contract.go +++ b/placement/go/seats/meshmoduleassigner/contract.go @@ -343,6 +343,25 @@ func DecodeSeatHoldersBySeatNodeValue(raw []byte) (SeatHoldersBySeatNodeValue, e return v, nil } +// FoundTunnel is a tunnel found on the machine when it was adopted: everything but its private key. +type FoundTunnel struct { + Address string `json:"address,omitempty"` + Config string `json:"config,omitempty"` + Interface string `json:"interface"` + Mtu int64 `json:"mtu,omitempty"` + Peers []FoundTunnelPeer `json:"peers,omitempty"` + Port int64 `json:"port,omitempty"` + PublicKey string `json:"public-key,omitempty"` + Range string `json:"range,omitempty"` + Unit string `json:"unit,omitempty"` +} + +// FoundTunnelPeer is one peer of a found tunnel. +type FoundTunnelPeer struct { + Address string `json:"address,omitempty"` + PublicKey string `json:"public-key"` +} + // Holding is one seat a module placed on the node holds. type Holding struct { Claim string `json:"claim"` @@ -368,7 +387,7 @@ type NodeDecided struct { Site string `json:"site,omitempty"` Taken []string `json:"taken,omitempty"` // the tunnel found on the node when it was adopted - Tunnel map[string]any `json:"tunnel,omitempty"` + Tunnel *FoundTunnel `json:"tunnel,omitempty"` } // PlacedModule is one module placed on a node. diff --git a/placement/go/seats/meshmoduleassigner/contract_test.go b/placement/go/seats/meshmoduleassigner/contract_test.go index 178ad88..a007587 100644 --- a/placement/go/seats/meshmoduleassigner/contract_test.go +++ b/placement/go/seats/meshmoduleassigner/contract_test.go @@ -25,6 +25,12 @@ func TestFixtures(t *testing.T) { err := json.Unmarshal(b, &v) return v, err }, subjectIs: nil}, + {name: "a node that came with a tunnel", subject: "", given: "{\"decided\":{\"tunnel\":{\"interface\":\"wg0\",\"peers\":[{\"address\":\"10.77.0.9/32\",\"public-key\":\"k2\"}],\"port\":51820,\"public-key\":\"k1\"}},\"modules\":[],\"node\":\"ace\",\"v\":1}", wire: "{\"decided\":{\"tunnel\":{\"interface\":\"wg0\",\"peers\":[{\"address\":\"10.77.0.9/32\",\"public-key\":\"k2\"}],\"port\":51820,\"public-key\":\"k1\"}},\"modules\":[],\"node\":\"ace\",\"v\":1}", + decode: func(b []byte) (any, error) { + var v PlacementByNodeNodeValue + err := json.Unmarshal(b, &v) + return v, err + }, subjectIs: nil}, {name: "a module's key", subject: "", given: "{\"node\":\"ace\",\"placed\":{\"bindings\":{\"database\":{\"module\":\"postgres\",\"node\":\"ace\"}},\"module\":\"plex\",\"ports\":{\"32400\":32400}},\"v\":1}", wire: "{\"node\":\"ace\",\"placed\":{\"bindings\":{\"database\":{\"module\":\"postgres\",\"node\":\"ace\"}},\"module\":\"plex\",\"ports\":{\"32400\":32400}},\"v\":1}", decode: func(b []byte) (any, error) { var v PlacementByNodeModuleValue diff --git a/placement/seats/mesh-module-assigner/fixtures/states.json b/placement/seats/mesh-module-assigner/fixtures/states.json index 2ccef79..4c176ff 100644 --- a/placement/seats/mesh-module-assigner/fixtures/states.json +++ b/placement/seats/mesh-module-assigner/fixtures/states.json @@ -16,6 +16,28 @@ ] } }, + { + "name": "a node that came with a tunnel", + "of": "state:placement/.node", + "given": { + "v": 1, + "node": "ace", + "decided": { + "tunnel": { + "interface": "wg0", + "port": 51820, + "public-key": "k1", + "peers": [ + { + "public-key": "k2", + "address": "10.77.0.9/32" + } + ] + } + }, + "modules": [] + } + }, { "name": "a module's key", "of": "state:placement/.", diff --git a/placement/seats/mesh-module-assigner/seat.json b/placement/seats/mesh-module-assigner/seat.json index 8e18a70..77108a2 100644 --- a/placement/seats/mesh-module-assigner/seat.json +++ b/placement/seats/mesh-module-assigner/seat.json @@ -514,7 +514,7 @@ } }, "tunnel": { - "type": "object", + "$ref": "#/defs/FoundTunnel", "description": "the tunnel found on the node when it was adopted" }, "peer-names": { @@ -526,6 +526,60 @@ } } }, + "FoundTunnel": { + "type": "object", + "description": "a tunnel found on the machine when it was adopted: everything but its private key", + "properties": { + "interface": { + "type": "string" + }, + "unit": { + "type": "string" + }, + "config": { + "type": "string" + }, + "port": { + "type": "integer" + }, + "mtu": { + "type": "integer" + }, + "address": { + "type": "string" + }, + "range": { + "type": "string" + }, + "public-key": { + "type": "string" + }, + "peers": { + "type": "array", + "items": { + "$ref": "#/defs/FoundTunnelPeer" + } + } + }, + "required": [ + "interface" + ] + }, + "FoundTunnelPeer": { + "type": "object", + "description": "one peer of a found tunnel", + "properties": { + "public-key": { + "type": "string" + }, + "address": { + "type": "string" + } + }, + "required": [ + "public-key" + ] + }, "Placement": { "type": "object", "description": "one node's placement assembled", diff --git a/placement/ts/seats/meshmoduleassigner/src/index.ts b/placement/ts/seats/meshmoduleassigner/src/index.ts index 8f958a4..137274b 100644 --- a/placement/ts/seats/meshmoduleassigner/src/index.ts +++ b/placement/ts/seats/meshmoduleassigner/src/index.ts @@ -178,6 +178,25 @@ export function parseSeatHoldersBySeatNodeKey(key: string): { seat: string; node return { seat, node }; } +/** a tunnel found on the machine when it was adopted: everything but its private key */ +export interface FoundTunnel { + "address"?: string; + "config"?: string; + "interface": string; + "mtu"?: number; + "peers"?: FoundTunnelPeer[]; + "port"?: number; + "public-key"?: string; + "range"?: string; + "unit"?: string; +} + +/** one peer of a found tunnel */ +export interface FoundTunnelPeer { + "address"?: string; + "public-key": string; +} + /** one seat a module placed on the node holds */ export interface Holding { "claim": string; @@ -203,7 +222,7 @@ export interface NodeDecided { "site"?: string; "taken"?: string[]; /** the tunnel found on the node when it was adopted */ - "tunnel"?: Record; + "tunnel"?: FoundTunnel; } /** one module placed on a node */