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

Side by Side Diff: webrtc/p2p/base/fakeportallocator.h

Issue 2006423004: Making FakePortAllocator support IPv6. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | no next file » | 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 2010 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2010 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 #ifndef WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ 11 #ifndef WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
12 #define WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ 12 #define WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
13 13
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/nethelpers.h"
18 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 19 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
19 #include "webrtc/p2p/base/portallocator.h" 20 #include "webrtc/p2p/base/portallocator.h"
20 #include "webrtc/p2p/base/udpport.h" 21 #include "webrtc/p2p/base/udpport.h"
21 22
22 namespace rtc { 23 namespace rtc {
23 class SocketFactory; 24 class SocketFactory;
24 class Thread; 25 class Thread;
25 } 26 }
26 27
27 namespace cricket { 28 namespace cricket {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 min_port, 76 min_port,
76 max_port, 77 max_port,
77 username, 78 username,
78 password, 79 password,
79 origin, 80 origin,
80 emit_localhost_for_anyaddress) {} 81 emit_localhost_for_anyaddress) {}
81 82
82 bool sent_binding_response_ = false; 83 bool sent_binding_response_ = false;
83 }; 84 };
84 85
86 // A FakePortAllocatorSession can be used with either a real or fake socket
87 // factory. It gathers a single loopback port, using IPv6 if available and
88 // not disabled.
85 class FakePortAllocatorSession : public PortAllocatorSession { 89 class FakePortAllocatorSession : public PortAllocatorSession {
86 public: 90 public:
87 FakePortAllocatorSession(PortAllocator* allocator, 91 FakePortAllocatorSession(PortAllocator* allocator,
88 rtc::Thread* worker_thread, 92 rtc::Thread* worker_thread,
89 rtc::PacketSocketFactory* factory, 93 rtc::PacketSocketFactory* factory,
90 const std::string& content_name, 94 const std::string& content_name,
91 int component, 95 int component,
92 const std::string& ice_ufrag, 96 const std::string& ice_ufrag,
93 const std::string& ice_pwd) 97 const std::string& ice_pwd)
94 : PortAllocatorSession(content_name, 98 : PortAllocatorSession(content_name,
95 component, 99 component,
96 ice_ufrag, 100 ice_ufrag,
97 ice_pwd, 101 ice_pwd,
98 allocator->flags()), 102 allocator->flags()),
99 worker_thread_(worker_thread), 103 worker_thread_(worker_thread),
100 factory_(factory), 104 factory_(factory),
101 network_("network", "unittest", rtc::IPAddress(INADDR_LOOPBACK), 8), 105 ipv4_network_("network",
106 "unittest",
107 rtc::IPAddress(INADDR_LOOPBACK),
108 32),
109 ipv6_network_("network",
110 "unittest",
111 rtc::IPAddress(in6addr_loopback),
112 64),
102 port_(), 113 port_(),
103 running_(false), 114 running_(false),
104 port_config_count_(0), 115 port_config_count_(0),
105 stun_servers_(allocator->stun_servers()), 116 stun_servers_(allocator->stun_servers()),
106 turn_servers_(allocator->turn_servers()) { 117 turn_servers_(allocator->turn_servers()) {
107 network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); 118 ipv4_network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK));
119 ipv6_network_.AddIP(rtc::IPAddress(in6addr_loopback));
108 } 120 }
109 121
110 void SetCandidateFilter(uint32_t filter) override { 122 void SetCandidateFilter(uint32_t filter) override {
111 candidate_filter_ = filter; 123 candidate_filter_ = filter;
112 } 124 }
113 125
114 void StartGettingPorts() override { 126 void StartGettingPorts() override {
115 if (!port_) { 127 if (!port_) {
116 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network_, 128 rtc::Network& network =
117 network_.GetBestIP(), 0, 0, username(), 129 (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6))
130 ? ipv6_network_
131 : ipv4_network_;
132 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network,
133 network.GetBestIP(), 0, 0, username(),
118 password(), std::string(), false)); 134 password(), std::string(), false));
119 AddPort(port_.get()); 135 AddPort(port_.get());
120 } 136 }
121 ++port_config_count_; 137 ++port_config_count_;
122 running_ = true; 138 running_ = true;
123 } 139 }
124 140
125 void StopGettingPorts() override { running_ = false; } 141 void StopGettingPorts() override { running_ = false; }
126 bool IsGettingPorts() override { return running_; } 142 bool IsGettingPorts() override { return running_; }
127 void ClearGettingPorts() override {} 143 void ClearGettingPorts() override {}
128 std::vector<PortInterface*> ReadyPorts() const override { 144 std::vector<PortInterface*> ReadyPorts() const override {
129 return ready_ports_; 145 return ready_ports_;
130 } 146 }
131 std::vector<Candidate> ReadyCandidates() const override { 147 std::vector<Candidate> ReadyCandidates() const override {
132 return candidates_; 148 return candidates_;
133 } 149 }
134 bool CandidatesAllocationDone() const override { return allocation_done_; } 150 bool CandidatesAllocationDone() const override { return allocation_done_; }
135 151
136 int port_config_count() { return port_config_count_; } 152 int port_config_count() { return port_config_count_; }
137 153
138 const ServerAddresses& stun_servers() const { return stun_servers_; } 154 const ServerAddresses& stun_servers() const { return stun_servers_; }
139 155
140 const std::vector<RelayServerConfig>& turn_servers() const { 156 const std::vector<RelayServerConfig>& turn_servers() const {
141 return turn_servers_; 157 return turn_servers_;
142 } 158 }
143 159
144 uint32_t candidate_filter() const { return candidate_filter_; } 160 uint32_t candidate_filter() const { return candidate_filter_; }
145 161
162 int transport_info_update_count() const {
163 return transport_info_update_count_;
164 }
165
166 protected:
167 void UpdateIceParametersInternal() override {
168 // Since this class is a fake and this method only is overridden for tests,
169 // we don't need to actually update the transport info.
170 ++transport_info_update_count_;
171 }
172
173 private:
146 void AddPort(cricket::Port* port) { 174 void AddPort(cricket::Port* port) {
147 port->set_component(component()); 175 port->set_component(component());
148 port->set_generation(generation()); 176 port->set_generation(generation());
149 port->SignalPortComplete.connect(this, 177 port->SignalPortComplete.connect(this,
150 &FakePortAllocatorSession::OnPortComplete); 178 &FakePortAllocatorSession::OnPortComplete);
151 port->PrepareAddress(); 179 port->PrepareAddress();
152 ready_ports_.push_back(port); 180 ready_ports_.push_back(port);
153 SignalPortReady(this, port); 181 SignalPortReady(this, port);
154 } 182 }
155 void OnPortComplete(cricket::Port* port) { 183 void OnPortComplete(cricket::Port* port) {
156 const std::vector<Candidate>& candidates = port->Candidates(); 184 const std::vector<Candidate>& candidates = port->Candidates();
157 candidates_.insert(candidates_.end(), candidates.begin(), candidates.end()); 185 candidates_.insert(candidates_.end(), candidates.begin(), candidates.end());
158 SignalCandidatesReady(this, candidates); 186 SignalCandidatesReady(this, candidates);
159 187
160 allocation_done_ = true; 188 allocation_done_ = true;
161 SignalCandidatesAllocationDone(this); 189 SignalCandidatesAllocationDone(this);
162 } 190 }
163 191
164 int transport_info_update_count() const {
165 return transport_info_update_count_;
166 }
167
168 protected:
169 void UpdateIceParametersInternal() override {
170 // Since this class is a fake and this method only is overridden for tests,
171 // we don't need to actually update the transport info.
172 ++transport_info_update_count_;
173 }
174
175 private:
176 rtc::Thread* worker_thread_; 192 rtc::Thread* worker_thread_;
177 rtc::PacketSocketFactory* factory_; 193 rtc::PacketSocketFactory* factory_;
178 rtc::Network network_; 194 rtc::Network ipv4_network_;
195 rtc::Network ipv6_network_;
179 std::unique_ptr<cricket::Port> port_; 196 std::unique_ptr<cricket::Port> port_;
180 bool running_; 197 bool running_;
181 int port_config_count_; 198 int port_config_count_;
182 std::vector<Candidate> candidates_; 199 std::vector<Candidate> candidates_;
183 std::vector<PortInterface*> ready_ports_; 200 std::vector<PortInterface*> ready_ports_;
184 bool allocation_done_ = false; 201 bool allocation_done_ = false;
185 ServerAddresses stun_servers_; 202 ServerAddresses stun_servers_;
186 std::vector<RelayServerConfig> turn_servers_; 203 std::vector<RelayServerConfig> turn_servers_;
187 uint32_t candidate_filter_ = CF_ALL; 204 uint32_t candidate_filter_ = CF_ALL;
188 int transport_info_update_count_ = 0; 205 int transport_info_update_count_ = 0;
(...skipping 24 matching lines...) Expand all
213 230
214 private: 231 private:
215 rtc::Thread* worker_thread_; 232 rtc::Thread* worker_thread_;
216 rtc::PacketSocketFactory* factory_; 233 rtc::PacketSocketFactory* factory_;
217 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; 234 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_;
218 }; 235 };
219 236
220 } // namespace cricket 237 } // namespace cricket
221 238
222 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ 239 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698