@blockcast/mmt-base 0.1.0-main.54c140948db3 → 0.1.0-main.55f2a358ca01

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/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './mmtp.js';
2
+ export * from './net-constants.js';
3
+ export * from './ntp-short.js';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './mmtp.js';
2
+ export * from './net-constants.js';
3
+ export * from './ntp-short.js';
2
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * AMT well-known UDP port (RFC 7450 §4).
3
+ *
4
+ * The single definition for the whole repo. It lives here, in the one package
5
+ * both `@blockcast/mmt-transport` and `@blockcast/mmt-container` already
6
+ * depend on, because the two apply it on opposite sides of a boundary that
7
+ * does not otherwise share code:
8
+ *
9
+ * - container resolves it where `networkSource` semantics live, so a catalog
10
+ * relay that names no port is reachable instead of handing a join a
11
+ * portless relay that fails.
12
+ * - transport applies it when reading a catalog, dialling a gateway, and
13
+ * answering DRIAD — but deliberately not at every boundary. Which call
14
+ * sites do and do not take the default is transport's business; the
15
+ * reasoning lives beside those call sites, not here.
16
+ */
17
+ export declare const DEFAULT_AMT_RELAY_PORT = 2268;
18
+ //# sourceMappingURL=net-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"net-constants.d.ts","sourceRoot":"","sources":["../src/net-constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * AMT well-known UDP port (RFC 7450 §4).
3
+ *
4
+ * The single definition for the whole repo. It lives here, in the one package
5
+ * both `@blockcast/mmt-transport` and `@blockcast/mmt-container` already
6
+ * depend on, because the two apply it on opposite sides of a boundary that
7
+ * does not otherwise share code:
8
+ *
9
+ * - container resolves it where `networkSource` semantics live, so a catalog
10
+ * relay that names no port is reachable instead of handing a join a
11
+ * portless relay that fails.
12
+ * - transport applies it when reading a catalog, dialling a gateway, and
13
+ * answering DRIAD — but deliberately not at every boundary. Which call
14
+ * sites do and do not take the default is transport's business; the
15
+ * reasoning lives beside those call sites, not here.
16
+ */
17
+ export const DEFAULT_AMT_RELAY_PORT = 2268;
18
+ //# sourceMappingURL=net-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"net-constants.js","sourceRoot":"","sources":["../src/net-constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * NTP short format (RFC 5905 §6): an unsigned 32-bit, 16.16 fixed-point count
3
+ * of seconds. The MMTP header `timestamp` field (ISO/IEC 23008-1 §9.2.2)
4
+ * carries each packet's UTC sending instant in this format, so the value wraps
5
+ * to 0 every 2^16 s (~18.2 h).
6
+ *
7
+ * Plain numeric order on these values breaks at every wrap: a retained
8
+ * `Math.max` stays at the pre-wrap value and every later instant compares as
9
+ * older. Order send times only with {@link compareNtpShort}, which applies
10
+ * RFC 1982 serial-number arithmetic over the field's width.
11
+ */
12
+ /** Width in bits of the MMTP `timestamp` field (NTP short). */
13
+ export declare const NTP_SHORT_BITS = 32;
14
+ /** Number of distinct NTP-short values; the field wraps to 0 here. */
15
+ export declare const NTP_SHORT_MODULUS: number;
16
+ /**
17
+ * RFC 1982 §3.2's `2^(SERIAL_BITS - 1)`. Two values whose forward distance is
18
+ * below this are ordered; exactly this far apart they are not ordered at all.
19
+ * Two instants must be less than this far apart (2^15 s, ~9.1 h of send time)
20
+ * for the comparison to give their true order.
21
+ */
22
+ export declare const NTP_SHORT_HALF_RANGE: number;
23
+ /**
24
+ * Serial order of one NTP-short value relative to another.
25
+ *
26
+ * `'unordered'` is RFC 1982's undefined case: the values are exactly
27
+ * {@link NTP_SHORT_HALF_RANGE} apart, so neither precedes the other. It is
28
+ * never folded into `'before'` or `'after'`; each caller decides what an
29
+ * unorderable pair means for it.
30
+ */
31
+ export type NtpShortOrder = 'before' | 'equal' | 'after' | 'unordered';
32
+ /** True when `value` is an NTP-short value: an integer in [0, NTP_SHORT_MODULUS). */
33
+ export declare function isNtpShort(value: number): boolean;
34
+ /**
35
+ * RFC 1982 serial comparison of NTP-short `a` against `b`: `'after'` when `a`
36
+ * is the later instant, `'before'` when it is the earlier one.
37
+ *
38
+ * The answer is the true order only while the two instants are less than
39
+ * {@link NTP_SHORT_HALF_RANGE} apart. Past that a 32-bit field cannot tell
40
+ * later from earlier, and the result names whichever direction is nearer.
41
+ * This is not a total order (it is not transitive across the whole space), so
42
+ * it must never be used to sort.
43
+ *
44
+ * @throws {RangeError} if either operand is not an NTP-short value
45
+ */
46
+ export declare function compareNtpShort(a: number, b: number): NtpShortOrder;
47
+ //# sourceMappingURL=ntp-short.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ntp-short.d.ts","sourceRoot":"","sources":["../src/ntp-short.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,+DAA+D;AAC/D,eAAO,MAAM,cAAc,KAAK,CAAA;AAEhC,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,QAAsB,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,QAA4B,CAAA;AAE7D;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,CAAA;AAEtE,qFAAqF;AACrF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,aAAa,CAanE"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * NTP short format (RFC 5905 §6): an unsigned 32-bit, 16.16 fixed-point count
3
+ * of seconds. The MMTP header `timestamp` field (ISO/IEC 23008-1 §9.2.2)
4
+ * carries each packet's UTC sending instant in this format, so the value wraps
5
+ * to 0 every 2^16 s (~18.2 h).
6
+ *
7
+ * Plain numeric order on these values breaks at every wrap: a retained
8
+ * `Math.max` stays at the pre-wrap value and every later instant compares as
9
+ * older. Order send times only with {@link compareNtpShort}, which applies
10
+ * RFC 1982 serial-number arithmetic over the field's width.
11
+ */
12
+ /** Width in bits of the MMTP `timestamp` field (NTP short). */
13
+ export const NTP_SHORT_BITS = 32;
14
+ /** Number of distinct NTP-short values; the field wraps to 0 here. */
15
+ export const NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
16
+ /**
17
+ * RFC 1982 §3.2's `2^(SERIAL_BITS - 1)`. Two values whose forward distance is
18
+ * below this are ordered; exactly this far apart they are not ordered at all.
19
+ * Two instants must be less than this far apart (2^15 s, ~9.1 h of send time)
20
+ * for the comparison to give their true order.
21
+ */
22
+ export const NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1);
23
+ /** True when `value` is an NTP-short value: an integer in [0, NTP_SHORT_MODULUS). */
24
+ export function isNtpShort(value) {
25
+ return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS;
26
+ }
27
+ /**
28
+ * RFC 1982 serial comparison of NTP-short `a` against `b`: `'after'` when `a`
29
+ * is the later instant, `'before'` when it is the earlier one.
30
+ *
31
+ * The answer is the true order only while the two instants are less than
32
+ * {@link NTP_SHORT_HALF_RANGE} apart. Past that a 32-bit field cannot tell
33
+ * later from earlier, and the result names whichever direction is nearer.
34
+ * This is not a total order (it is not transitive across the whole space), so
35
+ * it must never be used to sort.
36
+ *
37
+ * @throws {RangeError} if either operand is not an NTP-short value
38
+ */
39
+ export function compareNtpShort(a, b) {
40
+ if (!isNtpShort(a) || !isNtpShort(b)) {
41
+ throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS}), got ${String(a)} and ${String(b)}`);
42
+ }
43
+ if (a === b)
44
+ return 'equal';
45
+ // Forward distance from b to a, reduced into [1, NTP_SHORT_MODULUS). Both
46
+ // operands are below 2^32, so every step is exact in a double.
47
+ const forward = (a - b + NTP_SHORT_MODULUS) % NTP_SHORT_MODULUS;
48
+ if (forward < NTP_SHORT_HALF_RANGE)
49
+ return 'after';
50
+ if (forward > NTP_SHORT_HALF_RANGE)
51
+ return 'before';
52
+ return 'unordered';
53
+ }
54
+ //# sourceMappingURL=ntp-short.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ntp-short.js","sourceRoot":"","sources":["../src/ntp-short.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAA;AAEhC,sEAAsE;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAI,cAAc,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAA;AAY7D,qFAAqF;AACrF,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,iBAAiB,CAAA;AAC3E,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS;IAClD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,UAAU,CAClB,8CAA8C,cAAc,UAAU,MAAM,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC,EAAE,CACnG,CAAA;IACH,CAAC;IACD,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAA;IAC3B,0EAA0E;IAC1E,+DAA+D;IAC/D,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,GAAG,iBAAiB,CAAA;IAC/D,IAAI,OAAO,GAAG,oBAAoB;QAAE,OAAO,OAAO,CAAA;IAClD,IAAI,OAAO,GAAG,oBAAoB;QAAE,OAAO,QAAQ,CAAA;IACnD,OAAO,WAAW,CAAA;AACpB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blockcast/mmt-base",
3
- "version": "0.1.0-main.54c140948db3",
4
- "description": "Shared MMTP packet parsing primitives (zero FEC dependency). Hosts MMTP_HEADER_SIZE, parseMMTPHeader, extractMFUPayload, and friends so both @blockcast/mmt-fec and @blockcast/mmt-container can import them without a circular dep.",
3
+ "version": "0.1.0-main.55f2a358ca01",
4
+ "description": "Shared MMTP parsing primitives and protocol constants (zero FEC dependency). Hosts MMTP_HEADER_SIZE, parseMMTPHeader, extractMFUPayload and friends, plus wire constants such as DEFAULT_AMT_RELAY_PORT, so @blockcast/mmt-fec, @blockcast/mmt-container and @blockcast/mmt-transport can share one definition without a circular dep.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "test:watch": "vitest"
30
30
  },
31
31
  "dependencies": {
32
- "@blockcast/mmt-alta-parse": "0.1.0-main.54c140948db3"
32
+ "@blockcast/mmt-alta-parse": "0.1.0-main.55f2a358ca01"
33
33
  },
34
34
  "devDependencies": {
35
35
  "typescript": "^5.3.0",
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './mmtp.js'
2
+ export * from './net-constants.js'
3
+ export * from './ntp-short.js'
@@ -0,0 +1,17 @@
1
+ /**
2
+ * AMT well-known UDP port (RFC 7450 §4).
3
+ *
4
+ * The single definition for the whole repo. It lives here, in the one package
5
+ * both `@blockcast/mmt-transport` and `@blockcast/mmt-container` already
6
+ * depend on, because the two apply it on opposite sides of a boundary that
7
+ * does not otherwise share code:
8
+ *
9
+ * - container resolves it where `networkSource` semantics live, so a catalog
10
+ * relay that names no port is reachable instead of handing a join a
11
+ * portless relay that fails.
12
+ * - transport applies it when reading a catalog, dialling a gateway, and
13
+ * answering DRIAD — but deliberately not at every boundary. Which call
14
+ * sites do and do not take the default is transport's business; the
15
+ * reasoning lives beside those call sites, not here.
16
+ */
17
+ export const DEFAULT_AMT_RELAY_PORT = 2268;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * NTP short format (RFC 5905 §6): an unsigned 32-bit, 16.16 fixed-point count
3
+ * of seconds. The MMTP header `timestamp` field (ISO/IEC 23008-1 §9.2.2)
4
+ * carries each packet's UTC sending instant in this format, so the value wraps
5
+ * to 0 every 2^16 s (~18.2 h).
6
+ *
7
+ * Plain numeric order on these values breaks at every wrap: a retained
8
+ * `Math.max` stays at the pre-wrap value and every later instant compares as
9
+ * older. Order send times only with {@link compareNtpShort}, which applies
10
+ * RFC 1982 serial-number arithmetic over the field's width.
11
+ */
12
+
13
+ /** Width in bits of the MMTP `timestamp` field (NTP short). */
14
+ export const NTP_SHORT_BITS = 32
15
+
16
+ /** Number of distinct NTP-short values; the field wraps to 0 here. */
17
+ export const NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS
18
+
19
+ /**
20
+ * RFC 1982 §3.2's `2^(SERIAL_BITS - 1)`. Two values whose forward distance is
21
+ * below this are ordered; exactly this far apart they are not ordered at all.
22
+ * Two instants must be less than this far apart (2^15 s, ~9.1 h of send time)
23
+ * for the comparison to give their true order.
24
+ */
25
+ export const NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1)
26
+
27
+ /**
28
+ * Serial order of one NTP-short value relative to another.
29
+ *
30
+ * `'unordered'` is RFC 1982's undefined case: the values are exactly
31
+ * {@link NTP_SHORT_HALF_RANGE} apart, so neither precedes the other. It is
32
+ * never folded into `'before'` or `'after'`; each caller decides what an
33
+ * unorderable pair means for it.
34
+ */
35
+ export type NtpShortOrder = 'before' | 'equal' | 'after' | 'unordered'
36
+
37
+ /** True when `value` is an NTP-short value: an integer in [0, NTP_SHORT_MODULUS). */
38
+ export function isNtpShort(value: number): boolean {
39
+ return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS
40
+ }
41
+
42
+ /**
43
+ * RFC 1982 serial comparison of NTP-short `a` against `b`: `'after'` when `a`
44
+ * is the later instant, `'before'` when it is the earlier one.
45
+ *
46
+ * The answer is the true order only while the two instants are less than
47
+ * {@link NTP_SHORT_HALF_RANGE} apart. Past that a 32-bit field cannot tell
48
+ * later from earlier, and the result names whichever direction is nearer.
49
+ * This is not a total order (it is not transitive across the whole space), so
50
+ * it must never be used to sort.
51
+ *
52
+ * @throws {RangeError} if either operand is not an NTP-short value
53
+ */
54
+ export function compareNtpShort(a: number, b: number): NtpShortOrder {
55
+ if (!isNtpShort(a) || !isNtpShort(b)) {
56
+ throw new RangeError(
57
+ `NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS}), got ${String(a)} and ${String(b)}`,
58
+ )
59
+ }
60
+ if (a === b) return 'equal'
61
+ // Forward distance from b to a, reduced into [1, NTP_SHORT_MODULUS). Both
62
+ // operands are below 2^32, so every step is exact in a double.
63
+ const forward = (a - b + NTP_SHORT_MODULUS) % NTP_SHORT_MODULUS
64
+ if (forward < NTP_SHORT_HALF_RANGE) return 'after'
65
+ if (forward > NTP_SHORT_HALF_RANGE) return 'before'
66
+ return 'unordered'
67
+ }