2014-10-28 22:20:11 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2012 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_PORTINTERFACE_H_
|
|
|
|
|
#define P2P_BASE_PORTINTERFACE_H_
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
2017-11-29 10:25:58 -08:00
|
|
|
#include <vector>
|
2014-10-28 22:20:11 +00:00
|
|
|
|
2017-12-19 10:26:23 -08:00
|
|
|
#include "api/candidate.h"
|
2018-02-20 16:03:18 -08:00
|
|
|
#include "api/optional.h"
|
2017-12-19 10:26:23 -08:00
|
|
|
#include "p2p/base/transportdescription.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/asyncpacketsocket.h"
|
|
|
|
|
#include "rtc_base/socketaddress.h"
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
class Network;
|
|
|
|
|
struct PacketOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
class Connection;
|
|
|
|
|
class IceMessage;
|
|
|
|
|
class StunMessage;
|
2018-02-20 16:03:18 -08:00
|
|
|
class StunStats;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
enum ProtocolType {
|
|
|
|
|
PROTO_UDP,
|
|
|
|
|
PROTO_TCP,
|
2016-12-13 05:17:23 -08:00
|
|
|
PROTO_SSLTCP, // Pseudo-TLS.
|
|
|
|
|
PROTO_TLS,
|
|
|
|
|
PROTO_LAST = PROTO_TLS
|
2014-10-28 22:20:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Defines the interface for a port, which represents a local communication
|
|
|
|
|
// mechanism that can be used to create connections to similar mechanisms of
|
|
|
|
|
// the other client. Various types of ports will implement this interface.
|
|
|
|
|
class PortInterface {
|
|
|
|
|
public:
|
2017-10-30 10:00:15 -07:00
|
|
|
virtual ~PortInterface();
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
virtual const std::string& Type() const = 0;
|
|
|
|
|
virtual rtc::Network* Network() const = 0;
|
|
|
|
|
|
|
|
|
|
// Methods to set/get ICE role and tiebreaker values.
|
|
|
|
|
virtual void SetIceRole(IceRole role) = 0;
|
|
|
|
|
virtual IceRole GetIceRole() const = 0;
|
|
|
|
|
|
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
|
|
|
virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
|
|
|
|
|
virtual uint64_t IceTiebreaker() const = 0;
|
2014-10-28 22:20:11 +00:00
|
|
|
|
|
|
|
|
virtual bool SharedSocket() const = 0;
|
|
|
|
|
|
2015-12-15 12:20:13 -08:00
|
|
|
virtual bool SupportsProtocol(const std::string& protocol) const = 0;
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
// PrepareAddress will attempt to get an address for this port that other
|
|
|
|
|
// clients can send to. It may take some time before the address is ready.
|
|
|
|
|
// Once it is ready, we will send SignalAddressReady. If errors are
|
|
|
|
|
// preventing the port from getting an address, it may send
|
|
|
|
|
// SignalAddressError.
|
|
|
|
|
virtual void PrepareAddress() = 0;
|
|
|
|
|
|
|
|
|
|
// Returns the connection to the given address or NULL if none exists.
|
|
|
|
|
virtual Connection* GetConnection(
|
|
|
|
|
const rtc::SocketAddress& remote_addr) = 0;
|
|
|
|
|
|
|
|
|
|
// Creates a new connection to the given address.
|
|
|
|
|
enum CandidateOrigin { ORIGIN_THIS_PORT, ORIGIN_OTHER_PORT, ORIGIN_MESSAGE };
|
|
|
|
|
virtual Connection* CreateConnection(
|
|
|
|
|
const Candidate& remote_candidate, CandidateOrigin origin) = 0;
|
|
|
|
|
|
|
|
|
|
// Functions on the underlying socket(s).
|
|
|
|
|
virtual int SetOption(rtc::Socket::Option opt, int value) = 0;
|
|
|
|
|
virtual int GetOption(rtc::Socket::Option opt, int* value) = 0;
|
|
|
|
|
virtual int GetError() = 0;
|
|
|
|
|
|
2016-06-30 20:52:02 -07:00
|
|
|
virtual ProtocolType GetProtocol() const = 0;
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
virtual const std::vector<Candidate>& Candidates() const = 0;
|
|
|
|
|
|
|
|
|
|
// Sends the given packet to the given address, provided that the address is
|
|
|
|
|
// that of a connection or an address that has sent to us already.
|
|
|
|
|
virtual int SendTo(const void* data, size_t size,
|
|
|
|
|
const rtc::SocketAddress& addr,
|
|
|
|
|
const rtc::PacketOptions& options, bool payload) = 0;
|
|
|
|
|
|
|
|
|
|
// Indicates that we received a successful STUN binding request from an
|
|
|
|
|
// address that doesn't correspond to any current connection. To turn this
|
|
|
|
|
// into a real connection, call CreateConnection.
|
|
|
|
|
sigslot::signal6<PortInterface*, const rtc::SocketAddress&,
|
|
|
|
|
ProtocolType, IceMessage*, const std::string&,
|
|
|
|
|
bool> SignalUnknownAddress;
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
virtual void SendBindingResponse(StunMessage* request,
|
|
|
|
|
const rtc::SocketAddress& addr) = 0;
|
|
|
|
|
virtual void SendBindingErrorResponse(
|
|
|
|
|
StunMessage* request, const rtc::SocketAddress& addr,
|
|
|
|
|
int error_code, const std::string& reason) = 0;
|
|
|
|
|
|
|
|
|
|
// Signaled when this port decides to delete itself because it no longer has
|
|
|
|
|
// any usefulness.
|
|
|
|
|
sigslot::signal1<PortInterface*> SignalDestroyed;
|
|
|
|
|
|
|
|
|
|
// Signaled when Port discovers ice role conflict with the peer.
|
|
|
|
|
sigslot::signal1<PortInterface*> SignalRoleConflict;
|
|
|
|
|
|
|
|
|
|
// Normally, packets arrive through a connection (or they result signaling of
|
|
|
|
|
// unknown address). Calling this method turns off delivery of packets
|
|
|
|
|
// through their respective connection and instead delivers every packet
|
|
|
|
|
// through this port.
|
|
|
|
|
virtual void EnablePortPackets() = 0;
|
|
|
|
|
sigslot::signal4<PortInterface*, const char*, size_t,
|
|
|
|
|
const rtc::SocketAddress&> SignalReadPacket;
|
|
|
|
|
|
2015-10-15 07:26:07 -07:00
|
|
|
// Emitted each time a packet is sent on this port.
|
2016-01-14 15:49:16 +01:00
|
|
|
sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
|
2015-10-15 07:26:07 -07:00
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
virtual std::string ToString() const = 0;
|
|
|
|
|
|
2018-02-20 16:03:18 -08:00
|
|
|
virtual void GetStunStats(rtc::Optional<StunStats>* stats) = 0;
|
|
|
|
|
|
2014-10-28 22:20:11 +00:00
|
|
|
protected:
|
2017-10-30 10:00:15 -07:00
|
|
|
PortInterface();
|
2014-10-28 22:20:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // P2P_BASE_PORTINTERFACE_H_
|