Reland "Clean up libjingle API dependencies."

This is a reland of 9185aca9ce

> 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 <solenberg@webrtc.org>
> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
> 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 <phoglund@webrtc.org>
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20167}
This commit is contained in:
Patrik Höglund 2017-10-05 14:53:33 +02:00 committed by Commit Bot
parent 779d3657ef
commit e2d6a06fa8
23 changed files with 401 additions and 338 deletions

View file

@ -34,12 +34,9 @@ rtc_source_set("call_api") {
} }
rtc_static_library("libjingle_peerconnection_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 = [] cflags = []
sources = [ sources = [
"datachannel.h", "candidate.h",
"datachannelinterface.h", "datachannelinterface.h",
"dtmfsenderinterface.h", "dtmfsenderinterface.h",
"jsep.h", "jsep.h",
@ -47,17 +44,13 @@ rtc_static_library("libjingle_peerconnection_api") {
"jsepsessiondescription.h", "jsepsessiondescription.h",
"mediaconstraintsinterface.cc", "mediaconstraintsinterface.cc",
"mediaconstraintsinterface.h", "mediaconstraintsinterface.h",
"mediastream.h",
"mediastreaminterface.cc", "mediastreaminterface.cc",
"mediastreaminterface.h",
"mediastreamproxy.h", "mediastreamproxy.h",
"mediastreamtrack.h",
"mediastreamtrackproxy.h", "mediastreamtrackproxy.h",
"mediatypes.cc", "mediatypes.cc",
"mediatypes.h", "mediatypes.h",
"notifier.h", "notifier.h",
"peerconnectionfactoryproxy.h", "peerconnectionfactoryproxy.h",
"peerconnectioninterface.h",
"peerconnectionproxy.h", "peerconnectionproxy.h",
"proxy.h", "proxy.h",
"rtcerror.cc", "rtcerror.cc",
@ -65,15 +58,11 @@ rtc_static_library("libjingle_peerconnection_api") {
"rtpparameters.cc", "rtpparameters.cc",
"rtpparameters.h", "rtpparameters.h",
"rtpreceiverinterface.h", "rtpreceiverinterface.h",
"rtpsender.h",
"rtpsenderinterface.h", "rtpsenderinterface.h",
"statstypes.cc", "statstypes.cc",
"statstypes.h", "statstypes.h",
"streamcollection.h",
"umametrics.h", "umametrics.h",
"videosourceproxy.h", "videosourceproxy.h",
"videotracksource.h",
"webrtcsdp.h",
] ]
if (!build_with_chromium && is_clang) { if (!build_with_chromium && is_clang) {
@ -81,7 +70,17 @@ rtc_static_library("libjingle_peerconnection_api") {
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] 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 = [ 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", ":rtc_stats_api",
"..:webrtc_common", "..:webrtc_common",
"../rtc_base:rtc_base", "../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") { rtc_source_set("ortc_api") {
check_includes = false # TODO(deadbeef): Remove (bugs.webrtc.org/6828) check_includes = false # TODO(deadbeef): Remove (bugs.webrtc.org/6828)
sources = [ sources = [

293
api/candidate.h Normal file
View file

@ -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 <limits.h>
#include <stdint.h>
#include <algorithm>
#include <string>
#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<float>(((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<uint64_t>(preference * 127) << 24;
priority_ = static_cast<uint32_t>(
std::min(prio_val, static_cast<uint64_t>(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_

View file

@ -18,8 +18,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/jsep.h" #include "api/jsep.h"
#include "p2p/base/candidate.h"
#include "rtc_base/constructormagic.h" #include "rtc_base/constructormagic.h"
namespace webrtc { namespace webrtc {

View file

@ -18,9 +18,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/jsep.h" #include "api/jsep.h"
#include "api/jsepicecandidate.h" #include "api/jsepicecandidate.h"
#include "p2p/base/candidate.h"
#include "rtc_base/constructormagic.h" #include "rtc_base/constructormagic.h"
namespace cricket { namespace cricket {

View file

@ -27,7 +27,6 @@
// TODO(zhihuang): Remove unrelated headers once downstream applications stop // TODO(zhihuang): Remove unrelated headers once downstream applications stop
// relying on them; they were previously transitively included by // relying on them; they were previously transitively included by
// mediachannel.h, which is no longer a dependency of this file. // mediachannel.h, which is no longer a dependency of this file.
#include "media/base/streamparams.h"
#include "media/base/videosinkinterface.h" #include "media/base/videosinkinterface.h"
#include "media/base/videosourceinterface.h" #include "media/base/videosourceinterface.h"
#include "rtc_base/ratetracker.h" #include "rtc_base/ratetracker.h"

View file

@ -8,300 +8,12 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef P2P_BASE_CANDIDATE_H_ // TODO(phoglund): remove this file after downstream projects are updated.
#define P2P_BASE_CANDIDATE_H_ // See bugs.webrtc.org/7504.
#include <limits.h> #ifndef P2P_CANDIDATE_H_
#include <math.h> #define P2P_CANDIDATE_H_
#include <stdint.h>
#include <algorithm> #include "api/candidate.h"
#include <iomanip>
#include <sstream>
#include <string>
#include "p2p/base/p2pconstants.h" #endif // P2P_CANDIDATE_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<float>(((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<uint64_t>(preference * 127) << 24;
priority_ = static_cast<uint32_t>(
std::min(prio_val, static_cast<uint64_t>(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_

View file

@ -13,7 +13,7 @@
#include <memory> #include <memory>
#include "p2p/base/candidate.h" #include "api/candidate.h"
#include "p2p/base/candidatepairinterface.h" #include "p2p/base/candidatepairinterface.h"
namespace cricket { namespace cricket {

View file

@ -13,7 +13,7 @@
#include <string> #include <string>
#include "p2p/base/candidate.h" #include "api/candidate.h"
#include "p2p/base/candidatepairinterface.h" #include "p2p/base/candidatepairinterface.h"
#include "p2p/base/jseptransport.h" #include "p2p/base/jseptransport.h"
#include "p2p/base/packettransportinternal.h" #include "p2p/base/packettransportinternal.h"

View file

@ -13,7 +13,7 @@
#include <memory> #include <memory>
#include <utility> // for std::pair #include <utility> // for std::pair
#include "p2p/base/candidate.h" #include "api/candidate.h"
#include "p2p/base/dtlstransport.h" #include "p2p/base/dtlstransport.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/p2ptransportchannel.h" #include "p2p/base/p2ptransportchannel.h"

View file

@ -16,8 +16,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/optional.h" #include "api/optional.h"
#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/sessiondescription.h" #include "p2p/base/sessiondescription.h"
#include "p2p/base/transportinfo.h" #include "p2p/base/transportinfo.h"

View file

@ -14,8 +14,8 @@
#include <iterator> #include <iterator>
#include <set> #include <set>
#include "api/candidate.h"
#include "api/umametrics.h" #include "api/umametrics.h"
#include "p2p/base/candidate.h"
#include "p2p/base/candidatepairinterface.h" #include "p2p/base/candidatepairinterface.h"
#include "p2p/base/common.h" #include "p2p/base/common.h"
#include "p2p/base/relayport.h" // For RELAY_PORT_TYPE. #include "p2p/base/relayport.h" // For RELAY_PORT_TYPE.

View file

@ -26,7 +26,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "p2p/base/candidate.h" #include "api/candidate.h"
#include "p2p/base/candidatepairinterface.h" #include "p2p/base/candidatepairinterface.h"
#include "p2p/base/icetransportinternal.h" #include "p2p/base/icetransportinternal.h"
#include "p2p/base/portallocator.h" #include "p2p/base/portallocator.h"

View file

@ -17,8 +17,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/optional.h" #include "api/optional.h"
#include "p2p/base/candidate.h"
#include "p2p/base/candidatepairinterface.h" #include "p2p/base/candidatepairinterface.h"
#include "p2p/base/jseptransport.h" #include "p2p/base/jseptransport.h"
#include "p2p/base/packetlossestimator.h" #include "p2p/base/packetlossestimator.h"

View file

@ -14,7 +14,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "p2p/base/candidate.h" #include "api/candidate.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/transportdescription.h" #include "p2p/base/transportdescription.h"
#include "rtc_base/helpers.h" #include "rtc_base/helpers.h"

View file

@ -11,10 +11,10 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "api/candidate.h"
#include "api/jsepicecandidate.h" #include "api/jsepicecandidate.h"
#include "api/jsepsessiondescription.h" #include "api/jsepsessiondescription.h"
#include "api/webrtcsdp.h" #include "api/webrtcsdp.h"
#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/sessiondescription.h" #include "p2p/base/sessiondescription.h"
#include "pc/mediasession.h" #include "pc/mediasession.h"

View file

@ -15,10 +15,10 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/mediastreaminterface.h" #include "api/mediastreaminterface.h"
#include "api/peerconnectioninterface.h" #include "api/peerconnectioninterface.h"
#include "media/base/mediachannel.h" #include "media/base/mediachannel.h"
#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/port.h" #include "p2p/base/port.h"
#include "pc/peerconnection.h" #include "pc/peerconnection.h"

View file

@ -16,7 +16,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "p2p/base/candidate.h" #include "api/candidate.h"
#include "p2p/base/dtlstransport.h" #include "p2p/base/dtlstransport.h"
#include "p2p/base/jseptransport.h" #include "p2p/base/jseptransport.h"
#include "p2p/base/p2ptransportchannel.h" #include "p2p/base/p2ptransportchannel.h"

View file

@ -20,6 +20,7 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/jsepicecandidate.h" #include "api/jsepicecandidate.h"
#include "api/jsepsessiondescription.h" #include "api/jsepsessiondescription.h"
// for RtpExtension // for RtpExtension
@ -29,7 +30,6 @@
#include "media/base/mediaconstants.h" #include "media/base/mediaconstants.h"
#include "media/base/rtputils.h" #include "media/base/rtputils.h"
#include "media/sctp/sctptransportinternal.h" #include "media/sctp/sctptransportinternal.h"
#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/port.h" #include "p2p/base/port.h"
#include "pc/mediasession.h" #include "pc/mediasession.h"

View file

@ -16,11 +16,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/candidate.h"
#include "api/optional.h" #include "api/optional.h"
#include "api/peerconnectioninterface.h" #include "api/peerconnectioninterface.h"
#include "api/statstypes.h" #include "api/statstypes.h"
#include "call/call.h" #include "call/call.h"
#include "p2p/base/candidate.h"
#include "pc/datachannel.h" #include "pc/datachannel.h"
#include "pc/mediasession.h" #include "pc/mediasession.h"
#include "pc/transportcontroller.h" #include "pc/transportcontroller.h"

View file

@ -526,6 +526,7 @@ rtc_static_library("rtc_base_generic") {
"nethelpers.h", "nethelpers.h",
"network.cc", "network.cc",
"network.h", "network.h",
"network_constants.h",
"networkmonitor.cc", "networkmonitor.cc",
"networkmonitor.h", "networkmonitor.h",
"nullsocketserver.cc", "nullsocketserver.cc",

View file

@ -38,12 +38,6 @@ class Network;
class NetworkMonitorInterface; class NetworkMonitorInterface;
class Thread; 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. // By default, ignore loopback interfaces on the host.
const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK; const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK;

View file

@ -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 <stdint.h>
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_

View file

@ -12,6 +12,7 @@
#define RTC_BASE_NETWORKMONITOR_H_ #define RTC_BASE_NETWORKMONITOR_H_
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/sigslot.h" #include "rtc_base/sigslot.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
@ -27,16 +28,6 @@ enum class NetworkBindingResult {
NETWORK_CHANGED = -4 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 { class NetworkBinderInterface {
public: public:
// Binds a socket to the network that is attached to |address| so that all // Binds a socket to the network that is attached to |address| so that all