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