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

Side by Side Diff: webrtc/p2p/base/port_unittest.cc

Issue 2063823008: Adding IceConfig option to assume TURN/TURN candidate pairs will work. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Responding to comments. Doing "presumed writable" determination in Connection. Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 int code = 0; 135 int code = 0;
136 if (last_stun_msg_) { 136 if (last_stun_msg_) {
137 const StunErrorCodeAttribute* error_attr = last_stun_msg_->GetErrorCode(); 137 const StunErrorCodeAttribute* error_attr = last_stun_msg_->GetErrorCode();
138 if (error_attr) { 138 if (error_attr) {
139 code = error_attr->code(); 139 code = error_attr->code();
140 } 140 }
141 } 141 }
142 return code; 142 return code;
143 } 143 }
144 144
145 virtual void PrepareAddress() { 145 void PrepareAddress() override {
146 rtc::SocketAddress addr(ip(), min_port()); 146 rtc::SocketAddress addr(ip(), min_port());
147 AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(), 147 AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(),
148 ICE_TYPE_PREFERENCE_HOST, 0, true); 148 ICE_TYPE_PREFERENCE_HOST, 0, true);
149 } 149 }
150 150
151 virtual bool SupportsProtocol(const std::string& protocol) const { 151 bool SupportsProtocol(const std::string& protocol) const override {
152 return true; 152 return true;
153 } 153 }
154 154
155 // Exposed for testing candidate building. 155 // Exposed for testing candidate building.
156 void AddCandidateAddress(const rtc::SocketAddress& addr) { 156 void AddCandidateAddress(const rtc::SocketAddress& addr) {
157 AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(), 157 AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(),
158 type_preference_, 0, false); 158 type_preference_, 0, false);
159 } 159 }
160 void AddCandidateAddress(const rtc::SocketAddress& addr, 160 void AddCandidateAddress(const rtc::SocketAddress& addr,
161 const rtc::SocketAddress& base_address, 161 const rtc::SocketAddress& base_address,
162 const std::string& type, 162 const std::string& type,
163 int type_preference, 163 int type_preference,
164 bool final) { 164 bool final) {
165 AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type, 165 AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type,
166 type_preference, 0, final); 166 type_preference, 0, final);
167 } 167 }
168 168
169 virtual Connection* CreateConnection(const Candidate& remote_candidate, 169 Connection* CreateConnection(const Candidate& remote_candidate,
170 CandidateOrigin origin) { 170 CandidateOrigin origin,
171 Connection* conn = new ProxyConnection(this, 0, remote_candidate); 171 const IceConfig& config) override {
172 Connection* conn = new ProxyConnection(this, 0, remote_candidate, config);
172 AddOrReplaceConnection(conn); 173 AddOrReplaceConnection(conn);
173 // Set use-candidate attribute flag as this will add USE-CANDIDATE attribute 174 // Set use-candidate attribute flag as this will add USE-CANDIDATE attribute
174 // in STUN binding requests. 175 // in STUN binding requests.
175 conn->set_use_candidate_attr(true); 176 conn->set_use_candidate_attr(true);
176 return conn; 177 return conn;
177 } 178 }
178 virtual int SendTo( 179 int SendTo(const void* data,
179 const void* data, size_t size, const rtc::SocketAddress& addr, 180 size_t size,
180 const rtc::PacketOptions& options, bool payload) { 181 const rtc::SocketAddress& addr,
182 const rtc::PacketOptions& options,
183 bool payload) override {
181 if (!payload) { 184 if (!payload) {
182 IceMessage* msg = new IceMessage; 185 IceMessage* msg = new IceMessage;
183 Buffer* buf = new Buffer(static_cast<const char*>(data), size); 186 Buffer* buf = new Buffer(static_cast<const char*>(data), size);
184 ByteBufferReader read_buf(*buf); 187 ByteBufferReader read_buf(*buf);
185 if (!msg->Read(&read_buf)) { 188 if (!msg->Read(&read_buf)) {
186 delete msg; 189 delete msg;
187 delete buf; 190 delete buf;
188 return -1; 191 return -1;
189 } 192 }
190 last_stun_buf_.reset(buf); 193 last_stun_buf_.reset(buf);
191 last_stun_msg_.reset(msg); 194 last_stun_msg_.reset(msg);
192 } 195 }
193 return static_cast<int>(size); 196 return static_cast<int>(size);
194 } 197 }
195 virtual int SetOption(rtc::Socket::Option opt, int value) { 198 int SetOption(rtc::Socket::Option opt, int value) override { return 0; }
196 return 0; 199 int GetOption(rtc::Socket::Option opt, int* value) override { return -1; }
197 } 200 int GetError() override { return 0; }
198 virtual int GetOption(rtc::Socket::Option opt, int* value) {
199 return -1;
200 }
201 virtual int GetError() {
202 return 0;
203 }
204 void Reset() { 201 void Reset() {
205 last_stun_buf_.reset(); 202 last_stun_buf_.reset();
206 last_stun_msg_.reset(); 203 last_stun_msg_.reset();
207 } 204 }
208 void set_type_preference(int type_preference) { 205 void set_type_preference(int type_preference) {
209 type_preference_ = type_preference; 206 type_preference_ = type_preference;
210 } 207 }
211 208
212 private: 209 private:
213 void OnSentPacket(rtc::AsyncPacketSocket* socket, 210 void OnSentPacket(rtc::AsyncPacketSocket* socket,
214 const rtc::SentPacket& sent_packet) { 211 const rtc::SentPacket& sent_packet) override {
215 PortInterface::SignalSentPacket(sent_packet); 212 PortInterface::SignalSentPacket(sent_packet);
216 } 213 }
217 std::unique_ptr<Buffer> last_stun_buf_; 214 std::unique_ptr<Buffer> last_stun_buf_;
218 std::unique_ptr<IceMessage> last_stun_msg_; 215 std::unique_ptr<IceMessage> last_stun_msg_;
219 int type_preference_ = 0; 216 int type_preference_ = 0;
220 }; 217 };
221 218
222 class TestChannel : public sigslot::has_slots<> { 219 class TestChannel : public sigslot::has_slots<> {
223 public: 220 public:
224 // Takes ownership of |p1| (but not |p2|). 221 // Takes ownership of |p1| (but not |p2|).
225 TestChannel(Port* p1) 222 TestChannel(Port* p1)
226 : ice_mode_(ICEMODE_FULL), 223 : ice_mode_(ICEMODE_FULL),
227 port_(p1), 224 port_(p1),
228 complete_count_(0), 225 complete_count_(0),
229 conn_(NULL), 226 conn_(NULL),
230 remote_request_(), 227 remote_request_(),
231 nominated_(false) { 228 nominated_(false) {
232 port_->SignalPortComplete.connect(this, &TestChannel::OnPortComplete); 229 port_->SignalPortComplete.connect(this, &TestChannel::OnPortComplete);
233 port_->SignalUnknownAddress.connect(this, &TestChannel::OnUnknownAddress); 230 port_->SignalUnknownAddress.connect(this, &TestChannel::OnUnknownAddress);
234 port_->SignalDestroyed.connect(this, &TestChannel::OnSrcPortDestroyed); 231 port_->SignalDestroyed.connect(this, &TestChannel::OnSrcPortDestroyed);
235 } 232 }
236 233
237 int complete_count() { return complete_count_; } 234 int complete_count() { return complete_count_; }
238 Connection* conn() { return conn_; } 235 Connection* conn() { return conn_; }
239 const SocketAddress& remote_address() { return remote_address_; } 236 const SocketAddress& remote_address() { return remote_address_; }
240 const std::string remote_fragment() { return remote_frag_; } 237 const std::string remote_fragment() { return remote_frag_; }
241 238
242 void Start() { port_->PrepareAddress(); } 239 void Start() { port_->PrepareAddress(); }
243 void CreateConnection(const Candidate& remote_candidate) { 240 void CreateConnection(const Candidate& remote_candidate) {
244 conn_ = port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE); 241 conn_ = port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE,
242 IceConfig());
245 IceMode remote_ice_mode = 243 IceMode remote_ice_mode =
246 (ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL; 244 (ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL;
247 conn_->set_remote_ice_mode(remote_ice_mode); 245 conn_->set_remote_ice_mode(remote_ice_mode);
248 conn_->set_use_candidate_attr(remote_ice_mode == ICEMODE_FULL); 246 conn_->set_use_candidate_attr(remote_ice_mode == ICEMODE_FULL);
249 conn_->SignalStateChange.connect( 247 conn_->SignalStateChange.connect(
250 this, &TestChannel::OnConnectionStateChange); 248 this, &TestChannel::OnConnectionStateChange);
251 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); 249 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed);
252 conn_->SignalReadyToSend.connect(this, 250 conn_->SignalReadyToSend.connect(this,
253 &TestChannel::OnConnectionReadyToSend); 251 &TestChannel::OnConnectionReadyToSend);
254 connection_ready_to_send_ = false; 252 connection_ready_to_send_ = false;
255 } 253 }
256 void OnConnectionStateChange(Connection* conn) { 254 void OnConnectionStateChange(Connection* conn) {
257 if (conn->write_state() == Connection::STATE_WRITABLE) { 255 if (conn->write_state() == Connection::STATE_WRITABLE) {
258 conn->set_use_candidate_attr(true); 256 conn->set_use_candidate_attr(true);
259 nominated_ = true; 257 nominated_ = true;
260 } 258 }
261 } 259 }
262 void AcceptConnection(const Candidate& remote_candidate) { 260 void AcceptConnection(const Candidate& remote_candidate) {
263 ASSERT_TRUE(remote_request_.get() != NULL); 261 ASSERT_TRUE(remote_request_.get() != NULL);
264 Candidate c = remote_candidate; 262 Candidate c = remote_candidate;
265 c.set_address(remote_address_); 263 c.set_address(remote_address_);
266 conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE); 264 conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE, IceConfig());
267 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); 265 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed);
268 port_->SendBindingResponse(remote_request_.get(), remote_address_); 266 port_->SendBindingResponse(remote_request_.get(), remote_address_);
269 remote_request_.reset(); 267 remote_request_.reset();
270 } 268 }
271 void Ping() { 269 void Ping() {
272 Ping(0); 270 Ping(0);
273 } 271 }
274 void Ping(int64_t now) { conn_->Ping(now); } 272 void Ping(int64_t now) { conn_->Ping(now); }
275 void Stop() { 273 void Stop() {
276 if (conn_) { 274 if (conn_) {
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 private: 972 private:
975 AsyncPacketSocket* next_udp_socket_; 973 AsyncPacketSocket* next_udp_socket_;
976 AsyncPacketSocket* next_server_tcp_socket_; 974 AsyncPacketSocket* next_server_tcp_socket_;
977 AsyncPacketSocket* next_client_tcp_socket_; 975 AsyncPacketSocket* next_client_tcp_socket_;
978 }; 976 };
979 977
980 class FakeAsyncPacketSocket : public AsyncPacketSocket { 978 class FakeAsyncPacketSocket : public AsyncPacketSocket {
981 public: 979 public:
982 // Returns current local address. Address may be set to NULL if the 980 // Returns current local address. Address may be set to NULL if the
983 // socket is not bound yet (GetState() returns STATE_BINDING). 981 // socket is not bound yet (GetState() returns STATE_BINDING).
984 virtual SocketAddress GetLocalAddress() const { 982 SocketAddress GetLocalAddress() const override { return SocketAddress(); }
985 return SocketAddress();
986 }
987 983
988 // Returns remote address. Returns zeroes if this is not a client TCP socket. 984 // Returns remote address. Returns zeroes if this is not a client TCP socket.
989 virtual SocketAddress GetRemoteAddress() const { 985 SocketAddress GetRemoteAddress() const override { return SocketAddress(); }
990 return SocketAddress();
991 }
992 986
993 // Send a packet. 987 // Send a packet.
994 virtual int Send(const void *pv, size_t cb, 988 int Send(const void* pv,
995 const rtc::PacketOptions& options) { 989 size_t cb,
990 const rtc::PacketOptions& options) override {
996 return static_cast<int>(cb); 991 return static_cast<int>(cb);
997 } 992 }
998 virtual int SendTo(const void *pv, size_t cb, const SocketAddress& addr, 993 int SendTo(const void* pv,
999 const rtc::PacketOptions& options) { 994 size_t cb,
995 const SocketAddress& addr,
996 const rtc::PacketOptions& options) override {
1000 return static_cast<int>(cb); 997 return static_cast<int>(cb);
1001 } 998 }
1002 virtual int Close() { 999 int Close() override { return 0; }
1003 return 0;
1004 }
1005 1000
1006 virtual State GetState() const { return state_; } 1001 State GetState() const override { return state_; }
1007 virtual int GetOption(Socket::Option opt, int* value) { return 0; } 1002 int GetOption(Socket::Option opt, int* value) override { return 0; }
1008 virtual int SetOption(Socket::Option opt, int value) { return 0; } 1003 int SetOption(Socket::Option opt, int value) override { return 0; }
1009 virtual int GetError() const { return 0; } 1004 int GetError() const override { return 0; }
1010 virtual void SetError(int error) { } 1005 void SetError(int error) override {}
1011 1006
1012 void set_state(State state) { state_ = state; } 1007 void set_state(State state) { state_ = state; }
1013 1008
1014 private: 1009 private:
1015 State state_; 1010 State state_;
1016 }; 1011 };
1017 1012
1018 // Local -> XXXX 1013 // Local -> XXXX
1019 TEST_F(PortTest, TestLocalToLocal) { 1014 TEST_F(PortTest, TestLocalToLocal) {
1020 TestLocalToLocal(); 1015 TestLocalToLocal();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 // should remain equal to the request generated by the port and role of port 1319 // should remain equal to the request generated by the port and role of port
1325 // must be in controlling. 1320 // must be in controlling.
1326 TEST_F(PortTest, TestLoopbackCal) { 1321 TEST_F(PortTest, TestLoopbackCal) {
1327 std::unique_ptr<TestPort> lport( 1322 std::unique_ptr<TestPort> lport(
1328 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); 1323 CreateTestPort(kLocalAddr1, "lfrag", "lpass"));
1329 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); 1324 lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
1330 lport->SetIceTiebreaker(kTiebreaker1); 1325 lport->SetIceTiebreaker(kTiebreaker1);
1331 lport->PrepareAddress(); 1326 lport->PrepareAddress();
1332 ASSERT_FALSE(lport->Candidates().empty()); 1327 ASSERT_FALSE(lport->Candidates().empty());
1333 Connection* conn = lport->CreateConnection(lport->Candidates()[0], 1328 Connection* conn = lport->CreateConnection(lport->Candidates()[0],
1334 Port::ORIGIN_MESSAGE); 1329 Port::ORIGIN_MESSAGE, IceConfig());
1335 conn->Ping(0); 1330 conn->Ping(0);
1336 1331
1337 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1332 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1338 IceMessage* msg = lport->last_stun_msg(); 1333 IceMessage* msg = lport->last_stun_msg();
1339 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); 1334 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
1340 conn->OnReadPacket(lport->last_stun_buf()->data<char>(), 1335 conn->OnReadPacket(lport->last_stun_buf()->data<char>(),
1341 lport->last_stun_buf()->size(), 1336 lport->last_stun_buf()->size(),
1342 rtc::PacketTime()); 1337 rtc::PacketTime());
1343 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1338 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1344 msg = lport->last_stun_msg(); 1339 msg = lport->last_stun_msg();
1345 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); 1340 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type());
1346 1341
1347 // If the tiebreaker value is different from port, we expect a error 1342 // If the tiebreaker value is different from port, we expect a error
1348 // response. 1343 // response.
1349 lport->Reset(); 1344 lport->Reset();
1350 lport->AddCandidateAddress(kLocalAddr2); 1345 lport->AddCandidateAddress(kLocalAddr2);
1351 // Creating a different connection as |conn| is receiving. 1346 // Creating a different connection as |conn| is receiving.
1352 Connection* conn1 = lport->CreateConnection(lport->Candidates()[1], 1347 Connection* conn1 = lport->CreateConnection(
1353 Port::ORIGIN_MESSAGE); 1348 lport->Candidates()[1], Port::ORIGIN_MESSAGE, IceConfig());
1354 conn1->Ping(0); 1349 conn1->Ping(0);
1355 1350
1356 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1351 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1357 msg = lport->last_stun_msg(); 1352 msg = lport->last_stun_msg();
1358 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); 1353 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
1359 std::unique_ptr<IceMessage> modified_req( 1354 std::unique_ptr<IceMessage> modified_req(
1360 CreateStunMessage(STUN_BINDING_REQUEST)); 1355 CreateStunMessage(STUN_BINDING_REQUEST));
1361 const StunByteStringAttribute* username_attr = msg->GetByteString( 1356 const StunByteStringAttribute* username_attr = msg->GetByteString(
1362 STUN_ATTR_USERNAME); 1357 STUN_ATTR_USERNAME);
1363 modified_req->AddAttribute(new StunByteStringAttribute( 1358 modified_req->AddAttribute(new StunByteStringAttribute(
(...skipping 26 matching lines...) Expand all
1390 lport->SetIceTiebreaker(kTiebreaker1); 1385 lport->SetIceTiebreaker(kTiebreaker1);
1391 std::unique_ptr<TestPort> rport( 1386 std::unique_ptr<TestPort> rport(
1392 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); 1387 CreateTestPort(kLocalAddr2, "rfrag", "rpass"));
1393 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); 1388 rport->SetIceRole(cricket::ICEROLE_CONTROLLING);
1394 rport->SetIceTiebreaker(kTiebreaker2); 1389 rport->SetIceTiebreaker(kTiebreaker2);
1395 1390
1396 lport->PrepareAddress(); 1391 lport->PrepareAddress();
1397 rport->PrepareAddress(); 1392 rport->PrepareAddress();
1398 ASSERT_FALSE(lport->Candidates().empty()); 1393 ASSERT_FALSE(lport->Candidates().empty());
1399 ASSERT_FALSE(rport->Candidates().empty()); 1394 ASSERT_FALSE(rport->Candidates().empty());
1400 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], 1395 Connection* lconn = lport->CreateConnection(
1401 Port::ORIGIN_MESSAGE); 1396 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1402 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], 1397 Connection* rconn = rport->CreateConnection(
1403 Port::ORIGIN_MESSAGE); 1398 lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1404 rconn->Ping(0); 1399 rconn->Ping(0);
1405 1400
1406 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); 1401 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
1407 IceMessage* msg = rport->last_stun_msg(); 1402 IceMessage* msg = rport->last_stun_msg();
1408 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); 1403 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
1409 // Send rport binding request to lport. 1404 // Send rport binding request to lport.
1410 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), 1405 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(),
1411 rport->last_stun_buf()->size(), 1406 rport->last_stun_buf()->size(),
1412 rtc::PacketTime()); 1407 rtc::PacketTime());
1413 1408
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 socket->SignalAddressReady(socket, addresses[i]); 1474 socket->SignalAddressReady(socket, addresses[i]);
1480 ports[i]->PrepareAddress(); 1475 ports[i]->PrepareAddress();
1481 } 1476 }
1482 1477
1483 // IPv4 Port, connects to IPv6 candidate and then to IPv4 candidate. 1478 // IPv4 Port, connects to IPv6 candidate and then to IPv4 candidate.
1484 if (type == SOCK_STREAM) { 1479 if (type == SOCK_STREAM) {
1485 FakeAsyncPacketSocket* clientsocket = new FakeAsyncPacketSocket(); 1480 FakeAsyncPacketSocket* clientsocket = new FakeAsyncPacketSocket();
1486 factory.set_next_client_tcp_socket(clientsocket); 1481 factory.set_next_client_tcp_socket(clientsocket);
1487 } 1482 }
1488 Connection* c = ports[0]->CreateConnection(GetCandidate(ports[2].get()), 1483 Connection* c = ports[0]->CreateConnection(GetCandidate(ports[2].get()),
1489 Port::ORIGIN_MESSAGE); 1484 Port::ORIGIN_MESSAGE, IceConfig());
1490 EXPECT_TRUE(NULL == c); 1485 EXPECT_TRUE(NULL == c);
1491 EXPECT_EQ(0U, ports[0]->connections().size()); 1486 EXPECT_EQ(0U, ports[0]->connections().size());
1492 c = ports[0]->CreateConnection(GetCandidate(ports[1].get()), 1487 c = ports[0]->CreateConnection(GetCandidate(ports[1].get()),
1493 Port::ORIGIN_MESSAGE); 1488 Port::ORIGIN_MESSAGE, IceConfig());
1494 EXPECT_FALSE(NULL == c); 1489 EXPECT_FALSE(NULL == c);
1495 EXPECT_EQ(1U, ports[0]->connections().size()); 1490 EXPECT_EQ(1U, ports[0]->connections().size());
1496 1491
1497 // IPv6 Port, connects to IPv4 candidate and to IPv6 candidate. 1492 // IPv6 Port, connects to IPv4 candidate and to IPv6 candidate.
1498 if (type == SOCK_STREAM) { 1493 if (type == SOCK_STREAM) {
1499 FakeAsyncPacketSocket* clientsocket = new FakeAsyncPacketSocket(); 1494 FakeAsyncPacketSocket* clientsocket = new FakeAsyncPacketSocket();
1500 factory.set_next_client_tcp_socket(clientsocket); 1495 factory.set_next_client_tcp_socket(clientsocket);
1501 } 1496 }
1502 c = ports[2]->CreateConnection(GetCandidate(ports[0].get()), 1497 c = ports[2]->CreateConnection(GetCandidate(ports[0].get()),
1503 Port::ORIGIN_MESSAGE); 1498 Port::ORIGIN_MESSAGE, IceConfig());
1504 EXPECT_TRUE(NULL == c); 1499 EXPECT_TRUE(NULL == c);
1505 EXPECT_EQ(0U, ports[2]->connections().size()); 1500 EXPECT_EQ(0U, ports[2]->connections().size());
1506 c = ports[2]->CreateConnection(GetCandidate(ports[3].get()), 1501 c = ports[2]->CreateConnection(GetCandidate(ports[3].get()),
1507 Port::ORIGIN_MESSAGE); 1502 Port::ORIGIN_MESSAGE, IceConfig());
1508 EXPECT_FALSE(NULL == c); 1503 EXPECT_FALSE(NULL == c);
1509 EXPECT_EQ(1U, ports[2]->connections().size()); 1504 EXPECT_EQ(1U, ports[2]->connections().size());
1510 } 1505 }
1511 1506
1512 TEST_F(PortTest, TestSkipCrossFamilyTcp) { 1507 TEST_F(PortTest, TestSkipCrossFamilyTcp) {
1513 TestCrossFamilyPorts(SOCK_STREAM); 1508 TestCrossFamilyPorts(SOCK_STREAM);
1514 } 1509 }
1515 1510
1516 TEST_F(PortTest, TestSkipCrossFamilyUdp) { 1511 TEST_F(PortTest, TestSkipCrossFamilyUdp) {
1517 TestCrossFamilyPorts(SOCK_DGRAM); 1512 TestCrossFamilyPorts(SOCK_DGRAM);
1518 } 1513 }
1519 1514
1520 void PortTest::ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2) { 1515 void PortTest::ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2) {
1521 Connection* c = p1->CreateConnection(GetCandidate(p2), 1516 Connection* c =
1522 Port::ORIGIN_MESSAGE); 1517 p1->CreateConnection(GetCandidate(p2), Port::ORIGIN_MESSAGE, IceConfig());
1523 if (can_connect) { 1518 if (can_connect) {
1524 EXPECT_FALSE(NULL == c); 1519 EXPECT_FALSE(NULL == c);
1525 EXPECT_EQ(1U, p1->connections().size()); 1520 EXPECT_EQ(1U, p1->connections().size());
1526 } else { 1521 } else {
1527 EXPECT_TRUE(NULL == c); 1522 EXPECT_TRUE(NULL == c);
1528 EXPECT_EQ(0U, p1->connections().size()); 1523 EXPECT_EQ(0U, p1->connections().size());
1529 } 1524 }
1530 } 1525 }
1531 1526
1532 TEST_F(PortTest, TestUdpV6CrossTypePorts) { 1527 TEST_F(PortTest, TestUdpV6CrossTypePorts) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); 1600 lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
1606 lport->SetIceTiebreaker(kTiebreaker1); 1601 lport->SetIceTiebreaker(kTiebreaker1);
1607 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); 1602 rport->SetIceRole(cricket::ICEROLE_CONTROLLED);
1608 rport->SetIceTiebreaker(kTiebreaker2); 1603 rport->SetIceTiebreaker(kTiebreaker2);
1609 1604
1610 // Send a fake ping from lport to rport. 1605 // Send a fake ping from lport to rport.
1611 lport->PrepareAddress(); 1606 lport->PrepareAddress();
1612 rport->PrepareAddress(); 1607 rport->PrepareAddress();
1613 ASSERT_FALSE(rport->Candidates().empty()); 1608 ASSERT_FALSE(rport->Candidates().empty());
1614 Connection* lconn = lport->CreateConnection( 1609 Connection* lconn = lport->CreateConnection(
1615 rport->Candidates()[0], Port::ORIGIN_MESSAGE); 1610 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1616 Connection* rconn = rport->CreateConnection( 1611 Connection* rconn = rport->CreateConnection(
1617 lport->Candidates()[0], Port::ORIGIN_MESSAGE); 1612 lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1618 lconn->Ping(0); 1613 lconn->Ping(0);
1619 1614
1620 // Check that it's a proper BINDING-REQUEST. 1615 // Check that it's a proper BINDING-REQUEST.
1621 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1616 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1622 IceMessage* msg = lport->last_stun_msg(); 1617 IceMessage* msg = lport->last_stun_msg();
1623 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); 1618 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
1624 EXPECT_FALSE(msg->IsLegacy()); 1619 EXPECT_FALSE(msg->IsLegacy());
1625 const StunByteStringAttribute* username_attr = 1620 const StunByteStringAttribute* username_attr =
1626 msg->GetByteString(STUN_ATTR_USERNAME); 1621 msg->GetByteString(STUN_ATTR_USERNAME);
1627 ASSERT_TRUE(username_attr != NULL); 1622 ASSERT_TRUE(username_attr != NULL);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); 1765 lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
1771 lport->SetIceTiebreaker(kTiebreaker1); 1766 lport->SetIceTiebreaker(kTiebreaker1);
1772 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); 1767 rport->SetIceRole(cricket::ICEROLE_CONTROLLED);
1773 rport->SetIceTiebreaker(kTiebreaker2); 1768 rport->SetIceTiebreaker(kTiebreaker2);
1774 1769
1775 // Send a fake ping from lport to rport. 1770 // Send a fake ping from lport to rport.
1776 lport->PrepareAddress(); 1771 lport->PrepareAddress();
1777 rport->PrepareAddress(); 1772 rport->PrepareAddress();
1778 ASSERT_FALSE(rport->Candidates().empty()); 1773 ASSERT_FALSE(rport->Candidates().empty());
1779 Connection* lconn = lport->CreateConnection( 1774 Connection* lconn = lport->CreateConnection(
1780 rport->Candidates()[0], Port::ORIGIN_MESSAGE); 1775 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1781 lconn->Ping(0); 1776 lconn->Ping(0);
1782 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1777 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1783 IceMessage* msg = lport->last_stun_msg(); 1778 IceMessage* msg = lport->last_stun_msg();
1784 const StunUInt64Attribute* ice_controlling_attr = 1779 const StunUInt64Attribute* ice_controlling_attr =
1785 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); 1780 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING);
1786 ASSERT_TRUE(ice_controlling_attr != NULL); 1781 ASSERT_TRUE(ice_controlling_attr != NULL);
1787 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( 1782 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString(
1788 STUN_ATTR_USE_CANDIDATE); 1783 STUN_ATTR_USE_CANDIDATE);
1789 ASSERT_TRUE(use_candidate_attr != NULL); 1784 ASSERT_TRUE(use_candidate_attr != NULL);
1790 } 1785 }
(...skipping 21 matching lines...) Expand all
1812 } 1807 }
1813 1808
1814 // Change the network type to wifi. 1809 // Change the network type to wifi.
1815 SetNetworkType(rtc::ADAPTER_TYPE_WIFI); 1810 SetNetworkType(rtc::ADAPTER_TYPE_WIFI);
1816 EXPECT_EQ(rtc::kNetworkCostLow, lport->network_cost()); 1811 EXPECT_EQ(rtc::kNetworkCostLow, lport->network_cost());
1817 for (const cricket::Candidate& candidate : lport->Candidates()) { 1812 for (const cricket::Candidate& candidate : lport->Candidates()) {
1818 EXPECT_EQ(rtc::kNetworkCostLow, candidate.network_cost()); 1813 EXPECT_EQ(rtc::kNetworkCostLow, candidate.network_cost());
1819 } 1814 }
1820 1815
1821 // Add a connection and then change the network type. 1816 // Add a connection and then change the network type.
1822 Connection* lconn = 1817 Connection* lconn = lport->CreateConnection(
1823 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); 1818 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1824 // Change the network type to cellular. 1819 // Change the network type to cellular.
1825 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); 1820 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
1826 EXPECT_EQ(rtc::kNetworkCostHigh, lport->network_cost()); 1821 EXPECT_EQ(rtc::kNetworkCostHigh, lport->network_cost());
1827 for (const cricket::Candidate& candidate : lport->Candidates()) { 1822 for (const cricket::Candidate& candidate : lport->Candidates()) {
1828 EXPECT_EQ(rtc::kNetworkCostHigh, candidate.network_cost()); 1823 EXPECT_EQ(rtc::kNetworkCostHigh, candidate.network_cost());
1829 } 1824 }
1830 1825
1831 SetNetworkType(rtc::ADAPTER_TYPE_WIFI); 1826 SetNetworkType(rtc::ADAPTER_TYPE_WIFI);
1832 Connection* rconn = 1827 Connection* rconn = rport->CreateConnection(
1833 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); 1828 lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1834 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); 1829 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
1835 lconn->Ping(0); 1830 lconn->Ping(0);
1836 // The rconn's remote candidate cost is rtc::kNetworkCostLow, but the ping 1831 // The rconn's remote candidate cost is rtc::kNetworkCostLow, but the ping
1837 // contains an attribute of network cost of rtc::kNetworkCostHigh. Once the 1832 // contains an attribute of network cost of rtc::kNetworkCostHigh. Once the
1838 // message is handled in rconn, The rconn's remote candidate will have cost 1833 // message is handled in rconn, The rconn's remote candidate will have cost
1839 // rtc::kNetworkCostHigh; 1834 // rtc::kNetworkCostHigh;
1840 EXPECT_EQ(rtc::kNetworkCostLow, rconn->remote_candidate().network_cost()); 1835 EXPECT_EQ(rtc::kNetworkCostLow, rconn->remote_candidate().network_cost());
1841 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1836 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1842 IceMessage* msg = lport->last_stun_msg(); 1837 IceMessage* msg = lport->last_stun_msg();
1843 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); 1838 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
(...skipping 13 matching lines...) Expand all
1857 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); 1852 lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
1858 lport->SetIceTiebreaker(kTiebreaker1); 1853 lport->SetIceTiebreaker(kTiebreaker1);
1859 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); 1854 rport->SetIceRole(cricket::ICEROLE_CONTROLLED);
1860 rport->SetIceTiebreaker(kTiebreaker2); 1855 rport->SetIceTiebreaker(kTiebreaker2);
1861 1856
1862 uint16_t lnetwork_id = 9; 1857 uint16_t lnetwork_id = 9;
1863 lport->Network()->set_id(lnetwork_id); 1858 lport->Network()->set_id(lnetwork_id);
1864 // Send a fake ping from lport to rport. 1859 // Send a fake ping from lport to rport.
1865 lport->PrepareAddress(); 1860 lport->PrepareAddress();
1866 rport->PrepareAddress(); 1861 rport->PrepareAddress();
1867 Connection* lconn = 1862 Connection* lconn = lport->CreateConnection(
1868 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); 1863 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1869 lconn->Ping(0); 1864 lconn->Ping(0);
1870 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 1865 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
1871 IceMessage* msg = lport->last_stun_msg(); 1866 IceMessage* msg = lport->last_stun_msg();
1872 const StunUInt32Attribute* network_info_attr = 1867 const StunUInt32Attribute* network_info_attr =
1873 msg->GetUInt32(STUN_ATTR_NETWORK_INFO); 1868 msg->GetUInt32(STUN_ATTR_NETWORK_INFO);
1874 ASSERT_TRUE(network_info_attr != NULL); 1869 ASSERT_TRUE(network_info_attr != NULL);
1875 uint32_t network_info = network_info_attr->value(); 1870 uint32_t network_info = network_info_attr->value();
1876 EXPECT_EQ(lnetwork_id, network_info >> 16); 1871 EXPECT_EQ(lnetwork_id, network_info >> 16);
1877 // Default network has unknown type and cost kNetworkCostUnknown. 1872 // Default network has unknown type and cost kNetworkCostUnknown.
1878 EXPECT_EQ(rtc::kNetworkCostUnknown, network_info & 0xFFFF); 1873 EXPECT_EQ(rtc::kNetworkCostUnknown, network_info & 0xFFFF);
1879 1874
1880 // Set the network type to be cellular so its cost will be kNetworkCostHigh. 1875 // Set the network type to be cellular so its cost will be kNetworkCostHigh.
1881 // Send a fake ping from rport to lport. 1876 // Send a fake ping from rport to lport.
1882 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); 1877 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
1883 uint16_t rnetwork_id = 8; 1878 uint16_t rnetwork_id = 8;
1884 rport->Network()->set_id(rnetwork_id); 1879 rport->Network()->set_id(rnetwork_id);
1885 Connection* rconn = 1880 Connection* rconn = rport->CreateConnection(
1886 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); 1881 lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
1887 rconn->Ping(0); 1882 rconn->Ping(0);
1888 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); 1883 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
1889 msg = rport->last_stun_msg(); 1884 msg = rport->last_stun_msg();
1890 network_info_attr = msg->GetUInt32(STUN_ATTR_NETWORK_INFO); 1885 network_info_attr = msg->GetUInt32(STUN_ATTR_NETWORK_INFO);
1891 ASSERT_TRUE(network_info_attr != NULL); 1886 ASSERT_TRUE(network_info_attr != NULL);
1892 network_info = network_info_attr->value(); 1887 network_info = network_info_attr->value();
1893 EXPECT_EQ(rnetwork_id, network_info >> 16); 1888 EXPECT_EQ(rnetwork_id, network_info >> 16);
1894 EXPECT_EQ(rtc::kNetworkCostHigh, network_info & 0xFFFF); 1889 EXPECT_EQ(rtc::kNetworkCostHigh, network_info & 0xFFFF);
1895 } 1890 }
1896 1891
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 std::unique_ptr<TestPort> rport( 2139 std::unique_ptr<TestPort> rport(
2145 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); 2140 CreateTestPort(kLocalAddr2, "rfrag", "rpass"));
2146 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); 2141 rport->SetIceRole(cricket::ICEROLE_CONTROLLED);
2147 rport->SetIceTiebreaker(kTiebreaker2); 2142 rport->SetIceTiebreaker(kTiebreaker2);
2148 2143
2149 lport->PrepareAddress(); 2144 lport->PrepareAddress();
2150 rport->PrepareAddress(); 2145 rport->PrepareAddress();
2151 ASSERT_FALSE(lport->Candidates().empty()); 2146 ASSERT_FALSE(lport->Candidates().empty());
2152 ASSERT_FALSE(rport->Candidates().empty()); 2147 ASSERT_FALSE(rport->Candidates().empty());
2153 2148
2154 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], 2149 Connection* lconn = lport->CreateConnection(
2155 Port::ORIGIN_MESSAGE); 2150 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
2156 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], 2151 Connection* rconn = rport->CreateConnection(
2157 Port::ORIGIN_MESSAGE); 2152 lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
2158 rconn->Ping(0); 2153 rconn->Ping(0);
2159 2154
2160 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); 2155 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
2161 IceMessage* msg = rport->last_stun_msg(); 2156 IceMessage* msg = rport->last_stun_msg();
2162 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); 2157 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
2163 // Send rport binding request to lport. 2158 // Send rport binding request to lport.
2164 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), 2159 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(),
2165 rport->last_stun_buf()->size(), 2160 rport->last_stun_buf()->size(),
2166 rtc::PacketTime()); 2161 rtc::PacketTime());
2167 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); 2162 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 rport->AddCandidateAddress(SocketAddress("10.1.1.100", 1234)); 2370 rport->AddCandidateAddress(SocketAddress("10.1.1.100", 1234));
2376 2371
2377 EXPECT_EQ(0x7E001E85U, lport->Candidates()[0].priority()); 2372 EXPECT_EQ(0x7E001E85U, lport->Candidates()[0].priority());
2378 EXPECT_EQ(0x2001EE9U, rport->Candidates()[0].priority()); 2373 EXPECT_EQ(0x2001EE9U, rport->Candidates()[0].priority());
2379 2374
2380 // RFC 5245 2375 // RFC 5245
2381 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0) 2376 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0)
2382 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); 2377 lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
2383 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); 2378 rport->SetIceRole(cricket::ICEROLE_CONTROLLED);
2384 Connection* lconn = lport->CreateConnection( 2379 Connection* lconn = lport->CreateConnection(
2385 rport->Candidates()[0], Port::ORIGIN_MESSAGE); 2380 rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
2386 #if defined(WEBRTC_WIN) 2381 #if defined(WEBRTC_WIN)
2387 EXPECT_EQ(0x2001EE9FC003D0BU, lconn->priority()); 2382 EXPECT_EQ(0x2001EE9FC003D0BU, lconn->priority());
2388 #else 2383 #else
2389 EXPECT_EQ(0x2001EE9FC003D0BLLU, lconn->priority()); 2384 EXPECT_EQ(0x2001EE9FC003D0BLLU, lconn->priority());
2390 #endif 2385 #endif
2391 2386
2392 lport->SetIceRole(cricket::ICEROLE_CONTROLLED); 2387 lport->SetIceRole(cricket::ICEROLE_CONTROLLED);
2393 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); 2388 rport->SetIceRole(cricket::ICEROLE_CONTROLLING);
2394 Connection* rconn = rport->CreateConnection( 2389 Connection* rconn = rport->CreateConnection(
2395 lport->Candidates()[0], Port::ORIGIN_MESSAGE); 2390 lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
2396 #if defined(WEBRTC_WIN) 2391 #if defined(WEBRTC_WIN)
2397 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); 2392 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority());
2398 #else 2393 #else
2399 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); 2394 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority());
2400 #endif 2395 #endif
2401 } 2396 }
2402 2397
2403 TEST_F(PortTest, TestWritableState) { 2398 TEST_F(PortTest, TestWritableState) {
2404 UDPPort* port1 = CreateUdpPort(kLocalAddr1); 2399 UDPPort* port1 = CreateUdpPort(kLocalAddr1);
2405 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); 2400 port1->SetIceRole(cricket::ICEROLE_CONTROLLING);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2531 // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly 2526 // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly
2532 // from port. 2527 // from port.
2533 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); 2528 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000);
2534 IceMessage* msg = ice_full_port->last_stun_msg(); 2529 IceMessage* msg = ice_full_port->last_stun_msg();
2535 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); 2530 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL);
2536 2531
2537 // Respond with a BINDING-RESPONSE from litemode client. 2532 // Respond with a BINDING-RESPONSE from litemode client.
2538 // NOTE: Ideally we should't create connection at this stage from lite 2533 // NOTE: Ideally we should't create connection at this stage from lite
2539 // port, as it should be done only after receiving ping with USE_CANDIDATE. 2534 // port, as it should be done only after receiving ping with USE_CANDIDATE.
2540 // But we need a connection to send a response message. 2535 // But we need a connection to send a response message.
2541 ice_lite_port->CreateConnection( 2536 ice_lite_port->CreateConnection(ice_full_port->Candidates()[0],
2542 ice_full_port->Candidates()[0], cricket::Port::ORIGIN_MESSAGE); 2537 cricket::Port::ORIGIN_MESSAGE, IceConfig());
2543 std::unique_ptr<IceMessage> request(CopyStunMessage(msg)); 2538 std::unique_ptr<IceMessage> request(CopyStunMessage(msg));
2544 ice_lite_port->SendBindingResponse( 2539 ice_lite_port->SendBindingResponse(
2545 request.get(), ice_full_port->Candidates()[0].address()); 2540 request.get(), ice_full_port->Candidates()[0].address());
2546 2541
2547 // Feeding the respone message from litemode to the full mode connection. 2542 // Feeding the respone message from litemode to the full mode connection.
2548 ch1.conn()->OnReadPacket(ice_lite_port->last_stun_buf()->data<char>(), 2543 ch1.conn()->OnReadPacket(ice_lite_port->last_stun_buf()->data<char>(),
2549 ice_lite_port->last_stun_buf()->size(), 2544 ice_lite_port->last_stun_buf()->size(),
2550 rtc::PacketTime()); 2545 rtc::PacketTime());
2551 // Verifying full mode connection becomes writable from the response. 2546 // Verifying full mode connection becomes writable from the response.
2552 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), 2547 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 } 2687 }
2693 2688
2694 TEST_F(PortTest, TestAddConnectionWithSameAddress) { 2689 TEST_F(PortTest, TestAddConnectionWithSameAddress) {
2695 std::unique_ptr<TestPort> port( 2690 std::unique_ptr<TestPort> port(
2696 CreateTestPort(kLocalAddr1, "ufrag1", "password1")); 2691 CreateTestPort(kLocalAddr1, "ufrag1", "password1"));
2697 port->PrepareAddress(); 2692 port->PrepareAddress();
2698 EXPECT_EQ(1u, port->Candidates().size()); 2693 EXPECT_EQ(1u, port->Candidates().size());
2699 rtc::SocketAddress address("1.1.1.1", 5000); 2694 rtc::SocketAddress address("1.1.1.1", 5000);
2700 cricket::Candidate candidate(1, "udp", address, 0, "", "", "relay", 0, ""); 2695 cricket::Candidate candidate(1, "udp", address, 0, "", "", "relay", 0, "");
2701 cricket::Connection* conn1 = 2696 cricket::Connection* conn1 =
2702 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); 2697 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE, IceConfig());
2703 cricket::Connection* conn_in_use = port->GetConnection(address); 2698 cricket::Connection* conn_in_use = port->GetConnection(address);
2704 EXPECT_EQ(conn1, conn_in_use); 2699 EXPECT_EQ(conn1, conn_in_use);
2705 EXPECT_EQ(0u, conn_in_use->remote_candidate().generation()); 2700 EXPECT_EQ(0u, conn_in_use->remote_candidate().generation());
2706 2701
2707 // Creating with a candidate with the same address again will get us a 2702 // Creating with a candidate with the same address again will get us a
2708 // different connection with the new candidate. 2703 // different connection with the new candidate.
2709 candidate.set_generation(2); 2704 candidate.set_generation(2);
2710 cricket::Connection* conn2 = 2705 cricket::Connection* conn2 =
2711 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); 2706 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE, IceConfig());
2712 EXPECT_NE(conn1, conn2); 2707 EXPECT_NE(conn1, conn2);
2713 conn_in_use = port->GetConnection(address); 2708 conn_in_use = port->GetConnection(address);
2714 EXPECT_EQ(conn2, conn_in_use); 2709 EXPECT_EQ(conn2, conn_in_use);
2715 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); 2710 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation());
2716 2711
2717 // Make sure the new connection was not deleted. 2712 // Make sure the new connection was not deleted.
2718 rtc::Thread::Current()->ProcessMessages(300); 2713 rtc::Thread::Current()->ProcessMessages(300);
2719 EXPECT_TRUE(port->GetConnection(address) != nullptr); 2714 EXPECT_TRUE(port->GetConnection(address) != nullptr);
2720 } 2715 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698