werift 0.14.2-debug2b → 0.14.4

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.
@@ -63,7 +63,6 @@ class SCTP {
63
63
  this.localVerificationTag = (0, src_1.random32)();
64
64
  this.remoteExtensions = [];
65
65
  this.remotePartialReliability = true;
66
- this.remotePort = 5000;
67
66
  this.remoteVerificationTag = 0;
68
67
  // inbound
69
68
  this.advertisedRwnd = 1024 * 1024; // Receiver Window
@@ -97,7 +96,7 @@ class SCTP {
97
96
  this.timer1Failures = 0;
98
97
  this.timer2Failures = 0;
99
98
  this.timerReconfigFailures = 0;
100
- this.send = async (streamId, ppId, userData, expiry = undefined, maxRetransmits = undefined, ordered = true) => {
99
+ this.send = async (streamId, ppId, userData, { expiry, maxRetransmits, ordered, } = { expiry: undefined, maxRetransmits: undefined, ordered: true }) => {
101
100
  const streamSeqNum = ordered ? this.outboundStreamSeq[streamId] || 0 : 0;
102
101
  const fragments = Math.ceil(userData.length / USERDATA_MAX_LENGTH);
103
102
  let pos = 0;
@@ -146,7 +145,11 @@ class SCTP {
146
145
  this.setState(const_1.SCTP_STATE.CLOSED);
147
146
  }
148
147
  else {
149
- setImmediate(() => this.sendChunk(this.timer1Chunk));
148
+ setImmediate(() => {
149
+ this.sendChunk(this.timer1Chunk).catch((err) => {
150
+ log("send timer1 chunk failed", err.message);
151
+ });
152
+ });
150
153
  this.timer1Handle = setTimeout(this.timer1Expired, this.rto * 1000);
151
154
  }
152
155
  };
@@ -157,7 +160,11 @@ class SCTP {
157
160
  this.setState(const_1.SCTP_STATE.CLOSED);
158
161
  }
159
162
  else {
160
- setImmediate(() => this.sendChunk(this.timer2Chunk));
163
+ setImmediate(() => {
164
+ this.sendChunk(this.timer2Chunk).catch((err) => {
165
+ log("send timer2Chunk failed", err.message);
166
+ });
167
+ });
161
168
  this.timer2Handle = setTimeout(this.timer2Expired, this.rto * 1000);
162
169
  }
163
170
  };
@@ -253,18 +260,24 @@ class SCTP {
253
260
  sack.advertisedRwnd = Math.max(0, this.advertisedRwnd);
254
261
  sack.duplicates = [...this.sackDuplicates];
255
262
  sack.gaps = gaps;
256
- await this.sendChunk(sack);
263
+ await this.sendChunk(sack).catch((err) => {
264
+ log("send sack failed", err.message);
265
+ });
257
266
  this.sackDuplicates = [];
258
267
  this.sackNeeded = false;
259
268
  }
260
269
  async receiveChunk(chunk) {
261
270
  switch (chunk.type) {
262
271
  case chunk_1.DataChunk.type:
263
- this.receiveDataChunk(chunk);
272
+ {
273
+ this.receiveDataChunk(chunk);
274
+ }
264
275
  break;
265
276
  case chunk_1.InitChunk.type:
266
- const init = chunk;
267
- if (this.isServer) {
277
+ {
278
+ if (!this.isServer)
279
+ return;
280
+ const init = chunk;
268
281
  log("receive init", init);
269
282
  this.lastReceivedTsn = tsnMinusOne(init.initialTsn);
270
283
  this.reconfigResponseSeq = tsnMinusOne(init.initialTsn);
@@ -288,11 +301,15 @@ class SCTP {
288
301
  ]);
289
302
  ack.params.push([SCTP_STATE_COOKIE, cookie]);
290
303
  log("send initAck", ack);
291
- await this.sendChunk(ack);
304
+ await this.sendChunk(ack).catch((err) => {
305
+ log("send initAck failed", err.message);
306
+ });
292
307
  }
293
308
  break;
294
309
  case chunk_1.InitAckChunk.type:
295
- if (this.associationState === const_1.SCTP_STATE.COOKIE_WAIT) {
310
+ {
311
+ if (this.associationState != const_1.SCTP_STATE.COOKIE_WAIT)
312
+ return;
296
313
  const initAck = chunk;
297
314
  this.timer1Cancel();
298
315
  this.lastReceivedTsn = tsnMinusOne(initAck.initialTsn);
@@ -309,42 +326,58 @@ class SCTP {
309
326
  break;
310
327
  }
311
328
  }
312
- await this.sendChunk(echo);
329
+ await this.sendChunk(echo).catch((err) => {
330
+ log("send echo failed", err.message);
331
+ });
313
332
  this.timer1Start(echo);
314
333
  this.setState(const_1.SCTP_STATE.COOKIE_ECHOED);
315
334
  }
316
335
  break;
317
336
  case chunk_1.SackChunk.type:
318
- await this.receiveSackChunk(chunk);
337
+ {
338
+ await this.receiveSackChunk(chunk);
339
+ }
319
340
  break;
320
341
  case chunk_1.HeartbeatChunk.type:
321
- const ack = new chunk_1.HeartbeatAckChunk();
322
- ack.params = chunk.params;
323
- await this.sendChunk(ack);
342
+ {
343
+ const ack = new chunk_1.HeartbeatAckChunk();
344
+ ack.params = chunk.params;
345
+ await this.sendChunk(ack).catch((err) => {
346
+ log("send heartbeat ack failed", err.message);
347
+ });
348
+ }
324
349
  break;
325
350
  case chunk_1.AbortChunk.type:
326
- this.setState(const_1.SCTP_STATE.CLOSED);
351
+ {
352
+ this.setState(const_1.SCTP_STATE.CLOSED);
353
+ }
327
354
  break;
328
355
  case chunk_1.ShutdownChunk.type:
329
356
  {
330
357
  this.timer2Cancel();
331
358
  this.setState(const_1.SCTP_STATE.SHUTDOWN_RECEIVED);
332
359
  const ack = new chunk_1.ShutdownAckChunk();
333
- await this.sendChunk(ack);
360
+ await this.sendChunk(ack).catch((err) => {
361
+ log("send shutdown ack failed", err.message);
362
+ });
334
363
  this.t2Start(ack);
335
364
  this.setState(const_1.SCTP_STATE.SHUTDOWN_SENT);
336
365
  }
337
366
  break;
338
367
  case chunk_1.ErrorChunk.type:
339
- // 3.3.10. Operation Error (ERROR) (9)
340
- // An Operation Error is not considered fatal in and of itself, but may be
341
- // used with an ABORT chunk to report a fatal condition. It has the
342
- // following parameters:
343
- log("ErrorChunk", chunk.descriptions);
368
+ {
369
+ // 3.3.10. Operation Error (ERROR) (9)
370
+ // An Operation Error is not considered fatal in and of itself, but may be
371
+ // used with an ABORT chunk to report a fatal condition. It has the
372
+ // following parameters:
373
+ log("ErrorChunk", chunk.descriptions);
374
+ }
344
375
  break;
345
376
  case chunk_1.CookieEchoChunk.type:
346
- const data = chunk;
347
- if (this.isServer) {
377
+ {
378
+ if (!this.isServer)
379
+ return;
380
+ const data = chunk;
348
381
  const cookie = data.body;
349
382
  const digest = (0, crypto_1.createHmac)("sha1", this.hmacKey)
350
383
  .update(cookie.slice(0, 4))
@@ -362,29 +395,39 @@ class SCTP {
362
395
  chunk_1.ErrorChunk.CODE.StaleCookieError,
363
396
  Buffer.concat([...Array(8)].map(() => Buffer.from("\x00"))),
364
397
  ]);
365
- await this.sendChunk(error);
398
+ await this.sendChunk(error).catch((err) => {
399
+ log("send errorChunk failed", err.message);
400
+ });
366
401
  return;
367
402
  }
368
403
  const ack = new chunk_1.CookieAckChunk();
369
- await this.sendChunk(ack);
404
+ await this.sendChunk(ack).catch((err) => {
405
+ log("send cookieAck failed", err.message);
406
+ });
370
407
  this.setState(const_1.SCTP_STATE.ESTABLISHED);
371
408
  }
372
409
  break;
373
410
  case chunk_1.CookieAckChunk.type:
374
- if (this.associationState === const_1.SCTP_STATE.COOKIE_ECHOED) {
411
+ {
412
+ if (this.associationState != const_1.SCTP_STATE.COOKIE_ECHOED)
413
+ return;
375
414
  this.timer1Cancel();
376
415
  this.setState(const_1.SCTP_STATE.ESTABLISHED);
377
416
  }
378
417
  break;
379
418
  case chunk_1.ShutdownCompleteChunk.type:
380
- if (this.associationState === const_1.SCTP_STATE.SHUTDOWN_ACK_SENT) {
419
+ {
420
+ if (this.associationState != const_1.SCTP_STATE.SHUTDOWN_ACK_SENT)
421
+ return;
381
422
  this.timer2Cancel();
382
423
  this.setState(const_1.SCTP_STATE.CLOSED);
383
424
  }
384
425
  break;
385
426
  // extensions
386
427
  case chunk_1.ReconfigChunk.type:
387
- if (this.associationState === const_1.SCTP_STATE.ESTABLISHED) {
428
+ {
429
+ if (this.associationState != const_1.SCTP_STATE.ESTABLISHED)
430
+ return;
388
431
  const reconfig = chunk;
389
432
  for (const [type, body] of reconfig.params) {
390
433
  const target = param_1.RECONFIG_PARAM_BY_TYPES[type];
@@ -395,7 +438,9 @@ class SCTP {
395
438
  }
396
439
  break;
397
440
  case chunk_1.ForwardTsnChunk.type:
398
- this.receiveForwardTsnChunk(chunk);
441
+ {
442
+ this.receiveForwardTsnChunk(chunk);
443
+ }
399
444
  break;
400
445
  }
401
446
  }
@@ -655,7 +700,9 @@ class SCTP {
655
700
  // """
656
701
  // # send FORWARD TSN
657
702
  if (this.forwardTsnChunk) {
658
- await this.sendChunk(this.forwardTsnChunk);
703
+ await this.sendChunk(this.forwardTsnChunk).catch((err) => {
704
+ log("send forwardTsn failed", err.message);
705
+ });
659
706
  this.forwardTsnChunk = undefined;
660
707
  if (!this.timer3Handle) {
661
708
  this.timer3Start();
@@ -678,7 +725,9 @@ class SCTP {
678
725
  dataChunk.misses = 0;
679
726
  dataChunk.retransmit = false;
680
727
  dataChunk.sentCount++;
681
- await this.sendChunk(dataChunk);
728
+ await this.sendChunk(dataChunk).catch((err) => {
729
+ log("send data failed", err.message);
730
+ });
682
731
  if (retransmitEarliest) {
683
732
  this.timer3Restart();
684
733
  }
@@ -695,7 +744,9 @@ class SCTP {
695
744
  // # update counters
696
745
  chunk.sentCount++;
697
746
  chunk.sentTime = Date.now() / 1000;
698
- await this.sendChunk(chunk);
747
+ await this.sendChunk(chunk).catch((err) => {
748
+ log("send data outboundQueue failed", err.message);
749
+ });
699
750
  if (!this.timer3Handle) {
700
751
  this.timer3Start();
701
752
  }
@@ -718,7 +769,9 @@ class SCTP {
718
769
  log("sendReconfigParam", param);
719
770
  const chunk = new chunk_1.ReconfigChunk();
720
771
  chunk.params.push([param.type, param.bytes]);
721
- await this.sendChunk(chunk);
772
+ await this.sendChunk(chunk).catch((err) => {
773
+ log("send reconfig failed", err.message);
774
+ });
722
775
  }
723
776
  // https://github.com/pion/sctp/pull/44/files
724
777
  async sendResetRequest(streamId) {
@@ -854,10 +907,13 @@ class SCTP {
854
907
  setRemotePort(port) {
855
908
  this.remotePort = port;
856
909
  }
857
- async start() {
910
+ async start(remotePort) {
858
911
  if (!this.started) {
859
912
  this.started = true;
860
913
  this.setConnectionState("connecting");
914
+ if (remotePort) {
915
+ this.setRemotePort(remotePort);
916
+ }
861
917
  if (!this.isServer) {
862
918
  await this.init();
863
919
  }
@@ -872,10 +928,15 @@ class SCTP {
872
928
  init.initialTsn = this.localTsn;
873
929
  this.setExtensions(init.params);
874
930
  log("send init", init);
875
- await this.sendChunk(init);
876
- // # start T1 timer and enter COOKIE-WAIT state
877
- this.timer1Start(init);
878
- this.setState(const_1.SCTP_STATE.COOKIE_WAIT);
931
+ try {
932
+ await this.sendChunk(init);
933
+ // # start T1 timer and enter COOKIE-WAIT state
934
+ this.timer1Start(init);
935
+ this.setState(const_1.SCTP_STATE.COOKIE_WAIT);
936
+ }
937
+ catch (error) {
938
+ log("send init failed", error.message);
939
+ }
879
940
  }
880
941
  setExtensions(params) {
881
942
  const extensions = [];
@@ -887,11 +948,11 @@ class SCTP {
887
948
  params.push([SCTP_SUPPORTED_CHUNK_EXT, Buffer.from(extensions)]);
888
949
  }
889
950
  async sendChunk(chunk) {
951
+ if (this.state === "closed")
952
+ return;
890
953
  if (this.remotePort === undefined) {
891
954
  throw new Error("invalid remote port");
892
955
  }
893
- if (this.state === "closed")
894
- return;
895
956
  const packet = (0, chunk_1.serializePacket)(this.localPort, this.remotePort, this.remoteVerificationTag, chunk);
896
957
  await this.transport.send(packet);
897
958
  }
@@ -912,6 +973,7 @@ class SCTP {
912
973
  }
913
974
  setConnectionState(state) {
914
975
  this.state = state;
976
+ log("setConnectionState", state);
915
977
  this.stateChanged[state].execute();
916
978
  }
917
979
  async stop() {
@@ -925,7 +987,9 @@ class SCTP {
925
987
  }
926
988
  async abort() {
927
989
  const abort = new chunk_1.AbortChunk();
928
- await this.sendChunk(abort);
990
+ await this.sendChunk(abort).catch((err) => {
991
+ log("send abort failed", err.message);
992
+ });
929
993
  }
930
994
  removeAllListeners() {
931
995
  Object.values(this.stateChanged).forEach((v) => v.allUnsubscribe());