From 3213c504a9d61d4382fd965c6d0a3ddc56555613 Mon Sep 17 00:00:00 2001 From: Yutaka Takeda Date: Sat, 23 Apr 2022 13:27:32 -0700 Subject: [PATCH 1/2] Max recv buf size via SettingEngine Relates to pion/sctp#218 --- sctptransport.go | 5 +++-- settingengine.go | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sctptransport.go b/sctptransport.go index 27e02ea65de..a379a96b1e1 100644 --- a/sctptransport.go +++ b/sctptransport.go @@ -103,8 +103,9 @@ func (r *SCTPTransport) Start(remoteCaps SCTPCapabilities) error { } sctpAssociation, err := sctp.Client(sctp.Config{ - NetConn: dtlsTransport.conn, - LoggerFactory: r.api.settingEngine.LoggerFactory, + NetConn: dtlsTransport.conn, + MaxReceiveBufferSize: r.api.settingEngine.sctp.maxReceiveBufferSize, + LoggerFactory: r.api.settingEngine.LoggerFactory, }) if err != nil { return err diff --git a/settingengine.go b/settingengine.go index a2f5ef41882..7cd0bb30881 100644 --- a/settingengine.go +++ b/settingengine.go @@ -54,6 +54,9 @@ type SettingEngine struct { dtls struct { retransmissionInterval time.Duration } + sctp struct { + maxReceiveBufferSize uint32 + } sdpMediaLevelFingerprints bool answeringDTLSRole DTLSRole disableCertificateFingerprintVerification bool @@ -304,3 +307,9 @@ func (e *SettingEngine) SetReceiveMTU(receiveMTU uint) { func (e *SettingEngine) SetDTLSRetransmissionInterval(interval time.Duration) { e.dtls.retransmissionInterval = interval } + +// SetSCTPMaxReceiveBufferSize sets the maximum receive buffer size. +// Leave this 0 for the default maxReceiveBufferSize. +func (e *SettingEngine) SetSCTPMaxReceiveBufferSize(maxReceiveBufferSize uint32) { + e.sctp.maxReceiveBufferSize = maxReceiveBufferSize +} From 1ef4789b7ec4b2af6b2fd7f19fd5864de0c879ce Mon Sep 17 00:00:00 2001 From: Yutaka Takeda Date: Sat, 23 Apr 2022 15:04:41 -0700 Subject: [PATCH 2/2] Added a unit test Relates to pion/sctp#218 --- settingengine_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/settingengine_test.go b/settingengine_test.go index 80817ca34bf..dd661d5e255 100644 --- a/settingengine_test.go +++ b/settingengine_test.go @@ -233,3 +233,12 @@ func TestSetDTLSRetransmissionInterval(t *testing.T) { t.Errorf("Failed to set DTLS retransmission interval") } } + +func TestSetSCTPMaxReceiverBufferSize(t *testing.T) { + s := SettingEngine{} + assert.Equal(t, uint32(0), s.sctp.maxReceiveBufferSize) + + expSize := uint32(4 * 1024 * 1024) + s.SetSCTPMaxReceiveBufferSize(expSize) + assert.Equal(t, expSize, s.sctp.maxReceiveBufferSize) +}