diff --git a/src/hermodr-daemon.cjs b/src/hermodr-daemon.cjs index 6e30ecd..21c1164 100644 --- a/src/hermodr-daemon.cjs +++ b/src/hermodr-daemon.cjs @@ -410,12 +410,9 @@ async function readOdinSurfaceProviderCatalog(options) { "hermodr-browser-lowering-odin-surface", odinRudpConnectionId, resolveHermodrRudpEndpoint(options.odinCultMeshUri, options), - { - connectTimeoutMs: 2_000, - maxFragmentBytes: 1200, - maxPendingReliablePackets: 512, + hermodrRudpPeerOptions({ resolveCultMeshRudpEndpoint: (uri) => resolveHermodrRudpEndpoint(uri, options), - }, + }), ); try { const keys = [ @@ -445,12 +442,9 @@ async function readOdinProviderAdvertisements(options) { "hermodr-browser-lowering-odin", odinRudpConnectionId, resolveHermodrRudpEndpoint(options.odinCultMeshUri, options), - { - connectTimeoutMs: 2_000, - maxFragmentBytes: 1200, - maxPendingReliablePackets: 512, + hermodrRudpPeerOptions({ resolveCultMeshRudpEndpoint: (uri) => resolveHermodrRudpEndpoint(uri, options), - }, + }), ); try { const response = await requestCultNetRawSnapshot( @@ -561,6 +555,16 @@ function normalizeRudpEndpoint(endpoint) { return text.startsWith("rudp://") ? text : `rudp://${text}`; } +function hermodrRudpPeerOptions(overrides = {}) { + return { + bindHost: "0.0.0.0", + connectTimeoutMs: 2_000, + maxFragmentBytes: 1200, + maxPendingReliablePackets: 512, + ...overrides, + }; +} + async function readProviderSurface(options, catalog, providerId, surfaceId = "") { const selectedSurfaceId = surfaceId || providerId; const recordKeys = surfaceRecordKeys(catalog, providerId, selectedSurfaceId); @@ -608,12 +612,9 @@ async function readOdinProviderSurface(options, providerId, surfaceId = provider "hermodr-browser-lowering-odin-provider-surface", odinRudpConnectionId, resolveHermodrRudpEndpoint(options.odinCultMeshUri, options), - { - connectTimeoutMs: 2_000, - maxFragmentBytes: 1200, - maxPendingReliablePackets: 512, + hermodrRudpPeerOptions({ resolveCultMeshRudpEndpoint: (uri) => resolveHermodrRudpEndpoint(uri, options), - }, + }), ); try { const candidates = recordKeys.length ? recordKeys : [surfaceId, `surface:${surfaceId}`, providerId, `surface:${providerId}`]; @@ -626,7 +627,7 @@ async function readOdinProviderSurface(options, providerId, surfaceId = provider { timeoutMs: 4_000, messageIdPrefix: "hermodr-odin-provider-surface" }, ); const state = normalizeSurfaceState(decodeMessagePack(bufferFromPayload(document.payload)), document.recordKey); - if (!state?.surface?.root || state.surface.id !== surfaceId) continue; + if (!state?.surface?.root) continue; return { providerId, documentProviderId: state.providerId, @@ -972,7 +973,7 @@ function normalizeSurfaceState(value, recordKey) { title: value.title || String(providerId), version: value.version || 0, updatedAt: value.updatedAt || value.updated_at || null, - surface: value.surface || null, + surface: value.surface ? normalizeEveSurfaceTree(value.surface) : null, }; } @@ -1173,11 +1174,7 @@ async function getProviderRudpPeer(endpoint) { "hermodr-browser-lowering-provider", providerRudpConnectionId, key, - { - connectTimeoutMs: 2_000, - maxFragmentBytes: 1200, - maxPendingReliablePackets: 512, - }, + hermodrRudpPeerOptions(), ).catch((error) => { providerRudpPeers.delete(key); throw error; @@ -1457,7 +1454,9 @@ module.exports = { createBrowserCatalog, createHermodrBridge, findProviderCdnRoute, + hermodrRudpPeerOptions, normalizeStateBindingSource, normalizeProviderAdvertisement, + normalizeSurfaceState, surfaceRecordKeys, }; diff --git a/test/hermodr-catalog.test.cjs b/test/hermodr-catalog.test.cjs index b4d3d62..7a4a2c2 100644 --- a/test/hermodr-catalog.test.cjs +++ b/test/hermodr-catalog.test.cjs @@ -6,10 +6,18 @@ const test = require("node:test"); const { createBrowserCatalog, findProviderCdnRoute, + hermodrRudpPeerOptions, normalizeProviderAdvertisement, + normalizeSurfaceState, surfaceRecordKeys, } = require("../src/hermodr-daemon.cjs"); +test("Hermodr outbound RUDP peers bind beyond loopback", () => { + const options = hermodrRudpPeerOptions(); + assert.equal(options.bindHost, "0.0.0.0"); + assert.equal(options.connectTimeoutMs, 2_000); +}); + const provider = normalizeProviderAdvertisement({ providerId: "fixture.game", title: "Fixture game", @@ -36,6 +44,24 @@ test("surface reads prefer the provider-advertised record reference", () => { assert.equal(surfaceRecordKeys(catalog, "fixture.game", "fixture.world")[0], "cultmesh://fixture/surfaces/world"); }); +test("surface-state normalization lowers MessagePack array records", () => { + const state = normalizeSurfaceState([ + "gjallar.overview", + "Gjallar", + 7, + "2026-08-25T00:00:00Z", + [ + "gjallar.overview.surface", + ["root", "dashboard", { title: "Gjallar" }, [], [], [], { mode: "weighted-bisect" }, {}], + [], + ], + ], "gjallar.overview"); + + assert.equal(state.surface.id, "gjallar.overview.surface"); + assert.equal(state.surface.root.kind, "dashboard"); + assert.equal(state.surface.root.layout.mode, "weighted-bisect"); +}); + test("CDN routing follows the asset URI provider instead of a product name", () => { const catalog = createBrowserCatalog([provider]); const route = findProviderCdnRoute(catalog, "cultmesh://fixture.game/assets/player");