mediasoup 3.20.1 → 3.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/node/lib/DataConsumer.d.ts +2 -3
  2. package/node/lib/DataConsumer.d.ts.map +1 -1
  3. package/node/lib/DataConsumer.js +8 -6
  4. package/node/lib/DataConsumerTypes.d.ts +5 -4
  5. package/node/lib/DataConsumerTypes.d.ts.map +1 -1
  6. package/node/lib/fbs/data-consumer/send-response.d.ts +21 -0
  7. package/node/lib/fbs/data-consumer/send-response.d.ts.map +1 -0
  8. package/node/lib/fbs/data-consumer/send-response.js +91 -0
  9. package/node/lib/fbs/data-consumer.d.ts +1 -0
  10. package/node/lib/fbs/data-consumer.d.ts.map +1 -1
  11. package/node/lib/fbs/data-consumer.js +4 -1
  12. package/node/lib/fbs/response/body.d.ts +7 -5
  13. package/node/lib/fbs/response/body.d.ts.map +1 -1
  14. package/node/lib/fbs/response/body.js +7 -3
  15. package/node/lib/fbs/response/response.d.ts +3 -2
  16. package/node/lib/fbs/response/response.d.ts.map +1 -1
  17. package/node/lib/test/test-DataConsumer.js +6 -0
  18. package/node/lib/test/test-werift-sctp.js +7 -0
  19. package/package.json +4 -4
  20. package/worker/Makefile +5 -1
  21. package/worker/fbs/dataConsumer.fbs +4 -0
  22. package/worker/fbs/response.fbs +1 -0
  23. package/worker/include/RTC/PortManager.hpp +91 -11
  24. package/worker/include/RTC/TcpServer.hpp +3 -2
  25. package/worker/include/RTC/UdpSocket.hpp +3 -2
  26. package/worker/meson.build +1 -0
  27. package/worker/src/RTC/DataConsumer.cpp +12 -2
  28. package/worker/src/RTC/PipeTransport.cpp +5 -4
  29. package/worker/src/RTC/PlainTransport.cpp +9 -8
  30. package/worker/src/RTC/PortManager.cpp +174 -114
  31. package/worker/src/RTC/SCTP/association/Association.cpp +17 -14
  32. package/worker/src/RTC/TcpServer.cpp +4 -4
  33. package/worker/src/RTC/Transport.cpp +33 -10
  34. package/worker/src/RTC/UdpSocket.cpp +4 -4
  35. package/worker/src/RTC/WebRtcServer.cpp +8 -8
  36. package/worker/src/RTC/WebRtcTransport.cpp +9 -8
  37. package/worker/tasks.py +293 -196
  38. package/worker/test/src/RTC/TestNackGenerator.cpp +1 -1
  39. package/worker/test/src/RTC/TestPortManager.cpp +126 -0
  40. package/worker/test/src/RTC/TestTransportTuple.cpp +3 -2
@@ -6,7 +6,8 @@
6
6
  #include "Logger.hpp"
7
7
  #include "MediaSoupErrors.hpp"
8
8
  #include "Utils.hpp"
9
- #include <tuple> // std:make_tuple()
9
+ #include <cstring> // std::memcmp(), std::memset()
10
+ #include <tuple> // std::make_tuple()
10
11
 
11
12
  /* Static methods for UV callbacks. */
12
13
 
@@ -31,9 +32,11 @@ namespace RTC
31
32
  {
32
33
  /* Class variables. */
33
34
 
34
- thread_local ankerl::unordered_dense::map<uint64_t, PortManager::PortRange> PortManager::mapPortRanges;
35
+ thread_local ankerl::unordered_dense::
36
+ map<PortManager::PortRangeKey, PortManager::PortRange, PortManager::PortRangeKeyHash>
37
+ PortManager::mapPortRanges;
35
38
 
36
- /* Class methods. */
39
+ /* PortManager class methods. */
37
40
 
38
41
  uv_handle_t* PortManager::Bind(
39
42
  Protocol protocol, std::string& ip, uint16_t port, RTC::Transport::SocketFlags& flags)
@@ -71,7 +74,8 @@ namespace RTC
71
74
  {
72
75
  case AF_INET:
73
76
  {
74
- err = uv_ip4_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in*>(&bindAddr));
77
+ err = uv_ip4_addr(
78
+ ip.c_str(), 0, reinterpret_cast<struct sockaddr_in*>(std::addressof(bindAddr)));
75
79
 
76
80
  if (err != 0)
77
81
  {
@@ -83,7 +87,8 @@ namespace RTC
83
87
 
84
88
  case AF_INET6:
85
89
  {
86
- err = uv_ip6_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in6*>(&bindAddr));
90
+ err = uv_ip6_addr(
91
+ ip.c_str(), 0, reinterpret_cast<struct sockaddr_in6*>(std::addressof(bindAddr)));
87
92
 
88
93
  if (err != 0)
89
94
  {
@@ -105,14 +110,14 @@ namespace RTC
105
110
  {
106
111
  case AF_INET:
107
112
  {
108
- (reinterpret_cast<struct sockaddr_in*>(&bindAddr))->sin_port = htons(port);
113
+ (reinterpret_cast<struct sockaddr_in*>(std::addressof(bindAddr)))->sin_port = htons(port);
109
114
 
110
115
  break;
111
116
  }
112
117
 
113
118
  case AF_INET6:
114
119
  {
115
- (reinterpret_cast<struct sockaddr_in6*>(&bindAddr))->sin6_port = htons(port);
120
+ (reinterpret_cast<struct sockaddr_in6*>(std::addressof(bindAddr)))->sin6_port = htons(port);
116
121
 
117
122
  break;
118
123
  }
@@ -175,7 +180,7 @@ namespace RTC
175
180
  {
176
181
  err = uv_udp_bind(
177
182
  reinterpret_cast<uv_udp_t*>(uvHandle),
178
- reinterpret_cast<const struct sockaddr*>(&bindAddr),
183
+ reinterpret_cast<const struct sockaddr*>(std::addressof(bindAddr)),
179
184
  bitFlags);
180
185
 
181
186
  if (err != 0)
@@ -198,7 +203,7 @@ namespace RTC
198
203
  {
199
204
  err = uv_tcp_bind(
200
205
  reinterpret_cast<uv_tcp_t*>(uvHandle),
201
- reinterpret_cast<const struct sockaddr*>(&bindAddr),
206
+ reinterpret_cast<const struct sockaddr*>(std::addressof(bindAddr)),
202
207
  bitFlags);
203
208
 
204
209
  if (err != 0)
@@ -250,7 +255,7 @@ namespace RTC
250
255
  uint16_t minPort,
251
256
  uint16_t maxPort,
252
257
  RTC::Transport::SocketFlags& flags,
253
- uint64_t& hash)
258
+ PortRangeKey& key)
254
259
  {
255
260
  MS_TRACE();
256
261
 
@@ -288,7 +293,8 @@ namespace RTC
288
293
  {
289
294
  case AF_INET:
290
295
  {
291
- err = uv_ip4_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in*>(&bindAddr));
296
+ err = uv_ip4_addr(
297
+ ip.c_str(), 0, reinterpret_cast<struct sockaddr_in*>(std::addressof(bindAddr)));
292
298
 
293
299
  if (err != 0)
294
300
  {
@@ -300,7 +306,8 @@ namespace RTC
300
306
 
301
307
  case AF_INET6:
302
308
  {
303
- err = uv_ip6_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in6*>(&bindAddr));
309
+ err = uv_ip6_addr(
310
+ ip.c_str(), 0, reinterpret_cast<struct sockaddr_in6*>(std::addressof(bindAddr)));
304
311
 
305
312
  if (err != 0)
306
313
  {
@@ -317,9 +324,9 @@ namespace RTC
317
324
  }
318
325
  }
319
326
 
320
- hash = GeneratePortRangeHash(protocol, std::addressof(bindAddr), minPort, maxPort);
327
+ key = PortRangeKey(protocol, bindAddr, minPort, maxPort);
321
328
 
322
- auto& portRange = PortManager::GetOrCreatePortRange(hash, minPort, maxPort);
329
+ auto& portRange = PortManager::GetOrCreatePortRange(key, minPort, maxPort);
323
330
  const size_t numPorts = portRange.ports.size();
324
331
  const size_t numAttempts = numPorts;
325
332
  size_t attempt{ 0u };
@@ -385,14 +392,14 @@ namespace RTC
385
392
  {
386
393
  case AF_INET:
387
394
  {
388
- (reinterpret_cast<struct sockaddr_in*>(&bindAddr))->sin_port = htons(port);
395
+ (reinterpret_cast<struct sockaddr_in*>(std::addressof(bindAddr)))->sin_port = htons(port);
389
396
 
390
397
  break;
391
398
  }
392
399
 
393
400
  case AF_INET6:
394
401
  {
395
- (reinterpret_cast<struct sockaddr_in6*>(&bindAddr))->sin6_port = htons(port);
402
+ (reinterpret_cast<struct sockaddr_in6*>(std::addressof(bindAddr)))->sin6_port = htons(port);
396
403
 
397
404
  break;
398
405
  }
@@ -455,7 +462,7 @@ namespace RTC
455
462
  {
456
463
  err = uv_udp_bind(
457
464
  reinterpret_cast<uv_udp_t*>(uvHandle),
458
- reinterpret_cast<const struct sockaddr*>(&bindAddr),
465
+ reinterpret_cast<const struct sockaddr*>(std::addressof(bindAddr)),
459
466
  bitFlags);
460
467
 
461
468
  if (err != 0)
@@ -477,7 +484,7 @@ namespace RTC
477
484
  {
478
485
  err = uv_tcp_bind(
479
486
  reinterpret_cast<uv_tcp_t*>(uvHandle),
480
- reinterpret_cast<const struct sockaddr*>(&bindAddr),
487
+ reinterpret_cast<const struct sockaddr*>(std::addressof(bindAddr)),
481
488
  bitFlags);
482
489
 
483
490
  if (err != 0)
@@ -595,16 +602,19 @@ namespace RTC
595
602
  return uvHandle;
596
603
  }
597
604
 
598
- void PortManager::Unbind(uint64_t hash, uint16_t port)
605
+ void PortManager::Unbind(const PortRangeKey& key, uint16_t port)
599
606
  {
600
607
  MS_TRACE();
601
608
 
602
- auto it = PortManager::mapPortRanges.find(hash);
609
+ auto it = PortManager::mapPortRanges.find(key);
603
610
 
604
611
  // This should not happen.
605
612
  if (it == PortManager::mapPortRanges.end())
606
613
  {
607
- MS_ERROR("hash %" PRIu64 " doesn't exist in the map", hash);
614
+ MS_ERROR(
615
+ "port range key [minPort:%" PRIu16 ", maxPort:%" PRIu16 "] doesn't exist in the map",
616
+ key.minPort,
617
+ key.maxPort);
608
618
 
609
619
  return;
610
620
  }
@@ -633,13 +643,15 @@ namespace RTC
633
643
  {
634
644
  MS_DUMP_CLEAN(indentation, "<PortManager>");
635
645
 
636
- for (auto& kv : PortManager::mapPortRanges)
646
+ for (const auto& kv : PortManager::mapPortRanges)
637
647
  {
638
- auto hash = kv.first;
639
- auto portRange = kv.second;
648
+ const auto& key = kv.first;
649
+ const auto& portRange = kv.second;
650
+ const char* protocolStr = (key.protocol == Protocol::UDP) ? "udp" : "tcp";
640
651
 
641
652
  MS_DUMP_CLEAN(indentation + 1, "<PortRange>");
642
- MS_DUMP_CLEAN(indentation + 1, " hash: %" PRIu64, hash);
653
+ MS_DUMP_CLEAN(indentation + 1, " protocol: %s", protocolStr);
654
+ MS_DUMP_CLEAN(indentation + 1, " family: %d", key.bindAddr.ss_family);
643
655
  MS_DUMP_CLEAN(indentation + 1, " minPort: %" PRIu16, portRange.minPort);
644
656
  MS_DUMP_CLEAN(indentation + 1, " maxPort: %zu", portRange.minPort + portRange.ports.size() - 1);
645
657
  MS_DUMP_CLEAN(indentation + 1, " numUsedPorts: %" PRIu16, portRange.numUsedPorts);
@@ -649,95 +661,14 @@ namespace RTC
649
661
  MS_DUMP_CLEAN(indentation, "</PortManager>");
650
662
  }
651
663
 
652
- /*
653
- * Hash for IPv4.
654
- *
655
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
656
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
657
- * | MIN PORT | MAX PORT |
658
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
659
- * | IP | IP >> 2 |F|P|
660
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
661
- *
662
- * Hash for IPv6.
663
- *
664
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
665
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
666
- * | MIN PORT | MAX PORT |
667
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
668
- * |IP[0] ^ IP[1] ^ IP[2] ^ IP[3] | same >> 2 |F|P|
669
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
670
- */
671
- uint64_t PortManager::GeneratePortRangeHash(
672
- Protocol protocol, sockaddr_storage* bindAddr, uint16_t minPort, uint16_t maxPort)
673
- {
674
- MS_TRACE();
675
-
676
- uint64_t hash{ 0u };
677
-
678
- switch (bindAddr->ss_family)
679
- {
680
- case AF_INET:
681
- {
682
- auto* bindAddrIn = reinterpret_cast<struct sockaddr_in*>(bindAddr);
683
-
684
- // We want it in network order.
685
- const uint64_t address = bindAddrIn->sin_addr.s_addr;
686
-
687
- hash |= static_cast<uint64_t>(minPort) << 48;
688
- hash |= static_cast<uint64_t>(maxPort) << 32;
689
- hash |= (address >> 2) << 2;
690
- hash |= 0x0000; // AF_INET.
691
-
692
- break;
693
- }
694
-
695
- case AF_INET6:
696
- {
697
- auto* bindAddrIn6 = reinterpret_cast<struct sockaddr_in6*>(bindAddr);
698
- auto* a = reinterpret_cast<uint32_t*>(std::addressof(bindAddrIn6->sin6_addr));
699
-
700
- const auto address = a[0] ^ a[1] ^ a[2] ^ a[3];
701
-
702
- hash |= static_cast<uint64_t>(minPort) << 48;
703
- hash |= static_cast<uint64_t>(maxPort) << 32;
704
- hash |= static_cast<uint64_t>(address) << 16;
705
- hash |= (static_cast<uint64_t>(address) >> 2) << 2;
706
- hash |= 0x0002; // AF_INET6.
707
-
708
- break;
709
- }
710
-
711
- // This cannot happen.
712
- default:
713
- {
714
- MS_THROW_ERROR("unknown IP family");
715
- }
716
- }
717
-
718
- // Override least significant bit with protocol information:
719
- // - If UDP, start with 0.
720
- // - If TCP, start with 1.
721
- if (protocol == Protocol::UDP)
722
- {
723
- hash |= 0x0000;
724
- }
725
- else
726
- {
727
- hash |= 0x0001;
728
- }
729
-
730
- return hash;
731
- }
732
-
733
664
  PortManager::PortRange& PortManager::GetOrCreatePortRange(
734
- uint64_t hash, uint16_t minPort, uint16_t maxPort)
665
+ const PortRangeKey& key, uint16_t minPort, uint16_t maxPort)
735
666
  {
736
667
  MS_TRACE();
737
668
 
738
- auto it = PortManager::mapPortRanges.find(hash);
669
+ const auto it = PortManager::mapPortRanges.find(key);
739
670
 
740
- // If the hash is already handled, return its port range.
671
+ // If the key is already handled, return its port range.
741
672
  if (it != PortManager::mapPortRanges.end())
742
673
  {
743
674
  auto& portRange = it->second;
@@ -747,10 +678,10 @@ namespace RTC
747
678
 
748
679
  const uint16_t numPorts = maxPort - minPort + 1;
749
680
 
750
- // Emplace a new vector filled with numPorts false values, meaning that
681
+ // Emplace a new vector filled with `numPorts` false values, meaning that
751
682
  // all ports are available.
752
- auto pair = PortManager::mapPortRanges.emplace(
753
- std::piecewise_construct, std::make_tuple(hash), std::make_tuple(numPorts, minPort));
683
+ const auto pair = PortManager::mapPortRanges.emplace(
684
+ std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(numPorts, minPort));
754
685
 
755
686
  // pair.first is an iterator to the inserted value.
756
687
  auto& portRange = pair.first->second;
@@ -764,7 +695,7 @@ namespace RTC
764
695
 
765
696
  uint8_t bitFlags{ 0b00000000 };
766
697
 
767
- // Ignore ipv6Only in IPv4, otherwise libuv will throw.
698
+ // Ignore `ipv6Only` in IPv4, otherwise libuv will throw.
768
699
  if (flags.ipv6Only && family == AF_INET6)
769
700
  {
770
701
  switch (protocol)
@@ -785,7 +716,7 @@ namespace RTC
785
716
  }
786
717
  }
787
718
 
788
- // Ignore udpReusePort in TCP, otherwise libuv will throw.
719
+ // Ignore `udpReusePort` in TCP, otherwise libuv will throw.
789
720
  if (flags.udpReusePort && protocol == Protocol::UDP)
790
721
  {
791
722
  bitFlags |= UV_UDP_REUSEADDR;
@@ -793,4 +724,133 @@ namespace RTC
793
724
 
794
725
  return bitFlags;
795
726
  }
727
+
728
+ /* PortRangeKey instance methods. */
729
+
730
+ PortManager::PortRangeKey::PortRangeKey(
731
+ Protocol protocol, const sockaddr_storage& bindAddr, uint16_t minPort, uint16_t maxPort)
732
+ : protocol(protocol), bindAddr(bindAddr), minPort(minPort), maxPort(maxPort)
733
+ {
734
+ MS_TRACE();
735
+
736
+ // `sockaddr_storage` is padded; the unused tail bytes are caller-controlled.
737
+ // `operator==` inspects only the meaningful address bytes (`sin_addr` /
738
+ // `sin6_addr`) so padding does not affect equality, and the hash function
739
+ // hashes the same exact fields, so two structurally-equal keys always
740
+ // produce the same hash regardless of how the caller zero-initialized.
741
+ }
742
+
743
+ bool PortManager::PortRangeKey::operator==(const PortRangeKey& other) const noexcept
744
+ {
745
+ MS_TRACE();
746
+
747
+ if (this->protocol != other.protocol)
748
+ {
749
+ return false;
750
+ }
751
+ else if (this->minPort != other.minPort)
752
+ {
753
+ return false;
754
+ }
755
+ else if (this->maxPort != other.maxPort)
756
+ {
757
+ return false;
758
+ }
759
+ else if (this->bindAddr.ss_family != other.bindAddr.ss_family)
760
+ {
761
+ return false;
762
+ }
763
+
764
+ switch (this->bindAddr.ss_family)
765
+ {
766
+ case AF_INET:
767
+ {
768
+ const auto* a = reinterpret_cast<const sockaddr_in*>(std::addressof(this->bindAddr));
769
+ const auto* b = reinterpret_cast<const sockaddr_in*>(std::addressof(other.bindAddr));
770
+
771
+ return a->sin_addr.s_addr == b->sin_addr.s_addr;
772
+ }
773
+
774
+ case AF_INET6:
775
+ {
776
+ const auto* a = reinterpret_cast<const sockaddr_in6*>(std::addressof(this->bindAddr));
777
+ const auto* b = reinterpret_cast<const sockaddr_in6*>(std::addressof(other.bindAddr));
778
+
779
+ return std::memcmp(
780
+ std::addressof(a->sin6_addr), std::addressof(b->sin6_addr), sizeof(in6_addr)) == 0;
781
+ }
782
+
783
+ default:
784
+ {
785
+ // Unknown family; treat as not equal to avoid accidental merge.
786
+ return false;
787
+ }
788
+ }
789
+ }
790
+
791
+ /* PortRangeKeyHash instance methods. */
792
+
793
+ size_t PortManager::PortRangeKeyHash::operator()(const PortRangeKey& key) const noexcept
794
+ {
795
+ MS_TRACE();
796
+
797
+ const auto protocolBits = static_cast<uint8_t>(key.protocol);
798
+ const auto familyBits = static_cast<uint16_t>(key.bindAddr.ss_family);
799
+
800
+ auto hashCombine = [](size_t& seed, size_t value)
801
+ {
802
+ seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
803
+ };
804
+
805
+ size_t seed = 0;
806
+
807
+ switch (key.bindAddr.ss_family)
808
+ {
809
+ case AF_INET:
810
+ {
811
+ const auto* in = reinterpret_cast<const sockaddr_in*>(std::addressof(key.bindAddr));
812
+
813
+ hashCombine(seed, ankerl::unordered_dense::hash<uint8_t>{}(protocolBits));
814
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(familyBits));
815
+ hashCombine(seed, ankerl::unordered_dense::hash<uint32_t>{}(in->sin_addr.s_addr));
816
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(key.minPort));
817
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(key.maxPort));
818
+
819
+ break;
820
+ }
821
+
822
+ case AF_INET6:
823
+ {
824
+ const auto* in6 = reinterpret_cast<const sockaddr_in6*>(std::addressof(key.bindAddr));
825
+ const auto* addr = in6->sin6_addr.s6_addr;
826
+
827
+ uint64_t hi;
828
+ uint64_t lo;
829
+
830
+ std::memcpy(std::addressof(hi), addr, sizeof(uint64_t));
831
+ std::memcpy(std::addressof(lo), addr + sizeof(uint64_t), sizeof(uint64_t));
832
+
833
+ hashCombine(seed, ankerl::unordered_dense::hash<uint8_t>{}(protocolBits));
834
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(familyBits));
835
+ hashCombine(seed, ankerl::unordered_dense::hash<uint64_t>{}(hi));
836
+ hashCombine(seed, ankerl::unordered_dense::hash<uint64_t>{}(lo));
837
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(key.minPort));
838
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(key.maxPort));
839
+
840
+ break;
841
+ }
842
+
843
+ default:
844
+ {
845
+ hashCombine(seed, ankerl::unordered_dense::hash<uint8_t>{}(protocolBits));
846
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(familyBits));
847
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(key.minPort));
848
+ hashCombine(seed, ankerl::unordered_dense::hash<uint16_t>{}(key.maxPort));
849
+
850
+ break;
851
+ }
852
+ }
853
+
854
+ return seed;
855
+ }
796
856
  } // namespace RTC
@@ -1104,11 +1104,12 @@ namespace RTC
1104
1104
  {
1105
1105
  MS_WARN_TAG(
1106
1106
  sctp,
1107
- "ABORT chunk verification tag %" PRIu32 " is wrong, packet discarded",
1107
+ "receievd ABORT chunk has invalid verification tag %" PRIu32 ", packet discarded",
1108
1108
  receivedPacket->GetVerificationTag());
1109
1109
 
1110
1110
  this->associationListenerDeferrer.OnAssociationError(
1111
- Types::ErrorKind::PARSE_FAILED, "packet with ABORT chunk has invalid verification tag");
1111
+ Types::ErrorKind::PARSE_FAILED,
1112
+ "received packet with ABORT chunk has invalid verification tag");
1112
1113
 
1113
1114
  return false;
1114
1115
  }
@@ -1124,13 +1125,14 @@ namespace RTC
1124
1125
  {
1125
1126
  MS_WARN_TAG(
1126
1127
  sctp,
1127
- "INIT-ACK chunk verification tag %" PRIu32 " (should be %" PRIu32 ")",
1128
+ "received INIT-ACK chunk has invalid verification tag %" PRIu32 " (should be %" PRIu32
1129
+ "), packet discarded",
1128
1130
  receivedPacket->GetVerificationTag(),
1129
1131
  this->preTcb.localVerificationTag);
1130
1132
 
1131
1133
  this->associationListenerDeferrer.OnAssociationError(
1132
1134
  Types::ErrorKind::PARSE_FAILED,
1133
- "packet with INIT-ACK chunk has invalid verification tag");
1135
+ "received packet with INIT-ACK chunk has invalid verification tag");
1134
1136
 
1135
1137
  return false;
1136
1138
  }
@@ -1173,12 +1175,13 @@ namespace RTC
1173
1175
  {
1174
1176
  MS_WARN_TAG(
1175
1177
  sctp,
1176
- "SHUTDOWN-COMPLETE chunk verification tag %" PRIu32 " is wrong, packet discarded",
1178
+ "received SHUTDOWN-COMPLETE chunk has invalid verification tag %" PRIu32
1179
+ ", packet discarded",
1177
1180
  receivedPacket->GetVerificationTag());
1178
1181
 
1179
1182
  this->associationListenerDeferrer.OnAssociationError(
1180
1183
  Types::ErrorKind::PARSE_FAILED,
1181
- "packet with SHUTDOWN-COMPLETE chunk has invalid verification tag");
1184
+ "received packet with SHUTDOWN-COMPLETE chunk has invalid verification tag");
1182
1185
 
1183
1186
  return false;
1184
1187
  }
@@ -1200,7 +1203,8 @@ namespace RTC
1200
1203
  {
1201
1204
  MS_WARN_TAG(
1202
1205
  sctp,
1203
- "invalid verification tag %" PRIu32 " (should be %" PRIu32 ")",
1206
+ "received packet has invalid verification tag %" PRIu32 " (should be %" PRIu32
1207
+ "), packet discarded",
1204
1208
  receivedPacket->GetVerificationTag(),
1205
1209
  localVerificationTag);
1206
1210
 
@@ -1369,7 +1373,7 @@ namespace RTC
1369
1373
  // be 0, the receiver MUST silently discard the packet."
1370
1374
  if (receivedInitChunk->GetInitiateTag() == 0)
1371
1375
  {
1372
- MS_WARN_TAG(sctp, "invalid value 0 in Initiate Tagin received INIT chunk, discarded");
1376
+ MS_WARN_TAG(sctp, "invalid value 0 in Initiate Tag in received INIT chunk, packet discarded");
1373
1377
 
1374
1378
  return;
1375
1379
  }
@@ -1388,7 +1392,7 @@ namespace RTC
1388
1392
  {
1389
1393
  MS_WARN_TAG(
1390
1394
  sctp,
1391
- "invalid number of outbound streams or Number of inbound streams in received INIT chunk, aborting association");
1395
+ "invalid number of outbound streams or number of inbound streams in received INIT chunk, aborting association");
1392
1396
 
1393
1397
  auto packet = CreatePacketWithVerificationTag(0);
1394
1398
  auto* abortAssociationChunk = packet->BuildChunkInPlace<AbortAssociationChunk>();
@@ -1557,7 +1561,7 @@ namespace RTC
1557
1561
  // INIT ACK chunk."
1558
1562
  if (this->state != State::COOKIE_WAIT)
1559
1563
  {
1560
- MS_DEBUG_TAG(sctp, "ignoring received INIT-ACK chunk when not in COOKIE_WAIT state");
1564
+ MS_DEBUG_TAG(sctp, "ignoring INIT-ACK chunk when not in COOKIE_WAIT state");
1561
1565
 
1562
1566
  return;
1563
1567
  }
@@ -1567,8 +1571,7 @@ namespace RTC
1567
1571
 
1568
1572
  if (!stateCookieParameter || !stateCookieParameter->GetCookie())
1569
1573
  {
1570
- MS_WARN_TAG(
1571
- sctp, "ignoring received INIT-ACK chunk without StateCookieParameter or without cookie");
1574
+ MS_WARN_TAG(sctp, "ignoring INIT-ACK chunk without StateCookieParameter or without cookie");
1572
1575
 
1573
1576
  auto packet = CreatePacketWithVerificationTag(this->preTcb.localVerificationTag);
1574
1577
  auto* abortAssociationChunk = packet->BuildChunkInPlace<AbortAssociationChunk>();
@@ -1643,10 +1646,10 @@ namespace RTC
1643
1646
 
1644
1647
  if (!receivedCookieEchoChunk->HasCookie())
1645
1648
  {
1646
- MS_WARN_TAG(sctp, "ignoring received COOKIE-ECHO chunk without cookie");
1649
+ MS_WARN_TAG(sctp, "ignoring invalid COOKIE-ECHO chunk without cookie");
1647
1650
 
1648
1651
  this->associationListenerDeferrer.OnAssociationError(
1649
- Types::ErrorKind::PARSE_FAILED, "received COOKIE-ECHO chunk without cookie");
1652
+ Types::ErrorKind::PARSE_FAILED, "received COOKIE-ECHO chunk has no cookie");
1650
1653
 
1651
1654
  return;
1652
1655
  }
@@ -36,16 +36,16 @@ namespace RTC
36
36
  uint16_t minPort,
37
37
  uint16_t maxPort,
38
38
  RTC::Transport::SocketFlags& flags,
39
- uint64_t& portRangeHash)
39
+ RTC::PortManager::PortRangeKey& portRangeKey)
40
40
  : // This may throw.
41
41
  ::TcpServerHandle::TcpServerHandle(
42
- RTC::PortManager::BindTcp(ip, minPort, maxPort, flags, portRangeHash)),
42
+ RTC::PortManager::BindTcp(ip, minPort, maxPort, flags, portRangeKey)),
43
43
  listener(listener),
44
44
  connListener(connListener)
45
45
  {
46
46
  MS_TRACE();
47
47
 
48
- this->portRangeHash = portRangeHash;
48
+ this->portRangeKey = portRangeKey;
49
49
  }
50
50
 
51
51
  TcpServer::~TcpServer()
@@ -54,7 +54,7 @@ namespace RTC
54
54
 
55
55
  if (!this->fixedPort)
56
56
  {
57
- RTC::PortManager::Unbind(this->portRangeHash, this->localPort);
57
+ RTC::PortManager::Unbind(this->portRangeKey, this->localPort);
58
58
  }
59
59
  }
60
60
 
@@ -3058,13 +3058,26 @@ namespace RTC
3058
3058
 
3059
3059
  const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3060
3060
 
3061
- MS_WARN_TAG(
3062
- sctp,
3063
- "SCTP association failed [errorKind:%.*s, message:%.*s]",
3064
- static_cast<int>(errorKindStringView.size()),
3065
- errorKindStringView.data(),
3066
- static_cast<int>(errorMessage.size()),
3067
- errorMessage.data());
3061
+ if (errorKind == RTC::SCTP::Types::ErrorKind::SUCCESS || errorKind == RTC::SCTP::Types::ErrorKind::PEER_REPORTED)
3062
+ {
3063
+ MS_DEBUG_TAG(
3064
+ sctp,
3065
+ "SCTP association failed [errorKind:%.*s, message:%.*s]",
3066
+ static_cast<int>(errorKindStringView.size()),
3067
+ errorKindStringView.data(),
3068
+ static_cast<int>(errorMessage.size()),
3069
+ errorMessage.data());
3070
+ }
3071
+ else
3072
+ {
3073
+ MS_WARN_TAG(
3074
+ sctp,
3075
+ "SCTP association failed [errorKind:%.*s, message:%.*s]",
3076
+ static_cast<int>(errorKindStringView.size()),
3077
+ errorKindStringView.data(),
3078
+ static_cast<int>(errorMessage.size()),
3079
+ errorMessage.data());
3080
+ }
3068
3081
 
3069
3082
  // Tell all DataConsumers.
3070
3083
  for (auto& kv : this->mapDataConsumers)
@@ -3093,10 +3106,20 @@ namespace RTC
3093
3106
  {
3094
3107
  MS_TRACE();
3095
3108
 
3096
- if (errorKind != RTC::SCTP::Types::ErrorKind::SUCCESS)
3097
- {
3098
- const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3109
+ const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3099
3110
 
3111
+ if (errorKind == RTC::SCTP::Types::ErrorKind::SUCCESS || errorKind == RTC::SCTP::Types::ErrorKind::PEER_REPORTED)
3112
+ {
3113
+ MS_DEBUG_TAG(
3114
+ sctp,
3115
+ "SCTP association closed [errorKind:%.*s, message:%.*s]",
3116
+ static_cast<int>(errorKindStringView.size()),
3117
+ errorKindStringView.data(),
3118
+ static_cast<int>(errorMessage.size()),
3119
+ errorMessage.data());
3120
+ }
3121
+ else
3122
+ {
3100
3123
  MS_WARN_TAG(
3101
3124
  sctp,
3102
3125
  "SCTP association closed [errorKind:%.*s, message:%.*s]",
@@ -26,15 +26,15 @@ namespace RTC
26
26
  uint16_t minPort,
27
27
  uint16_t maxPort,
28
28
  RTC::Transport::SocketFlags& flags,
29
- uint64_t& portRangeHash)
29
+ RTC::PortManager::PortRangeKey& portRangeKey)
30
30
  : // This may throw.
31
31
  ::UdpSocketHandle::UdpSocketHandle(
32
- RTC::PortManager::BindUdp(ip, minPort, maxPort, flags, portRangeHash)),
32
+ RTC::PortManager::BindUdp(ip, minPort, maxPort, flags, portRangeKey)),
33
33
  listener(listener)
34
34
  {
35
35
  MS_TRACE();
36
36
 
37
- this->portRangeHash = portRangeHash;
37
+ this->portRangeKey = portRangeKey;
38
38
  }
39
39
 
40
40
  UdpSocket::~UdpSocket()
@@ -43,7 +43,7 @@ namespace RTC
43
43
 
44
44
  if (!this->fixedPort)
45
45
  {
46
- RTC::PortManager::Unbind(this->portRangeHash, this->localPort);
46
+ RTC::PortManager::Unbind(this->portRangeKey, this->localPort);
47
47
  }
48
48
  }
49
49