| Index: net/tools/quic/quic_time_wait_list_manager.cc
|
| diff --git a/net/tools/quic/quic_time_wait_list_manager.cc b/net/tools/quic/quic_time_wait_list_manager.cc
|
| index b145e8af14f3a2a9eb785ae821eba9e537211513..780a47375d6ba2493cc794501edeea01217d13d6 100644
|
| --- a/net/tools/quic/quic_time_wait_list_manager.cc
|
| +++ b/net/tools/quic/quic_time_wait_list_manager.cc
|
| @@ -27,23 +27,24 @@ namespace tools {
|
|
|
| namespace {
|
|
|
| -// Time period for which the guid should live in time wait state..
|
| +// Time period for which the connection_id should live in time wait state..
|
| const int kTimeWaitSeconds = 5;
|
|
|
| } // namespace
|
|
|
| // A very simple alarm that just informs the QuicTimeWaitListManager to clean
|
| -// up old guids. This alarm should be unregistered and deleted before the
|
| -// QuicTimeWaitListManager is deleted.
|
| -class GuidCleanUpAlarm : public EpollAlarm {
|
| +// up old connection_ids. This alarm should be unregistered and deleted before
|
| +// the QuicTimeWaitListManager is deleted.
|
| +class ConnectionIdCleanUpAlarm : public EpollAlarm {
|
| public:
|
| - explicit GuidCleanUpAlarm(QuicTimeWaitListManager* time_wait_list_manager)
|
| + explicit ConnectionIdCleanUpAlarm(
|
| + QuicTimeWaitListManager* time_wait_list_manager)
|
| : time_wait_list_manager_(time_wait_list_manager) {
|
| }
|
|
|
| virtual int64 OnAlarm() OVERRIDE {
|
| EpollAlarm::OnAlarm();
|
| - time_wait_list_manager_->CleanUpOldGuids();
|
| + time_wait_list_manager_->CleanUpOldConnectionIds();
|
| // Let the time wait manager register the alarm at appropriate time.
|
| return 0;
|
| }
|
| @@ -55,7 +56,7 @@ class GuidCleanUpAlarm : public EpollAlarm {
|
|
|
| // This class stores pending public reset packets to be sent to clients.
|
| // server_address - server address on which a packet what was received for
|
| -// a guid in time wait state.
|
| +// a connection_id in time wait state.
|
| // client_address - address of the client that sent that packet. Needed to send
|
| // the public reset packet back to the client.
|
| // packet - the pending public reset packet that is to be sent to the client.
|
| @@ -89,43 +90,48 @@ QuicTimeWaitListManager::QuicTimeWaitListManager(
|
| const QuicVersionVector& supported_versions)
|
| : epoll_server_(epoll_server),
|
| kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)),
|
| - guid_clean_up_alarm_(new GuidCleanUpAlarm(this)),
|
| + connection_id_clean_up_alarm_(new ConnectionIdCleanUpAlarm(this)),
|
| clock_(epoll_server_),
|
| writer_(writer),
|
| visitor_(visitor) {
|
| - SetGuidCleanUpAlarm();
|
| + SetConnectionIdCleanUpAlarm();
|
| }
|
|
|
| QuicTimeWaitListManager::~QuicTimeWaitListManager() {
|
| - guid_clean_up_alarm_->UnregisterIfRegistered();
|
| + connection_id_clean_up_alarm_->UnregisterIfRegistered();
|
| STLDeleteElements(&pending_packets_queue_);
|
| - for (GuidMap::iterator it = guid_map_.begin(); it != guid_map_.end(); ++it) {
|
| + for (ConnectionIdMap::iterator it = connection_id_map_.begin();
|
| + it != connection_id_map_.end();
|
| + ++it) {
|
| delete it->second.close_packet;
|
| }
|
| }
|
|
|
| -void QuicTimeWaitListManager::AddGuidToTimeWait(
|
| - QuicGuid guid,
|
| +void QuicTimeWaitListManager::AddConnectionIdToTimeWait(
|
| + QuicConnectionId connection_id,
|
| QuicVersion version,
|
| QuicEncryptedPacket* close_packet) {
|
| int num_packets = 0;
|
| - GuidMap::iterator it = guid_map_.find(guid);
|
| - if (it != guid_map_.end()) { // Replace record if it is reinserted.
|
| + ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
|
| + if (it != connection_id_map_.end()) { // Replace record if it is reinserted.
|
| num_packets = it->second.num_packets;
|
| delete it->second.close_packet;
|
| - guid_map_.erase(it);
|
| + connection_id_map_.erase(it);
|
| }
|
| - GuidData data(num_packets, version, clock_.ApproximateNow(), close_packet);
|
| - guid_map_.insert(make_pair(guid, data));
|
| + ConnectionIdData data(num_packets, version, clock_.ApproximateNow(),
|
| + close_packet);
|
| + connection_id_map_.insert(make_pair(connection_id, data));
|
| }
|
|
|
| -bool QuicTimeWaitListManager::IsGuidInTimeWait(QuicGuid guid) const {
|
| - return guid_map_.find(guid) != guid_map_.end();
|
| +bool QuicTimeWaitListManager::IsConnectionIdInTimeWait(
|
| + QuicConnectionId connection_id) const {
|
| + return ContainsKey(connection_id_map_, connection_id);
|
| }
|
|
|
| -QuicVersion QuicTimeWaitListManager::GetQuicVersionFromGuid(QuicGuid guid) {
|
| - GuidMap::iterator it = guid_map_.find(guid);
|
| - DCHECK(it != guid_map_.end());
|
| +QuicVersion QuicTimeWaitListManager::GetQuicVersionFromConnectionId(
|
| + QuicConnectionId connection_id) {
|
| + ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
|
| + DCHECK(it != connection_id_map_.end());
|
| return (it->second).version;
|
| }
|
|
|
| @@ -143,13 +149,13 @@ void QuicTimeWaitListManager::OnCanWrite() {
|
| void QuicTimeWaitListManager::ProcessPacket(
|
| const IPEndPoint& server_address,
|
| const IPEndPoint& client_address,
|
| - QuicGuid guid,
|
| + QuicConnectionId connection_id,
|
| QuicPacketSequenceNumber sequence_number) {
|
| - DCHECK(IsGuidInTimeWait(guid));
|
| + DCHECK(IsConnectionIdInTimeWait(connection_id));
|
| // TODO(satyamshekhar): Think about handling packets from different client
|
| // addresses.
|
| - GuidMap::iterator it = guid_map_.find(guid);
|
| - DCHECK(it != guid_map_.end());
|
| + ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
|
| + DCHECK(it != connection_id_map_.end());
|
| // Increment the received packet count.
|
| ++((it->second).num_packets);
|
| if (!ShouldSendResponse((it->second).num_packets)) {
|
| @@ -163,12 +169,16 @@ void QuicTimeWaitListManager::ProcessPacket(
|
| // Takes ownership of the packet.
|
| SendOrQueuePacket(queued_packet);
|
| } else {
|
| - SendPublicReset(server_address, client_address, guid, sequence_number);
|
| + SendPublicReset(server_address,
|
| + client_address,
|
| + connection_id,
|
| + sequence_number);
|
| }
|
| }
|
|
|
| -// Returns true if the number of packets received for this guid is a power of 2
|
| -// to throttle the number of public reset packets we send to a client.
|
| +// Returns true if the number of packets received for this connection_id is a
|
| +// power of 2 to throttle the number of public reset packets we send to a
|
| +// client.
|
| bool QuicTimeWaitListManager::ShouldSendResponse(int received_packet_count) {
|
| return (received_packet_count & (received_packet_count - 1)) == 0;
|
| }
|
| @@ -176,14 +186,14 @@ bool QuicTimeWaitListManager::ShouldSendResponse(int received_packet_count) {
|
| void QuicTimeWaitListManager::SendPublicReset(
|
| const IPEndPoint& server_address,
|
| const IPEndPoint& client_address,
|
| - QuicGuid guid,
|
| + QuicConnectionId connection_id,
|
| QuicPacketSequenceNumber rejected_sequence_number) {
|
| QuicPublicResetPacket packet;
|
| - packet.public_header.guid = guid;
|
| + packet.public_header.connection_id = connection_id;
|
| packet.public_header.reset_flag = true;
|
| packet.public_header.version_flag = false;
|
| packet.rejected_sequence_number = rejected_sequence_number;
|
| - // TODO(satyamshekhar): generate a valid nonce for this guid.
|
| + // TODO(satyamshekhar): generate a valid nonce for this connection_id.
|
| packet.nonce_proof = 1010101;
|
| packet.client_address = client_address;
|
| QueuedPacket* queued_packet = new QueuedPacket(
|
| @@ -228,42 +238,43 @@ bool QuicTimeWaitListManager::WriteToWire(QueuedPacket* queued_packet) {
|
| return true;
|
| }
|
|
|
| -void QuicTimeWaitListManager::SetGuidCleanUpAlarm() {
|
| - guid_clean_up_alarm_->UnregisterIfRegistered();
|
| +void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() {
|
| + connection_id_clean_up_alarm_->UnregisterIfRegistered();
|
| int64 next_alarm_interval;
|
| - if (!guid_map_.empty()) {
|
| - QuicTime oldest_guid = guid_map_.begin()->second.time_added;
|
| + if (!connection_id_map_.empty()) {
|
| + QuicTime oldest_connection_id =
|
| + connection_id_map_.begin()->second.time_added;
|
| QuicTime now = clock_.ApproximateNow();
|
| - if (now.Subtract(oldest_guid) < kTimeWaitPeriod_) {
|
| - next_alarm_interval = oldest_guid.Add(kTimeWaitPeriod_)
|
| - .Subtract(now)
|
| - .ToMicroseconds();
|
| + if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
|
| + next_alarm_interval = oldest_connection_id.Add(kTimeWaitPeriod_)
|
| + .Subtract(now)
|
| + .ToMicroseconds();
|
| } else {
|
| - LOG(ERROR) << "GUID lingered for longer than kTimeWaitPeriod";
|
| + LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod";
|
| next_alarm_interval = 0;
|
| }
|
| } else {
|
| - // No guids added so none will expire before kTimeWaitPeriod_.
|
| + // No connection_ids added so none will expire before kTimeWaitPeriod_.
|
| next_alarm_interval = kTimeWaitPeriod_.ToMicroseconds();
|
| }
|
|
|
| - epoll_server_->RegisterAlarmApproximateDelta(next_alarm_interval,
|
| - guid_clean_up_alarm_.get());
|
| + epoll_server_->RegisterAlarmApproximateDelta(
|
| + next_alarm_interval, connection_id_clean_up_alarm_.get());
|
| }
|
|
|
| -void QuicTimeWaitListManager::CleanUpOldGuids() {
|
| +void QuicTimeWaitListManager::CleanUpOldConnectionIds() {
|
| QuicTime now = clock_.ApproximateNow();
|
| - while (!guid_map_.empty()) {
|
| - GuidMap::iterator it = guid_map_.begin();
|
| - QuicTime oldest_guid = it->second.time_added;
|
| - if (now.Subtract(oldest_guid) < kTimeWaitPeriod_) {
|
| + while (!connection_id_map_.empty()) {
|
| + ConnectionIdMap::iterator it = connection_id_map_.begin();
|
| + QuicTime oldest_connection_id = it->second.time_added;
|
| + if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
|
| break;
|
| }
|
| - // This guid has lived its age, retire it now.
|
| + // This connection_id has lived its age, retire it now.
|
| delete it->second.close_packet;
|
| - guid_map_.erase(it);
|
| + connection_id_map_.erase(it);
|
| }
|
| - SetGuidCleanUpAlarm();
|
| + SetConnectionIdCleanUpAlarm();
|
| }
|
|
|
| } // namespace tools
|
|
|