OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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/turnport.h" | 11 #include "webrtc/p2p/base/turnport.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <functional> | 14 #include <functional> |
15 | 15 |
16 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | |
17 #include "webrtc/p2p/base/common.h" | 16 #include "webrtc/p2p/base/common.h" |
18 #include "webrtc/p2p/base/stun.h" | 17 #include "webrtc/p2p/base/stun.h" |
19 #include "webrtc/rtc_base/asyncpacketsocket.h" | 18 #include "webrtc/rtc_base/asyncpacketsocket.h" |
20 #include "webrtc/rtc_base/byteorder.h" | 19 #include "webrtc/rtc_base/byteorder.h" |
21 #include "webrtc/rtc_base/checks.h" | 20 #include "webrtc/rtc_base/checks.h" |
22 #include "webrtc/rtc_base/logging.h" | 21 #include "webrtc/rtc_base/logging.h" |
23 #include "webrtc/rtc_base/nethelpers.h" | 22 #include "webrtc/rtc_base/nethelpers.h" |
24 #include "webrtc/rtc_base/ptr_util.h" | 23 #include "webrtc/rtc_base/ptr_util.h" |
25 #include "webrtc/rtc_base/socketaddress.h" | 24 #include "webrtc/rtc_base/socketaddress.h" |
26 #include "webrtc/rtc_base/stringencode.h" | 25 #include "webrtc/rtc_base/stringencode.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 183 |
185 TurnPort::TurnPort(rtc::Thread* thread, | 184 TurnPort::TurnPort(rtc::Thread* thread, |
186 rtc::PacketSocketFactory* factory, | 185 rtc::PacketSocketFactory* factory, |
187 rtc::Network* network, | 186 rtc::Network* network, |
188 rtc::AsyncPacketSocket* socket, | 187 rtc::AsyncPacketSocket* socket, |
189 const std::string& username, | 188 const std::string& username, |
190 const std::string& password, | 189 const std::string& password, |
191 const ProtocolAddress& server_address, | 190 const ProtocolAddress& server_address, |
192 const RelayCredentials& credentials, | 191 const RelayCredentials& credentials, |
193 int server_priority, | 192 int server_priority, |
194 const std::string& origin, | 193 const std::string& origin) |
195 webrtc::RtcEventLog* event_log) | 194 : Port(thread, |
196 : Port(thread, RELAY_PORT_TYPE, factory, network, username, password), | 195 RELAY_PORT_TYPE, |
| 196 factory, |
| 197 network, |
| 198 username, |
| 199 password), |
197 server_address_(server_address), | 200 server_address_(server_address), |
198 credentials_(credentials), | 201 credentials_(credentials), |
199 socket_(socket), | 202 socket_(socket), |
200 resolver_(NULL), | 203 resolver_(NULL), |
201 error_(0), | 204 error_(0), |
202 request_manager_(thread), | 205 request_manager_(thread), |
203 next_channel_number_(TURN_CHANNEL_NUMBER_START), | 206 next_channel_number_(TURN_CHANNEL_NUMBER_START), |
204 state_(STATE_CONNECTING), | 207 state_(STATE_CONNECTING), |
205 server_priority_(server_priority), | 208 server_priority_(server_priority), |
206 allocate_mismatch_retries_(0), | 209 allocate_mismatch_retries_(0) { |
207 event_log_(event_log) { | |
208 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); | 210 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); |
209 request_manager_.set_origin(origin); | 211 request_manager_.set_origin(origin); |
210 } | 212 } |
211 | 213 |
212 TurnPort::TurnPort(rtc::Thread* thread, | 214 TurnPort::TurnPort(rtc::Thread* thread, |
213 rtc::PacketSocketFactory* factory, | 215 rtc::PacketSocketFactory* factory, |
214 rtc::Network* network, | 216 rtc::Network* network, |
215 uint16_t min_port, | 217 uint16_t min_port, |
216 uint16_t max_port, | 218 uint16_t max_port, |
217 const std::string& username, | 219 const std::string& username, |
218 const std::string& password, | 220 const std::string& password, |
219 const ProtocolAddress& server_address, | 221 const ProtocolAddress& server_address, |
220 const RelayCredentials& credentials, | 222 const RelayCredentials& credentials, |
221 int server_priority, | 223 int server_priority, |
222 const std::string& origin, | 224 const std::string& origin) |
223 webrtc::RtcEventLog* event_log) | |
224 : Port(thread, | 225 : Port(thread, |
225 RELAY_PORT_TYPE, | 226 RELAY_PORT_TYPE, |
226 factory, | 227 factory, |
227 network, | 228 network, |
228 min_port, | 229 min_port, |
229 max_port, | 230 max_port, |
230 username, | 231 username, |
231 password), | 232 password), |
232 server_address_(server_address), | 233 server_address_(server_address), |
233 credentials_(credentials), | 234 credentials_(credentials), |
234 socket_(NULL), | 235 socket_(NULL), |
235 resolver_(NULL), | 236 resolver_(NULL), |
236 error_(0), | 237 error_(0), |
237 request_manager_(thread), | 238 request_manager_(thread), |
238 next_channel_number_(TURN_CHANNEL_NUMBER_START), | 239 next_channel_number_(TURN_CHANNEL_NUMBER_START), |
239 state_(STATE_CONNECTING), | 240 state_(STATE_CONNECTING), |
240 server_priority_(server_priority), | 241 server_priority_(server_priority), |
241 allocate_mismatch_retries_(0), | 242 allocate_mismatch_retries_(0) { |
242 event_log_(event_log) { | |
243 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); | 243 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); |
244 request_manager_.set_origin(origin); | 244 request_manager_.set_origin(origin); |
245 } | 245 } |
246 | 246 |
247 TurnPort::~TurnPort() { | 247 TurnPort::~TurnPort() { |
248 // TODO(juberti): Should this even be necessary? | 248 // TODO(juberti): Should this even be necessary? |
249 | 249 |
250 // release the allocation by sending a refresh with | 250 // release the allocation by sending a refresh with |
251 // lifetime 0. | 251 // lifetime 0. |
252 if (ready()) { | 252 if (ready()) { |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 if (resolver_->GetError() != 0 && server_address_.proto == PROTO_TCP) { | 701 if (resolver_->GetError() != 0 && server_address_.proto == PROTO_TCP) { |
702 if (!CreateTurnClientSocket()) { | 702 if (!CreateTurnClientSocket()) { |
703 OnAllocateError(); | 703 OnAllocateError(); |
704 } | 704 } |
705 return; | 705 return; |
706 } | 706 } |
707 | 707 |
708 // Copy the original server address in |resolved_address|. For TLS based | 708 // Copy the original server address in |resolved_address|. For TLS based |
709 // sockets we need hostname along with resolved address. | 709 // sockets we need hostname along with resolved address. |
710 rtc::SocketAddress resolved_address = server_address_.address; | 710 rtc::SocketAddress resolved_address = server_address_.address; |
711 | 711 if (resolver_->GetError() != 0 || |
712 bool found = resolver_->GetError() == 0 && | 712 !resolver_->GetResolvedAddress(Network()->GetBestIP().family(), |
713 resolver_->GetResolvedAddress(Network()->GetBestIP().family(), | 713 &resolved_address)) { |
714 &resolved_address); | 714 LOG_J(LS_WARNING, this) << "TURN host lookup received error " |
715 if (event_log_) { | 715 << resolver_->GetError(); |
716 int error = resolver_->GetError(); | |
717 event_log_->LogHostLookupResult( | |
718 found ? 0 : (error == 0 ? -1 : error), | |
719 resolver_->GetResolveElapsedTimeMilliseconds()); | |
720 } | |
721 | |
722 if (!found) { | |
723 LOG_J(LS_WARNING, this) | |
724 << "TURN host lookup for " << resolved_address.hostname() | |
725 << " received error " << resolver_->GetError() << " after " | |
726 << resolver_->GetResolveElapsedTimeMilliseconds() << " ms"; | |
727 error_ = resolver_->GetError(); | 716 error_ = resolver_->GetError(); |
728 OnAllocateError(); | 717 OnAllocateError(); |
729 return; | 718 return; |
730 } | 719 } |
731 | |
732 LOG_J(LS_INFO, this) << "TURN host lookup for " << resolved_address.hostname() | |
733 << " completed in " | |
734 << resolver_->GetResolveElapsedTimeMilliseconds() | |
735 << " ms"; | |
736 | |
737 // Signal needs both resolved and unresolved address. After signal is sent | 720 // Signal needs both resolved and unresolved address. After signal is sent |
738 // we can copy resolved address back into |server_address_|. | 721 // we can copy resolved address back into |server_address_|. |
739 SignalResolvedServerAddress(this, server_address_.address, | 722 SignalResolvedServerAddress(this, server_address_.address, |
740 resolved_address); | 723 resolved_address); |
741 server_address_.address = resolved_address; | 724 server_address_.address = resolved_address; |
742 PrepareAddress(); | 725 PrepareAddress(); |
743 } | 726 } |
744 | 727 |
745 void TurnPort::OnSendStunPacket(const void* data, size_t size, | 728 void TurnPort::OnSendStunPacket(const void* data, size_t size, |
746 StunRequest* request) { | 729 StunRequest* request) { |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 } else { | 1591 } else { |
1609 state_ = STATE_UNBOUND; | 1592 state_ = STATE_UNBOUND; |
1610 port_->FailAndPruneConnection(ext_addr_); | 1593 port_->FailAndPruneConnection(ext_addr_); |
1611 } | 1594 } |
1612 } | 1595 } |
1613 void TurnEntry::OnChannelBindTimeout() { | 1596 void TurnEntry::OnChannelBindTimeout() { |
1614 state_ = STATE_UNBOUND; | 1597 state_ = STATE_UNBOUND; |
1615 port_->FailAndPruneConnection(ext_addr_); | 1598 port_->FailAndPruneConnection(ext_addr_); |
1616 } | 1599 } |
1617 } // namespace cricket | 1600 } // namespace cricket |
OLD | NEW |