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.

91 lines
2.0 KiB

6 years ago
7 years ago
7 years ago
  1. /*
  2. * tunnel.h - Define tunnel's buffers and callbacks
  3. *
  4. * Copyright (C) 2013 - 2018, Max Lv <max.c.lv@gmail.com>
  5. *
  6. * This file is part of the shadowsocks-libev.
  7. *
  8. * shadowsocks-libev is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * shadowsocks-libev is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with shadowsocks-libev; see the file COPYING. If not, see
  20. * <http://www.gnu.org/licenses/>.
  21. */
  22. #ifndef _TUNNEL_H
  23. #define _TUNNEL_H
  24. #ifdef HAVE_LIBEV_EV_H
  25. #include <libev/ev.h>
  26. #else
  27. #include <ev.h>
  28. #endif
  29. #ifdef __MINGW32__
  30. #include "winsock.h"
  31. #endif
  32. #include "crypto.h"
  33. #include "jconf.h"
  34. #include "common.h"
  35. typedef struct listen_ctx {
  36. ev_io io;
  37. ss_addr_t tunnel_addr;
  38. char *iface;
  39. int remote_num;
  40. int timeout;
  41. int fd;
  42. int mptcp;
  43. struct sockaddr **remote_addr;
  44. } listen_ctx_t;
  45. typedef struct server_ctx {
  46. ev_io io;
  47. int connected;
  48. struct server *server;
  49. } server_ctx_t;
  50. typedef struct server {
  51. int fd;
  52. buffer_t *buf;
  53. cipher_ctx_t *e_ctx;
  54. cipher_ctx_t *d_ctx;
  55. struct server_ctx *recv_ctx;
  56. struct server_ctx *send_ctx;
  57. struct remote *remote;
  58. ss_addr_t destaddr;
  59. } server_t;
  60. typedef struct remote_ctx {
  61. ev_io io;
  62. ev_timer watcher;
  63. int connected;
  64. struct remote *remote;
  65. } remote_ctx_t;
  66. typedef struct remote {
  67. int fd;
  68. #ifdef TCP_FASTOPEN_WINSOCK
  69. OVERLAPPED olap;
  70. int connect_ex_done;
  71. #endif
  72. buffer_t *buf;
  73. struct remote_ctx *recv_ctx;
  74. struct remote_ctx *send_ctx;
  75. struct server *server;
  76. struct sockaddr *addr;
  77. uint32_t counter;
  78. } remote_t;
  79. #endif // _TUNNEL_H