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 <memory> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "webrtc/base/asyncpacketsocket.h" | 16 #include "webrtc/base/asyncpacketsocket.h" |
17 #include "webrtc/base/asyncresolverinterface.h" | 17 #include "webrtc/base/asyncresolverinterface.h" |
18 #include "webrtc/base/bind.h" | 18 #include "webrtc/base/bind.h" |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
21 #include "webrtc/base/helpers.h" | 21 #include "webrtc/base/helpers.h" |
22 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
23 #include "webrtc/base/timeutils.h" | 23 #include "webrtc/base/timeutils.h" |
24 #include "webrtc/base/thread.h" | 24 #include "webrtc/base/thread.h" |
| 25 #include "webrtc/base/thread_scope.h" |
25 #include "webrtc/p2p/base/packetsocketfactory.h" | 26 #include "webrtc/p2p/base/packetsocketfactory.h" |
26 #include "webrtc/p2p/base/stun.h" | 27 #include "webrtc/p2p/base/stun.h" |
27 #include "webrtc/p2p/stunprober/stunprober.h" | 28 #include "webrtc/p2p/stunprober/stunprober.h" |
28 | 29 |
29 namespace stunprober { | 30 namespace stunprober { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const int THREAD_WAKE_UP_INTERVAL_MS = 5; | 34 const int THREAD_WAKE_UP_INTERVAL_MS = 5; |
34 | 35 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 91 |
91 StunProber* prober_; | 92 StunProber* prober_; |
92 | 93 |
93 // The socket for this session. | 94 // The socket for this session. |
94 std::unique_ptr<rtc::AsyncPacketSocket> socket_; | 95 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
95 | 96 |
96 // Temporary SocketAddress and buffer for RecvFrom. | 97 // Temporary SocketAddress and buffer for RecvFrom. |
97 rtc::SocketAddress addr_; | 98 rtc::SocketAddress addr_; |
98 std::unique_ptr<rtc::ByteBufferWriter> response_packet_; | 99 std::unique_ptr<rtc::ByteBufferWriter> response_packet_; |
99 | 100 |
100 std::vector<Request*> requests_; | 101 std::vector<Request*> requests_ GUARDED_BY(thread_checker_); |
101 std::vector<rtc::SocketAddress> server_ips_; | 102 std::vector<rtc::SocketAddress> server_ips_; |
102 int16_t num_request_sent_ = 0; | 103 int16_t num_request_sent_ = 0; |
103 int16_t num_response_received_ = 0; | 104 int16_t num_response_received_ = 0; |
104 | 105 |
105 rtc::ThreadChecker& thread_checker_; | 106 rtc::ThreadChecker& thread_checker_; |
106 | 107 |
107 RTC_DISALLOW_COPY_AND_ASSIGN(Requester); | 108 RTC_DISALLOW_COPY_AND_ASSIGN(Requester); |
108 }; | 109 }; |
109 | 110 |
110 StunProber::Requester::Requester( | 111 StunProber::Requester::Requester( |
(...skipping 14 matching lines...) Expand all Loading... |
125 socket_->Close(); | 126 socket_->Close(); |
126 } | 127 } |
127 for (auto req : requests_) { | 128 for (auto req : requests_) { |
128 if (req) { | 129 if (req) { |
129 delete req; | 130 delete req; |
130 } | 131 } |
131 } | 132 } |
132 } | 133 } |
133 | 134 |
134 void StunProber::Requester::SendStunRequest() { | 135 void StunProber::Requester::SendStunRequest() { |
135 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 136 RTC_DCHECK_RUN_ON(&thread_checker_); |
136 requests_.push_back(new Request()); | 137 requests_.push_back(new Request()); |
137 Request& request = *(requests_.back()); | 138 Request& request = *(requests_.back()); |
138 cricket::StunMessage message; | 139 cricket::StunMessage message; |
139 | 140 |
140 // Random transaction ID, STUN_BINDING_REQUEST | 141 // Random transaction ID, STUN_BINDING_REQUEST |
141 message.SetTransactionID( | 142 message.SetTransactionID( |
142 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); | 143 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); |
143 message.SetType(cricket::STUN_BINDING_REQUEST); | 144 message.SetType(cricket::STUN_BINDING_REQUEST); |
144 | 145 |
145 std::unique_ptr<rtc::ByteBufferWriter> request_packet( | 146 std::unique_ptr<rtc::ByteBufferWriter> request_packet( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 prober_->ReportOnFinished(GENERIC_FAILURE); | 213 prober_->ReportOnFinished(GENERIC_FAILURE); |
213 return; | 214 return; |
214 } | 215 } |
215 | 216 |
216 num_response_received_++; | 217 num_response_received_++; |
217 request->ProcessResponse(buf, size); | 218 request->ProcessResponse(buf, size); |
218 } | 219 } |
219 | 220 |
220 StunProber::Requester::Request* StunProber::Requester::GetRequestByAddress( | 221 StunProber::Requester::Request* StunProber::Requester::GetRequestByAddress( |
221 const rtc::IPAddress& ipaddr) { | 222 const rtc::IPAddress& ipaddr) { |
222 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 223 RTC_DCHECK_RUN_ON(&thread_checker_); |
223 for (auto request : requests_) { | 224 for (auto request : requests_) { |
224 if (request->server_addr == ipaddr) { | 225 if (request->server_addr == ipaddr) { |
225 return request; | 226 return request; |
226 } | 227 } |
227 } | 228 } |
228 | 229 |
229 return nullptr; | 230 return nullptr; |
230 } | 231 } |
231 | 232 |
232 StunProber::StunProber(rtc::PacketSocketFactory* socket_factory, | 233 StunProber::StunProber(rtc::PacketSocketFactory* socket_factory, |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 } | 564 } |
564 } | 565 } |
565 | 566 |
566 void StunProber::ReportOnFinished(StunProber::Status status) { | 567 void StunProber::ReportOnFinished(StunProber::Status status) { |
567 if (observer_) { | 568 if (observer_) { |
568 observer_->OnFinished(this, status); | 569 observer_->OnFinished(this, status); |
569 } | 570 } |
570 } | 571 } |
571 | 572 |
572 } // namespace stunprober | 573 } // namespace stunprober |
OLD | NEW |