OLD | NEW |
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 |
11 #include <map> | 11 #include <map> |
| 12 #include <memory> |
12 #include <set> | 13 #include <set> |
13 #include <string> | 14 #include <string> |
14 | 15 |
15 #include "webrtc/base/asyncpacketsocket.h" | 16 #include "webrtc/base/asyncpacketsocket.h" |
16 #include "webrtc/base/asyncresolverinterface.h" | 17 #include "webrtc/base/asyncresolverinterface.h" |
17 #include "webrtc/base/bind.h" | 18 #include "webrtc/base/bind.h" |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/helpers.h" | 21 #include "webrtc/base/helpers.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 bool Done() { | 84 bool Done() { |
84 return static_cast<size_t>(num_request_sent_) == server_ips_.size(); | 85 return static_cast<size_t>(num_request_sent_) == server_ips_.size(); |
85 } | 86 } |
86 | 87 |
87 private: | 88 private: |
88 Request* GetRequestByAddress(const rtc::IPAddress& ip); | 89 Request* GetRequestByAddress(const rtc::IPAddress& ip); |
89 | 90 |
90 StunProber* prober_; | 91 StunProber* prober_; |
91 | 92 |
92 // The socket for this session. | 93 // The socket for this session. |
93 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_; | 94 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
94 | 95 |
95 // Temporary SocketAddress and buffer for RecvFrom. | 96 // Temporary SocketAddress and buffer for RecvFrom. |
96 rtc::SocketAddress addr_; | 97 rtc::SocketAddress addr_; |
97 rtc::scoped_ptr<rtc::ByteBufferWriter> response_packet_; | 98 std::unique_ptr<rtc::ByteBufferWriter> response_packet_; |
98 | 99 |
99 std::vector<Request*> requests_; | 100 std::vector<Request*> requests_; |
100 std::vector<rtc::SocketAddress> server_ips_; | 101 std::vector<rtc::SocketAddress> server_ips_; |
101 int16_t num_request_sent_ = 0; | 102 int16_t num_request_sent_ = 0; |
102 int16_t num_response_received_ = 0; | 103 int16_t num_response_received_ = 0; |
103 | 104 |
104 rtc::ThreadChecker& thread_checker_; | 105 rtc::ThreadChecker& thread_checker_; |
105 | 106 |
106 RTC_DISALLOW_COPY_AND_ASSIGN(Requester); | 107 RTC_DISALLOW_COPY_AND_ASSIGN(Requester); |
107 }; | 108 }; |
(...skipping 26 matching lines...) Expand all Loading... |
134 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 135 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
135 requests_.push_back(new Request()); | 136 requests_.push_back(new Request()); |
136 Request& request = *(requests_.back()); | 137 Request& request = *(requests_.back()); |
137 cricket::StunMessage message; | 138 cricket::StunMessage message; |
138 | 139 |
139 // Random transaction ID, STUN_BINDING_REQUEST | 140 // Random transaction ID, STUN_BINDING_REQUEST |
140 message.SetTransactionID( | 141 message.SetTransactionID( |
141 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); | 142 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); |
142 message.SetType(cricket::STUN_BINDING_REQUEST); | 143 message.SetType(cricket::STUN_BINDING_REQUEST); |
143 | 144 |
144 rtc::scoped_ptr<rtc::ByteBufferWriter> request_packet( | 145 std::unique_ptr<rtc::ByteBufferWriter> request_packet( |
145 new rtc::ByteBufferWriter(nullptr, kMaxUdpBufferSize)); | 146 new rtc::ByteBufferWriter(nullptr, kMaxUdpBufferSize)); |
146 if (!message.Write(request_packet.get())) { | 147 if (!message.Write(request_packet.get())) { |
147 prober_->ReportOnFinished(WRITE_FAILED); | 148 prober_->ReportOnFinished(WRITE_FAILED); |
148 return; | 149 return; |
149 } | 150 } |
150 | 151 |
151 auto addr = server_ips_[num_request_sent_]; | 152 auto addr = server_ips_[num_request_sent_]; |
152 request.server_addr = addr.ipaddr(); | 153 request.server_addr = addr.ipaddr(); |
153 | 154 |
154 // The write must succeed immediately. Otherwise, the calculating of the STUN | 155 // The write must succeed immediately. Otherwise, the calculating of the STUN |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 return; | 339 return; |
339 } | 340 } |
340 | 341 |
341 // Dedupe. | 342 // Dedupe. |
342 std::set<rtc::SocketAddress> addrs(all_servers_addrs_.begin(), | 343 std::set<rtc::SocketAddress> addrs(all_servers_addrs_.begin(), |
343 all_servers_addrs_.end()); | 344 all_servers_addrs_.end()); |
344 all_servers_addrs_.assign(addrs.begin(), addrs.end()); | 345 all_servers_addrs_.assign(addrs.begin(), addrs.end()); |
345 | 346 |
346 // Prepare all the sockets beforehand. All of them will bind to "any" address. | 347 // Prepare all the sockets beforehand. All of them will bind to "any" address. |
347 while (sockets_.size() < total_socket_required()) { | 348 while (sockets_.size() < total_socket_required()) { |
348 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket( | 349 std::unique_ptr<rtc::AsyncPacketSocket> socket( |
349 socket_factory_->CreateUdpSocket(rtc::SocketAddress(INADDR_ANY, 0), 0, | 350 socket_factory_->CreateUdpSocket(rtc::SocketAddress(INADDR_ANY, 0), 0, |
350 0)); | 351 0)); |
351 if (!socket) { | 352 if (!socket) { |
352 ReportOnPrepared(GENERIC_FAILURE); | 353 ReportOnPrepared(GENERIC_FAILURE); |
353 return; | 354 return; |
354 } | 355 } |
355 // Chrome and WebRTC behave differently in terms of the state of a socket | 356 // Chrome and WebRTC behave differently in terms of the state of a socket |
356 // once returned from PacketSocketFactory::CreateUdpSocket. | 357 // once returned from PacketSocketFactory::CreateUdpSocket. |
357 if (socket->GetState() == rtc::AsyncPacketSocket::STATE_BINDING) { | 358 if (socket->GetState() == rtc::AsyncPacketSocket::STATE_BINDING) { |
358 socket->SignalAddressReady.connect(this, &StunProber::OnSocketReady); | 359 socket->SignalAddressReady.connect(this, &StunProber::OnSocketReady); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 563 } |
563 } | 564 } |
564 | 565 |
565 void StunProber::ReportOnFinished(StunProber::Status status) { | 566 void StunProber::ReportOnFinished(StunProber::Status status) { |
566 if (observer_) { | 567 if (observer_) { |
567 observer_->OnFinished(this, status); | 568 observer_->OnFinished(this, status); |
568 } | 569 } |
569 } | 570 } |
570 | 571 |
571 } // namespace stunprober | 572 } // namespace stunprober |
OLD | NEW |