Commit Graph

70 Commits

Author SHA1 Message Date
Eric Daniels
78c8a2e07c Add PeerConnection.GracefulClose 2024-08-06 09:51:54 -04:00
Sean DuBois
e17ce04589 Revert 7c8bfbd44a and add test
Don't block Close on spawned goroutines
2024-07-15 11:26:21 -04:00
Eric Daniels
7c8bfbd44a Make pc.Close wait on spawned goroutines to close 2024-07-01 20:54:27 -04:00
knowmost
a97c420d0c Fix typos in multiple comments 2024-04-27 23:27:55 -04:00
cnderrauber
d851a44e18 Replace pool with bytes in readLoop
Replace pool with bytes in readLoop
2024-04-24 17:02:24 +08:00
sukun
835ac3b08e Drop reference to detached datachannels
This allows users of detached datachannels to garbage collect
resources associated with the datachannel and the sctp stream.
There is no functional change here.
2024-03-24 22:21:35 -04:00
sukun
37c7e3c551 Fix DataChannel.handleOpen
Take copy of bufferedAmountLowThreshold and onBufferedAmountLow.
This allows us to this later without holding the lock.
2023-09-23 23:33:17 -04:00
WofWca
66f0c402c1 Docs: correct 'OnBufferedAmountLow' condition
This is in line with
* the docs for 'BufferedAmountLowThreshold' ("When the bufferedAmount
decreases from above this threshold to equal or below it")

* The actual code in 'pion/sctp':
d6446e3b0d/stream.go (L422)

* The Web WebRTC spec:
https://w3c.github.io/webrtc-pc/#event-datachannel-bufferedamountlow
2023-09-11 19:06:22 -04:00
Sean DuBois
dc4b591c4d Start pion/webrtc/v4
60eea43 is a breaking change
2023-09-05 11:48:14 -04:00
Steffen Vogel
683fc837d0 Make repo REUSE compliant 2023-05-05 11:58:49 -04:00
Jerry Tao
16fea9ee04 Set DataChannel SCTPTransport before OnDataChannel
ORTC API would return a nil SCTPTransport for DataChannels returned via
Callback
2023-04-24 00:51:50 -04:00
Yutaka Takeda
cf60891524 Fix ignored calls during OnDataChannel
Set cached values passed by SetBufferedAmountLowThreshold and
OnBufferedAmountLow correctly when the underlying datachannel become
open
2023-03-26 23:32:54 -04:00
treyhakanson
657dab7b97 Adding OnDial handler for datachannels
Adds an `OnDial` handler to be fired once the dialing side has sent
the DCEP OPEN message over the data channel.
2023-02-01 22:03:28 -08:00
Pion
c1467e4871 Update CI configs to v0.7.2
Update lint scripts and CI configs.
2022-04-27 23:00:19 -04:00
Sean DuBois
157220e800 Run gofmt to add new build constraints
Also remove some 1.13 specific WASM code
2022-01-17 22:36:01 -05:00
David Zhao
5f6baf7325 Fixed locking order in SRTP and DataChannel
Two separate potential deadlocks

1. typically the locking order is SRTP first, then DataChannel.
   However, when data channel is opened, it's locking srtp when
   generating an ID.
   It also would return without unlocking when an error is encountered
2. recursive RLock could be potentially problematic. MediaEngine
   contained a section doing so.
2021-11-11 13:06:19 -08:00
Eric Daniels
5dc7245bee Fire DataChannel.onOpen when already negotiated
Fix regression from 0180ee. Before Datachannels would always fire
OnOpen. Now they only fire when DCEP ACK is received. This caused
OnOpen to not be fired for negotiated channels. This re-enables
the previous behavior of firing OnOpen for negotiated channels.
2021-11-01 12:23:37 -04:00
Benny Daon
0180ee3805 Use OnOpen handler for DataChannels
Using an improvment of pion/datachannel, the channel opener can now
set an event to be called when the DATA_CHANNEL_ACK message is recieved

Resolves #1063
Relates to pion/datachannel#81
2021-10-28 11:59:51 -04:00
Will Forcey
5d0ea98f08 Improve DataChannel.Ordered documentation
Explain what true/false values represent
2021-10-10 21:23:58 -04:00
Markus Tzoe
338dfa81f1 SCTPTransport: add association()
use assocation() instead of accessing private struct member from
outside
2021-04-06 20:54:46 -07:00
Markus Tzoe
2f77a28dca Fixes DataChannel panic on sctptransport race
DataChannel.open would panic during which if PeerConnection is closed,
stopping underlying sctpTransport which sets association to nil;

And ensureSCTP() method doesn't guarantee sctpTransport's availability
out of it's own scope.
2021-04-05 22:06:24 -07:00
Bo Shi
32c082f6ff Avoid blocking resource release by client code
The change in #1520 unnecessarily waits for a client-provided callback
to complete before release resources that are no longer necessary.
Won't have any impact in microbenchmarks that have no-op callbacks.
Release as early as possible.
2020-11-17 11:23:18 -08:00
Sean DuBois
49ddb9dab8 Make DataChannel.ReadyState atomic
Fix deadlock, see trace in issue

Resolves #1531
2020-11-16 13:49:25 -08:00
Bo Shi
159ba5aca3 Reduce memory allocated in DataChannel.readLoop
See https://github.com/pion/webrtc/issues/1516

This patch preserves the semantics of the OnMessage handler and is
more safe but less efficient than the patch first described in #1516.

$ git checkout origin/master datachannel.go && \
  go test -bench=. -run=XXX -benchmem -count=10 > original.txt
$ git checkout datachannel.go && git apply pool.patch && \
  go test -bench=. -run=XXX -benchmem -count=10 > option1.txt

$ benchstat original.txt option1.txt
name                 old time/op    new time/op    delta
DSend2-8     20.3µs ±51%     3.7µs ± 6%   -81.74%  (p=0.000 n=10+10)
DSend4-8     23.5µs ±34%     3.6µs ± 8%   -84.80%  (p=0.000 n=10+8)
DSend8-8     18.9µs ±35%     5.8µs ±68%   -69.45%  (p=0.000 n=9+10)
DSend16-8    16.8µs ±30%    10.0µs ±24%   -40.77%  (p=0.000 n=10+10)
DSend32-8    710ms ±100%       0ms ±81%  -100.00%  (p=0.035 n=10+9)

name                 old alloc/op   new alloc/op   delta
DSend2-8     15.3kB ±89%     1.4kB ± 0%   -90.59%  (p=0.000 n=9+10)
DSend4-8     41.7kB ±63%     1.4kB ± 1%   -96.58%  (p=0.000 n=10+10)
DSend8-8     45.0kB ±33%     1.4kB ± 2%   -96.83%  (p=0.000 n=9+10)
DSend16-8    34.0kB ±69%     1.4kB ± 1%   -95.77%  (p=0.000 n=10+10)
DSend32-8   37.4MB ±388%     0.0MB ± 4%  -100.00%  (p=0.000 n=10+7)

name                 old allocs/op  new allocs/op  delta
DSend2-8       15.8 ±46%      38.6 ± 2%  +144.30%  (p=0.000 n=10+10)
DSend4-8       27.1 ±48%      38.0 ± 0%   +40.22%  (p=0.000 n=10+9)
DSend8-8       29.3 ±16%      38.0 ± 0%   +29.55%  (p=0.000 n=9+8)
DSend16-8      23.6 ±41%      37.0 ± 0%   +56.78%  (p=0.000 n=10+9)
DSend32-8    19.3k ±100%      0.0k ± 0%      ~     (p=0.178 n=10+7)
2020-11-14 14:39:22 -08:00
Sean DuBois
804a12fed3 Update CI configs to v0.4.7
Update lint scripts and CI configs.
2020-09-30 09:06:34 -07:00
obasajujoshua31
78cda933e3 Fix issue 1211
return io.ErrClosedPipe instead of default error coming from ensureOpened

wrote test for attempting to send when close
2020-09-14 13:51:37 -04:00
soolaugust
6f6de25b24 Modify all hdlr to handler for better reading
change hdlr -> handler, Hdlr -> Handler for better reading.
Since this is first commit, add myself to contributors
2020-08-17 22:04:29 -07:00
Sam Lancia
87e23ced10 Don't set state open before datachannel valid
Previously it was possible for datachannel writers to see
"DataChannelStateOpen" without "dataChannel" non-nil and
crash
2020-07-17 10:41:24 -07:00
Sean DuBois
89d7de1787 Start /v3
See #9 for the features we have planned, and the breaking changes that
may occur.
2020-06-25 09:45:27 -07:00
Norman Rasmussen
80c9ef9a59 Fix handling of Empty DataChannel messages
Requires: github.com/pion/datachannel v1.4.17
2020-05-13 10:07:48 -07:00
Atsushi Watanabe
58338965b2 Fix DataChannel open race
Concurrent call of generateDataChannelID caused data race.
2020-03-28 15:15:21 -07:00
Atsushi Watanabe
9fca58f510 Reduce blocking in datachannel handler
OnOpen handler is sometimes called with a huge delay in
TestDataChannel_Open and causes handler_should_be_called_once
failure.
This commit minimizes mutex lock scope around handler registration
and removes redundant mutex.

Also, add sleep before closing PeerConnections in
TestDataChannel_Open to ensure all messages are processed.
2019-12-15 02:13:29 -08:00
Sean DuBois
36a5685154 Fix race in checkDetachAfterOpen
checkDetachAfterOpen incorrectly accesses detachCalled
without holding the lock

Relates to #838
2019-12-10 16:55:18 -08:00
Patrick Lange
aa582df55e Add error when forgetting to Detach datachannel
Throw error after OnOpen if Detach has not been called but
DetachDataChannels is used.

Resolves #838
2019-12-10 01:18:16 -08:00
Hugo Arregui
e4d636da91 Check for dc.id in stats
Recent changes allow a dc to have a nil id before it's actually open,
but stats used to require the id.
2019-11-29 10:35:01 -08:00
Sean DuBois
bba6460597 Allow user to Close DataChannel before signaling
Match W3C WebRTC and allow a DataChannel to close even before
signaling happens. When SCTPTransport opens make sure
to check the readyState first.
2019-11-25 17:18:47 -08:00
Sean DuBois
1c32bc9a46 Properly set DataChannel readyState on Close
DataChannel readyState should be set to Closed on PeerConnection
shutdown. If not properly set it would attempt to interact with
state that doesn't exist after the PeerConnection has been Closed.

Setting the readyState is also clearly defined in the W3C webrtc-pc

Resolves #915
2019-11-22 18:06:43 -08:00
Sean DuBois
721b342e2e Properly generate DataChannel streamId
Before we computed DataChannel IDs before signaling, this
is incorrect because IDs must take into account if we are
running an DTLS Client or Server.

This updates the DataChannel ID generation code to take this
into account before generating a streamId.

Resolves #908
2019-11-14 10:51:05 -08:00
Vicken Simonian
5f25df2209 Various spell fixes
For error types, vars, docs and comments
2019-10-17 23:31:21 -07:00
Sean DuBois
92867d3de6 Support negotiated DataChannels in Go
Relates to #748
2019-09-28 22:34:57 -07:00
Sean DuBois
d692ddfa54 Support DataChannel protocol in Go
Relates to #748
2019-09-27 16:19:49 -07:00
Sean DuBois
d54b494292 Remove RTCDataChannel priority
This has been removed from webrtc-pc[0]

Relates to #748

[0] https://github.com/w3c/webrtc-pc/issues/2258
2019-09-26 15:44:19 -07:00
Sean DuBois
dbca703798 Don't return event status if unused
In lots of our event handlers we return the event status.
This is so we can know if the callee has finished. In lots
of cases we don't care so get rid of them to simplify the code.
2019-09-15 21:01:47 -07:00
spaceCh1mp
26f0fa5d33 Implement RTCDataChannel onError
OnError sets an event handler which is called
when the data transport cannot be read

Resolves #746
2019-07-28 01:27:03 -07:00
Sean DuBois
2f4049b15a Replace TODOs in PeerConnection with issues
Update all TODOs with issues in github

Relates to #106
2019-07-22 21:31:39 -07:00
Sean DuBois
e0a748c2d7 Remove TODO from DataChannel Priority
This value is properly passed into SCTP now

Relates to #106
2019-07-22 21:31:39 -07:00
Cecylia Bocovich
b6bacf34c6 Increase dataChannelBufferSize to send limit
The current dataChannelBufferSize is less than the limit used in
WriteSCTP (called by Send), which means that peers using this
implementations of WebRTC can send messages that will be thrown out by
Read because of an io.ErrShortBuffer error.
In the case that the message is too long, a more appropriate response
would be to close the channel and issue an error rather than log a
warning and continue reading data.
2019-07-12 11:29:42 -04:00
Hugo Arregui
2d465ebeee Fix datachannel stats invalid pointer
Datachannel can be have a nil datachannel pointer
2019-07-02 18:51:04 +00:00
Hugo Arregui
93261960b1 Basic stats
Load DC, CandidatePair and Candidate basic stats
2019-06-25 19:36:57 +00:00
Hugo Arregui
7c94c5478c Fix DC open
it's expected for a open Datachannel to have an associated
datachannel.Datachannel. Handling everything under the same lock
guarantee that
2019-05-22 14:18:42 -07:00