client.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @file client.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. #include <stdio.h>
  23. #include <stdint.h>
  24. #include <protocol/scproto.h>
  25. #include <structure/LinkedList2.h>
  26. #include <structure/BAVL.h>
  27. #include <flow/SinglePacketBuffer.h>
  28. #include <flow/PacketPassFairQueue.h>
  29. #include <tuntap/BTap.h>
  30. #include <client/DatagramPeerIO.h>
  31. #include <client/StreamPeerIO.h>
  32. #include <client/DataProto.h>
  33. #include <client/FrameDecider.h>
  34. // NOTE: all time values are in milliseconds
  35. // name of the program
  36. #define PROGRAM_NAME "client"
  37. // server output buffer size
  38. #define SERVER_BUFFER_MIN_PACKETS 200
  39. // maximum UDP payload size
  40. #define CLIENT_UDP_MTU 1472
  41. // maximum number of peers
  42. #define MAX_PEERS 256
  43. // maximum number of peer's MAC addresses to remember
  44. #define PEER_MAX_MACS 16
  45. // maximum number of multicast addresses per peer
  46. #define PEER_MAX_GROUPS 16
  47. // how long we wait for a packet to reach full size before sending it (see FragmentProtoDisassembler latency argument)
  48. #define PEER_DEFAULT_FRAGMENTATION_LATENCY 0
  49. // keep-alive packet interval for p2p communication
  50. #define PEER_KEEPALIVE_INTERVAL 10000
  51. // keep-alive receive timer for p2p communication (after how long to consider the link down)
  52. #define PEER_KEEPALIVE_RECEIVE_TIMER 22000
  53. // size of frame send buffer, in number of frames
  54. #define PEER_DEFAULT_SEND_BUFFER_SIZE 32
  55. // size of frame send buffer for relayed packets, in number of frames
  56. #define PEER_DEFAULT_SEND_BUFFER_RELAY_SIZE 32
  57. // retry time
  58. #define PEER_RETRY_TIME 5000
  59. // for how long a peer can send no Membership Reports for a group
  60. // before the peer and group are disassociated
  61. #define IGMP_GROUP_MEMBERSHIP_INTERVAL 260000
  62. // how long to wait for joins after a Group Specific query has been
  63. // forwarded to a peer before assuming there are no listeners at the peer
  64. #define IGMP_LAST_MEMBER_QUERY_TIME 2000
  65. // maximum bind addresses
  66. #define MAX_BIND_ADDRS 8
  67. // maximum external addresses per bind address
  68. #define MAX_EXT_ADDRS 8
  69. // maximum scopes
  70. #define MAX_SCOPES 8
  71. struct device_data {
  72. BTap btap;
  73. int mtu;
  74. // input
  75. SinglePacketBuffer input_buffer;
  76. PacketPassInterface input_interface;
  77. // output
  78. PacketPassFairQueue output_queue;
  79. };
  80. struct peer_data {
  81. // peer identifier
  82. peerid_t id;
  83. // flags provided by the server
  84. int flags;
  85. // certificate reported by the server, defined only if using SSL
  86. uint8_t cert[SCID_NEWCLIENT_MAX_CERT_LEN];
  87. int cert_len;
  88. // local flow
  89. DataProtoLocalSource local_dpflow;
  90. // local receive flow
  91. PacketPassInterface *local_recv_if;
  92. PacketPassFairQueueFlow local_recv_qflow;
  93. // relay source
  94. DataProtoRelaySource relay_source;
  95. // flag if link objects are initialized
  96. int have_link;
  97. // link sending
  98. DataProtoDest send_dp;
  99. // link receive interface
  100. PacketPassInterface recv_ppi;
  101. // transport-specific link objects
  102. union {
  103. struct {
  104. DatagramPeerIO pio;
  105. uint16_t sendseed_nextid;
  106. int sendseed_sent;
  107. uint16_t sendseed_sent_id;
  108. uint8_t sendseed_sent_key[BENCRYPTION_MAX_KEY_SIZE];
  109. uint8_t sendseed_sent_iv[BENCRYPTION_MAX_BLOCK_SIZE];
  110. } udp;
  111. struct {
  112. StreamPeerIO pio;
  113. } tcp;
  114. } pio;
  115. // flag if relaying is installed
  116. int have_relaying;
  117. // relaying objects
  118. struct peer_data *relaying_peer; // peer through which we are relaying
  119. LinkedList2Node relaying_list_node; // node in relay peer's relay_users
  120. // waiting for relay data
  121. int waiting_relay;
  122. LinkedList2Node waiting_relay_list_node;
  123. // retry timer
  124. BTimer reset_timer;
  125. // frame decider peer
  126. FrameDeciderPeer decider_peer;
  127. // relay server specific
  128. int is_relay;
  129. LinkedList2Node relay_list_node;
  130. LinkedList2 relay_users;
  131. // binding state
  132. int binding;
  133. int binding_addrpos;
  134. // jobs
  135. BPending job_send_seed_after_binding;
  136. // peers linked list node
  137. LinkedList2Node list_node;
  138. // peers-by-ID hash table node
  139. BAVLNode tree_node;
  140. };