ns_turn_session.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2011, 2012, 2013 Citrix Systems
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the project nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #ifndef __TURN_SESSION__
  31. #define __TURN_SESSION__
  32. #include "ns_turn_utils.h"
  33. #include "ns_turn_maps.h"
  34. #include "ns_turn_ioalib.h"
  35. #include "ns_turn_allocation.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. ////////// REALM ////////////
  40. typedef struct _perf_options_t {
  41. band_limit_t max_bps;
  42. vint total_quota;
  43. vint user_quota;
  44. } perf_options_t;
  45. struct _realm_options_t {
  46. s08bits name[STUN_MAX_REALM_SIZE + 1];
  47. perf_options_t perf_options;
  48. };
  49. //////////////// session info //////////////////////
  50. typedef u64bits turnsession_id;
  51. #define NONCE_MAX_SIZE (NONCE_LENGTH_32BITS*4+1)
  52. typedef u64bits mobile_id_t;
  53. struct _ts_ur_super_session {
  54. void* server;
  55. turnsession_id id;
  56. turn_time_t start_time;
  57. ioa_socket_handle client_socket;
  58. allocation alloc;
  59. ioa_timer_handle to_be_allocated_timeout_ev;
  60. int enforce_fingerprints;
  61. int is_tcp_relay;
  62. int to_be_closed;
  63. /* Auth */
  64. u08bits nonce[NONCE_MAX_SIZE];
  65. turn_time_t nonce_expiration_time;
  66. u08bits username[STUN_MAX_USERNAME_SIZE+1];
  67. hmackey_t hmackey;
  68. int hmackey_set;
  69. st_password_t pwd;
  70. int quota_used;
  71. int oauth;
  72. turn_time_t max_session_time_auth;
  73. /* Realm */
  74. realm_options_t realm_options;
  75. int origin_set;
  76. s08bits origin[STUN_MAX_ORIGIN_SIZE + 1];
  77. /* Stats */
  78. u32bits received_packets;
  79. u32bits sent_packets;
  80. u32bits received_bytes;
  81. u32bits sent_bytes;
  82. u64bits t_received_packets;
  83. u64bits t_sent_packets;
  84. u64bits t_received_bytes;
  85. u64bits t_sent_bytes;
  86. u64bits received_rate;
  87. size_t sent_rate;
  88. size_t total_rate;
  89. /* Mobile */
  90. int is_mobile;
  91. mobile_id_t mobile_id;
  92. mobile_id_t old_mobile_id;
  93. char s_mobile_id[33];
  94. /* Bandwidth */
  95. band_limit_t bps;
  96. };
  97. ////// Session info for statistics //////
  98. #define TURN_ADDR_STR_SIZE (65)
  99. #define TURN_MAIN_PEERS_ARRAY_SIZE (5)
  100. typedef struct _addr_data {
  101. ioa_addr addr;
  102. char saddr[TURN_ADDR_STR_SIZE];
  103. } addr_data;
  104. struct turn_session_info {
  105. turnsession_id id;
  106. int valid;
  107. turn_time_t start_time;
  108. turn_time_t expiration_time;
  109. SOCKET_TYPE client_protocol;
  110. SOCKET_TYPE peer_protocol;
  111. char tls_method[17];
  112. char tls_cipher[65];
  113. addr_data local_addr_data;
  114. addr_data remote_addr_data;
  115. addr_data relay_addr_data_ipv4;
  116. addr_data relay_addr_data_ipv6;
  117. u08bits username[STUN_MAX_USERNAME_SIZE+1];
  118. int enforce_fingerprints;
  119. /* Stats */
  120. u64bits received_packets;
  121. u64bits sent_packets;
  122. u64bits received_bytes;
  123. u64bits sent_bytes;
  124. u32bits received_rate;
  125. u32bits sent_rate;
  126. u32bits total_rate;
  127. /* Mobile */
  128. int is_mobile;
  129. /* Peers */
  130. addr_data main_peers_data[TURN_MAIN_PEERS_ARRAY_SIZE];
  131. size_t main_peers_size;
  132. addr_data *extra_peers_data;
  133. size_t extra_peers_size;
  134. /* Realm */
  135. char realm[STUN_MAX_REALM_SIZE + 1];
  136. char origin[STUN_MAX_ORIGIN_SIZE + 1];
  137. /* Bandwidth */
  138. band_limit_t bps;
  139. };
  140. void turn_session_info_init(struct turn_session_info* tsi);
  141. void turn_session_info_clean(struct turn_session_info* tsi);
  142. void turn_session_info_add_peer(struct turn_session_info* tsi, ioa_addr *peer);
  143. int turn_session_info_copy_from(struct turn_session_info* tsi, ts_ur_super_session *ss);
  144. ////////////// ss /////////////////////
  145. allocation* get_allocation_ss(ts_ur_super_session *ss);
  146. ///////////////////////////////////////////////////////
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif //__TURN_SESSION__