OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2004 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_P2P_BASE_TRANSPORTCHANNEL_H_ |
| 12 #define WEBRTC_P2P_BASE_TRANSPORTCHANNEL_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <string> |
| 16 #include <vector> |
| 17 |
| 18 #include "webrtc/base/asyncpacketsocket.h" |
| 19 #include "webrtc/base/basictypes.h" |
| 20 #include "webrtc/base/constructormagic.h" |
| 21 #include "webrtc/base/dscp.h" |
| 22 #include "webrtc/base/sigslot.h" |
| 23 #include "webrtc/base/socket.h" |
| 24 #include "webrtc/base/sslidentity.h" |
| 25 #include "webrtc/base/sslstreamadapter.h" |
| 26 #include "webrtc/p2p/base/candidate.h" |
| 27 #include "webrtc/p2p/base/candidatepairinterface.h" |
| 28 #include "webrtc/p2p/base/icetransportinternal.h" |
| 29 #include "webrtc/p2p/base/jseptransport.h" |
| 30 #include "webrtc/p2p/base/packettransportinterface.h" |
| 31 #include "webrtc/p2p/base/transportdescription.h" |
| 32 |
| 33 namespace cricket { |
| 34 |
| 35 class Candidate; |
| 36 |
| 37 // Flags for SendPacket/SignalReadPacket. |
| 38 enum PacketFlags { |
| 39 PF_NORMAL = 0x00, // A normal packet. |
| 40 PF_SRTP_BYPASS = 0x01, // An encrypted SRTP packet; bypass any additional |
| 41 // crypto provided by the transport (e.g. DTLS) |
| 42 }; |
| 43 |
| 44 // A TransportChannel represents one logical stream of packets that are sent |
| 45 // between the two sides of a session. |
| 46 // TODO(deadbeef): This interface currently represents the unity of an ICE |
| 47 // transport and a DTLS transport. They need to be separated apart. |
| 48 class TransportChannel : public rtc::PacketTransportInterface { |
| 49 public: |
| 50 TransportChannel(const std::string& transport_name, int component) |
| 51 : transport_name_(transport_name), |
| 52 component_(component), |
| 53 writable_(false), |
| 54 receiving_(false) {} |
| 55 virtual ~TransportChannel() {} |
| 56 |
| 57 // TODO(guoweis) - Make this pure virtual once all subclasses of |
| 58 // TransportChannel have this defined. |
| 59 virtual IceTransportState GetState() const { |
| 60 return IceTransportState::STATE_CONNECTING; |
| 61 } |
| 62 |
| 63 const std::string& transport_name() const { return transport_name_; } |
| 64 int component() const { return component_; } |
| 65 const std::string debug_name() const override { |
| 66 return transport_name() + " " + std::to_string(component()); |
| 67 } |
| 68 |
| 69 // Returns the states of this channel. Each time one of these states changes, |
| 70 // a signal is raised. These states are aggregated by the TransportManager. |
| 71 bool writable() const override { return writable_; } |
| 72 bool receiving() const override { return receiving_; } |
| 73 DtlsTransportState dtls_state() const { return dtls_state_; } |
| 74 // Emitted whenever DTLS-SRTP is setup which will require setting up a new |
| 75 // SRTP context. |
| 76 sigslot::signal2<TransportChannel*, DtlsTransportState> SignalDtlsState; |
| 77 |
| 78 // Returns the current stats for this connection. |
| 79 virtual bool GetStats(ConnectionInfos* infos) = 0; |
| 80 |
| 81 // Is DTLS active? |
| 82 virtual bool IsDtlsActive() const = 0; |
| 83 |
| 84 // Default implementation. |
| 85 virtual bool GetSslRole(rtc::SSLRole* role) const = 0; |
| 86 |
| 87 // Sets up the ciphers to use for DTLS-SRTP. TODO(guoweis): Make this pure |
| 88 // virtual once all dependencies have implementation. |
| 89 virtual bool SetSrtpCryptoSuites(const std::vector<int>& ciphers); |
| 90 |
| 91 // Keep the original one for backward compatibility until all dependencies |
| 92 // move away. TODO(guoweis): Remove this function. |
| 93 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers); |
| 94 |
| 95 // Finds out which DTLS-SRTP cipher was negotiated. |
| 96 // TODO(guoweis): Remove this once all dependencies implement this. |
| 97 virtual bool GetSrtpCryptoSuite(int* cipher) { return false; } |
| 98 |
| 99 // Finds out which DTLS cipher was negotiated. |
| 100 // TODO(guoweis): Remove this once all dependencies implement this. |
| 101 virtual bool GetSslCipherSuite(int* cipher) { return false; } |
| 102 |
| 103 // Gets the local RTCCertificate used for DTLS. |
| 104 virtual rtc::scoped_refptr<rtc::RTCCertificate> |
| 105 GetLocalCertificate() const = 0; |
| 106 |
| 107 // Gets a copy of the remote side's SSL certificate. |
| 108 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() |
| 109 const = 0; |
| 110 |
| 111 // Allows key material to be extracted for external encryption. |
| 112 virtual bool ExportKeyingMaterial(const std::string& label, |
| 113 const uint8_t* context, |
| 114 size_t context_len, |
| 115 bool use_context, |
| 116 uint8_t* result, |
| 117 size_t result_len) = 0; |
| 118 |
| 119 // Deprecated by SignalSelectedCandidatePairChanged |
| 120 // This signal occurs when there is a change in the way that packets are |
| 121 // being routed, i.e. to a different remote location. The candidate |
| 122 // indicates where and how we are currently sending media. |
| 123 sigslot::signal2<TransportChannel*, const Candidate&> SignalRouteChange; |
| 124 |
| 125 // Signalled when the current selected candidate pair has changed. |
| 126 // The first parameter is the transport channel that signals the event. |
| 127 // The second parameter is the new selected candidate pair. The third |
| 128 // parameter is the last packet id sent on the previous candidate pair. |
| 129 // The fourth parameter is a boolean which is true if the TransportChannel |
| 130 // is ready to send with this candidate pair. |
| 131 sigslot::signal4<TransportChannel*, CandidatePairInterface*, int, bool> |
| 132 SignalSelectedCandidatePairChanged; |
| 133 |
| 134 // Invoked when the channel is being destroyed. |
| 135 sigslot::signal1<TransportChannel*> SignalDestroyed; |
| 136 |
| 137 // Debugging description of this transport channel. |
| 138 std::string ToString() const; |
| 139 |
| 140 protected: |
| 141 // Sets the writable state, signaling if necessary. |
| 142 void set_writable(bool writable); |
| 143 |
| 144 // Sets the receiving state, signaling if necessary. |
| 145 void set_receiving(bool receiving); |
| 146 |
| 147 // Sets the DTLS state, signaling if necessary. |
| 148 void set_dtls_state(DtlsTransportState state); |
| 149 |
| 150 private: |
| 151 // Used mostly for debugging. |
| 152 std::string transport_name_; |
| 153 int component_; |
| 154 bool writable_; |
| 155 bool receiving_; |
| 156 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; |
| 157 |
| 158 RTC_DISALLOW_COPY_AND_ASSIGN(TransportChannel); |
| 159 }; |
| 160 |
| 161 } // namespace cricket |
| 162 |
| 163 #endif // WEBRTC_P2P_BASE_TRANSPORTCHANNEL_H_ |
OLD | NEW |