UdpGwClient.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @file UdpGwClient.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN 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 along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_UDPGW_CLIENT_UDPGWCLIENT_H
  23. #define BADVPN_UDPGW_CLIENT_UDPGWCLIENT_H
  24. #include <stdint.h>
  25. #include <protocol/udpgw_proto.h>
  26. #include <misc/debug.h>
  27. #include <structure/BAVL.h>
  28. #include <structure/LinkedList1.h>
  29. #include <base/DebugObject.h>
  30. #include <system/BAddr.h>
  31. #include <base/BPending.h>
  32. #include <flow/PacketPassFairQueue.h>
  33. #include <flow/PacketStreamSender.h>
  34. #include <flow/PacketProtoFlow.h>
  35. #include <flow/PacketProtoDecoder.h>
  36. #include <flow/PacketPassConnector.h>
  37. #include <flowextra/PacketPassInactivityMonitor.h>
  38. typedef void (*UdpGwClient_handler_servererror) (void *user);
  39. typedef void (*UdpGwClient_handler_received) (void *user, BAddr local_addr, BAddr remote_addr, const char *data, int data_len);
  40. typedef struct {
  41. int udp_mtu;
  42. int max_connections;
  43. int send_buffer_size;
  44. btime_t keepalive_time;
  45. BReactor *reactor;
  46. void *user;
  47. UdpGwClient_handler_servererror handler_servererror;
  48. UdpGwClient_handler_received handler_received;
  49. int udpgw_mtu;
  50. int pp_mtu;
  51. BAVL connections_tree_by_conaddr;
  52. BAVL connections_tree_by_conid;
  53. LinkedList1 connections_list;
  54. int num_connections;
  55. int next_conid;
  56. PacketPassFairQueue send_queue;
  57. PacketPassInactivityMonitor send_monitor;
  58. PacketPassConnector send_connector;
  59. struct {
  60. struct packetproto_header pp;
  61. struct udpgw_header udpgw;
  62. } __attribute__((packed)) keepalive_packet;
  63. PacketPassInterface *keepalive_if;
  64. PacketPassFairQueueFlow keepalive_qflow;
  65. int keepalive_sending;
  66. int have_server;
  67. FlowErrorDomain domain;
  68. PacketStreamSender send_sender;
  69. PacketProtoDecoder recv_decoder;
  70. PacketPassInterface recv_if;
  71. DebugObject d_obj;
  72. } UdpGwClient;
  73. struct UdpGwClient_conaddr {
  74. BAddr local_addr;
  75. BAddr remote_addr;
  76. };
  77. struct UdpGwClient_connection {
  78. UdpGwClient *client;
  79. struct UdpGwClient_conaddr conaddr;
  80. const uint8_t *first_data;
  81. int first_data_len;
  82. uint16_t conid;
  83. BPending first_job;
  84. BufferWriter *send_if;
  85. PacketProtoFlow send_ppflow;
  86. PacketPassFairQueueFlow send_qflow;
  87. BAVLNode connections_tree_by_conaddr_node;
  88. BAVLNode connections_tree_by_conid_node;
  89. LinkedList1Node connections_list_node;
  90. };
  91. void UdpGwClient_Init (UdpGwClient *o, int udp_mtu, int max_connections, int send_buffer_size, btime_t keepalive_time, BReactor *reactor, void *user,
  92. UdpGwClient_handler_servererror handler_servererror,
  93. UdpGwClient_handler_received handler_received);
  94. void UdpGwClient_Free (UdpGwClient *o);
  95. void UdpGwClient_SubmitPacket (UdpGwClient *o, BAddr local_addr, BAddr remote_addr, const uint8_t *data, int data_len);
  96. int UdpGwClient_ConnectServer (UdpGwClient *o, StreamPassInterface *send_if, StreamRecvInterface *recv_if) WARN_UNUSED;
  97. void UdpGwClient_DisconnectServer (UdpGwClient *o);
  98. #endif