@net-mesh/browser 0.39.0 → 0.41.0
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/CHANGELOG.md +24 -0
- package/dist/index.bundle.js +2 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/leader/index.d.ts +1 -1
- package/dist/net_leaf.d.ts +27 -27
- package/dist/net_leaf.js +88 -88
- package/dist/net_leaf_bg.wasm +0 -0
- package/dist/net_leaf_bg.wasm.d.ts +2 -2
- package/dist/netcode/index.d.ts +3 -0
- package/dist/netcode/index.js +4 -0
- package/dist/store/host.d.ts +19 -3
- package/dist/store/host.js +21 -7
- package/dist/store/index.d.ts +23 -0
- package/dist/store/index.js +16 -0
- package/dist/store/join.d.ts +6 -1
- package/dist/store/join.js +14 -8
- package/dist/world/link.js +3 -3
- package/dist/world/regions.js +3 -3
- package/package.json +1 -1
package/dist/store/join.d.ts
CHANGED
|
@@ -57,7 +57,12 @@ export declare const MAX_OUTSTANDING = 64;
|
|
|
57
57
|
export interface JoinStoreOptions<S extends object, A extends ActionSpec, I extends InputSpec> {
|
|
58
58
|
readonly definition: StoreDefinition<S, A, I>;
|
|
59
59
|
readonly transport: StoreTransport;
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The node hosting the store: 16 hex digits, as `nodeIdHex()` and a
|
|
62
|
+
* descriptor's `peerIdHex` print it. The decimal `peerNode` of an
|
|
63
|
+
* event is accepted too, unless it is exactly sixteen digits long —
|
|
64
|
+
* that is the hex spelling, and it is read as hex.
|
|
65
|
+
*/
|
|
61
66
|
readonly host: string;
|
|
62
67
|
/** The audience this caller wants. */
|
|
63
68
|
readonly audience: readonly string[];
|
package/dist/store/join.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { StoreCore } from './core.js';
|
|
25
25
|
import { isStaleStream, StoreError } from './errors.js';
|
|
26
|
-
import {
|
|
26
|
+
import { nodeHexOf, peerHexOf } from './host.js';
|
|
27
27
|
import { StoreReplica } from './replica.js';
|
|
28
28
|
import { decodeMessage, encodeMessage, utf8Length } from './wire.js';
|
|
29
29
|
/** How often a live handle renews its lease (§1.6). */
|
|
@@ -83,7 +83,10 @@ export function joinStore(options) {
|
|
|
83
83
|
// had already accepted the subscription. Refused here instead,
|
|
84
84
|
// where the caller can read what it did wrong.
|
|
85
85
|
const selfId = options.transport.nodeIdHex();
|
|
86
|
-
|
|
86
|
+
// Read ONCE, as an id the caller holds: hex when it is the sixteen
|
|
87
|
+
// digits `nodeIdHex()` prints, even when none of them is a letter.
|
|
88
|
+
const hostHex = nodeHexOf(options.host);
|
|
89
|
+
if (selfId !== null && hostHex !== null && nodeHexOf(selfId) === hostHex) {
|
|
87
90
|
throw new StoreError('invalid-data', 'a replica cannot join the node it runs on: hold the hostStore handle instead');
|
|
88
91
|
}
|
|
89
92
|
const streamId = options.streamId ?? `store/${options.definition.id}`;
|
|
@@ -124,8 +127,7 @@ export function joinStore(options) {
|
|
|
124
127
|
return upstream;
|
|
125
128
|
if (opening !== null)
|
|
126
129
|
return opening;
|
|
127
|
-
|
|
128
|
-
if (addressable === null) {
|
|
130
|
+
if (hostHex === null) {
|
|
129
131
|
return Promise.reject(new StoreError('invalid-data', `the host id is not a node id: ${options.host}`));
|
|
130
132
|
}
|
|
131
133
|
// `label`, never `streamId`: see {@link StoreTransport.openStream}.
|
|
@@ -139,11 +141,11 @@ export function joinStore(options) {
|
|
|
139
141
|
// the relay is installed before the direct half is even tried, so
|
|
140
142
|
// the open below is the thing that decides, and its refusal is
|
|
141
143
|
// typed.
|
|
142
|
-
opening = Promise.resolve(options.transport.connectPeer?.(
|
|
144
|
+
opening = Promise.resolve(options.transport.connectPeer?.(hostHex))
|
|
143
145
|
.catch(() => undefined)
|
|
144
146
|
.then(() => options.transport.openStream({
|
|
145
147
|
reliability: 'reliable',
|
|
146
|
-
peer:
|
|
148
|
+
peer: hostHex,
|
|
147
149
|
label: streamId,
|
|
148
150
|
}))
|
|
149
151
|
.then(open => {
|
|
@@ -350,8 +352,12 @@ export function joinStore(options) {
|
|
|
350
352
|
// is what identifies this store's traffic.
|
|
351
353
|
// The host's identity, compared as a NUMBER: the event carries an
|
|
352
354
|
// exact decimal and `options.host` is hex, so `!==` on the strings
|
|
353
|
-
// rejected every frame the host ever sent.
|
|
354
|
-
|
|
355
|
+
// rejected every frame the host ever sent. Each side is read in
|
|
356
|
+
// its OWN spelling: one reader for both took an all-digit hex host
|
|
357
|
+
// for a decimal, and then no frame of that host's ever matched.
|
|
358
|
+
if (typeof event.peerNode !== 'string' || hostHex === null)
|
|
359
|
+
return;
|
|
360
|
+
if (peerHexOf(event.peerNode) !== hostHex)
|
|
355
361
|
return;
|
|
356
362
|
const payload = event.payload;
|
|
357
363
|
if (payload === undefined)
|
package/dist/world/link.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* handoffs.handoff('ship-7', 'r:4:8'); // when the ship crosses the border
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
import { peerHexOf } from '../store/host.js';
|
|
17
|
+
import { nodeHexOf, peerHexOf } from '../store/host.js';
|
|
18
18
|
import { ghostTargets, onForwardedAction, pruneActs, } from './border.js';
|
|
19
19
|
import { beginHandoff, locate, onHandoffOffer, onHandoffReply, pruneHandled, reofferHandoff, retryHandoffs, } from './handoff.js';
|
|
20
20
|
const encoder = new TextEncoder();
|
|
@@ -140,7 +140,7 @@ export function handoffLink(options) {
|
|
|
140
140
|
// handoff on another region's behalf.
|
|
141
141
|
const sender = typeof event.peerNode === 'string' ? peerHexOf(event.peerNode) : null;
|
|
142
142
|
const expected = options.peerOf(body.from);
|
|
143
|
-
if (sender === null || expected === null ||
|
|
143
|
+
if (sender === null || expected === null || nodeHexOf(expected) !== sender) {
|
|
144
144
|
drop('unauthenticated');
|
|
145
145
|
refresh(body.from);
|
|
146
146
|
return;
|
|
@@ -153,7 +153,7 @@ export function handoffLink(options) {
|
|
|
153
153
|
if (closed)
|
|
154
154
|
return;
|
|
155
155
|
const peer = options.peerOf(message.to);
|
|
156
|
-
const hex = peer === null ? null :
|
|
156
|
+
const hex = peer === null ? null : nodeHexOf(peer);
|
|
157
157
|
if (hex === null) {
|
|
158
158
|
drop('unknown-region');
|
|
159
159
|
refresh(message.to);
|
package/dist/world/regions.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* directory (`handoffLink({ peerOf: directory.peerOf })`) needs the list:
|
|
28
28
|
* otherwise a node that announces a region could also send offers as it.
|
|
29
29
|
*/
|
|
30
|
-
import {
|
|
30
|
+
import { nodeHexOf } from '../store/host.js';
|
|
31
31
|
import { joinStore } from '../store/join.js';
|
|
32
32
|
/** Region `r:<rx>:<rz>` for a position, with regions `size` units square. */
|
|
33
33
|
export function regionOf(x, z, size) {
|
|
@@ -77,7 +77,7 @@ export function announceRegions(node, world, regions, options = {}) {
|
|
|
77
77
|
export function regionDirectory(options) {
|
|
78
78
|
const trusted = options.trustedHosts === undefined
|
|
79
79
|
? null
|
|
80
|
-
: new Set(options.trustedHosts.map(id =>
|
|
80
|
+
: new Set(options.trustedHosts.map(id => nodeHexOf(id)).filter((id) => id !== null));
|
|
81
81
|
const cache = new Map();
|
|
82
82
|
return {
|
|
83
83
|
async lookup(region) {
|
|
@@ -90,7 +90,7 @@ export function regionDirectory(options) {
|
|
|
90
90
|
}
|
|
91
91
|
const hosts = [
|
|
92
92
|
...new Set(found
|
|
93
|
-
.map(descriptor =>
|
|
93
|
+
.map(descriptor => nodeHexOf(descriptor.peerIdHex))
|
|
94
94
|
.filter((id) => id !== null && (trusted === null || trusted.has(id)))),
|
|
95
95
|
].sort();
|
|
96
96
|
const answer = hosts.length === 0
|