Commit 44387769 authored by bnc's avatar bnc Committed by Commit bot

Introduce AlternativeService in BrokenAlternateProtol{List,Map}.

Introduce struct AlternativeService and use it in
BrokenAlternateProtol{List,Map} instead of BrokenAlternateProtocolEntry.  This
is the first step towards making an alternative service broken not with respect
to an origin, but by itself.

BUG=392576

Review URL: https://codereview.chromium.org/987813002

Cr-Commit-Position: refs/heads/master@{#319680}
parent 9bae2008
...@@ -86,6 +86,32 @@ NET_EXPORT AlternateProtocol AlternateProtocolFromString( ...@@ -86,6 +86,32 @@ NET_EXPORT AlternateProtocol AlternateProtocolFromString(
NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto( NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
NextProto next_proto); NextProto next_proto);
struct NET_EXPORT AlternativeService {
AlternativeService()
: protocol(UNINITIALIZED_ALTERNATE_PROTOCOL), host(), port(0) {}
AlternativeService(AlternateProtocol protocol,
const std::string& host,
uint16 port)
: protocol(protocol), host(host), port(port) {}
AlternativeService(const AlternativeService& alternative_service) = default;
AlternativeService& operator=(const AlternativeService& alternative_service) =
default;
bool operator<(const AlternativeService& other) const {
if (protocol != other.protocol)
return protocol < other.protocol;
if (host != other.host)
return host < other.host;
return port < other.port;
}
AlternateProtocol protocol;
std::string host;
uint16 port;
};
struct NET_EXPORT AlternateProtocolInfo { struct NET_EXPORT AlternateProtocolInfo {
AlternateProtocolInfo() AlternateProtocolInfo()
: port(0), : port(0),
......
...@@ -318,14 +318,14 @@ void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( ...@@ -318,14 +318,14 @@ void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
it = alternate_protocol_map_.Put(server, alternate); it = alternate_protocol_map_.Put(server, alternate);
} }
it->second.is_broken = true; it->second.is_broken = true;
const BrokenAlternateProtocolEntry entry(server, alternate.port, const AlternativeService alternative_service(alternate.protocol,
alternate.protocol); server.host(), alternate.port);
int count = ++broken_alternate_protocol_map_[entry]; int count = ++broken_alternate_protocol_map_[alternative_service];
base::TimeDelta delay = base::TimeDelta delay =
base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1));
broken_alternate_protocol_list_.push_back( broken_alternate_protocol_list_.push_back(
BrokenAlternateProtocolEntryWithTime(entry, when)); BrokenAlternateProtocolEntryWithTime(alternative_service, when));
// Do not leave this host as canonical so that we don't infer the other // Do not leave this host as canonical so that we don't infer the other
// hosts are also broken without testing them first. // hosts are also broken without testing them first.
...@@ -343,9 +343,9 @@ bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( ...@@ -343,9 +343,9 @@ bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken(
const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
return false; return false;
const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port, const AlternativeService alternative_service(
alternate_protocol.protocol); alternate_protocol.protocol, server.host(), alternate_protocol.port);
return ContainsKey(broken_alternate_protocol_map_, entry); return ContainsKey(broken_alternate_protocol_map_, alternative_service);
} }
void HttpServerPropertiesImpl::ConfirmAlternateProtocol( void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
...@@ -353,9 +353,9 @@ void HttpServerPropertiesImpl::ConfirmAlternateProtocol( ...@@ -353,9 +353,9 @@ void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
return; return;
const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port, const AlternativeService alternative_service(
alternate_protocol.protocol); alternate_protocol.protocol, server.host(), alternate_protocol.port);
broken_alternate_protocol_map_.erase(entry); broken_alternate_protocol_map_.erase(alternative_service);
} }
void HttpServerPropertiesImpl::ClearAlternateProtocol( void HttpServerPropertiesImpl::ClearAlternateProtocol(
...@@ -511,9 +511,10 @@ void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { ...@@ -511,9 +511,10 @@ void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() {
break; break;
} }
const BrokenAlternateProtocolEntry& entry = const AlternativeService& alternative_service =
entry_with_time.broken_alternate_protocol_entry; entry_with_time.alternative_service;
ClearAlternateProtocol(entry.server); ClearAlternateProtocol(
HostPortPair(alternative_service.host, alternative_service.port));
broken_alternate_protocol_list_.pop_front(); broken_alternate_protocol_list_.pop_front();
} }
ScheduleBrokenAlternateProtocolMappingsExpiration(); ScheduleBrokenAlternateProtocolMappingsExpiration();
......
...@@ -117,37 +117,14 @@ class NET_EXPORT HttpServerPropertiesImpl ...@@ -117,37 +117,14 @@ class NET_EXPORT HttpServerPropertiesImpl
typedef std::vector<std::string> CanonicalSufficList; typedef std::vector<std::string> CanonicalSufficList;
typedef std::set<HostPortPair> Http11ServerHostPortSet; typedef std::set<HostPortPair> Http11ServerHostPortSet;
// Server, port, and AlternateProtocol: an entity that can be broken. (Once // Broken alternative service with expiration time.
// we use AlternativeService, the same AltSvc can be broken for one server but
// not for another depending on what certificate it can offer.)
struct BrokenAlternateProtocolEntry {
BrokenAlternateProtocolEntry(const BrokenAlternateProtocolEntry&) = default;
BrokenAlternateProtocolEntry(const HostPortPair& server,
uint16 port,
AlternateProtocol protocol)
: server(server), port(port), protocol(protocol) {}
bool operator<(const BrokenAlternateProtocolEntry& other) const {
if (!server.Equals(other.server))
return server < other.server;
if (port != other.port)
return port < other.port;
return protocol < other.protocol;
}
HostPortPair server;
uint16 port;
AlternateProtocol protocol;
};
// BrokenAlternateProtocolEntry with expiration time.
struct BrokenAlternateProtocolEntryWithTime { struct BrokenAlternateProtocolEntryWithTime {
BrokenAlternateProtocolEntryWithTime( BrokenAlternateProtocolEntryWithTime(
const BrokenAlternateProtocolEntry& broken_alternate_protocol_entry, const AlternativeService& alternative_service,
base::TimeTicks when) base::TimeTicks when)
: broken_alternate_protocol_entry(broken_alternate_protocol_entry), : alternative_service(alternative_service), when(when) {}
when(when) {}
BrokenAlternateProtocolEntry broken_alternate_protocol_entry; AlternativeService alternative_service;
base::TimeTicks when; base::TimeTicks when;
}; };
// Deque of BrokenAlternateProtocolEntryWithTime items, ordered by expiration // Deque of BrokenAlternateProtocolEntryWithTime items, ordered by expiration
...@@ -156,8 +133,7 @@ class NET_EXPORT HttpServerPropertiesImpl ...@@ -156,8 +133,7 @@ class NET_EXPORT HttpServerPropertiesImpl
BrokenAlternateProtocolList; BrokenAlternateProtocolList;
// Map from (server, alternate protocol and port) to the number of // Map from (server, alternate protocol and port) to the number of
// times that alternate protocol has been marked broken for that server. // times that alternate protocol has been marked broken for that server.
typedef std::map<BrokenAlternateProtocolEntry, int> typedef std::map<AlternativeService, int> BrokenAlternateProtocolMap;
BrokenAlternateProtocolMap;
// Return the iterator for |server|, or for its canonical host, or end. // Return the iterator for |server|, or for its canonical host, or end.
AlternateProtocolMap::const_iterator GetAlternateProtocolIterator( AlternateProtocolMap::const_iterator GetAlternateProtocolIterator(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment