Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(968)

Side by Side Diff: webrtc/p2p/base/stunport.cc

Issue 1275703006: Bug 4517: Enable connectivity for demo page when no STUN/TURN specifiefd. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | webrtc/p2p/base/stunport_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/stunport.h" 11 #include "webrtc/p2p/base/stunport.h"
12 12
13 #include "webrtc/p2p/base/common.h" 13 #include "webrtc/p2p/base/common.h"
14 #include "webrtc/p2p/base/portallocator.h" 14 #include "webrtc/p2p/base/portallocator.h"
15 #include "webrtc/p2p/base/stun.h" 15 #include "webrtc/p2p/base/stun.h"
16 #include "webrtc/base/common.h" 16 #include "webrtc/base/common.h"
17 #include "webrtc/base/helpers.h" 17 #include "webrtc/base/helpers.h"
18 #include "webrtc/base/ipaddress.h"
18 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
19 #include "webrtc/base/nethelpers.h" 20 #include "webrtc/base/nethelpers.h"
20 21
21 namespace cricket { 22 namespace cricket {
22 23
23 // TODO: Move these to a common place (used in relayport too) 24 // TODO: Move these to a common place (used in relayport too)
24 const int KEEPALIVE_DELAY = 10 * 1000; // 10 seconds - sort timeouts 25 const int KEEPALIVE_DELAY = 10 * 1000; // 10 seconds - sort timeouts
25 const int RETRY_DELAY = 50; // 50ms, from ICE spec 26 const int RETRY_DELAY = 50; // 50ms, from ICE spec
26 const int RETRY_TIMEOUT = 50 * 1000; // ICE says 50 secs 27 const int RETRY_TIMEOUT = 50 * 1000; // ICE says 50 secs
27 28
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 } 159 }
159 } 160 }
160 161
161 UDPPort::UDPPort(rtc::Thread* thread, 162 UDPPort::UDPPort(rtc::Thread* thread,
162 rtc::PacketSocketFactory* factory, 163 rtc::PacketSocketFactory* factory,
163 rtc::Network* network, 164 rtc::Network* network,
164 rtc::AsyncPacketSocket* socket, 165 rtc::AsyncPacketSocket* socket,
165 const std::string& username, 166 const std::string& username,
166 const std::string& password, 167 const std::string& password,
167 const std::string& origin) 168 const std::string& origin,
169 bool emit_localhost_for_anyaddress)
168 : Port(thread, factory, network, socket->GetLocalAddress().ipaddr(), 170 : Port(thread, factory, network, socket->GetLocalAddress().ipaddr(),
169 username, password), 171 username, password),
170 requests_(thread), 172 requests_(thread),
171 socket_(socket), 173 socket_(socket),
172 error_(0), 174 error_(0),
173 ready_(false), 175 ready_(false),
174 stun_keepalive_delay_(KEEPALIVE_DELAY) { 176 stun_keepalive_delay_(KEEPALIVE_DELAY),
177 emit_localhost_for_anyaddress_(emit_localhost_for_anyaddress) {
175 requests_.set_origin(origin); 178 requests_.set_origin(origin);
176 } 179 }
177 180
178 UDPPort::UDPPort(rtc::Thread* thread, 181 UDPPort::UDPPort(rtc::Thread* thread,
179 rtc::PacketSocketFactory* factory, 182 rtc::PacketSocketFactory* factory,
180 rtc::Network* network, 183 rtc::Network* network,
181 const rtc::IPAddress& ip, 184 const rtc::IPAddress& ip,
182 uint16 min_port, 185 uint16 min_port,
183 uint16 max_port, 186 uint16 max_port,
184 const std::string& username, 187 const std::string& username,
185 const std::string& password, 188 const std::string& password,
186 const std::string& origin) 189 const std::string& origin,
190 bool emit_localhost_for_anyaddress)
187 : Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port, 191 : Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port,
188 username, password), 192 username, password),
189 requests_(thread), 193 requests_(thread),
190 socket_(NULL), 194 socket_(NULL),
191 error_(0), 195 error_(0),
192 ready_(false), 196 ready_(false),
193 stun_keepalive_delay_(KEEPALIVE_DELAY) { 197 stun_keepalive_delay_(KEEPALIVE_DELAY),
198 emit_localhost_for_anyaddress_(emit_localhost_for_anyaddress) {
194 requests_.set_origin(origin); 199 requests_.set_origin(origin);
195 } 200 }
196 201
197 bool UDPPort::Init() { 202 bool UDPPort::Init() {
198 if (!SharedSocket()) { 203 if (!SharedSocket()) {
199 ASSERT(socket_ == NULL); 204 ASSERT(socket_ == NULL);
200 socket_ = socket_factory()->CreateUdpSocket( 205 socket_ = socket_factory()->CreateUdpSocket(
201 rtc::SocketAddress(ip(), 0), min_port(), max_port()); 206 rtc::SocketAddress(ip(), 0), min_port(), max_port());
202 if (!socket_) { 207 if (!socket_) {
203 LOG_J(LS_WARNING, this) << "UDP socket creation failed"; 208 LOG_J(LS_WARNING, this) << "UDP socket creation failed";
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 int UDPPort::GetOption(rtc::Socket::Option opt, int* value) { 278 int UDPPort::GetOption(rtc::Socket::Option opt, int* value) {
274 return socket_->GetOption(opt, value); 279 return socket_->GetOption(opt, value);
275 } 280 }
276 281
277 int UDPPort::GetError() { 282 int UDPPort::GetError() {
278 return error_; 283 return error_;
279 } 284 }
280 285
281 void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket, 286 void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket,
282 const rtc::SocketAddress& address) { 287 const rtc::SocketAddress& address) {
283 AddAddress(address, address, rtc::SocketAddress(), 288 // When adapter enumeration is disabled and binding to the any address, the
284 UDP_PROTOCOL_NAME, "", LOCAL_PORT_TYPE, 289 // loopback address will be issued as a candidate instead if
285 ICE_TYPE_PREFERENCE_HOST, 0, false); 290 // |emit_localhost_for_anyaddress| is true. This is to allow connectivity on
291 // demo pages without STUN/TURN to work.
292 rtc::SocketAddress addr = address;
293 if (addr.IsAnyIP() && emit_localhost_for_anyaddress_) {
294 addr.SetIP(rtc::GetLoopbackIP(addr.family()));
295 }
296
297 AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "",
298 LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, false);
286 MaybePrepareStunCandidate(); 299 MaybePrepareStunCandidate();
287 } 300 }
288 301
289 void UDPPort::OnReadPacket( 302 void UDPPort::OnReadPacket(
290 rtc::AsyncPacketSocket* socket, const char* data, size_t size, 303 rtc::AsyncPacketSocket* socket, const char* data, size_t size,
291 const rtc::SocketAddress& remote_addr, 304 const rtc::SocketAddress& remote_addr,
292 const rtc::PacketTime& packet_time) { 305 const rtc::PacketTime& packet_time) {
293 ASSERT(socket == socket_); 306 ASSERT(socket == socket_);
294 ASSERT(!remote_addr.IsUnresolved()); 307 ASSERT(!remote_addr.IsUnresolved());
295 308
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 const std::vector<Candidate>& existing_candidates = Candidates(); 463 const std::vector<Candidate>& existing_candidates = Candidates();
451 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); 464 std::vector<Candidate>::const_iterator it = existing_candidates.begin();
452 for (; it != existing_candidates.end(); ++it) { 465 for (; it != existing_candidates.end(); ++it) {
453 if (it->address() == addr) 466 if (it->address() == addr)
454 return true; 467 return true;
455 } 468 }
456 return false; 469 return false;
457 } 470 }
458 471
459 } // namespace cricket 472 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | webrtc/p2p/base/stunport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698