| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ | 11 #ifndef WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ |
| 12 #define WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ | 12 #define WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 #include "webrtc/p2p/base/candidate.h" | 16 #include "webrtc/p2p/base/candidate.h" |
| 17 #include "webrtc/p2p/base/rawtransport.h" | 17 #include "webrtc/p2p/base/rawtransport.h" |
| 18 #include "webrtc/p2p/base/transportchannelimpl.h" | 18 #include "webrtc/p2p/base/transportchannelimpl.h" |
| 19 #include "webrtc/base/messagequeue.h" | 19 #include "webrtc/base/messagequeue.h" |
| 20 | 20 |
| 21 #if defined(FEATURE_ENABLE_PSTN) | 21 #if defined(FEATURE_ENABLE_PSTN) |
| 22 | 22 |
| 23 namespace rtc { | |
| 24 class Thread; | |
| 25 } | |
| 26 | |
| 27 namespace cricket { | 23 namespace cricket { |
| 28 | 24 |
| 29 class Connection; | 25 class Connection; |
| 30 class PortAllocator; | 26 class PortAllocator; |
| 31 class PortAllocatorSession; | 27 class PortAllocatorSession; |
| 32 class PortInterface; | 28 class PortInterface; |
| 33 class RelayPort; | 29 class RelayPort; |
| 34 class StunPort; | 30 class StunPort; |
| 35 | 31 |
| 36 // Implements a channel that just sends bare packets once we have received the | 32 // 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 | 33 // address of the other side. We pick a single address to send them based on |
| 38 // a simple investigation of NAT type. | 34 // a simple investigation of NAT type. |
| 39 class RawTransportChannel : public TransportChannelImpl, | 35 class RawTransportChannel : public TransportChannelImpl { |
| 40 public rtc::MessageHandler { | |
| 41 public: | 36 public: |
| 42 RawTransportChannel(const std::string& content_name, | 37 RawTransportChannel(const std::string& content_name, |
| 43 int component, | 38 int component, |
| 44 RawTransport* transport, | 39 RawTransport* transport, |
| 45 rtc::Thread *worker_thread, | 40 PortAllocator* allocator); |
| 46 PortAllocator *allocator); | |
| 47 virtual ~RawTransportChannel(); | 41 virtual ~RawTransportChannel(); |
| 48 | 42 |
| 49 // Implementation of normal channel packet sending. | 43 // Implementation of normal channel packet sending. |
| 50 virtual int SendPacket(const char *data, size_t len, | 44 virtual int SendPacket(const char *data, size_t len, |
| 51 const rtc::PacketOptions& options, int flags); | 45 const rtc::PacketOptions& options, int flags); |
| 52 virtual int SetOption(rtc::Socket::Option opt, int value); | 46 virtual int SetOption(rtc::Socket::Option opt, int value); |
| 53 virtual bool GetOption(rtc::Socket::Option opt, int* value); | 47 virtual bool GetOption(rtc::Socket::Option opt, int* value); |
| 54 virtual int GetError(); | 48 virtual int GetError(); |
| 55 | 49 |
| 56 // Implements TransportChannelImpl. | 50 // Implements TransportChannelImpl. |
| 57 virtual Transport* GetTransport() { return raw_transport_; } | 51 virtual Transport* GetTransport() { return raw_transport_; } |
| 58 virtual TransportChannelState GetState() const { | 52 virtual TransportChannelState GetState() const { |
| 59 return TransportChannelState::STATE_COMPLETED; | 53 return TransportChannelState::STATE_COMPLETED; |
| 60 } | 54 } |
| 61 virtual void SetIceCredentials(const std::string& ice_ufrag, | 55 virtual void SetIceCredentials(const std::string& ice_ufrag, |
| 62 const std::string& ice_pwd) {} | 56 const std::string& ice_pwd) {} |
| 63 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, | 57 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, |
| 64 const std::string& ice_pwd) {} | 58 const std::string& ice_pwd) {} |
| 65 | 59 |
| 66 // Creates an allocator session to start figuring out which type of | 60 // Creates an allocator session to start figuring out which type of |
| 67 // port we should send to the other client. This will send | 61 // port we should send to the other client. This will send |
| 68 // SignalAvailableCandidate once we have decided. | 62 // SignalAvailableCandidate once we have decided. |
| 69 virtual void Connect(); | 63 virtual void Connect(); |
| 70 | 64 |
| 65 virtual Transport::CandidateGatheringState candidate_gathering_state() const { |
| 66 return Transport::kGatheringNew; |
| 67 } |
| 68 |
| 71 // Resets state back to unconnected. | 69 // Resets state back to unconnected. |
| 72 virtual void Reset(); | 70 virtual void Reset(); |
| 73 | 71 |
| 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 | 72 // Handles a message setting the remote address. We are writable once we |
| 78 // have this since we now know where to send. | 73 // have this since we now know where to send. |
| 79 virtual void OnCandidate(const Candidate& candidate); | 74 virtual void OnCandidate(const Candidate& candidate); |
| 80 | 75 |
| 81 void OnRemoteAddress(const rtc::SocketAddress& remote_address); | 76 void OnRemoteAddress(const rtc::SocketAddress& remote_address); |
| 82 | 77 |
| 83 // Below ICE specific virtual methods not implemented. | 78 // Below ICE specific virtual methods not implemented. |
| 84 virtual IceRole GetIceRole() const { return ICEROLE_UNKNOWN; } | 79 virtual IceRole GetIceRole() const { return ICEROLE_UNKNOWN; } |
| 85 virtual void SetIceRole(IceRole role) {} | 80 virtual void SetIceRole(IceRole role) {} |
| 86 virtual void SetIceTiebreaker(uint64 tiebreaker) {} | 81 virtual void SetIceTiebreaker(uint64 tiebreaker) {} |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const std::string& digest_alg, | 148 const std::string& digest_alg, |
| 154 const uint8* digest, | 149 const uint8* digest, |
| 155 size_t digest_len) { | 150 size_t digest_len) { |
| 156 return false; | 151 return false; |
| 157 } | 152 } |
| 158 | 153 |
| 159 void SetReceivingTimeout(int timeout) override {} | 154 void SetReceivingTimeout(int timeout) override {} |
| 160 | 155 |
| 161 private: | 156 private: |
| 162 RawTransport* raw_transport_; | 157 RawTransport* raw_transport_; |
| 163 rtc::Thread *worker_thread_; | |
| 164 PortAllocator* allocator_; | 158 PortAllocator* allocator_; |
| 165 PortAllocatorSession* allocator_session_; | 159 PortAllocatorSession* allocator_session_; |
| 166 StunPort* stun_port_; | 160 StunPort* stun_port_; |
| 167 RelayPort* relay_port_; | 161 RelayPort* relay_port_; |
| 168 PortInterface* port_; | 162 PortInterface* port_; |
| 169 bool use_relay_; | 163 bool use_relay_; |
| 170 rtc::SocketAddress remote_address_; | 164 rtc::SocketAddress remote_address_; |
| 171 | 165 |
| 172 // Called when the allocator creates another port. | 166 // Called when the allocator creates another port. |
| 173 void OnPortReady(PortAllocatorSession* session, PortInterface* port); | 167 void OnPortReady(PortAllocatorSession* session, PortInterface* port); |
| 174 | 168 |
| 175 // Called when one of the ports we are using has determined its address. | 169 // Called when one of the ports we are using has determined its address. |
| 176 void OnCandidatesReady(PortAllocatorSession *session, | 170 void OnCandidatesReady(PortAllocatorSession *session, |
| 177 const std::vector<Candidate>& candidates); | 171 const std::vector<Candidate>& candidates); |
| 178 | 172 |
| 179 // Called once we have chosen the port to use for communication with the | 173 // 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. | 174 // other client. This will send its address and prepare the port for use. |
| 181 void SetPort(PortInterface* port); | 175 void SetPort(PortInterface* port); |
| 182 | 176 |
| 183 // Called once we have a port and a remote address. This will set mark the | 177 // 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. | 178 // channel as writable and signal the route to the client. |
| 185 void SetWritable(); | 179 void SetWritable(); |
| 186 | 180 |
| 187 // Called when we receive a packet from the other client. | 181 // Called when we receive a packet from the other client. |
| 188 void OnReadPacket(PortInterface* port, const char* data, size_t size, | 182 void OnReadPacket(PortInterface* port, const char* data, size_t size, |
| 189 const rtc::SocketAddress& addr); | 183 const rtc::SocketAddress& addr); |
| 190 | 184 |
| 191 // Handles a message to destroy unused ports. | 185 void DestroyUnusedPorts(); |
| 192 virtual void OnMessage(rtc::Message *msg); | |
| 193 | 186 |
| 194 DISALLOW_COPY_AND_ASSIGN(RawTransportChannel); | 187 DISALLOW_COPY_AND_ASSIGN(RawTransportChannel); |
| 195 }; | 188 }; |
| 196 | 189 |
| 197 } // namespace cricket | 190 } // namespace cricket |
| 198 | 191 |
| 199 #endif // defined(FEATURE_ENABLE_PSTN) | 192 #endif // defined(FEATURE_ENABLE_PSTN) |
| 200 #endif // WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ | 193 #endif // WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_ |
| OLD | NEW |