1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_BASE_TRANSPORT_INFO_H_ 6 #define NET_BASE_TRANSPORT_INFO_H_ 7 8 #include <iosfwd> 9 #include <string> 10 11 #include "base/strings/string_piece.h" 12 #include "net/base/ip_endpoint.h" 13 #include "net/base/net_export.h" 14 15 namespace net { 16 17 // Specifies the type of a network transport. 18 enum class TransportType { 19 // The transport was established directly to a peer. 20 kDirect, 21 // The transport was established to a proxy of some kind. 22 kProxied, 23 }; 24 25 // Returns a string representation of the given transport type. 26 // The returned StringPiece is static, has no lifetime restrictions. 27 NET_EXPORT base::StringPiece TransportTypeToString(TransportType type); 28 29 // Describes a network transport. 30 struct NET_EXPORT TransportInfo { 31 TransportInfo(); 32 TransportInfo(TransportType type_arg, IPEndPoint endpoint_arg); 33 ~TransportInfo(); 34 35 // Instances of this type are comparable for equality. 36 bool operator==(const TransportInfo& other) const; 37 bool operator!=(const TransportInfo& other) const; 38 39 // Returns a string representation of this struct, suitable for debugging. 40 std::string ToString() const; 41 42 // The type of the transport. 43 TransportType type = TransportType::kDirect; 44 45 // If |type| is kDirect, then this identifies the peer endpoint. 46 // If |type| is kProxied, then this identifies the proxy endpoint. 47 IPEndPoint endpoint; 48 }; 49 50 // Instances of these types are streamable for easier debugging. 51 NET_EXPORT std::ostream& operator<<(std::ostream& out, TransportType type); 52 NET_EXPORT std::ostream& operator<<(std::ostream& out, 53 const TransportInfo& info); 54 55 } // namespace net 56 57 #endif // NET_BASE_TRANSPORT_INFO_H_ 58