SCTP: Treat message size zero as "responder selects"

This also refactors some of the code in peerconnection for
handling SCTP transports to be internal to the webrtc::SctpTransport
class, rather than being in peerconnection.

Bug: webrtc:10358, webrtc:10629
Change-Id: I15ecf95c199f56b08909e5a9311d446a412ed162
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137041
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27960}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index e1cc6ef..065247d 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -5657,35 +5657,24 @@
     auto remote_sctp_description = cricket::GetFirstSctpDataContentDescription(
         remote_description()->description());
     if (local_sctp_description && remote_sctp_description) {
-      int max_message_size =
-          std::min(local_sctp_description->max_message_size(),
-                   remote_sctp_description->max_message_size());
-      bool success = network_thread()->Invoke<bool>(
-          RTC_FROM_HERE,
-          rtc::Bind(&PeerConnection::PushdownSctpParameters_n, this, source,
-                    local_sctp_description->port(),
-                    remote_sctp_description->port(), max_message_size));
-      if (!success) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                             "Failed to push down SCTP parameters.");
+      int max_message_size;
+      // A remote max message size of zero means "any size supported".
+      // We configure the connection with our own max message size.
+      if (remote_sctp_description->max_message_size() == 0) {
+        max_message_size = local_sctp_description->max_message_size();
+      } else {
+        max_message_size =
+            std::min(local_sctp_description->max_message_size(),
+                     remote_sctp_description->max_message_size());
       }
+      sctp_transport_->Start(local_sctp_description->port(),
+                             remote_sctp_description->port(), max_message_size);
     }
   }
 
   return RTCError::OK();
 }
 
-bool PeerConnection::PushdownSctpParameters_n(cricket::ContentSource source,
-                                              int local_sctp_port,
-                                              int remote_sctp_port,
-                                              int max_message_size) {
-  RTC_DCHECK_RUN_ON(network_thread());
-  // Apply the SCTP port (which is hidden inside a DataCodec structure...)
-  // When we support "max-message-size", that would also be pushed down here.
-  return cricket_sctp_transport()->Start(local_sctp_port, remote_sctp_port,
-                                         max_message_size);
-}
-
 RTCError PeerConnection::PushdownTransportDescription(
     cricket::ContentSource source,
     SdpType type) {