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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../../ice/src/turn/protocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAohCA,4CAuEC;AAED,4DAOC;AAwDD,4CAMC;AAlqCD,uCAAgC;AAChC,8CAAgC;AAChC,8CAA6C;AAE7C,4DAAyE;AAEzE,8CAKuB;AACvB,sCAA6E;AAC7E,8CAa2B;AAC3B,yCAAiD;AACjD,6CAAuE;AACvE,qDAO6B;AAE7B,6CAAiD;AACjD,mCAMiB;AAEjB,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,8CAA8C,CAAC,CAAC;AAElE,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,gFAAgF;AAChF,MAAM,8BAA8B,GAAG,CAAC,CAAC;AAEzC,4CAGuB;AAFrB,+GAAA,iBAAiB,OAAA;AA6BnB,SAAS,iBAAiB,CAAC,SAAoB;IAC7C,OAAO,SAAS,CAAC,IAAI,KAAK,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC;AAC9D,CAAC;AAED,+CAA+C;AAC/C,SAAS,aAAa,CAAC,IAAa;IAClC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,gEAAgE;AAChE,SAAS,UAAU,CAAC,IAAa;IAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAa,oBAAoB;IAgB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,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,yEAAyE;IACzE,qEAAqE;IACrE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAChD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAC5B,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,aAAa,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,aAAa,CAC5E,CAAC;IACF,OAAO;QACL,MAAM,EAAE,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC;QAC/B,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,kBAAkB,CAAC;KAC7D,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,KAAa,EACb,QAAgB;IAEhB,OAAO,IAAA,2BAAoB,EAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { isIP } from \"node:net\";\nimport * as tls from \"node:tls\";\nimport { setTimeout } from \"timers/promises\";\n\nimport { makeTurnIntegrityKey } from \"../../../ice-server/src/turn/auth\";\nimport type { Candidate } from \"../candidate\";\nimport {\n TransactionCancelled,\n TransactionChallenge,\n TransactionFailed,\n TurnRedirectError,\n} from \"../exceptions\";\nimport { type Cancelable, cancelable, randomTransactionId } from \"../helper\";\nimport {\n type Address,\n bufferReader,\n debug,\n Event,\n EventDisposer,\n type InterfaceAddresses,\n int,\n TcpTransport,\n type TlsConnectionOptions,\n TlsTransport,\n type Transport,\n UdpTransport,\n} from \"../imports/common\";\nimport { classes, methods } from \"../stun/const\";\nimport { Message, paddingLength, parseMessage } from \"../stun/message\";\nimport {\n addressEquals,\n buildTransactionOptions,\n hasMessageIntegrity,\n isUnauthenticatedChallenge,\n resolveRequestAddress,\n Transaction,\n} from \"../stun/transaction\";\nimport type { Protocol, TransactionRequestOptions } from \"../types/model\";\nimport { credentialRetryOf } from \"./credential\";\nimport {\n decodeChannelData,\n encodeChannelData,\n isChannelData,\n padTurnFrame,\n splitTurnTcpFrames,\n} from \"./frame\";\n\nconst log = debug(\"werift-ice:packages/ice/src/turn/protocol.ts\");\n\nconst DEFAULT_CHANNEL_REFRESH_TIME = 500;\nconst DEFAULT_ALLOCATION_LIFETIME = 600;\nconst UDP_TRANSPORT = 0x11000000;\n/** 300 (Try Alternate) redirects followed for one Allocate before giving up. */\nconst DEFAULT_MAX_ALLOCATE_REDIRECTS = 3;\n\nexport {\n TurnRedirectError,\n type TurnRedirectFailureReason,\n} from \"../exceptions\";\n\n/**\n * Opens a new stream transport to the TURN server named by a 300 (Try\n * Alternate) ALTERNATE-SERVER. `alternateDomain` is the ALTERNATE-DOMAIN\n * attribute, if any, which a TLS transport must validate the certificate\n * against (RFC 8489 §10).\n */\nexport type TurnStreamReconnect = (\n server: Address,\n alternateDomain: string | undefined,\n) => Promise<Transport>;\n\n/** Where a 300 (Try Alternate) response tells the client to go. */\ninterface TurnAlternate {\n server: Address;\n domain?: string;\n}\n\n/** Channel binding state for a single peer transport address. */\nexport interface TurnChannel {\n number: number;\n address: Address;\n /** Unix seconds when this channel should be refreshed. */\n refreshAt: number;\n}\n\nfunction isStreamTransport(transport: Transport) {\n return transport.type === \"tcp\" || transport.type === \"tls\";\n}\n\n/** Permission is peer-IP scoped (RFC 8656). */\nfunction permissionKey(addr: Address): string {\n return addr[0];\n}\n\n/** ChannelBind is peer transport-address scoped (IP + port). */\nfunction channelKey(addr: Address): string {\n return JSON.stringify(addr);\n}\n\nexport class StunOverTurnProtocol implements Protocol {\n public turn: TurnProtocol;\n /**\n * The transport the TURN server was configured with. A UDP entry whose\n * allocation fell back to TCP keeps \"udp\" here, so a restart that removes\n * that entry also releases the fallback allocation.\n */\n configuredTransport?: \"udp\" | \"tcp\" | \"tls\";\n\n static type = \"turn\";\n readonly type = StunOverTurnProtocol.type;\n localCandidate!: Candidate;\n private disposer = new EventDisposer();\n onRequestReceived: Event<[Message, Address, Buffer]> = new Event();\n onDataReceived: Event<[Buffer]> = new Event();\n\n constructor(turn: TurnProtocol) {\n this.turn = turn;\n turn.onData\n .subscribe((data, addr) => {\n this.handleStunMessage(data, addr);\n })\n .disposer(this.disposer);\n }\n\n private handleStunMessage = (data: Buffer, addr: Address) => {\n try {\n const message = parseMessage(data);\n if (!message) {\n this.onDataReceived.execute(data);\n return;\n }\n\n if (\n message.messageClass === classes.RESPONSE ||\n message.messageClass === classes.ERROR\n ) {\n const transaction = this.turn.transactions[message.transactionIdHex];\n if (transaction) {\n const verified = transaction.integrityKey\n ? parseMessage(data, transaction.integrityKey)\n : message;\n if (!verified) {\n log(\"STUN over TURN response failed MESSAGE-INTEGRITY check\");\n return;\n }\n transaction.responseReceived(verified, addr);\n }\n } else if (message.messageClass === classes.REQUEST) {\n this.onRequestReceived.execute(message, addr, data);\n }\n } catch (error) {\n log(\"datagramReceived error\", error);\n }\n };\n\n async request(\n request: Message,\n addr: Address,\n integrityKey?: Buffer,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n ) {\n if (this.turn.transactions[request.transactionIdHex]) {\n throw new Error(\"exist\");\n }\n\n if (integrityKey) {\n request.addMessageIntegrity(integrityKey);\n request.addFingerprint();\n }\n\n // Peer-facing STUN over TURN must honor retransmissions/responseTimeout\n // (consent uses retransmissions: 0). Do not confuse with TURN server\n // allocation/refresh policy on TurnProtocol.\n // Peer addresses are already IPs from candidates; resolve for safety.\n const resolvedAddr = await resolveRequestAddress(addr);\n const options = buildTransactionOptions(\n integrityKey,\n retransmissionsOrOptions,\n onRequestSent,\n );\n const transaction = new Transaction(request, resolvedAddr, this, options);\n this.turn.transactions[request.transactionIdHex] = transaction;\n\n try {\n return await transaction.run();\n } catch (e) {\n throw e;\n } finally {\n delete this.turn.transactions[request.transactionIdHex];\n }\n }\n async connectionMade() {}\n async sendData(data: Buffer, addr: Address) {\n await this.turn.sendData(data, addr);\n }\n async sendStun(message: Message, addr: Address) {\n await this.turn.sendData(message.bytes, addr);\n }\n async close() {\n this.disposer.dispose();\n return this.turn.close();\n }\n}\n\nexport class TurnProtocol implements Protocol {\n /**\n * TURN server the allocation is made on; the host may be a hostname.\n * Starts as the configured server and becomes the ALTERNATE-SERVER when\n * an Allocate is redirected with 300 (Try Alternate).\n */\n public server: Address;\n public username: string;\n public password: string;\n public lifetime: number;\n public transport: Transport;\n public options: {\n /**sec */\n channelRefreshTime?: number;\n /**\n * 300 (Try Alternate) redirects followed for one Allocate.\n * Defaults to 3.\n */\n maxAllocateRedirects?: number;\n /**\n * Reconnects a TCP/TLS transport to an ALTERNATE-SERVER. Without it, a\n * redirect over a stream transport fails with TurnRedirectError\n * (\"unsupported-transport\"). UDP needs no reconnect.\n */\n reconnect?: TurnStreamReconnect;\n };\n\n static type = \"turn\";\n readonly type = TurnProtocol.type;\n readonly onData = new Event<[Buffer, Address]>();\n onRequestReceived: Event<[Message, Address, Buffer]> = new Event();\n onDataReceived: Event<[Buffer]> = new Event();\n integrityKey?: Buffer;\n nonce?: Buffer;\n realm?: string;\n relayedAddress!: Address;\n mappedAddress!: Address;\n localCandidate!: Candidate;\n transactions: { [hexId: string]: Transaction } = {};\n /** close() ran: no new transaction starts. */\n private closed = false;\n private refreshHandle?: Cancelable<void>;\n private channelNumber = 0x4000;\n private channelByAddr: { [key: string]: TurnChannel } = {};\n private addrByChannel: { [channel: number]: Address } = {};\n /**sec */\n private channelRefreshTime: number;\n /**\n * Serializes ChannelBind requests so allocation-wide auth state\n * (nonce/realm/integrityKey) is not updated concurrently. Rejections\n * must not poison this tail — see channelBindQueue assignment sites.\n */\n private channelBindQueue: Promise<void> = Promise.resolve();\n /** In-flight ChannelBind per peer transport address (dedupe concurrent). */\n private channelBindingByAddr = new Map<string, Promise<TurnChannel>>();\n private tcpBuffer: Buffer = Buffer.alloc(0);\n /** Permission cache keyed by peer IP only (RFC 8656). */\n private permissionByAddr: { [peerIp: string]: boolean } = {};\n /**\n * Serializes CreatePermission requests (auth state race avoidance).\n * Rejections must not poison this tail.\n */\n private permissionQueue: Promise<void> = Promise.resolve();\n /** In-flight CreatePermission per peer IP (dedupe concurrent). */\n private creatingPermissionByAddr = new Map<string, Promise<void>>();\n /** Concrete TURN server address the allocation lives on, once selected. */\n private pinnedServerEndpoint?: Address;\n private serverEndpointSelection?: Promise<Address>;\n\n /** TURN server as configured, before any 300 (Try Alternate) redirect. */\n readonly configuredServer: Address;\n\n constructor(\n server: Address,\n username: string,\n password: string,\n lifetime: number,\n transport: Transport,\n options: {\n /**sec */\n channelRefreshTime?: number;\n /**\n * 300 (Try Alternate) redirects followed for one Allocate.\n * Defaults to 3.\n */\n maxAllocateRedirects?: number;\n /**\n * Reconnects a TCP/TLS transport to an ALTERNATE-SERVER. Without it, a\n * redirect over a stream transport fails with TurnRedirectError\n * (\"unsupported-transport\"). UDP needs no reconnect.\n */\n reconnect?: TurnStreamReconnect;\n } = {},\n ) {\n this.server = server;\n this.username = username;\n this.password = password;\n this.lifetime = lifetime;\n this.transport = transport;\n this.options = options;\n this.configuredServer = server;\n this.channelRefreshTime =\n this.options.channelRefreshTime ?? DEFAULT_CHANNEL_REFRESH_TIME;\n }\n\n async connectionMade() {\n this.attachTransport();\n\n const [response] = await this.allocate().catch((e) => {\n log(\"connect error\", e);\n throw e;\n });\n this.relayedAddress = response.getAttributeValue(\"XOR-RELAYED-ADDRESS\");\n this.mappedAddress = response.getAttributeValue(\"XOR-MAPPED-ADDRESS\");\n const exp = response.getAttributeValue(\"LIFETIME\");\n log(\"connect\", this.relayedAddress, this.mappedAddress, { exp });\n\n // close() ran while the response was in flight: no refresh starts.\n if (this.closed) throw new TransactionCancelled();\n this.refresh(exp);\n }\n\n private attachTransport() {\n this.transport.onData = (data, addr) => {\n this.dataReceived(data, addr);\n };\n this.transport.onError?.subscribe((error) => {\n log(\"transport error\", error);\n });\n }\n\n /**\n * Allocate on the current server, following 300 (Try Alternate) to the\n * ALTERNATE-SERVER with the same transport protocol and credentials\n * (RFC 8656 §7.4, RFC 8489 §10). Only Allocate is redirected: an existing\n * allocation lives on one server, so Refresh, CreatePermission and\n * ChannelBind never move.\n */\n private async allocate(): Promise<[Message, Address]> {\n const maxRedirects =\n this.options.maxAllocateRedirects ?? DEFAULT_MAX_ALLOCATE_REDIRECTS;\n /** Servers this Allocate has been sent to, to detect redirect loops. */\n const tried: Address[] = [];\n\n for (let redirects = 0; ; redirects++) {\n // A fresh request per server: a redirected request may already carry\n // MESSAGE-INTEGRITY for the previous server's realm and nonce.\n const request = new Message(methods.ALLOCATE, classes.REQUEST)\n .setAttribute(\"LIFETIME\", this.lifetime)\n .setAttribute(\"REQUESTED-TRANSPORT\", UDP_TRANSPORT);\n\n try {\n return await this.requestWithRetry(request, this.server);\n } catch (error) {\n const alternate = tryAlternateOf(error, this.transport.addressFamily);\n if (!alternate) {\n throw error;\n }\n // The request has resolved the configured host, so its endpoint is\n // known here: a redirect to the resolved IP of a host name is a loop.\n tried.push(this.server);\n if (this.pinnedServerEndpoint) {\n tried.push(this.pinnedServerEndpoint);\n }\n const failed = error as TransactionFailed;\n const fail = (\n reason: ConstructorParameters<typeof TurnRedirectError>[0],\n ) =>\n new TurnRedirectError(reason, this.server, alternate.server, failed);\n\n if (!alternate.server) {\n throw new TurnRedirectError(\n \"missing-alternate\",\n this.server,\n undefined,\n failed,\n );\n }\n if (tried.some((addr) => addressEquals(addr, alternate.server!))) {\n throw fail(\"loop\");\n }\n if (redirects >= maxRedirects) {\n throw fail(\"too-many-redirects\");\n }\n if (isStreamTransport(this.transport) && !this.options.reconnect) {\n throw fail(\"unsupported-transport\");\n }\n\n log(\"allocate redirected\", this.server, \"->\", alternate);\n await this.switchServer(alternate as TurnAlternate);\n }\n }\n }\n\n /**\n * Point the client at an ALTERNATE-SERVER. Authentication state belongs to\n * the previous server, so the alternate starts again with an\n * unauthenticated Allocate and its own 401 realm/nonce; username and\n * password are kept.\n */\n private async switchServer({ server, domain }: TurnAlternate) {\n let endpoint: Address;\n if (isStreamTransport(this.transport)) {\n const previous = this.transport;\n previous.onData = () => {};\n await previous.close();\n const reconnected = await this.options.reconnect!(server, domain);\n // close() ran while reconnecting: it saw only the closed previous\n // transport, so the new connection is released here.\n if (this.closed) {\n reconnected.onData = () => {};\n await reconnected.close();\n throw new TransactionCancelled();\n }\n this.transport = reconnected;\n this.tcpBuffer = Buffer.alloc(0);\n this.attachTransport();\n endpoint = this.transport.remoteAddress ?? server;\n } else {\n // ALTERNATE-SERVER is an IP literal. One of the other family cannot be\n // reached from this socket (AddressFamilyMismatch).\n endpoint = await resolveRequestAddress(\n server,\n this.transport.addressFamily ?? 0,\n );\n }\n\n this.server = server;\n this.pinnedServerEndpoint = endpoint;\n this.serverEndpointSelection = Promise.resolve(endpoint);\n this.nonce = undefined;\n this.realm = undefined;\n this.integrityKey = undefined;\n }\n\n private handleChannelData(data: Buffer) {\n const decoded = decodeChannelData(data);\n const addr = decoded && this.addrByChannel[decoded.channelNumber];\n\n if (addr && decoded) {\n this.onData.execute(decoded.data, addr);\n }\n }\n\n private handleSTUNMessage(data: Buffer, addr: Address) {\n try {\n const message = parseMessage(data);\n if (!message) {\n throw new Error(\"not stun message\");\n }\n\n if (\n message.messageClass === classes.RESPONSE ||\n message.messageClass === classes.ERROR\n ) {\n const transaction = this.transactions[message.transactionIdHex];\n if (transaction) {\n this.handleResponse(transaction, message, data, addr);\n }\n } else if (message.messageClass === classes.REQUEST) {\n this.onData.execute(data, addr);\n }\n\n if (message.getAttributeValue(\"DATA\")) {\n const buf: Buffer = message.getAttributeValue(\"DATA\");\n const peerAddress =\n message.getAttributeValue(\"XOR-PEER-ADDRESS\") ?? addr;\n this.onData.execute(buf, peerAddress);\n }\n } catch (error) {\n log(\"parse error\", data.toString());\n }\n }\n\n /**\n * Long-term credentials (RFC 8489 §9.2.5): a response to an authenticated\n * request must carry a valid MESSAGE-INTEGRITY, except a 401/438 challenge\n * without one, which goes to the retry logic of requestWithRetry. Over\n * UDP an unverified response is dropped and retransmissions continue; over\n * TCP/TLS it ends the transaction, except an unsigned 400, which is\n * discarded as if never received.\n */\n private handleResponse(\n transaction: Transaction,\n message: Message,\n data: Buffer,\n addr: Address,\n ) {\n if (!transaction.integrityKey) {\n transaction.responseReceived(message, addr);\n return;\n }\n if (isUnauthenticatedChallenge(message)) {\n transaction.challengeReceived(message, addr);\n return;\n }\n const verified = parseMessage(data, transaction.integrityKey);\n if (verified) {\n transaction.responseReceived(verified, addr);\n return;\n }\n log(\"TURN STUN response failed MESSAGE-INTEGRITY check\");\n const [errorCode] = message.getAttributeValue(\"ERROR-CODE\") ?? [];\n const unsignedBadRequest =\n message.messageClass === classes.ERROR &&\n errorCode === 400 &&\n !hasMessageIntegrity(message);\n if (isStreamTransport(this.transport) && !unsignedBadRequest) {\n transaction.integrityViolated(addr);\n }\n }\n\n private dataReceived(data: Buffer, addr: Address) {\n const datagramReceived = (data: Buffer, addr: Address) => {\n if (data.length >= 4 && isChannelData(data)) {\n this.handleChannelData(data);\n } else {\n this.handleSTUNMessage(data, addr);\n }\n };\n\n if (isStreamTransport(this.transport)) {\n this.tcpBuffer = Buffer.concat([this.tcpBuffer, data]);\n const { frames, rest } = splitTurnTcpFrames(this.tcpBuffer);\n this.tcpBuffer = rest;\n for (const frame of frames) {\n datagramReceived(frame, addr);\n }\n } else {\n datagramReceived(data, addr);\n }\n }\n\n private async send(data: Buffer, addr: Address) {\n if (this.transport.closed) {\n return;\n }\n\n await this.transport.send(\n isStreamTransport(this.transport) ? padTurnFrame(data) : data,\n addr,\n );\n }\n\n private async createPermission(peerAddress: Address) {\n const request = new Message(methods.CREATE_PERMISSION, classes.REQUEST);\n request\n .setAttribute(\"XOR-PEER-ADDRESS\", peerAddress)\n .setAttribute(\"USERNAME\", this.username)\n .setAttribute(\"REALM\", this.realm)\n .setAttribute(\"NONCE\", this.nonce);\n // Use requestWithRetry for stale-nonce (438) consistency with ChannelBind.\n await this.requestWithRetry(request, this.server);\n }\n\n private refresh = (exp: number) => {\n this.refreshHandle = cancelable<void>(async (_, __, onCancel) => {\n const abort = new AbortController();\n onCancel.once(() => {\n abort.abort();\n });\n\n while (!abort.signal.aborted) {\n // refresh before expire\n const delay = (5 / 6) * exp * 1000;\n log(\"refresh delay\", delay, { exp });\n try {\n await setTimeout(delay, undefined, { signal: abort.signal });\n } catch (error) {\n if (abort.signal.aborted) {\n return;\n }\n throw error;\n }\n\n if (abort.signal.aborted) {\n return;\n }\n\n const request = new Message(methods.REFRESH, classes.REQUEST);\n request.setAttribute(\"LIFETIME\", exp);\n\n try {\n const [message] = await this.requestWithRetry(\n request,\n this.server,\n abort.signal,\n );\n exp = message.getAttributeValue(\"LIFETIME\");\n log(\"refresh\", { exp });\n } catch (error) {\n if (abort.signal.aborted) {\n return;\n }\n log(\"refresh error\", error);\n }\n }\n });\n };\n\n async request(\n request: Message,\n addr: Address,\n _integrityKey?: Buffer,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n credentials?: { realm: string; nonce: Buffer; integrityKey: Buffer },\n ): Promise<[Message, Address]> {\n if (this.transactions[request.transactionIdHex]) {\n throw new Error(\"exist\");\n }\n const signing = credentials ?? {\n realm: this.realm,\n nonce: this.nonce,\n integrityKey: this.integrityKey,\n };\n if (signing.integrityKey) {\n // A retried request still carries the previous signature, which would\n // otherwise be covered by the new MESSAGE-INTEGRITY.\n request\n .removeAttribute(\"MESSAGE-INTEGRITY\")\n .removeAttribute(\"MESSAGE-INTEGRITY-SHA256\")\n .removeAttribute(\"FINGERPRINT\")\n .setAttribute(\"USERNAME\", this.username)\n .setAttribute(\"REALM\", signing.realm)\n .setAttribute(\"NONCE\", signing.nonce)\n .addMessageIntegrity(signing.integrityKey)\n .addFingerprint();\n }\n\n // TURN server allocation/refresh uses default STUN retry policy unless\n // callers pass explicit options. Peer consent goes through StunOverTurnProtocol.\n // Prefer the TURN session integrity key for response verification.\n const resolvedAddr = await this.resolveRequestTarget(addr);\n // close() ran during the lookup: no transaction starts on a closed client.\n if (this.closed) throw new TransactionCancelled();\n const options = buildTransactionOptions(\n signing.integrityKey,\n retransmissionsOrOptions,\n onRequestSent,\n );\n const transaction = new Transaction(request, resolvedAddr, this, options);\n this.transactions[request.transactionIdHex] = transaction;\n\n try {\n return await transaction.run();\n } catch (e) {\n throw e;\n } finally {\n delete this.transactions[request.transactionIdHex];\n }\n }\n\n /**\n * The concrete TURN server address, selected on the first request and\n * pinned for the rest of the allocation, so a later DNS answer can never\n * move REFRESH, CREATE_PERMISSION, CHANNEL_BIND or data to another server.\n */\n get serverEndpoint(): Address | undefined {\n return this.pinnedServerEndpoint;\n }\n\n /**\n * Address a request to `addr` is sent to, and the address its response\n * must come from. A stream carries every request to the peer it is\n * connected to, so it always uses the server endpoint.\n */\n private async resolveRequestTarget(addr: Address): Promise<Address> {\n if (isStreamTransport(this.transport) || addressEquals(addr, this.server)) {\n return this.selectServerEndpoint();\n }\n return resolveRequestAddress(addr, this.transport.addressFamily ?? 0);\n }\n\n private async serverDestination(): Promise<Address> {\n return this.pinnedServerEndpoint ?? this.selectServerEndpoint();\n }\n\n private selectServerEndpoint(): Promise<Address> {\n this.serverEndpointSelection ??= this.resolveServerEndpoint().then(\n (endpoint) => {\n this.pinnedServerEndpoint = endpoint;\n return endpoint;\n },\n (error) => {\n // Let a later request try again, e.g. after a transient DNS failure.\n this.serverEndpointSelection = undefined;\n throw error;\n },\n );\n return this.serverEndpointSelection;\n }\n\n /**\n * UDP: resolve the configured server in the bound socket's family; a udp4\n * socket cannot send to an IPv6 answer. TCP/TLS: use the peer the socket\n * actually connected to. Looking the hostname up again could return a\n * different A/AAAA record, and responses from the real peer would then be\n * dropped as coming from an unexpected address.\n */\n private async resolveServerEndpoint(): Promise<Address> {\n const transport = this.transport;\n if (!isStreamTransport(transport)) {\n return resolveRequestAddress(this.server, transport.addressFamily ?? 0);\n }\n if (transport.remoteAddress) {\n return transport.remoteAddress;\n }\n if (\n transport instanceof TcpTransport ||\n transport instanceof TlsTransport\n ) {\n throw new Error(`${transport.type} transport has no remote address`);\n }\n // A custom stream transport that does not report its peer: fall back to\n // a lookup with no family preference.\n return resolveRequestAddress(this.server);\n }\n\n /**\n * Send a request and follow the long-term credential mechanism of\n * RFC 8489 §9.2.5: a 401 (Unauthenticated) or 438 (Stale Nonce) that\n * allows it (see credentialRetryOf) is retried once with the new realm and\n * nonce; any other error, or a second challenge, is thrown. The allocation's\n * realm, nonce and integrity key change only when a retry is made; a retry\n * under a new realm adopts them only once the server accepted it.\n */\n async requestWithRetry(\n request: Message,\n addr: Address,\n signal?: AbortSignal,\n ): Promise<[Message, Address]> {\n try {\n return await this.request(request, addr, undefined, { signal });\n } catch (error) {\n if (error instanceof TransactionFailed == false) {\n log(\"requestWithRetry error\", error);\n throw error;\n }\n\n // request() signed the request with the credentials of that moment.\n const authenticated =\n request.attributesKeys.includes(\"MESSAGE-INTEGRITY\");\n const sentRealm: string | undefined = authenticated\n ? request.getAttributeValue(\"REALM\")\n : undefined;\n const retry = credentialRetryOf(\n error.response,\n { authenticated, realm: sentRealm },\n this.realm,\n );\n if (!retry) {\n throw error;\n }\n log(\"retry with nonce\", error.str, {\n signedError: !(error instanceof TransactionChallenge),\n });\n\n const integrityKey = makeIntegrityKey(\n this.username,\n retry.realm,\n this.password,\n );\n request.transactionId = randomTransactionId();\n\n // A new realm on an authenticated request rekeys the whole allocation.\n // Sign the retry with its own credentials and adopt them only once the\n // server accepted it, so concurrent failures never overwrite the shared\n // state with credentials that were rejected.\n if (authenticated && retry.realm !== sentRealm) {\n const credentials = {\n realm: retry.realm,\n nonce: retry.nonce,\n integrityKey,\n };\n const result = await this.request(\n request,\n this.server,\n undefined,\n { signal },\n undefined,\n credentials,\n );\n this.nonce = credentials.nonce;\n this.realm = credentials.realm;\n this.integrityKey = credentials.integrityKey;\n return result;\n }\n\n this.nonce = retry.nonce;\n this.realm = retry.realm;\n this.integrityKey = integrityKey;\n return await this.request(request, this.server, undefined, { signal });\n }\n }\n\n async sendData(data: Buffer, addr: Address) {\n let channel: TurnChannel | undefined;\n try {\n channel = await this.getChannel(addr);\n } catch (e) {\n // Keep original ChannelBind error for diagnostics (403/438/timeout).\n log(\"channelBind error; falling back to Send Indication\", e);\n }\n\n if (!channel) {\n await this.getPermission(addr);\n const indicate = new Message(methods.SEND, classes.INDICATION)\n .setAttribute(\"DATA\", data)\n .setAttribute(\"XOR-PEER-ADDRESS\", addr);\n\n await this.sendStun(indicate, await this.serverDestination());\n return;\n }\n\n await this.send(\n encodeChannelData(channel.number, data),\n await this.serverDestination(),\n );\n }\n\n /**\n * Ensure a CreatePermission exists for the peer IP.\n * Peer failures are isolated: a rejection for peer A does not poison peer B.\n */\n async getPermission(addr: Address) {\n const key = permissionKey(addr);\n\n if (this.permissionByAddr[key]) {\n return;\n }\n\n const existing = this.creatingPermissionByAddr.get(key);\n if (existing) {\n return existing;\n }\n\n const operation = this.permissionQueue.then(async () => {\n // Another caller may have succeeded while we waited on the queue.\n if (this.permissionByAddr[key]) {\n return;\n }\n\n await this.createPermission(addr);\n // Cache only after successful CreatePermission.\n this.permissionByAddr[key] = true;\n });\n\n // Do not let rejection poison subsequent peers on the shared queue.\n this.permissionQueue = operation.then(\n () => undefined,\n () => undefined,\n );\n\n this.creatingPermissionByAddr.set(key, operation);\n\n try {\n await operation;\n } catch (error) {\n log(\"createPermission error\", error);\n throw error;\n } finally {\n if (this.creatingPermissionByAddr.get(key) === operation) {\n this.creatingPermissionByAddr.delete(key);\n }\n }\n }\n\n /**\n * Ensure a ChannelBind exists for the peer transport address.\n * Peer failures are isolated; concurrent same-peer calls share one Promise.\n */\n async getChannel(addr: Address): Promise<TurnChannel> {\n const key = channelKey(addr);\n\n const existing = this.channelBindingByAddr.get(key);\n if (existing) {\n return existing;\n }\n\n // Fast path: bound and not due for refresh.\n const cached = this.channelByAddr[key];\n const now = int(Date.now() / 1000);\n if (cached && cached.refreshAt > now) {\n return cached;\n }\n\n const operation = this.channelBindQueue.then(() =>\n this.ensureChannel(addr),\n );\n\n // Do not let rejection poison subsequent peers on the shared queue.\n this.channelBindQueue = operation.then(\n () => undefined,\n () => undefined,\n );\n\n this.channelBindingByAddr.set(key, operation);\n\n try {\n return await operation;\n } catch (error) {\n log(\"channelBind error\", error);\n throw error;\n } finally {\n if (this.channelBindingByAddr.get(key) === operation) {\n this.channelBindingByAddr.delete(key);\n }\n }\n }\n\n /**\n * Create or refresh a channel for addr. Provisional mapping is installed\n * before the request so early ChannelData can be decoded; only a failed\n * *initial* bind rolls the mapping back. Failed channel numbers are never\n * reused.\n */\n private async ensureChannel(addr: Address): Promise<TurnChannel> {\n const key = channelKey(addr);\n const now = int(Date.now() / 1000);\n\n let channel = this.channelByAddr[key];\n if (channel && channel.refreshAt > now) {\n return channel;\n }\n\n const isNew = !channel;\n\n if (!channel) {\n channel = {\n number: this.channelNumber++,\n address: addr,\n refreshAt: 0,\n };\n // Provisional mapping for ChannelData that may arrive before success.\n this.channelByAddr[key] = channel;\n this.addrByChannel[channel.number] = addr;\n }\n\n try {\n await this.channelBind(channel.number, addr);\n channel.refreshAt = int(Date.now() / 1000) + this.channelRefreshTime;\n log(isNew ? \"channelBind\" : \"channelBind refresh\", channel);\n return channel;\n } catch (error) {\n if (isNew) {\n // Roll back provisional mapping only for a failed initial bind.\n delete this.channelByAddr[key];\n delete this.addrByChannel[channel.number];\n // Do not reuse the channel number (no channelNumber--).\n }\n throw error;\n }\n }\n\n private async channelBind(channelNumber: number, addr: Address) {\n const request = new Message(methods.CHANNEL_BIND, classes.REQUEST);\n request\n .setAttribute(\"CHANNEL-NUMBER\", channelNumber)\n .setAttribute(\"XOR-PEER-ADDRESS\", addr);\n const [response] = await this.requestWithRetry(request, this.server);\n if (response.messageMethod !== methods.CHANNEL_BIND) {\n throw new Error(\"should be CHANNEL_BIND\");\n }\n }\n\n async sendStun(message: Message, addr: Address) {\n await this.send(message.bytes, addr);\n }\n\n /**\n * Release the client: its transactions, refresh timer and socket. Known\n * constraint (as in develop): the allocation is not deleted on the server\n * (no Refresh with lifetime 0), so the server keeps it until its lifetime\n * ends.\n */\n async close() {\n if (this.closed) return;\n this.closed = true;\n // An allocation, refresh or ChannelBind still waiting settles now.\n for (const transaction of Object.values(this.transactions)) {\n transaction.cancel();\n }\n this.refreshHandle?.resolve?.();\n await this.transport.close();\n }\n}\n\nexport interface TurnClientConfig {\n address: Address;\n username: string;\n password: string;\n}\nexport interface TurnClientOptions {\n lifetime?: number;\n ssl?: boolean;\n transport?: \"udp\" | \"tcp\" | \"tls\";\n tlsOptions?: TlsConnectionOptions;\n portRange?: [number, number];\n interfaceAddresses?: InterfaceAddresses;\n /** Maximum time to wait for TCP/TLS connection establishment, in milliseconds. */\n connectTimeoutMs?: number;\n /**\n * Preferred IP family of the UDP socket, applied only when the server\n * address is a hostname. Ignored for an IP literal server address, whose\n * own family always selects the socket. Defaults to 4.\n */\n udpFamily?: 4 | 6;\n /**\n * Aborting it while the allocation runs closes the client (its socket and\n * transactions) and rejects with `TransactionCancelled`.\n */\n signal?: AbortSignal;\n}\n\n/**\n * Select the UDP socket type for a TURN server.\n * Precedence: IP literal family > udpFamily > 4.\n * An IP literal fixes the destination family, so a conflicting udpFamily is\n * ignored (and logged) rather than making the server unreachable.\n */\nfunction selectTurnUdpSocketType(\n address: Address,\n udpFamily: 4 | 6 | undefined,\n): \"udp4\" | \"udp6\" {\n const literalFamily = isIP(address[0]);\n if (literalFamily === 4 || literalFamily === 6) {\n if (udpFamily && udpFamily !== literalFamily) {\n log(\"udpFamily ignored for IP literal TURN server\", {\n address,\n udpFamily,\n literalFamily,\n });\n }\n return literalFamily === 6 ? \"udp6\" : \"udp4\";\n }\n return (udpFamily ?? 4) === 6 ? \"udp6\" : \"udp4\";\n}\n\nexport async function createTurnClient(\n { address, username, password }: TurnClientConfig,\n {\n lifetime,\n portRange,\n interfaceAddresses,\n ssl,\n tlsOptions,\n transport: transportType,\n connectTimeoutMs,\n udpFamily,\n signal,\n }: TurnClientOptions = {},\n) {\n lifetime ??= DEFAULT_ALLOCATION_LIFETIME;\n transportType ??= ssl ? \"tls\" : \"udp\";\n const transport =\n transportType === \"udp\"\n ? await UdpTransport.init(selectTurnUdpSocketType(address, udpFamily), {\n portRange,\n interfaceAddresses,\n })\n : transportType === \"tcp\"\n ? await TcpTransport.init(address, { connectTimeoutMs })\n : await TlsTransport.init(address, tlsOptions, { connectTimeoutMs });\n\n const turn = new TurnProtocol(\n address,\n username,\n password,\n lifetime,\n transport,\n {\n reconnect:\n transportType === \"udp\"\n ? undefined\n : (alternate, alternateDomain) =>\n transportType === \"tcp\"\n ? TcpTransport.init(alternate, { connectTimeoutMs })\n : TlsTransport.init(\n alternate,\n alternateTlsOptions(address, alternateDomain, tlsOptions),\n { connectTimeoutMs },\n ),\n },\n );\n // The owner (an ICE agent) closed while the allocation runs: release the\n // socket and its retransmissions now instead of after the allocation.\n const abort = () => {\n turn\n .close()\n .catch((error) => log(\"failed to close aborted TURN client\", error));\n };\n if (signal?.aborted) abort();\n signal?.addEventListener(\"abort\", abort, { once: true });\n\n try {\n if (signal?.aborted) throw new TransactionCancelled();\n await turn.connectionMade();\n if (signal?.aborted) throw new TransactionCancelled();\n } catch (error) {\n try {\n await turn.close();\n } catch (closeError) {\n log(\"failed to close TURN client after allocation failure\", closeError);\n }\n throw error;\n } finally {\n signal?.removeEventListener(\"abort\", abort);\n }\n return turn;\n}\n\nexport async function createStunOverTurnClient(\n config: TurnClientConfig,\n options: TurnClientOptions = {},\n) {\n const turn = await createTurnClient(config, options);\n const turnTransport = new StunOverTurnProtocol(turn);\n return turnTransport;\n}\n\n/**\n * TLS options for a connection to an ALTERNATE-SERVER (an IP literal). The\n * certificate is validated against ALTERNATE-DOMAIN when present, otherwise\n * against the name the original server would have been validated with\n * (RFC 8489 §10): `tlsOptions.servername`, else the configured host.\n */\nfunction alternateTlsOptions(\n configured: Address,\n alternateDomain: string | undefined,\n tlsOptions: TlsConnectionOptions = {},\n): TlsConnectionOptions {\n const identity = alternateDomain ?? tlsOptions.servername ?? configured[0];\n const checkServerIdentity =\n tlsOptions.checkServerIdentity ?? tls.checkServerIdentity;\n return {\n ...tlsOptions,\n // SNI cannot carry an IP literal.\n servername: isIP(identity) ? undefined : identity,\n checkServerIdentity: (_host, cert) => checkServerIdentity(identity, cert),\n };\n}\n\n/**\n * The redirect target of a 300 (Try Alternate) error response, or undefined\n * for any other error. `server` is undefined when ALTERNATE-SERVER is\n * missing.\n */\nfunction tryAlternateOf(\n error: unknown,\n addressFamily?: number,\n): { server?: Address; domain?: string } | undefined {\n if (!(error instanceof TransactionFailed)) {\n return undefined;\n }\n const [errorCode] = error.response.getAttributeValue(\"ERROR-CODE\") ?? [];\n if (errorCode !== 300) {\n return undefined;\n }\n // A response may carry one ALTERNATE-SERVER per address family (RFC 8489\n // §10): take the first one this transport can reach, else the first.\n const servers = error.response.alternateServers;\n const reachable = servers.find(\n ([host]) => addressFamily === undefined || ipFamily(host) === addressFamily,\n );\n return {\n server: reachable ?? servers[0],\n domain: error.response.getAttributeValue(\"ALTERNATE-DOMAIN\"),\n };\n}\n\nfunction ipFamily(host: string): number {\n return host.includes(\":\") ? 6 : 4;\n}\n\nexport function makeIntegrityKey(\n username: string,\n realm: string,\n password: string,\n) {\n return makeTurnIntegrityKey(username, realm, password);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../../ice/src/turn/protocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuhCA,4CAuEC;AAED,4DAOC;AAwDD,4CAMC;AArqCD,uCAAgC;AAChC,8CAAgC;AAChC,8CAA6C;AAE7C,4DAAyE;AAEzE,8CAKuB;AACvB,sCAA6E;AAC7E,8CAa2B;AAC3B,yCAA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C7D,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,KAAa,EACb,QAAgB;IAEhB,OAAO,IAAA,2BAAoB,EAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { isIP } from \"node:net\";\nimport * as tls from \"node:tls\";\nimport { setTimeout } from \"timers/promises\";\n\nimport { makeTurnIntegrityKey } from \"../../../ice-server/src/turn/auth\";\nimport type { Candidate } from \"../candidate\";\nimport {\n TransactionCancelled,\n TransactionChallenge,\n TransactionFailed,\n TurnRedirectError,\n} from \"../exceptions\";\nimport { type Cancelable, cancelable, randomTransactionId } from \"../helper\";\nimport {\n type Address,\n bufferReader,\n debug,\n Event,\n EventDisposer,\n type InterfaceAddresses,\n int,\n TcpTransport,\n type TlsConnectionOptions,\n TlsTransport,\n type Transport,\n UdpTransport,\n} from \"../imports/common\";\nimport { classes, methods } from \"../stun/const\";\nimport { Message, paddingLength, parseMessage } from \"../stun/message\";\nimport {\n addressEquals,\n buildTransactionOptions,\n hasMessageIntegrity,\n isUnauthenticatedChallenge,\n resolveRequestAddress,\n Transaction,\n} from \"../stun/transaction\";\nimport type { Protocol, TransactionRequestOptions } from \"../types/model\";\nimport { credentialRetryOf } from \"./credential\";\nimport {\n decodeChannelData,\n encodeChannelData,\n isChannelData,\n padTurnFrame,\n splitTurnTcpFrames,\n} from \"./frame\";\n\nconst log = debug(\"werift-ice:packages/ice/src/turn/protocol.ts\");\n\nconst DEFAULT_CHANNEL_REFRESH_TIME = 500;\nconst DEFAULT_ALLOCATION_LIFETIME = 600;\nconst UDP_TRANSPORT = 0x11000000;\n/** 300 (Try Alternate) redirects followed for one Allocate before giving up. */\nconst DEFAULT_MAX_ALLOCATE_REDIRECTS = 3;\n\nexport {\n TurnRedirectError,\n type TurnRedirectFailureReason,\n} from \"../exceptions\";\n\n/**\n * Opens a new stream transport to the TURN server named by a 300 (Try\n * Alternate) ALTERNATE-SERVER. `alternateDomain` is the ALTERNATE-DOMAIN\n * attribute, if any, which a TLS transport must validate the certificate\n * against (RFC 8489 §10).\n */\nexport type TurnStreamReconnect = (\n server: Address,\n alternateDomain: string | undefined,\n) => Promise<Transport>;\n\n/** Where a 300 (Try Alternate) response tells the client to go. */\ninterface TurnAlternate {\n server: Address;\n domain?: string;\n}\n\n/** Channel binding state for a single peer transport address. */\nexport interface TurnChannel {\n number: number;\n address: Address;\n /** Unix seconds when this channel should be refreshed. */\n refreshAt: number;\n}\n\nfunction isStreamTransport(transport: Transport) {\n return transport.type === \"tcp\" || transport.type === \"tls\";\n}\n\n/** Permission is peer-IP scoped (RFC 8656). */\nfunction permissionKey(addr: Address): string {\n return addr[0];\n}\n\n/** ChannelBind is peer transport-address scoped (IP + port). */\nfunction channelKey(addr: Address): string {\n return JSON.stringify(addr);\n}\n\nexport class StunOverTurnProtocol implements Protocol {\n public turn: TurnProtocol;\n /**\n * The transport the TURN server was configured with. A UDP entry whose\n * allocation fell back to TCP keeps \"udp\" here, so a restart that removes\n * that entry also releases the fallback allocation.\n */\n configuredTransport?: \"udp\" | \"tcp\" | \"tls\";\n\n static type = \"turn\";\n readonly type = StunOverTurnProtocol.type;\n localCandidate!: Candidate;\n private disposer = new EventDisposer();\n onRequestReceived: Event<[Message, Address, Buffer]> = new Event();\n onDataReceived: Event<[Buffer, Address]> = new Event();\n\n constructor(turn: TurnProtocol) {\n this.turn = turn;\n turn.onData\n .subscribe((data, addr) => {\n this.handleStunMessage(data, addr);\n })\n .disposer(this.disposer);\n }\n\n private handleStunMessage = (data: Buffer, addr: Address) => {\n try {\n const message = parseMessage(data);\n if (!message) {\n this.onDataReceived.execute(data, addr);\n return;\n }\n\n if (\n message.messageClass === classes.RESPONSE ||\n message.messageClass === classes.ERROR\n ) {\n const transaction = this.turn.transactions[message.transactionIdHex];\n if (transaction) {\n const verified = transaction.integrityKey\n ? parseMessage(data, transaction.integrityKey)\n : message;\n if (!verified) {\n log(\"STUN over TURN response failed MESSAGE-INTEGRITY check\");\n return;\n }\n transaction.responseReceived(verified, addr);\n }\n } else if (message.messageClass === classes.REQUEST) {\n this.onRequestReceived.execute(message, addr, data);\n }\n } catch (error) {\n log(\"datagramReceived error\", error);\n }\n };\n\n async request(\n request: Message,\n addr: Address,\n integrityKey?: Buffer,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n ) {\n if (this.turn.transactions[request.transactionIdHex]) {\n throw new Error(\"exist\");\n }\n\n const options = buildTransactionOptions(\n integrityKey,\n retransmissionsOrOptions,\n onRequestSent,\n );\n if (integrityKey) {\n request.addIntegrity(integrityKey, options.integrityAlgorithm);\n request.addFingerprint();\n }\n\n // Peer-facing STUN over TURN must honor retransmissions/responseTimeout\n // (consent uses retransmissions: 0). Do not confuse with TURN server\n // allocation/refresh policy on TurnProtocol.\n // Peer addresses are already IPs from candidates; resolve for safety.\n const resolvedAddr = await resolveRequestAddress(addr);\n const transaction = new Transaction(request, resolvedAddr, this, options);\n this.turn.transactions[request.transactionIdHex] = transaction;\n\n try {\n return await transaction.run();\n } catch (e) {\n throw e;\n } finally {\n delete this.turn.transactions[request.transactionIdHex];\n }\n }\n async connectionMade() {}\n async sendData(data: Buffer, addr: Address) {\n await this.turn.sendData(data, addr);\n }\n async sendStun(message: Message, addr: Address) {\n await this.turn.sendData(message.bytes, addr);\n }\n async close() {\n this.disposer.dispose();\n return this.turn.close();\n }\n}\n\nexport class TurnProtocol implements Protocol {\n /**\n * TURN server the allocation is made on; the host may be a hostname.\n * Starts as the configured server and becomes the ALTERNATE-SERVER when\n * an Allocate is redirected with 300 (Try Alternate).\n */\n public server: Address;\n public username: string;\n public password: string;\n public lifetime: number;\n public transport: Transport;\n public options: {\n /**sec */\n channelRefreshTime?: number;\n /**\n * 300 (Try Alternate) redirects followed for one Allocate.\n * Defaults to 3.\n */\n maxAllocateRedirects?: number;\n /**\n * Reconnects a TCP/TLS transport to an ALTERNATE-SERVER. Without it, a\n * redirect over a stream transport fails with TurnRedirectError\n * (\"unsupported-transport\"). UDP needs no reconnect.\n */\n reconnect?: TurnStreamReconnect;\n };\n\n static type = \"turn\";\n readonly type = TurnProtocol.type;\n readonly onData = new Event<[Buffer, Address]>();\n onRequestReceived: Event<[Message, Address, Buffer]> = new Event();\n onDataReceived: Event<[Buffer, Address]> = new Event();\n integrityKey?: Buffer;\n nonce?: Buffer;\n realm?: string;\n relayedAddress!: Address;\n mappedAddress!: Address;\n localCandidate!: Candidate;\n transactions: { [hexId: string]: Transaction } = {};\n /** close() ran: no new transaction starts. */\n private closed = false;\n private refreshHandle?: Cancelable<void>;\n private channelNumber = 0x4000;\n private channelByAddr: { [key: string]: TurnChannel } = {};\n private addrByChannel: { [channel: number]: Address } = {};\n /**sec */\n private channelRefreshTime: number;\n /**\n * Serializes ChannelBind requests so allocation-wide auth state\n * (nonce/realm/integrityKey) is not updated concurrently. Rejections\n * must not poison this tail — see channelBindQueue assignment sites.\n */\n private channelBindQueue: Promise<void> = Promise.resolve();\n /** In-flight ChannelBind per peer transport address (dedupe concurrent). */\n private channelBindingByAddr = new Map<string, Promise<TurnChannel>>();\n private tcpBuffer: Buffer = Buffer.alloc(0);\n /** Permission cache keyed by peer IP only (RFC 8656). */\n private permissionByAddr: { [peerIp: string]: boolean } = {};\n /**\n * Serializes CreatePermission requests (auth state race avoidance).\n * Rejections must not poison this tail.\n */\n private permissionQueue: Promise<void> = Promise.resolve();\n /** In-flight CreatePermission per peer IP (dedupe concurrent). */\n private creatingPermissionByAddr = new Map<string, Promise<void>>();\n /** Concrete TURN server address the allocation lives on, once selected. */\n private pinnedServerEndpoint?: Address;\n private serverEndpointSelection?: Promise<Address>;\n\n /** TURN server as configured, before any 300 (Try Alternate) redirect. */\n readonly configuredServer: Address;\n\n constructor(\n server: Address,\n username: string,\n password: string,\n lifetime: number,\n transport: Transport,\n options: {\n /**sec */\n channelRefreshTime?: number;\n /**\n * 300 (Try Alternate) redirects followed for one Allocate.\n * Defaults to 3.\n */\n maxAllocateRedirects?: number;\n /**\n * Reconnects a TCP/TLS transport to an ALTERNATE-SERVER. Without it, a\n * redirect over a stream transport fails with TurnRedirectError\n * (\"unsupported-transport\"). UDP needs no reconnect.\n */\n reconnect?: TurnStreamReconnect;\n } = {},\n ) {\n this.server = server;\n this.username = username;\n this.password = password;\n this.lifetime = lifetime;\n this.transport = transport;\n this.options = options;\n this.configuredServer = server;\n this.channelRefreshTime =\n this.options.channelRefreshTime ?? DEFAULT_CHANNEL_REFRESH_TIME;\n }\n\n async connectionMade() {\n this.attachTransport();\n\n const [response] = await this.allocate().catch((e) => {\n log(\"connect error\", e);\n throw e;\n });\n this.relayedAddress = response.getAttributeValue(\"XOR-RELAYED-ADDRESS\");\n this.mappedAddress = response.getAttributeValue(\"XOR-MAPPED-ADDRESS\");\n const exp = response.getAttributeValue(\"LIFETIME\");\n log(\"connect\", this.relayedAddress, this.mappedAddress, { exp });\n\n // close() ran while the response was in flight: no refresh starts.\n if (this.closed) throw new TransactionCancelled();\n this.refresh(exp);\n }\n\n private attachTransport() {\n this.transport.onData = (data, addr) => {\n this.dataReceived(data, addr);\n };\n this.transport.onError?.subscribe((error) => {\n log(\"transport error\", error);\n });\n }\n\n /**\n * Allocate on the current server, following 300 (Try Alternate) to the\n * ALTERNATE-SERVER with the same transport protocol and credentials\n * (RFC 8656 §7.4, RFC 8489 §10). Only Allocate is redirected: an existing\n * allocation lives on one server, so Refresh, CreatePermission and\n * ChannelBind never move.\n */\n private async allocate(): Promise<[Message, Address]> {\n const maxRedirects =\n this.options.maxAllocateRedirects ?? DEFAULT_MAX_ALLOCATE_REDIRECTS;\n /** Servers this Allocate has been sent to, to detect redirect loops. */\n const tried: Address[] = [];\n\n for (let redirects = 0; ; redirects++) {\n // A fresh request per server: a redirected request may already carry\n // MESSAGE-INTEGRITY for the previous server's realm and nonce.\n const request = new Message(methods.ALLOCATE, classes.REQUEST)\n .setAttribute(\"LIFETIME\", this.lifetime)\n .setAttribute(\"REQUESTED-TRANSPORT\", UDP_TRANSPORT);\n\n try {\n return await this.requestWithRetry(request, this.server);\n } catch (error) {\n const alternate = tryAlternateOf(error, this.transport.addressFamily);\n if (!alternate) {\n throw error;\n }\n // The request has resolved the configured host, so its endpoint is\n // known here: a redirect to the resolved IP of a host name is a loop.\n tried.push(this.server);\n if (this.pinnedServerEndpoint) {\n tried.push(this.pinnedServerEndpoint);\n }\n const failed = error as TransactionFailed;\n const fail = (\n reason: ConstructorParameters<typeof TurnRedirectError>[0],\n ) =>\n new TurnRedirectError(reason, this.server, alternate.server, failed);\n\n if (!alternate.server) {\n throw new TurnRedirectError(\n \"missing-alternate\",\n this.server,\n undefined,\n failed,\n );\n }\n if (tried.some((addr) => addressEquals(addr, alternate.server!))) {\n throw fail(\"loop\");\n }\n if (redirects >= maxRedirects) {\n throw fail(\"too-many-redirects\");\n }\n if (isStreamTransport(this.transport) && !this.options.reconnect) {\n throw fail(\"unsupported-transport\");\n }\n\n log(\"allocate redirected\", this.server, \"->\", alternate);\n await this.switchServer(alternate as TurnAlternate);\n }\n }\n }\n\n /**\n * Point the client at an ALTERNATE-SERVER. Authentication state belongs to\n * the previous server, so the alternate starts again with an\n * unauthenticated Allocate and its own 401 realm/nonce; username and\n * password are kept.\n */\n private async switchServer({ server, domain }: TurnAlternate) {\n let endpoint: Address;\n if (isStreamTransport(this.transport)) {\n const previous = this.transport;\n previous.onData = () => {};\n await previous.close();\n const reconnected = await this.options.reconnect!(server, domain);\n // close() ran while reconnecting: it saw only the closed previous\n // transport, so the new connection is released here.\n if (this.closed) {\n reconnected.onData = () => {};\n await reconnected.close();\n throw new TransactionCancelled();\n }\n this.transport = reconnected;\n this.tcpBuffer = Buffer.alloc(0);\n this.attachTransport();\n endpoint = this.transport.remoteAddress ?? server;\n } else {\n // ALTERNATE-SERVER is an IP literal. One of the other family cannot be\n // reached from this socket (AddressFamilyMismatch).\n endpoint = await resolveRequestAddress(\n server,\n this.transport.addressFamily ?? 0,\n );\n }\n\n this.server = server;\n this.pinnedServerEndpoint = endpoint;\n this.serverEndpointSelection = Promise.resolve(endpoint);\n this.nonce = undefined;\n this.realm = undefined;\n this.integrityKey = undefined;\n }\n\n private handleChannelData(data: Buffer) {\n const decoded = decodeChannelData(data);\n const addr = decoded && this.addrByChannel[decoded.channelNumber];\n\n if (addr && decoded) {\n this.onData.execute(decoded.data, addr);\n }\n }\n\n private handleSTUNMessage(data: Buffer, addr: Address) {\n try {\n const message = parseMessage(data);\n if (!message) {\n throw new Error(\"not stun message\");\n }\n\n if (\n message.messageClass === classes.RESPONSE ||\n message.messageClass === classes.ERROR\n ) {\n const transaction = this.transactions[message.transactionIdHex];\n if (transaction) {\n this.handleResponse(transaction, message, data, addr);\n }\n } else if (message.messageClass === classes.REQUEST) {\n this.onData.execute(data, addr);\n }\n\n if (message.getAttributeValue(\"DATA\")) {\n const buf: Buffer = message.getAttributeValue(\"DATA\");\n const peerAddress =\n message.getAttributeValue(\"XOR-PEER-ADDRESS\") ?? addr;\n this.onData.execute(buf, peerAddress);\n }\n } catch (error) {\n log(\"parse error\", data.toString());\n }\n }\n\n /**\n * Long-term credentials (RFC 8489 §9.2.5): a response to an authenticated\n * request must carry a valid MESSAGE-INTEGRITY, except a 401/438 challenge\n * without one, which goes to the retry logic of requestWithRetry. Over\n * UDP an unverified response is dropped and retransmissions continue; over\n * TCP/TLS it ends the transaction, except an unsigned 400, which is\n * discarded as if never received.\n */\n private handleResponse(\n transaction: Transaction,\n message: Message,\n data: Buffer,\n addr: Address,\n ) {\n if (!transaction.integrityKey) {\n transaction.responseReceived(message, addr);\n return;\n }\n if (isUnauthenticatedChallenge(message)) {\n transaction.challengeReceived(message, addr);\n return;\n }\n const verified = parseMessage(data, transaction.integrityKey);\n if (verified) {\n transaction.responseReceived(verified, addr);\n return;\n }\n log(\"TURN STUN response failed MESSAGE-INTEGRITY check\");\n const [errorCode] = message.getAttributeValue(\"ERROR-CODE\") ?? [];\n const unsignedBadRequest =\n message.messageClass === classes.ERROR &&\n errorCode === 400 &&\n !hasMessageIntegrity(message);\n if (isStreamTransport(this.transport) && !unsignedBadRequest) {\n transaction.integrityViolated(addr);\n }\n }\n\n private dataReceived(data: Buffer, addr: Address) {\n const datagramReceived = (data: Buffer, addr: Address) => {\n if (data.length >= 4 && isChannelData(data)) {\n this.handleChannelData(data);\n } else {\n this.handleSTUNMessage(data, addr);\n }\n };\n\n if (isStreamTransport(this.transport)) {\n this.tcpBuffer = Buffer.concat([this.tcpBuffer, data]);\n const { frames, rest } = splitTurnTcpFrames(this.tcpBuffer);\n this.tcpBuffer = rest;\n for (const frame of frames) {\n datagramReceived(frame, addr);\n }\n } else {\n datagramReceived(data, addr);\n }\n }\n\n private async send(data: Buffer, addr: Address) {\n if (this.transport.closed) {\n return;\n }\n\n await this.transport.send(\n isStreamTransport(this.transport) ? padTurnFrame(data) : data,\n addr,\n );\n }\n\n private async createPermission(peerAddress: Address) {\n const request = new Message(methods.CREATE_PERMISSION, classes.REQUEST);\n request\n .setAttribute(\"XOR-PEER-ADDRESS\", peerAddress)\n .setAttribute(\"USERNAME\", this.username)\n .setAttribute(\"REALM\", this.realm)\n .setAttribute(\"NONCE\", this.nonce);\n // Use requestWithRetry for stale-nonce (438) consistency with ChannelBind.\n await this.requestWithRetry(request, this.server);\n }\n\n private refresh = (exp: number) => {\n this.refreshHandle = cancelable<void>(async (_, __, onCancel) => {\n const abort = new AbortController();\n onCancel.once(() => {\n abort.abort();\n });\n\n while (!abort.signal.aborted) {\n // refresh before expire\n const delay = (5 / 6) * exp * 1000;\n log(\"refresh delay\", delay, { exp });\n try {\n await setTimeout(delay, undefined, { signal: abort.signal });\n } catch (error) {\n if (abort.signal.aborted) {\n return;\n }\n throw error;\n }\n\n if (abort.signal.aborted) {\n return;\n }\n\n const request = new Message(methods.REFRESH, classes.REQUEST);\n request.setAttribute(\"LIFETIME\", exp);\n\n try {\n const [message] = await this.requestWithRetry(\n request,\n this.server,\n abort.signal,\n );\n exp = message.getAttributeValue(\"LIFETIME\");\n log(\"refresh\", { exp });\n } catch (error) {\n if (abort.signal.aborted) {\n return;\n }\n log(\"refresh error\", error);\n }\n }\n });\n };\n\n async request(\n request: Message,\n addr: Address,\n _integrityKey?: Buffer,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n credentials?: { realm: string; nonce: Buffer; integrityKey: Buffer },\n ): Promise<[Message, Address]> {\n if (this.transactions[request.transactionIdHex]) {\n throw new Error(\"exist\");\n }\n // Long-term credentials stay MESSAGE-INTEGRITY (SHA-1): SHA-256 needs the\n // PASSWORD-ALGORITHM(S) negotiation of RFC 8489 §9.2, which is out of\n // scope here (options.integrityAlgorithm is not applied).\n const signing = credentials ?? {\n realm: this.realm,\n nonce: this.nonce,\n integrityKey: this.integrityKey,\n };\n if (signing.integrityKey) {\n // A retried request still carries the previous signature, which would\n // otherwise be covered by the new MESSAGE-INTEGRITY.\n request\n .removeAttribute(\"MESSAGE-INTEGRITY\")\n .removeAttribute(\"MESSAGE-INTEGRITY-SHA256\")\n .removeAttribute(\"FINGERPRINT\")\n .setAttribute(\"USERNAME\", this.username)\n .setAttribute(\"REALM\", signing.realm)\n .setAttribute(\"NONCE\", signing.nonce)\n .addMessageIntegrity(signing.integrityKey)\n .addFingerprint();\n }\n\n // TURN server allocation/refresh uses default STUN retry policy unless\n // callers pass explicit options. Peer consent goes through StunOverTurnProtocol.\n // Prefer the TURN session integrity key for response verification.\n const resolvedAddr = await this.resolveRequestTarget(addr);\n // close() ran during the lookup: no transaction starts on a closed client.\n if (this.closed) throw new TransactionCancelled();\n const options = buildTransactionOptions(\n signing.integrityKey,\n retransmissionsOrOptions,\n onRequestSent,\n );\n const transaction = new Transaction(request, resolvedAddr, this, options);\n this.transactions[request.transactionIdHex] = transaction;\n\n try {\n return await transaction.run();\n } catch (e) {\n throw e;\n } finally {\n delete this.transactions[request.transactionIdHex];\n }\n }\n\n /**\n * The concrete TURN server address, selected on the first request and\n * pinned for the rest of the allocation, so a later DNS answer can never\n * move REFRESH, CREATE_PERMISSION, CHANNEL_BIND or data to another server.\n */\n get serverEndpoint(): Address | undefined {\n return this.pinnedServerEndpoint;\n }\n\n /**\n * Address a request to `addr` is sent to, and the address its response\n * must come from. A stream carries every request to the peer it is\n * connected to, so it always uses the server endpoint.\n */\n private async resolveRequestTarget(addr: Address): Promise<Address> {\n if (isStreamTransport(this.transport) || addressEquals(addr, this.server)) {\n return this.selectServerEndpoint();\n }\n return resolveRequestAddress(addr, this.transport.addressFamily ?? 0);\n }\n\n private async serverDestination(): Promise<Address> {\n return this.pinnedServerEndpoint ?? this.selectServerEndpoint();\n }\n\n private selectServerEndpoint(): Promise<Address> {\n this.serverEndpointSelection ??= this.resolveServerEndpoint().then(\n (endpoint) => {\n this.pinnedServerEndpoint = endpoint;\n return endpoint;\n },\n (error) => {\n // Let a later request try again, e.g. after a transient DNS failure.\n this.serverEndpointSelection = undefined;\n throw error;\n },\n );\n return this.serverEndpointSelection;\n }\n\n /**\n * UDP: resolve the configured server in the bound socket's family; a udp4\n * socket cannot send to an IPv6 answer. TCP/TLS: use the peer the socket\n * actually connected to. Looking the hostname up again could return a\n * different A/AAAA record, and responses from the real peer would then be\n * dropped as coming from an unexpected address.\n */\n private async resolveServerEndpoint(): Promise<Address> {\n const transport = this.transport;\n if (!isStreamTransport(transport)) {\n return resolveRequestAddress(this.server, transport.addressFamily ?? 0);\n }\n if (transport.remoteAddress) {\n return transport.remoteAddress;\n }\n if (\n transport instanceof TcpTransport ||\n transport instanceof TlsTransport\n ) {\n throw new Error(`${transport.type} transport has no remote address`);\n }\n // A custom stream transport that does not report its peer: fall back to\n // a lookup with no family preference.\n return resolveRequestAddress(this.server);\n }\n\n /**\n * Send a request and follow the long-term credential mechanism of\n * RFC 8489 §9.2.5: a 401 (Unauthenticated) or 438 (Stale Nonce) that\n * allows it (see credentialRetryOf) is retried once with the new realm and\n * nonce; any other error, or a second challenge, is thrown. The allocation's\n * realm, nonce and integrity key change only when a retry is made; a retry\n * under a new realm adopts them only once the server accepted it.\n */\n async requestWithRetry(\n request: Message,\n addr: Address,\n signal?: AbortSignal,\n ): Promise<[Message, Address]> {\n try {\n return await this.request(request, addr, undefined, { signal });\n } catch (error) {\n if (error instanceof TransactionFailed == false) {\n log(\"requestWithRetry error\", error);\n throw error;\n }\n\n // request() signed the request with the credentials of that moment.\n const authenticated =\n request.attributesKeys.includes(\"MESSAGE-INTEGRITY\");\n const sentRealm: string | undefined = authenticated\n ? request.getAttributeValue(\"REALM\")\n : undefined;\n const retry = credentialRetryOf(\n error.response,\n { authenticated, realm: sentRealm },\n this.realm,\n );\n if (!retry) {\n throw error;\n }\n log(\"retry with nonce\", error.str, {\n signedError: !(error instanceof TransactionChallenge),\n });\n\n const integrityKey = makeIntegrityKey(\n this.username,\n retry.realm,\n this.password,\n );\n request.transactionId = randomTransactionId();\n\n // A new realm on an authenticated request rekeys the whole allocation.\n // Sign the retry with its own credentials and adopt them only once the\n // server accepted it, so concurrent failures never overwrite the shared\n // state with credentials that were rejected.\n if (authenticated && retry.realm !== sentRealm) {\n const credentials = {\n realm: retry.realm,\n nonce: retry.nonce,\n integrityKey,\n };\n const result = await this.request(\n request,\n this.server,\n undefined,\n { signal },\n undefined,\n credentials,\n );\n this.nonce = credentials.nonce;\n this.realm = credentials.realm;\n this.integrityKey = credentials.integrityKey;\n return result;\n }\n\n this.nonce = retry.nonce;\n this.realm = retry.realm;\n this.integrityKey = integrityKey;\n return await this.request(request, this.server, undefined, { signal });\n }\n }\n\n async sendData(data: Buffer, addr: Address) {\n let channel: TurnChannel | undefined;\n try {\n channel = await this.getChannel(addr);\n } catch (e) {\n // Keep original ChannelBind error for diagnostics (403/438/timeout).\n log(\"channelBind error; falling back to Send Indication\", e);\n }\n\n if (!channel) {\n await this.getPermission(addr);\n const indicate = new Message(methods.SEND, classes.INDICATION)\n .setAttribute(\"DATA\", data)\n .setAttribute(\"XOR-PEER-ADDRESS\", addr);\n\n await this.sendStun(indicate, await this.serverDestination());\n return;\n }\n\n await this.send(\n encodeChannelData(channel.number, data),\n await this.serverDestination(),\n );\n }\n\n /**\n * Ensure a CreatePermission exists for the peer IP.\n * Peer failures are isolated: a rejection for peer A does not poison peer B.\n */\n async getPermission(addr: Address) {\n const key = permissionKey(addr);\n\n if (this.permissionByAddr[key]) {\n return;\n }\n\n const existing = this.creatingPermissionByAddr.get(key);\n if (existing) {\n return existing;\n }\n\n const operation = this.permissionQueue.then(async () => {\n // Another caller may have succeeded while we waited on the queue.\n if (this.permissionByAddr[key]) {\n return;\n }\n\n await this.createPermission(addr);\n // Cache only after successful CreatePermission.\n this.permissionByAddr[key] = true;\n });\n\n // Do not let rejection poison subsequent peers on the shared queue.\n this.permissionQueue = operation.then(\n () => undefined,\n () => undefined,\n );\n\n this.creatingPermissionByAddr.set(key, operation);\n\n try {\n await operation;\n } catch (error) {\n log(\"createPermission error\", error);\n throw error;\n } finally {\n if (this.creatingPermissionByAddr.get(key) === operation) {\n this.creatingPermissionByAddr.delete(key);\n }\n }\n }\n\n /**\n * Ensure a ChannelBind exists for the peer transport address.\n * Peer failures are isolated; concurrent same-peer calls share one Promise.\n */\n async getChannel(addr: Address): Promise<TurnChannel> {\n const key = channelKey(addr);\n\n const existing = this.channelBindingByAddr.get(key);\n if (existing) {\n return existing;\n }\n\n // Fast path: bound and not due for refresh.\n const cached = this.channelByAddr[key];\n const now = int(Date.now() / 1000);\n if (cached && cached.refreshAt > now) {\n return cached;\n }\n\n const operation = this.channelBindQueue.then(() =>\n this.ensureChannel(addr),\n );\n\n // Do not let rejection poison subsequent peers on the shared queue.\n this.channelBindQueue = operation.then(\n () => undefined,\n () => undefined,\n );\n\n this.channelBindingByAddr.set(key, operation);\n\n try {\n return await operation;\n } catch (error) {\n log(\"channelBind error\", error);\n throw error;\n } finally {\n if (this.channelBindingByAddr.get(key) === operation) {\n this.channelBindingByAddr.delete(key);\n }\n }\n }\n\n /**\n * Create or refresh a channel for addr. Provisional mapping is installed\n * before the request so early ChannelData can be decoded; only a failed\n * *initial* bind rolls the mapping back. Failed channel numbers are never\n * reused.\n */\n private async ensureChannel(addr: Address): Promise<TurnChannel> {\n const key = channelKey(addr);\n const now = int(Date.now() / 1000);\n\n let channel = this.channelByAddr[key];\n if (channel && channel.refreshAt > now) {\n return channel;\n }\n\n const isNew = !channel;\n\n if (!channel) {\n channel = {\n number: this.channelNumber++,\n address: addr,\n refreshAt: 0,\n };\n // Provisional mapping for ChannelData that may arrive before success.\n this.channelByAddr[key] = channel;\n this.addrByChannel[channel.number] = addr;\n }\n\n try {\n await this.channelBind(channel.number, addr);\n channel.refreshAt = int(Date.now() / 1000) + this.channelRefreshTime;\n log(isNew ? \"channelBind\" : \"channelBind refresh\", channel);\n return channel;\n } catch (error) {\n if (isNew) {\n // Roll back provisional mapping only for a failed initial bind.\n delete this.channelByAddr[key];\n delete this.addrByChannel[channel.number];\n // Do not reuse the channel number (no channelNumber--).\n }\n throw error;\n }\n }\n\n private async channelBind(channelNumber: number, addr: Address) {\n const request = new Message(methods.CHANNEL_BIND, classes.REQUEST);\n request\n .setAttribute(\"CHANNEL-NUMBER\", channelNumber)\n .setAttribute(\"XOR-PEER-ADDRESS\", addr);\n const [response] = await this.requestWithRetry(request, this.server);\n if (response.messageMethod !== methods.CHANNEL_BIND) {\n throw new Error(\"should be CHANNEL_BIND\");\n }\n }\n\n async sendStun(message: Message, addr: Address) {\n await this.send(message.bytes, addr);\n }\n\n /**\n * Release the client: its transactions, refresh timer and socket. Known\n * constraint (as in develop): the allocation is not deleted on the server\n * (no Refresh with lifetime 0), so the server keeps it until its lifetime\n * ends.\n */\n async close() {\n if (this.closed) return;\n this.closed = true;\n // An allocation, refresh or ChannelBind still waiting settles now.\n for (const transaction of Object.values(this.transactions)) {\n transaction.cancel();\n }\n this.refreshHandle?.resolve?.();\n await this.transport.close();\n }\n}\n\nexport interface TurnClientConfig {\n address: Address;\n username: string;\n password: string;\n}\nexport interface TurnClientOptions {\n lifetime?: number;\n ssl?: boolean;\n transport?: \"udp\" | \"tcp\" | \"tls\";\n tlsOptions?: TlsConnectionOptions;\n portRange?: [number, number];\n interfaceAddresses?: InterfaceAddresses;\n /** Maximum time to wait for TCP/TLS connection establishment, in milliseconds. */\n connectTimeoutMs?: number;\n /**\n * Preferred IP family of the UDP socket, applied only when the server\n * address is a hostname. Ignored for an IP literal server address, whose\n * own family always selects the socket. Defaults to 4.\n */\n udpFamily?: 4 | 6;\n /**\n * Aborting it while the allocation runs closes the client (its socket and\n * transactions) and rejects with `TransactionCancelled`.\n */\n signal?: AbortSignal;\n}\n\n/**\n * Select the UDP socket type for a TURN server.\n * Precedence: IP literal family > udpFamily > 4.\n * An IP literal fixes the destination family, so a conflicting udpFamily is\n * ignored (and logged) rather than making the server unreachable.\n */\nfunction selectTurnUdpSocketType(\n address: Address,\n udpFamily: 4 | 6 | undefined,\n): \"udp4\" | \"udp6\" {\n const literalFamily = isIP(address[0]);\n if (literalFamily === 4 || literalFamily === 6) {\n if (udpFamily && udpFamily !== literalFamily) {\n log(\"udpFamily ignored for IP literal TURN server\", {\n address,\n udpFamily,\n literalFamily,\n });\n }\n return literalFamily === 6 ? \"udp6\" : \"udp4\";\n }\n return (udpFamily ?? 4) === 6 ? \"udp6\" : \"udp4\";\n}\n\nexport async function createTurnClient(\n { address, username, password }: TurnClientConfig,\n {\n lifetime,\n portRange,\n interfaceAddresses,\n ssl,\n tlsOptions,\n transport: transportType,\n connectTimeoutMs,\n udpFamily,\n signal,\n }: TurnClientOptions = {},\n) {\n lifetime ??= DEFAULT_ALLOCATION_LIFETIME;\n transportType ??= ssl ? \"tls\" : \"udp\";\n const transport =\n transportType === \"udp\"\n ? await UdpTransport.init(selectTurnUdpSocketType(address, udpFamily), {\n portRange,\n interfaceAddresses,\n })\n : transportType === \"tcp\"\n ? await TcpTransport.init(address, { connectTimeoutMs })\n : await TlsTransport.init(address, tlsOptions, { connectTimeoutMs });\n\n const turn = new TurnProtocol(\n address,\n username,\n password,\n lifetime,\n transport,\n {\n reconnect:\n transportType === \"udp\"\n ? undefined\n : (alternate, alternateDomain) =>\n transportType === \"tcp\"\n ? TcpTransport.init(alternate, { connectTimeoutMs })\n : TlsTransport.init(\n alternate,\n alternateTlsOptions(address, alternateDomain, tlsOptions),\n { connectTimeoutMs },\n ),\n },\n );\n // The owner (an ICE agent) closed while the allocation runs: release the\n // socket and its retransmissions now instead of after the allocation.\n const abort = () => {\n turn\n .close()\n .catch((error) => log(\"failed to close aborted TURN client\", error));\n };\n if (signal?.aborted) abort();\n signal?.addEventListener(\"abort\", abort, { once: true });\n\n try {\n if (signal?.aborted) throw new TransactionCancelled();\n await turn.connectionMade();\n if (signal?.aborted) throw new TransactionCancelled();\n } catch (error) {\n try {\n await turn.close();\n } catch (closeError) {\n log(\"failed to close TURN client after allocation failure\", closeError);\n }\n throw error;\n } finally {\n signal?.removeEventListener(\"abort\", abort);\n }\n return turn;\n}\n\nexport async function createStunOverTurnClient(\n config: TurnClientConfig,\n options: TurnClientOptions = {},\n) {\n const turn = await createTurnClient(config, options);\n const turnTransport = new StunOverTurnProtocol(turn);\n return turnTransport;\n}\n\n/**\n * TLS options for a connection to an ALTERNATE-SERVER (an IP literal). The\n * certificate is validated against ALTERNATE-DOMAIN when present, otherwise\n * against the name the original server would have been validated with\n * (RFC 8489 §10): `tlsOptions.servername`, else the configured host.\n */\nfunction alternateTlsOptions(\n configured: Address,\n alternateDomain: string | undefined,\n tlsOptions: TlsConnectionOptions = {},\n): TlsConnectionOptions {\n const identity = alternateDomain ?? tlsOptions.servername ?? configured[0];\n const checkServerIdentity =\n tlsOptions.checkServerIdentity ?? tls.checkServerIdentity;\n return {\n ...tlsOptions,\n // SNI cannot carry an IP literal.\n servername: isIP(identity) ? undefined : identity,\n checkServerIdentity: (_host, cert) => checkServerIdentity(identity, cert),\n };\n}\n\n/**\n * The redirect target of a 300 (Try Alternate) error response, or undefined\n * for any other error. `server` is undefined when ALTERNATE-SERVER is\n * missing.\n */\nfunction tryAlternateOf(\n error: unknown,\n addressFamily?: number,\n): { server?: Address; domain?: string } | undefined {\n if (!(error instanceof TransactionFailed)) {\n return undefined;\n }\n const [errorCode] = error.response.getAttributeValue(\"ERROR-CODE\") ?? [];\n if (errorCode !== 300) {\n return undefined;\n }\n // A response may carry one ALTERNATE-SERVER per address family (RFC 8489\n // §10): take the first one this transport can reach, else the first.\n const servers = error.response.alternateServers;\n const reachable = servers.find(\n ([host]) => addressFamily === undefined || ipFamily(host) === addressFamily,\n );\n return {\n server: reachable ?? servers[0],\n domain: error.response.getAttributeValue(\"ALTERNATE-DOMAIN\"),\n };\n}\n\nfunction ipFamily(host: string): number {\n return host.includes(\":\") ? 6 : 4;\n}\n\nexport function makeIntegrityKey(\n username: string,\n realm: string,\n password: string,\n) {\n return makeTurnIntegrityKey(username, realm, password);\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Candidate } from "../candidate";
|
|
2
2
|
import type { Address, Event } from "../imports/common";
|
|
3
|
+
import type { MessageIntegrityMode } from "../stun/const";
|
|
3
4
|
import type { Message } from "../stun/message";
|
|
4
5
|
/**
|
|
5
6
|
* Options for a STUN transaction / Protocol.request.
|
|
@@ -26,17 +27,27 @@ export interface TransactionRequestOptions {
|
|
|
26
27
|
*/
|
|
27
28
|
failOnSendError?: boolean;
|
|
28
29
|
/**
|
|
29
|
-
* When set, responses must include MESSAGE-INTEGRITY
|
|
30
|
-
* verification (protocol re-parses
|
|
31
|
-
* transaction also rejects unsigned
|
|
32
|
-
* Unsigned or forged responses must not
|
|
30
|
+
* When set, responses must include MESSAGE-INTEGRITY or
|
|
31
|
+
* MESSAGE-INTEGRITY-SHA256 and pass HMAC verification (protocol re-parses
|
|
32
|
+
* the wire bytes with this key; the transaction also rejects unsigned
|
|
33
|
+
* Messages as defense-in-depth). Unsigned or forged responses must not
|
|
34
|
+
* complete the transaction.
|
|
33
35
|
*/
|
|
34
36
|
integrityKey?: Buffer;
|
|
37
|
+
/**
|
|
38
|
+
* Integrity attributes a request signed with `integrityKey` carries.
|
|
39
|
+
* Defaults to `"sha1"` (MESSAGE-INTEGRITY only). Responses are accepted
|
|
40
|
+
* with either algorithm regardless of this choice. Ignored by the TURN
|
|
41
|
+
* client's own long-term credential requests (TurnProtocol), which stay
|
|
42
|
+
* MESSAGE-INTEGRITY only.
|
|
43
|
+
*/
|
|
44
|
+
integrityAlgorithm?: MessageIntegrityMode;
|
|
35
45
|
}
|
|
36
46
|
export interface Protocol {
|
|
37
47
|
type: string;
|
|
38
48
|
onRequestReceived: Event<[Message, Address, Buffer]>;
|
|
39
|
-
|
|
49
|
+
/** Application data (not STUN) and the remote address it came from. */
|
|
50
|
+
onDataReceived: Event<[Buffer, Address]>;
|
|
40
51
|
/** Connection-oriented protocols: the connection to this remote address is gone. */
|
|
41
52
|
onConnectionClosed?: Event<[Address]>;
|
|
42
53
|
request: (message: Message, addr: Address, integrityKey?: Buffer, retransmissionsOrOptions?: number | TransactionRequestOptions, onRequestSent?: (attempt: number) => void) => Promise<[Message, Address]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../../ice/src/types/model.ts"],"names":[],"mappings":"","sourcesContent":["import type { Candidate } from \"../candidate\";\nimport type { Address, Event } from \"../imports/common\";\nimport type { Message } from \"../stun/message\";\n\n/**\n * Options for a STUN transaction / Protocol.request.\n * Retransmission count and response wait deadline are independent\n * so consent freshness (retransmissions: 0, longer timeout) can be expressed.\n */\nexport interface TransactionRequestOptions {\n /** Number of retransmissions after the initial send. 0 = send once. */\n retransmissions?: number;\n /**\n * Initial response wait deadline in milliseconds.\n * Doubled after each retransmission when retransmissions > 0.\n * Defaults to RETRY_RTO when omitted.\n */\n responseTimeout?: number;\n /** Called for each wire send (attempt 0 is the initial transmission). */\n onRequestSent?: (attempt: number) => void;\n /** Abort the outstanding transaction (e.g. consent lifecycle teardown). */\n signal?: AbortSignal;\n /**\n * Fail the transaction as soon as the request cannot be sent instead of\n * waiting for the response timeout. Used on reliable transports (TCP),\n * where a send error means the connection itself is unusable.\n */\n failOnSendError?: boolean;\n /**\n * When set, responses must include MESSAGE-INTEGRITY and pass HMAC
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../../ice/src/types/model.ts"],"names":[],"mappings":"","sourcesContent":["import type { Candidate } from \"../candidate\";\nimport type { Address, Event } from \"../imports/common\";\nimport type { MessageIntegrityMode } from \"../stun/const\";\nimport type { Message } from \"../stun/message\";\n\n/**\n * Options for a STUN transaction / Protocol.request.\n * Retransmission count and response wait deadline are independent\n * so consent freshness (retransmissions: 0, longer timeout) can be expressed.\n */\nexport interface TransactionRequestOptions {\n /** Number of retransmissions after the initial send. 0 = send once. */\n retransmissions?: number;\n /**\n * Initial response wait deadline in milliseconds.\n * Doubled after each retransmission when retransmissions > 0.\n * Defaults to RETRY_RTO when omitted.\n */\n responseTimeout?: number;\n /** Called for each wire send (attempt 0 is the initial transmission). */\n onRequestSent?: (attempt: number) => void;\n /** Abort the outstanding transaction (e.g. consent lifecycle teardown). */\n signal?: AbortSignal;\n /**\n * Fail the transaction as soon as the request cannot be sent instead of\n * waiting for the response timeout. Used on reliable transports (TCP),\n * where a send error means the connection itself is unusable.\n */\n failOnSendError?: boolean;\n /**\n * When set, responses must include MESSAGE-INTEGRITY or\n * MESSAGE-INTEGRITY-SHA256 and pass HMAC verification (protocol re-parses\n * the wire bytes with this key; the transaction also rejects unsigned\n * Messages as defense-in-depth). Unsigned or forged responses must not\n * complete the transaction.\n */\n integrityKey?: Buffer;\n /**\n * Integrity attributes a request signed with `integrityKey` carries.\n * Defaults to `\"sha1\"` (MESSAGE-INTEGRITY only). Responses are accepted\n * with either algorithm regardless of this choice. Ignored by the TURN\n * client's own long-term credential requests (TurnProtocol), which stay\n * MESSAGE-INTEGRITY only.\n */\n integrityAlgorithm?: MessageIntegrityMode;\n}\n\nexport interface Protocol {\n type: string;\n onRequestReceived: Event<[Message, Address, Buffer]>;\n /** Application data (not STUN) and the remote address it came from. */\n onDataReceived: Event<[Buffer, Address]>;\n /** Connection-oriented protocols: the connection to this remote address is gone. */\n onConnectionClosed?: Event<[Address]>;\n request: (\n message: Message,\n addr: Address,\n integrityKey?: Buffer,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n ) => Promise<[Message, Address]>;\n close: () => Promise<void>;\n connectionMade: (...args: any) => Promise<void>;\n sendStun: (message: Message, addr: Address) => Promise<void>;\n sendData: (data: Buffer, addr: Address) => Promise<void>;\n localCandidate?: Candidate;\n sentMessage?: Message;\n responseAddr?: Address;\n responseMessage?: string;\n localIp?: string;\n}\n"]}
|
|
@@ -164,6 +164,10 @@ const ATTRIBUTES = [
|
|
|
164
164
|
[0x802a, "ICE-CONTROLLING", packUnsigned64, unpackUnsigned64],
|
|
165
165
|
[0x802b, "RESPONSE-ORIGIN", packAddress, unpackAddress],
|
|
166
166
|
[0x802c, "OTHER-ADDRESS", packAddress, unpackAddress],
|
|
167
|
+
// draft-thatcher-ice-renomination (libwebrtc's GOOG_NOMINATION): the
|
|
168
|
+
// controlling agent nominates with an increasing value; the controlled
|
|
169
|
+
// agent selects the pair with the largest one.
|
|
170
|
+
[0xc001, "NOMINATION", packUnsigned, unpackUnsigned],
|
|
167
171
|
];
|
|
168
172
|
class AttributeRepository {
|
|
169
173
|
constructor(attributes = []) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../../../ice-server/src/stun/attributes.ts"],"names":[],"mappings":";;;AAsBA,0CASC;AA4CD,4CAEC;AAED,sCAOC;AAED,sDAMC;AAED,0DAUC;AAED,wCAEC;AA5GD,mCAKiB;AACjB,6BAA2E;AAE3E,SAAS,WAAW,CAAC,KA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CACnC,CAAC","sourcesContent":["import type { Address } from \"../../../common/src\";\n\nimport {\n type AttributeKeys,\n COOKIE,\n IPV4_PROTOCOL,\n IPV6_PROTOCOL,\n} from \"./const\";\nimport { bufferToIpAddress, ipAddressToBuffer, isIpV4Address } from \"./ip\";\n\nfunction packAddress(value: Address) {\n const [address] = value;\n const protocol = isIpV4Address(address) ? IPV4_PROTOCOL : IPV6_PROTOCOL;\n\n const buffer = Buffer.alloc(4);\n buffer.writeUInt8(0, 0);\n buffer.writeUInt8(protocol, 1);\n buffer.writeUInt16BE(value[1], 2);\n\n return Buffer.concat([buffer, ipAddressToBuffer(address)]);\n}\n\nexport function unpackErrorCode(data: Buffer): [number, string] {\n if (data.length < 4) {\n throw new Error(\"STUN error code is less than 4 bytes\");\n }\n\n const codeHigh = data.readUInt8(2);\n const codeLow = data.readUInt8(3);\n const reason = data.slice(4).toString(\"utf8\");\n return [codeHigh * 100 + codeLow, reason];\n}\n\nfunction unpackAddress(data: Buffer): Address {\n if (data.length < 4) {\n throw new Error(\"STUN address length is less than 4 bytes\");\n }\n\n const protocol = data.readUInt8(1);\n const port = data.readUInt16BE(2);\n const address = data.slice(4);\n\n switch (protocol) {\n case IPV4_PROTOCOL:\n if (address.length !== 4) {\n throw new Error(\"STUN address has invalid length for IPv4\");\n }\n return [bufferToIpAddress(address), port];\n case IPV6_PROTOCOL:\n if (address.length !== 16) {\n throw new Error(\"STUN address has invalid length for IPv6\");\n }\n return [bufferToIpAddress(address), port];\n default:\n throw new Error(\"STUN address has unknown protocol\");\n }\n}\n\nconst cookieBuffer = Buffer.alloc(6);\ncookieBuffer.writeUInt16BE(COOKIE >> 16, 0);\ncookieBuffer.writeUInt32BE(COOKIE, 2);\n\nfunction xorAddress(data: Buffer, transactionId: Buffer) {\n const xPad = [...cookieBuffer, ...transactionId];\n let xData = data.slice(0, 2);\n\n for (let i = 2; i < data.length; i++) {\n const num = data[i] ^ xPad[i - 2];\n const buf = Buffer.alloc(1);\n buf.writeUIntBE(num, 0, 1);\n xData = Buffer.concat([xData, buf]);\n }\n return xData;\n}\n\nexport function unpackXorAddress(data: Buffer, transactionId: Buffer): Address {\n return unpackAddress(xorAddress(data, transactionId));\n}\n\nexport function packErrorCode(value: [number, string]) {\n const buffer = Buffer.alloc(4);\n buffer.writeUInt16BE(0, 0);\n buffer.writeUInt8(Math.floor(value[0] / 100), 2);\n buffer.writeUInt8(value[0] % 100, 3);\n const encoded = Buffer.from(value[1], \"utf8\");\n return Buffer.concat([buffer, encoded]);\n}\n\nexport function packUnknownAttributes(value: number[]) {\n const buffer = Buffer.alloc(value.length * 2);\n value.forEach((attributeType, index) => {\n buffer.writeUInt16BE(attributeType, index * 2);\n });\n return buffer;\n}\n\nexport function unpackUnknownAttributes(data: Buffer) {\n if (data.length % 2 !== 0) {\n throw new Error(\"UNKNOWN-ATTRIBUTES must have an even length\");\n }\n\n const attributes: number[] = [];\n for (let offset = 0; offset < data.length; offset += 2) {\n attributes.push(data.readUInt16BE(offset));\n }\n return attributes;\n}\n\nexport function packXorAddress(value: Address, transactionId: Buffer) {\n return xorAddress(packAddress(value), transactionId);\n}\n\nconst packUnsigned = (value: number) => {\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(value, 0);\n return buffer;\n};\n\nconst unpackUnsigned = (data: Buffer) => data.readUInt32BE(0);\n\nconst packUnsignedShort = (value: number) => {\n const buffer = Buffer.alloc(4);\n buffer.writeUInt16BE(value, 0);\n return buffer;\n};\n\nconst unpackUnsignedShort = (data: Buffer) => data.readUInt16BE(0);\n\nconst packUnsigned64 = (value: bigint) => {\n const buffer = Buffer.allocUnsafe(8);\n buffer.writeBigUInt64BE(value, 0);\n return buffer;\n};\n\nconst unpackUnsigned64 = (data: Buffer) => data.readBigUInt64BE(0);\n\nconst packString = (value: string) => Buffer.from(value, \"utf8\");\nconst unpackString = (data: Buffer) => data.toString(\"utf8\");\n\nconst packSoftware = (value: string) => {\n if ([...value].length >= 128) {\n throw new Error(\"SOFTWARE must be shorter than 128 characters\");\n }\n return packString(value);\n};\n\nconst packBytes = (value: Buffer) => value;\nconst unpackBytes = (data: Buffer) => data;\n\nconst packNone = () => Buffer.alloc(0);\nconst unpackNone = () => null;\n\nexport type ATTRIBUTE = [\n number,\n AttributeKey,\n (...args: any[]) => Buffer,\n (...args: any[]) => any,\n];\n\nexport type RawAttribute = {\n type: number;\n length?: number;\n value: Buffer;\n};\n\nconst ATTRIBUTES: ATTRIBUTE[] = [\n [0x0001, \"MAPPED-ADDRESS\", packAddress, unpackAddress],\n [0x0003, \"CHANGE-REQUEST\", packUnsigned, unpackUnsigned],\n [0x0004, \"SOURCE-ADDRESS\", packAddress, unpackAddress],\n [0x0005, \"CHANGED-ADDRESS\", packAddress, unpackAddress],\n [0x0006, \"USERNAME\", packString, unpackString],\n [0x0008, \"MESSAGE-INTEGRITY\", packBytes, unpackBytes],\n [0x0009, \"ERROR-CODE\", packErrorCode, unpackErrorCode],\n [\n 0x000a,\n \"UNKNOWN-ATTRIBUTES\",\n packUnknownAttributes,\n unpackUnknownAttributes,\n ],\n [0x000c, \"CHANNEL-NUMBER\", packUnsignedShort, unpackUnsignedShort],\n [0x000d, \"LIFETIME\", packUnsigned, unpackUnsigned],\n [0x0012, \"XOR-PEER-ADDRESS\", packXorAddress, unpackXorAddress],\n [0x0013, \"DATA\", packBytes, unpackBytes],\n [0x0014, \"REALM\", packString, unpackString],\n [0x0015, \"NONCE\", packBytes, unpackBytes],\n [0x0016, \"XOR-RELAYED-ADDRESS\", packXorAddress, unpackXorAddress],\n [0x0017, \"REQUESTED-ADDRESS-FAMILY\", packUnsigned, unpackUnsigned],\n [0x0018, \"EVEN-PORT\", packBytes, unpackBytes],\n [0x0019, \"REQUESTED-TRANSPORT\", packUnsigned, unpackUnsigned],\n [0x001c, \"MESSAGE-INTEGRITY-SHA256\", packBytes, unpackBytes],\n [0x001d, \"PASSWORD-ALGORITHM\", packBytes, unpackBytes],\n [0x001e, \"USERHASH\", packBytes, unpackBytes],\n [0x0020, \"XOR-MAPPED-ADDRESS\", packXorAddress, unpackXorAddress],\n [0x0022, \"RESERVATION-TOKEN\", packBytes, unpackBytes],\n [0x0024, \"PRIORITY\", packUnsigned, unpackUnsigned],\n [0x0025, \"USE-CANDIDATE\", packNone, unpackNone],\n [0x8002, \"PASSWORD-ALGORITHMS\", packBytes, unpackBytes],\n [0x8003, \"ALTERNATE-DOMAIN\", packString, unpackString],\n [0x8022, \"SOFTWARE\", packSoftware, unpackString],\n [0x8023, \"ALTERNATE-SERVER\", packAddress, unpackAddress],\n [0x8028, \"FINGERPRINT\", packUnsigned, unpackUnsigned],\n [0x8029, \"ICE-CONTROLLED\", packUnsigned64, unpackUnsigned64],\n [0x802a, \"ICE-CONTROLLING\", packUnsigned64, unpackUnsigned64],\n [0x802b, \"RESPONSE-ORIGIN\", packAddress, unpackAddress],\n [0x802c, \"OTHER-ADDRESS\", packAddress, unpackAddress],\n];\n\nexport class AttributeRepository {\n protected attributes: AttributePair[];\n\n constructor(attributes: AttributePair[] = []) {\n this.attributes = attributes;\n }\n\n getAttributes() {\n return this.attributes;\n }\n\n setAttribute(key: AttributeKey, value: any) {\n const existing = this.attributes.find((attribute) => attribute[0] === key);\n if (existing) {\n existing[1] = value;\n } else {\n this.attributes.push([key, value]);\n }\n return this;\n }\n\n getAttributeValue(key: AttributeKey) {\n const attribute = this.attributes.find((candidate) => candidate[0] === key);\n return attribute?.[1];\n }\n\n get attributesKeys(): AttributeKey[] {\n return this.attributes.map((attribute) => attribute[0]);\n }\n\n /** Remove the attribute named `key`, if present. */\n removeAttribute(key: AttributeKey) {\n this.attributes = this.attributes.filter(\n (attribute) => attribute[0] !== key,\n );\n return this;\n }\n\n clear() {\n this.attributes = [];\n }\n}\n\nexport type AttributeKey = (typeof AttributeKeys)[number];\nexport type AttributePair = [AttributeKey, any];\n\nexport const ATTRIBUTES_BY_TYPE = ATTRIBUTES.reduce(\n (acc, cur) => {\n acc[cur[0]] = cur;\n return acc;\n },\n {} as { [key: string]: ATTRIBUTE },\n);\n\nexport const ATTRIBUTES_BY_NAME = ATTRIBUTES.reduce(\n (acc, cur) => {\n acc[cur[1]] = cur;\n return acc;\n },\n {} as { [key: string]: ATTRIBUTE },\n);\n"]}
|
|
1
|
+
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../../../ice-server/src/stun/attributes.ts"],"names":[],"mappings":";;;AAsBA,0CASC;AA4CD,4CAEC;AAED,sCAOC;AAED,sDAMC;AAED,0DAUC;AAED,wCAEC;AA5GD,mCAKiB;AACjB,6BAA2E;AAE3E,SAAS,WAAW,CAAC,KAAc;IACjC,MAAM,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;IACxB,MAAM,QAAQ,GAAG,IAAA,kBAAa,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,qBAAa,CAAC,CAAC,CAAC,qBAAa,CAAC;IAExE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxB,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC/B,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAA,sBAAiB,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAgB,eAAe,CAAC,IAAY;IAC1C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,CAA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AAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;CACF;AAzCD,kDAyCC;AAKY,QAAA,kBAAkB,GAAG,UAAU,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACX,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IAClB,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAkC,CACnC,CAAC;AAEW,QAAA,kBAAkB,GAAG,UAAU,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACX,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IAClB,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAkC,CACnC,CAAC","sourcesContent":["import type { Address } from \"../../../common/src\";\n\nimport {\n type AttributeKeys,\n COOKIE,\n IPV4_PROTOCOL,\n IPV6_PROTOCOL,\n} from \"./const\";\nimport { bufferToIpAddress, ipAddressToBuffer, isIpV4Address } from \"./ip\";\n\nfunction packAddress(value: Address) {\n const [address] = value;\n const protocol = isIpV4Address(address) ? IPV4_PROTOCOL : IPV6_PROTOCOL;\n\n const buffer = Buffer.alloc(4);\n buffer.writeUInt8(0, 0);\n buffer.writeUInt8(protocol, 1);\n buffer.writeUInt16BE(value[1], 2);\n\n return Buffer.concat([buffer, ipAddressToBuffer(address)]);\n}\n\nexport function unpackErrorCode(data: Buffer): [number, string] {\n if (data.length < 4) {\n throw new Error(\"STUN error code is less than 4 bytes\");\n }\n\n const codeHigh = data.readUInt8(2);\n const codeLow = data.readUInt8(3);\n const reason = data.slice(4).toString(\"utf8\");\n return [codeHigh * 100 + codeLow, reason];\n}\n\nfunction unpackAddress(data: Buffer): Address {\n if (data.length < 4) {\n throw new Error(\"STUN address length is less than 4 bytes\");\n }\n\n const protocol = data.readUInt8(1);\n const port = data.readUInt16BE(2);\n const address = data.slice(4);\n\n switch (protocol) {\n case IPV4_PROTOCOL:\n if (address.length !== 4) {\n throw new Error(\"STUN address has invalid length for IPv4\");\n }\n return [bufferToIpAddress(address), port];\n case IPV6_PROTOCOL:\n if (address.length !== 16) {\n throw new Error(\"STUN address has invalid length for IPv6\");\n }\n return [bufferToIpAddress(address), port];\n default:\n throw new Error(\"STUN address has unknown protocol\");\n }\n}\n\nconst cookieBuffer = Buffer.alloc(6);\ncookieBuffer.writeUInt16BE(COOKIE >> 16, 0);\ncookieBuffer.writeUInt32BE(COOKIE, 2);\n\nfunction xorAddress(data: Buffer, transactionId: Buffer) {\n const xPad = [...cookieBuffer, ...transactionId];\n let xData = data.slice(0, 2);\n\n for (let i = 2; i < data.length; i++) {\n const num = data[i] ^ xPad[i - 2];\n const buf = Buffer.alloc(1);\n buf.writeUIntBE(num, 0, 1);\n xData = Buffer.concat([xData, buf]);\n }\n return xData;\n}\n\nexport function unpackXorAddress(data: Buffer, transactionId: Buffer): Address {\n return unpackAddress(xorAddress(data, transactionId));\n}\n\nexport function packErrorCode(value: [number, string]) {\n const buffer = Buffer.alloc(4);\n buffer.writeUInt16BE(0, 0);\n buffer.writeUInt8(Math.floor(value[0] / 100), 2);\n buffer.writeUInt8(value[0] % 100, 3);\n const encoded = Buffer.from(value[1], \"utf8\");\n return Buffer.concat([buffer, encoded]);\n}\n\nexport function packUnknownAttributes(value: number[]) {\n const buffer = Buffer.alloc(value.length * 2);\n value.forEach((attributeType, index) => {\n buffer.writeUInt16BE(attributeType, index * 2);\n });\n return buffer;\n}\n\nexport function unpackUnknownAttributes(data: Buffer) {\n if (data.length % 2 !== 0) {\n throw new Error(\"UNKNOWN-ATTRIBUTES must have an even length\");\n }\n\n const attributes: number[] = [];\n for (let offset = 0; offset < data.length; offset += 2) {\n attributes.push(data.readUInt16BE(offset));\n }\n return attributes;\n}\n\nexport function packXorAddress(value: Address, transactionId: Buffer) {\n return xorAddress(packAddress(value), transactionId);\n}\n\nconst packUnsigned = (value: number) => {\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(value, 0);\n return buffer;\n};\n\nconst unpackUnsigned = (data: Buffer) => data.readUInt32BE(0);\n\nconst packUnsignedShort = (value: number) => {\n const buffer = Buffer.alloc(4);\n buffer.writeUInt16BE(value, 0);\n return buffer;\n};\n\nconst unpackUnsignedShort = (data: Buffer) => data.readUInt16BE(0);\n\nconst packUnsigned64 = (value: bigint) => {\n const buffer = Buffer.allocUnsafe(8);\n buffer.writeBigUInt64BE(value, 0);\n return buffer;\n};\n\nconst unpackUnsigned64 = (data: Buffer) => data.readBigUInt64BE(0);\n\nconst packString = (value: string) => Buffer.from(value, \"utf8\");\nconst unpackString = (data: Buffer) => data.toString(\"utf8\");\n\nconst packSoftware = (value: string) => {\n if ([...value].length >= 128) {\n throw new Error(\"SOFTWARE must be shorter than 128 characters\");\n }\n return packString(value);\n};\n\nconst packBytes = (value: Buffer) => value;\nconst unpackBytes = (data: Buffer) => data;\n\nconst packNone = () => Buffer.alloc(0);\nconst unpackNone = () => null;\n\nexport type ATTRIBUTE = [\n number,\n AttributeKey,\n (...args: any[]) => Buffer,\n (...args: any[]) => any,\n];\n\nexport type RawAttribute = {\n type: number;\n length?: number;\n value: Buffer;\n};\n\nconst ATTRIBUTES: ATTRIBUTE[] = [\n [0x0001, \"MAPPED-ADDRESS\", packAddress, unpackAddress],\n [0x0003, \"CHANGE-REQUEST\", packUnsigned, unpackUnsigned],\n [0x0004, \"SOURCE-ADDRESS\", packAddress, unpackAddress],\n [0x0005, \"CHANGED-ADDRESS\", packAddress, unpackAddress],\n [0x0006, \"USERNAME\", packString, unpackString],\n [0x0008, \"MESSAGE-INTEGRITY\", packBytes, unpackBytes],\n [0x0009, \"ERROR-CODE\", packErrorCode, unpackErrorCode],\n [\n 0x000a,\n \"UNKNOWN-ATTRIBUTES\",\n packUnknownAttributes,\n unpackUnknownAttributes,\n ],\n [0x000c, \"CHANNEL-NUMBER\", packUnsignedShort, unpackUnsignedShort],\n [0x000d, \"LIFETIME\", packUnsigned, unpackUnsigned],\n [0x0012, \"XOR-PEER-ADDRESS\", packXorAddress, unpackXorAddress],\n [0x0013, \"DATA\", packBytes, unpackBytes],\n [0x0014, \"REALM\", packString, unpackString],\n [0x0015, \"NONCE\", packBytes, unpackBytes],\n [0x0016, \"XOR-RELAYED-ADDRESS\", packXorAddress, unpackXorAddress],\n [0x0017, \"REQUESTED-ADDRESS-FAMILY\", packUnsigned, unpackUnsigned],\n [0x0018, \"EVEN-PORT\", packBytes, unpackBytes],\n [0x0019, \"REQUESTED-TRANSPORT\", packUnsigned, unpackUnsigned],\n [0x001c, \"MESSAGE-INTEGRITY-SHA256\", packBytes, unpackBytes],\n [0x001d, \"PASSWORD-ALGORITHM\", packBytes, unpackBytes],\n [0x001e, \"USERHASH\", packBytes, unpackBytes],\n [0x0020, \"XOR-MAPPED-ADDRESS\", packXorAddress, unpackXorAddress],\n [0x0022, \"RESERVATION-TOKEN\", packBytes, unpackBytes],\n [0x0024, \"PRIORITY\", packUnsigned, unpackUnsigned],\n [0x0025, \"USE-CANDIDATE\", packNone, unpackNone],\n [0x8002, \"PASSWORD-ALGORITHMS\", packBytes, unpackBytes],\n [0x8003, \"ALTERNATE-DOMAIN\", packString, unpackString],\n [0x8022, \"SOFTWARE\", packSoftware, unpackString],\n [0x8023, \"ALTERNATE-SERVER\", packAddress, unpackAddress],\n [0x8028, \"FINGERPRINT\", packUnsigned, unpackUnsigned],\n [0x8029, \"ICE-CONTROLLED\", packUnsigned64, unpackUnsigned64],\n [0x802a, \"ICE-CONTROLLING\", packUnsigned64, unpackUnsigned64],\n [0x802b, \"RESPONSE-ORIGIN\", packAddress, unpackAddress],\n [0x802c, \"OTHER-ADDRESS\", packAddress, unpackAddress],\n // draft-thatcher-ice-renomination (libwebrtc's GOOG_NOMINATION): the\n // controlling agent nominates with an increasing value; the controlled\n // agent selects the pair with the largest one.\n [0xc001, \"NOMINATION\", packUnsigned, unpackUnsigned],\n];\n\nexport class AttributeRepository {\n protected attributes: AttributePair[];\n\n constructor(attributes: AttributePair[] = []) {\n this.attributes = attributes;\n }\n\n getAttributes() {\n return this.attributes;\n }\n\n setAttribute(key: AttributeKey, value: any) {\n const existing = this.attributes.find((attribute) => attribute[0] === key);\n if (existing) {\n existing[1] = value;\n } else {\n this.attributes.push([key, value]);\n }\n return this;\n }\n\n getAttributeValue(key: AttributeKey) {\n const attribute = this.attributes.find((candidate) => candidate[0] === key);\n return attribute?.[1];\n }\n\n get attributesKeys(): AttributeKey[] {\n return this.attributes.map((attribute) => attribute[0]);\n }\n\n /** Remove the attribute named `key`, if present. */\n removeAttribute(key: AttributeKey) {\n this.attributes = this.attributes.filter(\n (attribute) => attribute[0] !== key,\n );\n return this;\n }\n\n clear() {\n this.attributes = [];\n }\n}\n\nexport type AttributeKey = (typeof AttributeKeys)[number];\nexport type AttributePair = [AttributeKey, any];\n\nexport const ATTRIBUTES_BY_TYPE = ATTRIBUTES.reduce(\n (acc, cur) => {\n acc[cur[0]] = cur;\n return acc;\n },\n {} as { [key: string]: ATTRIBUTE },\n);\n\nexport const ATTRIBUTES_BY_NAME = ATTRIBUTES.reduce(\n (acc, cur) => {\n acc[cur[1]] = cur;\n return acc;\n },\n {} as { [key: string]: ATTRIBUTE },\n);\n"]}
|
|
@@ -2,12 +2,31 @@ export declare const COOKIE = 554869826;
|
|
|
2
2
|
export declare const FINGERPRINT_LENGTH = 8;
|
|
3
3
|
export declare const FINGERPRINT_XOR = 1398035790;
|
|
4
4
|
export declare const HEADER_LENGTH = 20;
|
|
5
|
+
/** MESSAGE-INTEGRITY (HMAC-SHA1, 20 bytes) including its 4 byte TLV header. */
|
|
5
6
|
export declare const INTEGRITY_LENGTH = 24;
|
|
7
|
+
/** Untruncated MESSAGE-INTEGRITY-SHA256 value length (RFC 8489 §14.6). */
|
|
8
|
+
export declare const INTEGRITY_SHA256_VALUE_LENGTH = 32;
|
|
9
|
+
/** Shortest allowed truncation of MESSAGE-INTEGRITY-SHA256 (RFC 8489 §14.6). */
|
|
10
|
+
export declare const INTEGRITY_SHA256_MIN_VALUE_LENGTH = 16;
|
|
11
|
+
/** Default MESSAGE-INTEGRITY-SHA256 (32 bytes) including its 4 byte TLV header. */
|
|
12
|
+
export declare const INTEGRITY_SHA256_LENGTH: number;
|
|
6
13
|
export declare const IPV4_PROTOCOL = 1;
|
|
7
14
|
export declare const IPV6_PROTOCOL = 2;
|
|
8
15
|
export declare const RETRY_MAX = 6;
|
|
9
16
|
export declare const RETRY_RTO = 50;
|
|
10
|
-
export declare const AttributeKeys: readonly ["FINGERPRINT", "MESSAGE-INTEGRITY", "MESSAGE-INTEGRITY-SHA256", "CHANGE-REQUEST", "PRIORITY", "USERNAME", "USERHASH", "ICE-CONTROLLING", "SOURCE-ADDRESS", "USE-CANDIDATE", "ICE-CONTROLLED", "ERROR-CODE", "UNKNOWN-ATTRIBUTES", "XOR-MAPPED-ADDRESS", "CHANGED-ADDRESS", "LIFETIME", "REQUESTED-TRANSPORT", "NONCE", "REALM", "REQUESTED-ADDRESS-FAMILY", "EVEN-PORT", "PASSWORD-ALGORITHM", "PASSWORD-ALGORITHMS", "XOR-RELAYED-ADDRESS", "RESERVATION-TOKEN", "CHANNEL-NUMBER", "XOR-PEER-ADDRESS", "DATA", "SOFTWARE", "MAPPED-ADDRESS", "ALTERNATE-DOMAIN", "ALTERNATE-SERVER", "RESPONSE-ORIGIN", "OTHER-ADDRESS"];
|
|
17
|
+
export declare const AttributeKeys: readonly ["FINGERPRINT", "MESSAGE-INTEGRITY", "MESSAGE-INTEGRITY-SHA256", "CHANGE-REQUEST", "PRIORITY", "USERNAME", "USERHASH", "ICE-CONTROLLING", "SOURCE-ADDRESS", "USE-CANDIDATE", "ICE-CONTROLLED", "ERROR-CODE", "UNKNOWN-ATTRIBUTES", "XOR-MAPPED-ADDRESS", "CHANGED-ADDRESS", "LIFETIME", "REQUESTED-TRANSPORT", "NONCE", "REALM", "REQUESTED-ADDRESS-FAMILY", "EVEN-PORT", "PASSWORD-ALGORITHM", "PASSWORD-ALGORITHMS", "XOR-RELAYED-ADDRESS", "RESERVATION-TOKEN", "CHANNEL-NUMBER", "XOR-PEER-ADDRESS", "DATA", "SOFTWARE", "MAPPED-ADDRESS", "ALTERNATE-DOMAIN", "ALTERNATE-SERVER", "RESPONSE-ORIGIN", "OTHER-ADDRESS", "NOMINATION"];
|
|
18
|
+
/**
|
|
19
|
+
* Short-term credential integrity attribute a message is signed with:
|
|
20
|
+
* `"sha1"` = MESSAGE-INTEGRITY (0x0008),
|
|
21
|
+
* `"sha256"` = MESSAGE-INTEGRITY-SHA256 (0x001C, RFC 8489).
|
|
22
|
+
*/
|
|
23
|
+
export type MessageIntegrityAlgorithm = "sha1" | "sha256";
|
|
24
|
+
/**
|
|
25
|
+
* Which integrity attributes an outgoing message carries. `"both"` adds
|
|
26
|
+
* MESSAGE-INTEGRITY followed by MESSAGE-INTEGRITY-SHA256 (RFC 8489 §14.6
|
|
27
|
+
* order), so an agent that only knows SHA-1 can still verify it.
|
|
28
|
+
*/
|
|
29
|
+
export type MessageIntegrityMode = MessageIntegrityAlgorithm | "both";
|
|
11
30
|
/**
|
|
12
31
|
* @enum
|
|
13
32
|
*/
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.methods = exports.classes = exports.AttributeKeys = exports.RETRY_RTO = exports.RETRY_MAX = exports.IPV6_PROTOCOL = exports.IPV4_PROTOCOL = exports.INTEGRITY_LENGTH = exports.HEADER_LENGTH = exports.FINGERPRINT_XOR = exports.FINGERPRINT_LENGTH = exports.COOKIE = void 0;
|
|
3
|
+
exports.methods = exports.classes = exports.AttributeKeys = exports.RETRY_RTO = exports.RETRY_MAX = exports.IPV6_PROTOCOL = exports.IPV4_PROTOCOL = exports.INTEGRITY_SHA256_LENGTH = exports.INTEGRITY_SHA256_MIN_VALUE_LENGTH = exports.INTEGRITY_SHA256_VALUE_LENGTH = exports.INTEGRITY_LENGTH = exports.HEADER_LENGTH = exports.FINGERPRINT_XOR = exports.FINGERPRINT_LENGTH = exports.COOKIE = void 0;
|
|
4
4
|
exports.isComprehensionRequiredAttribute = isComprehensionRequiredAttribute;
|
|
5
5
|
exports.isStunMessage = isStunMessage;
|
|
6
6
|
exports.COOKIE = 0x2112a442;
|
|
7
7
|
exports.FINGERPRINT_LENGTH = 8;
|
|
8
8
|
exports.FINGERPRINT_XOR = 0x5354554e;
|
|
9
9
|
exports.HEADER_LENGTH = 20;
|
|
10
|
+
/** MESSAGE-INTEGRITY (HMAC-SHA1, 20 bytes) including its 4 byte TLV header. */
|
|
10
11
|
exports.INTEGRITY_LENGTH = 24;
|
|
12
|
+
/** Untruncated MESSAGE-INTEGRITY-SHA256 value length (RFC 8489 §14.6). */
|
|
13
|
+
exports.INTEGRITY_SHA256_VALUE_LENGTH = 32;
|
|
14
|
+
/** Shortest allowed truncation of MESSAGE-INTEGRITY-SHA256 (RFC 8489 §14.6). */
|
|
15
|
+
exports.INTEGRITY_SHA256_MIN_VALUE_LENGTH = 16;
|
|
16
|
+
/** Default MESSAGE-INTEGRITY-SHA256 (32 bytes) including its 4 byte TLV header. */
|
|
17
|
+
exports.INTEGRITY_SHA256_LENGTH = 4 + exports.INTEGRITY_SHA256_VALUE_LENGTH;
|
|
11
18
|
exports.IPV4_PROTOCOL = 1;
|
|
12
19
|
exports.IPV6_PROTOCOL = 2;
|
|
13
20
|
exports.RETRY_MAX = 6;
|
|
@@ -47,6 +54,7 @@ exports.AttributeKeys = [
|
|
|
47
54
|
"ALTERNATE-SERVER",
|
|
48
55
|
"RESPONSE-ORIGIN",
|
|
49
56
|
"OTHER-ADDRESS",
|
|
57
|
+
"NOMINATION",
|
|
50
58
|
];
|
|
51
59
|
/**
|
|
52
60
|
* @enum
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../../ice-server/src/stun/const.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources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;AAGX;;GAEG;AACU,QAAA,OAAO,GAAG;IACrB,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,GAAG;IAClB,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,iBAAiB,EAAE,GAAG;IACtB,YAAY,EAAE,GAAG;CACT,CAAC;AAGX,SAAgB,gCAAgC,CAAC,IAAY;IAC3D,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;AAC1C,CAAC;AAED,SAAgB,aAAa,CAAC,IAAY;IACxC,IAAI,IAAI,CAAC,MAAM,GAAG,qBAAa,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,cAAM,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,KAAK,qBAAa,GAAG,MAAM,CAAC;AAChD,CAAC","sourcesContent":["export const COOKIE = 0x2112a442;\nexport const FINGERPRINT_LENGTH = 8;\nexport const FINGERPRINT_XOR = 0x5354554e;\nexport const HEADER_LENGTH = 20;\n/** MESSAGE-INTEGRITY (HMAC-SHA1, 20 bytes) including its 4 byte TLV header. */\nexport const INTEGRITY_LENGTH = 24;\n/** Untruncated MESSAGE-INTEGRITY-SHA256 value length (RFC 8489 §14.6). */\nexport const INTEGRITY_SHA256_VALUE_LENGTH = 32;\n/** Shortest allowed truncation of MESSAGE-INTEGRITY-SHA256 (RFC 8489 §14.6). */\nexport const INTEGRITY_SHA256_MIN_VALUE_LENGTH = 16;\n/** Default MESSAGE-INTEGRITY-SHA256 (32 bytes) including its 4 byte TLV header. */\nexport const INTEGRITY_SHA256_LENGTH = 4 + INTEGRITY_SHA256_VALUE_LENGTH;\nexport const IPV4_PROTOCOL = 1;\nexport const IPV6_PROTOCOL = 2;\n\nexport const RETRY_MAX = 6;\nexport const RETRY_RTO = 50;\n\nexport const AttributeKeys = [\n \"FINGERPRINT\",\n \"MESSAGE-INTEGRITY\",\n \"MESSAGE-INTEGRITY-SHA256\",\n \"CHANGE-REQUEST\",\n \"PRIORITY\",\n \"USERNAME\",\n \"USERHASH\",\n \"ICE-CONTROLLING\",\n \"SOURCE-ADDRESS\",\n \"USE-CANDIDATE\",\n \"ICE-CONTROLLED\",\n \"ERROR-CODE\",\n \"UNKNOWN-ATTRIBUTES\",\n \"XOR-MAPPED-ADDRESS\",\n \"CHANGED-ADDRESS\",\n \"LIFETIME\",\n \"REQUESTED-TRANSPORT\",\n \"NONCE\",\n \"REALM\",\n \"REQUESTED-ADDRESS-FAMILY\",\n \"EVEN-PORT\",\n \"PASSWORD-ALGORITHM\",\n \"PASSWORD-ALGORITHMS\",\n \"XOR-RELAYED-ADDRESS\",\n \"RESERVATION-TOKEN\",\n \"CHANNEL-NUMBER\",\n \"XOR-PEER-ADDRESS\",\n \"DATA\",\n \"SOFTWARE\",\n \"MAPPED-ADDRESS\",\n \"ALTERNATE-DOMAIN\",\n \"ALTERNATE-SERVER\",\n \"RESPONSE-ORIGIN\",\n \"OTHER-ADDRESS\",\n \"NOMINATION\",\n] as const;\n\n/**\n * Short-term credential integrity attribute a message is signed with:\n * `\"sha1\"` = MESSAGE-INTEGRITY (0x0008),\n * `\"sha256\"` = MESSAGE-INTEGRITY-SHA256 (0x001C, RFC 8489).\n */\nexport type MessageIntegrityAlgorithm = \"sha1\" | \"sha256\";\n\n/**\n * Which integrity attributes an outgoing message carries. `\"both\"` adds\n * MESSAGE-INTEGRITY followed by MESSAGE-INTEGRITY-SHA256 (RFC 8489 §14.6\n * order), so an agent that only knows SHA-1 can still verify it.\n */\nexport type MessageIntegrityMode = MessageIntegrityAlgorithm | \"both\";\n\n/**\n * @enum\n */\nexport const classes = {\n REQUEST: 0x000,\n INDICATION: 0x010,\n RESPONSE: 0x100,\n ERROR: 0x110,\n} as const;\nexport type classes = (typeof classes)[keyof typeof classes];\n\n/**\n * @enum\n */\nexport const methods = {\n BINDING: 0x1,\n SHARED_SECRET: 0x2,\n ALLOCATE: 0x3,\n REFRESH: 0x4,\n SEND: 0x6,\n DATA: 0x7,\n CREATE_PERMISSION: 0x8,\n CHANNEL_BIND: 0x9,\n} as const;\nexport type methods = (typeof methods)[keyof typeof methods];\n\nexport function isComprehensionRequiredAttribute(type: number) {\n return type >= 0x0000 && type <= 0x7fff;\n}\n\nexport function isStunMessage(data: Buffer) {\n if (data.length < HEADER_LENGTH) {\n return false;\n }\n\n if ((data[0] & 0xc0) !== 0) {\n return false;\n }\n\n if (data.readUInt32BE(4) !== COOKIE) {\n return false;\n }\n\n const length = data.readUInt16BE(2);\n if (length % 4 !== 0) {\n return false;\n }\n\n return data.length === HEADER_LENGTH + length;\n}\n"]}
|