diff options
Diffstat (limited to 'src/peerinfo/peerinfo_api.c')
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 427 |
1 files changed, 211 insertions, 216 deletions
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index 485b5e183..ada6f5462 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file peerinfo/peerinfo_api.c | 22 | * @file peerinfo/peerinfo_api.c |
@@ -28,15 +28,13 @@ | |||
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | #include "peerinfo.h" | 29 | #include "peerinfo.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerinfo-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Context for an iteration request. | 35 | * Context for an iteration request. |
36 | */ | 36 | */ |
37 | struct GNUNET_PEERINFO_IteratorContext | 37 | struct GNUNET_PEERINFO_IteratorContext { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Kept in a DLL. | 39 | * Kept in a DLL. |
42 | */ | 40 | */ |
@@ -76,15 +74,13 @@ struct GNUNET_PEERINFO_IteratorContext | |||
76 | * Only include friends in reply? | 74 | * Only include friends in reply? |
77 | */ | 75 | */ |
78 | int include_friend_only; | 76 | int include_friend_only; |
79 | |||
80 | }; | 77 | }; |
81 | 78 | ||
82 | 79 | ||
83 | /** | 80 | /** |
84 | * Handle to the peerinfo service. | 81 | * Handle to the peerinfo service. |
85 | */ | 82 | */ |
86 | struct GNUNET_PEERINFO_Handle | 83 | struct GNUNET_PEERINFO_Handle { |
87 | { | ||
88 | /** | 84 | /** |
89 | * Our configuration. | 85 | * Our configuration. |
90 | */ | 86 | */ |
@@ -109,7 +105,6 @@ struct GNUNET_PEERINFO_Handle | |||
109 | * ID for a reconnect task. | 105 | * ID for a reconnect task. |
110 | */ | 106 | */ |
111 | struct GNUNET_SCHEDULER_Task *r_task; | 107 | struct GNUNET_SCHEDULER_Task *r_task; |
112 | |||
113 | }; | 108 | }; |
114 | 109 | ||
115 | 110 | ||
@@ -119,7 +114,7 @@ struct GNUNET_PEERINFO_Handle | |||
119 | * @param h handle to the service | 114 | * @param h handle to the service |
120 | */ | 115 | */ |
121 | static void | 116 | static void |
122 | reconnect (struct GNUNET_PEERINFO_Handle *h); | 117 | reconnect(struct GNUNET_PEERINFO_Handle *h); |
123 | 118 | ||
124 | 119 | ||
125 | /** | 120 | /** |
@@ -130,18 +125,18 @@ reconnect (struct GNUNET_PEERINFO_Handle *h); | |||
130 | * establishment may happen asynchronously). | 125 | * establishment may happen asynchronously). |
131 | */ | 126 | */ |
132 | struct GNUNET_PEERINFO_Handle * | 127 | struct GNUNET_PEERINFO_Handle * |
133 | GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 128 | GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
134 | { | 129 | { |
135 | struct GNUNET_PEERINFO_Handle *h; | 130 | struct GNUNET_PEERINFO_Handle *h; |
136 | 131 | ||
137 | h = GNUNET_new (struct GNUNET_PEERINFO_Handle); | 132 | h = GNUNET_new(struct GNUNET_PEERINFO_Handle); |
138 | h->cfg = cfg; | 133 | h->cfg = cfg; |
139 | reconnect (h); | 134 | reconnect(h); |
140 | if (NULL == h->mq) | 135 | if (NULL == h->mq) |
141 | { | 136 | { |
142 | GNUNET_free (h); | 137 | GNUNET_free(h); |
143 | return NULL; | 138 | return NULL; |
144 | } | 139 | } |
145 | return h; | 140 | return h; |
146 | } | 141 | } |
147 | 142 | ||
@@ -156,28 +151,28 @@ GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
156 | * @param h handle to disconnect | 151 | * @param h handle to disconnect |
157 | */ | 152 | */ |
158 | void | 153 | void |
159 | GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | 154 | GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h) |
160 | { | 155 | { |
161 | struct GNUNET_PEERINFO_IteratorContext *ic; | 156 | struct GNUNET_PEERINFO_IteratorContext *ic; |
162 | 157 | ||
163 | while (NULL != (ic = h->ic_head)) | 158 | while (NULL != (ic = h->ic_head)) |
164 | { | 159 | { |
165 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 160 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
166 | h->ic_tail, | 161 | h->ic_tail, |
167 | ic); | 162 | ic); |
168 | GNUNET_free (ic); | 163 | GNUNET_free(ic); |
169 | } | 164 | } |
170 | if (NULL != h->mq) | 165 | if (NULL != h->mq) |
171 | { | 166 | { |
172 | GNUNET_MQ_destroy (h->mq); | 167 | GNUNET_MQ_destroy(h->mq); |
173 | h->mq = NULL; | 168 | h->mq = NULL; |
174 | } | 169 | } |
175 | if (NULL != h->r_task) | 170 | if (NULL != h->r_task) |
176 | { | 171 | { |
177 | GNUNET_SCHEDULER_cancel (h->r_task); | 172 | GNUNET_SCHEDULER_cancel(h->r_task); |
178 | h->r_task = NULL; | 173 | h->r_task = NULL; |
179 | } | 174 | } |
180 | GNUNET_free (h); | 175 | GNUNET_free(h); |
181 | } | 176 | } |
182 | 177 | ||
183 | 178 | ||
@@ -187,12 +182,12 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | |||
187 | * @param cls the `struct GNUNET_PEERINFO_Handle *` | 182 | * @param cls the `struct GNUNET_PEERINFO_Handle *` |
188 | */ | 183 | */ |
189 | static void | 184 | static void |
190 | reconnect_task (void *cls) | 185 | reconnect_task(void *cls) |
191 | { | 186 | { |
192 | struct GNUNET_PEERINFO_Handle *h = cls; | 187 | struct GNUNET_PEERINFO_Handle *h = cls; |
193 | 188 | ||
194 | h->r_task = NULL; | 189 | h->r_task = NULL; |
195 | reconnect (h); | 190 | reconnect(h); |
196 | } | 191 | } |
197 | 192 | ||
198 | 193 | ||
@@ -202,26 +197,26 @@ reconnect_task (void *cls) | |||
202 | * @param h handle to reconnect | 197 | * @param h handle to reconnect |
203 | */ | 198 | */ |
204 | static void | 199 | static void |
205 | do_reconnect (struct GNUNET_PEERINFO_Handle *h) | 200 | do_reconnect(struct GNUNET_PEERINFO_Handle *h) |
206 | { | 201 | { |
207 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 202 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
208 | 203 | ||
209 | GNUNET_MQ_destroy (h->mq); | 204 | GNUNET_MQ_destroy(h->mq); |
210 | h->mq = NULL; | 205 | h->mq = NULL; |
211 | if (NULL != ic) | 206 | if (NULL != ic) |
212 | { | 207 | { |
213 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 208 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
214 | h->ic_tail, | 209 | h->ic_tail, |
215 | ic); | 210 | ic); |
216 | if (NULL != ic->callback) | 211 | if (NULL != ic->callback) |
217 | ic->callback (ic->callback_cls, | 212 | ic->callback(ic->callback_cls, |
218 | NULL, | 213 | NULL, |
219 | NULL, | 214 | NULL, |
220 | _("Failed to receive response from `PEERINFO' service.")); | 215 | _("Failed to receive response from `PEERINFO' service.")); |
221 | GNUNET_free (ic); | 216 | GNUNET_free(ic); |
222 | } | 217 | } |
223 | h->r_task = GNUNET_SCHEDULER_add_now (&reconnect_task, | 218 | h->r_task = GNUNET_SCHEDULER_add_now(&reconnect_task, |
224 | h); | 219 | h); |
225 | } | 220 | } |
226 | 221 | ||
227 | 222 | ||
@@ -233,12 +228,12 @@ do_reconnect (struct GNUNET_PEERINFO_Handle *h) | |||
233 | * @param error error code | 228 | * @param error error code |
234 | */ | 229 | */ |
235 | static void | 230 | static void |
236 | mq_error_handler (void *cls, | 231 | mq_error_handler(void *cls, |
237 | enum GNUNET_MQ_Error error) | 232 | enum GNUNET_MQ_Error error) |
238 | { | 233 | { |
239 | struct GNUNET_PEERINFO_Handle *h = cls; | 234 | struct GNUNET_PEERINFO_Handle *h = cls; |
240 | 235 | ||
241 | do_reconnect (h); | 236 | do_reconnect(h); |
242 | } | 237 | } |
243 | 238 | ||
244 | 239 | ||
@@ -252,70 +247,70 @@ mq_error_handler (void *cls, | |||
252 | * @return #GNUNET_OK if the message is OK | 247 | * @return #GNUNET_OK if the message is OK |
253 | */ | 248 | */ |
254 | static int | 249 | static int |
255 | check_info (void *cls, | 250 | check_info(void *cls, |
256 | const struct InfoMessage *im) | 251 | const struct InfoMessage *im) |
257 | { | 252 | { |
258 | struct GNUNET_PEERINFO_Handle *h = cls; | 253 | struct GNUNET_PEERINFO_Handle *h = cls; |
259 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 254 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
260 | uint16_t ms = ntohs (im->header.size) - sizeof (*im); | 255 | uint16_t ms = ntohs(im->header.size) - sizeof(*im); |
261 | 256 | ||
262 | if (0 != ntohl (im->reserved)) | 257 | if (0 != ntohl(im->reserved)) |
263 | { | 258 | { |
264 | GNUNET_break (0); | 259 | GNUNET_break(0); |
265 | return GNUNET_SYSERR; | 260 | return GNUNET_SYSERR; |
266 | } | 261 | } |
267 | if (NULL == ic) | 262 | if (NULL == ic) |
268 | { | ||
269 | /* didn't expect a response, bad */ | ||
270 | GNUNET_break (0); | ||
271 | return GNUNET_SYSERR; | ||
272 | } | ||
273 | if ( (GNUNET_YES == ic->have_peer) && | ||
274 | (0 != GNUNET_memcmp (&ic->peer, | ||
275 | &im->peer)) ) | ||
276 | { | ||
277 | /* bogus message (from a different iteration call?); out of sequence! */ | ||
278 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
279 | "Received HELLO for peer `%s', expected peer `%s'\n", | ||
280 | GNUNET_i2s (&im->peer), | ||
281 | GNUNET_i2s (&ic->peer)); | ||
282 | GNUNET_break (0); | ||
283 | return GNUNET_SYSERR; | ||
284 | } | ||
285 | if (ms > sizeof (struct GNUNET_MessageHeader)) | ||
286 | { | ||
287 | const struct GNUNET_HELLO_Message *hello; | ||
288 | struct GNUNET_PeerIdentity id; | ||
289 | |||
290 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
291 | if (ms != GNUNET_HELLO_size (hello)) | ||
292 | { | 263 | { |
293 | /* malformed message */ | 264 | /* didn't expect a response, bad */ |
294 | GNUNET_break (0); | 265 | GNUNET_break(0); |
295 | return GNUNET_SYSERR; | 266 | return GNUNET_SYSERR; |
296 | } | 267 | } |
297 | if (GNUNET_OK != | 268 | if ((GNUNET_YES == ic->have_peer) && |
298 | GNUNET_HELLO_get_id (hello, | 269 | (0 != GNUNET_memcmp(&ic->peer, |
299 | &id)) | 270 | &im->peer))) |
300 | { | 271 | { |
301 | /* malformed message */ | 272 | /* bogus message (from a different iteration call?); out of sequence! */ |
302 | GNUNET_break (0); | 273 | LOG(GNUNET_ERROR_TYPE_ERROR, |
274 | "Received HELLO for peer `%s', expected peer `%s'\n", | ||
275 | GNUNET_i2s(&im->peer), | ||
276 | GNUNET_i2s(&ic->peer)); | ||
277 | GNUNET_break(0); | ||
303 | return GNUNET_SYSERR; | 278 | return GNUNET_SYSERR; |
304 | } | 279 | } |
305 | if (0 != GNUNET_memcmp (&im->peer, | 280 | if (ms > sizeof(struct GNUNET_MessageHeader)) |
306 | &id)) | 281 | { |
282 | const struct GNUNET_HELLO_Message *hello; | ||
283 | struct GNUNET_PeerIdentity id; | ||
284 | |||
285 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | ||
286 | if (ms != GNUNET_HELLO_size(hello)) | ||
287 | { | ||
288 | /* malformed message */ | ||
289 | GNUNET_break(0); | ||
290 | return GNUNET_SYSERR; | ||
291 | } | ||
292 | if (GNUNET_OK != | ||
293 | GNUNET_HELLO_get_id(hello, | ||
294 | &id)) | ||
295 | { | ||
296 | /* malformed message */ | ||
297 | GNUNET_break(0); | ||
298 | return GNUNET_SYSERR; | ||
299 | } | ||
300 | if (0 != GNUNET_memcmp(&im->peer, | ||
301 | &id)) | ||
302 | { | ||
303 | /* malformed message */ | ||
304 | GNUNET_break(0); | ||
305 | return GNUNET_SYSERR; | ||
306 | } | ||
307 | } | ||
308 | else if (0 != ms) | ||
307 | { | 309 | { |
308 | /* malformed message */ | 310 | /* malformed message */ |
309 | GNUNET_break (0); | 311 | GNUNET_break(0); |
310 | return GNUNET_SYSERR; | 312 | return GNUNET_SYSERR; |
311 | } | 313 | } |
312 | } | ||
313 | else if (0 != ms) | ||
314 | { | ||
315 | /* malformed message */ | ||
316 | GNUNET_break (0); | ||
317 | return GNUNET_SYSERR; | ||
318 | } | ||
319 | return GNUNET_OK; | 314 | return GNUNET_OK; |
320 | } | 315 | } |
321 | 316 | ||
@@ -327,22 +322,22 @@ check_info (void *cls, | |||
327 | * @param im message received | 322 | * @param im message received |
328 | */ | 323 | */ |
329 | static void | 324 | static void |
330 | handle_info (void *cls, | 325 | handle_info(void *cls, |
331 | const struct InfoMessage *im) | 326 | const struct InfoMessage *im) |
332 | { | 327 | { |
333 | struct GNUNET_PEERINFO_Handle *h = cls; | 328 | struct GNUNET_PEERINFO_Handle *h = cls; |
334 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 329 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
335 | const struct GNUNET_HELLO_Message *hello = NULL; | 330 | const struct GNUNET_HELLO_Message *hello = NULL; |
336 | uint16_t ms; | 331 | uint16_t ms; |
337 | 332 | ||
338 | ms = ntohs (im->header.size); | 333 | ms = ntohs(im->header.size); |
339 | if (ms > sizeof (struct InfoMessage)) | 334 | if (ms > sizeof(struct InfoMessage)) |
340 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | 335 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; |
341 | if (NULL != ic->callback) | 336 | if (NULL != ic->callback) |
342 | ic->callback (ic->callback_cls, | 337 | ic->callback(ic->callback_cls, |
343 | &im->peer, | 338 | &im->peer, |
344 | hello, | 339 | hello, |
345 | NULL); | 340 | NULL); |
346 | } | 341 | } |
347 | 342 | ||
348 | 343 | ||
@@ -352,7 +347,7 @@ handle_info (void *cls, | |||
352 | * @param h handle | 347 | * @param h handle |
353 | */ | 348 | */ |
354 | static void | 349 | static void |
355 | send_ic_request (struct GNUNET_PEERINFO_Handle *h) | 350 | send_ic_request(struct GNUNET_PEERINFO_Handle *h) |
356 | { | 351 | { |
357 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 352 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
358 | struct GNUNET_MQ_Envelope *env; | 353 | struct GNUNET_MQ_Envelope *env; |
@@ -360,35 +355,35 @@ send_ic_request (struct GNUNET_PEERINFO_Handle *h) | |||
360 | struct ListPeerMessage *lpm; | 355 | struct ListPeerMessage *lpm; |
361 | 356 | ||
362 | if (NULL == ic) | 357 | if (NULL == ic) |
363 | { | 358 | { |
364 | GNUNET_break (0); | 359 | GNUNET_break(0); |
365 | return; | 360 | return; |
366 | } | 361 | } |
367 | if (NULL == h->mq) | 362 | if (NULL == h->mq) |
368 | { | 363 | { |
369 | GNUNET_break (0); | 364 | GNUNET_break(0); |
370 | return; | 365 | return; |
371 | } | 366 | } |
372 | if (GNUNET_NO == ic->have_peer) | 367 | if (GNUNET_NO == ic->have_peer) |
373 | { | 368 | { |
374 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 369 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
375 | "Requesting list of peers from PEERINFO service\n"); | 370 | "Requesting list of peers from PEERINFO service\n"); |
376 | env = GNUNET_MQ_msg (lapm, | 371 | env = GNUNET_MQ_msg(lapm, |
377 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | 372 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); |
378 | lapm->include_friend_only = htonl (ic->include_friend_only); | 373 | lapm->include_friend_only = htonl(ic->include_friend_only); |
379 | } | 374 | } |
380 | else | 375 | else |
381 | { | 376 | { |
382 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 377 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
383 | "Requesting information on peer `%s' from PEERINFO service\n", | 378 | "Requesting information on peer `%s' from PEERINFO service\n", |
384 | GNUNET_i2s (&ic->peer)); | 379 | GNUNET_i2s(&ic->peer)); |
385 | env = GNUNET_MQ_msg (lpm, | 380 | env = GNUNET_MQ_msg(lpm, |
386 | GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 381 | GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
387 | lpm->include_friend_only = htonl (ic->include_friend_only); | 382 | lpm->include_friend_only = htonl(ic->include_friend_only); |
388 | lpm->peer = ic->peer; | 383 | lpm->peer = ic->peer; |
389 | } | 384 | } |
390 | GNUNET_MQ_send (h->mq, | 385 | GNUNET_MQ_send(h->mq, |
391 | env); | 386 | env); |
392 | } | 387 | } |
393 | 388 | ||
394 | 389 | ||
@@ -402,32 +397,32 @@ send_ic_request (struct GNUNET_PEERINFO_Handle *h) | |||
402 | * @param msg message received, NULL on timeout or fatal error | 397 | * @param msg message received, NULL on timeout or fatal error |
403 | */ | 398 | */ |
404 | static void | 399 | static void |
405 | handle_end_iteration (void *cls, | 400 | handle_end_iteration(void *cls, |
406 | const struct GNUNET_MessageHeader *msg) | 401 | const struct GNUNET_MessageHeader *msg) |
407 | { | 402 | { |
408 | struct GNUNET_PEERINFO_Handle *h = cls; | 403 | struct GNUNET_PEERINFO_Handle *h = cls; |
409 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 404 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
410 | 405 | ||
411 | if (NULL == ic) | 406 | if (NULL == ic) |
412 | { | 407 | { |
413 | /* didn't expect a response, reconnect */ | 408 | /* didn't expect a response, reconnect */ |
414 | GNUNET_break (0); | 409 | GNUNET_break(0); |
415 | reconnect (h); | 410 | reconnect(h); |
416 | return; | 411 | return; |
417 | } | 412 | } |
418 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 413 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
419 | "Received end of list of peers from PEERINFO service\n"); | 414 | "Received end of list of peers from PEERINFO service\n"); |
420 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 415 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
421 | h->ic_tail, | 416 | h->ic_tail, |
422 | ic); | 417 | ic); |
423 | if (NULL != h->ic_head) | 418 | if (NULL != h->ic_head) |
424 | send_ic_request (h); | 419 | send_ic_request(h); |
425 | if (NULL != ic->callback) | 420 | if (NULL != ic->callback) |
426 | ic->callback (ic->callback_cls, | 421 | ic->callback(ic->callback_cls, |
427 | NULL, | 422 | NULL, |
428 | NULL, | 423 | NULL, |
429 | NULL); | 424 | NULL); |
430 | GNUNET_free (ic); | 425 | GNUNET_free(ic); |
431 | } | 426 | } |
432 | 427 | ||
433 | 428 | ||
@@ -437,37 +432,37 @@ handle_end_iteration (void *cls, | |||
437 | * @param h handle to the service | 432 | * @param h handle to the service |
438 | */ | 433 | */ |
439 | static void | 434 | static void |
440 | reconnect (struct GNUNET_PEERINFO_Handle *h) | 435 | reconnect(struct GNUNET_PEERINFO_Handle *h) |
441 | { | 436 | { |
442 | struct GNUNET_MQ_MessageHandler handlers[] = { | 437 | struct GNUNET_MQ_MessageHandler handlers[] = { |
443 | GNUNET_MQ_hd_var_size (info, | 438 | GNUNET_MQ_hd_var_size(info, |
444 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, | 439 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, |
445 | struct InfoMessage, | 440 | struct InfoMessage, |
446 | h), | 441 | h), |
447 | GNUNET_MQ_hd_fixed_size (end_iteration, | 442 | GNUNET_MQ_hd_fixed_size(end_iteration, |
448 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, | 443 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, |
449 | struct GNUNET_MessageHeader, | 444 | struct GNUNET_MessageHeader, |
450 | h), | 445 | h), |
451 | GNUNET_MQ_handler_end () | 446 | GNUNET_MQ_handler_end() |
452 | }; | 447 | }; |
453 | 448 | ||
454 | if (NULL != h->r_task) | 449 | if (NULL != h->r_task) |
455 | { | 450 | { |
456 | GNUNET_SCHEDULER_cancel (h->r_task); | 451 | GNUNET_SCHEDULER_cancel(h->r_task); |
457 | h->r_task = NULL; | 452 | h->r_task = NULL; |
458 | } | 453 | } |
459 | if (NULL != h->mq) | 454 | if (NULL != h->mq) |
460 | { | 455 | { |
461 | GNUNET_MQ_destroy (h->mq); | 456 | GNUNET_MQ_destroy(h->mq); |
462 | h->mq = NULL; | 457 | h->mq = NULL; |
463 | } | 458 | } |
464 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 459 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
465 | "peerinfo", | 460 | "peerinfo", |
466 | handlers, | 461 | handlers, |
467 | &mq_error_handler, | 462 | &mq_error_handler, |
468 | h); | 463 | h); |
469 | if (NULL != h->ic_head) | 464 | if (NULL != h->ic_head) |
470 | send_ic_request (h); | 465 | send_ic_request(h); |
471 | } | 466 | } |
472 | 467 | ||
473 | 468 | ||
@@ -488,29 +483,29 @@ reconnect (struct GNUNET_PEERINFO_Handle *h) | |||
488 | * @return iterator context | 483 | * @return iterator context |
489 | */ | 484 | */ |
490 | struct GNUNET_PEERINFO_IteratorContext * | 485 | struct GNUNET_PEERINFO_IteratorContext * |
491 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | 486 | GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, |
492 | int include_friend_only, | 487 | int include_friend_only, |
493 | const struct GNUNET_PeerIdentity *peer, | 488 | const struct GNUNET_PeerIdentity *peer, |
494 | GNUNET_PEERINFO_Processor callback, | 489 | GNUNET_PEERINFO_Processor callback, |
495 | void *callback_cls) | 490 | void *callback_cls) |
496 | { | 491 | { |
497 | struct GNUNET_PEERINFO_IteratorContext *ic; | 492 | struct GNUNET_PEERINFO_IteratorContext *ic; |
498 | 493 | ||
499 | ic = GNUNET_new (struct GNUNET_PEERINFO_IteratorContext); | 494 | ic = GNUNET_new(struct GNUNET_PEERINFO_IteratorContext); |
500 | ic->h = h; | 495 | ic->h = h; |
501 | ic->include_friend_only = include_friend_only; | 496 | ic->include_friend_only = include_friend_only; |
502 | ic->callback = callback; | 497 | ic->callback = callback; |
503 | ic->callback_cls = callback_cls; | 498 | ic->callback_cls = callback_cls; |
504 | if (NULL != peer) | 499 | if (NULL != peer) |
505 | { | 500 | { |
506 | ic->have_peer = GNUNET_YES; | 501 | ic->have_peer = GNUNET_YES; |
507 | ic->peer = *peer; | 502 | ic->peer = *peer; |
508 | } | 503 | } |
509 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, | 504 | GNUNET_CONTAINER_DLL_insert_tail(h->ic_head, |
510 | h->ic_tail, | 505 | h->ic_tail, |
511 | ic); | 506 | ic); |
512 | if (h->ic_head == ic) | 507 | if (h->ic_head == ic) |
513 | send_ic_request (h); | 508 | send_ic_request(h); |
514 | return ic; | 509 | return ic; |
515 | } | 510 | } |
516 | 511 | ||
@@ -521,17 +516,17 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
521 | * @param ic context of the iterator to cancel | 516 | * @param ic context of the iterator to cancel |
522 | */ | 517 | */ |
523 | void | 518 | void |
524 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) | 519 | GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic) |
525 | { | 520 | { |
526 | struct GNUNET_PEERINFO_Handle *h = ic->h; | 521 | struct GNUNET_PEERINFO_Handle *h = ic->h; |
527 | 522 | ||
528 | ic->callback = NULL; | 523 | ic->callback = NULL; |
529 | if (ic == h->ic_head) | 524 | if (ic == h->ic_head) |
530 | return; | 525 | return; |
531 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 526 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
532 | h->ic_tail, | 527 | h->ic_tail, |
533 | ic); | 528 | ic); |
534 | GNUNET_free (ic); | 529 | GNUNET_free(ic); |
535 | } | 530 | } |
536 | 531 | ||
537 | 532 | ||
@@ -554,29 +549,29 @@ GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) | |||
554 | * calling @a cont must be prevented) | 549 | * calling @a cont must be prevented) |
555 | */ | 550 | */ |
556 | struct GNUNET_MQ_Envelope * | 551 | struct GNUNET_MQ_Envelope * |
557 | GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, | 552 | GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, |
558 | const struct GNUNET_HELLO_Message *hello, | 553 | const struct GNUNET_HELLO_Message *hello, |
559 | GNUNET_SCHEDULER_TaskCallback cont, | 554 | GNUNET_SCHEDULER_TaskCallback cont, |
560 | void *cont_cls) | 555 | void *cont_cls) |
561 | { | 556 | { |
562 | struct GNUNET_MQ_Envelope *env; | 557 | struct GNUNET_MQ_Envelope *env; |
563 | struct GNUNET_PeerIdentity peer; | 558 | struct GNUNET_PeerIdentity peer; |
564 | 559 | ||
565 | if (NULL == h->mq) | 560 | if (NULL == h->mq) |
566 | return NULL; | 561 | return NULL; |
567 | GNUNET_assert (GNUNET_OK == | 562 | GNUNET_assert(GNUNET_OK == |
568 | GNUNET_HELLO_get_id (hello, | 563 | GNUNET_HELLO_get_id(hello, |
569 | &peer)); | 564 | &peer)); |
570 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 565 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
571 | "Adding peer `%s' to PEERINFO database\n", | 566 | "Adding peer `%s' to PEERINFO database\n", |
572 | GNUNET_i2s (&peer)); | 567 | GNUNET_i2s(&peer)); |
573 | env = GNUNET_MQ_msg_copy ((const struct GNUNET_MessageHeader *) hello); | 568 | env = GNUNET_MQ_msg_copy((const struct GNUNET_MessageHeader *)hello); |
574 | if (NULL != cont) | 569 | if (NULL != cont) |
575 | GNUNET_MQ_notify_sent (env, | 570 | GNUNET_MQ_notify_sent(env, |
576 | cont, | 571 | cont, |
577 | cont_cls); | 572 | cont_cls); |
578 | GNUNET_MQ_send (h->mq, | 573 | GNUNET_MQ_send(h->mq, |
579 | env); | 574 | env); |
580 | return env; | 575 | return env; |
581 | } | 576 | } |
582 | 577 | ||