session.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 __SESSION__
  31. #define __SESSION__
  32. #include <event2/event.h>
  33. #include <event2/bufferevent.h>
  34. #include "ns_turn_ioaddr.h"
  35. #include "ns_turn_utils.h"
  36. #include "stun_buffer.h"
  37. #include "apputils.h"
  38. #include <openssl/ssl.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. ///////// types ////////////
  43. enum _UR_STATE {
  44. UR_STATE_UNKNOWN=0,
  45. UR_STATE_READY,
  46. UR_STATE_DONE
  47. };
  48. typedef enum _UR_STATE UR_STATE;
  49. //////////////// session info //////////////////////
  50. typedef struct
  51. {
  52. /* RFC 6062 */
  53. u32bits cid;
  54. ioa_addr tcp_data_local_addr;
  55. ioa_socket_raw tcp_data_fd;
  56. SSL *tcp_data_ssl;
  57. int tcp_data_bound;
  58. } app_tcp_conn_info;
  59. typedef struct {
  60. ioa_addr local_addr;
  61. char lsaddr[129];
  62. ioa_addr remote_addr;
  63. char rsaddr[129];
  64. char ifname[129];
  65. ioa_addr peer_addr;
  66. ioa_socket_raw fd;
  67. SSL *ssl;
  68. int broken;
  69. u08bits nonce[STUN_MAX_NONCE_SIZE+1];
  70. u08bits realm[STUN_MAX_REALM_SIZE+1];
  71. /* oAuth */
  72. int oauth;
  73. u08bits server_name[STUN_MAX_SERVER_NAME_SIZE+1];
  74. hmackey_t key;
  75. int key_set;
  76. int cok;
  77. /* RFC 6062 */
  78. app_tcp_conn_info **tcp_conn;
  79. size_t tcp_conn_number;
  80. int is_peer;
  81. SHATYPE shatype;
  82. char s_mobile_id[33];
  83. } app_ur_conn_info;
  84. typedef struct {
  85. app_ur_conn_info pinfo;
  86. UR_STATE state;
  87. unsigned int ctime;
  88. uint16_t chnum;
  89. int wait_cycles;
  90. int timer_cycle;
  91. int completed;
  92. struct event *input_ev;
  93. struct event *input_tcp_data_ev;
  94. stun_buffer in_buffer;
  95. stun_buffer out_buffer;
  96. u32bits refresh_time;
  97. u32bits finished_time;
  98. //Msg counters:
  99. int tot_msgnum;
  100. int wmsgnum;
  101. int rmsgnum;
  102. int recvmsgnum;
  103. u32bits recvtimems;
  104. u32bits to_send_timems;
  105. //Statistics:
  106. size_t loss;
  107. u64bits latency;
  108. u64bits jitter;
  109. } app_ur_session;
  110. ///////////////////////////////////////////////////////
  111. typedef struct _message_info {
  112. int msgnum;
  113. u64bits mstime;
  114. } message_info;
  115. ///////////////////////////////////////////////////////////////////////////////
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif //__SESSION__