aboutsummaryrefslogtreecommitdiff
path: root/rtc_base
diff options
context:
space:
mode:
authorSebastian Jansson <srte@webrtc.org>2020-03-02 11:32:23 +0100
committerCommit Bot <commit-bot@chromium.org>2020-03-02 11:36:58 +0000
commitdb5d7e470fcbc625410c5646f95d37382da3e3b9 (patch)
treebda616a9270e40c4294ba3a8ad0331f2ff822d13 /rtc_base
parent61f74d91f823c9d600490ff8b3856ba2a520ec22 (diff)
downloadwebrtc-db5d7e470fcbc625410c5646f95d37382da3e3b9.tar.gz
Cleanup: Use common IP overhead definitions in test and prod code
This avoid duplication. As part of this moving the overhead calculation to the IP address class so it's easier to find and more natural to use. Bug: webrtc:9883 Change-Id: If4d865f445bc1a302572896932966ce30294e339 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169445 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30657}
Diffstat (limited to 'rtc_base')
-rw-r--r--rtc_base/async_packet_socket.cc9
-rw-r--r--rtc_base/ip_address.cc11
-rw-r--r--rtc_base/ip_address.h3
-rw-r--r--rtc_base/net_helper.cc23
-rw-r--r--rtc_base/net_helper.h4
5 files changed, 23 insertions, 27 deletions
diff --git a/rtc_base/async_packet_socket.cc b/rtc_base/async_packet_socket.cc
index a42725c424..d5435d71d0 100644
--- a/rtc_base/async_packet_socket.cc
+++ b/rtc_base/async_packet_socket.cc
@@ -10,8 +10,6 @@
#include "rtc_base/async_packet_socket.h"
-#include "rtc_base/net_helper.h"
-
namespace rtc {
PacketTimeUpdateParams::PacketTimeUpdateParams() = default;
@@ -35,12 +33,7 @@ void CopySocketInformationToPacketInfo(size_t packet_size_bytes,
bool is_connectionless,
rtc::PacketInfo* info) {
info->packet_size_bytes = packet_size_bytes;
- // TODO(srte): Make sure that the family of the local socket is always set
- // in the VirtualSocket implementation and remove this check.
- int family = socket_from.GetLocalAddress().family();
- if (family != 0) {
- info->ip_overhead_bytes = cricket::GetIpOverhead(family);
- }
+ info->ip_overhead_bytes = socket_from.GetLocalAddress().ipaddr().overhead();
}
} // namespace rtc
diff --git a/rtc_base/ip_address.cc b/rtc_base/ip_address.cc
index cf7ffa8b90..9dd534c2b5 100644
--- a/rtc_base/ip_address.cc
+++ b/rtc_base/ip_address.cc
@@ -53,6 +53,17 @@ uint32_t IPAddress::v4AddressAsHostOrderInteger() const {
}
}
+int IPAddress::overhead() const {
+ switch (family_) {
+ case AF_INET: // IPv4
+ return 20;
+ case AF_INET6: // IPv6
+ return 40;
+ default:
+ return 0;
+ }
+}
+
bool IPAddress::IsNil() const {
return IPIsUnspec(*this);
}
diff --git a/rtc_base/ip_address.h b/rtc_base/ip_address.h
index 6d857afe84..ae135a69dc 100644
--- a/rtc_base/ip_address.h
+++ b/rtc_base/ip_address.h
@@ -111,6 +111,9 @@ class RTC_EXPORT IPAddress {
// For socketaddress' benefit. Returns the IP in host byte order.
uint32_t v4AddressAsHostOrderInteger() const;
+ // Get the network layer overhead per packet based on the IP address family.
+ int overhead() const;
+
// Whether this is an unspecified IP address.
bool IsNil() const;
diff --git a/rtc_base/net_helper.cc b/rtc_base/net_helper.cc
index 7dcb599933..893b500d56 100644
--- a/rtc_base/net_helper.cc
+++ b/rtc_base/net_helper.cc
@@ -10,9 +10,6 @@
#include "rtc_base/net_helper.h"
-#include "rtc_base/checks.h"
-#include "rtc_base/ip_address.h"
-
namespace cricket {
const char UDP_PROTOCOL_NAME[] = "udp";
@@ -20,23 +17,15 @@ const char TCP_PROTOCOL_NAME[] = "tcp";
const char SSLTCP_PROTOCOL_NAME[] = "ssltcp";
const char TLS_PROTOCOL_NAME[] = "tls";
-int GetIpOverhead(int addr_family) {
- switch (addr_family) {
- case AF_INET: // IPv4
- return 20;
- case AF_INET6: // IPv6
- return 40;
- default:
- RTC_NOTREACHED() << "Invaild address family.";
- return 0;
- }
-}
-
int GetProtocolOverhead(const std::string& protocol) {
if (protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME) {
- return 20;
+ return kTcpHeaderSize;
+ } else if (protocol == UDP_PROTOCOL_NAME) {
+ return kUdpHeaderSize;
+ } else {
+ // TODO(srte): We should crash on unexpected input and handle TLS correctly.
+ return 8;
}
- return 8;
}
} // namespace cricket
diff --git a/rtc_base/net_helper.h b/rtc_base/net_helper.h
index e42502bb18..9abbbdefb2 100644
--- a/rtc_base/net_helper.h
+++ b/rtc_base/net_helper.h
@@ -21,8 +21,8 @@ extern const char TCP_PROTOCOL_NAME[];
extern const char SSLTCP_PROTOCOL_NAME[];
extern const char TLS_PROTOCOL_NAME[];
-// Get the network layer overhead per packet based on the IP address family.
-int GetIpOverhead(int addr_family);
+constexpr int kTcpHeaderSize = 20;
+constexpr int kUdpHeaderSize = 8;
// Get the transport layer overhead per packet based on the protocol.
int GetProtocolOverhead(const std::string& protocol);