* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef TALK_P2P_BASE_PORT_H_
-#define TALK_P2P_BASE_PORT_H_
+#ifndef WEBRTC_P2P_BASE_PORT_H_
+#define WEBRTC_P2P_BASE_PORT_H_
+#include <map>
+#include <set>
#include <string>
#include <vector>
-#include <map>
-#include "talk/base/network.h"
-#include "talk/base/proxyinfo.h"
-#include "talk/base/ratetracker.h"
-#include "talk/base/sigslot.h"
-#include "talk/base/socketaddress.h"
-#include "talk/base/thread.h"
-#include "talk/p2p/base/candidate.h"
-#include "talk/p2p/base/packetsocketfactory.h"
-#include "talk/p2p/base/portinterface.h"
-#include "talk/p2p/base/stun.h"
-#include "talk/p2p/base/stunrequest.h"
-#include "talk/p2p/base/transport.h"
-
-namespace talk_base {
-class AsyncPacketSocket;
-}
+#include "webrtc/p2p/base/candidate.h"
+#include "webrtc/p2p/base/packetsocketfactory.h"
+#include "webrtc/p2p/base/portinterface.h"
+#include "webrtc/p2p/base/stun.h"
+#include "webrtc/p2p/base/stunrequest.h"
+#include "webrtc/p2p/base/transport.h"
+#include "webrtc/base/asyncpacketsocket.h"
+#include "webrtc/base/network.h"
+#include "webrtc/base/proxyinfo.h"
+#include "webrtc/base/ratetracker.h"
+#include "webrtc/base/sigslot.h"
+#include "webrtc/base/socketaddress.h"
+#include "webrtc/base/thread.h"
namespace cricket {
extern const char TCP_PROTOCOL_NAME[];
extern const char SSLTCP_PROTOCOL_NAME[];
+// 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[];
+
// The length of time we wait before timing out readability on a connection.
const uint32 CONNECTION_READ_TIMEOUT = 30 * 1000; // 30 seconds
bool StringToProto(const char* value, ProtocolType* proto);
struct ProtocolAddress {
- talk_base::SocketAddress address;
+ rtc::SocketAddress address;
ProtocolType proto;
bool secure;
- ProtocolAddress(const talk_base::SocketAddress& a, ProtocolType p)
+ ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p)
: address(a), proto(p), secure(false) { }
- ProtocolAddress(const talk_base::SocketAddress& a, ProtocolType p, bool sec)
+ ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p, bool sec)
: address(a), proto(p), secure(sec) { }
};
+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 talk_base::MessageHandler,
+class Port : public PortInterface, public rtc::MessageHandler,
public sigslot::has_slots<> {
public:
- Port(talk_base::Thread* thread, talk_base::Network* network,
- const talk_base::IPAddress& ip,
+ Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
+ rtc::Network* network, const rtc::IPAddress& ip,
const std::string& username_fragment, const std::string& password);
- Port(talk_base::Thread* thread, const std::string& type,
- talk_base::PacketSocketFactory* factory,
- talk_base::Network* network, const talk_base::IPAddress& ip,
+ Port(rtc::Thread* thread, const std::string& type,
+ rtc::PacketSocketFactory* factory,
+ rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username_fragment,
const std::string& password);
virtual ~Port();
virtual const std::string& Type() const { return type_; }
- virtual talk_base::Network* Network() const { return network_; }
+ virtual rtc::Network* Network() const { return network_; }
// This method will set the flag which enables standard ICE/STUN procedures
// in STUN connectivity checks. Currently this method does
uint64 IceTiebreaker() const { return tiebreaker_; }
virtual bool SharedSocket() const { return shared_socket_; }
+ void ResetSharedSocket() { shared_socket_ = false; }
// The thread on which this port performs its I/O.
- talk_base::Thread* thread() { return thread_; }
+ rtc::Thread* thread() { return thread_; }
// The factory used to create the sockets of this port.
- talk_base::PacketSocketFactory* socket_factory() const { return factory_; }
- void set_socket_factory(talk_base::PacketSocketFactory* factory) {
+ rtc::PacketSocketFactory* socket_factory() const { return factory_; }
+ void set_socket_factory(rtc::PacketSocketFactory* factory) {
factory_ = factory;
}
send_retransmit_count_attribute_ = enable;
}
- const talk_base::SocketAddress& related_address() const {
- return related_address_;
- }
- void set_related_address(const talk_base::SocketAddress& address) {
- related_address_ = address;
- }
-
// Identifies the generation that this port was created in.
uint32 generation() { return generation_; }
void set_generation(uint32 generation) { generation_ = generation; }
// Returns a map containing all of the connections of this port, keyed by the
// remote address.
- typedef std::map<talk_base::SocketAddress, Connection*> AddressMap;
+ typedef std::map<rtc::SocketAddress, Connection*> AddressMap;
const AddressMap& connections() { return connections_; }
// Returns the connection to the given address or NULL if none exists.
virtual Connection* GetConnection(
- const talk_base::SocketAddress& remote_addr);
+ const rtc::SocketAddress& remote_addr);
// Called each time a connection is created.
sigslot::signal2<Port*, Connection*> SignalConnectionCreated;
// port implemented this method.
// TODO(mallinath) - Make it pure virtual.
virtual bool HandleIncomingPacket(
- talk_base::AsyncPacketSocket* socket, const char* data, size_t size,
- const talk_base::SocketAddress& remote_addr) {
+ rtc::AsyncPacketSocket* socket, const char* data, size_t size,
+ const rtc::SocketAddress& remote_addr,
+ const rtc::PacketTime& packet_time) {
ASSERT(false);
return false;
}
// these methods should be called as a response to SignalUnknownAddress.
// NOTE: You MUST call CreateConnection BEFORE SendBindingResponse.
virtual void SendBindingResponse(StunMessage* request,
- const talk_base::SocketAddress& addr);
+ const rtc::SocketAddress& addr);
virtual void SendBindingErrorResponse(
- StunMessage* request, const talk_base::SocketAddress& addr,
+ StunMessage* request, const rtc::SocketAddress& addr,
int error_code, const std::string& reason);
void set_proxy(const std::string& user_agent,
- const talk_base::ProxyInfo& proxy) {
+ const rtc::ProxyInfo& proxy) {
user_agent_ = user_agent;
proxy_ = proxy;
}
const std::string& user_agent() { return user_agent_; }
- const talk_base::ProxyInfo& proxy() { return proxy_; }
+ const rtc::ProxyInfo& proxy() { return proxy_; }
virtual void EnablePortPackets();
- // Indicates to the port that its official use has now begun. This will
- // start the timer that checks to see if the port is being used.
- void Start();
-
// Called if the port has no connections and is no longer useful.
void Destroy();
- virtual void OnMessage(talk_base::Message *pmsg);
+ virtual void OnMessage(rtc::Message *pmsg);
// Debugging description of this port
virtual std::string ToString() const;
- talk_base::IPAddress& ip() { return ip_; }
+ rtc::IPAddress& ip() { return ip_; }
int min_port() { return min_port_; }
int max_port() { return max_port_; }
+ // 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,
- std::string* remote_username) const;
+ std::string* remote_username,
+ IceProtocolType* remote_protocol_type) const;
void CreateStunUsername(const std::string& remote_username,
std::string* stun_username_attr_str) const;
- bool MaybeIceRoleConflict(const talk_base::SocketAddress& addr,
+ bool MaybeIceRoleConflict(const rtc::SocketAddress& addr,
IceMessage* stun_msg,
const std::string& remote_ufrag);
// Returns if Google ICE protocol is used.
bool IsGoogleIce() const;
- // Returns default DSCP value.
- talk_base::DiffServCodePoint DefaultDscpValue() const {
- return default_dscp_;
+ // Returns if Hybrid ICE protocol is used.
+ bool IsHybridIce() const;
+
+ void set_candidate_filter(uint32 candidate_filter) {
+ candidate_filter_ = candidate_filter;
}
protected:
};
void set_type(const std::string& type) { type_ = type; }
- // Fills in the local address of the port.
- void AddAddress(const talk_base::SocketAddress& address,
- const talk_base::SocketAddress& base_address,
- const std::string& protocol, const std::string& type,
- uint32 type_preference, bool final);
+
+ void AddAddress(const rtc::SocketAddress& address,
+ const rtc::SocketAddress& base_address,
+ const rtc::SocketAddress& related_address,
+ const std::string& protocol, const std::string& tcptype,
+ const std::string& type, uint32 type_preference,
+ uint32 relay_preference, bool final);
// Adds the given connection to the list. (Deleting removes them.)
void AddConnection(Connection* conn);
// 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 talk_base::SocketAddress& addr,
+ const rtc::SocketAddress& addr,
ProtocolType proto);
// If the given data comprises a complete and correct STUN message then the
// message. Otherwise, the function may send a STUN response internally.
// remote_username contains the remote fragment of the STUN username.
bool GetStunMessage(const char* data, size_t size,
- const talk_base::SocketAddress& addr,
+ const rtc::SocketAddress& addr,
IceMessage** out_msg, std::string* out_username);
// Checks if the address in addr is compatible with the port's ip.
- bool IsCompatibleAddress(const talk_base::SocketAddress& addr);
+ bool IsCompatibleAddress(const rtc::SocketAddress& addr);
- // Default DSCP value for this port. Set by TransportChannel.
- void SetDefaultDscpValue(talk_base::DiffServCodePoint dscp) {
- default_dscp_ = dscp;
+ // Returns default DSCP value.
+ rtc::DiffServCodePoint DefaultDscpValue() const {
+ // No change from what MediaChannel set.
+ return rtc::DSCP_NO_CHANGE;
}
+ uint32 candidate_filter() { return candidate_filter_; }
+
private:
void Construct();
// Called when one of our connections deletes itself.
// Checks if this port is useless, and hence, should be destroyed.
void CheckTimeout();
- talk_base::Thread* thread_;
- talk_base::PacketSocketFactory* factory_;
+ rtc::Thread* thread_;
+ rtc::PacketSocketFactory* factory_;
std::string type_;
bool send_retransmit_count_attribute_;
- talk_base::Network* network_;
- talk_base::IPAddress ip_;
+ rtc::Network* network_;
+ rtc::IPAddress ip_;
int min_port_;
int max_port_;
std::string content_name_;
int component_;
uint32 generation_;
- talk_base::SocketAddress related_address_;
// 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.
std::string password_;
std::vector<Candidate> candidates_;
AddressMap connections_;
- enum Lifetime { LT_PRESTART, LT_PRETIMEOUT, LT_POSTTIMEOUT } lifetime_;
+ int timeout_delay_;
bool enable_port_packets_;
IceProtocolType ice_protocol_;
IceRole ice_role_;
uint64 tiebreaker_;
bool shared_socket_;
- // DSCP value for ICE/STUN messages. Set by the P2PTransportChannel after
- // port becomes ready.
- talk_base::DiffServCodePoint default_dscp_;
// Information to use when going through a proxy.
std::string user_agent_;
- talk_base::ProxyInfo proxy_;
+ rtc::ProxyInfo proxy_;
+
+ // Candidate filter is pushed down to Port such that each Port could
+ // make its own decision on how to create candidates. For example,
+ // when IceTransportsType is set to relay, both RelayPort and
+ // TurnPort will hide raddr to avoid local address leakage.
+ uint32 candidate_filter_;
friend class Connection;
};
// Represents a communication link between a port on the local client and a
// port on the remote client.
-class Connection : public talk_base::MessageHandler,
+class Connection : public rtc::MessageHandler,
public sigslot::has_slots<> {
public:
// States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4
// the interface of AsyncPacketSocket, which may use UDP or TCP under the
// covers.
virtual int Send(const void* data, size_t size,
- talk_base::DiffServCodePoint dscp) = 0;
+ const rtc::PacketOptions& options) = 0;
// Error if Send() returns < 0
virtual int GetError() = 0;
- sigslot::signal3<Connection*, const char*, size_t> SignalReadPacket;
+ sigslot::signal4<Connection*, const char*, size_t,
+ const rtc::PacketTime&> SignalReadPacket;
sigslot::signal1<Connection*> SignalReadyToSend;
// Called when a packet is received on this connection.
- void OnReadPacket(const char* data, size_t size);
+ void OnReadPacket(const char* data, size_t size,
+ const rtc::PacketTime& packet_time);
// Called when the socket is currently able to send.
void OnReadyToSend();
// Checks if this connection is useless, and hence, should be destroyed.
void CheckTimeout();
- void OnMessage(talk_base::Message *pmsg);
+ void OnMessage(rtc::Message *pmsg);
Port* port_;
size_t local_candidate_index_;
uint32 last_ping_response_received_;
std::vector<uint32> pings_since_last_response_;
- talk_base::RateTracker recv_rate_tracker_;
- talk_base::RateTracker send_rate_tracker_;
+ rtc::RateTracker recv_rate_tracker_;
+ rtc::RateTracker send_rate_tracker_;
private:
void MaybeAddPrflxCandidate(ConnectionRequest* request,
ProxyConnection(Port* port, size_t index, const Candidate& candidate);
virtual int Send(const void* data, size_t size,
- talk_base::DiffServCodePoint dscp);
+ const rtc::PacketOptions& options);
virtual int GetError() { return error_; }
private:
} // namespace cricket
-#endif // TALK_P2P_BASE_PORT_H_
+#endif // WEBRTC_P2P_BASE_PORT_H_