OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/p2p/quic_p2p_session.h" | 5 #include "net/quic/p2p/quic_p2p_session.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/quic/crypto/quic_random.h" | 15 #include "net/quic/crypto/quic_random.h" |
16 #include "net/quic/p2p/quic_p2p_crypto_config.h" | 16 #include "net/quic/p2p/quic_p2p_crypto_config.h" |
17 #include "net/quic/p2p/quic_p2p_stream.h" | 17 #include "net/quic/p2p/quic_p2p_stream.h" |
18 #include "net/quic/quic_connection_helper.h" | 18 #include "net/quic/quic_connection_helper.h" |
19 #include "net/quic/quic_default_packet_writer.h" | 19 #include "net/quic/quic_default_packet_writer.h" |
20 #include "net/socket/socket.h" | 20 #include "net/socket/socket.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 | 24 |
| 25 class SocketPerformanceWatcher; |
| 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 const char kTestSharedKey[] = "Shared key exchanged out of bound."; | 29 const char kTestSharedKey[] = "Shared key exchanged out of bound."; |
28 | 30 |
29 class FakeP2PDatagramSocket : public Socket { | 31 class FakeP2PDatagramSocket : public Socket { |
30 public: | 32 public: |
31 FakeP2PDatagramSocket() : weak_factory_(this) {} | 33 FakeP2PDatagramSocket() : weak_factory_(this) {} |
32 ~FakeP2PDatagramSocket() override {} | 34 ~FakeP2PDatagramSocket() override {} |
33 | 35 |
34 base::WeakPtr<FakeP2PDatagramSocket> GetWeakPtr() { | 36 base::WeakPtr<FakeP2PDatagramSocket> GetWeakPtr() { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 CreateP2PSession(socket1.Pass(), crypto_config, Perspective::IS_SERVER); | 235 CreateP2PSession(socket1.Pass(), crypto_config, Perspective::IS_SERVER); |
234 session2_ = | 236 session2_ = |
235 CreateP2PSession(socket2.Pass(), crypto_config, Perspective::IS_CLIENT); | 237 CreateP2PSession(socket2.Pass(), crypto_config, Perspective::IS_CLIENT); |
236 } | 238 } |
237 | 239 |
238 scoped_ptr<QuicP2PSession> CreateP2PSession(scoped_ptr<Socket> socket, | 240 scoped_ptr<QuicP2PSession> CreateP2PSession(scoped_ptr<Socket> socket, |
239 QuicP2PCryptoConfig crypto_config, | 241 QuicP2PCryptoConfig crypto_config, |
240 Perspective perspective) { | 242 Perspective perspective) { |
241 DefaultPacketWriterFactory writer_factory(socket.get()); | 243 DefaultPacketWriterFactory writer_factory(socket.get()); |
242 net::IPAddressNumber ip(net::kIPv4AddressSize, 0); | 244 net::IPAddressNumber ip(net::kIPv4AddressSize, 0); |
243 scoped_ptr<QuicConnection> quic_connection1( | 245 scoped_ptr<QuicConnection> quic_connection1(new QuicConnection( |
244 new QuicConnection(0, net::IPEndPoint(ip, 0), &quic_helper_, | 246 0, net::IPEndPoint(ip, 0), &quic_helper_, writer_factory, |
245 writer_factory, true /* owns_writer */, perspective, | 247 true /* owns_writer */, perspective, true /* is_secuire */, |
246 true /* is_secuire */, QuicSupportedVersions())); | 248 QuicSupportedVersions(), scoped_ptr<SocketPerformanceWatcher>())); |
247 | 249 |
248 scoped_ptr<QuicP2PSession> result(new QuicP2PSession( | 250 scoped_ptr<QuicP2PSession> result(new QuicP2PSession( |
249 config_, crypto_config, quic_connection1.Pass(), socket.Pass())); | 251 config_, crypto_config, quic_connection1.Pass(), socket.Pass())); |
250 result->Initialize(); | 252 result->Initialize(); |
251 return result.Pass(); | 253 return result.Pass(); |
252 } | 254 } |
253 | 255 |
254 void TestStreamConnection(QuicP2PSession* from_session, | 256 void TestStreamConnection(QuicP2PSession* from_session, |
255 QuicP2PSession* to_session, | 257 QuicP2PSession* to_session, |
256 QuicStreamId expected_stream_id); | 258 QuicStreamId expected_stream_id); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 EXPECT_TRUE(stream_delegate.is_closed()); | 385 EXPECT_TRUE(stream_delegate.is_closed()); |
384 EXPECT_EQ(QUIC_PACKET_READ_ERROR, stream_delegate.error()); | 386 EXPECT_EQ(QUIC_PACKET_READ_ERROR, stream_delegate.error()); |
385 EXPECT_TRUE(session_delegate.is_closed()); | 387 EXPECT_TRUE(session_delegate.is_closed()); |
386 EXPECT_EQ(QUIC_PACKET_READ_ERROR, session_delegate.error()); | 388 EXPECT_EQ(QUIC_PACKET_READ_ERROR, session_delegate.error()); |
387 | 389 |
388 // Verify that the socket was destroyed. | 390 // Verify that the socket was destroyed. |
389 EXPECT_FALSE(socket1_); | 391 EXPECT_FALSE(socket1_); |
390 } | 392 } |
391 | 393 |
392 } // namespace net | 394 } // namespace net |
OLD | NEW |