client.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <client/DatagramPeerIO.h>
  27. #include <client/StreamPeerIO.h>
  28. #include <client/DataProto.h>
  29. #include <client/DPReceive.h>
  30. #include <client/FrameDecider.h>
  31. // NOTE: all time values are in milliseconds
  32. // name of the program
  33. #define PROGRAM_NAME "client"
  34. // server output buffer size
  35. #define SERVER_BUFFER_MIN_PACKETS 200
  36. // maximum UDP payload size
  37. #define CLIENT_UDP_MTU 1472
  38. // maximum number of peers
  39. #define MAX_PEERS 256
  40. // maximum number of peer's MAC addresses to remember
  41. #define PEER_DEFAULT_MAX_MACS 16
  42. // maximum number of multicast addresses per peer
  43. #define PEER_DEFAULT_MAX_GROUPS 16
  44. // how long we wait for a packet to reach full size before sending it (see FragmentProtoDisassembler latency argument)
  45. #define PEER_DEFAULT_UDP_FRAGMENTATION_LATENCY 0
  46. // value related to how much out-of-order input we tolerate (see FragmentProtoAssembler num_frames argument)
  47. #define PEER_UDP_ASSEMBLER_NUM_FRAMES 4
  48. // keep-alive packet interval for p2p communication
  49. #define PEER_KEEPALIVE_INTERVAL 10000
  50. // keep-alive receive timer for p2p communication (after how long to consider the link down)
  51. #define PEER_KEEPALIVE_RECEIVE_TIMER 22000
  52. // size of frame send buffer, in number of frames
  53. #define PEER_DEFAULT_SEND_BUFFER_SIZE 32
  54. // size of frame send buffer for relayed packets, in number of frames
  55. #define PEER_DEFAULT_SEND_BUFFER_RELAY_SIZE 32
  56. // time after an unused relay flow is freed (-1 for never)
  57. #define PEER_RELAY_FLOW_INACTIVITY_TIME 10000
  58. // retry time
  59. #define PEER_RETRY_TIME 5000
  60. // for how long a peer can send no Membership Reports for a group
  61. // before the peer and group are disassociated
  62. #define DEFAULT_IGMP_GROUP_MEMBERSHIP_INTERVAL 260000
  63. // how long to wait for joins after a Group Specific query has been
  64. // forwarded to a peer before assuming there are no listeners at the peer
  65. #define DEFAULT_IGMP_LAST_MEMBER_QUERY_TIME 2000
  66. // maximum bind addresses
  67. #define MAX_BIND_ADDRS 8
  68. // maximum external addresses per bind address
  69. #define MAX_EXT_ADDRS 8
  70. // maximum scopes
  71. #define MAX_SCOPES 8
  72. struct peer_data {
  73. // peer identifier
  74. peerid_t id;
  75. // flags provided by the server
  76. int flags;
  77. // certificate reported by the server, defined only if using SSL
  78. uint8_t cert[SCID_NEWCLIENT_MAX_CERT_LEN];
  79. int cert_len;
  80. char *common_name;
  81. // local flow
  82. DataProtoFlow local_dpflow;
  83. // frame decider peer
  84. FrameDeciderPeer decider_peer;
  85. // receive peer
  86. DPReceivePeer receive_peer;
  87. // flag if link objects are initialized
  88. int have_link;
  89. // receive receiver
  90. DPReceiveReceiver receive_receiver;
  91. // transport-specific link objects
  92. union {
  93. struct {
  94. DatagramPeerIO pio;
  95. uint16_t sendseed_nextid;
  96. int sendseed_sent;
  97. uint16_t sendseed_sent_id;
  98. uint8_t sendseed_sent_key[BENCRYPTION_MAX_KEY_SIZE];
  99. uint8_t sendseed_sent_iv[BENCRYPTION_MAX_BLOCK_SIZE];
  100. uint16_t pending_recvseed_id;
  101. } udp;
  102. struct {
  103. StreamPeerIO pio;
  104. } tcp;
  105. } pio;
  106. // link sending
  107. DataProtoSink send_dp;
  108. // relaying objects
  109. struct peer_data *relaying_peer; // peer through which we are relaying, or NULL
  110. LinkedList2Node relaying_list_node; // node in relay peer's relay_users
  111. // waiting for relay data
  112. int waiting_relay;
  113. LinkedList2Node waiting_relay_list_node;
  114. // retry timer
  115. BTimer reset_timer;
  116. // relay server specific
  117. int is_relay;
  118. LinkedList2Node relay_list_node;
  119. LinkedList2 relay_users;
  120. // binding state
  121. int binding;
  122. int binding_addrpos;
  123. // jobs
  124. BPending job_send_seed_after_binding;
  125. // peers linked list node
  126. LinkedList2Node list_node;
  127. };