OLD | NEW |
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_CLIENT_FAKEPORTALLOCATOR_H_ |
12 #define WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ | 12 #define WEBRTC_P2P_CLIENT_FAKEPORTALLOCATOR_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | |
17 | 16 |
18 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 17 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
19 #include "webrtc/p2p/base/portallocator.h" | 18 #include "webrtc/p2p/base/portallocator.h" |
20 #include "webrtc/p2p/base/udpport.h" | 19 #include "webrtc/p2p/base/udpport.h" |
21 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
22 | 21 |
23 namespace rtc { | 22 namespace rtc { |
24 class SocketFactory; | 23 class SocketFactory; |
25 class Thread; | 24 class Thread; |
26 } | 25 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 username, | 77 username, |
79 password, | 78 password, |
80 origin, | 79 origin, |
81 emit_localhost_for_anyaddress) {} | 80 emit_localhost_for_anyaddress) {} |
82 | 81 |
83 bool sent_binding_response_ = false; | 82 bool sent_binding_response_ = false; |
84 }; | 83 }; |
85 | 84 |
86 class FakePortAllocatorSession : public PortAllocatorSession { | 85 class FakePortAllocatorSession : public PortAllocatorSession { |
87 public: | 86 public: |
88 FakePortAllocatorSession(PortAllocator* allocator, | 87 FakePortAllocatorSession(rtc::Thread* worker_thread, |
89 rtc::Thread* worker_thread, | |
90 rtc::PacketSocketFactory* factory, | 88 rtc::PacketSocketFactory* factory, |
91 const std::string& content_name, | 89 const std::string& content_name, |
92 int component, | 90 int component, |
93 const std::string& ice_ufrag, | 91 const std::string& ice_ufrag, |
94 const std::string& ice_pwd) | 92 const std::string& ice_pwd) |
95 : PortAllocatorSession(content_name, | 93 : PortAllocatorSession(content_name, component, ice_ufrag, ice_pwd, |
96 component, | 94 cricket::kDefaultPortAllocatorFlags), |
97 ice_ufrag, | |
98 ice_pwd, | |
99 allocator->flags()), | |
100 worker_thread_(worker_thread), | 95 worker_thread_(worker_thread), |
101 factory_(factory), | 96 factory_(factory), |
102 network_("network", "unittest", rtc::IPAddress(INADDR_LOOPBACK), 8), | 97 network_("network", "unittest", |
103 port_(), | 98 rtc::IPAddress(INADDR_LOOPBACK), 8), |
104 running_(false), | 99 port_(), running_(false), |
105 port_config_count_(0), | 100 port_config_count_(0) { |
106 stun_servers_(allocator->stun_servers()), | |
107 turn_servers_(allocator->turn_servers()), | |
108 candidate_filter_(allocator->candidate_filter()) { | |
109 network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); | 101 network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); |
110 } | 102 } |
111 | 103 |
112 void StartGettingPorts() override { | 104 virtual void StartGettingPorts() { |
113 if (!port_) { | 105 if (!port_) { |
114 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network_, | 106 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network_, |
115 network_.GetBestIP(), 0, 0, username(), | 107 network_.GetBestIP(), 0, 0, username(), |
116 password(), std::string(), false)); | 108 password(), std::string(), false)); |
117 AddPort(port_.get()); | 109 AddPort(port_.get()); |
118 } | 110 } |
119 ++port_config_count_; | 111 ++port_config_count_; |
120 running_ = true; | 112 running_ = true; |
121 } | 113 } |
122 | 114 |
123 void StopGettingPorts() override { running_ = false; } | 115 virtual void StopGettingPorts() { running_ = false; } |
124 bool IsGettingPorts() override { return running_; } | 116 virtual bool IsGettingPorts() { return running_; } |
125 void ClearGettingPorts() override {} | 117 virtual void ClearGettingPorts() {} |
126 std::vector<PortInterface*> ReadyPorts() const override { | |
127 return ready_ports_; | |
128 } | |
129 std::vector<Candidate> ReadyCandidates() const override { | |
130 return candidates_; | |
131 } | |
132 bool CandidatesAllocationDone() const override { return allocation_done_; } | |
133 | 118 |
134 int port_config_count() { return port_config_count_; } | 119 int port_config_count() { return port_config_count_; } |
135 | 120 |
136 const ServerAddresses& stun_servers() const { return stun_servers_; } | |
137 | |
138 const std::vector<RelayServerConfig>& turn_servers() const { | |
139 return turn_servers_; | |
140 } | |
141 | |
142 uint32_t candidate_filter() const { return candidate_filter_; } | |
143 | |
144 void AddPort(cricket::Port* port) { | 121 void AddPort(cricket::Port* port) { |
145 port->set_component(component()); | 122 port->set_component(component_); |
146 port->set_generation(generation()); | 123 port->set_generation(generation()); |
147 port->SignalPortComplete.connect(this, | 124 port->SignalPortComplete.connect( |
148 &FakePortAllocatorSession::OnPortComplete); | 125 this, &FakePortAllocatorSession::OnPortComplete); |
149 port->PrepareAddress(); | 126 port->PrepareAddress(); |
150 ready_ports_.push_back(port); | |
151 SignalPortReady(this, port); | 127 SignalPortReady(this, port); |
152 } | 128 } |
153 void OnPortComplete(cricket::Port* port) { | 129 void OnPortComplete(cricket::Port* port) { |
154 const std::vector<Candidate>& candidates = port->Candidates(); | 130 SignalCandidatesReady(this, port->Candidates()); |
155 candidates_.insert(candidates_.end(), candidates.begin(), candidates.end()); | |
156 SignalCandidatesReady(this, candidates); | |
157 | |
158 allocation_done_ = true; | |
159 SignalCandidatesAllocationDone(this); | 131 SignalCandidatesAllocationDone(this); |
160 } | 132 } |
161 | 133 |
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: | 134 private: |
174 rtc::Thread* worker_thread_; | 135 rtc::Thread* worker_thread_; |
175 rtc::PacketSocketFactory* factory_; | 136 rtc::PacketSocketFactory* factory_; |
176 rtc::Network network_; | 137 rtc::Network network_; |
177 std::unique_ptr<cricket::Port> port_; | 138 std::unique_ptr<cricket::Port> port_; |
178 bool running_; | 139 bool running_; |
179 int port_config_count_; | 140 int port_config_count_; |
180 std::vector<Candidate> candidates_; | |
181 std::vector<PortInterface*> ready_ports_; | |
182 bool allocation_done_ = false; | |
183 ServerAddresses stun_servers_; | |
184 std::vector<RelayServerConfig> turn_servers_; | |
185 uint32_t candidate_filter_; | |
186 int transport_info_update_count_ = 0; | |
187 }; | 141 }; |
188 | 142 |
189 class FakePortAllocator : public cricket::PortAllocator { | 143 class FakePortAllocator : public cricket::PortAllocator { |
190 public: | 144 public: |
191 FakePortAllocator(rtc::Thread* worker_thread, | 145 FakePortAllocator(rtc::Thread* worker_thread, |
192 rtc::PacketSocketFactory* factory) | 146 rtc::PacketSocketFactory* factory) |
193 : worker_thread_(worker_thread), factory_(factory) { | 147 : worker_thread_(worker_thread), factory_(factory) { |
194 if (factory_ == NULL) { | 148 if (factory_ == NULL) { |
195 owned_factory_.reset(new rtc::BasicPacketSocketFactory(worker_thread_)); | 149 owned_factory_.reset(new rtc::BasicPacketSocketFactory( |
| 150 worker_thread_)); |
196 factory_ = owned_factory_.get(); | 151 factory_ = owned_factory_.get(); |
197 } | 152 } |
198 } | 153 } |
199 | 154 |
| 155 void SetIceServers( |
| 156 const ServerAddresses& stun_servers, |
| 157 const std::vector<RelayServerConfig>& turn_servers) override { |
| 158 stun_servers_ = stun_servers; |
| 159 turn_servers_ = turn_servers; |
| 160 } |
| 161 |
200 void SetNetworkIgnoreMask(int network_ignore_mask) override {} | 162 void SetNetworkIgnoreMask(int network_ignore_mask) override {} |
201 | 163 |
202 cricket::PortAllocatorSession* CreateSessionInternal( | 164 const ServerAddresses& stun_servers() const { return stun_servers_; } |
| 165 |
| 166 const std::vector<RelayServerConfig>& turn_servers() const { |
| 167 return turn_servers_; |
| 168 } |
| 169 |
| 170 virtual cricket::PortAllocatorSession* CreateSessionInternal( |
203 const std::string& content_name, | 171 const std::string& content_name, |
204 int component, | 172 int component, |
205 const std::string& ice_ufrag, | 173 const std::string& ice_ufrag, |
206 const std::string& ice_pwd) override { | 174 const std::string& ice_pwd) override { |
207 return new FakePortAllocatorSession(this, worker_thread_, factory_, | 175 return new FakePortAllocatorSession( |
208 content_name, component, ice_ufrag, | 176 worker_thread_, factory_, content_name, component, ice_ufrag, ice_pwd); |
209 ice_pwd); | |
210 } | 177 } |
211 | 178 |
212 private: | 179 private: |
213 rtc::Thread* worker_thread_; | 180 rtc::Thread* worker_thread_; |
214 rtc::PacketSocketFactory* factory_; | 181 rtc::PacketSocketFactory* factory_; |
215 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; | 182 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; |
| 183 ServerAddresses stun_servers_; |
| 184 std::vector<RelayServerConfig> turn_servers_; |
216 }; | 185 }; |
217 | 186 |
218 } // namespace cricket | 187 } // namespace cricket |
219 | 188 |
220 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ | 189 #endif // WEBRTC_P2P_CLIENT_FAKEPORTALLOCATOR_H_ |
OLD | NEW |