werift 0.27.0 → 0.28.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/README.md +119 -8
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +12 -5
- package/lib/common/src/transport.js +3 -2
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/client.js +15 -1
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +2 -0
- package/lib/dtls/src/context/dtls.js +7 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +17 -1
- package/lib/dtls/src/context/transport.js +38 -2
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +4 -1
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +5 -0
- package/lib/dtls/src/flight/flight.js +10 -1
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +4 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/index.d.ts +3 -1
- package/lib/dtls/src/index.js +10 -1
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/const.d.ts +9 -0
- package/lib/dtls/src/record/const.js +9 -1
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +50 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/server.js +19 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +134 -2
- package/lib/dtls/src/socket.js +322 -6
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +49 -0
- package/lib/ice/src/consent.js +258 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/ice.d.ts +223 -71
- package/lib/ice/src/ice.js +873 -975
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +207 -8
- package/lib/ice/src/iceBase.js +94 -31
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +1 -0
- package/lib/ice/src/index.js +1 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
- package/lib/ice/src/internal/hostInterfaces.js +77 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
- package/lib/ice/src/nomination/selectionReplacement.js +371 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +9 -2
- package/lib/ice/src/stun/protocol.js +16 -17
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
- package/lib/ice/src/stun/tcpProtocol.js +7 -7
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.js +4 -2
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +2 -2
- package/lib/ice/src/turn/protocol.js +6 -3
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +16 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.js +4 -0
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +20 -1
- package/lib/ice-server/src/stun/const.js +9 -1
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +28 -1
- package/lib/ice-server/src/stun/message.js +102 -15
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/index.mjs +13394 -7732
- package/lib/nonstandard/index.mjs +680 -286
- package/lib/polyfill/dom.mjs +19605 -14243
- package/lib/polyfill/index.mjs +19605 -14243
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +14 -1
- package/lib/rtp/src/rtp/continuity.js +24 -4
- package/lib/rtp/src/rtp/continuity.js.map +1 -1
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/sctp/src/sctp.d.ts +5 -0
- package/lib/sctp/src/sctp.js +81 -47
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +348 -34
- package/lib/webrtc/src/api/peerConfig.js +90 -24
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +245 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +239 -51
- package/lib/webrtc/src/media/router.js +664 -237
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +222 -0
- package/lib/webrtc/src/media/rtpReceiver.js +668 -28
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +7 -0
- package/lib/webrtc/src/media/rtpSender.js +9 -3
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +18 -0
- package/lib/webrtc/src/media/rtpTransceiver.js +64 -2
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
- package/lib/webrtc/src/media/sender/senderStats.js +14 -19
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +9 -0
- package/lib/webrtc/src/media/track.js +9 -0
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +21 -0
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +35 -4
- package/lib/webrtc/src/negotiationTransaction.js +111 -8
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +65 -6
- package/lib/webrtc/src/peerConnection.js +283 -28
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.js +2 -0
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/sctpManager.js +4 -0
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +69 -0
- package/lib/webrtc/src/sdp.js +139 -14
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +85 -4
- package/lib/webrtc/src/sdpManager.js +214 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +38 -1
- package/lib/webrtc/src/secureTransportManager.js +82 -7
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +82 -4
- package/lib/webrtc/src/transceiverManager.js +231 -38
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +95 -1
- package/lib/webrtc/src/transport/dtls.js +324 -28
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +61 -4
- package/lib/webrtc/src/transport/ice.js +180 -11
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +23 -0
- package/lib/webrtc/src/transport/sctp.js +87 -2
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +33 -0
- package/lib/webrtc/src/utils.js +52 -3
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidateGatherer.js","sourceRoot":"","sources":["../../../../ice/src/candidateGatherer.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AACrC,2CAAgF;AAChF,qDAO0B;AAC1B,6CAAoD;AACpD,uCAMmB;AACnB,6CAAyE;AACzE,0DAAgE;AAChE,8DAAiE;AACjE,0EAIyC;AACzC,8CAA+C;AAC/C,oDAA2E;AAC3E,8CAA2D;AAG3D,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,0DAA0D,CAAC,CAAC;AA+C9E;;;;;;;GAOG;AACH,MAAa,iBAAiB;IAc5B,YAAY,IAAgB;QAb5B;;;WAGG;QACM;;;;mBAAoB,IAAI,OAAO,EAAyB;WAAC;QAClE;;;;WAIG;QACM;;;;mBAAoB,IAAI,GAAG,EAAuB;WAAC;QAC3C;;;;;WAAiB;QAGhC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CACf,aAA4B,EAC5B,OAAO,GAAG,CAAC,EACX,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EACnC,gBAAmC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAKtD,MAAM,OAAO,GAAuB,EAAE,CAAC;QACvC,oEAAoE;QACpE,MAAM,UAAU,GAAoD,EAAE,CAAC;QACvE,yEAAyE;QACzE,sEAAsE;QACtE,uCAAuC;QACvC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC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gB,CAAC,CAAC,CAAC,CAAC,EACxD,CAAC,EACD,KAAK,EACL,IAAA,6BAAiB,EAAC,OAAO,CAAC,EAC1B,gBAAgB,CAAC,CAAC,CAAC,EACnB,gBAAgB,CAAC,CAAC,CAAC,EACnB,OAAO,EACP,cAAc,CAAC,CAAC,CAAC,EACjB,cAAc,CAAC,CAAC,CAAC,EACjB,SAAS,EACT,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EACtB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAC1B,CAAC;QACF,mEAAmE;QACnE,mEAAmE;QACnE,kEAAkE;QAClE,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAExD,OAAO,QAAQ,CAAC,cAAc,CAAC;IACjC,CAAC;CACF;AAt8BD,8CAs8BC;AAED,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC,IAAA,YAAM,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9E,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC","sourcesContent":["import { isIPv4, isIPv6 } from \"net\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport {\n classifyGatherError,\n type GatherErrorContext,\n IceCandidateErrorCode,\n type IceServerRef,\n isServerAnswer,\n pickReportedGatherError,\n} from \"./candidateError\";\nimport { TransactionCancelled } from \"./exceptions\";\nimport {\n type IceOptions,\n isRelayOnlyGathering,\n type NormalizedTurnServer,\n queryServerReflexiveCandidate,\n type StunServerUrl,\n} from \"./iceBase\";\nimport { type Address, debug, interfaceAddress } from \"./imports/common\";\nimport { getRouteSourceAddress } from \"./internal/defaultRoute\";\nimport { hostLocalPreferences } from \"./internal/hostPreference\";\nimport {\n type HostAddress,\n HostAddressBind,\n normalizeIp,\n} from \"./internal/resolveHostAddresses\";\nimport { StunProtocol } from \"./stun/protocol\";\nimport { TcpActiveProtocol, TcpPassiveProtocol } from \"./stun/tcpProtocol\";\nimport { createStunOverTurnClient } from \"./turn/protocol\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/candidateGatherer.ts : log\");\n\n/** A failed STUN query / TURN allocation (see `Connection.onIceCandidateError`). */\ntype GatherFailure = { errorCode: number; errorText: string };\n\n/** What the agent supplies to its `CandidateGatherer`. */\nexport type GatherHost = {\n options: () => IceOptions;\n iceLite: () => boolean;\n /** The local generation the candidates belong to (read when each is made). */\n generation: () => number;\n localUsername: () => string;\n /** The agent's sockets and TURN allocations; new ones are pushed to it. */\n protocols: () => Protocol[];\n stunServers: () => Address[];\n turnServers: () => NormalizedTurnServer[];\n /**\n * The built-in default STUN server and the URL it is reported by, when\n * no STUN server is configured (see `DEFAULT_STUN_SERVER_URL`).\n */\n defaultStunServer: () => StunServerUrl | undefined;\n /** `generation` is still being gathered (no restart replaced it, the agent is open). */\n isGathering: (generation: number) => boolean;\n /** Aborted by close(): a TURN allocation still running is released. */\n closing: () => AbortSignal;\n /** Listen to the socket's checks and data. */\n ensureProtocol: (protocol: Protocol) => void;\n /** Pair a socket gathered after the remote candidates arrived. */\n pairLocalProtocol: (protocol: Protocol) => void;\n /** Report a local candidate. */\n appendLocalCandidate: (candidate: Candidate) => void;\n /** Report a failed STUN query / TURN allocation (`onIceCandidateError`). */\n emitCandidateError: (\n stale: () => boolean,\n generation: number,\n server: IceServerRef,\n failure: GatherFailure | undefined,\n local?: { address: string; port: number },\n ) => void;\n /** Report a STUN / TURN server that answered (`onIceServerReached`). */\n emitServerReached: (\n stale: () => boolean,\n generation: number,\n server: IceServerRef,\n ) => void;\n};\n\n/**\n * Candidate gathering of one agent (RFC 8445 §5.1.1): a UDP socket per host\n * address (kept across ICE restarts), TCP passive / active candidates\n * (RFC 6544), server-reflexive candidates from every STUN server (through\n * the host sockets and, in default mode, a wildcard socket per family), and\n * a relay candidate from every TURN server. Failed STUN / TURN servers are\n * reported through the host (`emitCandidateError`).\n */\nexport class CandidateGatherer {\n /**\n * Server-reflexive candidates each UDP socket advertised in its last\n * gathering (one per distinct mapping its STUN servers returned).\n */\n readonly reflexiveBySocket = new WeakMap<Protocol, Candidate[]>();\n /**\n * The wildcard UDP socket of each family (default mode with a STUN server).\n * It advertises no host candidate; its first server-reflexive candidate is\n * its local candidate. Kept across ICE restarts like the host sockets.\n */\n readonly wildcardProtocols = new Map<4 | 6, StunProtocol>();\n private readonly host: GatherHost;\n\n constructor(host: GatherHost) {\n this.host = host;\n }\n\n /**\n * The gathering work of one generation.\n *\n * - `primary`: what gathering waits for. The host sockets, the TURN\n * allocations and the server-reflexive queries of the representative\n * sockets: the wildcard socket of each family and the host socket of\n * the default-route address (every host socket when the family has\n * neither).\n * - `background`: the server-reflexive queries of the other host sockets,\n * complete once `primary` has settled. Their candidates trickle after\n * gathering returns; end-of-candidates (`localCandidatesEnd`) waits for\n * them. A network interface whose address cannot reach the STUN server\n * so no longer delays gathering.\n */\n candidatePromises(\n hostAddresses: HostAddress[],\n timeout = 5,\n generation = this.host.generation(),\n defaultRoutes: Promise<string[]> = Promise.resolve([]),\n ): {\n primary: Promise<unknown>[];\n background: { query: Promise<unknown>; settled: boolean }[];\n } {\n const primary: Promise<unknown>[] = [];\n // Filled while the primary work runs; complete once it has settled.\n const background: { query: Promise<unknown>; settled: boolean }[] = [];\n // Each continuation below runs after an await: a socket or allocation it\n // opened for a replaced generation (or a closed agent) is closed, and\n // nothing is added to the current one.\n const stale = () => !this.host.isGathering(generation);\n const stunServers = this.host.stunServers();\n const turnServers = this.host.turnServers();\n const { interfaceAddresses } = this.host.options();\n const gatherIceLite = this.host.iceLite();\n const gatherRelayOnly = isRelayOnlyGathering(this.host.options());\n // Local preferences over the whole host list (the sockets an ICE restart\n // keeps included), so they stay distinct across generations.\n const localPreferenceOf = defaultRoutes.then((routes) => {\n const preferences = hostLocalPreferences(hostAddresses, routes);\n return new Map(\n hostAddresses.map(({ address }, i) => [\n normalizeIp(address),\n preferences[i],\n ]),\n );\n });\n\n // TCP host candidates are kept per address like the UDP ones, but on\n // their own: a restart that turned useTcp on gathers them for addresses\n // whose UDP sockets were kept.\n const tcpAddresses = hostAddresses\n .map(({ address }) => address)\n .filter(\n (address) =>\n !this.host\n .protocols()\n .some(\n (protocol) =>\n protocol.localCandidate?.transport.toLowerCase() === \"tcp\" &&\n protocol.localIp === address,\n ),\n );\n const addresses = hostAddresses.filter(({ address }) => {\n // ice restartで同じアドレスが追加されるのを防ぐ\n // (localIp is the bound address, whose IPv6 notation may differ)\n if (\n this.host\n .protocols()\n .find(\n (protocol) =>\n protocol.localIp !== undefined &&\n normalizeIp(protocol.localIp) === normalizeIp(address),\n )\n ) {\n return false;\n }\n // A family bound to an interface address has one UDP host socket; its\n // localIp is the bound address, whose notation may differ (IPv6).\n if (\n interfaceAddress(socketTypeOf(address), interfaceAddresses) ===\n address &&\n this.host\n .protocols()\n .some(\n (protocol) =>\n protocol instanceof StunProtocol &&\n protocol.localCandidate?.type === \"host\" &&\n isIPv4(protocol.localCandidate.host) === isIPv4(address),\n )\n ) {\n return false;\n }\n return true;\n });\n // An ICE restart keeps its UDP sockets. They are not re-created above, but\n // their server-reflexive address is part of the new generation too, so\n // the STUN query below runs for them as well.\n const reusedStunProtocols = this.host\n .protocols()\n .filter(\n (protocol): protocol is StunProtocol =>\n protocol instanceof StunProtocol &&\n protocol.localCandidate?.type === \"host\" &&\n protocol.localCandidate.transport === \"udp\",\n );\n\n const localStunPromises = gatherRelayOnly\n ? []\n : addresses.map(async ({ address, bind, bindAddress }) => {\n // # create transport\n const protocol = new StunProtocol();\n this.host.ensureProtocol(protocol);\n // An explicit interface address or an enumerated local address is\n // bound to, so packets of the socket leave from the advertised\n // address (a wildcard socket's source follows the routing table).\n const boundInterface =\n bind === HostAddressBind.explicit\n ? interfaceAddress(socketTypeOf(address), interfaceAddresses)\n : bind === HostAddressBind.enumerated\n ? bindAddress\n : undefined;\n try {\n await protocol.connectionMade(\n isIPv4(address),\n this.host.options().portRange,\n interfaceAddresses,\n bind === HostAddressBind.enumerated ? { bindAddress } : {},\n );\n const localPreference = (await localPreferenceOf).get(\n normalizeIp(address),\n );\n if (stale()) {\n await protocol.close();\n return;\n }\n\n // # add host candidate\n // A socket bound to an address advertises the bound address: the\n // peer sends its checks there and the socket's packets leave from\n // it. A wildcard socket advertises the gathered address (never\n // 0.0.0.0 / ::).\n const [boundHost, boundPort] = protocol.getExtraInfo();\n let candidateHost = address;\n if (boundInterface) {\n candidateHost = stripZoneId(boundHost);\n if (normalizeIp(candidateHost) !== normalizeIp(address)) {\n log(\n \"host address differs from the bound interface address; advertise the bound one\",\n address,\n candidateHost,\n );\n }\n }\n const candidateAddress: Address = [candidateHost, boundPort];\n\n protocol.localIp = candidateHost;\n this.host.protocols().push(protocol);\n\n log(\"protocol\", protocol.localIp);\n\n protocol.localCandidate = new Candidate(\n candidateFoundation(\"host\", \"udp\", candidateAddress[0]),\n 1,\n \"udp\",\n candidatePriority(\"host\", {\n transport: \"udp\",\n localPreference,\n }),\n candidateAddress[0],\n candidateAddress[1],\n \"host\",\n undefined,\n undefined,\n undefined,\n this.host.generation(),\n this.host.localUsername(),\n );\n\n this.host.pairLocalProtocol(protocol);\n this.host.appendLocalCandidate(protocol.localCandidate);\n\n return protocol;\n } catch (error) {\n if (boundInterface) {\n // No host candidate for this address: advertising it from\n // another (wildcard) socket would mislead the peer. Candidates\n // of the other addresses are gathered independently.\n log(\n \"failed to bind UDP socket to host address\",\n boundInterface,\n error,\n );\n } else {\n log(\"error protocol STUN\", error);\n }\n }\n });\n\n if (!gatherRelayOnly) {\n primary.push(\n ...localStunPromises.map((localPromise) =>\n localPromise.then((protocol) => protocol?.localCandidate),\n ),\n );\n }\n if (!gatherRelayOnly && this.host.options().useTcp) {\n const tcpCandidatePromises = tcpAddresses.map(async (address) => {\n // Passive candidates open a listening TCP server; skip them when the\n // agent only makes outbound connections (tcpPassive === false). Active\n // candidates below still dial out, so direct TCP egress is unaffected.\n if (this.host.options().tcpPassive !== false) {\n const passiveProtocol = new TcpPassiveProtocol();\n this.host.ensureProtocol(passiveProtocol);\n await passiveProtocol.connectionMade(\n address,\n this.host.options().portRange,\n );\n if (stale()) {\n await passiveProtocol.close();\n return;\n }\n passiveProtocol.localIp = address;\n passiveProtocol.localCandidate = new Candidate(\n candidateFoundation(\"host\", \"tcp\", address),\n 1,\n \"tcp\",\n candidatePriority(\"host\", {\n transport: \"tcp\",\n tcptype: \"passive\",\n }),\n address,\n passiveProtocol.listeningPort,\n \"host\",\n undefined,\n undefined,\n \"passive\",\n this.host.generation(),\n this.host.localUsername(),\n );\n this.host.protocols().push(passiveProtocol);\n this.host.appendLocalCandidate(passiveProtocol.localCandidate);\n }\n\n if (!gatherIceLite) {\n const activeProtocol = new TcpActiveProtocol();\n this.host.ensureProtocol(activeProtocol);\n await activeProtocol.connectionMade(address);\n if (stale()) {\n await activeProtocol.close();\n return;\n }\n activeProtocol.localIp = address;\n activeProtocol.localCandidate = new Candidate(\n candidateFoundation(\"host\", \"tcp\", address),\n 1,\n \"tcp\",\n candidatePriority(\"host\", {\n transport: \"tcp\",\n tcptype: \"active\",\n }),\n address,\n 9,\n \"host\",\n undefined,\n undefined,\n \"active\",\n this.host.generation(),\n this.host.localUsername(),\n );\n this.host.protocols().push(activeProtocol);\n this.host.pairLocalProtocol(activeProtocol);\n this.host.appendLocalCandidate(activeProtocol.localCandidate);\n }\n });\n\n primary.push(...tcpCandidatePromises);\n }\n\n // The application's names of the STUN servers this gathering queries;\n // the built-in default one, in no configuration, gets a synthesized URL.\n const defaultStunServer = this.host.defaultStunServer();\n const stunServerUrls: StunServerUrl[] = [\n ...(this.host.options().stunServerUrls ?? []),\n ...(defaultStunServer ? [defaultStunServer] : []),\n ];\n const stunServerRef = (server: Address): IceServerRef => {\n const urls = [\n ...new Set(\n stunServerUrls\n .filter(\n (entry) =>\n entry?.address?.[0] === server[0] &&\n entry.address[1] === server[1],\n )\n .map((entry) => entry.url),\n ),\n ];\n return urls.length > 0\n ? { kind: \"stun\", address: server, urls }\n : { kind: \"stun\", address: server };\n };\n const stunContext: GatherErrorContext = { kind: \"stun\" };\n\n // W3C: a 701 means no host candidate reached the server. Every socket\n // path (a kept socket, a new socket) settles each STUN server once; a\n // server none of them reached (no answer, no error response) is\n // reported once, with the first such failure, when the last path\n // settled. A server's error response is reported per socket at once.\n type StunServerOutcome = {\n pending: number;\n reached: boolean;\n unreached?: {\n failure: { errorCode: number; errorText: string };\n local?: { address: string; port: number };\n };\n };\n const stunOutcomes = new Map<Address, StunServerOutcome>();\n const hostStunPathCount =\n reusedStunProtocols.filter((protocol) =>\n isIPv4(protocol.localCandidate!.host),\n ).length + localStunPromises.length;\n const defaultMode = !interfaceAddresses?.udp4 && !interfaceAddresses?.udp6;\n const wildcardFamilies = ([4, 6] as const).filter(\n (family) =>\n defaultMode &&\n (family === 4\n ? this.host.options().useIpv4\n : this.host.options().useIpv6) &&\n this.reflexiveServersOf(family).length > 0,\n );\n for (const server of stunServers) {\n const wildcardPaths = wildcardFamilies.filter((family) =>\n this.reflexiveServersOf(family).some(\n (candidate) =>\n candidate[0] === server[0] && candidate[1] === server[1],\n ),\n ).length;\n stunOutcomes.set(server, {\n pending: hostStunPathCount + wildcardPaths,\n reached: false,\n });\n }\n const settleStunServer = (\n server: Address,\n outcome: StunServerOutcome[\"unreached\"] | \"reached\" | \"skipped\",\n ) => {\n const state = stunOutcomes.get(server);\n if (!state || state.pending === 0) return;\n state.pending--;\n if (outcome === \"reached\") state.reached = true;\n else if (outcome && outcome !== \"skipped\") {\n if (!state.unreached || (!state.unreached.local && outcome.local)) {\n state.unreached = outcome;\n }\n }\n if (state.pending === 0 && !state.reached && state.unreached) {\n this.host.emitCandidateError(\n stale,\n generation,\n stunServerRef(server),\n state.unreached.failure,\n state.unreached.local,\n );\n }\n };\n /**\n * One counted path toward `servers`: settles every one of them `query`\n * did not settle (a socket that does not query: an IPv6 socket, one\n * that failed to open, a stale generation). Called synchronously while\n * the paths are set up, so stunPaths holds every path.\n */\n const stunPaths: Promise<unknown>[] = [];\n const settlingStunServers = <T>(\n query: (settled: Set<Address>) => Promise<T>,\n servers = stunServers,\n ) => {\n const settled = new Set<Address>();\n const path = (async () => {\n try {\n return await query(settled);\n } finally {\n for (const server of servers) {\n if (!settled.has(server)) settleStunServer(server, \"skipped\");\n }\n }\n })();\n stunPaths.push(path.catch(() => undefined));\n return path;\n };\n /**\n * Backstop once every path ended: a server still pending (a path that\n * was counted but never settled it) is judged now, so its 701 is not\n * lost to a counting mismatch.\n */\n const judgeRemainingStunServers = () => {\n void Promise.allSettled(stunPaths).then(() => {\n for (const [server, state] of stunOutcomes) {\n if (state.pending === 0) continue;\n log(\"STUN server still pending after every path ended\", server);\n state.pending = 1;\n settleStunServer(server, \"skipped\");\n }\n });\n };\n\n // A server-reflexive query of one socket to one STUN server, bounded by\n // the STUN gather timeout; an unanswered or failed one yields nothing.\n // The first of its failure and the timeout decides, a late result is\n // ignored; the outcome settles the server for this socket (above).\n const queryReflexive = async (\n protocol: StunProtocol,\n server: Address,\n settled?: Set<Address>,\n ) => {\n const local = protocol.localCandidate\n ? {\n address: protocol.localCandidate.host,\n port: protocol.localCandidate.port,\n }\n : undefined;\n // The first of the query's outcome and the timeout settles it.\n let settledQuery = false;\n // Assigned in the callbacks below (not narrowed by the initializer).\n let outcome = \"skipped\" as\n | StunServerOutcome[\"unreached\"]\n | \"reached\"\n | \"skipped\";\n const fail = (failure: { errorCode: number; errorText: string }) => {\n if (failure.errorCode === IceCandidateErrorCode.SERVER_NOT_REACHED) {\n outcome = { failure, local };\n return;\n }\n // The server answered: it was reached, its error is reported now.\n outcome = \"reached\";\n this.host.emitCandidateError(\n stale,\n generation,\n stunServerRef(server),\n failure,\n local,\n );\n };\n let timer: ReturnType<typeof setTimeout> | undefined;\n const candidate = await Promise.race([\n queryServerReflexiveCandidate(\n protocol,\n server,\n this.wildcardBaseOf(protocol),\n ).then(\n (candidate): Candidate | undefined => {\n if (!settledQuery) outcome = \"reached\";\n settledQuery = true;\n return candidate;\n },\n (error) => {\n log(\"query STUN server\", server, error);\n if (!settledQuery) {\n settledQuery = true;\n const failure = classifyGatherError(error, stunContext);\n if (failure) fail(failure);\n // Answers without a reportable STUN error still prove reachability.\n else if (isServerAnswer(error)) outcome = \"reached\";\n }\n return undefined;\n },\n ),\n new Promise<undefined>((resolve) => {\n timer = setTimeout(() => {\n if (settledQuery) return;\n settledQuery = true;\n log(\"query STUN server timed out\", server);\n fail({\n errorCode: IceCandidateErrorCode.SERVER_NOT_REACHED,\n errorText: \"STUN binding request timed out\",\n });\n resolve(undefined);\n }, timeout * 1000);\n }),\n ]);\n clearTimeout(timer);\n if (outcome === \"reached\") {\n this.host.emitServerReached(stale, generation, stunServerRef(server));\n }\n if (settled) {\n settled.add(server);\n settleStunServer(server, outcome);\n }\n return candidate;\n };\n // RFC 8445 §5.1.3: a mapping equal to one the socket already advertised\n // (same base, same transport address) is redundant.\n const sameMapping = (a: Candidate, b: Candidate) =>\n a.host === b.host && a.port === b.port;\n\n if (!gatherIceLite && !gatherRelayOnly && stunServers.length > 0) {\n // # wildcard sockets\n // In the default mode (no interfaceAddresses) every family with a STUN\n // server gets one more UDP socket bound to the wildcard address. It\n // advertises no host candidate; the OS picks its route, so it maps\n // even when the only way out is an interface the host sockets do not\n // cover, and it receives whatever reaches its port (a DNAT to another\n // local address, an address added after gathering).\n const wildcardReady = new Map<4 | 6, Promise<boolean>>();\n for (const family of wildcardFamilies) {\n const kept = this.wildcardProtocols.get(family);\n if (kept && this.host.protocols().includes(kept)) {\n // Kept across an ICE restart: queried again with the reused sockets.\n wildcardReady.set(family, Promise.resolve(true));\n continue;\n }\n // One still opening for a replaced generation is not reused.\n if (kept) {\n this.wildcardProtocols.delete(family);\n void kept.close().catch(() => {});\n }\n const wildcardServers = this.reflexiveServersOf(family);\n const query = settlingStunServers(\n (settled) =>\n this.gatherWildcardReflexive(\n family,\n (protocol, server) => queryReflexive(protocol, server, settled),\n sameMapping,\n stale,\n ),\n wildcardServers,\n );\n wildcardReady.set(\n family,\n query.then(({ bound }) => bound),\n );\n primary.push(query);\n }\n\n // Sockets kept across an ICE restart query every STUN server again.\n // The mappings they already advertised are in the new generation from\n // the start; a different fresh mapping (the NAT rebound) is added to\n // it, and the fresh mappings replace the kept ones for the next restart.\n const reflexiveOfReused = (protocol: StunProtocol) =>\n settlingStunServers(async (settled) => {\n const previous = this.reflexiveBySocket.get(protocol) ?? [];\n const advertised = [...previous];\n const fresh: Candidate[] = [];\n await Promise.all(\n this.reflexiveServersOf(protocol).map(async (server) => {\n const candidate = await queryReflexive(protocol, server, settled);\n if (!candidate || stale()) return;\n if (!fresh.some((known) => sameMapping(known, candidate))) {\n fresh.push(candidate);\n }\n if (advertised.some((known) => sameMapping(known, candidate)))\n return;\n advertised.push(candidate);\n this.host.appendLocalCandidate(candidate);\n }),\n );\n if (stale()) return;\n if (fresh.length > 0) this.reflexiveBySocket.set(protocol, fresh);\n return fresh.length > 0 ? fresh : previous;\n }, this.reflexiveServersOf(protocol)).catch((error) => {\n log(\"query reused STUN socket\", error);\n });\n\n // The queries of a new socket; its path (settlingStunServers) is\n // opened before the socket is, see newHosts.\n const reflexiveOfNew = async (\n protocol: StunProtocol,\n settled: Set<Address>,\n ) => {\n const advertised: Candidate[] = [];\n await Promise.all(\n stunServers.map(async (server) => {\n const candidate = await queryReflexive(protocol, server, settled);\n if (!candidate || stale()) return;\n if (advertised.some((known) => sameMapping(known, candidate)))\n return;\n advertised.push(candidate);\n this.reflexiveBySocket.set(protocol, advertised);\n this.host.appendLocalCandidate(candidate);\n }),\n ).catch((error) => {\n log(\"query new STUN socket\", error);\n });\n return advertised;\n };\n\n // A kept wildcard socket is a representative: gathering waits for it.\n const reusedWildcards = [...this.wildcardProtocols.values()].filter(\n (protocol) => this.host.protocols().includes(protocol),\n );\n primary.push(...reusedWildcards.map(reflexiveOfReused));\n\n // The host sockets' queries start at once. The representative ones\n // (the default-route address; every socket when the family has neither\n // a wildcard socket nor a default-route socket) are waited for, the\n // others run in the background.\n type HostQuery = { protocol: StunProtocol; query: Promise<unknown> };\n const track = (protocol: StunProtocol, query: Promise<unknown>) => {\n const entry = { protocol, query, settled: false };\n void query.finally(() => {\n entry.settled = true;\n });\n return entry;\n };\n const reusedHosts: HostQuery[] = reusedStunProtocols\n .filter((protocol) => isIPv4(protocol.localCandidate!.host))\n .map((protocol) => track(protocol, reflexiveOfReused(protocol)));\n // Every new socket is counted for every STUN server (stunOutcomes),\n // so its path opens now, before the socket does: a socket that does\n // not query (IPv6, failed to open) settles them as skipped.\n const newHosts = Promise.all(\n localStunPromises.map((protocolPromise) => {\n let resolveEntry!: (entry: HostQuery | undefined) => void;\n const entry = new Promise<HostQuery | undefined>((resolve) => {\n resolveEntry = resolve;\n });\n settlingStunServers(async (settled) => {\n const protocol = await Promise.resolve(protocolPromise).catch(\n () => undefined,\n );\n if (\n !protocol?.localCandidate ||\n !isIPv4(protocol.localCandidate.host)\n ) {\n resolveEntry(undefined);\n return;\n }\n const query = reflexiveOfNew(protocol, settled);\n resolveEntry(track(protocol, query));\n await query;\n }).catch((error) => {\n resolveEntry(undefined);\n log(\"query new STUN socket\", error);\n });\n return entry;\n }),\n );\n judgeRemainingStunServers();\n primary.push(\n (async () => {\n const queries = [\n ...reusedHosts,\n ...(await newHosts).filter((entry) => entry !== undefined),\n ] as (HostQuery & { settled: boolean })[];\n const routes = (await defaultRoutes).map(normalizeIp);\n const defaultRouteQueries = queries.filter(({ protocol }) =>\n routes.includes(normalizeIp(protocol.localCandidate!.host)),\n );\n const representative =\n defaultRouteQueries.length > 0 || (await wildcardReady.get(4))\n ? defaultRouteQueries\n : queries;\n // Filled before this primary work settles: gatherCandidates()\n // reads it then.\n background.push(\n ...queries.filter((entry) => !representative.includes(entry)),\n );\n await Promise.allSettled(representative.map(({ query }) => query));\n })(),\n );\n }\n\n if (!gatherIceLite) {\n // Every TURN server gets its own allocation, made with its own\n // credential and transport; one that fails does not stop the others.\n // A TURN allocation has its own UDP socket, bound to the wildcard\n // address unless interfaceAddresses binds the family: the OS picks\n // its route as for the wildcard STUN socket.\n const turnCandidatePromises = turnServers.map((server) =>\n this.gatherRelayCandidate(\n server,\n gatherRelayOnly,\n stale,\n generation,\n ).catch((error) => {\n log(\"query TURN server\", server.address, error);\n }),\n );\n primary.push(...turnCandidatePromises);\n }\n\n return { primary, background };\n }\n\n /**\n * Open the wildcard socket of `family` and query the STUN servers from it.\n * Its first server-reflexive candidate becomes the socket's local\n * candidate: the socket joins the agent and pairs with the remote\n * candidates (its checks leave through the NAT mapping it advertised).\n * A socket that maps nothing is closed.\n */\n private async gatherWildcardReflexive(\n family: 4 | 6,\n queryReflexive: (\n protocol: StunProtocol,\n server: Address,\n ) => Promise<Candidate | undefined>,\n sameMapping: (a: Candidate, b: Candidate) => boolean,\n stale: () => boolean,\n ): Promise<{ bound: boolean }> {\n const protocol = new StunProtocol();\n try {\n // No interfaceAddresses / bindAddress: the wildcard address.\n await protocol.connectionMade(\n family === 4,\n this.host.options().portRange,\n );\n } catch (error) {\n log(\"failed to bind the wildcard UDP socket\", family, error);\n return { bound: false };\n }\n if (stale()) {\n await protocol.close();\n return { bound: true };\n }\n this.wildcardProtocols.set(family, protocol);\n\n const advertised: Candidate[] = [];\n await Promise.all(\n this.reflexiveServersOf(family).map(async (server) => {\n const candidate = await queryReflexive(protocol, server);\n if (!candidate || stale() || !this.isWildcardProtocol(protocol)) return;\n if (advertised.some((known) => sameMapping(known, candidate))) {\n return;\n }\n advertised.push(candidate);\n this.reflexiveBySocket.set(protocol, advertised);\n if (!protocol.localCandidate) {\n protocol.localCandidate = candidate;\n protocol.localIp = family === 4 ? \"0.0.0.0\" : \"::\";\n this.host.ensureProtocol(protocol);\n this.host.protocols().push(protocol);\n this.host.pairLocalProtocol(protocol);\n }\n this.host.appendLocalCandidate(candidate);\n }),\n );\n if (!protocol.localCandidate) {\n if (this.wildcardProtocols.get(family) === protocol) {\n this.wildcardProtocols.delete(family);\n }\n await protocol.close();\n }\n return { bound: true };\n }\n\n /** Whether `protocol` is a wildcard socket (advertises no host candidate). */\n isWildcardProtocol(protocol: Protocol) {\n for (const wildcard of this.wildcardProtocols.values()) {\n if (wildcard === protocol) return true;\n }\n return false;\n }\n\n /**\n * Whether the wildcard socket should check `remoteCandidate`: only a path\n * no host socket covers. When the OS routes to the remote address from an\n * address a UDP host socket is bound to, that socket checks the same path\n * (through a NAT as its own server-reflexive address), while the wildcard\n * socket's packets would leave from an address it does not advertise and\n * make the peer learn a peer-reflexive candidate. Without a route the\n * socket cannot reach the address either.\n */\n async wildcardPathUncovered(remoteCandidate: Candidate) {\n const source = await getRouteSourceAddress(remoteCandidate.host);\n if (!source) return false;\n return !this.host\n .protocols()\n .some(\n (protocol) =>\n protocol instanceof StunProtocol &&\n protocol.localCandidate?.type === \"host\" &&\n protocol.localCandidate.transport === \"udp\" &&\n normalizeIp(protocol.localCandidate.host) === normalizeIp(source),\n );\n }\n\n /** The base of a wildcard socket's server-reflexive candidates. */\n private wildcardBaseOf(protocol: StunProtocol) {\n if (!this.isWildcardProtocol(protocol)) return undefined;\n const [host, port] = protocol.getExtraInfo();\n return {\n host: isIPv6(stripZoneId(host)) ? \"::\" : \"0.0.0.0\",\n port,\n transport: \"udp\",\n component: 1,\n };\n }\n\n /**\n * The STUN servers a socket (or the wildcard socket of a family) queries:\n * every server for IPv4 (as the IPv4 host sockets always did), only the\n * IPv6 literal servers for the IPv6 wildcard socket.\n */\n private reflexiveServersOf(target: StunProtocol | 4 | 6) {\n const family =\n typeof target === \"number\"\n ? target\n : this.isWildcardProtocol(target) &&\n isIPv6(stripZoneId(target.getExtraInfo()[0]))\n ? 6\n : 4;\n return family === 4\n ? this.host.stunServers()\n : this.host.stunServers().filter(([host]) => isIPv6(host));\n }\n\n /**\n * Allocate on one TURN server and add its relay candidate. A UDP\n * allocation that fails falls back to TCP on the same server. An\n * allocation that completes for a replaced generation (or a closed agent)\n * is released. A failed allocation (both attempts, for the fallback) is\n * reported once (onIceCandidateError) before it rejects.\n */\n private async gatherRelayCandidate(\n server: NormalizedTurnServer,\n relayOnly: boolean,\n stale: () => boolean,\n generation = this.host.generation(),\n ) {\n const { address, username, password, transport } = server;\n // Failures of the attempts at this server (UDP, then TCP fallback), and\n // whether any attempt got an answer from it (reached, even without a\n // STUN error code to report).\n const failures: ({ errorCode: number; errorText: string } | undefined)[] =\n [];\n let answered = false;\n const recordFailure = (\n error: unknown,\n attemptTransport: \"udp\" | \"tcp\" | \"tls\",\n ) => {\n if (isServerAnswer(error)) answered = true;\n failures.push(\n classifyGatherError(error, {\n kind: \"turn\",\n transport: attemptTransport,\n // Masked out of the server's reason phrase.\n secrets: [username, password],\n }),\n );\n };\n const ref: IceServerRef = {\n kind: \"turn\",\n address,\n transport,\n ...(server.urls ? { urls: [...server.urls] } : {}),\n };\n const protocol = await createStunOverTurnClient(\n { address, username, password },\n {\n portRange: this.host.options().portRange,\n interfaceAddresses: this.host.options().interfaceAddresses,\n transport,\n tlsOptions: this.host.options().turnTlsOptions,\n connectTimeoutMs: (this.host.options().turnConnectTimeout ?? 8) * 1000,\n udpFamily: this.host.options().turnUdpFamily,\n signal: this.host.closing(),\n },\n )\n .catch(async (e) => {\n recordFailure(e, transport);\n // close() cancelled the allocation: no TCP fallback.\n if (transport === \"udp\" && !this.host.closing().aborted) {\n return await createStunOverTurnClient(\n { address, username, password },\n {\n portRange: this.host.options().portRange,\n interfaceAddresses: this.host.options().interfaceAddresses,\n transport: \"tcp\",\n connectTimeoutMs:\n (this.host.options().turnConnectTimeout ?? 8) * 1000,\n signal: this.host.closing(),\n },\n ).catch((fallbackError) => {\n recordFailure(fallbackError, \"tcp\");\n throw fallbackError;\n });\n }\n throw e;\n })\n .catch((error) => {\n // A cancelled attempt (close) is not a failure of the server.\n if (\n error instanceof TransactionCancelled ||\n this.host.closing().aborted\n ) {\n throw error;\n }\n const reported = pickReportedGatherError(failures);\n const reachedServer =\n answered ||\n (reported !== undefined &&\n reported.errorCode !== IceCandidateErrorCode.SERVER_NOT_REACHED);\n // A server that answered is never reported as 701 (an attempt that\n // was not answered does not make it unreached).\n if (\n reported &&\n (reported.errorCode !== IceCandidateErrorCode.SERVER_NOT_REACHED ||\n !reachedServer)\n ) {\n this.host.emitCandidateError(stale, generation, ref, reported);\n }\n if (reachedServer) this.host.emitServerReached(stale, generation, ref);\n throw error;\n });\n if (stale()) {\n // The allocation never joins a generation: release it (and its\n // refresh timer) instead of keeping a second one alive.\n await protocol.close();\n return;\n }\n this.host.emitServerReached(stale, generation, ref);\n protocol.configuredTransport = transport;\n this.host.ensureProtocol(protocol);\n this.host.protocols().push(protocol);\n\n const candidateAddress = protocol.turn.relayedAddress;\n // The related address of a relay candidate is the address the TURN\n // server saw the agent at. A relay-only policy hides the agent's\n // addresses from the peer, so it advertises the unspecified address\n // and port 9 instead (RFC 8839 §5.1), in SDP and trickle alike.\n const relatedAddress: Address = relayOnly\n ? [isIPv4(candidateAddress[0]) ? \"0.0.0.0\" : \"::\", 9]\n : protocol.turn.mappedAddress;\n\n log(\"turn candidateAddress\", candidateAddress);\n\n protocol.localCandidate = new Candidate(\n candidateFoundation(\"relay\", \"udp\", candidateAddress[0]),\n 1,\n \"udp\",\n candidatePriority(\"relay\"),\n candidateAddress[0],\n candidateAddress[1],\n \"relay\",\n relatedAddress[0],\n relatedAddress[1],\n undefined,\n this.host.generation(),\n this.host.localUsername(),\n );\n // An allocation that completes after the remote candidates arrived\n // (early signaling, or an ICE restart that allocates afresh) pairs\n // with them; a connect() already running schedules the new pairs.\n this.host.pairLocalProtocol(protocol);\n this.host.appendLocalCandidate(protocol.localCandidate);\n\n return protocol.localCandidate;\n }\n}\n\nconst socketTypeOf = (address: string) => (isIPv4(address) ? \"udp4\" : \"udp6\");\nconst stripZoneId = (address: string) => address.split(\"%\")[0];\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type CandidatePair, type IceState } from "./iceBase";
|
|
2
|
+
import type { MessageIntegrityMode } from "./stun/const";
|
|
3
|
+
import type { Message } from "./stun/message";
|
|
4
|
+
/** What the agent supplies to its `ConsentFreshness`. */
|
|
5
|
+
export type ConsentHost = {
|
|
6
|
+
/** The selected pair: consent checks go to it. */
|
|
7
|
+
selected: () => CandidatePair | undefined;
|
|
8
|
+
state: () => IceState;
|
|
9
|
+
setState: (state: IceState) => void;
|
|
10
|
+
/** Answers of an earlier remote generation (an ICE restart) do not count. */
|
|
11
|
+
remoteGeneration: () => number;
|
|
12
|
+
remotePassword: () => string;
|
|
13
|
+
/** A local ICE-lite agent sends no consent checks. */
|
|
14
|
+
iceLite: () => boolean;
|
|
15
|
+
integrityAlgorithm: () => MessageIntegrityMode | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The consent check for `pair`, with what the nomination mode puts on it
|
|
18
|
+
* (USE-CANDIDATE, NOMINATION).
|
|
19
|
+
*/
|
|
20
|
+
buildRequest: (pair: CandidatePair) => Message;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* RFC 7675 consent freshness of the selected pair: a binding request every
|
|
24
|
+
* `CONSENT_INTERVAL` (randomized, measured between request starts), each
|
|
25
|
+
* response refreshes the consent, and `CONSENT_TIMEOUT` without one fails
|
|
26
|
+
* the agent. `start()` begins a session (the successful check that selected
|
|
27
|
+
* the pair counts as the first response); `stop()` ends it without changing
|
|
28
|
+
* the agent's state. A session id invalidates the callbacks of an ended
|
|
29
|
+
* session (restart, close, a replaced selection, expiry).
|
|
30
|
+
*/
|
|
31
|
+
export declare class ConsentFreshness {
|
|
32
|
+
/** Consent-to-send: application data may use the selected pair. */
|
|
33
|
+
fresh: boolean;
|
|
34
|
+
/** Invalidates in-flight consent callbacks on restart / close / replace / expire. */
|
|
35
|
+
sessionId: number;
|
|
36
|
+
private handle?;
|
|
37
|
+
private expiryTimer?;
|
|
38
|
+
private requestAbort?;
|
|
39
|
+
private readonly host;
|
|
40
|
+
constructor(host: ConsentHost);
|
|
41
|
+
/**
|
|
42
|
+
* Stop consent request cadence, expiry timer, and outstanding transactions.
|
|
43
|
+
* Does not change ICE state by itself.
|
|
44
|
+
*/
|
|
45
|
+
stop(): void;
|
|
46
|
+
private abortableDelay;
|
|
47
|
+
/** Start a consent session on the selected pair (replaces the previous one). */
|
|
48
|
+
start: () => void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsentFreshness = void 0;
|
|
4
|
+
const helper_1 = require("./helper");
|
|
5
|
+
const iceBase_1 = require("./iceBase");
|
|
6
|
+
const common_1 = require("./imports/common");
|
|
7
|
+
const log = (0, common_1.debug)("werift-ice : packages/ice/src/consent.ts : log");
|
|
8
|
+
/**
|
|
9
|
+
* RFC 7675 consent freshness of the selected pair: a binding request every
|
|
10
|
+
* `CONSENT_INTERVAL` (randomized, measured between request starts), each
|
|
11
|
+
* response refreshes the consent, and `CONSENT_TIMEOUT` without one fails
|
|
12
|
+
* the agent. `start()` begins a session (the successful check that selected
|
|
13
|
+
* the pair counts as the first response); `stop()` ends it without changing
|
|
14
|
+
* the agent's state. A session id invalidates the callbacks of an ended
|
|
15
|
+
* session (restart, close, a replaced selection, expiry).
|
|
16
|
+
*/
|
|
17
|
+
class ConsentFreshness {
|
|
18
|
+
constructor(host) {
|
|
19
|
+
/** Consent-to-send: application data may use the selected pair. */
|
|
20
|
+
Object.defineProperty(this, "fresh", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: false
|
|
25
|
+
});
|
|
26
|
+
/** Invalidates in-flight consent callbacks on restart / close / replace / expire. */
|
|
27
|
+
Object.defineProperty(this, "sessionId", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "handle", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "expiryTimer", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "requestAbort", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "host", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
/** Start a consent session on the selected pair (replaces the previous one). */
|
|
58
|
+
Object.defineProperty(this, "start", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: () => {
|
|
63
|
+
if (this.host.iceLite()) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Invalidate any previous consent session before starting a new one.
|
|
67
|
+
this.stop();
|
|
68
|
+
const sessionId = this.sessionId;
|
|
69
|
+
this.fresh = true;
|
|
70
|
+
const handle = (0, helper_1.cancelable)(async (_, __, onCancel) => {
|
|
71
|
+
let canceled = false;
|
|
72
|
+
const cancelEvent = new AbortController();
|
|
73
|
+
const clearConsentExpiry = () => {
|
|
74
|
+
if (this.expiryTimer === undefined) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
clearTimeout(this.expiryTimer);
|
|
78
|
+
this.expiryTimer = undefined;
|
|
79
|
+
};
|
|
80
|
+
const refreshConsentExpiry = () => {
|
|
81
|
+
// Only the active session may refresh the shared expiry timer.
|
|
82
|
+
if (canceled || sessionId !== this.sessionId) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
clearConsentExpiry();
|
|
86
|
+
this.expiryTimer = setTimeout(() => {
|
|
87
|
+
this.expiryTimer = undefined;
|
|
88
|
+
if (canceled || sessionId !== this.sessionId) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (this.host.state() === "closed" ||
|
|
92
|
+
this.host.state() === "failed") {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
log("Consent to send expired");
|
|
96
|
+
// Expire independently of request cadence / failure count (RFC 7675).
|
|
97
|
+
this.fresh = false;
|
|
98
|
+
this.sessionId++;
|
|
99
|
+
this.requestAbort?.abort();
|
|
100
|
+
this.requestAbort = undefined;
|
|
101
|
+
if (this.handle === handle) {
|
|
102
|
+
this.handle = undefined;
|
|
103
|
+
}
|
|
104
|
+
canceled = true;
|
|
105
|
+
cancelEvent.abort();
|
|
106
|
+
// Transport stays available for ICE restart; explicit close() uses "closed".
|
|
107
|
+
this.host.setState("failed");
|
|
108
|
+
}, iceBase_1.CONSENT_TIMEOUT * 1000);
|
|
109
|
+
};
|
|
110
|
+
onCancel.once(() => {
|
|
111
|
+
canceled = true;
|
|
112
|
+
// Avoid clearing a replacement session's timer/handle.
|
|
113
|
+
if (sessionId === this.sessionId) {
|
|
114
|
+
clearConsentExpiry();
|
|
115
|
+
this.requestAbort?.abort();
|
|
116
|
+
this.requestAbort = undefined;
|
|
117
|
+
}
|
|
118
|
+
cancelEvent.abort();
|
|
119
|
+
if (this.handle === handle) {
|
|
120
|
+
this.handle = undefined;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
// Initial ICE check success is the first valid consent response.
|
|
124
|
+
refreshConsentExpiry();
|
|
125
|
+
const randomizedConsentInterval = () => iceBase_1.CONSENT_INTERVAL * (0.8 + 0.4 * Math.random()) * 1000;
|
|
126
|
+
// Cadence is measured between request *starts*, not response completions.
|
|
127
|
+
let nextConsentAt = Date.now() + randomizedConsentInterval();
|
|
128
|
+
const isTerminalState = () => this.host.state() === "closed" || this.host.state() === "failed";
|
|
129
|
+
try {
|
|
130
|
+
while (!isTerminalState() &&
|
|
131
|
+
!canceled &&
|
|
132
|
+
sessionId === this.sessionId) {
|
|
133
|
+
await this.abortableDelay(Math.max(0, nextConsentAt - Date.now()), cancelEvent.signal);
|
|
134
|
+
if (canceled || isTerminalState() || sessionId !== this.sessionId) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
// Fix next start time before awaiting any response (independent timers).
|
|
138
|
+
nextConsentAt = Date.now() + randomizedConsentInterval();
|
|
139
|
+
const nominated = this.host.selected();
|
|
140
|
+
if (!nominated) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
const pairId = nominated.id;
|
|
144
|
+
const generation = this.host.remoteGeneration();
|
|
145
|
+
const remotePassword = this.host.remotePassword();
|
|
146
|
+
const request = this.host.buildRequest(nominated);
|
|
147
|
+
this.requestAbort?.abort();
|
|
148
|
+
const requestAbort = new AbortController();
|
|
149
|
+
this.requestAbort = requestAbort;
|
|
150
|
+
nominated.consentRequestsSent++;
|
|
151
|
+
nominated.requestsSent++;
|
|
152
|
+
// RTT-aware wait (floor 500ms); independent of retransmissions: 0.
|
|
153
|
+
const responseTimeout = (0, iceBase_1.consentResponseTimeoutMs)(nominated.rtt);
|
|
154
|
+
const requestStartedAt = performance.now();
|
|
155
|
+
// Do not await here: response wait must not stretch the 4–6s cadence.
|
|
156
|
+
nominated.protocol
|
|
157
|
+
.request(request, nominated.remoteAddr, Buffer.from(remotePassword, "utf8"), {
|
|
158
|
+
retransmissions: 0,
|
|
159
|
+
responseTimeout,
|
|
160
|
+
signal: requestAbort.signal,
|
|
161
|
+
integrityAlgorithm: this.host.integrityAlgorithm(),
|
|
162
|
+
onRequestSent: (attempt) => {
|
|
163
|
+
if (attempt > 0) {
|
|
164
|
+
nominated.retransmissionsSent++;
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
})
|
|
168
|
+
.then(() => {
|
|
169
|
+
// Accept only responses for the current pair / generation / session.
|
|
170
|
+
// Address / MESSAGE-INTEGRITY / response class are enforced in Transaction + protocol.
|
|
171
|
+
if (sessionId !== this.sessionId || canceled) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const state = this.host.state();
|
|
175
|
+
if (state === "closed" || state === "failed") {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (this.host.selected()?.id !== pairId) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (this.host.remoteGeneration() !== generation) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (this.host.remotePassword() !== remotePassword) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const rtt = (performance.now() - requestStartedAt) / 1000; // seconds
|
|
188
|
+
nominated.rtt = rtt;
|
|
189
|
+
nominated.totalRoundTripTime += rtt;
|
|
190
|
+
nominated.roundTripTimeMeasurements++;
|
|
191
|
+
nominated.responsesReceived++;
|
|
192
|
+
this.fresh = true;
|
|
193
|
+
refreshConsentExpiry();
|
|
194
|
+
if (state === "disconnected") {
|
|
195
|
+
this.host.setState("connected");
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
.catch((error) => {
|
|
199
|
+
// Individual request loss is expected; keep monitoring (RFC 7675).
|
|
200
|
+
if (sessionId === this.sessionId &&
|
|
201
|
+
this.host.selected()?.id === pairId) {
|
|
202
|
+
log("no stun response", error);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
// Abort during delay is normal on cancel / expire.
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
if (sessionId === this.sessionId) {
|
|
212
|
+
clearConsentExpiry();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
this.handle = handle;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
this.host = host;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Stop consent request cadence, expiry timer, and outstanding transactions.
|
|
223
|
+
* Does not change ICE state by itself.
|
|
224
|
+
*/
|
|
225
|
+
stop() {
|
|
226
|
+
this.sessionId++;
|
|
227
|
+
this.fresh = false;
|
|
228
|
+
if (this.expiryTimer !== undefined) {
|
|
229
|
+
clearTimeout(this.expiryTimer);
|
|
230
|
+
this.expiryTimer = undefined;
|
|
231
|
+
}
|
|
232
|
+
this.requestAbort?.abort();
|
|
233
|
+
this.requestAbort = undefined;
|
|
234
|
+
const handle = this.handle;
|
|
235
|
+
this.handle = undefined;
|
|
236
|
+
// Resolve after clearing the field so a stale onCancel cannot wipe a replacement.
|
|
237
|
+
handle?.resolve?.();
|
|
238
|
+
}
|
|
239
|
+
abortableDelay(ms, signal) {
|
|
240
|
+
return new Promise((resolve, reject) => {
|
|
241
|
+
if (signal.aborted) {
|
|
242
|
+
reject(new DOMException("The operation was aborted", "AbortError"));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const timer = setTimeout(() => {
|
|
246
|
+
signal.removeEventListener("abort", onAbort);
|
|
247
|
+
resolve();
|
|
248
|
+
}, ms);
|
|
249
|
+
const onAbort = () => {
|
|
250
|
+
clearTimeout(timer);
|
|
251
|
+
reject(new DOMException("The operation was aborted", "AbortError"));
|
|
252
|
+
};
|
|
253
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.ConsentFreshness = ConsentFreshness;
|
|
258
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.js","sourceRoot":"","sources":["../../../../ice/src/consent.ts"],"names":[],"mappings":";;;AAAA,qCAAuD;AACvD,uCAMmB;AACnB,6CAAyC;AAIzC,MAAM,GAA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,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC,CAAC;YACtE,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC;CAiMF;AAlPD,4CAkPC","sourcesContent":["import { type Cancelable, cancelable } from \"./helper\";\nimport {\n type CandidatePair,\n CONSENT_INTERVAL,\n CONSENT_TIMEOUT,\n consentResponseTimeoutMs,\n type IceState,\n} from \"./iceBase\";\nimport { debug } from \"./imports/common\";\nimport type { MessageIntegrityMode } from \"./stun/const\";\nimport type { Message } from \"./stun/message\";\n\nconst log = debug(\"werift-ice : packages/ice/src/consent.ts : log\");\n\n/** What the agent supplies to its `ConsentFreshness`. */\nexport type ConsentHost = {\n /** The selected pair: consent checks go to it. */\n selected: () => CandidatePair | undefined;\n state: () => IceState;\n setState: (state: IceState) => void;\n /** Answers of an earlier remote generation (an ICE restart) do not count. */\n remoteGeneration: () => number;\n remotePassword: () => string;\n /** A local ICE-lite agent sends no consent checks. */\n iceLite: () => boolean;\n integrityAlgorithm: () => MessageIntegrityMode | undefined;\n /**\n * The consent check for `pair`, with what the nomination mode puts on it\n * (USE-CANDIDATE, NOMINATION).\n */\n buildRequest: (pair: CandidatePair) => Message;\n};\n\n/**\n * RFC 7675 consent freshness of the selected pair: a binding request every\n * `CONSENT_INTERVAL` (randomized, measured between request starts), each\n * response refreshes the consent, and `CONSENT_TIMEOUT` without one fails\n * the agent. `start()` begins a session (the successful check that selected\n * the pair counts as the first response); `stop()` ends it without changing\n * the agent's state. A session id invalidates the callbacks of an ended\n * session (restart, close, a replaced selection, expiry).\n */\nexport class ConsentFreshness {\n /** Consent-to-send: application data may use the selected pair. */\n fresh = false;\n /** Invalidates in-flight consent callbacks on restart / close / replace / expire. */\n sessionId = 0;\n private handle?: Cancelable<void>;\n private expiryTimer?: ReturnType<typeof setTimeout>;\n private requestAbort?: AbortController;\n private readonly host: ConsentHost;\n\n constructor(host: ConsentHost) {\n this.host = host;\n }\n\n /**\n * Stop consent request cadence, expiry timer, and outstanding transactions.\n * Does not change ICE state by itself.\n */\n stop() {\n this.sessionId++;\n this.fresh = false;\n if (this.expiryTimer !== undefined) {\n clearTimeout(this.expiryTimer);\n this.expiryTimer = undefined;\n }\n this.requestAbort?.abort();\n this.requestAbort = undefined;\n const handle = this.handle;\n this.handle = undefined;\n // Resolve after clearing the field so a stale onCancel cannot wipe a replacement.\n handle?.resolve?.();\n }\n\n private abortableDelay(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal.aborted) {\n reject(new DOMException(\"The operation was aborted\", \"AbortError\"));\n return;\n }\n const timer = setTimeout(() => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(new DOMException(\"The operation was aborted\", \"AbortError\"));\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n }\n\n /** Start a consent session on the selected pair (replaces the previous one). */\n start = () => {\n if (this.host.iceLite()) {\n return;\n }\n\n // Invalidate any previous consent session before starting a new one.\n this.stop();\n const sessionId = this.sessionId;\n this.fresh = true;\n\n const handle = cancelable<void>(async (_, __, onCancel) => {\n let canceled = false;\n const cancelEvent = new AbortController();\n\n const clearConsentExpiry = () => {\n if (this.expiryTimer === undefined) {\n return;\n }\n clearTimeout(this.expiryTimer);\n this.expiryTimer = undefined;\n };\n\n const refreshConsentExpiry = () => {\n // Only the active session may refresh the shared expiry timer.\n if (canceled || sessionId !== this.sessionId) {\n return;\n }\n clearConsentExpiry();\n this.expiryTimer = setTimeout(() => {\n this.expiryTimer = undefined;\n if (canceled || sessionId !== this.sessionId) {\n return;\n }\n if (\n this.host.state() === \"closed\" ||\n this.host.state() === \"failed\"\n ) {\n return;\n }\n log(\"Consent to send expired\");\n // Expire independently of request cadence / failure count (RFC 7675).\n this.fresh = false;\n this.sessionId++;\n this.requestAbort?.abort();\n this.requestAbort = undefined;\n if (this.handle === handle) {\n this.handle = undefined;\n }\n canceled = true;\n cancelEvent.abort();\n // Transport stays available for ICE restart; explicit close() uses \"closed\".\n this.host.setState(\"failed\");\n }, CONSENT_TIMEOUT * 1000);\n };\n\n onCancel.once(() => {\n canceled = true;\n // Avoid clearing a replacement session's timer/handle.\n if (sessionId === this.sessionId) {\n clearConsentExpiry();\n this.requestAbort?.abort();\n this.requestAbort = undefined;\n }\n cancelEvent.abort();\n if (this.handle === handle) {\n this.handle = undefined;\n }\n });\n\n // Initial ICE check success is the first valid consent response.\n refreshConsentExpiry();\n\n const randomizedConsentInterval = () =>\n CONSENT_INTERVAL * (0.8 + 0.4 * Math.random()) * 1000;\n\n // Cadence is measured between request *starts*, not response completions.\n let nextConsentAt = Date.now() + randomizedConsentInterval();\n const isTerminalState = () =>\n this.host.state() === \"closed\" || this.host.state() === \"failed\";\n\n try {\n while (\n !isTerminalState() &&\n !canceled &&\n sessionId === this.sessionId\n ) {\n await this.abortableDelay(\n Math.max(0, nextConsentAt - Date.now()),\n cancelEvent.signal,\n );\n\n if (canceled || isTerminalState() || sessionId !== this.sessionId) {\n break;\n }\n\n // Fix next start time before awaiting any response (independent timers).\n nextConsentAt = Date.now() + randomizedConsentInterval();\n\n const nominated = this.host.selected();\n if (!nominated) {\n break;\n }\n\n const pairId = nominated.id;\n const generation = this.host.remoteGeneration();\n const remotePassword = this.host.remotePassword();\n\n const request = this.host.buildRequest(nominated);\n\n this.requestAbort?.abort();\n const requestAbort = new AbortController();\n this.requestAbort = requestAbort;\n\n nominated.consentRequestsSent++;\n nominated.requestsSent++;\n\n // RTT-aware wait (floor 500ms); independent of retransmissions: 0.\n const responseTimeout = consentResponseTimeoutMs(nominated.rtt);\n const requestStartedAt = performance.now();\n\n // Do not await here: response wait must not stretch the 4–6s cadence.\n nominated.protocol\n .request(\n request,\n nominated.remoteAddr,\n Buffer.from(remotePassword, \"utf8\"),\n {\n retransmissions: 0,\n responseTimeout,\n signal: requestAbort.signal,\n integrityAlgorithm: this.host.integrityAlgorithm(),\n onRequestSent: (attempt) => {\n if (attempt > 0) {\n nominated.retransmissionsSent++;\n }\n },\n },\n )\n .then(() => {\n // Accept only responses for the current pair / generation / session.\n // Address / MESSAGE-INTEGRITY / response class are enforced in Transaction + protocol.\n if (sessionId !== this.sessionId || canceled) {\n return;\n }\n const state = this.host.state();\n if (state === \"closed\" || state === \"failed\") {\n return;\n }\n if (this.host.selected()?.id !== pairId) {\n return;\n }\n if (this.host.remoteGeneration() !== generation) {\n return;\n }\n if (this.host.remotePassword() !== remotePassword) {\n return;\n }\n\n const rtt = (performance.now() - requestStartedAt) / 1000; // seconds\n nominated.rtt = rtt;\n nominated.totalRoundTripTime += rtt;\n nominated.roundTripTimeMeasurements++;\n\n nominated.responsesReceived++;\n this.fresh = true;\n refreshConsentExpiry();\n if (state === \"disconnected\") {\n this.host.setState(\"connected\");\n }\n })\n .catch((error) => {\n // Individual request loss is expected; keep monitoring (RFC 7675).\n if (\n sessionId === this.sessionId &&\n this.host.selected()?.id === pairId\n ) {\n log(\"no stun response\", error);\n }\n });\n }\n } catch (error) {\n // Abort during delay is normal on cancel / expire.\n } finally {\n if (sessionId === this.sessionId) {\n clearConsentExpiry();\n }\n }\n });\n this.handle = handle;\n };\n}\n"]}
|