OLD | NEW |
1 // TODO(pthatcher): Remove this file once Chrome's build files no | 1 /* |
2 // longer refer to it. | 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_RAWTRANSPORTCHANNEL_H_ |
| 12 #define WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ |
| 13 |
| 14 #include <string> |
| 15 #include <vector> |
| 16 #include "webrtc/p2p/base/candidate.h" |
| 17 #include "webrtc/p2p/base/rawtransport.h" |
| 18 #include "webrtc/p2p/base/transportchannelimpl.h" |
| 19 #include "webrtc/base/messagequeue.h" |
| 20 |
| 21 #if defined(FEATURE_ENABLE_PSTN) |
| 22 |
| 23 namespace rtc { |
| 24 class Thread; |
| 25 } |
| 26 |
| 27 namespace cricket { |
| 28 |
| 29 class Connection; |
| 30 class PortAllocator; |
| 31 class PortAllocatorSession; |
| 32 class PortInterface; |
| 33 class RelayPort; |
| 34 class StunPort; |
| 35 |
| 36 // Implements a channel that just sends bare packets once we have received the |
| 37 // address of the other side. We pick a single address to send them based on |
| 38 // a simple investigation of NAT type. |
| 39 class RawTransportChannel : public TransportChannelImpl, |
| 40 public rtc::MessageHandler { |
| 41 public: |
| 42 RawTransportChannel(const std::string& content_name, |
| 43 int component, |
| 44 RawTransport* transport, |
| 45 rtc::Thread *worker_thread, |
| 46 PortAllocator *allocator); |
| 47 virtual ~RawTransportChannel(); |
| 48 |
| 49 // Implementation of normal channel packet sending. |
| 50 virtual int SendPacket(const char *data, size_t len, |
| 51 const rtc::PacketOptions& options, int flags); |
| 52 virtual int SetOption(rtc::Socket::Option opt, int value); |
| 53 virtual bool GetOption(rtc::Socket::Option opt, int* value); |
| 54 virtual int GetError(); |
| 55 |
| 56 // Implements TransportChannelImpl. |
| 57 virtual Transport* GetTransport() { return raw_transport_; } |
| 58 virtual TransportChannelState GetState() const { |
| 59 return TransportChannelState::STATE_COMPLETED; |
| 60 } |
| 61 virtual void SetIceCredentials(const std::string& ice_ufrag, |
| 62 const std::string& ice_pwd) {} |
| 63 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, |
| 64 const std::string& ice_pwd) {} |
| 65 |
| 66 // Creates an allocator session to start figuring out which type of |
| 67 // port we should send to the other client. This will send |
| 68 // SignalAvailableCandidate once we have decided. |
| 69 virtual void Connect(); |
| 70 |
| 71 // Resets state back to unconnected. |
| 72 virtual void Reset(); |
| 73 |
| 74 // We don't actually worry about signaling since we can't send new candidates. |
| 75 virtual void OnSignalingReady() {} |
| 76 |
| 77 // Handles a message setting the remote address. We are writable once we |
| 78 // have this since we now know where to send. |
| 79 virtual void OnCandidate(const Candidate& candidate); |
| 80 |
| 81 void OnRemoteAddress(const rtc::SocketAddress& remote_address); |
| 82 |
| 83 // Below ICE specific virtual methods not implemented. |
| 84 virtual IceRole GetIceRole() const { return ICEROLE_UNKNOWN; } |
| 85 virtual void SetIceRole(IceRole role) {} |
| 86 virtual void SetIceTiebreaker(uint64 tiebreaker) {} |
| 87 |
| 88 virtual bool GetIceProtocolType(IceProtocolType* type) const { return false; } |
| 89 virtual void SetIceProtocolType(IceProtocolType type) {} |
| 90 |
| 91 virtual void SetIceUfrag(const std::string& ice_ufrag) {} |
| 92 virtual void SetIcePwd(const std::string& ice_pwd) {} |
| 93 virtual void SetRemoteIceMode(IceMode mode) {} |
| 94 virtual size_t GetConnectionCount() const { return 1; } |
| 95 |
| 96 virtual bool GetStats(ConnectionInfos* infos) { |
| 97 return false; |
| 98 } |
| 99 |
| 100 // DTLS methods. |
| 101 virtual bool IsDtlsActive() const { return false; } |
| 102 |
| 103 // Default implementation. |
| 104 virtual bool GetSslRole(rtc::SSLRole* role) const { |
| 105 return false; |
| 106 } |
| 107 |
| 108 virtual bool SetSslRole(rtc::SSLRole role) { |
| 109 return false; |
| 110 } |
| 111 |
| 112 // Set up the ciphers to use for DTLS-SRTP. |
| 113 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) { |
| 114 return false; |
| 115 } |
| 116 |
| 117 // Find out which DTLS-SRTP cipher was negotiated. |
| 118 virtual bool GetSrtpCipher(std::string* cipher) { |
| 119 return false; |
| 120 } |
| 121 |
| 122 // Find out which DTLS cipher was negotiated. |
| 123 virtual bool GetSslCipher(std::string* cipher) { |
| 124 return false; |
| 125 } |
| 126 |
| 127 // Returns false because the channel is not DTLS. |
| 128 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const { |
| 129 return false; |
| 130 } |
| 131 |
| 132 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const { |
| 133 return false; |
| 134 } |
| 135 |
| 136 // Allows key material to be extracted for external encryption. |
| 137 virtual bool ExportKeyingMaterial( |
| 138 const std::string& label, |
| 139 const uint8* context, |
| 140 size_t context_len, |
| 141 bool use_context, |
| 142 uint8* result, |
| 143 size_t result_len) { |
| 144 return false; |
| 145 } |
| 146 |
| 147 virtual bool SetLocalIdentity(rtc::SSLIdentity* identity) { |
| 148 return false; |
| 149 } |
| 150 |
| 151 // Set DTLS Remote fingerprint. Must be after local identity set. |
| 152 virtual bool SetRemoteFingerprint( |
| 153 const std::string& digest_alg, |
| 154 const uint8* digest, |
| 155 size_t digest_len) { |
| 156 return false; |
| 157 } |
| 158 |
| 159 void SetReceivingTimeout(int timeout) override {} |
| 160 |
| 161 private: |
| 162 RawTransport* raw_transport_; |
| 163 rtc::Thread *worker_thread_; |
| 164 PortAllocator* allocator_; |
| 165 PortAllocatorSession* allocator_session_; |
| 166 StunPort* stun_port_; |
| 167 RelayPort* relay_port_; |
| 168 PortInterface* port_; |
| 169 bool use_relay_; |
| 170 rtc::SocketAddress remote_address_; |
| 171 |
| 172 // Called when the allocator creates another port. |
| 173 void OnPortReady(PortAllocatorSession* session, PortInterface* port); |
| 174 |
| 175 // Called when one of the ports we are using has determined its address. |
| 176 void OnCandidatesReady(PortAllocatorSession *session, |
| 177 const std::vector<Candidate>& candidates); |
| 178 |
| 179 // Called once we have chosen the port to use for communication with the |
| 180 // other client. This will send its address and prepare the port for use. |
| 181 void SetPort(PortInterface* port); |
| 182 |
| 183 // Called once we have a port and a remote address. This will set mark the |
| 184 // channel as writable and signal the route to the client. |
| 185 void SetWritable(); |
| 186 |
| 187 // Called when we receive a packet from the other client. |
| 188 void OnReadPacket(PortInterface* port, const char* data, size_t size, |
| 189 const rtc::SocketAddress& addr); |
| 190 |
| 191 // Handles a message to destroy unused ports. |
| 192 virtual void OnMessage(rtc::Message *msg); |
| 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(RawTransportChannel); |
| 195 }; |
| 196 |
| 197 } // namespace cricket |
| 198 |
| 199 #endif // defined(FEATURE_ENABLE_PSTN) |
| 200 #endif // WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ |
OLD | NEW |