aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discovery/dnssd/public/dns_sd_instance_record.cc4
-rw-r--r--osp/impl/quic/quic_client.h5
-rw-r--r--osp/impl/quic/quic_connection_factory_impl.h2
-rw-r--r--osp/impl/quic/quic_server.h5
-rw-r--r--platform/base/ip_address.cc18
-rw-r--r--platform/base/ip_address.h26
6 files changed, 30 insertions, 30 deletions
diff --git a/discovery/dnssd/public/dns_sd_instance_record.cc b/discovery/dnssd/public/dns_sd_instance_record.cc
index 1feae0e8..90506a6b 100644
--- a/discovery/dnssd/public/dns_sd_instance_record.cc
+++ b/discovery/dnssd/public/dns_sd_instance_record.cc
@@ -205,11 +205,11 @@ bool operator<(const DnsSdInstanceRecord& lhs, const DnsSdInstanceRecord& rhs) {
}
if (lhs.address_v4_ != rhs.address_v4_) {
- return IPEndpointComparator()(lhs.address_v4_, rhs.address_v4_);
+ return lhs.address_v4_ < rhs.address_v4_;
}
if (lhs.address_v6_ != rhs.address_v6_) {
- return IPEndpointComparator()(lhs.address_v6_, rhs.address_v6_);
+ return lhs.address_v6_ < rhs.address_v6_;
}
return lhs.txt_ < rhs.txt_;
diff --git a/osp/impl/quic/quic_client.h b/osp/impl/quic/quic_client.h
index 7e37267d..548cbff5 100644
--- a/osp/impl/quic/quic_client.h
+++ b/osp/impl/quic/quic_client.h
@@ -103,7 +103,7 @@ class QuicClient final : public ProtocolConnectionClient,
// Maps an IPEndpoint to a generated endpoint ID. This is used to insulate
// callers from post-handshake changes to a connections actual peer endpoint.
- std::map<IPEndpoint, uint64_t, IPEndpointComparator> endpoint_map_;
+ std::map<IPEndpoint, uint64_t> endpoint_map_;
// Value that will be used for the next new endpoint in a Connect call.
uint64_t next_endpoint_id_ = 0;
@@ -119,8 +119,7 @@ class QuicClient final : public ProtocolConnectionClient,
// Maps endpoint addresses to data about connections that haven't successfully
// completed the QUIC handshake.
- std::map<IPEndpoint, PendingConnectionData, IPEndpointComparator>
- pending_connections_;
+ std::map<IPEndpoint, PendingConnectionData> pending_connections_;
// Maps endpoint IDs to data about connections that have successfully
// completed the QUIC handshake.
diff --git a/osp/impl/quic/quic_connection_factory_impl.h b/osp/impl/quic/quic_connection_factory_impl.h
index 0bfa242f..e3588f6a 100644
--- a/osp/impl/quic/quic_connection_factory_impl.h
+++ b/osp/impl/quic/quic_connection_factory_impl.h
@@ -53,7 +53,7 @@ class QuicConnectionFactoryImpl final : public QuicConnectionFactory {
QuicConnection* connection;
UdpSocket* socket; // References one of the owned |sockets_|.
};
- std::map<IPEndpoint, OpenConnection, IPEndpointComparator> connections_;
+ std::map<IPEndpoint, OpenConnection> connections_;
// NOTE: Must be provided in constructor and stored as an instance variable
// rather than using the static accessor method to allow for UTs to mock this
diff --git a/osp/impl/quic/quic_server.h b/osp/impl/quic/quic_server.h
index 31a3bbe8..ad195635 100644
--- a/osp/impl/quic/quic_server.h
+++ b/osp/impl/quic/quic_server.h
@@ -84,15 +84,14 @@ class QuicServer final : public ProtocolConnectionServer,
// Maps an IPEndpoint to a generated endpoint ID. This is used to insulate
// callers from post-handshake changes to a connections actual peer endpoint.
- std::map<IPEndpoint, uint64_t, IPEndpointComparator> endpoint_map_;
+ std::map<IPEndpoint, uint64_t> endpoint_map_;
// Value that will be used for the next new endpoint in a Connect call.
uint64_t next_endpoint_id_ = 0;
// Maps endpoint addresses to data about connections that haven't successfully
// completed the QUIC handshake.
- std::map<IPEndpoint, ServiceConnectionData, IPEndpointComparator>
- pending_connections_;
+ std::map<IPEndpoint, ServiceConnectionData> pending_connections_;
// Maps endpoint IDs to data about connections that have successfully
// completed the QUIC handshake.
diff --git a/platform/base/ip_address.cc b/platform/base/ip_address.cc
index 5b1ca00d..5a2048fc 100644
--- a/platform/base/ip_address.cc
+++ b/platform/base/ip_address.cc
@@ -269,23 +269,21 @@ bool operator!=(const IPEndpoint& a, const IPEndpoint& b) {
return !(a == b);
}
-bool IPAddressComparator::operator()(const IPAddress& a,
- const IPAddress& b) const {
- if (a.version() != b.version()) {
- return a.version() < b.version();
+bool IPAddress::operator<(const IPAddress& other) const {
+ if (version() != other.version()) {
+ return version() < other.version();
}
- if (a.IsV4()) {
- return memcmp(a.bytes_.data(), b.bytes_.data(), 4) < 0;
+ if (IsV4()) {
+ return memcmp(bytes_.data(), other.bytes_.data(), 4) < 0;
} else {
- return memcmp(a.bytes_.data(), b.bytes_.data(), 16) < 0;
+ return memcmp(bytes_.data(), other.bytes_.data(), 16) < 0;
}
}
-bool IPEndpointComparator::operator()(const IPEndpoint& a,
- const IPEndpoint& b) const {
+bool operator<(const IPEndpoint& a, const IPEndpoint& b) {
if (a.address != b.address) {
- return IPAddressComparator()(a.address, b.address);
+ return a.address < b.address;
}
return a.port < b.port;
diff --git a/platform/base/ip_address.h b/platform/base/ip_address.h
index 7a512551..3b025584 100644
--- a/platform/base/ip_address.h
+++ b/platform/base/ip_address.h
@@ -60,6 +60,11 @@ class IPAddress {
bool operator==(const IPAddress& o) const;
bool operator!=(const IPAddress& o) const;
+
+ bool operator<(const IPAddress& other) const;
+ bool operator>(const IPAddress& other) const { return other < *this; }
+ bool operator<=(const IPAddress& other) const { return !(other < *this); }
+ bool operator>=(const IPAddress& other) const { return !(*this < other); }
explicit operator bool() const;
Version version() const { return version_; }
@@ -81,8 +86,6 @@ class IPAddress {
static ErrorOr<IPAddress> Parse(const std::string& s);
private:
- friend class IPAddressComparator;
-
Version version_;
std::array<uint8_t, 16> bytes_;
};
@@ -101,15 +104,16 @@ struct IPEndpoint {
bool operator==(const IPEndpoint& a, const IPEndpoint& b);
bool operator!=(const IPEndpoint& a, const IPEndpoint& b);
-class IPAddressComparator {
- public:
- bool operator()(const IPAddress& a, const IPAddress& b) const;
-};
-
-class IPEndpointComparator {
- public:
- bool operator()(const IPEndpoint& a, const IPEndpoint& b) const;
-};
+bool operator<(const IPEndpoint& a, const IPEndpoint& b);
+inline bool operator>(const IPEndpoint& a, const IPEndpoint& b) {
+ return b < a;
+}
+inline bool operator<=(const IPEndpoint& a, const IPEndpoint& b) {
+ return !(b > a);
+}
+inline bool operator>=(const IPEndpoint& a, const IPEndpoint& b) {
+ return !(a > b);
+}
// Outputs a string of the form:
// 123.234.34.56