aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core_api.c')
-rw-r--r--src/core/core_api.c266
1 files changed, 87 insertions, 179 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 6adaadabf..6381d9097 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
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
@@ -29,7 +29,7 @@
29#include "gnunet_core_service.h" 29#include "gnunet_core_service.h"
30#include "core.h" 30#include "core.h"
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "core-api",__VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "core-api", __VA_ARGS__)
33 33
34 34
35/** 35/**
@@ -69,7 +69,6 @@ struct PeerRecord
69 * SendMessageRequest ID generator for this peer. 69 * SendMessageRequest ID generator for this peer.
70 */ 70 */
71 uint16_t smr_id_gen; 71 uint16_t smr_id_gen;
72
73}; 72};
74 73
75 74
@@ -144,7 +143,6 @@ struct GNUNET_CORE_Handle
144 * Did we ever get INIT? 143 * Did we ever get INIT?
145 */ 144 */
146 int have_init; 145 int have_init;
147
148}; 146};
149 147
150 148
@@ -170,8 +168,7 @@ reconnect_task (void *cls)
170 struct GNUNET_CORE_Handle *h = cls; 168 struct GNUNET_CORE_Handle *h = cls;
171 169
172 h->reconnect_task = NULL; 170 h->reconnect_task = NULL;
173 LOG (GNUNET_ERROR_TYPE_DEBUG, 171 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n");
174 "Connecting to CORE service after delay\n");
175 reconnect (h); 172 reconnect (h);
176} 173}
177 174
@@ -187,7 +184,7 @@ reconnect_task (void *cls)
187 */ 184 */
188static int 185static int
189disconnect_and_free_peer_entry (void *cls, 186disconnect_and_free_peer_entry (void *cls,
190 const struct GNUNET_PeerIdentity *key, 187 const struct GNUNET_PeerIdentity *key,
191 void *value) 188 void *value)
192{ 189{
193 struct GNUNET_CORE_Handle *h = cls; 190 struct GNUNET_CORE_Handle *h = cls;
@@ -195,13 +192,9 @@ disconnect_and_free_peer_entry (void *cls,
195 192
196 GNUNET_assert (pr->h == h); 193 GNUNET_assert (pr->h == h);
197 if (NULL != h->disconnects) 194 if (NULL != h->disconnects)
198 h->disconnects (h->cls, 195 h->disconnects (h->cls, &pr->peer, pr->client_cls);
199 &pr->peer,
200 pr->client_cls);
201 GNUNET_assert (GNUNET_YES == 196 GNUNET_assert (GNUNET_YES ==
202 GNUNET_CONTAINER_multipeermap_remove (h->peers, 197 GNUNET_CONTAINER_multipeermap_remove (h->peers, key, pr));
203 key,
204 pr));
205 GNUNET_MQ_destroy (pr->mq); 198 GNUNET_MQ_destroy (pr->mq);
206 GNUNET_assert (NULL == pr->mq); 199 GNUNET_assert (NULL == pr->mq);
207 if (NULL != pr->env) 200 if (NULL != pr->env)
@@ -231,9 +224,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
231 } 224 }
232 GNUNET_assert (NULL == h->reconnect_task); 225 GNUNET_assert (NULL == h->reconnect_task);
233 h->reconnect_task = 226 h->reconnect_task =
234 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, 227 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_task, h);
235 &reconnect_task,
236 h);
237 GNUNET_CONTAINER_multipeermap_iterate (h->peers, 228 GNUNET_CONTAINER_multipeermap_iterate (h->peers,
238 &disconnect_and_free_peer_entry, 229 &disconnect_and_free_peer_entry,
239 h); 230 h);
@@ -249,39 +240,16 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
249 * @param error error code 240 * @param error error code
250 */ 241 */
251static void 242static void
252handle_mq_error (void *cls, 243handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
253 enum GNUNET_MQ_Error error)
254{ 244{
255 struct GNUNET_CORE_Handle *h = cls; 245 struct GNUNET_CORE_Handle *h = cls;
256 246
257 LOG (GNUNET_ERROR_TYPE_DEBUG, 247 LOG (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %d\n", error);
258 "MQ ERROR: %d\n",
259 error);
260 reconnect_later (h); 248 reconnect_later (h);
261} 249}
262 250
263 251
264/** 252/**
265 * Inquire with CORE what options should be set for a message
266 * so that it is transmitted with the given @a priority and
267 * the given @a cork value.
268 *
269 * @param cork desired corking
270 * @param priority desired message priority
271 * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
272 * @return `extra` argument to give to #GNUNET_MQ_set_options()
273 */
274const void *
275GNUNET_CORE_get_mq_options (int cork,
276 enum GNUNET_CORE_Priority priority,
277 uint64_t *flags)
278{
279 *flags = ((uint64_t) priority) + (((uint64_t) cork) << 32);
280 return NULL;
281}
282
283
284/**
285 * Implement sending functionality of a message queue for 253 * Implement sending functionality of a message queue for
286 * us sending messages to a peer. 254 * us sending messages to a peer.
287 * 255 *
@@ -291,8 +259,8 @@ GNUNET_CORE_get_mq_options (int cork,
291 */ 259 */
292static void 260static void
293core_mq_send_impl (struct GNUNET_MQ_Handle *mq, 261core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
294 const struct GNUNET_MessageHeader *msg, 262 const struct GNUNET_MessageHeader *msg,
295 void *impl_state) 263 void *impl_state)
296{ 264{
297 struct PeerRecord *pr = impl_state; 265 struct PeerRecord *pr = impl_state;
298 struct GNUNET_CORE_Handle *h = pr->h; 266 struct GNUNET_CORE_Handle *h = pr->h;
@@ -300,9 +268,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
300 struct SendMessage *sm; 268 struct SendMessage *sm;
301 struct GNUNET_MQ_Envelope *env; 269 struct GNUNET_MQ_Envelope *env;
302 uint16_t msize; 270 uint16_t msize;
303 uint64_t flags; 271 enum GNUNET_MQ_PriorityPreferences flags;
304 int cork;
305 enum GNUNET_CORE_Priority priority;
306 272
307 if (NULL == h->mq) 273 if (NULL == h->mq)
308 { 274 {
@@ -313,11 +279,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
313 GNUNET_assert (NULL == pr->env); 279 GNUNET_assert (NULL == pr->env);
314 /* extract options from envelope */ 280 /* extract options from envelope */
315 env = GNUNET_MQ_get_current_envelope (mq); 281 env = GNUNET_MQ_get_current_envelope (mq);
316 GNUNET_break (NULL == 282 flags = GNUNET_MQ_env_get_options (env);
317 GNUNET_MQ_env_get_options (env,
318 &flags));
319 cork = (int) (flags >> 32);
320 priority = (uint32_t) flags;
321 283
322 /* check message size for sanity */ 284 /* check message size for sanity */
323 msize = ntohs (msg->size); 285 msize = ntohs (msg->size);
@@ -333,28 +295,20 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
333 "Asking core for transmission of %u bytes to `%s'\n", 295 "Asking core for transmission of %u bytes to `%s'\n",
334 (unsigned int) msize, 296 (unsigned int) msize,
335 GNUNET_i2s (&pr->peer)); 297 GNUNET_i2s (&pr->peer));
336 env = GNUNET_MQ_msg (smr, 298 env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
337 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST); 299 smr->priority = htonl ((uint32_t) flags);
338 smr->priority = htonl ((uint32_t) priority);
339 smr->peer = pr->peer; 300 smr->peer = pr->peer;
340 smr->reserved = htonl (0);
341 smr->size = htons (msize); 301 smr->size = htons (msize);
342 smr->smr_id = htons (++pr->smr_id_gen); 302 smr->smr_id = htons (++pr->smr_id_gen);
343 GNUNET_MQ_send (h->mq, 303 GNUNET_MQ_send (h->mq, env);
344 env);
345 304
346 /* prepare message with actual transmission data */ 305 /* prepare message with actual transmission data */
347 pr->env = GNUNET_MQ_msg_nested_mh (sm, 306 pr->env = GNUNET_MQ_msg_nested_mh (sm, GNUNET_MESSAGE_TYPE_CORE_SEND, msg);
348 GNUNET_MESSAGE_TYPE_CORE_SEND, 307 sm->priority = htonl ((uint32_t) flags);
349 msg);
350 sm->priority = htonl ((uint32_t) priority);
351 sm->peer = pr->peer; 308 sm->peer = pr->peer;
352 sm->cork = htonl ((uint32_t) cork);
353 sm->reserved = htonl (0);
354 LOG (GNUNET_ERROR_TYPE_DEBUG, 309 LOG (GNUNET_ERROR_TYPE_DEBUG,
355 "Calling get_message with buffer of %u bytes (%s)\n", 310 "Calling get_message with buffer of %u bytes\n",
356 (unsigned int) msize, 311 (unsigned int) msize);
357 cork ? "corked" : "uncorked");
358} 312}
359 313
360 314
@@ -366,8 +320,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
366 * @param impl_state state of the implementation 320 * @param impl_state state of the implementation
367 */ 321 */
368static void 322static void
369core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, 323core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
370 void *impl_state)
371{ 324{
372 struct PeerRecord *pr = impl_state; 325 struct PeerRecord *pr = impl_state;
373 326
@@ -384,8 +337,7 @@ core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq,
384 * @param impl_state state specific to the implementation 337 * @param impl_state state specific to the implementation
385 */ 338 */
386static void 339static void
387core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, 340core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
388 void *impl_state)
389{ 341{
390 struct PeerRecord *pr = impl_state; 342 struct PeerRecord *pr = impl_state;
391 343
@@ -404,8 +356,7 @@ core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq,
404 * @param error error code 356 * @param error error code
405 */ 357 */
406static void 358static void
407core_mq_error_handler (void *cls, 359core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
408 enum GNUNET_MQ_Error error)
409{ 360{
410 /* struct PeerRecord *pr = cls; */ 361 /* struct PeerRecord *pr = cls; */
411 362
@@ -423,41 +374,30 @@ core_mq_error_handler (void *cls,
423 */ 374 */
424static void 375static void
425connect_peer (struct GNUNET_CORE_Handle *h, 376connect_peer (struct GNUNET_CORE_Handle *h,
426 const struct GNUNET_PeerIdentity *peer) 377 const struct GNUNET_PeerIdentity *peer)
427{ 378{
428 struct PeerRecord *pr; 379 struct PeerRecord *pr;
429 uint64_t flags;
430 const void *extra;
431 380
432 pr = GNUNET_new (struct PeerRecord); 381 pr = GNUNET_new (struct PeerRecord);
433 pr->peer = *peer; 382 pr->peer = *peer;
434 pr->h = h; 383 pr->h = h;
435 GNUNET_assert (GNUNET_YES == 384 GNUNET_assert (GNUNET_YES ==
436 GNUNET_CONTAINER_multipeermap_put (h->peers, 385 GNUNET_CONTAINER_multipeermap_put (
437 &pr->peer, 386 h->peers,
438 pr, 387 &pr->peer,
439 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 388 pr,
389 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
440 pr->mq = GNUNET_MQ_queue_for_callbacks (&core_mq_send_impl, 390 pr->mq = GNUNET_MQ_queue_for_callbacks (&core_mq_send_impl,
441 &core_mq_destroy_impl, 391 &core_mq_destroy_impl,
442 &core_mq_cancel_impl, 392 &core_mq_cancel_impl,
443 pr, 393 pr,
444 h->handlers, 394 h->handlers,
445 &core_mq_error_handler, 395 &core_mq_error_handler,
446 pr); 396 pr);
447 /* get our default options */
448 extra = GNUNET_CORE_get_mq_options (GNUNET_NO,
449 GNUNET_CORE_PRIO_BEST_EFFORT,
450 &flags);
451 GNUNET_MQ_set_options (pr->mq,
452 flags,
453 extra);
454 if (NULL != h->connects) 397 if (NULL != h->connects)
455 { 398 {
456 pr->client_cls = h->connects (h->cls, 399 pr->client_cls = h->connects (h->cls, &pr->peer, pr->mq);
457 &pr->peer, 400 GNUNET_MQ_set_handlers_closure (pr->mq, pr->client_cls);
458 pr->mq);
459 GNUNET_MQ_set_handlers_closure (pr->mq,
460 pr->client_cls);
461 } 401 }
462} 402}
463 403
@@ -471,8 +411,7 @@ connect_peer (struct GNUNET_CORE_Handle *h,
471 * @param m the init reply 411 * @param m the init reply
472 */ 412 */
473static void 413static void
474handle_init_reply (void *cls, 414handle_init_reply (void *cls, const struct InitReplyMessage *m)
475 const struct InitReplyMessage *m)
476{ 415{
477 struct GNUNET_CORE_Handle *h = cls; 416 struct GNUNET_CORE_Handle *h = cls;
478 GNUNET_CORE_StartupCallback init; 417 GNUNET_CORE_StartupCallback init;
@@ -488,8 +427,7 @@ handle_init_reply (void *cls,
488 "Connected to core service of peer `%s'.\n", 427 "Connected to core service of peer `%s'.\n",
489 GNUNET_i2s (&h->me)); 428 GNUNET_i2s (&h->me));
490 h->have_init = GNUNET_YES; 429 h->have_init = GNUNET_YES;
491 init (h->cls, 430 init (h->cls, &h->me);
492 &h->me);
493 } 431 }
494 else 432 else
495 { 433 {
@@ -508,8 +446,7 @@ handle_init_reply (void *cls,
508 } 446 }
509 } 447 }
510 /* fake 'connect to self' */ 448 /* fake 'connect to self' */
511 connect_peer (h, 449 connect_peer (h, &h->me);
512 &h->me);
513} 450}
514 451
515 452
@@ -521,8 +458,7 @@ handle_init_reply (void *cls,
521 * @param cnm the connect message 458 * @param cnm the connect message
522 */ 459 */
523static void 460static void
524handle_connect_notify (void *cls, 461handle_connect_notify (void *cls, const struct ConnectNotifyMessage *cnm)
525 const struct ConnectNotifyMessage *cnm)
526{ 462{
527 struct GNUNET_CORE_Handle *h = cls; 463 struct GNUNET_CORE_Handle *h = cls;
528 struct PeerRecord *pr; 464 struct PeerRecord *pr;
@@ -530,24 +466,20 @@ handle_connect_notify (void *cls,
530 LOG (GNUNET_ERROR_TYPE_DEBUG, 466 LOG (GNUNET_ERROR_TYPE_DEBUG,
531 "Received notification about connection from `%s'.\n", 467 "Received notification about connection from `%s'.\n",
532 GNUNET_i2s (&cnm->peer)); 468 GNUNET_i2s (&cnm->peer));
533 if (0 == memcmp (&h->me, 469 if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity)))
534 &cnm->peer,
535 sizeof (struct GNUNET_PeerIdentity)))
536 { 470 {
537 /* connect to self!? */ 471 /* connect to self!? */
538 GNUNET_break (0); 472 GNUNET_break (0);
539 return; 473 return;
540 } 474 }
541 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 475 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &cnm->peer);
542 &cnm->peer);
543 if (NULL != pr) 476 if (NULL != pr)
544 { 477 {
545 GNUNET_break (0); 478 GNUNET_break (0);
546 reconnect_later (h); 479 reconnect_later (h);
547 return; 480 return;
548 } 481 }
549 connect_peer (h, 482 connect_peer (h, &cnm->peer);
550 &cnm->peer);
551} 483}
552 484
553 485
@@ -559,15 +491,12 @@ handle_connect_notify (void *cls,
559 * @param dnm message about the disconnect event 491 * @param dnm message about the disconnect event
560 */ 492 */
561static void 493static void
562handle_disconnect_notify (void *cls, 494handle_disconnect_notify (void *cls, const struct DisconnectNotifyMessage *dnm)
563 const struct DisconnectNotifyMessage *dnm)
564{ 495{
565 struct GNUNET_CORE_Handle *h = cls; 496 struct GNUNET_CORE_Handle *h = cls;
566 struct PeerRecord *pr; 497 struct PeerRecord *pr;
567 498
568 if (0 == memcmp (&h->me, 499 if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity)))
569 &dnm->peer,
570 sizeof (struct GNUNET_PeerIdentity)))
571 { 500 {
572 /* disconnect from self!? */ 501 /* disconnect from self!? */
573 GNUNET_break (0); 502 GNUNET_break (0);
@@ -577,17 +506,14 @@ handle_disconnect_notify (void *cls,
577 LOG (GNUNET_ERROR_TYPE_DEBUG, 506 LOG (GNUNET_ERROR_TYPE_DEBUG,
578 "Received notification about disconnect from `%s'.\n", 507 "Received notification about disconnect from `%s'.\n",
579 GNUNET_i2s (&dnm->peer)); 508 GNUNET_i2s (&dnm->peer));
580 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 509 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &dnm->peer);
581 &dnm->peer);
582 if (NULL == pr) 510 if (NULL == pr)
583 { 511 {
584 GNUNET_break (0); 512 GNUNET_break (0);
585 reconnect_later (h); 513 reconnect_later (h);
586 return; 514 return;
587 } 515 }
588 disconnect_and_free_peer_entry (h, 516 disconnect_and_free_peer_entry (h, &pr->peer, pr);
589 &pr->peer,
590 pr);
591} 517}
592 518
593 519
@@ -599,8 +525,7 @@ handle_disconnect_notify (void *cls,
599 * @return #GNUNET_OK if the message is well-formed 525 * @return #GNUNET_OK if the message is well-formed
600 */ 526 */
601static int 527static int
602check_notify_inbound (void *cls, 528check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
603 const struct NotifyTrafficMessage *ntm)
604{ 529{
605 uint16_t msize; 530 uint16_t msize;
606 const struct GNUNET_MessageHeader *em; 531 const struct GNUNET_MessageHeader *em;
@@ -629,8 +554,7 @@ check_notify_inbound (void *cls,
629 * @param ntm the message we got from CORE. 554 * @param ntm the message we got from CORE.
630 */ 555 */
631static void 556static void
632handle_notify_inbound (void *cls, 557handle_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
633 const struct NotifyTrafficMessage *ntm)
634{ 558{
635 struct GNUNET_CORE_Handle *h = cls; 559 struct GNUNET_CORE_Handle *h = cls;
636 const struct GNUNET_MessageHeader *em; 560 const struct GNUNET_MessageHeader *em;
@@ -640,16 +564,14 @@ handle_notify_inbound (void *cls,
640 "Received inbound message from `%s'.\n", 564 "Received inbound message from `%s'.\n",
641 GNUNET_i2s (&ntm->peer)); 565 GNUNET_i2s (&ntm->peer));
642 em = (const struct GNUNET_MessageHeader *) &ntm[1]; 566 em = (const struct GNUNET_MessageHeader *) &ntm[1];
643 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 567 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &ntm->peer);
644 &ntm->peer);
645 if (NULL == pr) 568 if (NULL == pr)
646 { 569 {
647 GNUNET_break (0); 570 GNUNET_break (0);
648 reconnect_later (h); 571 reconnect_later (h);
649 return; 572 return;
650 } 573 }
651 GNUNET_MQ_inject_message (pr->mq, 574 GNUNET_MQ_inject_message (pr->mq, em);
652 em);
653} 575}
654 576
655 577
@@ -662,14 +584,12 @@ handle_notify_inbound (void *cls,
662 * @param smr the message we got 584 * @param smr the message we got
663 */ 585 */
664static void 586static void
665handle_send_ready (void *cls, 587handle_send_ready (void *cls, const struct SendMessageReady *smr)
666 const struct SendMessageReady *smr)
667{ 588{
668 struct GNUNET_CORE_Handle *h = cls; 589 struct GNUNET_CORE_Handle *h = cls;
669 struct PeerRecord *pr; 590 struct PeerRecord *pr;
670 591
671 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 592 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &smr->peer);
672 &smr->peer);
673 if (NULL == pr) 593 if (NULL == pr)
674 { 594 {
675 GNUNET_break (0); 595 GNUNET_break (0);
@@ -693,8 +613,7 @@ handle_send_ready (void *cls,
693 } 613 }
694 614
695 /* ok, all good, send message out! */ 615 /* ok, all good, send message out! */
696 GNUNET_MQ_send (h->mq, 616 GNUNET_MQ_send (h->mq, pr->env);
697 pr->env);
698 pr->env = NULL; 617 pr->env = NULL;
699 GNUNET_MQ_impl_send_continue (pr->mq); 618 GNUNET_MQ_impl_send_continue (pr->mq);
700} 619}
@@ -709,39 +628,34 @@ handle_send_ready (void *cls,
709static void 628static void
710reconnect (struct GNUNET_CORE_Handle *h) 629reconnect (struct GNUNET_CORE_Handle *h)
711{ 630{
712 struct GNUNET_MQ_MessageHandler handlers[] = { 631 struct GNUNET_MQ_MessageHandler handlers[] =
713 GNUNET_MQ_hd_fixed_size (init_reply, 632 {GNUNET_MQ_hd_fixed_size (init_reply,
714 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY, 633 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY,
715 struct InitReplyMessage, 634 struct InitReplyMessage,
716 h), 635 h),
717 GNUNET_MQ_hd_fixed_size (connect_notify, 636 GNUNET_MQ_hd_fixed_size (connect_notify,
718 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT, 637 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT,
719 struct ConnectNotifyMessage, 638 struct ConnectNotifyMessage,
720 h), 639 h),
721 GNUNET_MQ_hd_fixed_size (disconnect_notify, 640 GNUNET_MQ_hd_fixed_size (disconnect_notify,
722 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT, 641 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT,
723 struct DisconnectNotifyMessage, 642 struct DisconnectNotifyMessage,
724 h), 643 h),
725 GNUNET_MQ_hd_var_size (notify_inbound, 644 GNUNET_MQ_hd_var_size (notify_inbound,
726 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND, 645 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND,
727 struct NotifyTrafficMessage, 646 struct NotifyTrafficMessage,
728 h), 647 h),
729 GNUNET_MQ_hd_fixed_size (send_ready, 648 GNUNET_MQ_hd_fixed_size (send_ready,
730 GNUNET_MESSAGE_TYPE_CORE_SEND_READY, 649 GNUNET_MESSAGE_TYPE_CORE_SEND_READY,
731 struct SendMessageReady, 650 struct SendMessageReady,
732 h), 651 h),
733 GNUNET_MQ_handler_end () 652 GNUNET_MQ_handler_end ()};
734 };
735 struct InitMessage *init; 653 struct InitMessage *init;
736 struct GNUNET_MQ_Envelope *env; 654 struct GNUNET_MQ_Envelope *env;
737 uint16_t *ts; 655 uint16_t *ts;
738 656
739 GNUNET_assert (NULL == h->mq); 657 GNUNET_assert (NULL == h->mq);
740 h->mq = GNUNET_CLIENT_connect (h->cfg, 658 h->mq = GNUNET_CLIENT_connect (h->cfg, "core", handlers, &handle_mq_error, h);
741 "core",
742 handlers,
743 &handle_mq_error,
744 h);
745 if (NULL == h->mq) 659 if (NULL == h->mq)
746 { 660 {
747 reconnect_later (h); 661 reconnect_later (h);
@@ -750,14 +664,12 @@ reconnect (struct GNUNET_CORE_Handle *h)
750 env = GNUNET_MQ_msg_extra (init, 664 env = GNUNET_MQ_msg_extra (init,
751 sizeof (uint16_t) * h->hcnt, 665 sizeof (uint16_t) * h->hcnt,
752 GNUNET_MESSAGE_TYPE_CORE_INIT); 666 GNUNET_MESSAGE_TYPE_CORE_INIT);
753 LOG (GNUNET_ERROR_TYPE_INFO, 667 LOG (GNUNET_ERROR_TYPE_INFO, "(Re)connecting to CORE service\n");
754 "(Re)connecting to CORE service\n");
755 init->options = htonl (0); 668 init->options = htonl (0);
756 ts = (uint16_t *) &init[1]; 669 ts = (uint16_t *) &init[1];
757 for (unsigned int hpos = 0; hpos < h->hcnt; hpos++) 670 for (unsigned int hpos = 0; hpos < h->hcnt; hpos++)
758 ts[hpos] = htons (h->handlers[hpos].type); 671 ts[hpos] = htons (h->handlers[hpos].type);
759 GNUNET_MQ_send (h->mq, 672 GNUNET_MQ_send (h->mq, env);
760 env);
761} 673}
762 674
763 675
@@ -791,15 +703,13 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
791 h->init = init; 703 h->init = init;
792 h->connects = connects; 704 h->connects = connects;
793 h->disconnects = disconnects; 705 h->disconnects = disconnects;
794 h->peers = GNUNET_CONTAINER_multipeermap_create (128, 706 h->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
795 GNUNET_NO);
796 h->handlers = GNUNET_MQ_copy_handlers (handlers); 707 h->handlers = GNUNET_MQ_copy_handlers (handlers);
797 h->hcnt = GNUNET_MQ_count_handlers (handlers); 708 h->hcnt = GNUNET_MQ_count_handlers (handlers);
798 GNUNET_assert (h->hcnt < 709 GNUNET_assert (h->hcnt <
799 (GNUNET_MAX_MESSAGE_SIZE - 710 (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InitMessage)) /
800 sizeof (struct InitMessage)) / sizeof (uint16_t)); 711 sizeof (uint16_t));
801 LOG (GNUNET_ERROR_TYPE_DEBUG, 712 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
802 "Connecting to CORE service\n");
803 reconnect (h); 713 reconnect (h);
804 if (NULL == h->mq) 714 if (NULL == h->mq)
805 { 715 {
@@ -818,8 +728,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
818void 728void
819GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) 729GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
820{ 730{
821 LOG (GNUNET_ERROR_TYPE_DEBUG, 731 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
822 "Disconnecting from CORE service\n");
823 GNUNET_CONTAINER_multipeermap_iterate (handle->peers, 732 GNUNET_CONTAINER_multipeermap_iterate (handle->peers,
824 &disconnect_and_free_peer_entry, 733 &disconnect_and_free_peer_entry,
825 handle); 734 handle);
@@ -849,12 +758,11 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
849 */ 758 */
850struct GNUNET_MQ_Handle * 759struct GNUNET_MQ_Handle *
851GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h, 760GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
852 const struct GNUNET_PeerIdentity *pid) 761 const struct GNUNET_PeerIdentity *pid)
853{ 762{
854 struct PeerRecord *pr; 763 struct PeerRecord *pr;
855 764
856 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 765 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, pid);
857 pid);
858 if (NULL == pr) 766 if (NULL == pr)
859 return NULL; 767 return NULL;
860 return pr->mq; 768 return pr->mq;