OLD | NEW |
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 Candidate c = remote_candidate; | 259 Candidate c = remote_candidate; |
260 c.set_address(remote_address_); | 260 c.set_address(remote_address_); |
261 conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE); | 261 conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE); |
262 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); | 262 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); |
263 port_->SendBindingResponse(remote_request_.get(), remote_address_); | 263 port_->SendBindingResponse(remote_request_.get(), remote_address_); |
264 remote_request_.reset(); | 264 remote_request_.reset(); |
265 } | 265 } |
266 void Ping() { | 266 void Ping() { |
267 Ping(0); | 267 Ping(0); |
268 } | 268 } |
269 void Ping(uint32_t now) { conn_->Ping(now); } | 269 void Ping(int64_t now) { conn_->Ping(now); } |
270 void Stop() { | 270 void Stop() { |
271 if (conn_) { | 271 if (conn_) { |
272 conn_->Destroy(); | 272 conn_->Destroy(); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 void OnPortComplete(Port* port) { | 276 void OnPortComplete(Port* port) { |
277 complete_count_++; | 277 complete_count_++; |
278 } | 278 } |
279 void SetIceMode(IceMode ice_mode) { | 279 void SetIceMode(IceMode ice_mode) { |
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 1254 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
1255 TestChannel ch1(port1); | 1255 TestChannel ch1(port1); |
1256 TestChannel ch2(port2); | 1256 TestChannel ch2(port2); |
1257 // Acquire address. | 1257 // Acquire address. |
1258 ch1.Start(); | 1258 ch1.Start(); |
1259 ch2.Start(); | 1259 ch2.Start(); |
1260 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 1260 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
1261 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 1261 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); |
1262 | 1262 |
1263 // Test case that the connection has never received anything. | 1263 // Test case that the connection has never received anything. |
1264 uint32_t before_created = rtc::Time(); | 1264 int64_t before_created = rtc::Time64(); |
1265 ch1.CreateConnection(GetCandidate(port2)); | 1265 ch1.CreateConnection(GetCandidate(port2)); |
1266 uint32_t after_created = rtc::Time(); | 1266 int64_t after_created = rtc::Time64(); |
1267 Connection* conn = ch1.conn(); | 1267 Connection* conn = ch1.conn(); |
1268 ASSERT(conn != nullptr); | 1268 ASSERT(conn != nullptr); |
1269 // It is not dead if it is after MIN_CONNECTION_LIFETIME but not pruned. | 1269 // It is not dead if it is after MIN_CONNECTION_LIFETIME but not pruned. |
1270 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); | 1270 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); |
1271 rtc::Thread::Current()->ProcessMessages(0); | 1271 rtc::Thread::Current()->ProcessMessages(0); |
1272 EXPECT_TRUE(ch1.conn() != nullptr); | 1272 EXPECT_TRUE(ch1.conn() != nullptr); |
1273 // It is not dead if it is before MIN_CONNECTION_LIFETIME and pruned. | 1273 // It is not dead if it is before MIN_CONNECTION_LIFETIME and pruned. |
1274 conn->UpdateState(before_created + MIN_CONNECTION_LIFETIME - 1); | 1274 conn->UpdateState(before_created + MIN_CONNECTION_LIFETIME - 1); |
1275 conn->Prune(); | 1275 conn->Prune(); |
1276 rtc::Thread::Current()->ProcessMessages(0); | 1276 rtc::Thread::Current()->ProcessMessages(0); |
1277 EXPECT_TRUE(ch1.conn() != nullptr); | 1277 EXPECT_TRUE(ch1.conn() != nullptr); |
1278 // It will be dead after MIN_CONNECTION_LIFETIME and pruned. | 1278 // It will be dead after MIN_CONNECTION_LIFETIME and pruned. |
1279 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); | 1279 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); |
1280 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout); | 1280 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout); |
1281 | 1281 |
1282 // Test case that the connection has received something. | 1282 // Test case that the connection has received something. |
1283 // Create a connection again and receive a ping. | 1283 // Create a connection again and receive a ping. |
1284 ch1.CreateConnection(GetCandidate(port2)); | 1284 ch1.CreateConnection(GetCandidate(port2)); |
1285 conn = ch1.conn(); | 1285 conn = ch1.conn(); |
1286 ASSERT(conn != nullptr); | 1286 ASSERT(conn != nullptr); |
1287 uint32_t before_last_receiving = rtc::Time(); | 1287 int64_t before_last_receiving = rtc::Time64(); |
1288 conn->ReceivedPing(); | 1288 conn->ReceivedPing(); |
1289 uint32_t after_last_receiving = rtc::Time(); | 1289 int64_t after_last_receiving = rtc::Time64(); |
1290 // The connection will be dead after DEAD_CONNECTION_RECEIVE_TIMEOUT | 1290 // The connection will be dead after DEAD_CONNECTION_RECEIVE_TIMEOUT |
1291 conn->UpdateState( | 1291 conn->UpdateState( |
1292 before_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT - 1); | 1292 before_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT - 1); |
1293 rtc::Thread::Current()->ProcessMessages(100); | 1293 rtc::Thread::Current()->ProcessMessages(100); |
1294 EXPECT_TRUE(ch1.conn() != nullptr); | 1294 EXPECT_TRUE(ch1.conn() != nullptr); |
1295 conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1); | 1295 conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1); |
1296 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout); | 1296 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout); |
1297 } | 1297 } |
1298 | 1298 |
1299 // This test case verifies standard ICE features in STUN messages. Currently it | 1299 // This test case verifies standard ICE features in STUN messages. Currently it |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 | 2026 |
2027 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 2027 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); |
2028 IceMessage* msg = rport->last_stun_msg(); | 2028 IceMessage* msg = rport->last_stun_msg(); |
2029 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 2029 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
2030 // Send rport binding request to lport. | 2030 // Send rport binding request to lport. |
2031 lconn->OnReadPacket(rport->last_stun_buf()->Data(), | 2031 lconn->OnReadPacket(rport->last_stun_buf()->Data(), |
2032 rport->last_stun_buf()->Length(), | 2032 rport->last_stun_buf()->Length(), |
2033 rtc::PacketTime()); | 2033 rtc::PacketTime()); |
2034 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 2034 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
2035 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); | 2035 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); |
2036 uint32_t last_ping_received1 = lconn->last_ping_received(); | 2036 int64_t last_ping_received1 = lconn->last_ping_received(); |
2037 | 2037 |
2038 // Adding a delay of 100ms. | 2038 // Adding a delay of 100ms. |
2039 rtc::Thread::Current()->ProcessMessages(100); | 2039 rtc::Thread::Current()->ProcessMessages(100); |
2040 // Pinging lconn using stun indication message. | 2040 // Pinging lconn using stun indication message. |
2041 lconn->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime()); | 2041 lconn->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime()); |
2042 uint32_t last_ping_received2 = lconn->last_ping_received(); | 2042 int64_t last_ping_received2 = lconn->last_ping_received(); |
2043 EXPECT_GT(last_ping_received2, last_ping_received1); | 2043 EXPECT_GT(last_ping_received2, last_ping_received1); |
2044 } | 2044 } |
2045 | 2045 |
2046 TEST_F(PortTest, TestComputeCandidatePriority) { | 2046 TEST_F(PortTest, TestComputeCandidatePriority) { |
2047 rtc::scoped_ptr<TestPort> port( | 2047 rtc::scoped_ptr<TestPort> port( |
2048 CreateTestPort(kLocalAddr1, "name", "pass")); | 2048 CreateTestPort(kLocalAddr1, "name", "pass")); |
2049 port->set_type_preference(90); | 2049 port->set_type_preference(90); |
2050 port->set_component(177); | 2050 port->set_component(177); |
2051 port->AddCandidateAddress(SocketAddress("192.168.1.4", 1234)); | 2051 port->AddCandidateAddress(SocketAddress("192.168.1.4", 1234)); |
2052 port->AddCandidateAddress(SocketAddress("2001:db8::1234", 1234)); | 2052 port->AddCandidateAddress(SocketAddress("2001:db8::1234", 1234)); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 2306 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
2307 kTimeout); | 2307 kTimeout); |
2308 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); | 2308 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); |
2309 | 2309 |
2310 // Ask the connection to update state as if enough time has passed to lose | 2310 // Ask the connection to update state as if enough time has passed to lose |
2311 // full writability and 5 pings went unresponded to. We'll accomplish the | 2311 // full writability and 5 pings went unresponded to. We'll accomplish the |
2312 // latter by sending pings but not pumping messages. | 2312 // latter by sending pings but not pumping messages. |
2313 for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2313 for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
2314 ch1.Ping(i); | 2314 ch1.Ping(i); |
2315 } | 2315 } |
2316 uint32_t unreliable_timeout_delay = CONNECTION_WRITE_CONNECT_TIMEOUT + 500u; | 2316 int unreliable_timeout_delay = CONNECTION_WRITE_CONNECT_TIMEOUT + 500; |
2317 ch1.conn()->UpdateState(unreliable_timeout_delay); | 2317 ch1.conn()->UpdateState(unreliable_timeout_delay); |
2318 EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state()); | 2318 EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state()); |
2319 | 2319 |
2320 // Data should be able to be sent in this state. | 2320 // Data should be able to be sent in this state. |
2321 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); | 2321 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); |
2322 | 2322 |
2323 // And now allow the other side to process the pings and send binding | 2323 // And now allow the other side to process the pings and send binding |
2324 // responses. | 2324 // responses. |
2325 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 2325 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
2326 kTimeout); | 2326 kTimeout); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 rtc::scoped_ptr<Port> tcp_port(CreateTcpPort(kLocalAddr1)); | 2536 rtc::scoped_ptr<Port> tcp_port(CreateTcpPort(kLocalAddr1)); |
2537 EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME)); | 2537 EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME)); |
2538 EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME)); | 2538 EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME)); |
2539 EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME)); | 2539 EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME)); |
2540 | 2540 |
2541 rtc::scoped_ptr<Port> turn_port( | 2541 rtc::scoped_ptr<Port> turn_port( |
2542 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2542 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
2543 EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME)); | 2543 EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME)); |
2544 EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME)); | 2544 EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME)); |
2545 } | 2545 } |
OLD | NEW |