@@ -9,7 +9,6 @@ package webrtc
99import (
1010 "errors"
1111 "io"
12- "math"
1312 "sync"
1413 "time"
1514
@@ -34,10 +33,6 @@ type SCTPTransport struct {
3433 // so we need a dedicated field
3534 isStarted bool
3635
37- // MaxMessageSize represents the maximum size of data that can be passed to
38- // DataChannel's send() method.
39- maxMessageSize float64
40-
4136 // MaxChannels represents the maximum amount of DataChannel's that can
4237 // be used simultaneously.
4338 maxChannels * uint16
@@ -74,7 +69,6 @@ func (api *API) NewSCTPTransport(dtls *DTLSTransport) *SCTPTransport {
7469 dataChannelIDsUsed : make (map [uint16 ]struct {}),
7570 }
7671
77- res .updateMessageSize ()
7872 res .updateMaxChannels ()
7973
8074 return res
@@ -90,20 +84,30 @@ func (r *SCTPTransport) Transport() *DTLSTransport {
9084
9185// GetCapabilities returns the SCTPCapabilities of the SCTPTransport.
9286func (r * SCTPTransport ) GetCapabilities () SCTPCapabilities {
87+ var maxMessageSize uint32
88+ if a := r .association (); a != nil {
89+ maxMessageSize = a .MaxMessageSize ()
90+ }
91+
9392 return SCTPCapabilities {
94- MaxMessageSize : 0 ,
93+ MaxMessageSize : maxMessageSize ,
9594 }
9695}
9796
9897// Start the SCTPTransport. Since both local and remote parties must mutually
9998// create an SCTPTransport, SCTP SO (Simultaneous Open) is used to establish
10099// a connection over SCTP.
101- func (r * SCTPTransport ) Start (_ SCTPCapabilities ) error {
100+ func (r * SCTPTransport ) Start (capabilities SCTPCapabilities ) error {
102101 if r .isStarted {
103102 return nil
104103 }
105104 r .isStarted = true
106105
106+ maxMessageSize := capabilities .MaxMessageSize
107+ if maxMessageSize == 0 {
108+ maxMessageSize = sctpMaxMessageSizeUnsetValue
109+ }
110+
107111 dtlsTransport := r .Transport ()
108112 if dtlsTransport == nil || dtlsTransport .conn == nil {
109113 return errSCTPTransportDTLS
@@ -115,6 +119,7 @@ func (r *SCTPTransport) Start(_ SCTPCapabilities) error {
115119 LoggerFactory : r .api .settingEngine .LoggerFactory ,
116120 RTOMax : float64 (r .api .settingEngine .sctp .rtoMax ) / float64 (time .Millisecond ),
117121 BlockWrite : r .api .settingEngine .detach .DataChannels && r .api .settingEngine .dataChannelBlockWrite ,
122+ MaxMessageSize : maxMessageSize ,
118123 })
119124 if err != nil {
120125 return err
@@ -344,36 +349,6 @@ func (r *SCTPTransport) onDataChannel(dc *DataChannel) (done chan struct{}) {
344349 return
345350}
346351
347- func (r * SCTPTransport ) updateMessageSize () {
348- r .lock .Lock ()
349- defer r .lock .Unlock ()
350-
351- var remoteMaxMessageSize float64 = 65536 // pion/webrtc#758
352- var canSendSize float64 = 65536 // pion/webrtc#758
353-
354- r .maxMessageSize = r .calcMessageSize (remoteMaxMessageSize , canSendSize )
355- }
356-
357- func (r * SCTPTransport ) calcMessageSize (remoteMaxMessageSize , canSendSize float64 ) float64 {
358- switch {
359- case remoteMaxMessageSize == 0 &&
360- canSendSize == 0 :
361- return math .Inf (1 )
362-
363- case remoteMaxMessageSize == 0 :
364- return canSendSize
365-
366- case canSendSize == 0 :
367- return remoteMaxMessageSize
368-
369- case canSendSize > remoteMaxMessageSize :
370- return remoteMaxMessageSize
371-
372- default :
373- return canSendSize
374- }
375- }
376-
377352func (r * SCTPTransport ) updateMaxChannels () {
378353 val := sctpMaxChannels
379354 r .maxChannels = & val
0 commit comments