| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/quic/quic_p2p_session_factory.h" |
| 6 |
| 7 #include "net/cert/x509_certificate.h" |
| 8 #include "net/quic/crypto/quic_random.h" |
| 9 #include "net/quic/quic_connection.h" |
| 10 #include "net/quic/quic_p2p_client_session.h" |
| 11 #include "net/quic/quic_p2p_server_session.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 namespace { |
| 16 string MakeSecret(QuicRandom* random) { |
| 17 uint8 buf[16]; |
| 18 random->RandBytes(buf, sizeof(buf)); |
| 19 return string(reinterpret_cast<char*>(buf), sizeof(buf)); |
| 20 } |
| 21 } // namespace |
| 22 |
| 23 QuicP2PSessionFactory::QuicP2PSessionFactory( |
| 24 QuicConnectionHelperInterface* helper) |
| 25 : helper_(helper), |
| 26 server_config_(MakeSecret(helper->GetRandomGenerator()), |
| 27 helper->GetRandomGenerator()) { |
| 28 client_config_.SetDefaults(); |
| 29 client_config_.set_user_agent_id("P2P"); |
| 30 // TODO(dmz) more on server_config_ |
| 31 server_config_.AddDefaultConfig(helper->GetRandomGenerator(), |
| 32 helper->GetClock(), |
| 33 QuicCryptoServerConfig::ConfigOptions()); |
| 34 } |
| 35 |
| 36 QuicP2PSession* QuicP2PSessionFactory::Create( |
| 37 bool is_server_role, |
| 38 X509Certificate* local_identity, |
| 39 base::StringPiece private_key, |
| 40 HashValue remote_fingerprint, |
| 41 QuicPacketWriter* writer, |
| 42 QuicP2PSession::Delegate* delegate, |
| 43 QuicMessageStream::ReadDelegate* read_delegate) { |
| 44 QuicConnection* connection = new QuicConnection( |
| 45 0xa5adface, // TODO(dmz) |
| 46 IPEndPoint(), |
| 47 helper_, |
| 48 is_server_role, |
| 49 QuicSupportedVersions()); |
| 50 connection->set_writer(writer, /* owned= */ false); |
| 51 QuicConfig config; |
| 52 config.SetDefaults(); |
| 53 // Let P2PTransportChannel handle the timeouts |
| 54 config.set_idle_connection_state_lifetime( |
| 55 QuicTime::Delta::FromSeconds(1000), |
| 56 QuicTime::Delta::FromSeconds(1000)); |
| 57 // TODO(dmz) This should probably use the same options as the normal QUIC |
| 58 // running in the I/O thread. We need to get at |
| 59 // IOThread::globals_->quic_connection_options somehow. |
| 60 QuicTagVector connection_options; |
| 61 connection_options.push_back(net::kPACE); |
| 62 connection_options.push_back(net::kTIME); |
| 63 config.SetConnectionOptionsToSend(connection_options); |
| 64 QuicP2PSession* session; |
| 65 if (is_server_role) { |
| 66 session = new QuicP2PServerSession(config, |
| 67 &server_config_, |
| 68 connection, |
| 69 delegate, |
| 70 read_delegate); |
| 71 } else { |
| 72 // TODO(dmz) more on client_config_ |
| 73 // TODO(dmz) QuicServerId has to match |
| 74 session = new QuicP2PClientSession(config, |
| 75 QuicServerId(), |
| 76 &client_config_, |
| 77 connection, |
| 78 delegate, |
| 79 read_delegate); |
| 80 } |
| 81 session->InitializeSession(); |
| 82 return session; |
| 83 } |
| 84 |
| 85 } // namespace net |
| OLD | NEW |