-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GoEphemeralKeySource to improve CPS.
* Connection throughput increased to 3800 CPS from 2800 CPS (+30%)
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |