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