| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #ifndef RTC_BASE_NETWORK_ROUTE_H_ |
| 12 | #define RTC_BASE_NETWORK_ROUTE_H_ |
| 13 |
| 14 | #include <stdint.h> |
| 15 |
| 16 | #include <string> |
| 17 |
| 18 | #include "rtc_base/network_constants.h" |
| 19 | #include "rtc_base/strings/string_builder.h" |
| 20 | #include "rtc_base/system/inline.h" |
| 21 |
| 22 | // TODO(honghaiz): Make a directory that describes the interfaces and structs |
| 23 | // the media code can rely on and the network code can implement, and both can |
| 24 | // depend on that, but not depend on each other. Then, move this file to that |
| 25 | // directory. |
| 26 | namespace rtc { |
| 27 |
| 28 | class RouteEndpoint { |
| 29 | public: |
| 30 | RouteEndpoint() {} // Used by tests. |
| 31 | RouteEndpoint(AdapterType adapter_type, |
| 32 | uint16_t adapter_id, |
| 33 | uint16_t network_id, |
| 34 | bool uses_turn) |
| 35 | : adapter_type_(adapter_type), |
| 36 | adapter_id_(adapter_id), |
| 37 | network_id_(network_id), |
| 38 | uses_turn_(uses_turn) {} |
| 39 |
| 40 | RouteEndpoint(const RouteEndpoint&) = default; |
| 41 | RouteEndpoint& operator=(const RouteEndpoint&) = default; |
| 42 |
| 43 | // Used by tests. |
| 44 | static RouteEndpoint CreateWithNetworkId(uint16_t network_id) { |
| 45 | return RouteEndpoint(ADAPTER_TYPE_UNKNOWN, |
| 46 | /* adapter_id = */ 0, network_id, |
| 47 | /* uses_turn = */ false); |
| 48 | } |
| 49 | RouteEndpoint CreateWithTurn(bool uses_turn) const { |
| 50 | return RouteEndpoint(adapter_type_, adapter_id_, network_id_, uses_turn); |
| 51 | } |
| 52 |
| 53 | AdapterType adapter_type() const { return adapter_type_; } |
| 54 | uint16_t adapter_id() const { return adapter_id_; } |
| 55 | uint16_t network_id() const { return network_id_; } |
| 56 | bool uses_turn() const { return uses_turn_; } |
| 57 |
| 58 | bool operator==(const RouteEndpoint& other) const; |
| 59 |
| 60 | private: |
| 61 | AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN; |
| 62 | uint16_t adapter_id_ = 0; |
| 63 | uint16_t network_id_ = 0; |
| 64 | bool uses_turn_ = false; |
| 65 | }; |
| 66 |
| 67 | struct NetworkRoute { |
| 68 | bool connected = false; |
| 69 | RouteEndpoint local; |
| 70 | RouteEndpoint remote; |
| 71 | // Last packet id sent on the PREVIOUS route. |
| 72 | int last_sent_packet_id = -1; |
| 73 | // The overhead in bytes from IP layer and above. |
| 74 | // This is the maximum of any part of the route. |
| 75 | int packet_overhead = 0; |
| 76 |
| 77 | RTC_NO_INLINE inline std::string DebugString() const { |
| 78 | rtc::StringBuilder oss; |
| 79 | oss << "[ connected: " << connected << " local: [ " << local.adapter_id() |
| 80 | << "/" << local.network_id() << " " |
| 81 | << AdapterTypeToString(local.adapter_type()) |
| 82 | << " turn: " << local.uses_turn() << " ] remote: [ " |
| 83 | << remote.adapter_id() << "/" << remote.network_id() << " " |
| 84 | << AdapterTypeToString(remote.adapter_type()) |
| 85 | << " turn: " << remote.uses_turn() |
| 86 | << " ] packet_overhead_bytes: " << packet_overhead << " ]"; |
| 87 | return oss.Release(); |
| 88 | } |
| 89 |
| 90 | bool operator==(const NetworkRoute& other) const; |
| 91 | }; |
| 92 |
| 93 | } // namespace rtc |
| 94 |
| 95 | #endif // RTC_BASE_NETWORK_ROUTE_H_ |
| 96 |