OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 #if defined(WEBRTC_POSIX) | 10 #if defined(WEBRTC_POSIX) |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 void CreateTurnPort(const rtc::SocketAddress& local_address, | 194 void CreateTurnPort(const rtc::SocketAddress& local_address, |
195 const std::string& username, | 195 const std::string& username, |
196 const std::string& password, | 196 const std::string& password, |
197 const cricket::ProtocolAddress& server_address) { | 197 const cricket::ProtocolAddress& server_address) { |
198 cricket::RelayCredentials credentials(username, password); | 198 cricket::RelayCredentials credentials(username, password); |
199 turn_port_.reset(TurnPort::Create(main_, &socket_factory_, &network_, | 199 turn_port_.reset(TurnPort::Create(main_, &socket_factory_, &network_, |
200 local_address.ipaddr(), 0, 0, | 200 local_address.ipaddr(), 0, 0, |
201 kIceUfrag1, kIcePwd1, | 201 kIceUfrag1, kIcePwd1, |
202 server_address, credentials, 0, | 202 server_address, credentials, 0, |
203 std::string())); | 203 std::string())); |
204 // Set ICE protocol type to ICEPROTO_RFC5245, as port by default will be | |
205 // in Hybrid mode. Protocol type is necessary to send correct type STUN ping | |
206 // messages. | |
207 // This TURN port will be the controlling. | 204 // This TURN port will be the controlling. |
208 turn_port_->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
209 turn_port_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 205 turn_port_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
210 ConnectSignals(); | 206 ConnectSignals(); |
211 } | 207 } |
212 | 208 |
213 // Should be identical to CreateTurnPort but specifies an origin value | 209 // Should be identical to CreateTurnPort but specifies an origin value |
214 // when creating the instance of TurnPort. | 210 // when creating the instance of TurnPort. |
215 void CreateTurnPortWithOrigin(const rtc::SocketAddress& local_address, | 211 void CreateTurnPortWithOrigin(const rtc::SocketAddress& local_address, |
216 const std::string& username, | 212 const std::string& username, |
217 const std::string& password, | 213 const std::string& password, |
218 const cricket::ProtocolAddress& server_address, | 214 const cricket::ProtocolAddress& server_address, |
219 const std::string& origin) { | 215 const std::string& origin) { |
220 cricket::RelayCredentials credentials(username, password); | 216 cricket::RelayCredentials credentials(username, password); |
221 turn_port_.reset(TurnPort::Create(main_, &socket_factory_, &network_, | 217 turn_port_.reset(TurnPort::Create(main_, &socket_factory_, &network_, |
222 local_address.ipaddr(), 0, 0, | 218 local_address.ipaddr(), 0, 0, |
223 kIceUfrag1, kIcePwd1, | 219 kIceUfrag1, kIcePwd1, |
224 server_address, credentials, 0, | 220 server_address, credentials, 0, |
225 origin)); | 221 origin)); |
226 // Set ICE protocol type to ICEPROTO_RFC5245, as port by default will be | |
227 // in Hybrid mode. Protocol type is necessary to send correct type STUN ping | |
228 // messages. | |
229 // This TURN port will be the controlling. | 222 // This TURN port will be the controlling. |
230 turn_port_->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
231 turn_port_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 223 turn_port_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
232 ConnectSignals(); | 224 ConnectSignals(); |
233 } | 225 } |
234 | 226 |
235 void CreateSharedTurnPort(const std::string& username, | 227 void CreateSharedTurnPort(const std::string& username, |
236 const std::string& password, | 228 const std::string& password, |
237 const cricket::ProtocolAddress& server_address) { | 229 const cricket::ProtocolAddress& server_address) { |
238 ASSERT(server_address.proto == cricket::PROTO_UDP); | 230 ASSERT(server_address.proto == cricket::PROTO_UDP); |
239 | 231 |
240 if (!socket_) { | 232 if (!socket_) { |
241 socket_.reset(socket_factory_.CreateUdpSocket( | 233 socket_.reset(socket_factory_.CreateUdpSocket( |
242 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0)); | 234 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0)); |
243 ASSERT_TRUE(socket_ != NULL); | 235 ASSERT_TRUE(socket_ != NULL); |
244 socket_->SignalReadPacket.connect( | 236 socket_->SignalReadPacket.connect( |
245 this, &TurnPortTest::OnSocketReadPacket); | 237 this, &TurnPortTest::OnSocketReadPacket); |
246 } | 238 } |
247 | 239 |
248 cricket::RelayCredentials credentials(username, password); | 240 cricket::RelayCredentials credentials(username, password); |
249 turn_port_.reset(cricket::TurnPort::Create( | 241 turn_port_.reset(cricket::TurnPort::Create( |
250 main_, &socket_factory_, &network_, socket_.get(), | 242 main_, &socket_factory_, &network_, socket_.get(), |
251 kIceUfrag1, kIcePwd1, server_address, credentials, 0, std::string())); | 243 kIceUfrag1, kIcePwd1, server_address, credentials, 0, std::string())); |
252 // Set ICE protocol type to ICEPROTO_RFC5245, as port by default will be | |
253 // in Hybrid mode. Protocol type is necessary to send correct type STUN ping | |
254 // messages. | |
255 // This TURN port will be the controlling. | 244 // This TURN port will be the controlling. |
256 turn_port_->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
257 turn_port_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 245 turn_port_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
258 ConnectSignals(); | 246 ConnectSignals(); |
259 } | 247 } |
260 | 248 |
261 void ConnectSignals() { | 249 void ConnectSignals() { |
262 turn_port_->SignalPortComplete.connect(this, | 250 turn_port_->SignalPortComplete.connect(this, |
263 &TurnPortTest::OnTurnPortComplete); | 251 &TurnPortTest::OnTurnPortComplete); |
264 turn_port_->SignalPortError.connect(this, | 252 turn_port_->SignalPortError.connect(this, |
265 &TurnPortTest::OnTurnPortError); | 253 &TurnPortTest::OnTurnPortError); |
266 turn_port_->SignalUnknownAddress.connect(this, | 254 turn_port_->SignalUnknownAddress.connect(this, |
267 &TurnPortTest::OnTurnUnknownAddress); | 255 &TurnPortTest::OnTurnUnknownAddress); |
268 turn_port_->SignalCreatePermissionResult.connect(this, | 256 turn_port_->SignalCreatePermissionResult.connect(this, |
269 &TurnPortTest::OnTurnCreatePermissionResult); | 257 &TurnPortTest::OnTurnCreatePermissionResult); |
270 } | 258 } |
271 void CreateUdpPort() { | 259 void CreateUdpPort() { |
272 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, | 260 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, |
273 kLocalAddr2.ipaddr(), 0, 0, | 261 kLocalAddr2.ipaddr(), 0, 0, |
274 kIceUfrag2, kIcePwd2, | 262 kIceUfrag2, kIcePwd2, |
275 std::string(), false)); | 263 std::string(), false)); |
276 // Set protocol type to RFC5245, as turn port is also in same mode. | |
277 // UDP port will be controlled. | 264 // UDP port will be controlled. |
278 udp_port_->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
279 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 265 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
280 udp_port_->SignalPortComplete.connect( | 266 udp_port_->SignalPortComplete.connect( |
281 this, &TurnPortTest::OnUdpPortComplete); | 267 this, &TurnPortTest::OnUdpPortComplete); |
282 } | 268 } |
283 | 269 |
284 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { | 270 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { |
285 std::vector<rtc::SocketAddress> redirect_addresses; | 271 std::vector<rtc::SocketAddress> redirect_addresses; |
286 redirect_addresses.push_back(kTurnAlternateIntAddr); | 272 redirect_addresses.push_back(kTurnAlternateIntAddr); |
287 | 273 |
288 cricket::TestTurnRedirector redirector(redirect_addresses); | 274 cricket::TestTurnRedirector redirector(redirect_addresses); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 turn_port_->PrepareAddress(); | 807 turn_port_->PrepareAddress(); |
822 ASSERT_TRUE_WAIT(turn_error_, kTimeout); | 808 ASSERT_TRUE_WAIT(turn_error_, kTimeout); |
823 EXPECT_TRUE(turn_port_->Candidates().empty()); | 809 EXPECT_TRUE(turn_port_->Candidates().empty()); |
824 turn_port_.reset(); | 810 turn_port_.reset(); |
825 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); | 811 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); |
826 // Waiting for above message to be processed. | 812 // Waiting for above message to be processed. |
827 ASSERT_TRUE_WAIT(test_finish_, kTimeout); | 813 ASSERT_TRUE_WAIT(test_finish_, kTimeout); |
828 EXPECT_EQ(last_fd_count, GetFDCount()); | 814 EXPECT_EQ(last_fd_count, GetFDCount()); |
829 } | 815 } |
830 #endif | 816 #endif |
OLD | NEW |