2014-10-28 22:20:11 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef P2P_BASE_PORT_H_
|
|
|
|
|
#define P2P_BASE_PORT_H_
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
#include <map>
|
2016-04-27 07:22:53 -07:00
|
|
|
#include <memory>
|
2014-10-28 22:20:11 +00:00
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
2019-06-01 12:23:43 +03:00
|
|
|
#include <utility>
|
2014-10-28 22:20:11 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-06-15 15:58:38 +02:00
|
|
|
#include "absl/types/optional.h"
|
2017-10-05 14:53:33 +02:00
|
|
|
#include "api/candidate.h"
|
2019-09-17 12:16:35 +02:00
|
|
|
#include "api/packet_socket_factory.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/rtc_error.h"
|
2018-01-30 17:13:09 -08:00
|
|
|
#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair.h"
|
|
|
|
|
#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "logging/rtc_event_log/ice_logger.h"
|
|
|
|
|
#include "p2p/base/candidate_pair_interface.h"
|
2019-05-29 09:30:55 +02:00
|
|
|
#include "p2p/base/connection.h"
|
|
|
|
|
#include "p2p/base/connection_info.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/p2p_constants.h"
|
|
|
|
|
#include "p2p/base/port_interface.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "p2p/base/stun.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/stun_request.h"
|
|
|
|
|
#include "rtc_base/async_packet_socket.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/net_helper.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/network.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/proxy_info.h"
|
|
|
|
|
#include "rtc_base/rate_tracker.h"
|
|
|
|
|
#include "rtc_base/socket_address.h"
|
2018-10-22 17:08:37 +02:00
|
|
|
#include "rtc_base/system/rtc_export.h"
|
2018-07-25 15:04:28 +02:00
|
|
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread.h"
|
2018-09-12 22:51:55 -07:00
|
|
|
#include "rtc_base/weak_ptr.h"
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
2019-04-02 11:33:59 +02:00
|
|
|
RTC_EXPORT extern const char LOCAL_PORT_TYPE[];
|
|
|
|
|
RTC_EXPORT extern const char STUN_PORT_TYPE[];
|
|
|
|
|
RTC_EXPORT extern const char PRFLX_PORT_TYPE[];
|
2018-10-22 17:08:37 +02:00
|
|
|
RTC_EXPORT extern const char RELAY_PORT_TYPE[];
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// RFC 6544, TCP candidate encoding rules.
|
|
|
|
|
extern const int DISCARD_PORT;
|
|
|
|
|
extern const char TCPTYPE_ACTIVE_STR[];
|
|
|
|
|
extern const char TCPTYPE_PASSIVE_STR[];
|
|
|
|
|
extern const char TCPTYPE_SIMOPEN_STR[];
|
|
|
|
|
|
|
|
|
|
enum IcePriorityValue {
|
2016-12-13 05:17:23 -08:00
|
|
|
ICE_TYPE_PREFERENCE_RELAY_TLS = 0,
|
|
|
|
|
ICE_TYPE_PREFERENCE_RELAY_TCP = 1,
|
|
|
|
|
ICE_TYPE_PREFERENCE_RELAY_UDP = 2,
|
2016-08-11 16:05:07 -07:00
|
|
|
ICE_TYPE_PREFERENCE_PRFLX_TCP = 80,
|
2014-10-28 22:20:11 +00:00
|
|
|
ICE_TYPE_PREFERENCE_HOST_TCP = 90,
|
|
|
|
|
ICE_TYPE_PREFERENCE_SRFLX = 100,
|
|
|
|
|
ICE_TYPE_PREFERENCE_PRFLX = 110,
|
|
|
|
|
ICE_TYPE_PREFERENCE_HOST = 126
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-06 17:51:02 -08:00
|
|
|
enum class MdnsNameRegistrationStatus {
|
|
|
|
|
// IP concealment with mDNS is not enabled or the name registration process is
|
|
|
|
|
// not started yet.
|
|
|
|
|
kNotStarted,
|
|
|
|
|
// A request to create and register an mDNS name for a local IP address of a
|
|
|
|
|
// host candidate is sent to the mDNS responder.
|
|
|
|
|
kInProgress,
|
|
|
|
|
// The name registration is complete and the created name is returned by the
|
|
|
|
|
// mDNS responder.
|
|
|
|
|
kCompleted,
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-26 19:29:05 -08:00
|
|
|
// Stats that we can return about the port of a STUN candidate.
|
2018-02-20 16:03:18 -08:00
|
|
|
class StunStats {
|
|
|
|
|
public:
|
|
|
|
|
StunStats() = default;
|
|
|
|
|
StunStats(const StunStats&) = default;
|
|
|
|
|
~StunStats() = default;
|
|
|
|
|
|
|
|
|
|
StunStats& operator=(const StunStats& other) = default;
|
|
|
|
|
|
|
|
|
|
int stun_binding_requests_sent = 0;
|
|
|
|
|
int stun_binding_responses_received = 0;
|
|
|
|
|
double stun_binding_rtt_ms_total = 0;
|
|
|
|
|
double stun_binding_rtt_ms_squared_total = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Stats that we can return about a candidate.
|
|
|
|
|
class CandidateStats {
|
|
|
|
|
public:
|
|
|
|
|
CandidateStats();
|
|
|
|
|
explicit CandidateStats(Candidate candidate);
|
|
|
|
|
CandidateStats(const CandidateStats&);
|
|
|
|
|
~CandidateStats();
|
|
|
|
|
|
|
|
|
|
Candidate candidate;
|
|
|
|
|
// STUN port stats if this candidate is a STUN candidate.
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<StunStats> stun_stats;
|
2018-02-20 16:03:18 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::vector<CandidateStats> CandidateStatsList;
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
const char* ProtoToString(ProtocolType proto);
|
|
|
|
|
bool StringToProto(const char* value, ProtocolType* proto);
|
|
|
|
|
|
|
|
|
|
struct ProtocolAddress {
|
|
|
|
|
rtc::SocketAddress address;
|
|
|
|
|
ProtocolType proto;
|
|
|
|
|
|
|
|
|
|
ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p)
|
2016-12-13 05:17:23 -08:00
|
|
|
: address(a), proto(p) {}
|
2016-05-13 08:15:11 -07:00
|
|
|
|
|
|
|
|
bool operator==(const ProtocolAddress& o) const {
|
2016-12-13 05:17:23 -08:00
|
|
|
return address == o.address && proto == o.proto;
|
2016-05-13 08:15:11 -07:00
|
|
|
}
|
|
|
|
|
bool operator!=(const ProtocolAddress& o) const { return !(*this == o); }
|
2014-10-28 22:20:11 +00:00
|
|
|
};
|
|
|
|
|
|
2019-06-01 12:23:43 +03:00
|
|
|
struct IceCandidateErrorEvent {
|
|
|
|
|
IceCandidateErrorEvent() = default;
|
|
|
|
|
IceCandidateErrorEvent(std::string host_candidate,
|
|
|
|
|
std::string url,
|
|
|
|
|
int error_code,
|
|
|
|
|
std::string error_text)
|
|
|
|
|
: host_candidate(std::move(host_candidate)),
|
|
|
|
|
url(std::move(url)),
|
|
|
|
|
error_code(error_code),
|
|
|
|
|
error_text(std::move(error_text)) {}
|
|
|
|
|
|
|
|
|
|
std::string host_candidate;
|
|
|
|
|
std::string url;
|
|
|
|
|
int error_code = 0;
|
|
|
|
|
std::string error_text;
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-06 10:54:47 -07:00
|
|
|
struct CandidatePairChangeEvent {
|
2019-08-28 09:18:37 -07:00
|
|
|
CandidatePair selected_candidate_pair;
|
2019-08-06 10:54:47 -07:00
|
|
|
int64_t last_data_received_ms;
|
|
|
|
|
std::string reason;
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
typedef std::set<rtc::SocketAddress> ServerAddresses;
|
|
|
|
|
|
|
|
|
|
// Represents a local communication mechanism that can be used to create
|
|
|
|
|
// connections to similar mechanisms of the other client. Subclasses of this
|
|
|
|
|
// one add support for specific mechanisms like local UDP ports.
|
|
|
|
|
class Port : public PortInterface,
|
|
|
|
|
public rtc::MessageHandler,
|
|
|
|
|
public sigslot::has_slots<> {
|
|
|
|
|
public:
|
2016-07-28 18:06:15 -07:00
|
|
|
// INIT: The state when a port is just created.
|
|
|
|
|
// KEEP_ALIVE_UNTIL_PRUNED: A port should not be destroyed even if no
|
|
|
|
|
// connection is using it.
|
|
|
|
|
// PRUNED: It will be destroyed if no connection is using it for a period of
|
|
|
|
|
// 30 seconds.
|
|
|
|
|
enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED };
|
2014-11-06 20:19:22 +00:00
|
|
|
Port(rtc::Thread* thread,
|
2016-06-28 09:44:47 -07:00
|
|
|
const std::string& type,
|
2014-10-28 22:20:11 +00:00
|
|
|
rtc::PacketSocketFactory* factory,
|
2014-11-06 20:19:22 +00:00
|
|
|
rtc::Network* network,
|
|
|
|
|
const std::string& username_fragment,
|
2017-10-31 16:27:34 -07:00
|
|
|
const std::string& password);
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
Port(rtc::Thread* thread,
|
|
|
|
|
const std::string& type,
|
|
|
|
|
rtc::PacketSocketFactory* factory,
|
|
|
|
|
rtc::Network* network,
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint16_t min_port,
|
|
|
|
|
uint16_t max_port,
|
2014-11-06 20:19:22 +00:00
|
|
|
const std::string& username_fragment,
|
2014-10-28 22:20:11 +00:00
|
|
|
const std::string& password);
|
2017-10-30 10:00:15 -07:00
|
|
|
~Port() override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2018-03-01 18:25:20 -08:00
|
|
|
// Note that the port type does NOT uniquely identify different subclasses of
|
|
|
|
|
// Port. Use the 2-tuple of the port type AND the protocol (GetProtocol()) to
|
|
|
|
|
// uniquely identify subclasses. Whenever a new subclass of Port introduces a
|
|
|
|
|
// conflit in the value of the 2-tuple, make sure that the implementation that
|
|
|
|
|
// relies on this 2-tuple for RTTI is properly changed.
|
2017-10-30 10:00:15 -07:00
|
|
|
const std::string& Type() const override;
|
|
|
|
|
rtc::Network* Network() const override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Methods to set/get ICE role and tiebreaker values.
|
2017-10-30 10:00:15 -07:00
|
|
|
IceRole GetIceRole() const override;
|
|
|
|
|
void SetIceRole(IceRole role) override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2017-10-30 10:00:15 -07:00
|
|
|
void SetIceTiebreaker(uint64_t tiebreaker) override;
|
|
|
|
|
uint64_t IceTiebreaker() const override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2017-10-30 10:00:15 -07:00
|
|
|
bool SharedSocket() const override;
|
2014-10-28 22:20:11 +00:00
|
|
|
void ResetSharedSocket() { shared_socket_ = false; }
|
|
|
|
|
|
2016-07-28 18:06:15 -07:00
|
|
|
// Should not destroy the port even if no connection is using it. Called when
|
|
|
|
|
// a port is ready to use.
|
|
|
|
|
void KeepAliveUntilPruned();
|
|
|
|
|
// Allows a port to be destroyed if no connection is using it.
|
|
|
|
|
void Prune();
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
// The thread on which this port performs its I/O.
|
|
|
|
|
rtc::Thread* thread() { return thread_; }
|
|
|
|
|
|
|
|
|
|
// The factory used to create the sockets of this port.
|
|
|
|
|
rtc::PacketSocketFactory* socket_factory() const { return factory_; }
|
|
|
|
|
void set_socket_factory(rtc::PacketSocketFactory* factory) {
|
|
|
|
|
factory_ = factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For debugging purposes.
|
|
|
|
|
const std::string& content_name() const { return content_name_; }
|
|
|
|
|
void set_content_name(const std::string& content_name) {
|
|
|
|
|
content_name_ = content_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int component() const { return component_; }
|
|
|
|
|
void set_component(int component) { component_ = component; }
|
|
|
|
|
|
|
|
|
|
bool send_retransmit_count_attribute() const {
|
|
|
|
|
return send_retransmit_count_attribute_;
|
|
|
|
|
}
|
|
|
|
|
void set_send_retransmit_count_attribute(bool enable) {
|
|
|
|
|
send_retransmit_count_attribute_ = enable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Identifies the generation that this port was created in.
|
2016-06-22 17:14:15 -07:00
|
|
|
uint32_t generation() const { return generation_; }
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
void set_generation(uint32_t generation) { generation_ = generation; }
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
const std::string username_fragment() const;
|
|
|
|
|
const std::string& password() const { return password_; }
|
|
|
|
|
|
2016-05-13 08:15:11 -07:00
|
|
|
// May be called when this port was initially created by a pooled
|
|
|
|
|
// PortAllocatorSession, and is now being assigned to an ICE transport.
|
|
|
|
|
// Updates the information for candidates as well.
|
|
|
|
|
void SetIceParameters(int component,
|
|
|
|
|
const std::string& username_fragment,
|
|
|
|
|
const std::string& password);
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
// Fired when candidates are discovered by the port. When all candidates
|
|
|
|
|
// are discovered that belong to port SignalAddressReady is fired.
|
|
|
|
|
sigslot::signal2<Port*, const Candidate&> SignalCandidateReady;
|
|
|
|
|
// Provides all of the above information in one handy object.
|
2017-10-30 10:00:15 -07:00
|
|
|
const std::vector<Candidate>& Candidates() const override;
|
2019-06-01 12:23:43 +03:00
|
|
|
// Fired when candidate discovery failed using certain server.
|
|
|
|
|
sigslot::signal2<Port*, const IceCandidateErrorEvent&> SignalCandidateError;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// SignalPortComplete is sent when port completes the task of candidates
|
|
|
|
|
// allocation.
|
|
|
|
|
sigslot::signal1<Port*> SignalPortComplete;
|
|
|
|
|
// This signal sent when port fails to allocate candidates and this port
|
|
|
|
|
// can't be used in establishing the connections. When port is in shared mode
|
|
|
|
|
// and port fails to allocate one of the candidates, port shouldn't send
|
|
|
|
|
// this signal as other candidates might be usefull in establishing the
|
|
|
|
|
// connection.
|
|
|
|
|
sigslot::signal1<Port*> SignalPortError;
|
|
|
|
|
|
|
|
|
|
// Returns a map containing all of the connections of this port, keyed by the
|
|
|
|
|
// remote address.
|
|
|
|
|
typedef std::map<rtc::SocketAddress, Connection*> AddressMap;
|
|
|
|
|
const AddressMap& connections() { return connections_; }
|
|
|
|
|
|
|
|
|
|
// Returns the connection to the given address or NULL if none exists.
|
2017-10-30 10:00:15 -07:00
|
|
|
Connection* GetConnection(const rtc::SocketAddress& remote_addr) override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Called each time a connection is created.
|
|
|
|
|
sigslot::signal2<Port*, Connection*> SignalConnectionCreated;
|
|
|
|
|
|
|
|
|
|
// In a shared socket mode each port which shares the socket will decide
|
|
|
|
|
// to accept the packet based on the |remote_addr|. Currently only UDP
|
|
|
|
|
// port implemented this method.
|
|
|
|
|
// TODO(mallinath) - Make it pure virtual.
|
2017-10-30 10:00:15 -07:00
|
|
|
virtual bool HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
|
|
|
|
|
const char* data,
|
|
|
|
|
size_t size,
|
|
|
|
|
const rtc::SocketAddress& remote_addr,
|
2018-11-05 13:01:41 +01:00
|
|
|
int64_t packet_time_us);
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2017-12-18 12:10:43 +01:00
|
|
|
// Shall the port handle packet from this |remote_addr|.
|
|
|
|
|
// This method is overridden by TurnPort.
|
|
|
|
|
virtual bool CanHandleIncomingPacketsFrom(
|
|
|
|
|
const rtc::SocketAddress& remote_addr) const;
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
// Sends a response message (normal or error) to the given request. One of
|
|
|
|
|
// these methods should be called as a response to SignalUnknownAddress.
|
|
|
|
|
// NOTE: You MUST call CreateConnection BEFORE SendBindingResponse.
|
2017-10-30 10:00:15 -07:00
|
|
|
void SendBindingResponse(StunMessage* request,
|
|
|
|
|
const rtc::SocketAddress& addr) override;
|
|
|
|
|
void SendBindingErrorResponse(StunMessage* request,
|
|
|
|
|
const rtc::SocketAddress& addr,
|
|
|
|
|
int error_code,
|
|
|
|
|
const std::string& reason) override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
void set_proxy(const std::string& user_agent, const rtc::ProxyInfo& proxy) {
|
|
|
|
|
user_agent_ = user_agent;
|
|
|
|
|
proxy_ = proxy;
|
|
|
|
|
}
|
|
|
|
|
const std::string& user_agent() { return user_agent_; }
|
|
|
|
|
const rtc::ProxyInfo& proxy() { return proxy_; }
|
|
|
|
|
|
2017-10-30 10:00:15 -07:00
|
|
|
void EnablePortPackets() override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Called if the port has no connections and is no longer useful.
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
2017-10-30 10:00:15 -07:00
|
|
|
void OnMessage(rtc::Message* pmsg) override;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Debugging description of this port
|
2017-10-30 10:00:15 -07:00
|
|
|
std::string ToString() const override;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint16_t min_port() { return min_port_; }
|
|
|
|
|
uint16_t max_port() { return max_port_; }
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Timeout shortening function to speed up unit tests.
|
|
|
|
|
void set_timeout_delay(int delay) { timeout_delay_ = delay; }
|
|
|
|
|
|
|
|
|
|
// This method will return local and remote username fragements from the
|
|
|
|
|
// stun username attribute if present.
|
|
|
|
|
bool ParseStunUsername(const StunMessage* stun_msg,
|
|
|
|
|
std::string* local_username,
|
2015-09-17 18:54:52 -07:00
|
|
|
std::string* remote_username) const;
|
2014-10-28 22:20:11 +00:00
|
|
|
void CreateStunUsername(const std::string& remote_username,
|
|
|
|
|
std::string* stun_username_attr_str) const;
|
|
|
|
|
|
|
|
|
|
bool MaybeIceRoleConflict(const rtc::SocketAddress& addr,
|
|
|
|
|
IceMessage* stun_msg,
|
|
|
|
|
const std::string& remote_ufrag);
|
|
|
|
|
|
2015-10-15 07:26:07 -07:00
|
|
|
// Called when a packet has been sent to the socket.
|
2016-01-14 15:49:16 +01:00
|
|
|
// This is made pure virtual to notify subclasses of Port that they MUST
|
|
|
|
|
// listen to AsyncPacketSocket::SignalSentPacket and then call
|
|
|
|
|
// PortInterface::OnSentPacket.
|
|
|
|
|
virtual void OnSentPacket(rtc::AsyncPacketSocket* socket,
|
|
|
|
|
const rtc::SentPacket& sent_packet) = 0;
|
2015-10-15 07:26:07 -07:00
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
// Called when the socket is currently able to send.
|
|
|
|
|
void OnReadyToSend();
|
|
|
|
|
|
|
|
|
|
// Called when the Connection discovers a local peer reflexive candidate.
|
|
|
|
|
// Returns the index of the new local candidate.
|
|
|
|
|
size_t AddPrflxCandidate(const Candidate& local);
|
|
|
|
|
|
2016-03-23 16:07:48 -07:00
|
|
|
int16_t network_cost() const { return network_cost_; }
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2019-02-20 10:13:16 -05:00
|
|
|
void GetStunStats(absl::optional<StunStats>* stats) override {}
|
2018-02-20 16:03:18 -08:00
|
|
|
|
2019-05-29 09:30:55 +02:00
|
|
|
// Foundation: An arbitrary string that is the same for two candidates
|
|
|
|
|
// that have the same type, base IP address, protocol (UDP, TCP,
|
|
|
|
|
// etc.), and STUN or TURN server. If any of these are different,
|
|
|
|
|
// then the foundation will be different. Two candidate pairs with
|
|
|
|
|
// the same foundation pairs are likely to have similar network
|
|
|
|
|
// characteristics. Foundations are used in the frozen algorithm.
|
|
|
|
|
static std::string ComputeFoundation(const std::string& type,
|
|
|
|
|
const std::string& protocol,
|
|
|
|
|
const std::string& relay_protocol,
|
|
|
|
|
const rtc::SocketAddress& base_address);
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
protected:
|
2016-07-28 18:06:15 -07:00
|
|
|
enum { MSG_DESTROY_IF_DEAD = 0, MSG_FIRST_AVAILABLE };
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2016-05-20 15:08:29 -07:00
|
|
|
virtual void UpdateNetworkCost();
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
void set_type(const std::string& type) { type_ = type; }
|
|
|
|
|
|
2017-02-13 20:33:27 -05:00
|
|
|
// Deprecated. Use the AddAddress() method below with "url" instead.
|
|
|
|
|
// TODO(zhihuang): Remove this after downstream applications stop using it.
|
|
|
|
|
void AddAddress(const rtc::SocketAddress& address,
|
|
|
|
|
const rtc::SocketAddress& base_address,
|
|
|
|
|
const rtc::SocketAddress& related_address,
|
|
|
|
|
const std::string& protocol,
|
|
|
|
|
const std::string& relay_protocol,
|
|
|
|
|
const std::string& tcptype,
|
|
|
|
|
const std::string& type,
|
|
|
|
|
uint32_t type_preference,
|
|
|
|
|
uint32_t relay_preference,
|
2018-11-06 17:51:02 -08:00
|
|
|
bool is_final);
|
2017-02-13 20:33:27 -05:00
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
void AddAddress(const rtc::SocketAddress& address,
|
|
|
|
|
const rtc::SocketAddress& base_address,
|
|
|
|
|
const rtc::SocketAddress& related_address,
|
2015-08-19 16:51:15 -07:00
|
|
|
const std::string& protocol,
|
|
|
|
|
const std::string& relay_protocol,
|
|
|
|
|
const std::string& tcptype,
|
|
|
|
|
const std::string& type,
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t type_preference,
|
|
|
|
|
uint32_t relay_preference,
|
2017-02-13 12:47:27 -08:00
|
|
|
const std::string& url,
|
2018-09-12 22:51:55 -07:00
|
|
|
bool is_final);
|
|
|
|
|
|
|
|
|
|
void FinishAddingAddress(const Candidate& c, bool is_final);
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2018-11-06 17:51:02 -08:00
|
|
|
virtual void PostAddAddress(bool is_final);
|
|
|
|
|
|
2016-06-01 15:57:03 -07:00
|
|
|
// Adds the given connection to the map keyed by the remote candidate address.
|
|
|
|
|
// If an existing connection has the same address, the existing one will be
|
|
|
|
|
// replaced and destroyed.
|
|
|
|
|
void AddOrReplaceConnection(Connection* conn);
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Called when a packet is received from an unknown address that is not
|
|
|
|
|
// currently a connection. If this is an authenticated STUN binding request,
|
|
|
|
|
// then we will signal the client.
|
|
|
|
|
void OnReadPacket(const char* data,
|
|
|
|
|
size_t size,
|
|
|
|
|
const rtc::SocketAddress& addr,
|
|
|
|
|
ProtocolType proto);
|
|
|
|
|
|
|
|
|
|
// If the given data comprises a complete and correct STUN message then the
|
|
|
|
|
// return value is true, otherwise false. If the message username corresponds
|
|
|
|
|
// with this port's username fragment, msg will contain the parsed STUN
|
|
|
|
|
// message. Otherwise, the function may send a STUN response internally.
|
|
|
|
|
// remote_username contains the remote fragment of the STUN username.
|
2016-03-15 11:09:39 -07:00
|
|
|
bool GetStunMessage(const char* data,
|
|
|
|
|
size_t size,
|
2014-10-28 22:20:11 +00:00
|
|
|
const rtc::SocketAddress& addr,
|
2016-04-27 07:22:53 -07:00
|
|
|
std::unique_ptr<IceMessage>* out_msg,
|
2016-03-15 11:09:39 -07:00
|
|
|
std::string* out_username);
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
// Checks if the address in addr is compatible with the port's ip.
|
|
|
|
|
bool IsCompatibleAddress(const rtc::SocketAddress& addr);
|
|
|
|
|
|
2018-09-17 17:06:08 -07:00
|
|
|
// Returns DSCP value packets generated by the port itself should use.
|
|
|
|
|
virtual rtc::DiffServCodePoint StunDscpValue() const;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2016-06-01 15:57:03 -07:00
|
|
|
// Extra work to be done in subclasses when a connection is destroyed.
|
|
|
|
|
virtual void HandleConnectionDestroyed(Connection* conn) {}
|
|
|
|
|
|
2018-04-11 20:14:17 -07:00
|
|
|
void CopyPortInformationToPacketInfo(rtc::PacketInfo* info) const;
|
|
|
|
|
|
2018-11-06 17:51:02 -08:00
|
|
|
MdnsNameRegistrationStatus mdns_name_registration_status() const {
|
|
|
|
|
return mdns_name_registration_status_;
|
|
|
|
|
}
|
|
|
|
|
void set_mdns_name_registration_status(MdnsNameRegistrationStatus status) {
|
|
|
|
|
mdns_name_registration_status_ = status;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
private:
|
|
|
|
|
void Construct();
|
|
|
|
|
// Called when one of our connections deletes itself.
|
|
|
|
|
void OnConnectionDestroyed(Connection* conn);
|
|
|
|
|
|
2016-05-20 15:08:29 -07:00
|
|
|
void OnNetworkTypeChanged(const rtc::Network* network);
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
rtc::Thread* thread_;
|
|
|
|
|
rtc::PacketSocketFactory* factory_;
|
|
|
|
|
std::string type_;
|
|
|
|
|
bool send_retransmit_count_attribute_;
|
|
|
|
|
rtc::Network* network_;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint16_t min_port_;
|
|
|
|
|
uint16_t max_port_;
|
2014-10-28 22:20:11 +00:00
|
|
|
std::string content_name_;
|
|
|
|
|
int component_;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t generation_;
|
2014-10-28 22:20:11 +00:00
|
|
|
// In order to establish a connection to this Port (so that real data can be
|
|
|
|
|
// sent through), the other side must send us a STUN binding request that is
|
|
|
|
|
// authenticated with this username_fragment and password.
|
|
|
|
|
// PortAllocatorSession will provide these username_fragment and password.
|
|
|
|
|
//
|
|
|
|
|
// Note: we should always use username_fragment() instead of using
|
|
|
|
|
// |ice_username_fragment_| directly. For the details see the comment on
|
|
|
|
|
// username_fragment().
|
|
|
|
|
std::string ice_username_fragment_;
|
|
|
|
|
std::string password_;
|
|
|
|
|
std::vector<Candidate> candidates_;
|
|
|
|
|
AddressMap connections_;
|
|
|
|
|
int timeout_delay_;
|
|
|
|
|
bool enable_port_packets_;
|
|
|
|
|
IceRole ice_role_;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint64_t tiebreaker_;
|
2014-10-28 22:20:11 +00:00
|
|
|
bool shared_socket_;
|
|
|
|
|
// Information to use when going through a proxy.
|
|
|
|
|
std::string user_agent_;
|
|
|
|
|
rtc::ProxyInfo proxy_;
|
|
|
|
|
|
2016-02-16 14:54:56 -08:00
|
|
|
// A virtual cost perceived by the user, usually based on the network type
|
|
|
|
|
// (WiFi. vs. Cellular). It takes precedence over the priority when
|
|
|
|
|
// comparing two connections.
|
2017-10-24 15:28:51 +02:00
|
|
|
int16_t network_cost_;
|
2016-07-28 18:06:15 -07:00
|
|
|
State state_ = State::INIT;
|
2016-07-28 13:23:05 -07:00
|
|
|
int64_t last_time_all_connections_removed_ = 0;
|
2018-11-06 17:51:02 -08:00
|
|
|
MdnsNameRegistrationStatus mdns_name_registration_status_ =
|
|
|
|
|
MdnsNameRegistrationStatus::kNotStarted;
|
2016-02-16 14:54:56 -08:00
|
|
|
|
2018-09-12 22:51:55 -07:00
|
|
|
rtc::WeakPtrFactory<Port> weak_factory_;
|
|
|
|
|
|
2018-11-27 13:20:39 -08:00
|
|
|
bool MaybeObfuscateAddress(Candidate* c,
|
|
|
|
|
const std::string& type,
|
|
|
|
|
bool is_final);
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
friend class Connection;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // P2P_BASE_PORT_H_
|