BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file client.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions 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 author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #include <stdio.h> |
||
31 | #include <stdint.h> |
||
32 | |||
33 | #include <protocol/scproto.h> |
||
34 | #include <structure/LinkedList1.h> |
||
35 | #include <flow/PacketPassFairQueue.h> |
||
36 | #include <flow/SinglePacketBuffer.h> |
||
37 | #include <flow/PacketRecvConnector.h> |
||
38 | #include <client/DatagramPeerIO.h> |
||
39 | #include <client/StreamPeerIO.h> |
||
40 | #include <client/DataProto.h> |
||
41 | #include <client/DPReceive.h> |
||
42 | #include <client/FrameDecider.h> |
||
43 | #include <client/PeerChat.h> |
||
44 | #include <client/SinglePacketSource.h> |
||
45 | |||
46 | // NOTE: all time values are in milliseconds |
||
47 | |||
48 | // name of the program |
||
49 | #define PROGRAM_NAME "client" |
||
50 | |||
51 | // server output buffer size |
||
52 | #define SERVER_BUFFER_MIN_PACKETS 200 |
||
53 | |||
54 | // maximum UDP payload size |
||
55 | #define CLIENT_UDP_MTU 1472 |
||
56 | |||
57 | // maximum number of pending TCP PasswordListener clients |
||
58 | #define TCP_MAX_PASSWORD_LISTENER_CLIENTS 50 |
||
59 | |||
60 | // maximum number of peers |
||
61 | #define DEFAULT_MAX_PEERS 256 |
||
62 | // maximum number of peer's MAC addresses to remember |
||
63 | #define PEER_DEFAULT_MAX_MACS 16 |
||
64 | // maximum number of multicast addresses per peer |
||
65 | #define PEER_DEFAULT_MAX_GROUPS 16 |
||
66 | // how long we wait for a packet to reach full size before sending it (see FragmentProtoDisassembler latency argument) |
||
67 | #define PEER_DEFAULT_UDP_FRAGMENTATION_LATENCY 0 |
||
68 | // value related to how much out-of-order input we tolerate (see FragmentProtoAssembler num_frames argument) |
||
69 | #define PEER_UDP_ASSEMBLER_NUM_FRAMES 4 |
||
70 | // socket send buffer (SO_SNDBUF) for peer TCP connections, <=0 to not set |
||
71 | #define PEER_DEFAULT_TCP_SOCKET_SNDBUF 1048576 |
||
72 | // keep-alive packet interval for p2p communication |
||
73 | #define PEER_KEEPALIVE_INTERVAL 10000 |
||
74 | // keep-alive receive timer for p2p communication (after how long to consider the link down) |
||
75 | #define PEER_KEEPALIVE_RECEIVE_TIMER 22000 |
||
76 | // size of frame send buffer, in number of frames |
||
77 | #define PEER_DEFAULT_SEND_BUFFER_SIZE 32 |
||
78 | // size of frame send buffer for relayed packets, in number of frames |
||
79 | #define PEER_DEFAULT_SEND_BUFFER_RELAY_SIZE 32 |
||
80 | // time after an unused relay flow is freed (-1 for never) |
||
81 | #define PEER_RELAY_FLOW_INACTIVITY_TIME 10000 |
||
82 | // retry time |
||
83 | #define PEER_RETRY_TIME 5000 |
||
84 | |||
85 | // for how long a peer can send no Membership Reports for a group |
||
86 | // before the peer and group are disassociated |
||
87 | #define DEFAULT_IGMP_GROUP_MEMBERSHIP_INTERVAL 260000 |
||
88 | // how long to wait for joins after a Group Specific query has been |
||
89 | // forwarded to a peer before assuming there are no listeners at the peer |
||
90 | #define DEFAULT_IGMP_LAST_MEMBER_QUERY_TIME 2000 |
||
91 | |||
92 | // maximum bind addresses |
||
93 | #define MAX_BIND_ADDRS 8 |
||
94 | // maximum external addresses per bind address |
||
95 | #define MAX_EXT_ADDRS 8 |
||
96 | // maximum scopes |
||
97 | #define MAX_SCOPES 8 |
||
98 | |||
99 | //#define SIMULATE_PEER_OUT_OF_BUFFER 70 |
||
100 | |||
101 | struct server_flow { |
||
102 | PacketPassFairQueueFlow qflow; |
||
103 | SinglePacketBuffer encoder_buffer; |
||
104 | PacketRecvConnector connector; |
||
105 | int connected; |
||
106 | }; |
||
107 | |||
108 | struct peer_data { |
||
109 | // peer identifier |
||
110 | peerid_t id; |
||
111 | |||
112 | // flags provided by the server |
||
113 | int flags; |
||
114 | |||
115 | // certificate reported by the server, defined only if using SSL |
||
116 | uint8_t cert[SCID_NEWCLIENT_MAX_CERT_LEN]; |
||
117 | int cert_len; |
||
118 | char *common_name; |
||
119 | |||
120 | // init job |
||
121 | BPending job_init; |
||
122 | |||
123 | // server flow |
||
124 | struct server_flow *server_flow; |
||
125 | |||
126 | // chat |
||
127 | int have_chat; |
||
128 | PeerChat chat; |
||
129 | int chat_send_msg_len; |
||
130 | |||
131 | // resetpeer source (when chat fails) |
||
132 | int have_resetpeer; |
||
133 | uint8_t resetpeer_packet[sizeof(struct packetproto_header) + sizeof(struct sc_header) + sizeof(struct sc_client_resetpeer)]; |
||
134 | SinglePacketSource resetpeer_source; |
||
135 | |||
136 | // local flow |
||
137 | DataProtoFlow local_dpflow; |
||
138 | |||
139 | // frame decider peer |
||
140 | FrameDeciderPeer decider_peer; |
||
141 | |||
142 | // receive peer |
||
143 | DPReceivePeer receive_peer; |
||
144 | |||
145 | // flag if link objects are initialized |
||
146 | int have_link; |
||
147 | |||
148 | // receive receiver |
||
149 | DPReceiveReceiver receive_receiver; |
||
150 | |||
151 | // transport-specific link objects |
||
152 | union { |
||
153 | struct { |
||
154 | DatagramPeerIO pio; |
||
155 | uint16_t sendseed_nextid; |
||
156 | int sendseed_sent; |
||
157 | uint16_t sendseed_sent_id; |
||
158 | uint8_t sendseed_sent_key[BENCRYPTION_MAX_KEY_SIZE]; |
||
159 | uint8_t sendseed_sent_iv[BENCRYPTION_MAX_BLOCK_SIZE]; |
||
160 | uint16_t pending_recvseed_id; |
||
161 | BPending job_send_seed; |
||
162 | } udp; |
||
163 | struct { |
||
164 | StreamPeerIO pio; |
||
165 | } tcp; |
||
166 | } pio; |
||
167 | |||
168 | // link sending |
||
169 | DataProtoSink send_dp; |
||
170 | |||
171 | // relaying objects |
||
172 | struct peer_data *relaying_peer; // peer through which we are relaying, or NULL |
||
173 | LinkedList1Node relaying_list_node; // node in relay peer's relay_users |
||
174 | |||
175 | // waiting for relay data |
||
176 | int waiting_relay; |
||
177 | LinkedList1Node waiting_relay_list_node; |
||
178 | |||
179 | // retry timer |
||
180 | BTimer reset_timer; |
||
181 | |||
182 | // relay server specific |
||
183 | int is_relay; |
||
184 | LinkedList1Node relay_list_node; |
||
185 | LinkedList1 relay_users; |
||
186 | |||
187 | // binding state |
||
188 | int binding; |
||
189 | int binding_addrpos; |
||
190 | |||
191 | // peers linked list node |
||
192 | LinkedList1Node list_node; |
||
193 | }; |