aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_core.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-08 17:50:41 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-08 17:50:41 +0000
commit08991f1a09f52270f51014edb6288a6799dbf05f (patch)
tree0980261e6daca93c1247999a089b59e3733c7b5c /src/transport/transport_api_core.c
parent55c53daf9f9afa97fa848baaab5ef38ce4716a8a (diff)
downloadgnunet-08991f1a09f52270f51014edb6288a6799dbf05f.tar.gz
gnunet-08991f1a09f52270f51014edb6288a6799dbf05f.zip
get transport_api_core to compile
Diffstat (limited to 'src/transport/transport_api_core.c')
-rw-r--r--src/transport/transport_api_core.c118
1 files changed, 60 insertions, 58 deletions
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c
index de18b7339..499aa96f6 100644
--- a/src/transport/transport_api_core.c
+++ b/src/transport/transport_api_core.c
@@ -121,7 +121,7 @@ struct Neighbour
121 * Handle for the transport service (includes all of the 121 * Handle for the transport service (includes all of the
122 * state for the transport service). 122 * state for the transport service).
123 */ 123 */
124struct GNUNET_TRANSPORT_Handle 124struct GNUNET_TRANSPORT_CoreHandle
125{ 125{
126 126
127 /** 127 /**
@@ -191,23 +191,13 @@ struct GNUNET_TRANSPORT_Handle
191 191
192 192
193/** 193/**
194 * Schedule the task to send one message, either from the control
195 * list or the peer message queues to the service.
196 *
197 * @param h transport service to schedule a transmission for
198 */
199static void
200schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
201
202
203/**
204 * Function that will schedule the job that will try 194 * Function that will schedule the job that will try
205 * to connect us again to the client. 195 * to connect us again to the client.
206 * 196 *
207 * @param h transport service to reconnect 197 * @param h transport service to reconnect
208 */ 198 */
209static void 199static void
210disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h); 200disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h);
211 201
212 202
213/** 203/**
@@ -218,7 +208,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h);
218 * @return NULL if no such peer entry exists 208 * @return NULL if no such peer entry exists
219 */ 209 */
220static struct Neighbour * 210static struct Neighbour *
221neighbour_find (struct GNUNET_TRANSPORT_Handle *h, 211neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h,
222 const struct GNUNET_PeerIdentity *peer) 212 const struct GNUNET_PeerIdentity *peer)
223{ 213{
224 return GNUNET_CONTAINER_multipeermap_get (h->neighbours, 214 return GNUNET_CONTAINER_multipeermap_get (h->neighbours,
@@ -236,18 +226,19 @@ static void
236notify_excess_cb (void *cls) 226notify_excess_cb (void *cls)
237{ 227{
238 struct Neighbour *n = cls; 228 struct Neighbour *n = cls;
239 struct GNUNET_TRANSPORT_Handle *h = n->h; 229 struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
240 230
241 if (NULL != h->neb_cb) 231 if (NULL != h->neb_cb)
242 h->neb_cb (h->cls, 232 h->neb_cb (h->cls,
243 &n->id); 233 &n->id,
234 n->handlers_cls);
244} 235}
245 236
246 237
247/** 238/**
248 * Iterator over hash map entries, for deleting state of a neighbour. 239 * Iterator over hash map entries, for deleting state of a neighbour.
249 * 240 *
250 * @param cls the `struct GNUNET_TRANSPORT_Handle *` 241 * @param cls the `struct GNUNET_TRANSPORT_CoreHandle *`
251 * @param key peer identity 242 * @param key peer identity
252 * @param value value in the hash map, the neighbour entry to delete 243 * @param value value in the hash map, the neighbour entry to delete
253 * @return #GNUNET_YES if we should continue to 244 * @return #GNUNET_YES if we should continue to
@@ -259,7 +250,7 @@ neighbour_delete (void *cls,
259 const struct GNUNET_PeerIdentity *key, 250 const struct GNUNET_PeerIdentity *key,
260 void *value) 251 void *value)
261{ 252{
262 struct GNUNET_TRANSPORT_Handle *handle = cls; 253 struct GNUNET_TRANSPORT_CoreHandle *handle = cls;
263 struct Neighbour *n = value; 254 struct Neighbour *n = value;
264 255
265 LOG (GNUNET_ERROR_TYPE_DEBUG, 256 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -297,14 +288,14 @@ neighbour_delete (void *cls,
297 * the message queue. 288 * the message queue.
298 * Not every message queue implementation supports an error handler. 289 * Not every message queue implementation supports an error handler.
299 * 290 *
300 * @param cls closure with the `struct GNUNET_TRANSPORT_Handle *` 291 * @param cls closure with the `struct GNUNET_TRANSPORT_CoreHandle *`
301 * @param error error code 292 * @param error error code
302 */ 293 */
303static void 294static void
304mq_error_handler (void *cls, 295mq_error_handler (void *cls,
305 enum GNUNET_MQ_Error error) 296 enum GNUNET_MQ_Error error)
306{ 297{
307 struct GNUNET_TRANSPORT_Handle *h = cls; 298 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
308 299
309 LOG (GNUNET_ERROR_TYPE_DEBUG, 300 LOG (GNUNET_ERROR_TYPE_DEBUG,
310 "Error receiving from transport service, disconnecting temporarily.\n"); 301 "Error receiving from transport service, disconnecting temporarily.\n");
@@ -315,7 +306,7 @@ mq_error_handler (void *cls,
315/** 306/**
316 * Function we use for checking incoming HELLO messages. 307 * Function we use for checking incoming HELLO messages.
317 * 308 *
318 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 309 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
319 * @param msg message received 310 * @param msg message received
320 * @return #GNUNET_OK if message is well-formed 311 * @return #GNUNET_OK if message is well-formed
321 */ 312 */
@@ -339,7 +330,7 @@ check_hello (void *cls,
339/** 330/**
340 * Function we use for handling incoming HELLO messages. 331 * Function we use for handling incoming HELLO messages.
341 * 332 *
342 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 333 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
343 * @param msg message received 334 * @param msg message received
344 */ 335 */
345static void 336static void
@@ -365,7 +356,7 @@ notify_send_done (void *cls)
365 struct GNUNET_TIME_Relative delay; 356 struct GNUNET_TIME_Relative delay;
366 357
367 n->timeout_task = NULL; 358 n->timeout_task = NULL;
368 if (NULL != env) 359 if (NULL != n->env)
369 { 360 {
370 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, 361 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker,
371 n->env_size + n->traffic_overhead); 362 n->env_size + n->traffic_overhead);
@@ -377,12 +368,13 @@ notify_send_done (void *cls)
377 if (0 == delay.rel_value_us) 368 if (0 == delay.rel_value_us)
378 { 369 {
379 n->is_ready = GNUNET_YES; 370 n->is_ready = GNUNET_YES;
380 GNUNET_MQ_impl_send_continue (mq); 371 GNUNET_MQ_impl_send_continue (n->mq);
381 return; 372 return;
382 } 373 }
383 /* cannot send even a small message without violating 374 /* cannot send even a small message without violating
384 quota, wait a before notifying MQ */ 375 quota, wait a before notifying MQ */
385 n->timeout_task = GNUNET_SCHEDULER_add_delayed (&notify_send_done, 376 n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
377 &notify_send_done,
386 n); 378 n);
387} 379}
388 380
@@ -405,7 +397,6 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
405 struct Neighbour *n = impl_state; 397 struct Neighbour *n = impl_state;
406 struct GNUNET_TRANSPORT_CoreHandle *h = n->h; 398 struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
407 struct OutboundMessage *obm; 399 struct OutboundMessage *obm;
408 struct GNUNET_MQ_Envelope *env;
409 uint16_t msize; 400 uint16_t msize;
410 401
411 GNUNET_assert (GNUNET_YES == n->is_ready); 402 GNUNET_assert (GNUNET_YES == n->is_ready);
@@ -420,18 +411,16 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
420 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 411 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
421 msg); 412 msg);
422 obm->reserved = htonl (0); 413 obm->reserved = htonl (0);
423 obm->timeout = 414 obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME: to be removed */
424 GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
425 (th->timeout));
426 obm->peer = n->id; 415 obm->peer = n->id;
427 GNUNET_assert (NULL == n->timeout_task); 416 GNUNET_assert (NULL == n->timeout_task);
428 n->is_ready = GNUNET_NO; 417 n->is_ready = GNUNET_NO;
429 n->env_size = ntohs (msg->size); 418 n->env_size = ntohs (msg->size);
430 GNUNET_MQ_notify_sent (env, 419 GNUNET_MQ_notify_sent (n->env,
431 &notify_send_done, 420 &notify_send_done,
432 n); 421 n);
433 GNUNET_MQ_send (h->mq, 422 GNUNET_MQ_send (h->mq,
434 env); 423 n->env);
435} 424}
436 425
437 426
@@ -489,13 +478,36 @@ static void
489peer_mq_error_handler (void *cls, 478peer_mq_error_handler (void *cls,
490 enum GNUNET_MQ_Error error) 479 enum GNUNET_MQ_Error error)
491{ 480{
492 struct Neighbour *n = cls; 481 /* struct Neighbour *n = cls; */
493 482
494 GNUNET_break_op (0); 483 GNUNET_break_op (0);
495} 484}
496 485
497 486
498/** 487/**
488 * The outbound quota has changed in a way that may require
489 * us to reset the timeout. Update the timeout.
490 *
491 * @param cls the `struct Neighbour` for which the timeout changed
492 */
493static void
494outbound_bw_tracker_update (void *cls)
495{
496 struct Neighbour *n = cls;
497 struct GNUNET_TIME_Relative delay;
498
499 if (NULL == n->timeout_task)
500 return;
501 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
502 128);
503 GNUNET_SCHEDULER_cancel (n->timeout_task);
504 n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
505 &notify_send_done,
506 n);
507}
508
509
510/**
499 * Function we use for handling incoming connect messages. 511 * Function we use for handling incoming connect messages.
500 * 512 *
501 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 513 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *`
@@ -505,7 +517,7 @@ static void
505handle_connect (void *cls, 517handle_connect (void *cls,
506 const struct ConnectInfoMessage *cim) 518 const struct ConnectInfoMessage *cim)
507{ 519{
508 struct GNUNET_TRANSPORT_Handle *h = cls; 520 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
509 struct Neighbour *n; 521 struct Neighbour *n;
510 522
511 LOG (GNUNET_ERROR_TYPE_DEBUG, 523 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -560,14 +572,14 @@ handle_connect (void *cls,
560/** 572/**
561 * Function we use for handling incoming disconnect messages. 573 * Function we use for handling incoming disconnect messages.
562 * 574 *
563 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 575 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
564 * @param dim message received 576 * @param dim message received
565 */ 577 */
566static void 578static void
567handle_disconnect (void *cls, 579handle_disconnect (void *cls,
568 const struct DisconnectInfoMessage *dim) 580 const struct DisconnectInfoMessage *dim)
569{ 581{
570 struct GNUNET_TRANSPORT_Handle *h = cls; 582 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
571 struct Neighbour *n; 583 struct Neighbour *n;
572 584
573 GNUNET_break (ntohl (dim->reserved) == 0); 585 GNUNET_break (ntohl (dim->reserved) == 0);
@@ -591,14 +603,14 @@ handle_disconnect (void *cls,
591/** 603/**
592 * Function we use for handling incoming send-ok messages. 604 * Function we use for handling incoming send-ok messages.
593 * 605 *
594 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 606 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
595 * @param okm message received 607 * @param okm message received
596 */ 608 */
597static void 609static void
598handle_send_ok (void *cls, 610handle_send_ok (void *cls,
599 const struct SendOkMessage *okm) 611 const struct SendOkMessage *okm)
600{ 612{
601 struct GNUNET_TRANSPORT_Handle *h = cls; 613 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
602 struct Neighbour *n; 614 struct Neighbour *n;
603 uint32_t bytes_msg; 615 uint32_t bytes_msg;
604 uint32_t bytes_physical; 616 uint32_t bytes_physical;
@@ -633,7 +645,7 @@ handle_send_ok (void *cls,
633/** 645/**
634 * Function we use for checking incoming "inbound" messages. 646 * Function we use for checking incoming "inbound" messages.
635 * 647 *
636 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 648 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
637 * @param im message received 649 * @param im message received
638 */ 650 */
639static int 651static int
@@ -663,14 +675,14 @@ check_recv (void *cls,
663/** 675/**
664 * Function we use for handling incoming messages. 676 * Function we use for handling incoming messages.
665 * 677 *
666 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 678 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
667 * @param im message received 679 * @param im message received
668 */ 680 */
669static void 681static void
670handle_recv (void *cls, 682handle_recv (void *cls,
671 const struct InboundMessage *im) 683 const struct InboundMessage *im)
672{ 684{
673 struct GNUNET_TRANSPORT_Handle *h = cls; 685 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
674 const struct GNUNET_MessageHeader *imm 686 const struct GNUNET_MessageHeader *imm
675 = (const struct GNUNET_MessageHeader *) &im[1]; 687 = (const struct GNUNET_MessageHeader *) &im[1];
676 struct Neighbour *n; 688 struct Neighbour *n;
@@ -695,14 +707,14 @@ handle_recv (void *cls,
695/** 707/**
696 * Function we use for handling incoming set quota messages. 708 * Function we use for handling incoming set quota messages.
697 * 709 *
698 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` 710 * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *`
699 * @param msg message received 711 * @param msg message received
700 */ 712 */
701static void 713static void
702handle_set_quota (void *cls, 714handle_set_quota (void *cls,
703 const struct QuotaSetMessage *qm) 715 const struct QuotaSetMessage *qm)
704{ 716{
705 struct GNUNET_TRANSPORT_Handle *h = cls; 717 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
706 struct Neighbour *n; 718 struct Neighbour *n;
707 719
708 n = neighbour_find (h, &qm->peer); 720 n = neighbour_find (h, &qm->peer);
@@ -747,7 +759,7 @@ reconnect (void *cls)
747 GNUNET_MQ_hd_fixed_size (set_quota, 759 GNUNET_MQ_hd_fixed_size (set_quota,
748 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, 760 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA,
749 struct QuotaSetMessage); 761 struct QuotaSetMessage);
750 struct GNUNET_TRANSPORT_Handle *h = cls; 762 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
751 struct GNUNET_MQ_MessageHandler handlers[] = { 763 struct GNUNET_MQ_MessageHandler handlers[] = {
752 make_hello_handler (h), 764 make_hello_handler (h),
753 make_connect_handler (h), 765 make_connect_handler (h),
@@ -777,7 +789,7 @@ reconnect (void *cls)
777 options = 0; 789 options = 0;
778 if (h->check_self) 790 if (h->check_self)
779 options |= 1; 791 options |= 1;
780 if (NULL != h->rec) 792 if (NULL != h->handlers)
781 options |= 2; 793 options |= 2;
782 s->options = htonl (options); 794 s->options = htonl (options);
783 s->self = h->self; 795 s->self = h->self;
@@ -793,7 +805,7 @@ reconnect (void *cls)
793 * @param h transport service to reconnect 805 * @param h transport service to reconnect
794 */ 806 */
795static void 807static void
796disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) 808disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
797{ 809{
798 GNUNET_assert (NULL == h->reconnect_task); 810 GNUNET_assert (NULL == h->reconnect_task);
799 if (NULL != h->mq) 811 if (NULL != h->mq)
@@ -805,11 +817,6 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
805 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, 817 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours,
806 &neighbour_delete, 818 &neighbour_delete,
807 h); 819 h);
808 if (NULL != h->quota_task)
809 {
810 GNUNET_SCHEDULER_cancel (h->quota_task);
811 h->quota_task = NULL;
812 }
813 LOG (GNUNET_ERROR_TYPE_DEBUG, 820 LOG (GNUNET_ERROR_TYPE_DEBUG,
814 "Scheduling task to reconnect to transport service in %s.\n", 821 "Scheduling task to reconnect to transport service in %s.\n",
815 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, 822 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
@@ -830,7 +837,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
830 * @return NULL if disconnected, otherwise message queue for @a peer 837 * @return NULL if disconnected, otherwise message queue for @a peer
831 */ 838 */
832struct GNUNET_MQ_Handle * 839struct GNUNET_MQ_Handle *
833GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_Handle *handle, 840GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
834 const struct GNUNET_PeerIdentity *peer) 841 const struct GNUNET_PeerIdentity *peer)
835{ 842{
836 struct Neighbour *n; 843 struct Neighbour *n;
@@ -862,9 +869,9 @@ GNUNET_TRANSPORT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
862 const struct GNUNET_PeerIdentity *self, 869 const struct GNUNET_PeerIdentity *self,
863 const struct GNUNET_MQ_MessageHandler *handlers, 870 const struct GNUNET_MQ_MessageHandler *handlers,
864 void *cls, 871 void *cls,
865 GNUNET_TRANSPORT_NotifyConnect nc, 872 GNUNET_TRANSPORT_NotifyConnecT nc,
866 GNUNET_TRANSPORT_NotifyDisconnect nd, 873 GNUNET_TRANSPORT_NotifyDisconnecT nd,
867 GNUNET_TRANSPORT_NotifyExcessBandwidth neb) 874 GNUNET_TRANSPORT_NotifyExcessBandwidtH neb)
868{ 875{
869 struct GNUNET_TRANSPORT_CoreHandle *h; 876 struct GNUNET_TRANSPORT_CoreHandle *h;
870 unsigned int i; 877 unsigned int i;
@@ -926,11 +933,6 @@ GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle)
926 } 933 }
927 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); 934 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours);
928 handle->neighbours = NULL; 935 handle->neighbours = NULL;
929 if (NULL != handle->quota_task)
930 {
931 GNUNET_SCHEDULER_cancel (handle->quota_task);
932 handle->quota_task = NULL;
933 }
934 GNUNET_free_non_null (handle->handlers); 936 GNUNET_free_non_null (handle->handlers);
935 handle->handlers = NULL; 937 handle->handlers = NULL;
936 GNUNET_free (handle); 938 GNUNET_free (handle);