string NewSourceAddressToken(
string config_id,
- IPEndPoint ip,
+ const IPEndPoint& ip,
QuicRandom* rand,
QuicWallTime now) {
+ return NewSourceAddressToken(config_id, ip, rand, now, NULL);
+ }
+
+ string NewSourceAddressToken(
+ string config_id,
+ const IPEndPoint& ip,
+ QuicRandom* rand,
+ QuicWallTime now,
+ CachedNetworkParameters* cached_network_params) {
return server_config_->NewSourceAddressToken(
- *GetConfig(config_id), ip, rand, now);
+ *GetConfig(config_id), ip, rand, now, cached_network_params);
}
HandshakeFailureReason ValidateSourceAddressToken(string config_id,
StringPiece srct,
- IPEndPoint ip,
+ const IPEndPoint& ip,
QuicWallTime now) {
+ return ValidateSourceAddressToken(config_id, srct, ip, now, NULL);
+ }
+
+ HandshakeFailureReason ValidateSourceAddressToken(
+ string config_id,
+ StringPiece srct,
+ const IPEndPoint& ip,
+ QuicWallTime now,
+ CachedNetworkParameters* cached_network_params) {
return server_config_->ValidateSourceAddressToken(
- *GetConfig(config_id), srct, ip, now);
+ *GetConfig(config_id), srct, ip, now, cached_network_params);
}
string NewServerNonce(QuicRandom* rand, QuicWallTime now) const {
}
// CheckConfigs compares the state of the Configs in |server_config_| to the
- // description given as arguments. The arguments are given as NULL-terminated
- // pairs. The first of each pair is the server config ID of a Config. The
- // second is a boolean describing whether the config is the primary. For
- // example:
- // CheckConfigs(NULL); // checks that no Configs are loaded.
+ // description given as arguments. The arguments are given as
+ // nullptr-terminated pairs. The first of each pair is the server config ID of
+ // a Config. The second is a boolean describing whether the config is the
+ // primary. For example:
+ // CheckConfigs(nullptr); // checks that no Configs are loaded.
//
// // Checks that exactly three Configs are loaded with the given IDs and
// // status.
// "id1", false,
// "id2", true,
// "id3", false,
- // NULL);
+ // nullptr);
void CheckConfigs(const char* server_config_id1, ...) {
va_list ap;
va_start(ap, server_config_id1);
is_known_orbit_called_(false) {
}
- virtual bool IsKnownOrbit(StringPiece orbit) const OVERRIDE {
+ bool IsKnownOrbit(StringPiece orbit) const override {
// Ensure that the strike register client lock is not held.
QuicCryptoServerConfigPeer peer(config_);
base::Lock* m = peer.GetStrikeRegisterClientLock();
return true;
}
- virtual void VerifyNonceIsValidAndUnique(
- StringPiece nonce,
- QuicWallTime now,
- ResultCallback* cb) OVERRIDE {
+ void VerifyNonceIsValidAndUnique(StringPiece nonce,
+ QuicWallTime now,
+ ResultCallback* cb) override {
LOG(FATAL) << "Not implemented";
}
now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2));
DCHECK_EQ(SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE,
peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now));
+
+ // Make sure that if the source address token contains CachedNetworkParameters
+ // that this gets written to ValidateSourceAddressToken output argument.
+ CachedNetworkParameters cached_network_params_input;
+ cached_network_params_input.set_bandwidth_estimate_bytes_per_second(1234);
+ const string token4_with_cached_network_params = peer.NewSourceAddressToken(
+ kPrimary, ip4, rand, now, &cached_network_params_input);
+
+ CachedNetworkParameters cached_network_params_output;
+ EXPECT_NE(cached_network_params_output, cached_network_params_input);
+ peer.ValidateSourceAddressToken(kPrimary, token4_with_cached_network_params,
+ ip4, now, &cached_network_params_output);
+ // TODO(rtenneti): For server, enable the following check after serialization
+ // of optional CachedNetworkParameters is implemented.
+ // EXPECT_EQ(cached_network_params_output, cached_network_params_input);
}
TEST(QuicCryptoServerConfigTest, ValidateServerNonce) {
config_(QuicCryptoServerConfig::TESTING, rand_),
test_peer_(&config_) {}
- virtual void SetUp() {
+ void SetUp() override {
clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1000));
}
// SetConfigs constructs suitable config protobufs and calls SetConfigs on
- // |config_|. The arguments are given as NULL-terminated pairs. The first of
- // each pair is the server config ID of a Config. The second is the
- // |primary_time| of that Config, given in epoch seconds. (Although note
- // that, in these tests, time is set to 1000 seconds since the epoch.) For
- // example:
- // SetConfigs(NULL); // calls |config_.SetConfigs| with no protobufs.
+ // |config_|. The arguments are given as nullptr-terminated pairs. The first
+ // of each pair is the server config ID of a Config. The second is the
+ // |primary_time| of that Config, given in epoch seconds. (Although note that,
+ // in these tests, time is set to 1000 seconds since the epoch.) For example:
+ // SetConfigs(nullptr); // calls |config_.SetConfigs| with no protobufs.
//
// // Calls |config_.SetConfigs| with two protobufs: one for a Config with
// // a |primary_time| of 900 and priority 1, and another with
// CheckConfigs(
// "id1", 900, 1,
// "id2", 1000, 2,
- // NULL);
+ // nullptr);
//
// If the server config id starts with "INVALID" then the generated protobuf
// will be invalid.
};
TEST_F(CryptoServerConfigsTest, NoConfigs) {
- test_peer_.CheckConfigs(NULL);
+ test_peer_.CheckConfigs(nullptr);
}
TEST_F(CryptoServerConfigsTest, MakePrimaryFirst) {
// Make sure that "b" is primary even though "a" comes first.
SetConfigs("a", 1100, 1,
"b", 900, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", true,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, MakePrimarySecond) {
// Make sure that a remains primary after b is added.
SetConfigs("a", 900, 1,
"b", 1100, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", true,
"b", false,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, Delete) {
SetConfigs("a", 800, 1,
"b", 900, 1,
"c", 1100, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", true,
"c", false,
- NULL);
+ nullptr);
SetConfigs("b", 900, 1,
"c", 1100, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"b", true,
"c", false,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, DeletePrimary) {
SetConfigs("a", 800, 1,
"b", 900, 1,
"c", 1100, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", true,
"c", false,
- NULL);
+ nullptr);
SetConfigs("a", 800, 1,
"c", 1100, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", true,
"c", false,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, FailIfDeletingAllConfigs) {
// Ensure that configs get deleted when removed.
SetConfigs("a", 800, 1,
"b", 900, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", true,
- NULL);
- SetConfigs(NULL);
+ nullptr);
+ SetConfigs(nullptr);
// Config change is rejected, still using old configs.
test_peer_.CheckConfigs(
"a", false,
"b", true,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, ChangePrimaryTime) {
SetConfigs("a", 400, 1,
"b", 800, 1,
"c", 1200, 1,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(500);
test_peer_.CheckConfigs(
"a", true,
"b", false,
"c", false,
- NULL);
+ nullptr);
SetConfigs("a", 1200, 1,
"b", 800, 1,
"c", 400, 1,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(500);
test_peer_.CheckConfigs(
"a", false,
"b", false,
"c", true,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, AllConfigsInThePast) {
SetConfigs("a", 400, 1,
"b", 800, 1,
"c", 1200, 1,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(1500);
test_peer_.CheckConfigs(
"a", false,
"b", false,
"c", true,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, AllConfigsInTheFuture) {
SetConfigs("a", 400, 1,
"b", 800, 1,
"c", 1200, 1,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(100);
test_peer_.CheckConfigs(
"a", true,
"b", false,
"c", false,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, SortByPriority) {
SetConfigs("a", 900, 1,
"b", 900, 2,
"c", 900, 3,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", true,
"b", false,
"c", false,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(800);
test_peer_.CheckConfigs(
"a", true,
"b", false,
"c", false,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(1000);
test_peer_.CheckConfigs(
"a", true,
"b", false,
"c", false,
- NULL);
+ nullptr);
// Change priorities and expect sort order to change.
SetConfigs("a", 900, 2,
"b", 900, 1,
"c", 900, 0,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", false,
"c", true,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(800);
test_peer_.CheckConfigs(
"a", false,
"b", false,
"c", true,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(1000);
test_peer_.CheckConfigs(
"a", false,
"b", false,
"c", true,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, AdvancePrimary) {
// Check that a new primary config is enabled at the right time.
SetConfigs("a", 900, 1,
"b", 1100, 1,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(1000);
test_peer_.CheckConfigs(
"a", true,
"b", false,
- NULL);
+ nullptr);
test_peer_.SelectNewPrimaryConfig(1101);
test_peer_.CheckConfigs(
"a", false,
"b", true,
- NULL);
+ nullptr);
}
TEST_F(CryptoServerConfigsTest, InvalidConfigs) {
SetConfigs("a", 800, 1,
"b", 900, 1,
"c", 1100, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", true,
"c", false,
- NULL);
+ nullptr);
SetConfigs("a", 800, 1,
"c", 1100, 1,
"INVALID1", 1000, 1,
- NULL);
+ nullptr);
test_peer_.CheckConfigs(
"a", false,
"b", true,
"c", false,
- NULL);
+ nullptr);
}
} // namespace test