diff options
author | Jonas Oreland <jonaso@webrtc.org> | 2020-03-20 16:11:56 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-03-20 16:55:38 +0000 |
commit | 71fda3613c1e5de4c4435cb98af6a2796a339dc7 (patch) | |
tree | 8fde1163f5048e30e0e7f880c19f9312ea704e8b /rtc_base | |
parent | 5b139d6f9bde6f3df79aa80a7e2ba7a17a8a8a2a (diff) | |
download | webrtc-71fda3613c1e5de4c4435cb98af6a2796a339dc7.tar.gz |
Extend NetworkRoute with more info about local/remote endpoints
This patch extends the NetworkRoute struct with more information
about local/remote endpoints. It adds
- adapter type
- adapter id
- relay
(previously it was "only" network_id)
The patch leaves the {local/remote}_network_id fields
around and populated since downstream projects depend
on them. They will be removed once they have migrated.
OWNER: srte@ call/ test/
OWNER: asapersson@ video/
OWNER: hta@ p2p/ pc/ rtc_base/
BUG: webrtc:11434
Change-Id: I9bcec385b40d707db385fef40b2c7a315dd35dd0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170628
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30848}
Diffstat (limited to 'rtc_base')
-rw-r--r-- | rtc_base/BUILD.gn | 2 | ||||
-rw-r--r-- | rtc_base/network.cc | 22 | ||||
-rw-r--r-- | rtc_base/network_constants.cc | 39 | ||||
-rw-r--r-- | rtc_base/network_constants.h | 4 | ||||
-rw-r--r-- | rtc_base/network_route.h | 65 |
5 files changed, 108 insertions, 24 deletions
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 2e4138e458..2c6dd3c56b 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -765,6 +765,7 @@ rtc_library("rtc_base") { "../system_wrappers:field_trial", "network:sent_packet", "system:file_wrapper", + "system:inline", "system:rtc_export", "task_utils:to_queued_task", "third_party/base64", @@ -818,6 +819,7 @@ rtc_library("rtc_base") { "net_helpers.h", "network.cc", "network.h", + "network_constants.cc", "network_constants.h", "network_monitor.cc", "network_monitor.h", diff --git a/rtc_base/network.cc b/rtc_base/network.cc index 4906184b5d..07b121bb3a 100644 --- a/rtc_base/network.cc +++ b/rtc_base/network.cc @@ -85,28 +85,6 @@ bool SortNetworks(const Network* a, const Network* b) { return a->key() < b->key(); } -std::string AdapterTypeToString(AdapterType type) { - switch (type) { - case ADAPTER_TYPE_ANY: - return "Wildcard"; - case ADAPTER_TYPE_UNKNOWN: - return "Unknown"; - case ADAPTER_TYPE_ETHERNET: - return "Ethernet"; - case ADAPTER_TYPE_WIFI: - return "Wifi"; - case ADAPTER_TYPE_CELLULAR: - return "Cellular"; - case ADAPTER_TYPE_VPN: - return "VPN"; - case ADAPTER_TYPE_LOOPBACK: - return "Loopback"; - default: - RTC_NOTREACHED() << "Invalid type " << type; - return std::string(); - } -} - uint16_t ComputeNetworkCostByType(int type) { switch (type) { case rtc::ADAPTER_TYPE_ETHERNET: diff --git a/rtc_base/network_constants.cc b/rtc_base/network_constants.cc new file mode 100644 index 0000000000..2cb5233ad6 --- /dev/null +++ b/rtc_base/network_constants.cc @@ -0,0 +1,39 @@ +/* + * Copyright 2020 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "rtc_base/network_constants.h" + +#include "rtc_base/checks.h" + +namespace rtc { + +std::string AdapterTypeToString(AdapterType type) { + switch (type) { + case ADAPTER_TYPE_ANY: + return "Wildcard"; + case ADAPTER_TYPE_UNKNOWN: + return "Unknown"; + case ADAPTER_TYPE_ETHERNET: + return "Ethernet"; + case ADAPTER_TYPE_WIFI: + return "Wifi"; + case ADAPTER_TYPE_CELLULAR: + return "Cellular"; + case ADAPTER_TYPE_VPN: + return "VPN"; + case ADAPTER_TYPE_LOOPBACK: + return "Loopback"; + default: + RTC_NOTREACHED() << "Invalid type " << type; + return std::string(); + } +} + +} // namespace rtc diff --git a/rtc_base/network_constants.h b/rtc_base/network_constants.h index efb2c83455..1b43243944 100644 --- a/rtc_base/network_constants.h +++ b/rtc_base/network_constants.h @@ -13,6 +13,8 @@ #include <stdint.h> +#include <string> + namespace rtc { static const uint16_t kNetworkCostMax = 999; @@ -37,6 +39,8 @@ enum AdapterType { ADAPTER_TYPE_ANY = 1 << 5, }; +std::string AdapterTypeToString(AdapterType type); + } // namespace rtc #endif // RTC_BASE_NETWORK_CONSTANTS_H_ diff --git a/rtc_base/network_route.h b/rtc_base/network_route.h index 6a8f183513..c2b492ce18 100644 --- a/rtc_base/network_route.h +++ b/rtc_base/network_route.h @@ -13,21 +13,82 @@ #include <stdint.h> +#include <string> + +#include "rtc_base/network_constants.h" +#include "rtc_base/strings/string_builder.h" +#include "rtc_base/system/inline.h" + // TODO(honghaiz): Make a directory that describes the interfaces and structs // the media code can rely on and the network code can implement, and both can // depend on that, but not depend on each other. Then, move this file to that // directory. namespace rtc { +class RouteEndpoint { + public: + RouteEndpoint() {} // Used by tests. + RouteEndpoint(AdapterType adapter_type, + uint16_t adapter_id, + uint16_t network_id, + bool uses_turn) + : adapter_type_(adapter_type), + adapter_id_(adapter_id), + network_id_(network_id), + uses_turn_(uses_turn) {} + + RouteEndpoint(const RouteEndpoint&) = default; + RouteEndpoint& operator=(const RouteEndpoint&) = default; + + // Used by tests. + static RouteEndpoint CreateWithNetworkId(uint16_t network_id) { + return RouteEndpoint(ADAPTER_TYPE_UNKNOWN, + /* adapter_id = */ 0, network_id, + /* uses_turn = */ false); + } + + AdapterType adapter_type() const { return adapter_type_; } + uint16_t adapter_id() const { return adapter_id_; } + uint16_t network_id() const { return network_id_; } + bool uses_turn() const { return uses_turn_; } + + private: + AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN; + uint16_t adapter_id_ = 0; + uint16_t network_id_ = 0; + bool uses_turn_ = false; +}; + struct NetworkRoute { bool connected = false; - uint16_t local_network_id = 0; - uint16_t remote_network_id = 0; + RouteEndpoint local; + RouteEndpoint remote; // Last packet id sent on the PREVIOUS route. int last_sent_packet_id = -1; // The overhead in bytes from IP layer and above. + // This is the maximum of any part of the route. int packet_overhead = 0; + + // Downstream projects depend on the old representation, + // populate that until they have been migrated. + // TODO(jonaso): remove. + uint16_t local_network_id = 0; + uint16_t remote_network_id = 0; + + RTC_NO_INLINE inline std::string DebugString() const { + rtc::StringBuilder oss; + oss << "[ connected: " << connected << " local: [ " << local.adapter_id() + << "/" << local.network_id() << " " + << AdapterTypeToString(local.adapter_type()) + << " turn: " << local.uses_turn() << " ] remote: [ " + << remote.adapter_id() << "/" << remote.network_id() << " " + << AdapterTypeToString(remote.adapter_type()) + << " turn: " << remote.uses_turn() + << " ] packet_overhead_bytes: " << packet_overhead << " ]"; + return oss.Release(); + } }; + } // namespace rtc #endif // RTC_BASE_NETWORK_ROUTE_H_ |