werift 0.26.0 → 0.27.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 +63 -0
- package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
- package/lib/common/src/binary.d.ts +1 -3
- package/lib/common/src/binary.js +8 -6
- package/lib/common/src/binary.js.map +1 -1
- package/lib/common/src/binaryData.js +2 -1
- package/lib/common/src/binaryData.js.map +1 -1
- package/lib/common/src/log.js +5 -7
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/transport.js +10 -5
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/context/cipher.d.ts +1 -1
- package/lib/dtls/src/context/cipher.js +6 -3
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/dtls/src/context/dtls.js +4 -2
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.js +2 -1
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight1.js +2 -1
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +4 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +1 -1
- package/lib/dtls/src/flight/flight.js +8 -4
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +4 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +2 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +17 -13
- package/lib/dtls/src/handshake/const.js +16 -14
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +4 -2
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +2 -1
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +14 -7
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/message/finished.js +2 -1
- package/lib/dtls/src/handshake/message/finished.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +12 -6
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
- package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/random.d.ts +2 -2
- package/lib/dtls/src/handshake/random.js +5 -2
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/record/const.d.ts +43 -33
- package/lib/dtls/src/record/const.js +43 -36
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.js +12 -6
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +10 -5
- package/lib/dtls/src/record/message/header.js.map +1 -1
- package/lib/dtls/src/record/message/plaintext.js +4 -2
- package/lib/dtls/src/record/message/plaintext.js.map +1 -1
- package/lib/dtls/src/record/receive.js +2 -2
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/socket.js +4 -2
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidate.d.ts +1 -1
- package/lib/ice/src/candidate.js +24 -12
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/dns/lookup.d.ts +10 -1
- package/lib/ice/src/dns/lookup.js +42 -7
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +21 -5
- package/lib/ice/src/exceptions.js +58 -13
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/ice.d.ts +52 -8
- package/lib/ice/src/ice.js +288 -152
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +126 -11
- package/lib/ice/src/iceBase.js +165 -12
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +30 -1
- package/lib/ice/src/stun/transaction.js +86 -17
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/credential.d.ts +49 -0
- package/lib/ice/src/turn/credential.js +78 -0
- package/lib/ice/src/turn/credential.js.map +1 -0
- package/lib/ice/src/turn/protocol.d.ts +29 -8
- package/lib/ice/src/turn/protocol.js +121 -48
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.d.ts +2 -0
- package/lib/ice-server/src/stun/attributes.js +7 -1
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +24 -16
- package/lib/ice-server/src/stun/const.js +22 -18
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +1 -3
- package/lib/ice-server/src/stun/message.js +13 -9
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/index.mjs +9770 -2648
- package/lib/nonstandard/index.mjs +2428 -1052
- package/lib/polyfill/dom.mjs +8738 -1815
- package/lib/polyfill/index.mjs +8738 -1815
- package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
- package/lib/rtp/src/codec/assertPayload.js +12 -0
- package/lib/rtp/src/codec/assertPayload.js.map +1 -0
- package/lib/rtp/src/codec/av1.js +2 -0
- package/lib/rtp/src/codec/av1.js.map +1 -1
- package/lib/rtp/src/codec/h264.js +35 -43
- package/lib/rtp/src/codec/h264.js.map +1 -1
- package/lib/rtp/src/codec/vp8.js +11 -5
- package/lib/rtp/src/codec/vp8.js.map +1 -1
- package/lib/rtp/src/codec/vp9.js +12 -0
- package/lib/rtp/src/codec/vp9.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/container.js +2 -1
- package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
- package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
- package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
- package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
- package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
- package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/dtx.js +4 -2
- package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
- package/lib/rtp/src/extra/processor/index.d.ts +2 -0
- package/lib/rtp/src/extra/processor/index.js +2 -0
- package/lib/rtp/src/extra/processor/index.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
- package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
- package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
- package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
- package/lib/rtp/src/extra/processor/lipsync.js +202 -51
- package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
- package/lib/rtp/src/extra/processor/mp4.js +6 -3
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/mute.js +4 -2
- package/lib/rtp/src/extra/processor/mute.js.map +1 -1
- package/lib/rtp/src/extra/processor/nack.js +4 -2
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
- package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
- package/lib/rtp/src/extra/processor/ogg.js +221 -0
- package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
- package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
- package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
- package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
- package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
- package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
- package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/webm.js +14 -7
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/index.d.ts +7 -0
- package/lib/rtp/src/index.js +7 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.js +8 -4
- package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
- package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
- package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
- package/lib/rtp/src/rtcp/sr.js +1 -0
- package/lib/rtp/src/rtcp/sr.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +36 -0
- package/lib/rtp/src/rtp/continuity.js +100 -0
- package/lib/rtp/src/rtp/continuity.js.map +1 -0
- package/lib/rtp/src/rtp/headerExtension.js +41 -21
- package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
- package/lib/rtp/src/rtp/padding.d.ts +17 -0
- package/lib/rtp/src/rtp/padding.js +37 -0
- package/lib/rtp/src/rtp/padding.js.map +1 -0
- package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
- package/lib/rtp/src/rtp/red/encoder.js +14 -1
- package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
- package/lib/rtp/src/rtp/red/packet.js +24 -8
- package/lib/rtp/src/rtp/red/packet.js.map +1 -1
- package/lib/rtp/src/rtp/rtp.d.ts +24 -1
- package/lib/rtp/src/rtp/rtp.js +70 -29
- package/lib/rtp/src/rtp/rtp.js.map +1 -1
- package/lib/rtp/src/rtp/rtx.js +3 -0
- package/lib/rtp/src/rtp/rtx.js.map +1 -1
- package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
- package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
- package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
- package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/index.js +8 -4
- package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
- package/lib/rtp/src/srtp/context/context.js +6 -3
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtcp.js +33 -0
- package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtp.js +34 -10
- package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
- package/lib/rtp/src/srtp/error.d.ts +8 -0
- package/lib/rtp/src/srtp/error.js +13 -1
- package/lib/rtp/src/srtp/error.js.map +1 -1
- package/lib/rtp/src/srtp/packet.js +4 -1
- package/lib/rtp/src/srtp/packet.js.map +1 -1
- package/lib/rtp/src/srtp/replay.d.ts +24 -0
- package/lib/rtp/src/srtp/replay.js +75 -0
- package/lib/rtp/src/srtp/replay.js.map +1 -0
- package/lib/rtp/src/srtp/session.js +2 -1
- package/lib/rtp/src/srtp/session.js.map +1 -1
- package/lib/rtp/src/srtp/srtcp.js +2 -1
- package/lib/rtp/src/srtp/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/srtp.js +2 -1
- package/lib/rtp/src/srtp/srtp.js.map +1 -1
- package/lib/rtp/src/util.js +2 -1
- package/lib/rtp/src/util.js.map +1 -1
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +31 -8
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/const.d.ts +25 -17
- package/lib/sctp/src/const.js +23 -19
- package/lib/sctp/src/const.js.map +1 -1
- package/lib/sctp/src/param.d.ts +6 -2
- package/lib/sctp/src/param.js +22 -8
- package/lib/sctp/src/param.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +80 -0
- package/lib/sctp/src/sctp.js +655 -108
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/sctp/src/transport.js +4 -2
- package/lib/sctp/src/transport.js.map +1 -1
- package/lib/webrtc/src/api/peerConfig.d.ts +48 -5
- package/lib/webrtc/src/api/peerConfig.js +41 -0
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +10 -0
- package/lib/webrtc/src/dataChannel.js +24 -4
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/media/index.d.ts +10 -0
- package/lib/webrtc/src/media/index.js +70 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.js +2 -1
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +14 -1
- package/lib/webrtc/src/media/router.js +46 -2
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +30 -2
- package/lib/webrtc/src/media/rtpReceiver.js +175 -26
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +184 -70
- package/lib/webrtc/src/media/rtpSender.js +626 -449
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +1 -3
- package/lib/webrtc/src/media/rtpTransceiver.js +10 -7
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
- package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
- package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
- package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
- package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
- package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
- package/lib/webrtc/src/media/sender/padding.js +134 -0
- package/lib/webrtc/src/media/sender/padding.js.map +1 -0
- package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
- package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
- package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
- package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
- package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
- package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
- package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
- package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
- package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -33
- package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
- package/lib/webrtc/src/media/sender/senderStats.js +322 -0
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
- package/lib/webrtc/src/media/track.d.ts +20 -2
- package/lib/webrtc/src/media/track.js +23 -5
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
- package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
- package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
- package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
- package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +22 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +19 -8
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +8 -1
- package/lib/webrtc/src/negotiationTransaction.js +18 -5
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.js +4 -3
- package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
- package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +44 -1
- package/lib/webrtc/src/peerConnection.js +74 -8
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +46 -14
- package/lib/webrtc/src/sctpManager.js +88 -25
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.js +12 -6
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +52 -4
- package/lib/webrtc/src/secureTransportManager.js +106 -23
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.js +8 -3
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +53 -1
- package/lib/webrtc/src/transport/dtls.js +131 -31
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +10 -86
- package/lib/webrtc/src/transport/ice.js +70 -31
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +2 -0
- package/lib/webrtc/src/transport/sctp.js +66 -20
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +36 -3
- package/lib/webrtc/src/utils.js +56 -16
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +8 -6
package/lib/sctp/src/sctp.js
CHANGED
|
@@ -60,6 +60,8 @@ const SCTPConnectionStates = [
|
|
|
60
60
|
"connected",
|
|
61
61
|
"connecting",
|
|
62
62
|
];
|
|
63
|
+
/** Shared empty payload of abandoned DATA chunks. */
|
|
64
|
+
const EMPTY_PAYLOAD = Buffer.alloc(0);
|
|
63
65
|
class SCTP {
|
|
64
66
|
get peerRwnd() {
|
|
65
67
|
// RFC 9260 §6.2.1(D-ii): available receiver window = a_rwnd - outstanding DATA.
|
|
@@ -70,13 +72,13 @@ class SCTP {
|
|
|
70
72
|
enumerable: true,
|
|
71
73
|
configurable: true,
|
|
72
74
|
writable: true,
|
|
73
|
-
value:
|
|
75
|
+
value: void 0
|
|
74
76
|
});
|
|
75
77
|
Object.defineProperty(this, "port", {
|
|
76
78
|
enumerable: true,
|
|
77
79
|
configurable: true,
|
|
78
80
|
writable: true,
|
|
79
|
-
value:
|
|
81
|
+
value: void 0
|
|
80
82
|
});
|
|
81
83
|
Object.defineProperty(this, "flush", {
|
|
82
84
|
enumerable: true,
|
|
@@ -145,6 +147,13 @@ class SCTP {
|
|
|
145
147
|
writable: true,
|
|
146
148
|
value: false
|
|
147
149
|
});
|
|
150
|
+
/** An INIT from the peer was accepted (answered with INIT_ACK). */
|
|
151
|
+
Object.defineProperty(this, "receivedInit", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
configurable: true,
|
|
154
|
+
writable: true,
|
|
155
|
+
value: false
|
|
156
|
+
});
|
|
148
157
|
Object.defineProperty(this, "hmacKey", {
|
|
149
158
|
enumerable: true,
|
|
150
159
|
configurable: true,
|
|
@@ -303,12 +312,19 @@ class SCTP {
|
|
|
303
312
|
writable: true,
|
|
304
313
|
value: false
|
|
305
314
|
});
|
|
315
|
+
/** FORWARD-TSN kept until the peer's SACK covers it, so a lost one can be resent. */
|
|
306
316
|
Object.defineProperty(this, "forwardTsnChunk", {
|
|
307
317
|
enumerable: true,
|
|
308
318
|
configurable: true,
|
|
309
319
|
writable: true,
|
|
310
320
|
value: void 0
|
|
311
321
|
});
|
|
322
|
+
Object.defineProperty(this, "forwardTsnPending", {
|
|
323
|
+
enumerable: true,
|
|
324
|
+
configurable: true,
|
|
325
|
+
writable: true,
|
|
326
|
+
value: false
|
|
327
|
+
});
|
|
312
328
|
Object.defineProperty(this, "flightSize", {
|
|
313
329
|
enumerable: true,
|
|
314
330
|
configurable: true,
|
|
@@ -414,6 +430,31 @@ class SCTP {
|
|
|
414
430
|
writable: true,
|
|
415
431
|
value: []
|
|
416
432
|
});
|
|
433
|
+
/** Result returned for the incoming request reconfigResponseSeq; resent to a retransmitted request. */
|
|
434
|
+
Object.defineProperty(this, "lastReconfigResult", {
|
|
435
|
+
enumerable: true,
|
|
436
|
+
configurable: true,
|
|
437
|
+
writable: true,
|
|
438
|
+
value: void 0
|
|
439
|
+
});
|
|
440
|
+
/** The peer answered our outstanding reset request with In progress (RFC 6525 §5.2.7). */
|
|
441
|
+
Object.defineProperty(this, "reconfigRequestInProgress", {
|
|
442
|
+
enumerable: true,
|
|
443
|
+
configurable: true,
|
|
444
|
+
writable: true,
|
|
445
|
+
value: false
|
|
446
|
+
});
|
|
447
|
+
/**
|
|
448
|
+
* RFC 6525 §5.2.2 deferred reset: an incoming Outgoing SSN Reset Request whose
|
|
449
|
+
* Sender's Last Assigned TSN has not been received yet. DATA for the reset
|
|
450
|
+
* streams beyond lastTsn belongs to the new streams and is held until the reset.
|
|
451
|
+
*/
|
|
452
|
+
Object.defineProperty(this, "deferredReset", {
|
|
453
|
+
enumerable: true,
|
|
454
|
+
configurable: true,
|
|
455
|
+
writable: true,
|
|
456
|
+
value: void 0
|
|
457
|
+
});
|
|
417
458
|
// rtt calculation
|
|
418
459
|
Object.defineProperty(this, "srtt", {
|
|
419
460
|
enumerable: true,
|
|
@@ -479,6 +520,23 @@ class SCTP {
|
|
|
479
520
|
writable: true,
|
|
480
521
|
value: void 0
|
|
481
522
|
});
|
|
523
|
+
/**
|
|
524
|
+
* Fires at the earliest expiry of a message in outboundQueue, so expired
|
|
525
|
+
* messages are abandoned even if nothing else (SACK, window update, send)
|
|
526
|
+
* runs transmit.
|
|
527
|
+
*/
|
|
528
|
+
Object.defineProperty(this, "outboundExpiryHandle", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
configurable: true,
|
|
531
|
+
writable: true,
|
|
532
|
+
value: void 0
|
|
533
|
+
});
|
|
534
|
+
Object.defineProperty(this, "outboundExpiryAt", {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
configurable: true,
|
|
537
|
+
writable: true,
|
|
538
|
+
value: void 0
|
|
539
|
+
});
|
|
482
540
|
/**Re-configuration Timer */
|
|
483
541
|
Object.defineProperty(this, "timerReconfigHandle", {
|
|
484
542
|
enumerable: true,
|
|
@@ -547,6 +605,8 @@ class SCTP {
|
|
|
547
605
|
for (const chunk of chunks) {
|
|
548
606
|
this.outboundQueue.push(chunk);
|
|
549
607
|
}
|
|
608
|
+
if (expiry !== undefined)
|
|
609
|
+
this.armOutboundExpiry(expiry);
|
|
550
610
|
if (ordered) {
|
|
551
611
|
this.outboundStreamSeq[streamId] = (0, common_1.uint16Add)(streamSeqNum, 1);
|
|
552
612
|
}
|
|
@@ -624,21 +684,63 @@ class SCTP {
|
|
|
624
684
|
return;
|
|
625
685
|
this.timer3Handle = undefined;
|
|
626
686
|
// # mark retransmit or abandoned chunks
|
|
687
|
+
// RFC 9260 §6.3.3 (E3): only outstanding chunks; gap-acked ones are kept
|
|
688
|
+
// for reneging but not retransmitted.
|
|
627
689
|
this.sentQueue.forEach((chunk) => {
|
|
690
|
+
if (chunk.acked || chunk.abandoned)
|
|
691
|
+
return;
|
|
628
692
|
if (!this.maybeAbandon(chunk)) {
|
|
629
693
|
chunk.retransmit = true;
|
|
630
694
|
}
|
|
695
|
+
this.flightSizeDecrease(chunk);
|
|
631
696
|
});
|
|
632
697
|
this.updateAdvancedPeerAckPoint();
|
|
698
|
+
// An unacknowledged FORWARD-TSN may have been lost; resend it.
|
|
699
|
+
if (this.forwardTsnChunk) {
|
|
700
|
+
this.forwardTsnPending = true;
|
|
701
|
+
}
|
|
633
702
|
// # adjust congestion window
|
|
634
703
|
this.fastRecoveryExit = undefined;
|
|
635
|
-
this.flightSize = 0;
|
|
636
704
|
this.partialBytesAcked = 0;
|
|
637
705
|
this.ssthresh = Math.max(Math.floor(this.cwnd / 2), 4 * this.maxPayloadSize);
|
|
638
706
|
this.cwnd = this.maxPayloadSize;
|
|
639
707
|
this.transmit();
|
|
640
708
|
}
|
|
641
709
|
});
|
|
710
|
+
/**
|
|
711
|
+
* Abandons every expired message still in outboundQueue, wherever it is.
|
|
712
|
+
* Chunks stay in place so TSN order is kept: transmit() moves them to
|
|
713
|
+
* sentQueue unsent when they reach the head, and FORWARD-TSN skips them.
|
|
714
|
+
* Their send() resolves now, without waiting for earlier messages.
|
|
715
|
+
*/
|
|
716
|
+
Object.defineProperty(this, "outboundExpiryExpired", {
|
|
717
|
+
enumerable: true,
|
|
718
|
+
configurable: true,
|
|
719
|
+
writable: true,
|
|
720
|
+
value: () => {
|
|
721
|
+
this.outboundExpiryHandle = undefined;
|
|
722
|
+
this.outboundExpiryAt = undefined;
|
|
723
|
+
if (this.isStopped)
|
|
724
|
+
return;
|
|
725
|
+
let nextExpiry;
|
|
726
|
+
for (const chunk of this.outboundQueue) {
|
|
727
|
+
if (chunk.abandoned || chunk.expiry === undefined)
|
|
728
|
+
continue;
|
|
729
|
+
if (this.isExpired(chunk)) {
|
|
730
|
+
this.markAbandoned(chunk);
|
|
731
|
+
this.resolveSendWaiterOutOfOrder(chunk);
|
|
732
|
+
}
|
|
733
|
+
else if (nextExpiry === undefined || chunk.expiry < nextExpiry) {
|
|
734
|
+
nextExpiry = chunk.expiry;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
if (nextExpiry !== undefined)
|
|
738
|
+
this.armOutboundExpiry(nextExpiry);
|
|
739
|
+
this.transmit().catch((err) => {
|
|
740
|
+
log("transmit on outbound expiry failed", err.message);
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
});
|
|
642
744
|
Object.defineProperty(this, "timerReconfigHandleExpired", {
|
|
643
745
|
enumerable: true,
|
|
644
746
|
configurable: true,
|
|
@@ -646,9 +748,13 @@ class SCTP {
|
|
|
646
748
|
value: async () => {
|
|
647
749
|
if (this.isStopped)
|
|
648
750
|
return;
|
|
649
|
-
|
|
751
|
+
// RFC 6525 §5.2.7: no error count while the peer reports In progress.
|
|
752
|
+
if (this.reconfigRequestInProgress)
|
|
753
|
+
this.timerReconfigFailures = 0;
|
|
754
|
+
else
|
|
755
|
+
this.timerReconfigFailures++;
|
|
650
756
|
// back off
|
|
651
|
-
this.rto = Math.ceil(this.rto * 1.5);
|
|
757
|
+
this.rto = Math.min(Math.ceil(this.rto * 1.5), SCTP_RTO_MAX);
|
|
652
758
|
if (this.timerReconfigFailures > SCTP_MAX_ASSOCIATION_RETRANS) {
|
|
653
759
|
log("timerReconfigFailures", this.timerReconfigFailures);
|
|
654
760
|
this.setState(const_1.SCTP_STATE.CLOSED);
|
|
@@ -683,6 +789,8 @@ class SCTP {
|
|
|
683
789
|
this.heartbeatStart();
|
|
684
790
|
}
|
|
685
791
|
});
|
|
792
|
+
this.transport = transport;
|
|
793
|
+
this.port = port;
|
|
686
794
|
this.mtu = options.mtu ?? exports.DEFAULT_SCTP_MTU;
|
|
687
795
|
validateSctpMtu(this.mtu);
|
|
688
796
|
this.maxPayloadSize = maxPayloadSizeForMtu(this.mtu);
|
|
@@ -722,7 +830,14 @@ class SCTP {
|
|
|
722
830
|
if (chunks.length != 1) {
|
|
723
831
|
throw new Error();
|
|
724
832
|
}
|
|
725
|
-
|
|
833
|
+
// RFC 9260 §8.5.1 (A): an INIT carries verification tag 0. An older
|
|
834
|
+
// werift (<= 0.26) that answered our INIT before its own start() then
|
|
835
|
+
// sends its INIT with the tag it learned from ours; only a peer that
|
|
836
|
+
// received our INIT knows that tag, so accept it as well.
|
|
837
|
+
expectedTag =
|
|
838
|
+
verificationTag === this.localVerificationTag
|
|
839
|
+
? this.localVerificationTag
|
|
840
|
+
: 0;
|
|
726
841
|
}
|
|
727
842
|
else {
|
|
728
843
|
expectedTag = this.localVerificationTag;
|
|
@@ -734,6 +849,9 @@ class SCTP {
|
|
|
734
849
|
for (const chunk of chunks) {
|
|
735
850
|
await this.receiveChunk(chunk);
|
|
736
851
|
}
|
|
852
|
+
// Messages of this packet are delivered by now, so the last message before
|
|
853
|
+
// the reset boundary reaches onReceive before onReconfigStreams.
|
|
854
|
+
await this.maybePerformDeferredReset();
|
|
737
855
|
if (this.sackNeeded) {
|
|
738
856
|
// RFC 9260 delayed ACK guidance is per packet ("every second packet").
|
|
739
857
|
if (this.sackHasNewDataInPacket) {
|
|
@@ -775,8 +893,8 @@ class SCTP {
|
|
|
775
893
|
return;
|
|
776
894
|
const gaps = [];
|
|
777
895
|
let gapNext;
|
|
778
|
-
|
|
779
|
-
const pos = (
|
|
896
|
+
sortTsns(this.sackMisOrdered, this.lastReceivedTsn).forEach((tsn) => {
|
|
897
|
+
const pos = tsnDistance(this.lastReceivedTsn, tsn);
|
|
780
898
|
if (tsn === gapNext) {
|
|
781
899
|
gaps[gaps.length - 1][1] = pos;
|
|
782
900
|
}
|
|
@@ -807,12 +925,28 @@ class SCTP {
|
|
|
807
925
|
break;
|
|
808
926
|
case chunk_1.InitChunk.type:
|
|
809
927
|
{
|
|
810
|
-
|
|
928
|
+
// RFC 9260 §5.2.1: an initiator that receives the peer's INIT in
|
|
929
|
+
// COOKIE-WAIT / COOKIE-ECHOED (both sides sent INIT) answers it
|
|
930
|
+
// with an INIT_ACK.
|
|
931
|
+
if (!this.isServer && !this.isInitiating)
|
|
811
932
|
return;
|
|
812
933
|
const init = chunk;
|
|
934
|
+
this.receivedInit = true;
|
|
813
935
|
log("receive init", init);
|
|
814
|
-
|
|
815
|
-
|
|
936
|
+
// Take the peer's initial TSN only before the handshake got past
|
|
937
|
+
// it (CLOSED / COOKIE-WAIT). In COOKIE-ECHOED our INIT_ACK handling
|
|
938
|
+
// already took it, and once ESTABLISHED a delayed duplicate INIT
|
|
939
|
+
// must not rewind the cumulative TSN of DATA received since.
|
|
940
|
+
// A different initiate tag is a restarted peer: start its TSNs over.
|
|
941
|
+
if (this.associationState === const_1.SCTP_STATE.CLOSED ||
|
|
942
|
+
this.associationState === const_1.SCTP_STATE.COOKIE_WAIT ||
|
|
943
|
+
init.initiateTag !== this.remoteVerificationTag) {
|
|
944
|
+
this.lastReceivedTsn = tsnMinusOne(init.initialTsn);
|
|
945
|
+
this.reconfigResponseSeq = tsnMinusOne(init.initialTsn);
|
|
946
|
+
// Reset requests of the previous TSN space no longer apply.
|
|
947
|
+
this.lastReconfigResult = undefined;
|
|
948
|
+
this.deferredReset = undefined;
|
|
949
|
+
}
|
|
816
950
|
this.remoteVerificationTag = init.initiateTag;
|
|
817
951
|
this.ssthresh = init.advertisedRwnd;
|
|
818
952
|
this.peerAdvertisedRwnd = init.advertisedRwnd;
|
|
@@ -863,11 +997,14 @@ class SCTP {
|
|
|
863
997
|
break;
|
|
864
998
|
}
|
|
865
999
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
1000
|
+
// Enter COOKIE_ECHOED and arm T1 before handing the chunk off: a
|
|
1001
|
+
// duplicate INIT_ACK or an early COOKIE_ACK during the send must see
|
|
1002
|
+
// the new state, and a failed send is packet loss that T1 recovers.
|
|
869
1003
|
this.timer1Start(echo);
|
|
870
1004
|
this.setState(const_1.SCTP_STATE.COOKIE_ECHOED);
|
|
1005
|
+
await this.sendChunk(echo).catch((err) => {
|
|
1006
|
+
log("send echo failed; T1 retransmits", err.message);
|
|
1007
|
+
});
|
|
871
1008
|
}
|
|
872
1009
|
break;
|
|
873
1010
|
case chunk_1.SackChunk.type:
|
|
@@ -912,8 +1049,14 @@ class SCTP {
|
|
|
912
1049
|
break;
|
|
913
1050
|
case chunk_1.CookieEchoChunk.type:
|
|
914
1051
|
{
|
|
915
|
-
|
|
1052
|
+
// An initiator accepts the COOKIE_ECHO that follows its INIT_ACK
|
|
1053
|
+
// to a colliding INIT (RFC 9260 §5.2.1).
|
|
1054
|
+
if (!this.isServer &&
|
|
1055
|
+
!(this.receivedInit &&
|
|
1056
|
+
(this.isInitiating ||
|
|
1057
|
+
this.associationState === const_1.SCTP_STATE.ESTABLISHED))) {
|
|
916
1058
|
return;
|
|
1059
|
+
}
|
|
917
1060
|
const data = chunk;
|
|
918
1061
|
const cookie = data.body;
|
|
919
1062
|
const digest = (0, crypto_1.createHmac)("sha1", this.hmacKey)
|
|
@@ -938,10 +1081,20 @@ class SCTP {
|
|
|
938
1081
|
return;
|
|
939
1082
|
}
|
|
940
1083
|
const ack = new chunk_1.CookieAckChunk();
|
|
941
|
-
|
|
942
|
-
|
|
1084
|
+
// Our own INIT / COOKIE_ECHO (collision) is superseded by the
|
|
1085
|
+
// association the peer's cookie established.
|
|
1086
|
+
this.timer1Cancel();
|
|
1087
|
+
// RFC 9260 §5.1 (D): move to ESTABLISHED when replying. Hand off the
|
|
1088
|
+
// COOKIE_ACK first so it precedes DATA flushed by the connected
|
|
1089
|
+
// event. A failed send is packet loss: the initiator retransmits
|
|
1090
|
+
// COOKIE_ECHO and this association (same cookie key) answers again.
|
|
1091
|
+
const sending = this.sendChunk(ack).catch((err) => {
|
|
1092
|
+
log("send cookieAck failed; peer retransmits", err.message);
|
|
943
1093
|
});
|
|
944
|
-
this.
|
|
1094
|
+
if (this.associationState !== const_1.SCTP_STATE.ESTABLISHED) {
|
|
1095
|
+
this.setState(const_1.SCTP_STATE.ESTABLISHED);
|
|
1096
|
+
}
|
|
1097
|
+
await sending;
|
|
945
1098
|
}
|
|
946
1099
|
break;
|
|
947
1100
|
case chunk_1.CookieAckChunk.type:
|
|
@@ -996,47 +1149,30 @@ class SCTP {
|
|
|
996
1149
|
switch (param.type) {
|
|
997
1150
|
case param_1.OutgoingSSNResetRequestParam.type:
|
|
998
1151
|
{
|
|
999
|
-
|
|
1000
|
-
// # send response
|
|
1001
|
-
const response = new param_1.ReconfigResponseParam(p.requestSequence, param_1.reconfigResult.ReconfigResultSuccessPerformed);
|
|
1002
|
-
this.reconfigResponseSeq = p.requestSequence;
|
|
1003
|
-
await this.sendReconfigParam(response);
|
|
1004
|
-
// # mark closed inbound streams
|
|
1005
|
-
await Promise.all(p.streams.map(async (streamId) => {
|
|
1006
|
-
delete this.inboundStreams[streamId];
|
|
1007
|
-
if (this.outboundStreamSeq[streamId]) {
|
|
1008
|
-
// Only add to reconfigQueue if not already present
|
|
1009
|
-
if (!this.reconfigQueue.includes(streamId)) {
|
|
1010
|
-
this.reconfigQueue.push(streamId);
|
|
1011
|
-
}
|
|
1012
|
-
// await this.sendResetRequest(streamId);
|
|
1013
|
-
}
|
|
1014
|
-
}));
|
|
1015
|
-
await this.transmitReconfigRequest();
|
|
1016
|
-
// # close data channel
|
|
1017
|
-
this.onReconfigStreams.execute(p.streams);
|
|
1152
|
+
await this.receiveOutgoingSSNResetRequest(param);
|
|
1018
1153
|
}
|
|
1019
1154
|
break;
|
|
1020
1155
|
case param_1.ReconfigResponseParam.type:
|
|
1021
1156
|
{
|
|
1022
1157
|
const reset = param;
|
|
1023
|
-
|
|
1158
|
+
const isCurrentRequest = reset.responseSequence === this.reconfigRequest?.requestSequence;
|
|
1159
|
+
if (reset.result === param_1.reconfigResult.InProgress) {
|
|
1160
|
+
if (isCurrentRequest) {
|
|
1161
|
+
// The peer deferred the reset (RFC 6525 §5.2.2). Keep the request so the
|
|
1162
|
+
// Re-configuration timer retransmits it; the peer answered, so this is
|
|
1163
|
+
// not a reachability failure.
|
|
1164
|
+
log("OutgoingSSNResetRequestParam in progress");
|
|
1165
|
+
this.reconfigRequestInProgress = true;
|
|
1166
|
+
// RFC 6525 §5.2.7 H2: restart the timer for this request.
|
|
1167
|
+
this.timerReconfigCancel();
|
|
1168
|
+
this.timerReconfigHandleStart();
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
else if (reset.result !== param_1.reconfigResult.ReconfigResultSuccessPerformed) {
|
|
1024
1172
|
log("OutgoingSSNResetRequestParam failed", Object.keys(param_1.reconfigResult).find((key) => param_1.reconfigResult[key] === reset.result));
|
|
1025
1173
|
}
|
|
1026
|
-
else if (
|
|
1027
|
-
|
|
1028
|
-
delete this.outboundStreamSeq[streamId];
|
|
1029
|
-
return streamId;
|
|
1030
|
-
});
|
|
1031
|
-
this.onReconfigStreams.execute(streamIds);
|
|
1032
|
-
this.reconfigRequest = undefined;
|
|
1033
|
-
this.timerReconfigCancel();
|
|
1034
|
-
// Reset RTO backoff on successful reconfiguration
|
|
1035
|
-
this.rto = SCTP_RTO_INITIAL;
|
|
1036
|
-
this.timerReconfigFailures = 0;
|
|
1037
|
-
if (this.reconfigQueue.length > 0) {
|
|
1038
|
-
await this.transmitReconfigRequest();
|
|
1039
|
-
}
|
|
1174
|
+
else if (isCurrentRequest) {
|
|
1175
|
+
await this.completeOutgoingReset();
|
|
1040
1176
|
}
|
|
1041
1177
|
}
|
|
1042
1178
|
break;
|
|
@@ -1044,13 +1180,143 @@ class SCTP {
|
|
|
1044
1180
|
{
|
|
1045
1181
|
const add = param;
|
|
1046
1182
|
this._inboundStreamsCount += add.newStreams;
|
|
1047
|
-
const res = new param_1.ReconfigResponseParam(add.requestSequence,
|
|
1183
|
+
const res = new param_1.ReconfigResponseParam(add.requestSequence, param_1.reconfigResult.ReconfigResultSuccessPerformed);
|
|
1048
1184
|
this.reconfigResponseSeq = add.requestSequence;
|
|
1185
|
+
this.lastReconfigResult = res.result;
|
|
1049
1186
|
await this.sendReconfigParam(res);
|
|
1050
1187
|
}
|
|
1051
1188
|
break;
|
|
1052
1189
|
}
|
|
1053
1190
|
}
|
|
1191
|
+
/** The peer answered our outstanding reset request with Success - Performed. */
|
|
1192
|
+
async completeOutgoingReset() {
|
|
1193
|
+
const streamIds = this.reconfigRequest.streams.map((streamId) => {
|
|
1194
|
+
delete this.outboundStreamSeq[streamId];
|
|
1195
|
+
return streamId;
|
|
1196
|
+
});
|
|
1197
|
+
this.onReconfigStreams.execute(streamIds);
|
|
1198
|
+
this.reconfigRequest = undefined;
|
|
1199
|
+
this.reconfigRequestInProgress = false;
|
|
1200
|
+
this.timerReconfigCancel();
|
|
1201
|
+
// Reset RTO backoff on successful reconfiguration
|
|
1202
|
+
this.rto = SCTP_RTO_INITIAL;
|
|
1203
|
+
this.timerReconfigFailures = 0;
|
|
1204
|
+
if (this.reconfigQueue.length > 0) {
|
|
1205
|
+
await this.transmitReconfigRequest();
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/** RFC 6525 §4.1: an empty stream list means every stream. */
|
|
1209
|
+
resetTargetStreams(request) {
|
|
1210
|
+
if (request.streams.length > 0)
|
|
1211
|
+
return request.streams;
|
|
1212
|
+
return [
|
|
1213
|
+
...new Set([
|
|
1214
|
+
...Object.keys(this.inboundStreams).map(Number),
|
|
1215
|
+
...Object.keys(this.outboundStreamSeq).map(Number),
|
|
1216
|
+
]),
|
|
1217
|
+
];
|
|
1218
|
+
}
|
|
1219
|
+
/** RFC 6525 §5.2.1 sequence check, then §5.2.2 immediate or deferred reset. */
|
|
1220
|
+
async receiveOutgoingSSNResetRequest(request) {
|
|
1221
|
+
const respond = (result) => this.sendReconfigParam(new param_1.ReconfigResponseParam(request.requestSequence, result));
|
|
1222
|
+
if (request.requestSequence === this.reconfigResponseSeq) {
|
|
1223
|
+
// Retransmission of an already processed request: resend the same result.
|
|
1224
|
+
await respond(this.lastReconfigResult ?? param_1.reconfigResult.BadSequenceNumber);
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
// Only one request is deferred at a time, so it is the expected one.
|
|
1228
|
+
const pending = this.deferredReset;
|
|
1229
|
+
const expected = pending
|
|
1230
|
+
? pending.request.requestSequence
|
|
1231
|
+
: tsnPlusOne(this.reconfigResponseSeq);
|
|
1232
|
+
if (request.requestSequence !== expected) {
|
|
1233
|
+
await respond(param_1.reconfigResult.BadSequenceNumber);
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
// RFC 6525 §5.2.2 E1: the peer has received our outstanding request. The
|
|
1237
|
+
// reset itself completes only with the peer's response, and that response
|
|
1238
|
+
// may be lost, so keep retransmitting the request (the peer answers a
|
|
1239
|
+
// retransmission with the same result) instead of stopping the timer. The
|
|
1240
|
+
// peer is reachable, so like In progress the expiries are not failures.
|
|
1241
|
+
if (this.reconfigRequest &&
|
|
1242
|
+
request.responseSequence === this.reconfigRequest.requestSequence) {
|
|
1243
|
+
this.reconfigRequestInProgress = true;
|
|
1244
|
+
this.timerReconfigCancel();
|
|
1245
|
+
this.timerReconfigHandleStart();
|
|
1246
|
+
}
|
|
1247
|
+
const target = pending?.request ?? request;
|
|
1248
|
+
if (!this.reachedResetBoundary(target)) {
|
|
1249
|
+
// Some DATA up to Sender's Last Assigned TSN is still missing. A
|
|
1250
|
+
// retransmitted request is evaluated again, so reconfigResponseSeq stays.
|
|
1251
|
+
this.deferredReset ?? (this.deferredReset = { request: target, heldChunks: [] });
|
|
1252
|
+
await respond(param_1.reconfigResult.InProgress);
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
const { transmitReverseReset } = this.performIncomingStreamReset(target);
|
|
1256
|
+
await respond(param_1.reconfigResult.ReconfigResultSuccessPerformed);
|
|
1257
|
+
await transmitReverseReset();
|
|
1258
|
+
}
|
|
1259
|
+
reachedResetBoundary(request) {
|
|
1260
|
+
return (this.lastReceivedTsn !== undefined &&
|
|
1261
|
+
(0, common_1.uint32Gte)(this.lastReceivedTsn, request.lastTsn));
|
|
1262
|
+
}
|
|
1263
|
+
async maybePerformDeferredReset() {
|
|
1264
|
+
const pending = this.deferredReset;
|
|
1265
|
+
if (!pending || !this.reachedResetBoundary(pending.request))
|
|
1266
|
+
return;
|
|
1267
|
+
// RFC 6525 §5.2.2: answer Success - Performed once the deferred reset is done.
|
|
1268
|
+
const { transmitReverseReset } = this.performIncomingStreamReset(pending.request);
|
|
1269
|
+
await this.sendReconfigParam(new param_1.ReconfigResponseParam(pending.request.requestSequence, param_1.reconfigResult.ReconfigResultSuccessPerformed));
|
|
1270
|
+
await transmitReverseReset();
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Resets the inbound streams of `request` synchronously, so no DATA received
|
|
1274
|
+
* while awaiting can reach the old streams. Returns the asynchronous part,
|
|
1275
|
+
* the reset of our own outgoing streams.
|
|
1276
|
+
*/
|
|
1277
|
+
performIncomingStreamReset(request) {
|
|
1278
|
+
const heldChunks = this.deferredReset?.request === request
|
|
1279
|
+
? this.deferredReset.heldChunks
|
|
1280
|
+
: [];
|
|
1281
|
+
this.deferredReset = undefined;
|
|
1282
|
+
this.reconfigResponseSeq = request.requestSequence;
|
|
1283
|
+
this.lastReconfigResult = param_1.reconfigResult.ReconfigResultSuccessPerformed;
|
|
1284
|
+
const resetStreams = this.resetTargetStreams(request);
|
|
1285
|
+
for (const streamId of resetStreams) {
|
|
1286
|
+
const inboundStream = this.inboundStreams[streamId];
|
|
1287
|
+
if (inboundStream) {
|
|
1288
|
+
// Incomplete messages of the old stream are discarded.
|
|
1289
|
+
for (const chunk of inboundStream.reassembly) {
|
|
1290
|
+
this.advertisedRwnd += chunk.userData.length;
|
|
1291
|
+
}
|
|
1292
|
+
delete this.inboundStreams[streamId];
|
|
1293
|
+
}
|
|
1294
|
+
if (this.outboundStreamSeq[streamId]) {
|
|
1295
|
+
// Only add to reconfigQueue if not already present
|
|
1296
|
+
if (!this.reconfigQueue.includes(streamId)) {
|
|
1297
|
+
this.reconfigQueue.push(streamId);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
// # close data channel
|
|
1302
|
+
this.onReconfigStreams.execute(resetStreams);
|
|
1303
|
+
// DATA beyond the boundary belongs to the reset streams (SSN starts at 0).
|
|
1304
|
+
const streamIds = new Set();
|
|
1305
|
+
for (const chunk of heldChunks) {
|
|
1306
|
+
this.getInboundStream(chunk.streamId).addChunk(chunk);
|
|
1307
|
+
streamIds.add(chunk.streamId);
|
|
1308
|
+
}
|
|
1309
|
+
for (const streamId of streamIds) {
|
|
1310
|
+
this.deliverMessages(this.getInboundStream(streamId));
|
|
1311
|
+
}
|
|
1312
|
+
return { transmitReverseReset: () => this.transmitReconfigRequest() };
|
|
1313
|
+
}
|
|
1314
|
+
deliverMessages(inboundStream) {
|
|
1315
|
+
for (const message of inboundStream.popMessages()) {
|
|
1316
|
+
this.advertisedRwnd += message[2].length;
|
|
1317
|
+
this.receive(...message);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1054
1320
|
receiveDataChunk(chunk) {
|
|
1055
1321
|
this.sackNeeded = true;
|
|
1056
1322
|
if (this.markReceived(chunk.tsn)) {
|
|
@@ -1068,13 +1334,19 @@ class SCTP {
|
|
|
1068
1334
|
// RFC 9260 permits immediate SACK on gap/loss indicators.
|
|
1069
1335
|
this.sackImmediate = true;
|
|
1070
1336
|
}
|
|
1071
|
-
const inboundStream = this.getInboundStream(chunk.streamId);
|
|
1072
|
-
inboundStream.addChunk(chunk);
|
|
1073
1337
|
this.advertisedRwnd -= chunk.userData.length;
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1338
|
+
const pending = this.deferredReset;
|
|
1339
|
+
if (pending &&
|
|
1340
|
+
(pending.request.streams.length === 0 ||
|
|
1341
|
+
pending.request.streams.includes(chunk.streamId)) &&
|
|
1342
|
+
(0, common_1.uint32Gt)(chunk.tsn, pending.request.lastTsn)) {
|
|
1343
|
+
// RFC 6525 §5.2.2: hold DATA for the new stream until the reset is performed.
|
|
1344
|
+
pending.heldChunks.push(chunk);
|
|
1345
|
+
return;
|
|
1077
1346
|
}
|
|
1347
|
+
const inboundStream = this.getInboundStream(chunk.streamId);
|
|
1348
|
+
inboundStream.addChunk(chunk);
|
|
1349
|
+
this.deliverMessages(inboundStream);
|
|
1078
1350
|
}
|
|
1079
1351
|
async receiveSackChunk(chunk) {
|
|
1080
1352
|
// """
|
|
@@ -1091,18 +1363,19 @@ class SCTP {
|
|
|
1091
1363
|
(0, common_1.uint32Gte)(this.lastSackedTsn, this.sentQueue.peek().tsn)) {
|
|
1092
1364
|
const sChunk = this.sentQueue.shift();
|
|
1093
1365
|
done++;
|
|
1094
|
-
if (!sChunk
|
|
1366
|
+
if (!sChunk.acked) {
|
|
1095
1367
|
doneBytes += sChunk.bookSize;
|
|
1096
|
-
this.flightSizeDecrease(sChunk);
|
|
1097
1368
|
}
|
|
1369
|
+
this.flightSizeDecrease(sChunk);
|
|
1098
1370
|
if (done === 1 && sChunk.sentCount === 1) {
|
|
1099
1371
|
this.updateRto(receivedTime - sChunk.sentTime);
|
|
1100
1372
|
}
|
|
1101
1373
|
}
|
|
1102
1374
|
// # handle gap blocks
|
|
1103
1375
|
let loss = false;
|
|
1376
|
+
const seen = new Set();
|
|
1377
|
+
let highestNewlyAcked = chunk.cumulativeTsn;
|
|
1104
1378
|
if (chunk.gaps.length > 0) {
|
|
1105
|
-
const seen = new Set();
|
|
1106
1379
|
let highestSeenTsn;
|
|
1107
1380
|
chunk.gaps.forEach((gap) => {
|
|
1108
1381
|
for (let pos = gap[0]; pos < gap[1] + 1; pos++) {
|
|
@@ -1110,7 +1383,6 @@ class SCTP {
|
|
|
1110
1383
|
seen.add(highestSeenTsn);
|
|
1111
1384
|
}
|
|
1112
1385
|
});
|
|
1113
|
-
let highestNewlyAcked = chunk.cumulativeTsn;
|
|
1114
1386
|
for (const sChunk of this.sentQueue) {
|
|
1115
1387
|
if ((0, common_1.uint32Gt)(sChunk.tsn, highestSeenTsn)) {
|
|
1116
1388
|
break;
|
|
@@ -1118,26 +1390,46 @@ class SCTP {
|
|
|
1118
1390
|
if (seen.has(sChunk.tsn) && !sChunk.acked) {
|
|
1119
1391
|
doneBytes += sChunk.bookSize;
|
|
1120
1392
|
sChunk.acked = true;
|
|
1393
|
+
sChunk.reneged = false;
|
|
1394
|
+
// A pending retransmission is moot once the peer holds the chunk.
|
|
1395
|
+
sChunk.retransmit = false;
|
|
1121
1396
|
this.flightSizeDecrease(sChunk);
|
|
1122
1397
|
highestNewlyAcked = sChunk.tsn;
|
|
1123
1398
|
}
|
|
1124
1399
|
}
|
|
1125
|
-
|
|
1400
|
+
}
|
|
1401
|
+
// # detect reneging (RFC 9260 6.2.1 D-iii)
|
|
1402
|
+
// A chunk gap-acked before but missing from this SACK was dropped by the
|
|
1403
|
+
// peer: it is outstanding again, and every SACK still missing it counts one
|
|
1404
|
+
// miss indication towards Fast Retransmit. Chunks up to HTNA are struck by
|
|
1405
|
+
// the loop below, so only the ones beyond it are struck here.
|
|
1406
|
+
let reneged = false;
|
|
1407
|
+
for (const sChunk of this.sentQueue) {
|
|
1408
|
+
// Abandoned chunks are never retransmitted nor counted in flight again.
|
|
1409
|
+
if (seen.has(sChunk.tsn) || sChunk.abandoned)
|
|
1410
|
+
continue;
|
|
1411
|
+
if (sChunk.acked) {
|
|
1412
|
+
sChunk.acked = false;
|
|
1413
|
+
sChunk.reneged = true;
|
|
1414
|
+
// Outstanding again, so it is counted in flight until resent or acked.
|
|
1415
|
+
this.flightSizeIncrease(sChunk);
|
|
1416
|
+
}
|
|
1417
|
+
if (!sChunk.reneged)
|
|
1418
|
+
continue;
|
|
1419
|
+
reneged = true;
|
|
1420
|
+
if (!sChunk.retransmit &&
|
|
1421
|
+
(chunk.gaps.length === 0 || (0, common_1.uint32Gt)(sChunk.tsn, highestNewlyAcked))) {
|
|
1422
|
+
loss = this.strikeChunk(sChunk) || loss;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
// # strike missing chunks prior to HTNA
|
|
1426
|
+
if (chunk.gaps.length > 0) {
|
|
1126
1427
|
for (const sChunk of this.sentQueue) {
|
|
1127
1428
|
if ((0, common_1.uint32Gt)(sChunk.tsn, highestNewlyAcked)) {
|
|
1128
1429
|
break;
|
|
1129
1430
|
}
|
|
1130
1431
|
if (!seen.has(sChunk.tsn)) {
|
|
1131
|
-
sChunk
|
|
1132
|
-
if (sChunk.misses === 3) {
|
|
1133
|
-
sChunk.misses = 0;
|
|
1134
|
-
if (!this.maybeAbandon(sChunk)) {
|
|
1135
|
-
sChunk.retransmit = true;
|
|
1136
|
-
}
|
|
1137
|
-
sChunk.acked = false;
|
|
1138
|
-
this.flightSizeDecrease(sChunk);
|
|
1139
|
-
loss = true;
|
|
1140
|
-
}
|
|
1432
|
+
loss = this.strikeChunk(sChunk) || loss;
|
|
1141
1433
|
}
|
|
1142
1434
|
}
|
|
1143
1435
|
}
|
|
@@ -1172,9 +1464,13 @@ class SCTP {
|
|
|
1172
1464
|
else if (done > 0) {
|
|
1173
1465
|
this.timer3Restart();
|
|
1174
1466
|
}
|
|
1467
|
+
else if (reneged && !this.timer3Handle) {
|
|
1468
|
+
this.timer3Start();
|
|
1469
|
+
}
|
|
1175
1470
|
// RFC 9260 §6.2.1(D-ii): keep latest peer a_rwnd; available window is derived via flightSize.
|
|
1176
1471
|
this.peerAdvertisedRwnd = chunk.advertisedRwnd;
|
|
1177
1472
|
this.updateAdvancedPeerAckPoint();
|
|
1473
|
+
this.settleForwardTsn(chunk.cumulativeTsn);
|
|
1178
1474
|
await this.onSackReceived();
|
|
1179
1475
|
await this.transmit();
|
|
1180
1476
|
}
|
|
@@ -1188,7 +1484,7 @@ class SCTP {
|
|
|
1188
1484
|
// # advance cumulative TSN
|
|
1189
1485
|
this.lastReceivedTsn = chunk.cumulativeTsn;
|
|
1190
1486
|
this.sackMisOrdered = new Set([...this.sackMisOrdered].filter(isObsolete));
|
|
1191
|
-
for (const tsn of
|
|
1487
|
+
for (const tsn of sortTsns(this.sackMisOrdered, this.lastReceivedTsn)) {
|
|
1192
1488
|
if (tsn === tsnPlusOne(this.lastReceivedTsn)) {
|
|
1193
1489
|
this.lastReceivedTsn = tsn;
|
|
1194
1490
|
}
|
|
@@ -1199,20 +1495,31 @@ class SCTP {
|
|
|
1199
1495
|
// # filter out obsolete entries
|
|
1200
1496
|
this.sackDuplicates = this.sackDuplicates.filter(isObsolete);
|
|
1201
1497
|
this.sackMisOrdered = new Set([...this.sackMisOrdered].filter(isObsolete));
|
|
1202
|
-
// # update reassembly
|
|
1498
|
+
// # update reassembly (RFC 3758 3.6)
|
|
1203
1499
|
for (const [streamId, streamSeqNum] of chunk.streams) {
|
|
1204
1500
|
const inboundStream = this.getInboundStream(streamId);
|
|
1205
|
-
// #
|
|
1206
|
-
|
|
1207
|
-
|
|
1501
|
+
// # deliver stranded complete messages, drop broken ones, then advance
|
|
1502
|
+
const { messages, prunedSize } = inboundStream.forwardSequenceNumber(streamSeqNum);
|
|
1503
|
+
this.advertisedRwnd += prunedSize;
|
|
1504
|
+
for (const message of [...messages, ...inboundStream.popMessages()]) {
|
|
1208
1505
|
this.advertisedRwnd += message[2].length;
|
|
1209
1506
|
this.receive(...message);
|
|
1210
1507
|
}
|
|
1211
1508
|
}
|
|
1212
|
-
// #
|
|
1213
|
-
Object.values(this.inboundStreams)
|
|
1214
|
-
this.advertisedRwnd += inboundStream.
|
|
1215
|
-
}
|
|
1509
|
+
// # unordered chunks covered by the cumulative TSN will never complete
|
|
1510
|
+
for (const inboundStream of Object.values(this.inboundStreams)) {
|
|
1511
|
+
this.advertisedRwnd += inboundStream.pruneUnorderedChunks(chunk.cumulativeTsn);
|
|
1512
|
+
}
|
|
1513
|
+
const pending = this.deferredReset;
|
|
1514
|
+
if (pending) {
|
|
1515
|
+
pending.heldChunks = pending.heldChunks.filter((held) => {
|
|
1516
|
+
// Only DATA the FORWARD-TSN skipped is dropped; later received DATA stays.
|
|
1517
|
+
if ((0, common_1.uint32Gt)(held.tsn, chunk.cumulativeTsn))
|
|
1518
|
+
return true;
|
|
1519
|
+
this.advertisedRwnd += held.userData.length;
|
|
1520
|
+
return false;
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1216
1523
|
}
|
|
1217
1524
|
updateRto(R) {
|
|
1218
1525
|
if (!this.srtt) {
|
|
@@ -1242,7 +1549,7 @@ class SCTP {
|
|
|
1242
1549
|
return true;
|
|
1243
1550
|
}
|
|
1244
1551
|
this.sackMisOrdered.add(tsn);
|
|
1245
|
-
for (const tsn of
|
|
1552
|
+
for (const tsn of sortTsns(this.sackMisOrdered, this.lastReceivedTsn)) {
|
|
1246
1553
|
if (tsn === tsnPlusOne(this.lastReceivedTsn)) {
|
|
1247
1554
|
this.lastReceivedTsn = tsn;
|
|
1248
1555
|
}
|
|
@@ -1256,8 +1563,24 @@ class SCTP {
|
|
|
1256
1563
|
return false;
|
|
1257
1564
|
}
|
|
1258
1565
|
resolveSendWaiters(sentChunk) {
|
|
1566
|
+
this.dropDoneSendWaiters();
|
|
1259
1567
|
if (this.sendWaiters.peek()?.chunk === sentChunk) {
|
|
1260
1568
|
this.sendWaiters.shift().resolve();
|
|
1569
|
+
this.dropDoneSendWaiters();
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
dropDoneSendWaiters() {
|
|
1573
|
+
while (this.sendWaiters.peek()?.done)
|
|
1574
|
+
this.sendWaiters.shift();
|
|
1575
|
+
}
|
|
1576
|
+
/** Resolves the send() of an expired queued message ahead of earlier ones (rare, O(n)). */
|
|
1577
|
+
resolveSendWaiterOutOfOrder(chunk) {
|
|
1578
|
+
for (const waiter of this.sendWaiters) {
|
|
1579
|
+
if (waiter.chunk === chunk && !waiter.done) {
|
|
1580
|
+
waiter.done = true;
|
|
1581
|
+
waiter.resolve();
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1261
1584
|
}
|
|
1262
1585
|
}
|
|
1263
1586
|
/** Settles every pending send() so no caller is left waiting after close. */
|
|
@@ -1293,11 +1616,11 @@ class SCTP {
|
|
|
1293
1616
|
// Transmit outbound data.
|
|
1294
1617
|
// """
|
|
1295
1618
|
// # send FORWARD TSN
|
|
1296
|
-
if (this.forwardTsnChunk) {
|
|
1619
|
+
if (this.forwardTsnChunk && this.forwardTsnPending) {
|
|
1620
|
+
this.forwardTsnPending = false;
|
|
1297
1621
|
await this.sendChunk(this.forwardTsnChunk).catch((err) => {
|
|
1298
1622
|
log("send forwardTsn failed", err.message);
|
|
1299
1623
|
});
|
|
1300
|
-
this.forwardTsnChunk = undefined;
|
|
1301
1624
|
if (!this.timer3Handle) {
|
|
1302
1625
|
this.timer3Start();
|
|
1303
1626
|
}
|
|
@@ -1306,9 +1629,20 @@ class SCTP {
|
|
|
1306
1629
|
? 2 * this.maxPayloadSize
|
|
1307
1630
|
: 4 * this.maxPayloadSize;
|
|
1308
1631
|
const cwnd = Math.min(this.flightSize + burstSize, this.cwnd);
|
|
1632
|
+
// Set when expired data is abandoned here, so the FORWARD-TSN goes out.
|
|
1633
|
+
let abandoned = false;
|
|
1309
1634
|
let retransmitEarliest = true;
|
|
1310
1635
|
for (const dataChunk of this.sentQueue) {
|
|
1636
|
+
if (dataChunk.retransmit && (dataChunk.acked || dataChunk.abandoned)) {
|
|
1637
|
+
// Acked or abandoned after being marked; nothing to resend.
|
|
1638
|
+
dataChunk.retransmit = false;
|
|
1639
|
+
}
|
|
1311
1640
|
if (dataChunk.retransmit) {
|
|
1641
|
+
// The lifetime may have run out while the chunk waited for cwnd.
|
|
1642
|
+
if (this.isExpired(dataChunk) && this.maybeAbandon(dataChunk)) {
|
|
1643
|
+
abandoned = true;
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1312
1646
|
if (this.fastRecoveryTransmit) {
|
|
1313
1647
|
this.fastRecoveryTransmit = false;
|
|
1314
1648
|
}
|
|
@@ -1318,6 +1652,7 @@ class SCTP {
|
|
|
1318
1652
|
this.flightSizeIncrease(dataChunk);
|
|
1319
1653
|
dataChunk.misses = 0;
|
|
1320
1654
|
dataChunk.retransmit = false;
|
|
1655
|
+
dataChunk.reneged = false;
|
|
1321
1656
|
dataChunk.sentCount++;
|
|
1322
1657
|
await this.sendChunk(dataChunk).catch((err) => {
|
|
1323
1658
|
log("send data failed", err.message);
|
|
@@ -1329,10 +1664,22 @@ class SCTP {
|
|
|
1329
1664
|
retransmitEarliest = false;
|
|
1330
1665
|
}
|
|
1331
1666
|
// Drain queued outbound DATA; retransmission pacing is controlled by RTO/T3.
|
|
1332
|
-
while (this.outboundQueue.length > 0
|
|
1333
|
-
this.flightSize < cwnd &&
|
|
1334
|
-
this.peerRwnd > 0) {
|
|
1667
|
+
while (this.outboundQueue.length > 0) {
|
|
1335
1668
|
const chunk = this.outboundQueue.peek();
|
|
1669
|
+
// A message that expired while waiting for cwnd/rwnd is never sent; its
|
|
1670
|
+
// TSNs are already assigned, so it is abandoned and skipped by FORWARD-TSN.
|
|
1671
|
+
// A message the expiry timer already abandoned in place goes the same way.
|
|
1672
|
+
if (chunk.abandoned || this.isExpired(chunk)) {
|
|
1673
|
+
this.outboundQueue.shift();
|
|
1674
|
+
this.sentQueue.push(chunk);
|
|
1675
|
+
this.resolveSendWaiters(chunk);
|
|
1676
|
+
this.abandonMessage(this.sentQueue.length - 1);
|
|
1677
|
+
abandoned = true;
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1680
|
+
if (this.flightSize >= cwnd || this.peerRwnd <= 0) {
|
|
1681
|
+
break;
|
|
1682
|
+
}
|
|
1336
1683
|
if (chunk.bookSize > this.peerRwnd && this.flightSize > 0) {
|
|
1337
1684
|
break;
|
|
1338
1685
|
}
|
|
@@ -1350,6 +1697,14 @@ class SCTP {
|
|
|
1350
1697
|
this.timer3Start();
|
|
1351
1698
|
}
|
|
1352
1699
|
}
|
|
1700
|
+
if (abandoned) {
|
|
1701
|
+
this.updateAdvancedPeerAckPoint();
|
|
1702
|
+
// Send the FORWARD-TSN in the next round of transmit().
|
|
1703
|
+
if (this.forwardTsnPending)
|
|
1704
|
+
this.transmitRequested = true;
|
|
1705
|
+
}
|
|
1706
|
+
if (this.outboundQueue.length === 0)
|
|
1707
|
+
this.outboundExpiryCancel();
|
|
1353
1708
|
this.flush.execute();
|
|
1354
1709
|
}
|
|
1355
1710
|
async transmitReconfigRequest() {
|
|
@@ -1363,6 +1718,7 @@ class SCTP {
|
|
|
1363
1718
|
const param = new param_1.OutgoingSSNResetRequestParam(this.reconfigRequestSeq, this.reconfigResponseSeq, tsnMinusOne(this.localTsn), streams);
|
|
1364
1719
|
this.reconfigRequestSeq = tsnPlusOne(this.reconfigRequestSeq);
|
|
1365
1720
|
this.reconfigRequest = param;
|
|
1721
|
+
this.reconfigRequestInProgress = false;
|
|
1366
1722
|
await this.sendReconfigParam(param);
|
|
1367
1723
|
this.timerReconfigHandleStart();
|
|
1368
1724
|
}
|
|
@@ -1385,11 +1741,20 @@ class SCTP {
|
|
|
1385
1741
|
await this.transmit();
|
|
1386
1742
|
}
|
|
1387
1743
|
}
|
|
1744
|
+
// flightSize always equals the bookSize sum of inFlight chunks in sentQueue,
|
|
1745
|
+
// so both helpers are idempotent per chunk.
|
|
1388
1746
|
flightSizeIncrease(chunk) {
|
|
1747
|
+
if (chunk.inFlight)
|
|
1748
|
+
return;
|
|
1749
|
+
chunk.inFlight = true;
|
|
1389
1750
|
this.flightSize += chunk.bookSize;
|
|
1390
1751
|
}
|
|
1752
|
+
/** No-op for chunks not counted in flightSize, so every exit path can call it. */
|
|
1391
1753
|
flightSizeDecrease(chunk) {
|
|
1392
|
-
|
|
1754
|
+
if (!chunk.inFlight)
|
|
1755
|
+
return;
|
|
1756
|
+
chunk.inFlight = false;
|
|
1757
|
+
this.flightSize -= chunk.bookSize;
|
|
1393
1758
|
}
|
|
1394
1759
|
// # timers
|
|
1395
1760
|
/**t1 is wait for initAck or cookieAck */
|
|
@@ -1438,6 +1803,25 @@ class SCTP {
|
|
|
1438
1803
|
// RFC 9260 requires restarting T3-rtx with current RTO (seconds -> JS ms).
|
|
1439
1804
|
this.timer3Handle = setTimeout(this.timer3Expired, this.rto * 1000);
|
|
1440
1805
|
}
|
|
1806
|
+
/** Arms the outbound expiry timer for `expiry` unless an earlier one is armed. */
|
|
1807
|
+
armOutboundExpiry(expiry) {
|
|
1808
|
+
if (this.isStopped)
|
|
1809
|
+
return;
|
|
1810
|
+
if (this.outboundExpiryHandle && this.outboundExpiryAt <= expiry)
|
|
1811
|
+
return;
|
|
1812
|
+
this.outboundExpiryCancel();
|
|
1813
|
+
this.outboundExpiryAt = expiry;
|
|
1814
|
+
this.outboundExpiryHandle = setTimeout(this.outboundExpiryExpired,
|
|
1815
|
+
// setTimeout overflows above 2^31 - 1 ms; a later expiry re-arms on fire.
|
|
1816
|
+
Math.min(Math.max(0, expiry - Date.now()), 0x7fffffff));
|
|
1817
|
+
}
|
|
1818
|
+
outboundExpiryCancel() {
|
|
1819
|
+
if (this.outboundExpiryHandle) {
|
|
1820
|
+
clearTimeout(this.outboundExpiryHandle);
|
|
1821
|
+
this.outboundExpiryHandle = undefined;
|
|
1822
|
+
}
|
|
1823
|
+
this.outboundExpiryAt = undefined;
|
|
1824
|
+
}
|
|
1441
1825
|
timer3Cancel() {
|
|
1442
1826
|
if (this.timer3Handle) {
|
|
1443
1827
|
clearTimeout(this.timer3Handle);
|
|
@@ -1488,14 +1872,30 @@ class SCTP {
|
|
|
1488
1872
|
this.heartbeatInterval = interval;
|
|
1489
1873
|
this.heartbeatRestart();
|
|
1490
1874
|
}
|
|
1875
|
+
/** Drops the FORWARD-TSN once acknowledged; otherwise keeps T3 running to resend it. */
|
|
1876
|
+
settleForwardTsn(sackedTsn) {
|
|
1877
|
+
if (!this.forwardTsnChunk)
|
|
1878
|
+
return;
|
|
1879
|
+
if ((0, common_1.uint32Gte)(sackedTsn, this.forwardTsnChunk.cumulativeTsn)) {
|
|
1880
|
+
this.forwardTsnChunk = undefined;
|
|
1881
|
+
this.forwardTsnPending = false;
|
|
1882
|
+
if (this.sentQueue.length === 0)
|
|
1883
|
+
this.timer3Cancel();
|
|
1884
|
+
}
|
|
1885
|
+
else if (!this.timer3Handle) {
|
|
1886
|
+
this.timer3Start();
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1491
1889
|
updateAdvancedPeerAckPoint() {
|
|
1492
1890
|
if ((0, common_1.uint32Gt)(this.lastSackedTsn, this.advancedPeerAckTsn)) {
|
|
1493
1891
|
this.advancedPeerAckTsn = this.lastSackedTsn;
|
|
1494
1892
|
}
|
|
1495
1893
|
let done = 0;
|
|
1496
|
-
|
|
1894
|
+
// Carry over streams of an unacknowledged FORWARD-TSN that this one replaces.
|
|
1895
|
+
const streams = Object.fromEntries(this.forwardTsnChunk?.streams ?? []);
|
|
1497
1896
|
while (this.sentQueue.length > 0 && this.sentQueue.peek().abandoned) {
|
|
1498
1897
|
const chunk = this.sentQueue.shift();
|
|
1898
|
+
this.flightSizeDecrease(chunk);
|
|
1499
1899
|
this.advancedPeerAckTsn = chunk.tsn;
|
|
1500
1900
|
done++;
|
|
1501
1901
|
if (!(chunk.flags & SCTP_DATA_UNORDERED)) {
|
|
@@ -1503,6 +1903,7 @@ class SCTP {
|
|
|
1503
1903
|
}
|
|
1504
1904
|
}
|
|
1505
1905
|
if (done) {
|
|
1906
|
+
this.forwardTsnPending = true;
|
|
1506
1907
|
this.forwardTsnChunk = new chunk_1.ForwardTsnChunk(0, undefined);
|
|
1507
1908
|
this.forwardTsnChunk.cumulativeTsn = this.advancedPeerAckTsn;
|
|
1508
1909
|
this.forwardTsnChunk.streams = Object.entries(streams).map(([k, v]) => [
|
|
@@ -1514,28 +1915,80 @@ class SCTP {
|
|
|
1514
1915
|
maybeAbandon(chunk) {
|
|
1515
1916
|
if (chunk.abandoned)
|
|
1516
1917
|
return true;
|
|
1918
|
+
// The peer already holds an acked chunk (gap SACK); abandoning it would
|
|
1919
|
+
// make the FORWARD-TSN discard data the receiver could deliver.
|
|
1920
|
+
if (chunk.acked)
|
|
1921
|
+
return false;
|
|
1517
1922
|
const abandon = (!!chunk.maxRetransmits && chunk.maxRetransmits < chunk.sentCount) ||
|
|
1518
|
-
(
|
|
1923
|
+
this.isExpired(chunk);
|
|
1519
1924
|
if (!abandon)
|
|
1520
1925
|
return false;
|
|
1521
|
-
const chunkPos = this.sentQueue.findIndex((v) => v
|
|
1926
|
+
const chunkPos = this.sentQueue.findIndex((v) => v === chunk);
|
|
1927
|
+
if (chunkPos < 0)
|
|
1928
|
+
return false;
|
|
1929
|
+
this.abandonMessage(chunkPos);
|
|
1930
|
+
return true;
|
|
1931
|
+
}
|
|
1932
|
+
/** Counts a miss indication; on the third, marks the chunk for Fast Retransmit (or abandons it). */
|
|
1933
|
+
strikeChunk(chunk) {
|
|
1934
|
+
chunk.misses++;
|
|
1935
|
+
if (chunk.misses < 3)
|
|
1936
|
+
return false;
|
|
1937
|
+
chunk.misses = 0;
|
|
1938
|
+
if (!this.maybeAbandon(chunk)) {
|
|
1939
|
+
chunk.retransmit = true;
|
|
1940
|
+
}
|
|
1941
|
+
chunk.acked = false;
|
|
1942
|
+
this.flightSizeDecrease(chunk);
|
|
1943
|
+
return true;
|
|
1944
|
+
}
|
|
1945
|
+
isExpired(chunk) {
|
|
1946
|
+
return chunk.expiry !== undefined && chunk.expiry <= Date.now();
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* An abandoned chunk is never sent or retransmitted again, so its payload is
|
|
1950
|
+
* released; bookSize and the TSN / stream metadata FORWARD-TSN needs stay.
|
|
1951
|
+
*/
|
|
1952
|
+
markAbandoned(chunk) {
|
|
1953
|
+
chunk.abandoned = true;
|
|
1954
|
+
chunk.retransmit = false;
|
|
1955
|
+
chunk.userData = EMPTY_PAYLOAD;
|
|
1956
|
+
}
|
|
1957
|
+
/** Marks every fragment of the message at sentQueue[chunkPos] abandoned. */
|
|
1958
|
+
abandonMessage(chunkPos) {
|
|
1959
|
+
// Abandon the whole message: walk back to its first fragment and forward
|
|
1960
|
+
// to its last fragment (RFC 3758 3.5 A3).
|
|
1522
1961
|
for (let pos = chunkPos; pos >= 0; pos--) {
|
|
1523
1962
|
const oChunk = this.sentQueue.at(pos);
|
|
1524
|
-
oChunk
|
|
1525
|
-
oChunk
|
|
1526
|
-
if (oChunk.flags &
|
|
1963
|
+
this.markAbandoned(oChunk);
|
|
1964
|
+
this.flightSizeDecrease(oChunk);
|
|
1965
|
+
if (oChunk.flags & SCTP_DATA_FIRST_FRAG) {
|
|
1527
1966
|
break;
|
|
1528
1967
|
}
|
|
1529
1968
|
}
|
|
1969
|
+
let lastFragReached = false;
|
|
1530
1970
|
for (let pos = chunkPos; pos < this.sentQueue.length; pos++) {
|
|
1531
1971
|
const oChunk = this.sentQueue.at(pos);
|
|
1532
|
-
oChunk
|
|
1533
|
-
oChunk
|
|
1972
|
+
this.markAbandoned(oChunk);
|
|
1973
|
+
this.flightSizeDecrease(oChunk);
|
|
1534
1974
|
if (oChunk.flags & SCTP_DATA_LAST_FRAG) {
|
|
1975
|
+
lastFragReached = true;
|
|
1535
1976
|
break;
|
|
1536
1977
|
}
|
|
1537
1978
|
}
|
|
1538
|
-
|
|
1979
|
+
// The remaining fragments may still be waiting in outboundQueue (cwnd/rwnd
|
|
1980
|
+
// limited). Sending them would leave the receiver with a headless message,
|
|
1981
|
+
// so move them to sentQueue as abandoned without transmitting; they are then
|
|
1982
|
+
// covered by the FORWARD-TSN like the rest of the message.
|
|
1983
|
+
while (!lastFragReached && this.outboundQueue.length > 0) {
|
|
1984
|
+
const oChunk = this.outboundQueue.shift();
|
|
1985
|
+
this.markAbandoned(oChunk);
|
|
1986
|
+
this.sentQueue.push(oChunk);
|
|
1987
|
+
this.resolveSendWaiters(oChunk);
|
|
1988
|
+
if (oChunk.flags & SCTP_DATA_LAST_FRAG) {
|
|
1989
|
+
lastFragReached = true;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1539
1992
|
}
|
|
1540
1993
|
static getCapabilities() {
|
|
1541
1994
|
return new RTCSctpCapabilities(65536);
|
|
@@ -1546,15 +1999,25 @@ class SCTP {
|
|
|
1546
1999
|
async start(remotePort) {
|
|
1547
2000
|
if (!this.started) {
|
|
1548
2001
|
this.started = true;
|
|
1549
|
-
|
|
2002
|
+
// Keep "connected" when the peer's INIT already established it.
|
|
2003
|
+
if (this.associationState !== const_1.SCTP_STATE.ESTABLISHED) {
|
|
2004
|
+
this.setConnectionState("connecting");
|
|
2005
|
+
}
|
|
1550
2006
|
if (remotePort) {
|
|
1551
2007
|
this.setRemotePort(remotePort);
|
|
1552
2008
|
}
|
|
1553
|
-
|
|
2009
|
+
// The peer's INIT may already have established the association
|
|
2010
|
+
// before start(); a new INIT would reset it.
|
|
2011
|
+
if (!this.isServer && this.associationState === const_1.SCTP_STATE.CLOSED) {
|
|
1554
2012
|
await this.init();
|
|
1555
2013
|
}
|
|
1556
2014
|
}
|
|
1557
2015
|
}
|
|
2016
|
+
/** Waiting for INIT_ACK / COOKIE_ACK of our own INIT. */
|
|
2017
|
+
get isInitiating() {
|
|
2018
|
+
return (this.associationState === const_1.SCTP_STATE.COOKIE_WAIT ||
|
|
2019
|
+
this.associationState === const_1.SCTP_STATE.COOKIE_ECHOED);
|
|
2020
|
+
}
|
|
1558
2021
|
async init() {
|
|
1559
2022
|
const init = new chunk_1.InitChunk();
|
|
1560
2023
|
init.initiateTag = this.localVerificationTag;
|
|
@@ -1564,14 +2027,17 @@ class SCTP {
|
|
|
1564
2027
|
init.initialTsn = this.localTsn;
|
|
1565
2028
|
this.setExtensions(init.params);
|
|
1566
2029
|
log("send init", init);
|
|
2030
|
+
// # start T1 timer and enter COOKIE-WAIT state
|
|
2031
|
+
// Before handing INIT off, so an INIT_ACK that arrives while the send is
|
|
2032
|
+
// still pending is not dropped by the COOKIE_WAIT guard, and a failed
|
|
2033
|
+
// send is packet loss that T1 retransmits (or closes after max retries).
|
|
2034
|
+
this.timer1Start(init);
|
|
2035
|
+
this.setState(const_1.SCTP_STATE.COOKIE_WAIT);
|
|
1567
2036
|
try {
|
|
1568
2037
|
await this.sendChunk(init);
|
|
1569
|
-
// # start T1 timer and enter COOKIE-WAIT state
|
|
1570
|
-
this.timer1Start(init);
|
|
1571
|
-
this.setState(const_1.SCTP_STATE.COOKIE_WAIT);
|
|
1572
2038
|
}
|
|
1573
2039
|
catch (error) {
|
|
1574
|
-
log("send init failed", error
|
|
2040
|
+
log("send init failed; T1 retransmits", error?.message);
|
|
1575
2041
|
}
|
|
1576
2042
|
}
|
|
1577
2043
|
setExtensions(params) {
|
|
@@ -1589,7 +2055,10 @@ class SCTP {
|
|
|
1589
2055
|
if (this.remotePort === undefined) {
|
|
1590
2056
|
throw new Error("invalid remote port");
|
|
1591
2057
|
}
|
|
1592
|
-
const packet = (0, chunk_1.serializePacket)(this.localPort, this.remotePort,
|
|
2058
|
+
const packet = (0, chunk_1.serializePacket)(this.localPort, this.remotePort,
|
|
2059
|
+
// RFC 9260 §8.5.1: INIT is always sent with verification tag 0, also
|
|
2060
|
+
// when an INIT answered before start() taught us the peer's tag.
|
|
2061
|
+
chunk.type === chunk_1.InitChunk.type ? 0 : this.remoteVerificationTag, chunk);
|
|
1593
2062
|
await this.transport.send(packet);
|
|
1594
2063
|
}
|
|
1595
2064
|
setState(state) {
|
|
@@ -1609,10 +2078,13 @@ class SCTP {
|
|
|
1609
2078
|
this.timer3Cancel();
|
|
1610
2079
|
this.timerReconfigCancel();
|
|
1611
2080
|
this.heartbeatCancel();
|
|
2081
|
+
this.outboundExpiryCancel();
|
|
1612
2082
|
if (this.sackTimeout) {
|
|
1613
2083
|
clearTimeout(this.sackTimeout);
|
|
1614
2084
|
this.sackTimeout = undefined;
|
|
1615
2085
|
}
|
|
2086
|
+
// Drop a deferred incoming stream reset and the DATA held for it.
|
|
2087
|
+
this.deferredReset = undefined;
|
|
1616
2088
|
this.setConnectionState("closed");
|
|
1617
2089
|
this.removeAllListeners();
|
|
1618
2090
|
this.releaseSendWaiters();
|
|
@@ -1641,6 +2113,7 @@ class SCTP {
|
|
|
1641
2113
|
clearTimeout(this.timer1Handle);
|
|
1642
2114
|
clearTimeout(this.timer2Handle);
|
|
1643
2115
|
clearTimeout(this.timer3Handle);
|
|
2116
|
+
this.outboundExpiryCancel();
|
|
1644
2117
|
clearTimeout(this.timerReconfigHandle);
|
|
1645
2118
|
clearTimeout(this.timerHeartbeatHandle);
|
|
1646
2119
|
clearTimeout(this.sackTimeout);
|
|
@@ -1716,8 +2189,8 @@ class InboundStream {
|
|
|
1716
2189
|
break;
|
|
1717
2190
|
}
|
|
1718
2191
|
else {
|
|
2192
|
+
// The partial message is broken; this chunk may start the next one.
|
|
1719
2193
|
startPos = undefined;
|
|
1720
|
-
pos++;
|
|
1721
2194
|
continue;
|
|
1722
2195
|
}
|
|
1723
2196
|
}
|
|
@@ -1739,8 +2212,12 @@ class InboundStream {
|
|
|
1739
2212
|
if (ordered && chunk.streamSeqNum === this.streamSequenceNumber) {
|
|
1740
2213
|
this.streamSequenceNumber = (0, common_1.uint16Add)(this.streamSequenceNumber, 1);
|
|
1741
2214
|
}
|
|
2215
|
+
// The next message starts at the removed one's position and need not
|
|
2216
|
+
// be TSN-contiguous with it, so restart the search there.
|
|
1742
2217
|
pos = startPos;
|
|
2218
|
+
startPos = undefined;
|
|
1743
2219
|
yield [chunk.streamId, chunk.protocol, userData];
|
|
2220
|
+
continue;
|
|
1744
2221
|
}
|
|
1745
2222
|
else {
|
|
1746
2223
|
pos++;
|
|
@@ -1748,6 +2225,67 @@ class InboundStream {
|
|
|
1748
2225
|
expectedTsn = tsnPlusOne(expectedTsn);
|
|
1749
2226
|
}
|
|
1750
2227
|
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Applies a FORWARD-TSN entry (RFC 3758 3.6): ordered messages with SSN up to
|
|
2230
|
+
* `ssn` are no longer waited for. Complete ones are returned for delivery in
|
|
2231
|
+
* order, incomplete ones are dropped, and the expected SSN moves past `ssn`
|
|
2232
|
+
* (never backwards, so a stale/duplicated entry is harmless).
|
|
2233
|
+
*/
|
|
2234
|
+
forwardSequenceNumber(ssn) {
|
|
2235
|
+
const messages = [];
|
|
2236
|
+
let prunedSize = 0;
|
|
2237
|
+
let fragments = [];
|
|
2238
|
+
const dropFragments = () => {
|
|
2239
|
+
for (const c of fragments)
|
|
2240
|
+
prunedSize += c.userData.length;
|
|
2241
|
+
fragments = [];
|
|
2242
|
+
};
|
|
2243
|
+
this.reassembly = this.reassembly.filter((chunk) => {
|
|
2244
|
+
if (chunk.flags & SCTP_DATA_UNORDERED ||
|
|
2245
|
+
(0, common_1.uint16Gt)(chunk.streamSeqNum, ssn)) {
|
|
2246
|
+
return true;
|
|
2247
|
+
}
|
|
2248
|
+
const prev = fragments[fragments.length - 1];
|
|
2249
|
+
if (chunk.flags & SCTP_DATA_FIRST_FRAG) {
|
|
2250
|
+
dropFragments();
|
|
2251
|
+
}
|
|
2252
|
+
else if (!prev ||
|
|
2253
|
+
chunk.tsn !== tsnPlusOne(prev.tsn) ||
|
|
2254
|
+
chunk.streamSeqNum !== prev.streamSeqNum) {
|
|
2255
|
+
dropFragments();
|
|
2256
|
+
prunedSize += chunk.userData.length;
|
|
2257
|
+
return false;
|
|
2258
|
+
}
|
|
2259
|
+
fragments.push(chunk);
|
|
2260
|
+
if (chunk.flags & SCTP_DATA_LAST_FRAG) {
|
|
2261
|
+
messages.push([
|
|
2262
|
+
chunk.streamId,
|
|
2263
|
+
chunk.protocol,
|
|
2264
|
+
Buffer.concat(fragments.map((c) => c.userData)),
|
|
2265
|
+
]);
|
|
2266
|
+
fragments = [];
|
|
2267
|
+
}
|
|
2268
|
+
return false;
|
|
2269
|
+
});
|
|
2270
|
+
dropFragments();
|
|
2271
|
+
const nextSsn = (0, common_1.uint16Add)(ssn, 1);
|
|
2272
|
+
if ((0, common_1.uint16Gt)(nextSsn, this.streamSequenceNumber)) {
|
|
2273
|
+
this.streamSequenceNumber = nextSsn;
|
|
2274
|
+
}
|
|
2275
|
+
return { messages, prunedSize };
|
|
2276
|
+
}
|
|
2277
|
+
/** Removes unordered chunks with TSN up to `tsn`. */
|
|
2278
|
+
pruneUnorderedChunks(tsn) {
|
|
2279
|
+
let size = 0;
|
|
2280
|
+
this.reassembly = this.reassembly.filter((chunk) => {
|
|
2281
|
+
if (chunk.flags & SCTP_DATA_UNORDERED && (0, common_1.uint32Gte)(tsn, chunk.tsn)) {
|
|
2282
|
+
size += chunk.userData.length;
|
|
2283
|
+
return false;
|
|
2284
|
+
}
|
|
2285
|
+
return true;
|
|
2286
|
+
});
|
|
2287
|
+
return size;
|
|
2288
|
+
}
|
|
1751
2289
|
pruneChunks(tsn) {
|
|
1752
2290
|
// """
|
|
1753
2291
|
// Prune chunks up to the given TSN.
|
|
@@ -1773,13 +2311,22 @@ class RTCSctpCapabilities {
|
|
|
1773
2311
|
enumerable: true,
|
|
1774
2312
|
configurable: true,
|
|
1775
2313
|
writable: true,
|
|
1776
|
-
value:
|
|
2314
|
+
value: void 0
|
|
1777
2315
|
});
|
|
2316
|
+
this.maxMessageSize = maxMessageSize;
|
|
1778
2317
|
}
|
|
1779
2318
|
}
|
|
1780
2319
|
exports.RTCSctpCapabilities = RTCSctpCapabilities;
|
|
1781
2320
|
function tsnMinusOne(a) {
|
|
1782
|
-
return (a - 1) % SCTP_TSN_MODULO;
|
|
2321
|
+
return (a - 1 + SCTP_TSN_MODULO) % SCTP_TSN_MODULO;
|
|
2322
|
+
}
|
|
2323
|
+
/** Serial-number distance from `base` to `tsn` (RFC 1982), 0..2^32-1. */
|
|
2324
|
+
function tsnDistance(base, tsn) {
|
|
2325
|
+
return (tsn - base + SCTP_TSN_MODULO) % SCTP_TSN_MODULO;
|
|
2326
|
+
}
|
|
2327
|
+
/** Sorts TSNs in serial-number order after `base`, so the order holds across a wrap. */
|
|
2328
|
+
function sortTsns(tsns, base) {
|
|
2329
|
+
return [...tsns].sort((a, b) => tsnDistance(base, a) - tsnDistance(base, b));
|
|
1783
2330
|
}
|
|
1784
2331
|
function tsnPlusOne(a) {
|
|
1785
2332
|
return (a + 1) % SCTP_TSN_MODULO;
|