diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-04-21 13:21:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-04-21 13:21:39 +0000 |
commit | 12aa63458e22aa369d8ac64d5448cc17a0618817 (patch) | |
tree | d44a702a086649718e0531d8dc6abb1227da8a5b /src/peerinfo/peerinfo_api.c | |
parent | cf3e70cea00a2d6d519fe563370ee9df16fdd913 (diff) | |
download | gnunet-12aa63458e22aa369d8ac64d5448cc17a0618817.tar.gz gnunet-12aa63458e22aa369d8ac64d5448cc17a0618817.zip |
docu
Diffstat (limited to 'src/peerinfo/peerinfo_api.c')
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index aac83f71b..c8a9daabe 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -27,6 +27,7 @@ | |||
27 | * - document NEW API implementation | 27 | * - document NEW API implementation |
28 | * - add timeout for iteration | 28 | * - add timeout for iteration |
29 | * - implement cancellation of iteration | 29 | * - implement cancellation of iteration |
30 | * - prevent transmit during receive! | ||
30 | */ | 31 | */ |
31 | #include "platform.h" | 32 | #include "platform.h" |
32 | #include "gnunet_client_lib.h" | 33 | #include "gnunet_client_lib.h" |
@@ -37,44 +38,48 @@ | |||
37 | #include "peerinfo.h" | 38 | #include "peerinfo.h" |
38 | 39 | ||
39 | /** | 40 | /** |
40 | * | 41 | * Function to call after transmission has succeeded. |
42 | * | ||
43 | * @param cls closure | ||
44 | * @param success GNUNET_OK if transmission worked, GNUNET_SYSERR on error | ||
41 | */ | 45 | */ |
42 | typedef void (*TransmissionContinuation)(void *cls, | 46 | typedef void (*TransmissionContinuation)(void *cls, |
43 | int success); | 47 | int success); |
44 | 48 | ||
45 | 49 | ||
46 | /** | 50 | /** |
47 | * | 51 | * Entry in the transmission queue to PEERINFO service. |
48 | */ | 52 | */ |
49 | struct TransmissionQueueEntry | 53 | struct TransmissionQueueEntry |
50 | { | 54 | { |
51 | /** | 55 | /** |
52 | * | 56 | * This is a linked list. |
53 | */ | 57 | */ |
54 | struct TransmissionQueueEntry *next; | 58 | struct TransmissionQueueEntry *next; |
55 | 59 | ||
56 | /** | 60 | /** |
57 | * | 61 | * This is a linked list. |
58 | */ | 62 | */ |
59 | struct TransmissionQueueEntry *prev; | 63 | struct TransmissionQueueEntry *prev; |
60 | 64 | ||
61 | /** | 65 | /** |
62 | * | 66 | * Function to call after request has been transmitted, or NULL (in which |
67 | * case we must consider sending the next entry immediately). | ||
63 | */ | 68 | */ |
64 | TransmissionContinuation cont; | 69 | TransmissionContinuation cont; |
65 | 70 | ||
66 | /** | 71 | /** |
67 | * | 72 | * Closure for 'cont'. |
68 | */ | 73 | */ |
69 | void *cont_cls; | 74 | void *cont_cls; |
70 | 75 | ||
71 | /** | 76 | /** |
72 | * | 77 | * When this request times out. |
73 | */ | 78 | */ |
74 | struct GNUNET_TIME_Absolute timeout; | 79 | struct GNUNET_TIME_Absolute timeout; |
75 | 80 | ||
76 | /** | 81 | /** |
77 | * | 82 | * Number of bytes of the request message (follows after this struct). |
78 | */ | 83 | */ |
79 | size_t size; | 84 | size_t size; |
80 | 85 | ||
@@ -102,19 +107,20 @@ struct GNUNET_PEERINFO_Handle | |||
102 | struct GNUNET_CLIENT_Connection *client; | 107 | struct GNUNET_CLIENT_Connection *client; |
103 | 108 | ||
104 | /** | 109 | /** |
105 | * | 110 | * Head of transmission queue. |
106 | */ | 111 | */ |
107 | struct TransmissionQueueEntry *tq_head; | 112 | struct TransmissionQueueEntry *tq_head; |
108 | 113 | ||
109 | /** | 114 | /** |
110 | * | 115 | * Tail of transmission queue. |
111 | */ | 116 | */ |
112 | struct TransmissionQueueEntry *tq_tail; | 117 | struct TransmissionQueueEntry *tq_tail; |
113 | 118 | ||
114 | /** | 119 | /** |
115 | * | 120 | * Handle for the current transmission request, or NULL if none is pending. |
116 | */ | 121 | */ |
117 | struct GNUNET_CLIENT_TransmitHandle *th; | 122 | struct GNUNET_CLIENT_TransmitHandle *th; |
123 | |||
118 | }; | 124 | }; |
119 | 125 | ||
120 | 126 | ||
@@ -173,14 +179,19 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | |||
173 | 179 | ||
174 | 180 | ||
175 | /** | 181 | /** |
182 | * Check if we have a request pending in the transmission queue and are | ||
183 | * able to transmit it right now. If so, schedule transmission. | ||
176 | * | 184 | * |
185 | * @param h handle to the service | ||
177 | */ | 186 | */ |
178 | static void | 187 | static void |
179 | trigger_transmit (struct GNUNET_PEERINFO_Handle *h); | 188 | trigger_transmit (struct GNUNET_PEERINFO_Handle *h); |
180 | 189 | ||
181 | 190 | ||
182 | /** | 191 | /** |
192 | * Close the existing connection to PEERINFO and reconnect. | ||
183 | * | 193 | * |
194 | * @param h handle to the service | ||
184 | */ | 195 | */ |
185 | static void | 196 | static void |
186 | reconnect (struct GNUNET_PEERINFO_Handle *h) | 197 | reconnect (struct GNUNET_PEERINFO_Handle *h) |
@@ -192,7 +203,13 @@ reconnect (struct GNUNET_PEERINFO_Handle *h) | |||
192 | 203 | ||
193 | 204 | ||
194 | /** | 205 | /** |
206 | * Transmit the request at the head of the transmission queue | ||
207 | * and trigger continuation (if any). | ||
195 | * | 208 | * |
209 | * @param cls the 'struct GNUNET_PEERINFO_Handle' (with the queue) | ||
210 | * @param size size of the buffer (0 on error) | ||
211 | * @param buf where to copy the message | ||
212 | * @return number of bytes copied to buf | ||
196 | */ | 213 | */ |
197 | static size_t | 214 | static size_t |
198 | do_transmit (void *cls, size_t size, void *buf) | 215 | do_transmit (void *cls, size_t size, void *buf) |
@@ -235,11 +252,19 @@ do_transmit (void *cls, size_t size, void *buf) | |||
235 | } | 252 | } |
236 | 253 | ||
237 | 254 | ||
255 | /** | ||
256 | * Check if we have a request pending in the transmission queue and are | ||
257 | * able to transmit it right now. If so, schedule transmission. | ||
258 | * | ||
259 | * @param h handle to the service | ||
260 | */ | ||
238 | static void | 261 | static void |
239 | trigger_transmit (struct GNUNET_PEERINFO_Handle *h) | 262 | trigger_transmit (struct GNUNET_PEERINFO_Handle *h) |
240 | { | 263 | { |
241 | struct TransmissionQueueEntry *tqe; | 264 | struct TransmissionQueueEntry *tqe; |
242 | 265 | ||
266 | /* FIXME: need to handle case where we are still *receiving* (and then | ||
267 | do nothing here as well!) */ | ||
243 | if (NULL == (tqe = h->tq_head)) | 268 | if (NULL == (tqe = h->tq_head)) |
244 | return; | 269 | return; |
245 | if (h->th != NULL) | 270 | if (h->th != NULL) |
@@ -292,35 +317,33 @@ GNUNET_PEERINFO_add_peer_new (struct GNUNET_PEERINFO_Handle *h, | |||
292 | } | 317 | } |
293 | 318 | ||
294 | 319 | ||
295 | |||
296 | /** | 320 | /** |
297 | * | 321 | * Context for an iteration request. |
298 | */ | 322 | */ |
299 | struct GNUNET_PEERINFO_NewIteratorContext | 323 | struct GNUNET_PEERINFO_NewIteratorContext |
300 | { | 324 | { |
301 | /** | 325 | /** |
302 | * | 326 | * Handle to the PEERINFO service. |
303 | */ | 327 | */ |
304 | struct GNUNET_PEERINFO_Handle *h; | 328 | struct GNUNET_PEERINFO_Handle *h; |
305 | 329 | ||
306 | /** | 330 | /** |
307 | * | 331 | * Function to call with the results. |
308 | */ | 332 | */ |
309 | GNUNET_PEERINFO_Processor callback; | 333 | GNUNET_PEERINFO_Processor callback; |
310 | 334 | ||
311 | /** | 335 | /** |
312 | * | 336 | * Closure for 'callback'. |
313 | */ | 337 | */ |
314 | void *callback_cls; | 338 | void *callback_cls; |
315 | 339 | ||
316 | /** | 340 | /** |
317 | * | 341 | * Timeout for the operation. |
318 | */ | 342 | */ |
319 | struct GNUNET_TIME_Absolute timeout; | 343 | struct GNUNET_TIME_Absolute timeout; |
320 | }; | 344 | }; |
321 | 345 | ||
322 | 346 | ||
323 | |||
324 | /** | 347 | /** |
325 | * Type of a function to call when we receive a message | 348 | * Type of a function to call when we receive a message |
326 | * from the service. | 349 | * from the service. |
@@ -400,7 +423,11 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
400 | 423 | ||
401 | 424 | ||
402 | /** | 425 | /** |
426 | * We've transmitted the iteration request. Now get ready to process | ||
427 | * the results (or handle transmission error). | ||
403 | * | 428 | * |
429 | * @param cls the 'struct GNUNET_PEERINFO_NewIteratorContext' | ||
430 | * @param transmit_success GNUNET_OK if transmission worked | ||
404 | */ | 431 | */ |
405 | static void | 432 | static void |
406 | iterator_start_receive (void *cls, | 433 | iterator_start_receive (void *cls, |