diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_channel.h')
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.h | 387 |
1 files changed, 143 insertions, 244 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h index 9d4893269..a3ef9a06d 100644 --- a/src/cadet/gnunet-service-cadet_channel.h +++ b/src/cadet/gnunet-service-cadet_channel.h | |||
@@ -1,6 +1,7 @@ | |||
1 | |||
1 | /* | 2 | /* |
2 | This file is part of GNUnet. | 3 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 4 | Copyright (C) 2001-2017 GNUnet e.V. |
4 | 5 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 6 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 7 | it under the terms of the GNU General Public License as published |
@@ -20,344 +21,242 @@ | |||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @file cadet/gnunet-service-cadet_channel.h | 23 | * @file cadet/gnunet-service-cadet_channel.h |
23 | * @brief cadet service; dealing with end-to-end channels | 24 | * @brief GNUnet CADET service with encryption |
24 | * @author Bartlomiej Polot | 25 | * @author Bartlomiej Polot |
25 | * | 26 | * @author Christian Grothoff |
26 | * All functions in this file should use the prefix GMCH (Gnunet Cadet CHannel) | ||
27 | */ | 27 | */ |
28 | |||
29 | #ifndef GNUNET_SERVICE_CADET_CHANNEL_H | 28 | #ifndef GNUNET_SERVICE_CADET_CHANNEL_H |
30 | #define GNUNET_SERVICE_CADET_CHANNEL_H | 29 | #define GNUNET_SERVICE_CADET_CHANNEL_H |
31 | 30 | ||
32 | #ifdef __cplusplus | 31 | #include "gnunet-service-cadet.h" |
33 | extern "C" | 32 | #include "gnunet-service-cadet_peer.h" |
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | #include "platform.h" | ||
41 | #include "gnunet_util_lib.h" | ||
42 | |||
43 | #include "cadet_protocol.h" | 33 | #include "cadet_protocol.h" |
44 | #include "cadet.h" | ||
45 | |||
46 | /** | ||
47 | * Struct containing all information regarding a channel to a remote client. | ||
48 | */ | ||
49 | struct CadetChannel; | ||
50 | |||
51 | |||
52 | #include "gnunet-service-cadet_tunnel.h" | ||
53 | #include "gnunet-service-cadet_local.h" | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Destroy a channel and free all resources. | ||
58 | * | ||
59 | * @param ch Channel to destroy. | ||
60 | */ | ||
61 | void | ||
62 | GCCH_destroy (struct CadetChannel *ch); | ||
63 | 34 | ||
64 | 35 | ||
65 | /** | 36 | /** |
66 | * Get the channel's public ID. | 37 | * A channel is a bidirectional connection between two CADET |
67 | * | 38 | * clients. Communiation can be reliable, unreliable, in-order |
68 | * @param ch Channel. | 39 | * or out-of-order. One client is the "local" client, this |
69 | * | 40 | * one initiated the connection. The other client is the |
70 | * @return ID used to identify the channel with the remote peer. | 41 | * "incoming" client, this one listened on a port to accept |
42 | * the connection from the "local" client. | ||
71 | */ | 43 | */ |
72 | struct GNUNET_CADET_ChannelTunnelNumber | 44 | struct CadetChannel; |
73 | GCCH_get_id (const struct CadetChannel *ch); | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Get the channel tunnel. | ||
78 | * | ||
79 | * @param ch Channel to get the tunnel from. | ||
80 | * | ||
81 | * @return tunnel of the channel. | ||
82 | */ | ||
83 | struct CadetTunnel * | ||
84 | GCCH_get_tunnel (const struct CadetChannel *ch); | ||
85 | 45 | ||
86 | 46 | ||
87 | /** | 47 | /** |
88 | * Get free buffer space towards the client on a specific channel. | 48 | * Get the static string for identification of the channel. |
89 | * | 49 | * |
90 | * @param ch Channel. | 50 | * @param ch Channel. |
91 | * @param fwd Is query about FWD traffic? | ||
92 | * | 51 | * |
93 | * @return Free buffer space [0 - 64] | 52 | * @return Static string with the channel IDs. |
94 | */ | 53 | */ |
95 | unsigned int | 54 | const char * |
96 | GCCH_get_buffer (struct CadetChannel *ch, int fwd); | 55 | GCCH_2s (const struct CadetChannel *ch); |
97 | 56 | ||
98 | 57 | ||
99 | /** | 58 | /** |
100 | * Get flow control status of end point: is client allow to send? | 59 | * Log channel info. |
101 | * | 60 | * |
102 | * @param ch Channel. | 61 | * @param ch Channel. |
103 | * @param fwd Is query about FWD traffic? (Request root status). | 62 | * @param level Debug level to use. |
104 | * | ||
105 | * @return #GNUNET_YES if client is allowed to send us data. | ||
106 | */ | 63 | */ |
107 | int | 64 | void |
108 | GCCH_get_allowed (struct CadetChannel *ch, int fwd); | 65 | GCCH_debug (struct CadetChannel *ch, |
66 | enum GNUNET_ErrorType level); | ||
109 | 67 | ||
110 | 68 | ||
111 | /** | 69 | /** |
112 | * Is the root client for this channel on this peer? | 70 | * Get the channel's public ID. |
113 | * | 71 | * |
114 | * @param ch Channel. | 72 | * @param ch Channel. |
115 | * @param fwd Is this for fwd traffic? | ||
116 | * | 73 | * |
117 | * @return #GNUNET_YES in case it is. | 74 | * @return ID used to identify the channel with the remote peer. |
118 | */ | 75 | */ |
119 | int | 76 | struct GNUNET_CADET_ChannelTunnelNumber |
120 | GCCH_is_origin (struct CadetChannel *ch, int fwd); | 77 | GCCH_get_id (const struct CadetChannel *ch); |
121 | 78 | ||
122 | /** | ||
123 | * Is the destination client for this channel on this peer? | ||
124 | * | ||
125 | * @param ch Channel. | ||
126 | * @param fwd Is this for fwd traffic? | ||
127 | * | ||
128 | * @return #GNUNET_YES in case it is. | ||
129 | */ | ||
130 | int | ||
131 | GCCH_is_terminal (struct CadetChannel *ch, int fwd); | ||
132 | 79 | ||
133 | /** | 80 | /** |
134 | * Send an end-to-end ACK message for the most recent in-sequence payload. | 81 | * Create a new channel. |
135 | * | 82 | * |
136 | * If channel is not reliable, do nothing. | 83 | * @param owner local client owning the channel |
137 | * | 84 | * @param owner_id local chid of this channel at the @a owner |
138 | * @param ch Channel this is about. | 85 | * @param destination peer to which we should build the channel |
139 | * @param fwd Is for FWD traffic? (ACK dest->owner) | 86 | * @param port desired port at @a destination |
87 | * @param options options for the channel | ||
88 | * @return handle to the new channel | ||
140 | */ | 89 | */ |
141 | void | 90 | struct CadetChannel * |
142 | GCCH_send_data_ack (struct CadetChannel *ch, int fwd); | 91 | GCCH_channel_local_new (struct CadetClient *owner, |
92 | struct GNUNET_CADET_ClientChannelNumber owner_id, | ||
93 | struct CadetPeer *destination, | ||
94 | const struct GNUNET_HashCode *port, | ||
95 | uint32_t options); | ||
143 | 96 | ||
144 | /** | ||
145 | * Notify the destination client that a new incoming channel was created. | ||
146 | * | ||
147 | * @param ch Channel that was created. | ||
148 | */ | ||
149 | void | ||
150 | GCCH_send_create (struct CadetChannel *ch); | ||
151 | 97 | ||
152 | /** | 98 | /** |
153 | * Allow a client to send us more data, in case it was choked. | 99 | * A client is bound to the port that we have a channel |
100 | * open to. Send the acknowledgement for the connection | ||
101 | * request and establish the link with the client. | ||
154 | * | 102 | * |
155 | * @param ch Channel. | 103 | * @param ch open incoming channel |
156 | * @param fwd Is this about FWD traffic? (Root client). | 104 | * @param c client listening on the respective port |
157 | */ | 105 | */ |
158 | void | 106 | void |
159 | GCCH_allow_client (struct CadetChannel *ch, int fwd); | 107 | GCCH_bind (struct CadetChannel *ch, |
108 | struct CadetClient *c); | ||
160 | 109 | ||
161 | /** | ||
162 | * Log channel info. | ||
163 | * | ||
164 | * @param ch Channel. | ||
165 | * @param level Debug level to use. | ||
166 | */ | ||
167 | void | ||
168 | GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level); | ||
169 | 110 | ||
170 | /** | 111 | /** |
171 | * Handle an ACK given by a client. | 112 | * Destroy locally created channel. Called by the |
113 | * local client, so no need to tell the client. | ||
172 | * | 114 | * |
173 | * Mark client as ready and send him any buffered data we could have for him. | 115 | * @param ch channel to destroy |
174 | * | 116 | * @param c client that caused the destruction |
175 | * @param ch Channel. | 117 | * @param ccn client number of the client @a c |
176 | * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK) | ||
177 | */ | 118 | */ |
178 | void | 119 | void |
179 | GCCH_handle_local_ack (struct CadetChannel *ch, int fwd); | 120 | GCCH_channel_local_destroy (struct CadetChannel *ch, |
121 | struct CadetClient *c, | ||
122 | struct GNUNET_CADET_ClientChannelNumber ccn); | ||
180 | 123 | ||
181 | /** | ||
182 | * Handle data given by a client. | ||
183 | * | ||
184 | * Check whether the client is allowed to send in this tunnel, save if channel | ||
185 | * is reliable and send an ACK to the client if there is still buffer space | ||
186 | * in the tunnel. | ||
187 | * | ||
188 | * @param ch Channel. | ||
189 | * @param c Client which sent the data. | ||
190 | * @param fwd Is this a FWD data? | ||
191 | * @param message Data message. | ||
192 | * @param size Size of data. | ||
193 | * | ||
194 | * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error. | ||
195 | */ | ||
196 | int | ||
197 | GCCH_handle_local_data (struct CadetChannel *ch, | ||
198 | struct CadetClient *c, int fwd, | ||
199 | const struct GNUNET_MessageHeader *message, | ||
200 | size_t size); | ||
201 | 124 | ||
202 | /** | 125 | /** |
203 | * Handle a channel destroy requested by a client. | 126 | * Function called once and only once after a channel was bound |
204 | * | 127 | * to its tunnel via #GCT_add_channel() is ready for transmission. |
205 | * Destroy the channel and the tunnel in case this was the last channel. | 128 | * Note that this is only the case for channels that this peer |
206 | * | 129 | * initiates, as for incoming channels we assume that they are |
207 | * @param ch Channel. | 130 | * ready for transmission immediately upon receiving the open |
208 | * @param c Client that requested the destruction (to avoid notifying him). | 131 | * message. Used to bootstrap the #GCT_send() process. |
209 | * @param is_root Is the request coming from root? | 132 | * |
133 | * @param ch the channel for which the tunnel is now ready | ||
210 | */ | 134 | */ |
211 | void | 135 | void |
212 | GCCH_handle_local_destroy (struct CadetChannel *ch, | 136 | GCCH_tunnel_up (struct CadetChannel *ch); |
213 | struct CadetClient *c, | ||
214 | int is_root); | ||
215 | 137 | ||
216 | 138 | ||
217 | /** | 139 | /** |
218 | * Handle a channel create requested by a client. | 140 | * Create a new channel based on a request coming in over the network. |
219 | * | 141 | * |
220 | * Create the channel and the tunnel in case this was the first0 channel. | 142 | * @param t tunnel to the remote peer |
221 | * | 143 | * @param chid identifier of this channel in the tunnel |
222 | * @param c Client that requested the creation (will be the root). | 144 | * @param origin peer to who initiated the channel |
223 | * @param msg Create Channel message. | 145 | * @param port desired local port |
224 | * | 146 | * @param options options for the channel |
225 | * @return #GNUNET_OK if everything went fine, #GNUNET_SYSERR otherwise. | 147 | * @return handle to the new channel |
226 | */ | 148 | */ |
227 | int | 149 | struct CadetChannel * |
228 | GCCH_handle_local_create (struct CadetClient *c, | 150 | GCCH_channel_incoming_new (struct CadetTunnel *t, |
229 | struct GNUNET_CADET_LocalChannelCreateMessage *msg); | 151 | struct GNUNET_CADET_ChannelTunnelNumber chid, |
230 | 152 | const struct GNUNET_HashCode *port, | |
231 | /** | 153 | uint32_t options); |
232 | * Handler for cadet network payload traffic. | ||
233 | * | ||
234 | * @param ch Channel for the message. | ||
235 | * @param msg Unencryted data message. | ||
236 | * @param fwd Is this message fwd? This only is meaningful in loopback channels. | ||
237 | * #GNUNET_YES if message is FWD on the respective channel (loopback) | ||
238 | * #GNUNET_NO if message is BCK on the respective channel (loopback) | ||
239 | * #GNUNET_SYSERR if message on a one-ended channel (remote) | ||
240 | */ | ||
241 | void | ||
242 | GCCH_handle_data (struct CadetChannel *ch, | ||
243 | const struct GNUNET_CADET_ChannelAppDataMessage *msg, | ||
244 | int fwd); | ||
245 | 154 | ||
246 | 155 | ||
247 | /** | 156 | /** |
248 | * Handler for cadet network traffic end-to-end ACKs. | 157 | * We got a #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN message again for |
158 | * this channel. If the binding was successful, (re)transmit the | ||
159 | * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK. | ||
249 | * | 160 | * |
250 | * @param ch Channel on which we got this message. | 161 | * @param ch channel that got the duplicate open |
251 | * @param msg Data message. | 162 | * @param cti identifier of the connection that delivered the message |
252 | * @param fwd Is this message fwd? This only is meaningful in loopback channels. | ||
253 | * #GNUNET_YES if message is FWD on the respective channel (loopback) | ||
254 | * #GNUNET_NO if message is BCK on the respective channel (loopback) | ||
255 | * #GNUNET_SYSERR if message on a one-ended channel (remote) | ||
256 | */ | 163 | */ |
257 | void | 164 | void |
258 | GCCH_handle_data_ack (struct CadetChannel *ch, | 165 | GCCH_handle_duplicate_open (struct CadetChannel *ch, |
259 | const struct GNUNET_CADET_ChannelDataAckMessage *msg, | 166 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti); |
260 | int fwd); | ||
261 | 167 | ||
262 | 168 | ||
263 | /** | ||
264 | * Handler for channel create messages. | ||
265 | * | ||
266 | * Does not have fwd parameter because it's always 'FWD': channel is incoming. | ||
267 | * | ||
268 | * @param t Tunnel this channel will be in. | ||
269 | * @param msg Channel crate message. | ||
270 | */ | ||
271 | struct CadetChannel * | ||
272 | GCCH_handle_create (struct CadetTunnel *t, | ||
273 | const struct GNUNET_CADET_ChannelOpenMessage *msg); | ||
274 | |||
275 | 169 | ||
276 | /** | 170 | /** |
277 | * Handler for channel NACK messages. | 171 | * We got payload data for a channel. Pass it on to the client. |
278 | * | 172 | * |
279 | * NACK messages always go dest -> root, no need for 'fwd' or 'msg' parameter. | 173 | * @param ch channel that got data |
280 | * | 174 | * @param cti identifier of the connection that delivered the message |
281 | * @param ch Channel. | 175 | * @param msg message that was received |
282 | */ | 176 | */ |
283 | void | 177 | void |
284 | GCCH_handle_nack (struct CadetChannel *ch); | 178 | GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, |
179 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | ||
180 | const struct GNUNET_CADET_ChannelAppDataMessage *msg); | ||
285 | 181 | ||
286 | 182 | ||
287 | /** | 183 | /** |
288 | * Handler for channel ack messages. | 184 | * We got an acknowledgement for payload data for a channel. |
185 | * Possibly resume transmissions. | ||
289 | * | 186 | * |
290 | * @param ch Channel this channel is to be created in. | 187 | * @param ch channel that got the ack |
291 | * @param msg Message. | 188 | * @param cti identifier of the connection that delivered the message |
292 | * @param fwd Is this message fwd? This only is meaningful in loopback channels. | 189 | * @param ack details about what was received |
293 | * #GNUNET_YES if message is FWD on the respective channel (loopback) | ||
294 | * #GNUNET_NO if message is BCK on the respective channel (loopback) | ||
295 | * #GNUNET_SYSERR if message on a one-ended channel (remote) | ||
296 | */ | 190 | */ |
297 | void | 191 | void |
298 | GCCH_handle_ack (struct CadetChannel *ch, | 192 | GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, |
299 | const struct GNUNET_CADET_ChannelManageMessage *msg, | 193 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
300 | int fwd); | 194 | const struct GNUNET_CADET_ChannelDataAckMessage *ack); |
301 | 195 | ||
302 | 196 | ||
303 | /** | 197 | /** |
304 | * Handler for channel destroy messages. | 198 | * We got an acknowledgement for the creation of the channel |
199 | * (the port is open on the other side). Begin transmissions. | ||
305 | * | 200 | * |
306 | * @param ch Channel this channel is to be destroyed of. | 201 | * @param ch channel to destroy |
307 | * @param msg Message. | 202 | * @param cti identifier of the connection that delivered the message, |
308 | * @param fwd Is this message fwd? This only is meaningful in loopback channels. | 203 | * NULL if the ACK was inferred because we got payload or are on loopback |
309 | * #GNUNET_YES if message is FWD on the respective channel (loopback) | ||
310 | * #GNUNET_NO if message is BCK on the respective channel (loopback) | ||
311 | * #GNUNET_SYSERR if message on a one-ended channel (remote) | ||
312 | */ | 204 | */ |
313 | void | 205 | void |
314 | GCCH_handle_destroy (struct CadetChannel *ch, | 206 | GCCH_handle_channel_open_ack (struct CadetChannel *ch, |
315 | const struct GNUNET_CADET_ChannelManageMessage *msg, | 207 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti); |
316 | int fwd); | ||
317 | 208 | ||
318 | 209 | ||
319 | /** | 210 | /** |
320 | * Sends an already built message on a channel. | 211 | * Destroy channel, based on the other peer closing the |
212 | * connection. Also needs to remove this channel from | ||
213 | * the tunnel. | ||
321 | * | 214 | * |
322 | * If the channel is on a loopback tunnel, notifies the appropriate destination | 215 | * FIXME: need to make it possible to defer destruction until we have |
323 | * client locally. | 216 | * received all messages up to the destroy, and right now the destroy |
217 | * message (and this API) fails to give is the information we need! | ||
324 | * | 218 | * |
325 | * On a normal channel passes the message to the tunnel for encryption and | 219 | * FIXME: also need to know if the other peer got a destroy from |
326 | * sending on a connection. | 220 | * us before! |
327 | * | 221 | * |
328 | * This function DOES NOT save the message for retransmission. | 222 | * @param ch channel to destroy |
329 | * | 223 | * @param cti identifier of the connection that delivered the message, |
330 | * @param message Message to send. Function makes a copy of it. | 224 | * NULL during shutdown |
331 | * @param ch Channel on which this message is transmitted. | ||
332 | * @param fwd Is this a fwd message? | ||
333 | * @param existing_copy This is a retransmission, don't save a copy. | ||
334 | */ | 225 | */ |
335 | void | 226 | void |
336 | GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | 227 | GCCH_handle_remote_destroy (struct CadetChannel *ch, |
337 | struct CadetChannel *ch, int fwd, | 228 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti); |
338 | void *existing_copy); | ||
339 | 229 | ||
340 | 230 | ||
341 | /** | 231 | /** |
342 | * Get the static string for identification of the channel. | 232 | * Handle data given by a client. |
343 | * | 233 | * |
344 | * @param ch Channel.i | 234 | * Check whether the client is allowed to send in this tunnel, save if |
235 | * channel is reliable and send an ACK to the client if there is still | ||
236 | * buffer space in the tunnel. | ||
345 | * | 237 | * |
346 | * @return Static string with the channel IDs. | 238 | * @param ch Channel. |
239 | * @param sender_ccn ccn of the sender | ||
240 | * @param buf payload to transmit. | ||
241 | * @param buf_len number of bytes in @a buf | ||
242 | * @return #GNUNET_OK if everything goes well, | ||
243 | * #GNUNET_SYSERR in case of an error. | ||
347 | */ | 244 | */ |
348 | const char * | 245 | int |
349 | GCCH_2s (const struct CadetChannel *ch); | 246 | GCCH_handle_local_data (struct CadetChannel *ch, |
350 | 247 | struct GNUNET_CADET_ClientChannelNumber sender_ccn, | |
351 | 248 | const char *buf, | |
249 | size_t buf_len); | ||
352 | 250 | ||
353 | 251 | ||
354 | #if 0 /* keep Emacsens' auto-indent happy */ | 252 | /** |
355 | { | 253 | * Handle ACK from client on local channel. |
356 | #endif | 254 | * |
357 | #ifdef __cplusplus | 255 | * @param ch channel to destroy |
358 | } | 256 | * @param client_ccn ccn of the client sending the ack |
359 | #endif | 257 | */ |
258 | void | ||
259 | GCCH_handle_local_ack (struct CadetChannel *ch, | ||
260 | struct GNUNET_CADET_ClientChannelNumber client_ccn); | ||
360 | 261 | ||
361 | /* ifndef GNUNET_SERVICE_CADET_CHANNEL_H */ | ||
362 | #endif | 262 | #endif |
363 | /* end of gnunet-service-cadet_channel.h */ | ||