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

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

Issue 1288843003: Revert "Generate localhost candidate when no STUN/TURN and portallocator has the right flag spefied… (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"
19 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
20 #include "webrtc/base/nethelpers.h" 19 #include "webrtc/base/nethelpers.h"
21 20
22 namespace cricket { 21 namespace cricket {
23 22
24 // TODO: Move these to a common place (used in relayport too) 23 // TODO: Move these to a common place (used in relayport too)
25 const int KEEPALIVE_DELAY = 10 * 1000; // 10 seconds - sort timeouts 24 const int KEEPALIVE_DELAY = 10 * 1000; // 10 seconds - sort timeouts
26 const int RETRY_DELAY = 50; // 50ms, from ICE spec 25 const int RETRY_DELAY = 50; // 50ms, from ICE spec
27 const int RETRY_TIMEOUT = 50 * 1000; // ICE says 50 secs 26 const int RETRY_TIMEOUT = 50 * 1000; // ICE says 50 secs
28 27
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 157 }
159 } 158 }
160 } 159 }
161 160
162 UDPPort::UDPPort(rtc::Thread* thread, 161 UDPPort::UDPPort(rtc::Thread* thread,
163 rtc::PacketSocketFactory* factory, 162 rtc::PacketSocketFactory* factory,
164 rtc::Network* network, 163 rtc::Network* network,
165 rtc::AsyncPacketSocket* socket, 164 rtc::AsyncPacketSocket* socket,
166 const std::string& username, 165 const std::string& username,
167 const std::string& password, 166 const std::string& password,
168 const std::string& origin, 167 const std::string& origin)
169 bool emit_localhost_for_anyaddress)
170 : Port(thread, factory, network, socket->GetLocalAddress().ipaddr(), 168 : Port(thread, factory, network, socket->GetLocalAddress().ipaddr(),
171 username, password), 169 username, password),
172 requests_(thread), 170 requests_(thread),
173 socket_(socket), 171 socket_(socket),
174 error_(0), 172 error_(0),
175 ready_(false), 173 ready_(false),
176 stun_keepalive_delay_(KEEPALIVE_DELAY), 174 stun_keepalive_delay_(KEEPALIVE_DELAY) {
177 emit_localhost_for_anyaddress_(emit_localhost_for_anyaddress) {
178 requests_.set_origin(origin); 175 requests_.set_origin(origin);
179 } 176 }
180 177
181 UDPPort::UDPPort(rtc::Thread* thread, 178 UDPPort::UDPPort(rtc::Thread* thread,
182 rtc::PacketSocketFactory* factory, 179 rtc::PacketSocketFactory* factory,
183 rtc::Network* network, 180 rtc::Network* network,
184 const rtc::IPAddress& ip, 181 const rtc::IPAddress& ip,
185 uint16 min_port, 182 uint16 min_port,
186 uint16 max_port, 183 uint16 max_port,
187 const std::string& username, 184 const std::string& username,
188 const std::string& password, 185 const std::string& password,
189 const std::string& origin, 186 const std::string& origin)
190 bool emit_localhost_for_anyaddress)
191 : Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port, 187 : Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port,
192 username, password), 188 username, password),
193 requests_(thread), 189 requests_(thread),
194 socket_(NULL), 190 socket_(NULL),
195 error_(0), 191 error_(0),
196 ready_(false), 192 ready_(false),
197 stun_keepalive_delay_(KEEPALIVE_DELAY), 193 stun_keepalive_delay_(KEEPALIVE_DELAY) {
198 emit_localhost_for_anyaddress_(emit_localhost_for_anyaddress) {
199 requests_.set_origin(origin); 194 requests_.set_origin(origin);
200 } 195 }
201 196
202 bool UDPPort::Init() { 197 bool UDPPort::Init() {
203 if (!SharedSocket()) { 198 if (!SharedSocket()) {
204 ASSERT(socket_ == NULL); 199 ASSERT(socket_ == NULL);
205 socket_ = socket_factory()->CreateUdpSocket( 200 socket_ = socket_factory()->CreateUdpSocket(
206 rtc::SocketAddress(ip(), 0), min_port(), max_port()); 201 rtc::SocketAddress(ip(), 0), min_port(), max_port());
207 if (!socket_) { 202 if (!socket_) {
208 LOG_J(LS_WARNING, this) << "UDP socket creation failed"; 203 LOG_J(LS_WARNING, this) << "UDP socket creation failed";
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 int UDPPort::GetOption(rtc::Socket::Option opt, int* value) { 273 int UDPPort::GetOption(rtc::Socket::Option opt, int* value) {
279 return socket_->GetOption(opt, value); 274 return socket_->GetOption(opt, value);
280 } 275 }
281 276
282 int UDPPort::GetError() { 277 int UDPPort::GetError() {
283 return error_; 278 return error_;
284 } 279 }
285 280
286 void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket, 281 void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket,
287 const rtc::SocketAddress& address) { 282 const rtc::SocketAddress& address) {
288 // When adapter enumeration is disabled and binding to the any address, the 283 AddAddress(address, address, rtc::SocketAddress(),
289 // loopback address will be issued as a candidate instead if 284 UDP_PROTOCOL_NAME, "", LOCAL_PORT_TYPE,
290 // |emit_localhost_for_anyaddress| is true. This is to allow connectivity on 285 ICE_TYPE_PREFERENCE_HOST, 0, false);
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);
299 MaybePrepareStunCandidate(); 286 MaybePrepareStunCandidate();
300 } 287 }
301 288
302 void UDPPort::OnReadPacket( 289 void UDPPort::OnReadPacket(
303 rtc::AsyncPacketSocket* socket, const char* data, size_t size, 290 rtc::AsyncPacketSocket* socket, const char* data, size_t size,
304 const rtc::SocketAddress& remote_addr, 291 const rtc::SocketAddress& remote_addr,
305 const rtc::PacketTime& packet_time) { 292 const rtc::PacketTime& packet_time) {
306 ASSERT(socket == socket_); 293 ASSERT(socket == socket_);
307 ASSERT(!remote_addr.IsUnresolved()); 294 ASSERT(!remote_addr.IsUnresolved());
308 295
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 const std::vector<Candidate>& existing_candidates = Candidates(); 450 const std::vector<Candidate>& existing_candidates = Candidates();
464 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); 451 std::vector<Candidate>::const_iterator it = existing_candidates.begin();
465 for (; it != existing_candidates.end(); ++it) { 452 for (; it != existing_candidates.end(); ++it) {
466 if (it->address() == addr) 453 if (it->address() == addr)
467 return true; 454 return true;
468 } 455 }
469 return false; 456 return false;
470 } 457 }
471 458
472 } // namespace cricket 459 } // 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