Skip to content

Commit

Permalink
Add GoEphemeralKeySource to improve CPS.
Browse files Browse the repository at this point in the history
  * Connection throughput increased to 3800 CPS from 2800 CPS (+30%)
  • Loading branch information
serialx committed Jun 14, 2015
1 parent 7d98072 commit ab7e25b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "go_quic_spdy_server_stream_go_wrapper.h"
#include "go_quic_alarm_go_wrapper.h"
#include "go_proof_source.h"
#include "go_ephemeral_key_source.h"

#include "net/quic/quic_connection.h"
#include "net/quic/quic_clock.h"
Expand Down Expand Up @@ -53,6 +54,8 @@ GoQuicDispatcher *create_quic_dispatcher(void* go_udp_conn, void* go_quic_dispat
QuicCryptoServerConfig* crypto_config = new QuicCryptoServerConfig("secret", QuicRandom::GetInstance());
QuicClock* clock = new QuicClock(); // Deleted by scoped ptr of TestConnectionHelper
QuicRandom* random_generator = QuicRandom::GetInstance();
net::EphemeralKeySource *keySource = new GoEphemeralKeySource();
crypto_config->SetEphemeralKeySource(keySource);

TestConnectionHelper *helper = new TestConnectionHelper(go_task_runner, clock, random_generator); // Deleted by delete_go_quic_dispatcher()
QuicVersionVector versions(net::QuicSupportedVersions());
Expand Down
25 changes: 25 additions & 0 deletions src/go_ephemeral_key_source.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "go_ephemeral_key_source.h"

GoEphemeralKeySource::GoEphemeralKeySource() : forward_secure_key_exchange_(nullptr), key_created_time_(net::QuicTime::Zero()) {
}

std::string GoEphemeralKeySource::CalculateForwardSecureKey(
const net::KeyExchange* key_exchange,
net::QuicRandom* rand,
net::QuicTime now,
base::StringPiece peer_public_value,
std::string* public_value) {
// Cache forward_secure_key_exchange for 10 seconds
if (forward_secure_key_exchange_.get() == nullptr ||
now.Subtract(key_created_time_).ToSeconds() > 10) {
forward_secure_key_exchange_.reset(key_exchange->NewKeyPair(rand));
key_created_time_ = now;
}

*public_value =
forward_secure_key_exchange_->public_value().as_string();
std::string forward_secure_premaster_secret;
forward_secure_key_exchange_->CalculateSharedKey(
peer_public_value, &forward_secure_premaster_secret);
return forward_secure_premaster_secret;
}
25 changes: 25 additions & 0 deletions src/go_ephemeral_key_source.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __GO_EPHEMERAL_KEY_SOURCE__H__
#define __GO_EPHEMERAL_KEY_SOURCE__H__

#include "net/quic/crypto/key_exchange.h"
#include "net/quic/crypto/ephemeral_key_source.h"
#include "net/quic/quic_time.h"
#include "base/memory/scoped_ptr.h"

class GoEphemeralKeySource : public net::EphemeralKeySource {
public:
GoEphemeralKeySource();

virtual std::string CalculateForwardSecureKey(
const net::KeyExchange* key_exchange,
net::QuicRandom* rand,
net::QuicTime now,
base::StringPiece peer_public_value,
std::string* public_value) override;

private:
scoped_ptr<net::KeyExchange> forward_secure_key_exchange_;
net::QuicTime key_created_time_;
};

#endif // __GO_EPHEMERAL_KEY_SOURCE__H__

0 comments on commit ab7e25b

Please sign in to comment.