From e2d6a06fa8c53f757b285318ce5ebaa3619f0597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20H=C3=B6glund?= Date: Thu, 5 Oct 2017 14:53:33 +0200 Subject: [PATCH] Reland "Clean up libjingle API dependencies." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a reland of 9185aca9ce1f66e983d9a5e797cab77a64cc46b0 > Original change's description: > > > Clean up libjingle API dependencies. > > > > > > This CL moves candidate.h into the public API, since it has > > > been implicitly included before. > > > > > > This is a straightforward way of solving the circular > > > dependencies involving that file. For instance, > > > libjingle_peerconnection_api includes candidate.h from > > > jsepicecandidate.h, but _api can't depend on rtc_p2p, which > > > depends on _api. In fact, _api can't depend on much at all > > > since it's a very high level abstraction; instead, things > > > should depend on it. > > > > > > Furthermore, we have the case where deprecated headers > > > include headers in internal modules. I just have to turn > > > off include checking for those, but that's not a big deal. > > > > > > This CL punts the problem of callfactoryinterface.h being > > > implicitly included, and pulling in most of the call > > > module with it. This should be addressed in a follow-up > > > CL. > Bug: webrtc:7504 > Change-Id: Icae0ba1a0488550e2871cc65e66d3661707aa5b6 > Reviewed-on: https://webrtc-review.googlesource.com/6460 > Reviewed-by: Fredrik Solenberg > Reviewed-by: Taylor Brandstetter > Commit-Queue: Patrik Höglund > Cr-Commit-Position: refs/heads/master@{#20156} TBR=deadbeef@webrtc.org Bug: webrtc:7504 Change-Id: Ic6598ac2af9355b60bbd289c86dc75e0ae9fed2e Reviewed-on: https://webrtc-review.googlesource.com/6801 Commit-Queue: Patrik Höglund Reviewed-by: Fredrik Solenberg Cr-Commit-Position: refs/heads/master@{#20167} --- api/BUILD.gn | 61 ++++-- api/candidate.h | 293 +++++++++++++++++++++++++ api/jsepicecandidate.h | 2 +- api/jsepsessiondescription.h | 2 +- api/mediastreaminterface.h | 1 - p2p/base/candidate.h | 300 +------------------------- p2p/base/fakecandidatepair.h | 2 +- p2p/base/icetransportinternal.h | 2 +- p2p/base/jseptransport.cc | 2 +- p2p/base/jseptransport.h | 2 +- p2p/base/p2ptransportchannel.cc | 2 +- p2p/base/p2ptransportchannel.h | 2 +- p2p/base/port.h | 2 +- p2p/base/transportinfo.h | 2 +- pc/jsepsessiondescription_unittest.cc | 2 +- pc/rtcstatscollector.cc | 2 +- pc/transportcontroller.h | 2 +- pc/webrtcsdp.cc | 2 +- pc/webrtcsession.h | 2 +- rtc_base/BUILD.gn | 1 + rtc_base/network.h | 6 - rtc_base/network_constants.h | 36 ++++ rtc_base/networkmonitor.h | 11 +- 23 files changed, 401 insertions(+), 338 deletions(-) create mode 100644 api/candidate.h create mode 100644 rtc_base/network_constants.h diff --git a/api/BUILD.gn b/api/BUILD.gn index 86a63e4dee..2b7e612316 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -34,12 +34,9 @@ rtc_source_set("call_api") { } rtc_static_library("libjingle_peerconnection_api") { - # Cannot have GN check enabled since that would introduce dependency cycles - # TODO(kjellander): Remove (bugs.webrtc.org/7504) - check_includes = false cflags = [] sources = [ - "datachannel.h", + "candidate.h", "datachannelinterface.h", "dtmfsenderinterface.h", "jsep.h", @@ -47,17 +44,13 @@ rtc_static_library("libjingle_peerconnection_api") { "jsepsessiondescription.h", "mediaconstraintsinterface.cc", "mediaconstraintsinterface.h", - "mediastream.h", "mediastreaminterface.cc", - "mediastreaminterface.h", "mediastreamproxy.h", - "mediastreamtrack.h", "mediastreamtrackproxy.h", "mediatypes.cc", "mediatypes.h", "notifier.h", "peerconnectionfactoryproxy.h", - "peerconnectioninterface.h", "peerconnectionproxy.h", "proxy.h", "rtcerror.cc", @@ -65,15 +58,11 @@ rtc_static_library("libjingle_peerconnection_api") { "rtpparameters.cc", "rtpparameters.h", "rtpreceiverinterface.h", - "rtpsender.h", "rtpsenderinterface.h", "statstypes.cc", "statstypes.h", - "streamcollection.h", "umametrics.h", "videosourceproxy.h", - "videotracksource.h", - "webrtcsdp.h", ] if (!build_with_chromium && is_clang) { @@ -81,7 +70,17 @@ rtc_static_library("libjingle_peerconnection_api") { suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] } + public_deps = [ + ":libjingle_api_deprecated_headers", + ":mediastream_interface_and_implicit_video_frame_api", + ":peerconnection_and_implicit_call_api", + ] + deps = [ + # Basically, don't add stuff here. You might break sensitive downstream + # targets like pnacl. API should not depend on anything, really. All these + # should go away, in time. + ":optional", ":rtc_stats_api", "..:webrtc_common", "../rtc_base:rtc_base", @@ -97,6 +96,44 @@ rtc_static_library("libjingle_peerconnection_api") { } } +rtc_source_set("peerconnection_and_implicit_call_api") { + # The peerconnectioninterface.h file pulls in call/callfactoryinterface.h + # and the entire call module with it. We need to either get rid of this + # dependency or pull most of call/ into the API. For now, silence the warnings + # this creates since it creates a circular dependency (call very much depends + # on API). See bugs.webrtc.org/7504. + check_includes = false + sources = [ + "peerconnectioninterface.h", + ] +} + +rtc_source_set("mediastream_interface_and_implicit_video_frame_api") { + # The mediastreaminterface.h file pulls in in video_frame.h, but the + # system_wrappers dependency that comes with that breaks pnacl downstream. + # TODO(phoglund): solve this (see bugs.webrtc.org/7504). + check_includes = false + sources = [ + "mediastreaminterface.h", + ] +} + +rtc_source_set("libjingle_api_deprecated_headers") { + # We need to include headers from undeclared targets here, since they cause + # circular dependencies. These deprecated headers are going away anyway. + # See http://bugs.webrtc.org/5883. + check_includes = false + sources = [ + "datachannel.h", + "mediastream.h", + "mediastreamtrack.h", + "rtpsender.h", + "streamcollection.h", + "videotracksource.h", + "webrtcsdp.h", + ] +} + rtc_source_set("ortc_api") { check_includes = false # TODO(deadbeef): Remove (bugs.webrtc.org/6828) sources = [ diff --git a/api/candidate.h b/api/candidate.h new file mode 100644 index 0000000000..78b20827e5 --- /dev/null +++ b/api/candidate.h @@ -0,0 +1,293 @@ +/* + * Copyright 2004 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. + */ + +#ifndef API_CANDIDATE_H_ +#define API_CANDIDATE_H_ + +#include +#include + +#include +#include + +#include "rtc_base/checks.h" +#include "rtc_base/helpers.h" +#include "rtc_base/network_constants.h" +#include "rtc_base/socketaddress.h" + +namespace cricket { + +// Candidate for ICE based connection discovery. +// TODO(phoglund): remove things in here that are not needed in the public API. + +class Candidate { + public: + // TODO(pthatcher): Match the ordering and param list as per RFC 5245 + // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1 + Candidate() + : id_(rtc::CreateRandomString(8)), + component_(0), + priority_(0), + network_type_(rtc::ADAPTER_TYPE_UNKNOWN), + generation_(0), + network_id_(0), + network_cost_(0) {} + + Candidate(int component, + const std::string& protocol, + const rtc::SocketAddress& address, + uint32_t priority, + const std::string& username, + const std::string& password, + const std::string& type, + uint32_t generation, + const std::string& foundation, + uint16_t network_id = 0, + uint16_t network_cost = 0) + : id_(rtc::CreateRandomString(8)), + component_(component), + protocol_(protocol), + address_(address), + priority_(priority), + username_(username), + password_(password), + type_(type), + network_type_(rtc::ADAPTER_TYPE_UNKNOWN), + generation_(generation), + foundation_(foundation), + network_id_(network_id), + network_cost_(network_cost) {} + + const std::string & id() const { return id_; } + void set_id(const std::string & id) { id_ = id; } + + int component() const { return component_; } + void set_component(int component) { component_ = component; } + + const std::string & protocol() const { return protocol_; } + void set_protocol(const std::string & protocol) { protocol_ = protocol; } + + // The protocol used to talk to relay. + const std::string& relay_protocol() const { return relay_protocol_; } + void set_relay_protocol(const std::string& protocol) { + relay_protocol_ = protocol; + } + + const rtc::SocketAddress & address() const { return address_; } + void set_address(const rtc::SocketAddress & address) { + address_ = address; + } + + uint32_t priority() const { return priority_; } + void set_priority(const uint32_t priority) { priority_ = priority; } + + // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc + // doesn't use it. + // Maps old preference (which was 0.0-1.0) to match priority (which + // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see + // https://docs.google.com/a/google.com/document/d/ + // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit + float preference() const { + // The preference value is clamped to two decimal precision. + return static_cast(((priority_ >> 24) * 100 / 127) / 100.0); + } + + // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc + // doesn't use it. + void set_preference(float preference) { + // Limiting priority to UINT_MAX when value exceeds uint32_t max. + // This can happen for e.g. when preference = 3. + uint64_t prio_val = static_cast(preference * 127) << 24; + priority_ = static_cast( + std::min(prio_val, static_cast(UINT_MAX))); + } + + // TODO(honghaiz): Change to usernameFragment or ufrag. + const std::string & username() const { return username_; } + void set_username(const std::string & username) { username_ = username; } + + const std::string & password() const { return password_; } + void set_password(const std::string & password) { password_ = password; } + + const std::string & type() const { return type_; } + void set_type(const std::string & type) { type_ = type; } + + const std::string & network_name() const { return network_name_; } + void set_network_name(const std::string & network_name) { + network_name_ = network_name; + } + + rtc::AdapterType network_type() const { return network_type_; } + void set_network_type(rtc::AdapterType network_type) { + network_type_ = network_type; + } + + // Candidates in a new generation replace those in the old generation. + uint32_t generation() const { return generation_; } + void set_generation(uint32_t generation) { generation_ = generation; } + const std::string generation_str() const { + std::ostringstream ost; + ost << generation_; + return ost.str(); + } + void set_generation_str(const std::string& str) { + std::istringstream ist(str); + ist >> generation_; + } + + // |network_cost| measures the cost/penalty of using this candidate. A network + // cost of 0 indicates this candidate can be used freely. A value of + // rtc::kNetworkCostMax indicates it should be used only as the last resort. + void set_network_cost(uint16_t network_cost) { + RTC_DCHECK_LE(network_cost, rtc::kNetworkCostMax); + network_cost_ = network_cost; + } + uint16_t network_cost() const { return network_cost_; } + + // An ID assigned to the network hosting the candidate. + uint16_t network_id() const { return network_id_; } + void set_network_id(uint16_t network_id) { network_id_ = network_id; } + + const std::string& foundation() const { + return foundation_; + } + void set_foundation(const std::string& foundation) { + foundation_ = foundation; + } + + const rtc::SocketAddress & related_address() const { + return related_address_; + } + void set_related_address( + const rtc::SocketAddress & related_address) { + related_address_ = related_address; + } + const std::string& tcptype() const { return tcptype_; } + void set_tcptype(const std::string& tcptype) { + tcptype_ = tcptype; + } + + // The name of the transport channel of this candidate. + // TODO(phoglund): remove. + const std::string& transport_name() const { return transport_name_; } + void set_transport_name(const std::string& transport_name) { + transport_name_ = transport_name; + } + + // The URL of the ICE server which this candidate is gathered from. + const std::string& url() const { return url_; } + void set_url(const std::string& url) { url_ = url; } + + // Determines whether this candidate is equivalent to the given one. + bool IsEquivalent(const Candidate& c) const { + // We ignore the network name, since that is just debug information, and + // the priority and the network cost, since they should be the same if the + // rest are. + return (component_ == c.component_) && (protocol_ == c.protocol_) && + (address_ == c.address_) && (username_ == c.username_) && + (password_ == c.password_) && (type_ == c.type_) && + (generation_ == c.generation_) && (foundation_ == c.foundation_) && + (related_address_ == c.related_address_) && + (network_id_ == c.network_id_); + } + + // Determines whether this candidate can be considered equivalent to the + // given one when looking for a matching candidate to remove. + bool MatchesForRemoval(const Candidate& c) const { + return component_ == c.component_ && protocol_ == c.protocol_ && + address_ == c.address_; + } + + std::string ToString() const { + return ToStringInternal(false); + } + + std::string ToSensitiveString() const { + return ToStringInternal(true); + } + + uint32_t GetPriority(uint32_t type_preference, + int network_adapter_preference, + int relay_preference) const { + // RFC 5245 - 4.1.2.1. + // priority = (2^24)*(type preference) + + // (2^8)*(local preference) + + // (2^0)*(256 - component ID) + + // |local_preference| length is 2 bytes, 0-65535 inclusive. + // In our implemenation we will partion local_preference into + // 0 1 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // | NIC Pref | Addr Pref | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // NIC Type - Type of the network adapter e.g. 3G/Wifi/Wired. + // Addr Pref - Address preference value as per RFC 3484. + // local preference = (NIC Type << 8 | Addr_Pref) - relay preference. + + int addr_pref = IPAddressPrecedence(address_.ipaddr()); + int local_preference = ((network_adapter_preference << 8) | addr_pref) + + relay_preference; + + return (type_preference << 24) | + (local_preference << 8) | + (256 - component_); + } + + bool operator==(const Candidate& o) const { + return id_ == o.id_ && component_ == o.component_ && + protocol_ == o.protocol_ && relay_protocol_ == o.relay_protocol_ && + address_ == o.address_ && priority_ == o.priority_ && + username_ == o.username_ && password_ == o.password_ && + type_ == o.type_ && network_name_ == o.network_name_ && + network_type_ == o.network_type_ && generation_ == o.generation_ && + foundation_ == o.foundation_ && + related_address_ == o.related_address_ && tcptype_ == o.tcptype_ && + transport_name_ == o.transport_name_ && network_id_ == o.network_id_; + } + bool operator!=(const Candidate& o) const { return !(*this == o); } + + private: + std::string ToStringInternal(bool sensitive) const { + std::ostringstream ost; + std::string address = sensitive ? address_.ToSensitiveString() : + address_.ToString(); + ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_ + << ":" << protocol_ << ":" << priority_ << ":" << address << ":" + << type_ << ":" << related_address_ << ":" << username_ << ":" + << password_ << ":" << network_id_ << ":" << network_cost_ << ":" + << generation_ << "]"; + return ost.str(); + } + + std::string id_; + int component_; + std::string protocol_; + std::string relay_protocol_; + rtc::SocketAddress address_; + uint32_t priority_; + std::string username_; + std::string password_; + std::string type_; + std::string network_name_; + rtc::AdapterType network_type_; + uint32_t generation_; + std::string foundation_; + rtc::SocketAddress related_address_; + std::string tcptype_; + std::string transport_name_; + uint16_t network_id_; + uint16_t network_cost_; + std::string url_; +}; + +} // namespace cricket + +#endif // API_CANDIDATE_H_ diff --git a/api/jsepicecandidate.h b/api/jsepicecandidate.h index 2965e866af..dae6121ead 100644 --- a/api/jsepicecandidate.h +++ b/api/jsepicecandidate.h @@ -18,8 +18,8 @@ #include #include +#include "api/candidate.h" #include "api/jsep.h" -#include "p2p/base/candidate.h" #include "rtc_base/constructormagic.h" namespace webrtc { diff --git a/api/jsepsessiondescription.h b/api/jsepsessiondescription.h index 21adfeefc0..6b115ee2e9 100644 --- a/api/jsepsessiondescription.h +++ b/api/jsepsessiondescription.h @@ -18,9 +18,9 @@ #include #include +#include "api/candidate.h" #include "api/jsep.h" #include "api/jsepicecandidate.h" -#include "p2p/base/candidate.h" #include "rtc_base/constructormagic.h" namespace cricket { diff --git a/api/mediastreaminterface.h b/api/mediastreaminterface.h index 4e5fde1822..fa074a0533 100644 --- a/api/mediastreaminterface.h +++ b/api/mediastreaminterface.h @@ -27,7 +27,6 @@ // TODO(zhihuang): Remove unrelated headers once downstream applications stop // relying on them; they were previously transitively included by // mediachannel.h, which is no longer a dependency of this file. -#include "media/base/streamparams.h" #include "media/base/videosinkinterface.h" #include "media/base/videosourceinterface.h" #include "rtc_base/ratetracker.h" diff --git a/p2p/base/candidate.h b/p2p/base/candidate.h index 87f24d22b8..ea7d2c9ebb 100644 --- a/p2p/base/candidate.h +++ b/p2p/base/candidate.h @@ -8,300 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef P2P_BASE_CANDIDATE_H_ -#define P2P_BASE_CANDIDATE_H_ +// TODO(phoglund): remove this file after downstream projects are updated. +// See bugs.webrtc.org/7504. -#include -#include -#include +#ifndef P2P_CANDIDATE_H_ +#define P2P_CANDIDATE_H_ -#include -#include -#include -#include +#include "api/candidate.h" -#include "p2p/base/p2pconstants.h" -#include "rtc_base/checks.h" -#include "rtc_base/helpers.h" -#include "rtc_base/network.h" -#include "rtc_base/socketaddress.h" - -namespace cricket { - -// Candidate for ICE based connection discovery. - -class Candidate { - public: - // TODO: Match the ordering and param list as per RFC 5245 - // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1 - Candidate() - : id_(rtc::CreateRandomString(8)), - component_(0), - priority_(0), - network_type_(rtc::ADAPTER_TYPE_UNKNOWN), - generation_(0), - network_id_(0), - network_cost_(0) {} - - Candidate(int component, - const std::string& protocol, - const rtc::SocketAddress& address, - uint32_t priority, - const std::string& username, - const std::string& password, - const std::string& type, - uint32_t generation, - const std::string& foundation, - uint16_t network_id = 0, - uint16_t network_cost = 0) - : id_(rtc::CreateRandomString(8)), - component_(component), - protocol_(protocol), - address_(address), - priority_(priority), - username_(username), - password_(password), - type_(type), - network_type_(rtc::ADAPTER_TYPE_UNKNOWN), - generation_(generation), - foundation_(foundation), - network_id_(network_id), - network_cost_(network_cost) {} - - const std::string & id() const { return id_; } - void set_id(const std::string & id) { id_ = id; } - - int component() const { return component_; } - void set_component(int component) { component_ = component; } - - const std::string & protocol() const { return protocol_; } - void set_protocol(const std::string & protocol) { protocol_ = protocol; } - - // The protocol used to talk to relay. - const std::string& relay_protocol() const { return relay_protocol_; } - void set_relay_protocol(const std::string& protocol) { - relay_protocol_ = protocol; - } - - const rtc::SocketAddress & address() const { return address_; } - void set_address(const rtc::SocketAddress & address) { - address_ = address; - } - - uint32_t priority() const { return priority_; } - void set_priority(const uint32_t priority) { priority_ = priority; } - - // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc - // doesn't use it. - // Maps old preference (which was 0.0-1.0) to match priority (which - // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see - // https://docs.google.com/a/google.com/document/d/ - // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit - float preference() const { - // The preference value is clamped to two decimal precision. - return static_cast(((priority_ >> 24) * 100 / 127) / 100.0); - } - - // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc - // doesn't use it. - void set_preference(float preference) { - // Limiting priority to UINT_MAX when value exceeds uint32_t max. - // This can happen for e.g. when preference = 3. - uint64_t prio_val = static_cast(preference * 127) << 24; - priority_ = static_cast( - std::min(prio_val, static_cast(UINT_MAX))); - } - - // TODO(honghaiz): Change to usernameFragment or ufrag. - const std::string & username() const { return username_; } - void set_username(const std::string & username) { username_ = username; } - - const std::string & password() const { return password_; } - void set_password(const std::string & password) { password_ = password; } - - const std::string & type() const { return type_; } - void set_type(const std::string & type) { type_ = type; } - - const std::string & network_name() const { return network_name_; } - void set_network_name(const std::string & network_name) { - network_name_ = network_name; - } - - rtc::AdapterType network_type() const { return network_type_; } - void set_network_type(rtc::AdapterType network_type) { - network_type_ = network_type; - } - - // Candidates in a new generation replace those in the old generation. - uint32_t generation() const { return generation_; } - void set_generation(uint32_t generation) { generation_ = generation; } - const std::string generation_str() const { - std::ostringstream ost; - ost << generation_; - return ost.str(); - } - void set_generation_str(const std::string& str) { - std::istringstream ist(str); - ist >> generation_; - } - - // |network_cost| measures the cost/penalty of using this candidate. A network - // cost of 0 indicates this candidate can be used freely. A value of - // rtc::kNetworkCostMax indicates it should be used only as the last resort. - void set_network_cost(uint16_t network_cost) { - RTC_DCHECK_LE(network_cost, rtc::kNetworkCostMax); - network_cost_ = network_cost; - } - uint16_t network_cost() const { return network_cost_; } - - // An ID assigned to the network hosting the candidate. - uint16_t network_id() const { return network_id_; } - void set_network_id(uint16_t network_id) { network_id_ = network_id; } - - const std::string& foundation() const { - return foundation_; - } - void set_foundation(const std::string& foundation) { - foundation_ = foundation; - } - - const rtc::SocketAddress & related_address() const { - return related_address_; - } - void set_related_address( - const rtc::SocketAddress & related_address) { - related_address_ = related_address; - } - const std::string& tcptype() const { return tcptype_; } - void set_tcptype(const std::string& tcptype){ - tcptype_ = tcptype; - } - - // The name of the transport channel of this candidate. - const std::string& transport_name() const { return transport_name_; } - void set_transport_name(const std::string& transport_name) { - transport_name_ = transport_name; - } - - // The URL of the ICE server which this candidate is gathered from. - const std::string& url() const { return url_; } - void set_url(const std::string& url) { url_ = url; } - - // Determines whether this candidate is equivalent to the given one. - bool IsEquivalent(const Candidate& c) const { - // We ignore the network name, since that is just debug information, and - // the priority and the network cost, since they should be the same if the - // rest are. - return (component_ == c.component_) && (protocol_ == c.protocol_) && - (address_ == c.address_) && (username_ == c.username_) && - (password_ == c.password_) && (type_ == c.type_) && - (generation_ == c.generation_) && (foundation_ == c.foundation_) && - (related_address_ == c.related_address_) && - (network_id_ == c.network_id_); - } - - // Determines whether this candidate can be considered equivalent to the - // given one when looking for a matching candidate to remove. - bool MatchesForRemoval(const Candidate& c) const { - return component_ == c.component_ && protocol_ == c.protocol_ && - address_ == c.address_; - } - - std::string ToString() const { - return ToStringInternal(false); - } - - std::string ToSensitiveString() const { - return ToStringInternal(true); - } - - uint32_t GetPriority(uint32_t type_preference, - int network_adapter_preference, - int relay_preference) const { - // RFC 5245 - 4.1.2.1. - // priority = (2^24)*(type preference) + - // (2^8)*(local preference) + - // (2^0)*(256 - component ID) - - // |local_preference| length is 2 bytes, 0-65535 inclusive. - // In our implemenation we will partion local_preference into - // 0 1 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | NIC Pref | Addr Pref | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // NIC Type - Type of the network adapter e.g. 3G/Wifi/Wired. - // Addr Pref - Address preference value as per RFC 3484. - // local preference = (NIC Type << 8 | Addr_Pref) - relay preference. - - int addr_pref = IPAddressPrecedence(address_.ipaddr()); - int local_preference = ((network_adapter_preference << 8) | addr_pref) + - relay_preference; - - return (type_preference << 24) | - (local_preference << 8) | - (256 - component_); - } - - bool operator==(const Candidate& o) const { - return id_ == o.id_ && component_ == o.component_ && - protocol_ == o.protocol_ && relay_protocol_ == o.relay_protocol_ && - address_ == o.address_ && priority_ == o.priority_ && - username_ == o.username_ && password_ == o.password_ && - type_ == o.type_ && network_name_ == o.network_name_ && - network_type_ == o.network_type_ && generation_ == o.generation_ && - foundation_ == o.foundation_ && - related_address_ == o.related_address_ && tcptype_ == o.tcptype_ && - transport_name_ == o.transport_name_ && network_id_ == o.network_id_; - } - bool operator!=(const Candidate& o) const { return !(*this == o); } - - private: - std::string ToStringInternal(bool sensitive) const { - std::ostringstream ost; - std::string address = sensitive ? address_.ToSensitiveString() : - address_.ToString(); - ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_ - << ":" << protocol_ << ":" << priority_ << ":" << address << ":" - << type_ << ":" << related_address_ << ":" << username_ << ":" - << password_ << ":" << network_id_ << ":" << network_cost_ << ":" - << generation_ << "]"; - return ost.str(); - } - - std::string id_; - int component_; - std::string protocol_; - std::string relay_protocol_; - rtc::SocketAddress address_; - uint32_t priority_; - std::string username_; - std::string password_; - std::string type_; - std::string network_name_; - rtc::AdapterType network_type_; - uint32_t generation_; - std::string foundation_; - rtc::SocketAddress related_address_; - std::string tcptype_; - std::string transport_name_; - uint16_t network_id_; - uint16_t network_cost_; - std::string url_; -}; - -// Used during parsing and writing to map component to channel name -// and back. This is primarily for converting old G-ICE candidate -// signalling to new ICE candidate classes. -class CandidateTranslator { - public: - virtual ~CandidateTranslator() {} - virtual bool GetChannelNameFromComponent( - int component, std::string* channel_name) const = 0; - virtual bool GetComponentFromChannelName( - const std::string& channel_name, int* component) const = 0; -}; - -} // namespace cricket - -#endif // P2P_BASE_CANDIDATE_H_ +#endif // P2P_CANDIDATE_H_ diff --git a/p2p/base/fakecandidatepair.h b/p2p/base/fakecandidatepair.h index 17387892fb..c49ac479bc 100644 --- a/p2p/base/fakecandidatepair.h +++ b/p2p/base/fakecandidatepair.h @@ -13,7 +13,7 @@ #include -#include "p2p/base/candidate.h" +#include "api/candidate.h" #include "p2p/base/candidatepairinterface.h" namespace cricket { diff --git a/p2p/base/icetransportinternal.h b/p2p/base/icetransportinternal.h index 5c67df9da6..48f8806277 100644 --- a/p2p/base/icetransportinternal.h +++ b/p2p/base/icetransportinternal.h @@ -13,7 +13,7 @@ #include -#include "p2p/base/candidate.h" +#include "api/candidate.h" #include "p2p/base/candidatepairinterface.h" #include "p2p/base/jseptransport.h" #include "p2p/base/packettransportinternal.h" diff --git a/p2p/base/jseptransport.cc b/p2p/base/jseptransport.cc index 74094fa07f..fbb6287ab2 100644 --- a/p2p/base/jseptransport.cc +++ b/p2p/base/jseptransport.cc @@ -13,7 +13,7 @@ #include #include // for std::pair -#include "p2p/base/candidate.h" +#include "api/candidate.h" #include "p2p/base/dtlstransport.h" #include "p2p/base/p2pconstants.h" #include "p2p/base/p2ptransportchannel.h" diff --git a/p2p/base/jseptransport.h b/p2p/base/jseptransport.h index 3486342a84..4cf9695ece 100644 --- a/p2p/base/jseptransport.h +++ b/p2p/base/jseptransport.h @@ -16,8 +16,8 @@ #include #include +#include "api/candidate.h" #include "api/optional.h" -#include "p2p/base/candidate.h" #include "p2p/base/p2pconstants.h" #include "p2p/base/sessiondescription.h" #include "p2p/base/transportinfo.h" diff --git a/p2p/base/p2ptransportchannel.cc b/p2p/base/p2ptransportchannel.cc index 44f8eee8ef..c02bac7e66 100644 --- a/p2p/base/p2ptransportchannel.cc +++ b/p2p/base/p2ptransportchannel.cc @@ -14,8 +14,8 @@ #include #include +#include "api/candidate.h" #include "api/umametrics.h" -#include "p2p/base/candidate.h" #include "p2p/base/candidatepairinterface.h" #include "p2p/base/common.h" #include "p2p/base/relayport.h" // For RELAY_PORT_TYPE. diff --git a/p2p/base/p2ptransportchannel.h b/p2p/base/p2ptransportchannel.h index b6a84bec94..56ca57e11e 100644 --- a/p2p/base/p2ptransportchannel.h +++ b/p2p/base/p2ptransportchannel.h @@ -26,7 +26,7 @@ #include #include -#include "p2p/base/candidate.h" +#include "api/candidate.h" #include "p2p/base/candidatepairinterface.h" #include "p2p/base/icetransportinternal.h" #include "p2p/base/portallocator.h" diff --git a/p2p/base/port.h b/p2p/base/port.h index 65f4d79f12..61fd750691 100644 --- a/p2p/base/port.h +++ b/p2p/base/port.h @@ -17,8 +17,8 @@ #include #include +#include "api/candidate.h" #include "api/optional.h" -#include "p2p/base/candidate.h" #include "p2p/base/candidatepairinterface.h" #include "p2p/base/jseptransport.h" #include "p2p/base/packetlossestimator.h" diff --git a/p2p/base/transportinfo.h b/p2p/base/transportinfo.h index 3657b8dce5..3502423c12 100644 --- a/p2p/base/transportinfo.h +++ b/p2p/base/transportinfo.h @@ -14,7 +14,7 @@ #include #include -#include "p2p/base/candidate.h" +#include "api/candidate.h" #include "p2p/base/p2pconstants.h" #include "p2p/base/transportdescription.h" #include "rtc_base/helpers.h" diff --git a/pc/jsepsessiondescription_unittest.cc b/pc/jsepsessiondescription_unittest.cc index 781b59690a..8e3c10f7c5 100644 --- a/pc/jsepsessiondescription_unittest.cc +++ b/pc/jsepsessiondescription_unittest.cc @@ -11,10 +11,10 @@ #include #include +#include "api/candidate.h" #include "api/jsepicecandidate.h" #include "api/jsepsessiondescription.h" #include "api/webrtcsdp.h" -#include "p2p/base/candidate.h" #include "p2p/base/p2pconstants.h" #include "p2p/base/sessiondescription.h" #include "pc/mediasession.h" diff --git a/pc/rtcstatscollector.cc b/pc/rtcstatscollector.cc index b282e7dc16..36a4d6eb06 100644 --- a/pc/rtcstatscollector.cc +++ b/pc/rtcstatscollector.cc @@ -15,10 +15,10 @@ #include #include +#include "api/candidate.h" #include "api/mediastreaminterface.h" #include "api/peerconnectioninterface.h" #include "media/base/mediachannel.h" -#include "p2p/base/candidate.h" #include "p2p/base/p2pconstants.h" #include "p2p/base/port.h" #include "pc/peerconnection.h" diff --git a/pc/transportcontroller.h b/pc/transportcontroller.h index f8cfc0c2ef..be8dd8af70 100644 --- a/pc/transportcontroller.h +++ b/pc/transportcontroller.h @@ -16,7 +16,7 @@ #include #include -#include "p2p/base/candidate.h" +#include "api/candidate.h" #include "p2p/base/dtlstransport.h" #include "p2p/base/jseptransport.h" #include "p2p/base/p2ptransportchannel.h" diff --git a/pc/webrtcsdp.cc b/pc/webrtcsdp.cc index 648d78c76b..47e429863e 100644 --- a/pc/webrtcsdp.cc +++ b/pc/webrtcsdp.cc @@ -20,6 +20,7 @@ #include #include +#include "api/candidate.h" #include "api/jsepicecandidate.h" #include "api/jsepsessiondescription.h" // for RtpExtension @@ -29,7 +30,6 @@ #include "media/base/mediaconstants.h" #include "media/base/rtputils.h" #include "media/sctp/sctptransportinternal.h" -#include "p2p/base/candidate.h" #include "p2p/base/p2pconstants.h" #include "p2p/base/port.h" #include "pc/mediasession.h" diff --git a/pc/webrtcsession.h b/pc/webrtcsession.h index 44b64b8a36..284c601b41 100644 --- a/pc/webrtcsession.h +++ b/pc/webrtcsession.h @@ -16,11 +16,11 @@ #include #include +#include "api/candidate.h" #include "api/optional.h" #include "api/peerconnectioninterface.h" #include "api/statstypes.h" #include "call/call.h" -#include "p2p/base/candidate.h" #include "pc/datachannel.h" #include "pc/mediasession.h" #include "pc/transportcontroller.h" diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 4167ad1b26..8c3000e0d0 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -526,6 +526,7 @@ rtc_static_library("rtc_base_generic") { "nethelpers.h", "network.cc", "network.h", + "network_constants.h", "networkmonitor.cc", "networkmonitor.h", "nullsocketserver.cc", diff --git a/rtc_base/network.h b/rtc_base/network.h index b3b43d834f..6bddf4626a 100644 --- a/rtc_base/network.h +++ b/rtc_base/network.h @@ -38,12 +38,6 @@ class Network; class NetworkMonitorInterface; class Thread; -static const uint16_t kNetworkCostMax = 999; -static const uint16_t kNetworkCostHigh = 900; -static const uint16_t kNetworkCostUnknown = 50; -static const uint16_t kNetworkCostLow = 10; -static const uint16_t kNetworkCostMin = 0; - // By default, ignore loopback interfaces on the host. const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK; diff --git a/rtc_base/network_constants.h b/rtc_base/network_constants.h new file mode 100644 index 0000000000..b4c8beaf31 --- /dev/null +++ b/rtc_base/network_constants.h @@ -0,0 +1,36 @@ +/* + * Copyright 2004 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. + */ + +#ifndef RTC_BASE_NETWORK_CONSTANTS_H_ +#define RTC_BASE_NETWORK_CONSTANTS_H_ + +#include + +namespace rtc { + +static const uint16_t kNetworkCostMax = 999; +static const uint16_t kNetworkCostHigh = 900; +static const uint16_t kNetworkCostUnknown = 50; +static const uint16_t kNetworkCostLow = 10; +static const uint16_t kNetworkCostMin = 0; + +enum AdapterType { + // This enum resembles the one in Chromium net::ConnectionType. + ADAPTER_TYPE_UNKNOWN = 0, + ADAPTER_TYPE_ETHERNET = 1 << 0, + ADAPTER_TYPE_WIFI = 1 << 1, + ADAPTER_TYPE_CELLULAR = 1 << 2, + ADAPTER_TYPE_VPN = 1 << 3, + ADAPTER_TYPE_LOOPBACK = 1 << 4 +}; + +} // namespace rtc + +#endif // RTC_BASE_NETWORK_CONSTANTS_H_ diff --git a/rtc_base/networkmonitor.h b/rtc_base/networkmonitor.h index d98b803169..254b22575a 100644 --- a/rtc_base/networkmonitor.h +++ b/rtc_base/networkmonitor.h @@ -12,6 +12,7 @@ #define RTC_BASE_NETWORKMONITOR_H_ #include "rtc_base/logging.h" +#include "rtc_base/network_constants.h" #include "rtc_base/sigslot.h" #include "rtc_base/thread.h" @@ -27,16 +28,6 @@ enum class NetworkBindingResult { NETWORK_CHANGED = -4 }; -enum AdapterType { - // This enum resembles the one in Chromium net::ConnectionType. - ADAPTER_TYPE_UNKNOWN = 0, - ADAPTER_TYPE_ETHERNET = 1 << 0, - ADAPTER_TYPE_WIFI = 1 << 1, - ADAPTER_TYPE_CELLULAR = 1 << 2, - ADAPTER_TYPE_VPN = 1 << 3, - ADAPTER_TYPE_LOOPBACK = 1 << 4 -}; - class NetworkBinderInterface { public: // Binds a socket to the network that is attached to |address| so that all