You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2012, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_P2P_BASE_PORTINTERFACE_H_
  28. #define TALK_P2P_BASE_PORTINTERFACE_H_
  29. #include <string>
  30. #include "talk/base/socketaddress.h"
  31. #include "talk/p2p/base/transport.h"
  32. namespace talk_base {
  33. class Network;
  34. class PacketSocketFactory;
  35. }
  36. namespace cricket {
  37. class Connection;
  38. class IceMessage;
  39. class StunMessage;
  40. enum ProtocolType {
  41. PROTO_UDP,
  42. PROTO_TCP,
  43. PROTO_SSLTCP,
  44. PROTO_LAST = PROTO_SSLTCP
  45. };
  46. // Defines the interface for a port, which represents a local communication
  47. // mechanism that can be used to create connections to similar mechanisms of
  48. // the other client. Various types of ports will implement this interface.
  49. class PortInterface {
  50. public:
  51. virtual ~PortInterface() {}
  52. virtual const std::string& Type() const = 0;
  53. virtual talk_base::Network* Network() const = 0;
  54. virtual void SetIceProtocolType(IceProtocolType protocol) = 0;
  55. virtual IceProtocolType IceProtocol() const = 0;
  56. // Methods to set/get ICE role and tiebreaker values.
  57. virtual void SetRole(TransportRole role) = 0;
  58. virtual TransportRole Role() const = 0;
  59. virtual void SetTiebreaker(uint64 tiebreaker) = 0;
  60. virtual uint64 Tiebreaker() const = 0;
  61. virtual bool SharedSocket() const = 0;
  62. // PrepareAddress will attempt to get an address for this port that other
  63. // clients can send to. It may take some time before the address is ready.
  64. // Once it is ready, we will send SignalAddressReady. If errors are
  65. // preventing the port from getting an address, it may send
  66. // SignalAddressError.
  67. virtual void PrepareAddress() = 0;
  68. // Returns the connection to the given address or NULL if none exists.
  69. virtual Connection* GetConnection(
  70. const talk_base::SocketAddress& remote_addr) = 0;
  71. // Creates a new connection to the given address.
  72. enum CandidateOrigin { ORIGIN_THIS_PORT, ORIGIN_OTHER_PORT, ORIGIN_MESSAGE };
  73. virtual Connection* CreateConnection(
  74. const Candidate& remote_candidate, CandidateOrigin origin) = 0;
  75. // Functions on the underlying socket(s).
  76. virtual int SetOption(talk_base::Socket::Option opt, int value) = 0;
  77. virtual int GetError() = 0;
  78. virtual int GetOption(talk_base::Socket::Option opt, int* value) = 0;
  79. virtual const std::vector<Candidate>& Candidates() const = 0;
  80. // Sends the given packet to the given address, provided that the address is
  81. // that of a connection or an address that has sent to us already.
  82. virtual int SendTo(const void* data, size_t size,
  83. const talk_base::SocketAddress& addr, bool payload) = 0;
  84. // Indicates that we received a successful STUN binding request from an
  85. // address that doesn't correspond to any current connection. To turn this
  86. // into a real connection, call CreateConnection.
  87. sigslot::signal6<PortInterface*, const talk_base::SocketAddress&,
  88. ProtocolType, IceMessage*, const std::string&,
  89. bool> SignalUnknownAddress;
  90. // Sends a response message (normal or error) to the given request. One of
  91. // these methods should be called as a response to SignalUnknownAddress.
  92. // NOTE: You MUST call CreateConnection BEFORE SendBindingResponse.
  93. virtual void SendBindingResponse(StunMessage* request,
  94. const talk_base::SocketAddress& addr) = 0;
  95. virtual void SendBindingErrorResponse(
  96. StunMessage* request, const talk_base::SocketAddress& addr,
  97. int error_code, const std::string& reason) = 0;
  98. // Signaled when this port decides to delete itself because it no longer has
  99. // any usefulness.
  100. sigslot::signal1<PortInterface*> SignalDestroyed;
  101. // Signaled when Port discovers ice role conflict with the peer.
  102. sigslot::signal0<> SignalRoleConflict;
  103. // Normally, packets arrive through a connection (or they result signaling of
  104. // unknown address). Calling this method turns off delivery of packets
  105. // through their respective connection and instead delivers every packet
  106. // through this port.
  107. virtual void EnablePortPackets() = 0;
  108. sigslot::signal4<PortInterface*, const char*, size_t,
  109. const talk_base::SocketAddress&> SignalReadPacket;
  110. virtual std::string ToString() const = 0;
  111. protected:
  112. PortInterface() {}
  113. };
  114. } // namespace cricket
  115. #endif // TALK_P2P_BASE_PORTINTERFACE_H_