doc_turn.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /**
  19. @defgroup PJNATH_TURN TURN: Traversal Using Relays around NAT
  20. @brief TURN protocol implementation
  21. @ingroup PJNATH
  22. \section turn_intro_sec Introduction to TURN
  23. When a direct communication path cannot be found, it is necessary to
  24. use the services of an intermediate host that acts as a relay for the
  25. packets. This relay typically sits in the public Internet and relays
  26. packets between two hosts that both sit behind NATs.
  27. TURN allows a host behind a NAT (called the TURN client) to request that
  28. another host (called the TURN server) act as a relay. The client can
  29. arrange for the server to relay packets to and from certain other hosts
  30. (called peers) and can control aspects of how the relaying is done.
  31. The client does this by obtaining an IP address and port on the
  32. server, called the relayed-transport-address. When a peer sends a
  33. packet to the relayed-transport-address, the server relays the packet
  34. to the client. When the client sends a data packet to the server,
  35. the server relays it to the appropriate peer using the relayed-
  36. transport-address as the source.
  37. \section turn_op_sec Overview of TURN operations
  38. <b>Discovering TURN server</b>.\n
  39. Client learns the IP address of the TURN
  40. server either through some privisioning or by querying DNS SRV records
  41. for TURN service for the specified domain. Client may use UDP or TCP (or
  42. TLS) to connect to the TURN server.
  43. <b>Authentication</b>.\n
  44. All TURN operations requires the use of authentication
  45. (it uses STUN long term autentication method), hence client must be
  46. configured with the correct credential to use the service.
  47. <b>Allocation</b>.\n
  48. Client creates one "relay port" (or called <b>relayed-transport-address</b>
  49. in TURN terminology) in the TURN server by sending TURN \a Allocate request,
  50. hence this process is called creating allocation. Once the allocation is
  51. successful, client will be given the IP address and port of the "relay
  52. port" in the Allocate response.
  53. <b>Sending data through the relay</b>.\n
  54. Once allocation has been created, client may send data to any remote
  55. endpoints (called peers in TURN terminology) via the "relay port". It does
  56. so by sending Send Indication to the TURN server, giving the peer address
  57. in the indication message. But note that at this point peers are not allowed
  58. to send data towards the client (via the "relay port") before permission is
  59. installed for that peer.
  60. <b>Creating permissions</b>.\n
  61. Permission needs to be created in the TURN server so that a peer can send
  62. data to the client via the relay port (a peer in this case is identified by
  63. its IP address). Without this, when the TURN server receives data from the
  64. peer in the "relay port", it will drop this data.
  65. <b>Receiving data from peers</b>.\n
  66. Once permission has been installed for the peer, any data received by the
  67. TURN server (from that peer) in the "relay port" will be relayed back to
  68. client by using Data Indication.
  69. <b>Using ChannelData</b>.\n
  70. TURN provides optimized framing to the data by using ChannelData
  71. packetization. The client activates this format by sending ChannelBind
  72. request to the TURN server, which provides (channel) binding which maps a
  73. particular peer address with a channel number. Data sent or received to/for
  74. this peer will then use ChannelData format instead of Send or Data
  75. Indications.
  76. <b>Refreshing the allocation, permissions, and channel bindings</b>.\n
  77. Allocations, permissions, and channel bindings need to be refreshed
  78. periodically by client, or otherwise they will expire.
  79. <b>Destroying the allocation</b>.\n
  80. Once the "relay port" is no longer needed, client destroys the allocation
  81. by sending Refresh request with LIFETIME attribute set to zero.
  82. \section turn_org_sec Library organizations
  83. The TURN functionalities in PJNATH primarily consist of
  84. \ref PJNATH_TURN_SOCK and \ref PJNATH_TURN_SESSION. Please see more
  85. below.
  86. \section turn_using_sec Using TURN transport
  87. The \ref PJNATH_TURN_SOCK is a ready to use object for relaying
  88. application data via a TURN server, by managing all the operations
  89. above.
  90. Among other things it provides the following features:
  91. - resolution of the TURN server with DNS SRV
  92. - interface to create allocation, permissions, and channel
  93. bindings
  94. - interface to send and receive packets through the relay
  95. - provides callback to notify the application about incoming data
  96. - managing the allocation, permissions, and channel bindings
  97. Please see \ref PJNATH_TURN_SOCK for more documentation about and
  98. on how to use this object.
  99. \section turn_owntransport_sec Creating custom TURN transport
  100. The \ref PJNATH_TURN_SESSION is a transport-independent object to
  101. manage a client TURN session. It contains the core logic for managing
  102. the TURN client session as listed in TURN operations above, but
  103. in transport-independent manner (i.e. it doesn't have a socket), so
  104. that developer can integrate TURN client functionality into existing
  105. framework that already has its own means to send and receive data,
  106. or to support new transport types to TURN, such as TLS.
  107. You can create your own (custom) TURN transport by wrapping this
  108. into your own object, and provide it with the means to send and
  109. receive packets.
  110. Please see \ref PJNATH_TURN_SESSION for more information.
  111. \section turn_samples_sec Samples
  112. The \ref turn_client_sample is a sample application to use the
  113. \ref PJNATH_TURN_SOCK. Also there is a sample TURN server in
  114. the distribution as well.
  115. Also see <b>\ref samples_page</b> for other samples.
  116. */
  117. /**
  118. * @defgroup PJNATH_TURN_SOCK TURN client transport
  119. * @brief Client transport utilizing TURN relay
  120. * @ingroup PJNATH_TURN
  121. */
  122. /**
  123. * @defgroup PJNATH_TURN_SESSION TURN client session
  124. * @brief Transport independent TURN client session
  125. * @ingroup PJNATH_TURN
  126. */