@statewalker/httpeers-libp2p 0.3.0 → 0.3.2

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.
@@ -21,8 +21,27 @@ import { type RelaySupervisor } from "./reservation.js";
21
21
  * connection it already holds to the hub.
22
22
  */
23
23
  export declare function hubRoute(hubPeerId: string, peerId: string): string;
24
- /** How many times `dialWebRTC` tries a WebRTC upgrade before giving up. */
24
+ /** How many times `dialWebRTC` tries a WebRTC upgrade under node-datachannel before giving up. */
25
25
  export declare const WEBRTC_UPGRADE_ATTEMPTS = 3;
26
+ /**
27
+ * How many attempts `dialWebRTC` makes by default: one where WebRTC is the
28
+ * runtime's own (a browser), `WEBRTC_UPGRADE_ATTEMPTS` elsewhere (Node, with
29
+ * node-datachannel). Read at each call, not at import.
30
+ *
31
+ * WHY ONE IN A BROWSER. The retry exists for a node-datachannel race (below),
32
+ * which a browser's WebRTC does not have. There, a path that cannot come up
33
+ * (symmetric NAT, UDP blocked) fails every attempt alike, each after libp2p's
34
+ * per-address dial timeout (6 s in libp2p 3), and the caller's relay fallback
35
+ * waits for all of them: measured in Chromium with UDP blocked, a Guest's join
36
+ * took 18 s, all of it in three timed-out upgrades, and 6 s with one.
37
+ *
38
+ * THE TEST IS THE GLOBAL, NOT THE IMPLEMENTATION libp2p PICKS (it picks by the
39
+ * package's `browser` field). Under Node they agree unless a process installs a
40
+ * global RTCPeerConnection (e.g. node-datachannel's polyfill assigned to
41
+ * `globalThis`): libp2p still runs node-datachannel there, and this would
42
+ * drop its retry. Pass `attempts` explicitly in such a process.
43
+ */
44
+ export declare function defaultWebRTCAttempts(): number;
26
45
  /**
27
46
  * Dial a `/webrtc` address, trying the upgrade again when it fails.
28
47
  *
@@ -37,7 +56,8 @@ export declare const WEBRTC_UPGRADE_ATTEMPTS = 3;
37
56
  * load. Each attempt is an independent race, so one retry nearly always
38
57
  * succeeds. Fixed upstream by libdatachannel 0235225 ("start DTLS after
39
58
  * remote description"); drop the retry once node-datachannel ships it.
40
- * Browsers implement WebRTC themselves and are not affected.
59
+ * Browsers implement WebRTC themselves and are not affected, so they get one
60
+ * attempt (`defaultWebRTCAttempts`).
41
61
  *
42
62
  * A WebRTC path that cannot come up fails every attempt, and the caller's
43
63
  * fallback (the relay circuit) runs as before.
@@ -1 +1 @@
1
- {"version":3,"file":"hub-link.d.ts","sourceRoot":"","sources":["../src/hub-link.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAC;AAEpE,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,kBAAkB,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,2EAA2E;AAC3E,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,EAC/B,QAAQ,GAAE,MAAgC,GACzC,OAAO,CAAC,UAAU,CAAC,CAUrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIhG;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,gBAAg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,OAAO,CAAA;KAAE,EAI5B;CACF;AA2ED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAenF;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/E;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,2BAA2B,GAAG,eAAe,CAY1F"}
package/dist/hub-link.js CHANGED
@@ -24,8 +24,31 @@ import { superviseRelay } from "./reservation.js";
24
24
  export function hubRoute(hubPeerId, peerId) {
25
25
  return `/p2p/${hubPeerId}/p2p-circuit/webrtc/p2p/${peerId}`;
26
26
  }
27
- /** How many times `dialWebRTC` tries a WebRTC upgrade before giving up. */
27
+ /** How many times `dialWebRTC` tries a WebRTC upgrade under node-datachannel before giving up. */
28
28
  export const WEBRTC_UPGRADE_ATTEMPTS = 3;
29
+ /**
30
+ * How many attempts `dialWebRTC` makes by default: one where WebRTC is the
31
+ * runtime's own (a browser), `WEBRTC_UPGRADE_ATTEMPTS` elsewhere (Node, with
32
+ * node-datachannel). Read at each call, not at import.
33
+ *
34
+ * WHY ONE IN A BROWSER. The retry exists for a node-datachannel race (below),
35
+ * which a browser's WebRTC does not have. There, a path that cannot come up
36
+ * (symmetric NAT, UDP blocked) fails every attempt alike, each after libp2p's
37
+ * per-address dial timeout (6 s in libp2p 3), and the caller's relay fallback
38
+ * waits for all of them: measured in Chromium with UDP blocked, a Guest's join
39
+ * took 18 s, all of it in three timed-out upgrades, and 6 s with one.
40
+ *
41
+ * THE TEST IS THE GLOBAL, NOT THE IMPLEMENTATION libp2p PICKS (it picks by the
42
+ * package's `browser` field). Under Node they agree unless a process installs a
43
+ * global RTCPeerConnection (e.g. node-datachannel's polyfill assigned to
44
+ * `globalThis`): libp2p still runs node-datachannel there, and this would
45
+ * drop its retry. Pass `attempts` explicitly in such a process.
46
+ */
47
+ export function defaultWebRTCAttempts() {
48
+ return typeof globalThis.RTCPeerConnection === "function"
49
+ ? 1
50
+ : WEBRTC_UPGRADE_ATTEMPTS;
51
+ }
29
52
  /**
30
53
  * Dial a `/webrtc` address, trying the upgrade again when it fails.
31
54
  *
@@ -40,12 +63,13 @@ export const WEBRTC_UPGRADE_ATTEMPTS = 3;
40
63
  * load. Each attempt is an independent race, so one retry nearly always
41
64
  * succeeds. Fixed upstream by libdatachannel 0235225 ("start DTLS after
42
65
  * remote description"); drop the retry once node-datachannel ships it.
43
- * Browsers implement WebRTC themselves and are not affected.
66
+ * Browsers implement WebRTC themselves and are not affected, so they get one
67
+ * attempt (`defaultWebRTCAttempts`).
44
68
  *
45
69
  * A WebRTC path that cannot come up fails every attempt, and the caller's
46
70
  * fallback (the relay circuit) runs as before.
47
71
  */
48
- export async function dialWebRTC(node, target, attempts = WEBRTC_UPGRADE_ATTEMPTS) {
72
+ export async function dialWebRTC(node, target, attempts = defaultWebRTCAttempts()) {
49
73
  let lastError;
50
74
  for (let attempt = 1; attempt <= attempts; attempt++) {
51
75
  try {
package/dist/index.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
  export { createDuplexMounts, DUPLEX_PROTOCOL, type DuplexContext, type DuplexHandler, type DuplexMounts, NO_MOUNT, type OpenDuplexInit, openDuplex, type PeerDuplex, type ServeDuplexInit, serveDuplex, } from "./duplex.js";
18
18
  export { decodeHopAnswer, HOP_RESERVE_TIMEOUT_MS, HOP_STATUS_NAMES, HOP_STATUS_OK, type HopAnswer, RelayNotConnectedError, type RelayReservationGrant, RelayReservationRefusedError, requestRelayReservation, } from "./hop-reserve.js";
19
- export { dialWebRTC, HubReservationError, type HubReservationRefusal, hubRoute, leaveRelay, reachHub, reachHubRelayed, reserveOnHub, type SuperviseHubReservationInit, superviseHubReservation, WEBRTC_UPGRADE_ATTEMPTS, } from "./hub-link.js";
19
+ export { defaultWebRTCAttempts, dialWebRTC, HubReservationError, type HubReservationRefusal, hubRoute, leaveRelay, reachHub, reachHubRelayed, reserveOnHub, type SuperviseHubReservationInit, superviseHubReservation, WEBRTC_UPGRADE_ATTEMPTS, } from "./hub-link.js";
20
20
  export { HUB_MAX_RESERVATIONS, type HubRelayComponents, type HubRelayServiceInit, hubRelayService, type IsMember, membershipGater, releaseReservation, } from "./hub-relay.js";
21
21
  export { type BytesStore, decodeKey, encodeKey, type GenerateKeyInit, generateKey, type IdentityStore, type IdentityStoreInit, identityStore, peerIdOf, type SignerLike, signerOf, } from "./identity.js";
22
22
  export type { CallOnLimitedConnection } from "./link.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,QAAQ,EACR,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACb,KAAK,SAAS,EACd,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,eAAe,EACf,YAA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K,gBAAgB,GACtB,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,QAAQ,EACR,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACb,KAAK,SAAS,EACd,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,KAAK,2BAA2B,EAChC,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,eAAe,EACf,KAAK,QAAQ,EACb,eAAe,EACf,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,UAAU,EACf,SAAS,EACT,SAAS,EACT,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,aAAa,EACb,QAAQ,EACR,KAAK,UAAU,EACf,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACL,KAAK,YAAY,EACjB,YAAY,EACZ,2BAA2B,EAC3B,SAAS,EACT,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,4BAA4B,EAC5B,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,KAAK,kBAAkB,EACvB,cAAc,EACd,KAAK,6BAA6B,EAClC,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,QAAQ,EACR,KAAK,kBAAkB,EACvB,cAAc,EACd,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
  export { createDuplexMounts, DUPLEX_PROTOCOL, NO_MOUNT, openDuplex, serveDuplex, } from "./duplex.js";
18
18
  export { decodeHopAnswer, HOP_RESERVE_TIMEOUT_MS, HOP_STATUS_NAMES, HOP_STATUS_OK, RelayNotConnectedError, RelayReservationRefusedError, requestRelayReservation, } from "./hop-reserve.js";
19
- export { dialWebRTC, HubReservationError, hubRoute, leaveRelay, reachHub, reachHubRelayed, reserveOnHub, superviseHubReservation, WEBRTC_UPGRADE_ATTEMPTS, } from "./hub-link.js";
19
+ export { defaultWebRTCAttempts, dialWebRTC, HubReservationError, hubRoute, leaveRelay, reachHub, reachHubRelayed, reserveOnHub, superviseHubReservation, WEBRTC_UPGRADE_ATTEMPTS, } from "./hub-link.js";
20
20
  export { HUB_MAX_RESERVATIONS, hubRelayService, membershipGater, releaseReservation, } from "./hub-relay.js";
21
21
  export { decodeKey, encodeKey, generateKey, identityStore, peerIdOf, signerOf, } from "./identity.js";
22
22
  export { lastPeerIdOf } from "./multiaddr-parts.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/httpeers-libp2p",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "The transport: nodes, identity, and servePeer — the one place in the extraction that knows what libp2p is.",
6
6
  "bugs": {
@@ -50,11 +50,11 @@
50
50
  "@libp2p/webrtc": "^7.0.2",
51
51
  "@libp2p/websockets": "^10.1.21",
52
52
  "@multiformats/multiaddr": "^13.0.3",
53
- "@statewalker/webrun-http-streams": "^0.3.0",
54
- "@statewalker/webrun-streams": "^0.2.0",
53
+ "@statewalker/webrun-http-streams": "^0.3.1",
54
+ "@statewalker/webrun-streams": "^0.2.3",
55
55
  "@statewalker/webrun-streams-libp2p": "^0.1.6",
56
56
  "libp2p": "^3.5.1",
57
- "@statewalker/httpeers-bridge": "^0.2.0",
57
+ "@statewalker/httpeers-bridge": "^0.2.1",
58
58
  "@statewalker/httpeers-core": "^0.1.3"
59
59
  },
60
60
  "devDependencies": {
package/src/hub-link.ts CHANGED
@@ -28,9 +28,33 @@ export function hubRoute(hubPeerId: string, peerId: string): string {
28
28
  return `/p2p/${hubPeerId}/p2p-circuit/webrtc/p2p/${peerId}`;
29
29
  }
30
30
 
31
- /** How many times `dialWebRTC` tries a WebRTC upgrade before giving up. */
31
+ /** How many times `dialWebRTC` tries a WebRTC upgrade under node-datachannel before giving up. */
32
32
  export const WEBRTC_UPGRADE_ATTEMPTS = 3;
33
33
 
34
+ /**
35
+ * How many attempts `dialWebRTC` makes by default: one where WebRTC is the
36
+ * runtime's own (a browser), `WEBRTC_UPGRADE_ATTEMPTS` elsewhere (Node, with
37
+ * node-datachannel). Read at each call, not at import.
38
+ *
39
+ * WHY ONE IN A BROWSER. The retry exists for a node-datachannel race (below),
40
+ * which a browser's WebRTC does not have. There, a path that cannot come up
41
+ * (symmetric NAT, UDP blocked) fails every attempt alike, each after libp2p's
42
+ * per-address dial timeout (6 s in libp2p 3), and the caller's relay fallback
43
+ * waits for all of them: measured in Chromium with UDP blocked, a Guest's join
44
+ * took 18 s, all of it in three timed-out upgrades, and 6 s with one.
45
+ *
46
+ * THE TEST IS THE GLOBAL, NOT THE IMPLEMENTATION libp2p PICKS (it picks by the
47
+ * package's `browser` field). Under Node they agree unless a process installs a
48
+ * global RTCPeerConnection (e.g. node-datachannel's polyfill assigned to
49
+ * `globalThis`): libp2p still runs node-datachannel there, and this would
50
+ * drop its retry. Pass `attempts` explicitly in such a process.
51
+ */
52
+ export function defaultWebRTCAttempts(): number {
53
+ return typeof (globalThis as { RTCPeerConnection?: unknown }).RTCPeerConnection === "function"
54
+ ? 1
55
+ : WEBRTC_UPGRADE_ATTEMPTS;
56
+ }
57
+
34
58
  /**
35
59
  * Dial a `/webrtc` address, trying the upgrade again when it fails.
36
60
  *
@@ -45,7 +69,8 @@ export const WEBRTC_UPGRADE_ATTEMPTS = 3;
45
69
  * load. Each attempt is an independent race, so one retry nearly always
46
70
  * succeeds. Fixed upstream by libdatachannel 0235225 ("start DTLS after
47
71
  * remote description"); drop the retry once node-datachannel ships it.
48
- * Browsers implement WebRTC themselves and are not affected.
72
+ * Browsers implement WebRTC themselves and are not affected, so they get one
73
+ * attempt (`defaultWebRTCAttempts`).
49
74
  *
50
75
  * A WebRTC path that cannot come up fails every attempt, and the caller's
51
76
  * fallback (the relay circuit) runs as before.
@@ -53,7 +78,7 @@ export const WEBRTC_UPGRADE_ATTEMPTS = 3;
53
78
  export async function dialWebRTC(
54
79
  node: Libp2p,
55
80
  target: Multiaddr | Multiaddr[],
56
- attempts: number = WEBRTC_UPGRADE_ATTEMPTS,
81
+ attempts: number = defaultWebRTCAttempts(),
57
82
  ): Promise<Connection> {
58
83
  let lastError: unknown;
59
84
  for (let attempt = 1; attempt <= attempts; attempt++) {
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export {
40
40
  requestRelayReservation,
41
41
  } from "./hop-reserve.js";
42
42
  export {
43
+ defaultWebRTCAttempts,
43
44
  dialWebRTC,
44
45
  HubReservationError,
45
46
  type HubReservationRefusal,