123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- #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/network_constants.h"
- #include "rtc_base/socket_address.h"
- #include "rtc_base/system/rtc_export.h"
- namespace cricket {
- class RTC_EXPORT Candidate {
- public:
- Candidate();
-
-
- 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);
- Candidate(const Candidate&);
- ~Candidate();
- 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; }
-
- 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; }
-
-
-
-
-
-
- float preference() const {
-
- return static_cast<float>(((priority_ >> 24) * 100 / 127) / 100.0);
- }
-
-
- void set_preference(float preference) {
-
-
- 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)));
- }
-
- 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;
- }
-
- uint32_t generation() const { return generation_; }
- void set_generation(uint32_t generation) { generation_ = generation; }
-
-
-
- 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_; }
-
- 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; }
-
-
- const std::string& transport_name() const { return transport_name_; }
- void set_transport_name(const std::string& transport_name) {
- transport_name_ = transport_name;
- }
-
- const std::string& url() const { return url_; }
- void set_url(const std::string& url) { url_ = url; }
-
- bool IsEquivalent(const Candidate& c) const;
-
-
- bool MatchesForRemoval(const Candidate& c) const;
- 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;
- bool operator==(const Candidate& o) const;
- bool operator!=(const Candidate& o) const;
-
-
-
-
-
-
-
- Candidate ToSanitizedCopy(bool use_hostname_address,
- bool filter_related_address) const;
- private:
- std::string ToStringInternal(bool sensitive) const;
- 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_;
- };
- }
- #endif
|