| 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 #include "webrtc/p2p/base/rawtransportchannel.h" | 11 #include "webrtc/p2p/base/rawtransportchannel.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 #include "webrtc/p2p/base/constants.h" | 15 #include "webrtc/p2p/base/constants.h" |
| 16 #include "webrtc/p2p/base/portallocator.h" | 16 #include "webrtc/p2p/base/portallocator.h" |
| 17 #include "webrtc/p2p/base/portinterface.h" | 17 #include "webrtc/p2p/base/portinterface.h" |
| 18 #include "webrtc/p2p/base/rawtransport.h" | 18 #include "webrtc/p2p/base/rawtransport.h" |
| 19 #include "webrtc/p2p/base/relayport.h" | 19 #include "webrtc/p2p/base/relayport.h" |
| 20 #include "webrtc/p2p/base/stunport.h" | 20 #include "webrtc/p2p/base/stunport.h" |
| 21 #include "webrtc/base/common.h" | 21 #include "webrtc/base/common.h" |
| 22 | 22 |
| 23 #if defined(FEATURE_ENABLE_PSTN) | 23 #if defined(FEATURE_ENABLE_PSTN) |
| 24 | 24 |
| 25 namespace { | |
| 26 | |
| 27 const uint32 MSG_DESTROY_RTC_UNUSED_PORTS = 1; | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 namespace cricket { | 25 namespace cricket { |
| 32 | 26 |
| 33 RawTransportChannel::RawTransportChannel(const std::string& content_name, | 27 RawTransportChannel::RawTransportChannel(const std::string& content_name, |
| 34 int component, | 28 int component, |
| 35 RawTransport* transport, | 29 RawTransport* transport, |
| 36 rtc::Thread *worker_thread, | 30 PortAllocator* allocator) |
| 37 PortAllocator *allocator) | |
| 38 : TransportChannelImpl(content_name, component), | 31 : TransportChannelImpl(content_name, component), |
| 39 raw_transport_(transport), | 32 raw_transport_(transport), |
| 40 allocator_(allocator), | 33 allocator_(allocator), |
| 41 allocator_session_(NULL), | 34 allocator_session_(NULL), |
| 42 stun_port_(NULL), | 35 stun_port_(NULL), |
| 43 relay_port_(NULL), | 36 relay_port_(NULL), |
| 44 port_(NULL), | 37 port_(NULL), |
| 45 use_relay_(false) { | 38 use_relay_(false) { |
| 46 if (worker_thread == NULL) | |
| 47 worker_thread_ = raw_transport_->worker_thread(); | |
| 48 else | |
| 49 worker_thread_ = worker_thread; | |
| 50 } | 39 } |
| 51 | 40 |
| 52 RawTransportChannel::~RawTransportChannel() { | 41 RawTransportChannel::~RawTransportChannel() { |
| 53 delete allocator_session_; | 42 delete allocator_session_; |
| 54 } | 43 } |
| 55 | 44 |
| 56 int RawTransportChannel::SendPacket(const char *data, size_t size, | 45 int RawTransportChannel::SendPacket(const char *data, size_t size, |
| 57 const rtc::PacketOptions& options, | 46 const rtc::PacketOptions& options, |
| 58 int flags) { | 47 int flags) { |
| 59 if (port_ == NULL) | 48 if (port_ == NULL) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (port->Type() == STUN_PORT_TYPE) { | 140 if (port->Type() == STUN_PORT_TYPE) { |
| 152 stun_port_ = static_cast<StunPort*>(port); | 141 stun_port_ = static_cast<StunPort*>(port); |
| 153 } else if (port->Type() == RELAY_PORT_TYPE) { | 142 } else if (port->Type() == RELAY_PORT_TYPE) { |
| 154 relay_port_ = static_cast<RelayPort*>(port); | 143 relay_port_ = static_cast<RelayPort*>(port); |
| 155 } else { | 144 } else { |
| 156 ASSERT(false); | 145 ASSERT(false); |
| 157 } | 146 } |
| 158 } | 147 } |
| 159 | 148 |
| 160 void RawTransportChannel::OnCandidatesReady( | 149 void RawTransportChannel::OnCandidatesReady( |
| 161 PortAllocatorSession *session, const std::vector<Candidate>& candidates) { | 150 PortAllocatorSession* session, const std::vector<Candidate>& candidates) { |
| 162 ASSERT(session == allocator_session_); | 151 ASSERT(session == allocator_session_); |
| 163 ASSERT(candidates.size() >= 1); | 152 ASSERT(candidates.size() >= 1); |
| 164 | 153 |
| 165 // The most recent candidate is the one we haven't seen yet. | 154 // The most recent candidate is the one we haven't seen yet. |
| 166 Candidate c = candidates[candidates.size() - 1]; | 155 Candidate c = candidates[candidates.size() - 1]; |
| 167 | 156 |
| 168 if (c.type() == STUN_PORT_TYPE) { | 157 if (c.type() == STUN_PORT_TYPE) { |
| 169 ASSERT(stun_port_ != NULL); | 158 ASSERT(stun_port_ != NULL); |
| 170 | 159 |
| 171 #if defined(FEATURE_ENABLE_STUN_CLASSIFICATION) | 160 #if defined(FEATURE_ENABLE_STUN_CLASSIFICATION) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 200 ASSERT(false); | 189 ASSERT(false); |
| 201 } | 190 } |
| 202 } | 191 } |
| 203 | 192 |
| 204 void RawTransportChannel::SetPort(PortInterface* port) { | 193 void RawTransportChannel::SetPort(PortInterface* port) { |
| 205 ASSERT(port_ == NULL); | 194 ASSERT(port_ == NULL); |
| 206 port_ = port; | 195 port_ = port; |
| 207 | 196 |
| 208 // We don't need any ports other than the one we picked. | 197 // We don't need any ports other than the one we picked. |
| 209 allocator_session_->StopGettingPorts(); | 198 allocator_session_->StopGettingPorts(); |
| 210 worker_thread_->Post( | 199 DestroyUnusedPorts(); |
| 211 this, MSG_DESTROY_RTC_UNUSED_PORTS, NULL); | |
| 212 | 200 |
| 213 // Send a message to the other client containing our address. | 201 // Send a message to the other client containing our address. |
| 214 | 202 |
| 215 ASSERT(port_->Candidates().size() >= 1); | 203 ASSERT(port_->Candidates().size() >= 1); |
| 216 ASSERT(port_->Candidates()[0].protocol() == "udp"); | 204 ASSERT(port_->Candidates()[0].protocol() == "udp"); |
| 217 SignalCandidateReady(this, port_->Candidates()[0]); | 205 SignalCandidateReady(this, port_->Candidates()[0]); |
| 218 | 206 |
| 219 // Read all packets from this port. | 207 // Read all packets from this port. |
| 220 port_->EnablePortPackets(); | 208 port_->EnablePortPackets(); |
| 221 port_->SignalReadPacket.connect(this, &RawTransportChannel::OnReadPacket); | 209 port_->SignalReadPacket.connect(this, &RawTransportChannel::OnReadPacket); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 236 SignalRouteChange(this, remote_candidate); | 224 SignalRouteChange(this, remote_candidate); |
| 237 } | 225 } |
| 238 | 226 |
| 239 void RawTransportChannel::OnReadPacket( | 227 void RawTransportChannel::OnReadPacket( |
| 240 PortInterface* port, const char* data, size_t size, | 228 PortInterface* port, const char* data, size_t size, |
| 241 const rtc::SocketAddress& addr) { | 229 const rtc::SocketAddress& addr) { |
| 242 ASSERT(port_ == port); | 230 ASSERT(port_ == port); |
| 243 SignalReadPacket(this, data, size, rtc::CreatePacketTime(0), 0); | 231 SignalReadPacket(this, data, size, rtc::CreatePacketTime(0), 0); |
| 244 } | 232 } |
| 245 | 233 |
| 246 void RawTransportChannel::OnMessage(rtc::Message* msg) { | 234 void RawTransportChannel::DestroyUnusedPorts() { |
| 247 ASSERT(msg->message_id == MSG_DESTROY_RTC_UNUSED_PORTS); | |
| 248 ASSERT(port_ != NULL); | 235 ASSERT(port_ != NULL); |
| 249 if (port_ != stun_port_) { | 236 if (port_ != stun_port_) { |
| 250 stun_port_->Destroy(); | 237 stun_port_->Destroy(); |
| 251 stun_port_ = NULL; | 238 stun_port_ = NULL; |
| 252 } | 239 } |
| 253 if (port_ != relay_port_ && relay_port_ != NULL) { | 240 if (port_ != relay_port_ && relay_port_ != NULL) { |
| 254 relay_port_->Destroy(); | 241 relay_port_->Destroy(); |
| 255 relay_port_ = NULL; | 242 relay_port_ = NULL; |
| 256 } | 243 } |
| 257 } | 244 } |
| 258 | 245 |
| 259 } // namespace cricket | 246 } // namespace cricket |
| 260 #endif // defined(FEATURE_ENABLE_PSTN) | 247 #endif // defined(FEATURE_ENABLE_PSTN) |
| OLD | NEW |