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

Side by Side Diff: webrtc/p2p/stunprober/stunprober.cc

Issue 1162263012: Add SocketFactoryInterface::Prepare and fix how symmetric NAT is determined (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 6 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/stunprober/stunprober.h ('k') | webrtc/p2p/stunprober/stunprober_dependencies.h » ('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 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 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
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 rtc::scoped_ptr<rtc::ByteBuffer> request_packet( 67 rtc::scoped_ptr<rtc::ByteBuffer> request_packet(
68 new rtc::ByteBuffer(nullptr, kMaxUdpBufferSize)); 68 new rtc::ByteBuffer(nullptr, kMaxUdpBufferSize));
69 if (!message.Write(request_packet.get())) { 69 if (!message.Write(request_packet.get())) {
70 prober_->End(WRITE_FAILED, 0); 70 prober_->End(WRITE_FAILED, 0);
71 return; 71 return;
72 } 72 }
73 73
74 auto addr = server_ips_[num_request_sent_]; 74 auto addr = server_ips_[num_request_sent_];
75 request.server_addr = addr.ipaddr(); 75 request.server_addr = addr.ipaddr();
76 76
77 int rv = 0;
78
79 // Only bind to the interface at the first request.
80 if (num_request_sent_ == 0) {
81 rtc::IPAddress local_addr;
82 rv = prober_->GetLocalAddress(&local_addr);
83 if (rv != 0) {
84 prober_->End(GENERIC_FAILURE, rv);
85 return;
86 }
87 rv = socket_->Bind(rtc::SocketAddress(local_addr, 0));
88 if (rv < 0) {
89 prober_->End(GENERIC_FAILURE, rv);
90 return;
91 }
92 }
93
94 // The write must succeed immediately. Otherwise, the calculating of the STUN 77 // The write must succeed immediately. Otherwise, the calculating of the STUN
95 // request timing could become too complicated. Callback is ignored by passing 78 // request timing could become too complicated. Callback is ignored by passing
96 // empty AsyncCallback. 79 // empty AsyncCallback.
97 rv = socket_->SendTo(addr, const_cast<char*>(request_packet->Data()), 80 int rv = socket_->SendTo(addr, const_cast<char*>(request_packet->Data()),
98 request_packet->Length(), AsyncCallback()); 81 request_packet->Length(), AsyncCallback());
99 if (rv < 0) { 82 if (rv < 0) {
100 prober_->End(WRITE_FAILED, rv); 83 prober_->End(WRITE_FAILED, rv);
101 return; 84 return;
102 } 85 }
103 86
104 request.sent_time_ms = rtc::Time(); 87 request.sent_time_ms = rtc::Time();
105 88
106 // Post a read waiting for response. For share mode, the subsequent read will 89 // Post a read waiting for response. For share mode, the subsequent read will
107 // be posted inside OnStunResponseReceived. 90 // be posted inside OnStunResponseReceived.
108 if (num_request_sent_ == 0) { 91 if (num_request_sent_ == 0) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 std::set<rtc::SocketAddress> addrs(all_servers_ips_.begin(), 255 std::set<rtc::SocketAddress> addrs(all_servers_ips_.begin(),
273 all_servers_ips_.end()); 256 all_servers_ips_.end());
274 all_servers_ips_.assign(addrs.begin(), addrs.end()); 257 all_servers_ips_.assign(addrs.begin(), addrs.end());
275 258
276 rtc::IPAddress addr; 259 rtc::IPAddress addr;
277 if (GetLocalAddress(&addr) != 0) { 260 if (GetLocalAddress(&addr) != 0) {
278 End(GENERIC_FAILURE, result); 261 End(GENERIC_FAILURE, result);
279 return; 262 return;
280 } 263 }
281 264
282 MaybeScheduleStunRequests(); 265 socket_factory_->Prepare(GetTotalClientSockets(), GetTotalServerSockets(),
266 [this](int result) {
267 if (result == 0) {
268 this->MaybeScheduleStunRequests();
269 }
270 });
283 } 271 }
284 272
285 int StunProber::GetLocalAddress(rtc::IPAddress* addr) { 273 int StunProber::GetLocalAddress(rtc::IPAddress* addr) {
286 DCHECK(thread_checker_.CalledOnValidThread()); 274 DCHECK(thread_checker_.CalledOnValidThread());
287 if (local_addr_.family() == AF_UNSPEC) { 275 if (local_addr_.family() == AF_UNSPEC) {
288 rtc::SocketAddress sock_addr; 276 rtc::SocketAddress sock_addr;
289 rtc::scoped_ptr<ClientSocketInterface> socket( 277 rtc::scoped_ptr<ClientSocketInterface> socket(
290 socket_factory_->CreateClientSocket()); 278 socket_factory_->CreateClientSocket());
291 int rv = socket->Connect(all_servers_ips_[0]); 279 int rv = socket->Connect(all_servers_ips_[0]);
292 if (rv != SUCCESS) { 280 if (rv != SUCCESS) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 421
434 // Shared mode is only true if we use the shared socket and there are more 422 // Shared mode is only true if we use the shared socket and there are more
435 // than 1 responding servers. 423 // than 1 responding servers.
436 stats.shared_socket_mode = 424 stats.shared_socket_mode =
437 shared_socket_mode_ && (num_server_ip_with_response > 1); 425 shared_socket_mode_ && (num_server_ip_with_response > 1);
438 426
439 stats.host_ip = local_addr_.ToString(); 427 stats.host_ip = local_addr_.ToString();
440 stats.num_request_sent = num_sent; 428 stats.num_request_sent = num_sent;
441 stats.num_response_received = num_received; 429 stats.num_response_received = num_received;
442 stats.target_request_interval_ns = interval_ms_ * 1000; 430 stats.target_request_interval_ns = interval_ms_ * 1000;
431 stats.symmetric_nat =
432 stats.srflx_addrs.size() > static_cast<size_t>(GetTotalServerSockets());
443 433
444 if (num_sent) { 434 if (num_sent) {
445 stats.success_percent = static_cast<int>(100 * num_received / num_sent); 435 stats.success_percent = static_cast<int>(100 * num_received / num_sent);
446 } 436 }
447 437
448 if (num_sent > 1) { 438 if (num_sent > 1) {
449 stats.actual_request_interval_ns = 439 stats.actual_request_interval_ns =
450 (1000 * (last_sent_time - first_sent_time)) / (num_sent - 1); 440 (1000 * (last_sent_time - first_sent_time)) / (num_sent - 1);
451 } 441 }
452 442
(...skipping 10 matching lines...) Expand all
463 if (!finished_callback_.empty()) { 453 if (!finished_callback_.empty()) {
464 AsyncCallback callback = finished_callback_; 454 AsyncCallback callback = finished_callback_;
465 finished_callback_ = AsyncCallback(); 455 finished_callback_ = AsyncCallback();
466 456
467 // Callback at the last since the prober might be deleted in the callback. 457 // Callback at the last since the prober might be deleted in the callback.
468 callback(status); 458 callback(status);
469 } 459 }
470 } 460 }
471 461
472 } // namespace stunprober 462 } // namespace stunprober
OLDNEW
« no previous file with comments | « webrtc/p2p/stunprober/stunprober.h ('k') | webrtc/p2p/stunprober/stunprober_dependencies.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698