Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_MEDIA_SCTP_SCTPTRANSPORTINTERNAL_H_ | |
| 12 #define WEBRTC_MEDIA_SCTP_SCTPTRANSPORTINTERNAL_H_ | |
| 13 | |
| 14 #include <memory> // for unique_ptr | |
| 15 #include <string> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "webrtc/base/copyonwritebuffer.h" | |
| 19 #include "webrtc/base/thread.h" | |
| 20 // For SendDataParams/ReceiveDataParams. | |
| 21 // TODO(deadbeef): Use something else for SCTP. It's confusing that we use an | |
| 22 // SSRC field for SID. | |
| 23 #include "webrtc/media/base/mediachannel.h" | |
| 24 #include "webrtc/p2p/base/transportchannel.h" | |
| 25 | |
| 26 namespace cricket { | |
| 27 | |
| 28 // The number of outgoing streams that we'll negotiate. Since stream IDs (SIDs) | |
| 29 // are 0-based, the highest usable SID is 1023. | |
| 30 // | |
| 31 // It's recommended to use the maximum of 65535 in: | |
| 32 // https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-6.2 | |
| 33 // However, we use 1024 in order to save memory. usrsctp allocates 104 bytes | |
| 34 // for each pair of incoming/outgoing streams (on a 64-bit system), so 65535 | |
| 35 // streams would waste ~6MB. | |
| 36 // | |
| 37 // Note: "max" and "min" here are inclusive. | |
| 38 constexpr uint16_t kMaxSctpStreams = 1024; | |
| 39 constexpr uint16_t kMaxSctpSid = kMaxSctpStreams - 1; | |
| 40 constexpr uint16_t kMinSctpSid = 0; | |
| 41 | |
| 42 // This is the default SCTP port to use. It is passed along the wire and the | |
| 43 // connectee and connector must be using the same port. It is not related to the | |
| 44 // ports at the IP level. (Corresponds to: sockaddr_conn.sconn_port in | |
| 45 // usrsctp.h) | |
| 46 const int kSctpDefaultPort = 5000; | |
| 47 | |
| 48 // Abstract SctpTransport interface for use internally (by | |
| 49 // PeerConnection/WebRtcSession/etc.). Exists to allow mock/fake SctpTransports | |
| 50 // to be created. | |
| 51 class SctpTransportInternal { | |
| 52 public: | |
| 53 virtual ~SctpTransportInternal() {} | |
| 54 | |
| 55 // Changes what underlying DTLS channel is uses. Used when switching which | |
| 56 // bundled transport the SctpTransport uses. | |
| 57 // Assumes |channel| is non-null. | |
| 58 virtual void SetTransportChannel(TransportChannel* channel) = 0; | |
| 59 | |
| 60 // When Start is called, connects as soon as possible; this can be called | |
| 61 // before DTLS completes, in which case the connection will begin when DTLS | |
| 62 // completes. This method can be called multiple times, though not if either | |
| 63 // of the ports are changed. | |
| 64 // | |
| 65 // |local_sctp_port| and |remote_sctp_port| are passed along the wire and the | |
| 66 // listener and connector must be using the same port. They are not related | |
| 67 // to the ports at the IP level. If set to -1, we default to | |
| 68 // kSctpDefaultPort. | |
| 69 // | |
| 70 // TODO(deadbeef): Add remote max message size as parameter to Start, once we | |
| 71 // start supporting it. | |
| 72 // TODO(deadbeef): Support calling Start with different local/remote ports | |
| 73 // and create a new association? Not clear if this is something we need to | |
| 74 // support though. See: https://github.com/w3c/webrtc-pc/issues/979 | |
|
pthatcher1
2016/12/23 01:39:31
I don't think we'll ever need that.
Taylor Brandstetter
2016/12/23 06:29:05
Can you comment on the github issue?
pthatcher1
2017/01/03 18:31:26
I commented on github. It seems like Bernard agre
| |
| 75 virtual bool Start(int local_sctp_port, int remote_sctp_port) = 0; | |
|
pthatcher1
2016/12/23 01:39:31
We could model this as the ORTC object:
- A port
Taylor Brandstetter
2016/12/23 06:29:05
There's an issue filed for ORTC for that. There wa
pthatcher1
2017/01/03 18:31:26
Sure, we can always refactor more later.
I just
pthatcher1
2017/01/03 20:45:00
Nevermind, I was wrong about that :).
| |
| 76 | |
| 77 // NOTE: Initially there was a "Stop" method here, but it was never used, so | |
| 78 // it was removed. | |
| 79 | |
| 80 // Informs SctpTransport that |sid| will start being used. Returns false if | |
| 81 // it is impossible to use |sid|, or if it's already in use. | |
| 82 // Until calling this, can't send data using |sid|. | |
| 83 // TODO(deadbeef): Actually implement the "returns false if |sid| can't be | |
| 84 // used" part. See: | |
| 85 // https://bugs.chromium.org/p/chromium/issues/detail?id=619849 | |
| 86 virtual bool OpenStream(int sid) = 0; | |
|
pthatcher1
2016/12/23 01:39:31
It would be nice if we instead had a CreateDataCha
Taylor Brandstetter
2016/12/23 06:29:05
I disagree; that would create a circular dependenc
pthatcher1
2017/01/03 18:31:26
Sorry, I meant return a DataChannelInterface, whic
| |
| 87 // The inverse of OpenStream. When this method returns, the reset process may | |
| 88 // have not finished but it will have begun. | |
| 89 // TODO(deadbeef): We need a way to tell when it's done. See: | |
| 90 // https://bugs.chromium.org/p/webrtc/issues/detail?id=4453 | |
| 91 virtual bool ResetStream(int sid) = 0; | |
|
pthatcher1
2016/12/23 01:39:31
Why not CloseStream (to go along with DataChannel.
Taylor Brandstetter
2016/12/23 06:29:05
Because streams aren't closed, they're reset; that
| |
| 92 // Send data down this channel (will be wrapped as SCTP packets then given to | |
| 93 // usrsctp that will then post the network interface). | |
| 94 // Returns true iff successful data somewhere on the send-queue/network. | |
| 95 // Uses |params.ssrc| as the SCTP sid. | |
| 96 virtual bool SendData(const SendDataParams& params, | |
| 97 const rtc::CopyOnWriteBuffer& payload, | |
| 98 SendDataResult* result = nullptr) = 0; | |
| 99 | |
| 100 // Indicates when the SCTP socket is created and not blocked by congestion | |
| 101 // control. This changes to false when SDR_BLOCK is returned from SendData, | |
| 102 // and | |
| 103 // changes to true when SignalReadyToSendData is fired. The underlying DTLS/ | |
| 104 // ICE channels may be unwritable while ReadyToSendData is true, because data | |
| 105 // can still be queued in usrsctp. | |
| 106 virtual bool ReadyToSendData() = 0; | |
| 107 | |
| 108 sigslot::signal0<> SignalReadyToSendData; | |
| 109 // ReceiveDataParams includes SID, seq num, timestamp, etc. CopyOnWriteBuffer | |
| 110 // contains message payload. | |
| 111 sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&> | |
| 112 SignalDataReceived; | |
| 113 // Parameter is SID of closed stream. | |
| 114 sigslot::signal1<int> SignalStreamClosedRemotely; | |
| 115 | |
| 116 // Helper for debugging. | |
| 117 virtual void set_debug_name_for_testing(const char* debug_name) = 0; | |
| 118 }; | |
| 119 | |
| 120 // Factory class which can be used to allow fake SctpTransports to be injected | |
| 121 // for testing. Or, theoretically, SctpTransportInternal implementations that | |
| 122 // use something other than usrsctp. | |
| 123 class SctpTransportInternalFactory { | |
| 124 public: | |
| 125 virtual ~SctpTransportInternalFactory() {} | |
| 126 | |
| 127 // Create an SCTP transport using |channel| for the underlying transport. | |
| 128 virtual std::unique_ptr<SctpTransportInternal> CreateSctpTransport( | |
| 129 TransportChannel* channel) = 0; | |
| 130 }; | |
| 131 | |
| 132 } // namespace cricket | |
| 133 | |
| 134 #endif // WEBRTC_MEDIA_SCTP_SCTPTRANSPORTINTERNAL_H_ | |
| OLD | NEW |