aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-08-30 14:48:16 +0000
committerBart Polot <bart@net.in.tum.de>2011-08-30 14:48:16 +0000
commit1b70d33f033d80ddfa5fe7bf89f695bced0d5e13 (patch)
tree99479dd63d7c06061f2b221e2c58b66f92ada49e /src
parentad2625015419e3afaac6e4f6ff919a8b488be306 (diff)
downloadgnunet-1b70d33f033d80ddfa5fe7bf89f695bced0d5e13.tar.gz
gnunet-1b70d33f033d80ddfa5fe7bf89f695bced0d5e13.zip
Indent
Diffstat (limited to 'src')
-rw-r--r--src/mesh/mesh_api_new.c268
1 files changed, 129 insertions, 139 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 84e3c7f38..6a58d14f0 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -84,8 +84,8 @@ struct GNUNET_MESH_TransmitHandle
84 struct GNUNET_MESH_TransmitHandle *prev; 84 struct GNUNET_MESH_TransmitHandle *prev;
85 85
86 /** 86 /**
87 * Data itself, currently points to the end of this struct if 87 * Data itself, currently points to the end of this struct if
88 * we have a message already, NULL if the message is to be 88 * we have a message already, NULL if the message is to be
89 * obtained from the callback. 89 * obtained from the callback.
90 */ 90 */
91 const struct GNUNET_MessageHeader *data; 91 const struct GNUNET_MessageHeader *data;
@@ -107,10 +107,10 @@ struct GNUNET_MESH_TransmitHandle
107 * Closure for 'notify' 107 * Closure for 'notify'
108 */ 108 */
109 void *notify_cls; 109 void *notify_cls;
110 110
111 /** 111 /**
112 * How long is this message valid. Once the timeout has been 112 * How long is this message valid. Once the timeout has been
113 * reached, the message must no longer be sent. If this 113 * reached, the message must no longer be sent. If this
114 * is a message with a 'notify' callback set, the 'notify' 114 * is a message with a 'notify' callback set, the 'notify'
115 * function should be called with 'buf' NULL and size 0. 115 * function should be called with 'buf' NULL and size 0.
116 */ 116 */
@@ -126,13 +126,13 @@ struct GNUNET_MESH_TransmitHandle
126 * control messages have the maximum priority (UINT32_MAX). 126 * control messages have the maximum priority (UINT32_MAX).
127 */ 127 */
128 uint32_t priority; 128 uint32_t priority;
129 129
130 /** 130 /**
131 * Target of the message, 0 for broadcast. This field 131 * Target of the message, 0 for broadcast. This field
132 * is only valid if 'notify' is non-NULL. 132 * is only valid if 'notify' is non-NULL.
133 */ 133 */
134 GNUNET_PEER_Id target; 134 GNUNET_PEER_Id target;
135 135
136 /** 136 /**
137 * Size of 'data' -- or the desired size of 'notify' if 'data' is NULL. 137 * Size of 'data' -- or the desired size of 'notify' if 'data' is NULL.
138 */ 138 */
@@ -161,7 +161,7 @@ struct GNUNET_MESH_Handle
161 * registered independently and the mapping is up to the developer of the 161 * registered independently and the mapping is up to the developer of the
162 * client application. 162 * client application.
163 */ 163 */
164 const GNUNET_MESH_ApplicationType *applications; 164 const GNUNET_MESH_ApplicationType *applications;
165 165
166 /** 166 /**
167 * Double linked list of the tunnels this client is connected to. 167 * Double linked list of the tunnels this client is connected to.
@@ -529,120 +529,110 @@ send_raw (void *cls, size_t size, void *buf)
529 529
530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size); 530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size);
531 h->th = NULL; 531 h->th = NULL;
532 if ( (0 == size) || (NULL == buf) ) 532 if ((0 == size) || (NULL == buf))
533 { 533 {
534 // FIXME: disconnect, reconnect, retry? 534 // FIXME: disconnect, reconnect, retry?
535 // do_reconnect (); 535 // do_reconnect ();
536 return 0; 536 return 0;
537 } 537 }
538 ret = 0; 538 ret = 0;
539 while ( (NULL != (q = h->queue_head)) && 539 while ((NULL != (q = h->queue_head)) && (size >= q->size))
540 (size >= q->size) ) 540 {
541 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "mesh-api", "type: %u\n",
542 ntohs (q->data->type));
543 if (NULL == q->data)
541 { 544 {
542 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 545 GNUNET_assert (NULL != q->notify);
543 "mesh-api", 546 if (q->target == 0)
544 "type: %u\n", 547 {
545 ntohs (q->data->type)); 548 /* multicast */
546 if (NULL == q->data) 549 struct GNUNET_MESH_Multicast mc;
547 { 550
548 GNUNET_assert (NULL != q->notify); 551 GNUNET_assert (size >= sizeof (mc) + q->size);
549 if (q->target == 0) 552 psize =
550 { 553 q->notify (q->notify_cls, size - sizeof (mc), &cbuf[sizeof (mc)]);
551 /* multicast */ 554 if (psize > 0)
552 struct GNUNET_MESH_Multicast mc; 555 {
553 556 mc.header.size = htons (sizeof (mc) + q->size);
554 GNUNET_assert (size >= sizeof (mc) + q->size); 557 mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
555 psize = q->notify (q->notify_cls, 558 mc.tid = htonl (q->tunnel->tid);
556 size - sizeof (mc), 559 memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */
557 &cbuf[sizeof(mc)]); 560 memcpy (cbuf, &mc, sizeof (mc));
558 if (psize > 0) 561 psize = q->size + sizeof (mc);
559 { 562 }
560 mc.header.size = htons (sizeof (mc) + q->size); 563 }
561 mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
562 mc.tid = htonl (q->tunnel->tid);
563 memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */
564 memcpy (cbuf, &mc, sizeof (mc));
565 psize = q->size + sizeof (mc);
566 }
567 }
568 else
569 {
570 /* unicast */
571 struct GNUNET_MESH_Unicast uc;
572
573 GNUNET_assert (size >= sizeof (uc) + q->size);
574 psize = q->notify (q->notify_cls,
575 size - sizeof (uc),
576 &cbuf[sizeof(uc)]);
577 if (psize > 0)
578 {
579 uc.header.size = htons (sizeof (uc) + q->size);
580 uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
581 uc.tid = htonl (q->tunnel->tid);
582 memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */
583 GNUNET_PEER_resolve (q->target, &uc.destination);
584 memcpy (cbuf, &uc, sizeof (uc));
585 psize = q->size + sizeof (uc);
586 }
587 }
588 }
589 else 564 else
590 { 565 {
591 memcpy (cbuf, q->data, q->size); 566 /* unicast */
592 psize = q->size; 567 struct GNUNET_MESH_Unicast uc;
593 } 568
594 if (q->timeout_task != GNUNET_SCHEDULER_NO_TASK) 569 GNUNET_assert (size >= sizeof (uc) + q->size);
595 GNUNET_SCHEDULER_cancel (q->timeout_task); 570 psize =
596 GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, q); 571 q->notify (q->notify_cls, size - sizeof (uc), &cbuf[sizeof (uc)]);
597 GNUNET_free (q); 572 if (psize > 0)
598 cbuf += psize; 573 {
599 size -= psize; 574 uc.header.size = htons (sizeof (uc) + q->size);
600 ret += psize; 575 uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
576 uc.tid = htonl (q->tunnel->tid);
577 memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */
578 GNUNET_PEER_resolve (q->target, &uc.destination);
579 memcpy (cbuf, &uc, sizeof (uc));
580 psize = q->size + sizeof (uc);
581 }
582 }
583 }
584 else
585 {
586 memcpy (cbuf, q->data, q->size);
587 psize = q->size;
601 } 588 }
589 if (q->timeout_task != GNUNET_SCHEDULER_NO_TASK)
590 GNUNET_SCHEDULER_cancel (q->timeout_task);
591 GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, q);
592 GNUNET_free (q);
593 cbuf += psize;
594 size -= psize;
595 ret += psize;
596 }
602 597
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", ret); 598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", ret);
604 599
605 if (NULL != (q = h->queue_head)) 600 if (NULL != (q = h->queue_head))
606 { 601 {
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: next size: %u\n", 602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: next size: %u\n", q->size);
608 q->size);
609 h->th = 603 h->th =
610 GNUNET_CLIENT_notify_transmit_ready (h->client, q->size, 604 GNUNET_CLIENT_notify_transmit_ready (h->client, q->size,
611 GNUNET_TIME_UNIT_FOREVER_REL, 605 GNUNET_TIME_UNIT_FOREVER_REL,
612 GNUNET_YES, &send_raw, h); 606 GNUNET_YES, &send_raw, h);
613 } 607 }
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n"); 608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n");
615 if (GNUNET_NO == h->in_receive) 609 if (GNUNET_NO == h->in_receive)
616 { 610 {
617 h->in_receive = GNUNET_YES; 611 h->in_receive = GNUNET_YES;
618 GNUNET_CLIENT_receive (h->client, &msg_received, h, 612 GNUNET_CLIENT_receive (h->client, &msg_received, h,
619 GNUNET_TIME_UNIT_FOREVER_REL); 613 GNUNET_TIME_UNIT_FOREVER_REL);
620 } 614 }
621 return ret; 615 return ret;
622} 616}
623 617
624 618
625static void 619static void
626timeout_transmission (void *cls, 620timeout_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
627 const struct GNUNET_SCHEDULER_TaskContext *tc)
628{ 621{
629 struct GNUNET_MESH_TransmitHandle *q = cls; 622 struct GNUNET_MESH_TransmitHandle *q = cls;
630 struct GNUNET_MESH_Handle *mesh; 623 struct GNUNET_MESH_Handle *mesh;
631 624
632 mesh = q->tunnel->mesh; 625 mesh = q->tunnel->mesh;
633 GNUNET_CONTAINER_DLL_remove (mesh->queue_head, 626 GNUNET_CONTAINER_DLL_remove (mesh->queue_head, mesh->queue_tail, q);
634 mesh->queue_tail,
635 q);
636 if (q->notify != NULL) 627 if (q->notify != NULL)
637 q->notify (q->notify_cls, 0, NULL); /* signal timeout */ 628 q->notify (q->notify_cls, 0, NULL); /* signal timeout */
638 GNUNET_free (q); 629 GNUNET_free (q);
639 if ( (NULL == mesh->queue_head) && 630 if ((NULL == mesh->queue_head) && (NULL != mesh->th))
640 (NULL != mesh->th) ) 631 {
641 { 632 /* queue empty, no point in asking for transmission */
642 /* queue empty, no point in asking for transmission */ 633 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th);
643 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th); 634 mesh->th = NULL;
644 mesh->th = NULL; 635 }
645 }
646} 636}
647 637
648 638
@@ -655,18 +645,18 @@ timeout_transmission (void *cls,
655 */ 645 */
656static void 646static void
657queue_transmit_handle (struct GNUNET_MESH_Handle *h, 647queue_transmit_handle (struct GNUNET_MESH_Handle *h,
658 struct GNUNET_MESH_TransmitHandle *q) 648 struct GNUNET_MESH_TransmitHandle *q)
659{ 649{
660 struct GNUNET_MESH_TransmitHandle *p; 650 struct GNUNET_MESH_TransmitHandle *p;
661 651
662 p = h->queue_head; 652 p = h->queue_head;
663 while ( (NULL != p) && (q->priority < p->priority) ) 653 while ((NULL != p) && (q->priority < p->priority))
664 p = p->next; 654 p = p->next;
665 GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, p->prev, q); 655 GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, p->prev, q);
666 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value != q->timeout.abs_value) 656 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value != q->timeout.abs_value)
667 q->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (q->timeout), 657 q->timeout_task =
668 &timeout_transmission, 658 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
669 q); 659 (q->timeout), &timeout_transmission, q);
670} 660}
671 661
672 662
@@ -678,8 +668,8 @@ queue_transmit_handle (struct GNUNET_MESH_Handle *h,
678 * @param msg message to transmit 668 * @param msg message to transmit
679 */ 669 */
680static void 670static void
681send_packet (struct GNUNET_MESH_Handle *h, 671send_packet (struct GNUNET_MESH_Handle *h,
682 const struct GNUNET_MessageHeader *msg) 672 const struct GNUNET_MessageHeader *msg)
683{ 673{
684 struct GNUNET_MESH_TransmitHandle *q; 674 struct GNUNET_MESH_TransmitHandle *q;
685 size_t msize; 675 size_t msize;
@@ -687,17 +677,17 @@ send_packet (struct GNUNET_MESH_Handle *h,
687 msize = ntohs (msg->size); 677 msize = ntohs (msg->size);
688 q = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); 678 q = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize);
689 q->priority = UINT32_MAX; 679 q->priority = UINT32_MAX;
690 q->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 680 q->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
691 q->size = msize; 681 q->size = msize;
692 q->data = (void*) &q[1]; 682 q->data = (void *) &q[1];
693 memcpy (&q[1], msg, msize); 683 memcpy (&q[1], msg, msize);
694 queue_transmit_handle (h, q); 684 queue_transmit_handle (h, q);
695 if (NULL != h->th) 685 if (NULL != h->th)
696 return; 686 return;
697 h->th = 687 h->th =
698 GNUNET_CLIENT_notify_transmit_ready (h->client, msize, 688 GNUNET_CLIENT_notify_transmit_ready (h->client, msize,
699 GNUNET_TIME_UNIT_FOREVER_REL, 689 GNUNET_TIME_UNIT_FOREVER_REL,
700 GNUNET_YES, &send_raw, h); 690 GNUNET_YES, &send_raw, h);
701} 691}
702 692
703/******************************************************************************/ 693/******************************************************************************/
@@ -735,7 +725,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
735 725
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); 726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n");
737 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); 727 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
738 h->max_queue_size = MESH_API_MAX_QUEUE; /* FIXME: add to arguments to 'GNUNET_MESH_connect' */ 728 h->max_queue_size = MESH_API_MAX_QUEUE; /* FIXME: add to arguments to 'GNUNET_MESH_connect' */
739 h->cleaner = cleaner; 729 h->cleaner = cleaner;
740 h->client = GNUNET_CLIENT_connect ("mesh", cfg); 730 h->client = GNUNET_CLIENT_connect ("mesh", cfg);
741 if (h->client == NULL) 731 if (h->client == NULL)
@@ -767,17 +757,17 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
767 msg->header.size = htons (size); 757 msg->header.size = htons (size);
768 types = (uint16_t *) & msg[1]; 758 types = (uint16_t *) & msg[1];
769 for (ntypes = 0; ntypes < h->n_handlers; ntypes++) 759 for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
770 types[ntypes] = h->message_handlers[ntypes].type; 760 types[ntypes] = h->message_handlers[ntypes].type;
771 apps = (GNUNET_MESH_ApplicationType *) &types[ntypes]; 761 apps = (GNUNET_MESH_ApplicationType *) &types[ntypes];
772 for (napps = 0; napps < h->n_applications; napps++) 762 for (napps = 0; napps < h->n_applications; napps++)
773 apps[napps] = h->applications[napps]; 763 apps[napps] = h->applications[napps];
774 msg->applications = htons (napps); 764 msg->applications = htons (napps);
775 msg->types = htons (ntypes); 765 msg->types = htons (ntypes);
776 766
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "mesh: Sending %lu bytes long message %d types and %d apps\n", 768 "mesh: Sending %lu bytes long message %d types and %d apps\n",
779 ntohs (msg->header.size), ntypes, napps); 769 ntohs (msg->header.size), ntypes, napps);
780 770
781 send_packet (h, &msg->header); 771 send_packet (h, &msg->header);
782 } 772 }
783 773
@@ -884,7 +874,7 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
884 struct GNUNET_MESH_PeerControl *msg; 874 struct GNUNET_MESH_PeerControl *msg;
885 GNUNET_PEER_Id peer_id; 875 GNUNET_PEER_Id peer_id;
886 unsigned int i; 876 unsigned int i;
887 877
888 peer_id = GNUNET_PEER_intern (peer); 878 peer_id = GNUNET_PEER_intern (peer);
889 for (i = 0; i < tunnel->npeers; i++) 879 for (i = 0; i < tunnel->npeers; i++)
890 { 880 {
@@ -903,7 +893,8 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
903 msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 893 msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
904 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD); 894 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
905 msg->tunnel_id = htonl (tunnel->tid); 895 msg->tunnel_id = htonl (tunnel->tid);
906 msg->timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout)); 896 msg->timeout =
897 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout));
907 memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); 898 memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity));
908 899
909 send_packet (tunnel->mesh, &msg->header); 900 send_packet (tunnel->mesh, &msg->header);
@@ -931,23 +922,21 @@ GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
931 922
932 peer_id = GNUNET_PEER_search (peer); 923 peer_id = GNUNET_PEER_search (peer);
933 if (0 == peer_id) 924 if (0 == peer_id)
934 { 925 {
935 GNUNET_break (0); 926 GNUNET_break (0);
936 return; 927 return;
937 } 928 }
938 for (i = 0; i < tunnel->npeers; i++) 929 for (i = 0; i < tunnel->npeers; i++)
939 if (tunnel->peers[i] == peer_id) 930 if (tunnel->peers[i] == peer_id)
940 break; 931 break;
941 if (i == tunnel->npeers) 932 if (i == tunnel->npeers)
942 { 933 {
943 GNUNET_break (0); 934 GNUNET_break (0);
944 return; 935 return;
945 } 936 }
946 GNUNET_PEER_change_rc (peer_id, -1); 937 GNUNET_PEER_change_rc (peer_id, -1);
947 tunnel->peers[i] = tunnel->peers[tunnel->npeers-1]; 938 tunnel->peers[i] = tunnel->peers[tunnel->npeers - 1];
948 GNUNET_array_grow (tunnel->peers, 939 GNUNET_array_grow (tunnel->peers, tunnel->npeers, tunnel->npeers - 1);
949 tunnel->npeers,
950 tunnel->npeers - 1);
951 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 940 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
952 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL); 941 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL);
953 msg.tunnel_id = htonl (tunnel->tid); 942 msg.tunnel_id = htonl (tunnel->tid);
@@ -975,9 +964,10 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
975 964
976 /* FIXME: remember request connect by type for reconnect! */ 965 /* FIXME: remember request connect by type for reconnect! */
977 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType)); 966 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
978 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE); 967 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE);
979 msg.tunnel_id = htonl (tunnel->tid); 968 msg.tunnel_id = htonl (tunnel->tid);
980 msg.timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout)); 969 msg.timeout =
970 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout));
981 msg.type = htonl (app_type); 971 msg.type = htonl (app_type);
982 send_packet (tunnel->mesh, &msg.header); 972 send_packet (tunnel->mesh, &msg.header);
983} 973}
@@ -1018,14 +1008,17 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1018 size_t overhead; 1008 size_t overhead;
1019 1009
1020 if (get_queue_length (tunnel->mesh) >= tunnel->mesh->max_queue_size) 1010 if (get_queue_length (tunnel->mesh) >= tunnel->mesh->max_queue_size)
1021 return NULL; /* queue full */ 1011 return NULL; /* queue full */
1022 1012
1023 q = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); 1013 q = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
1024 q->tunnel = tunnel; 1014 q->tunnel = tunnel;
1025 q->priority = priority; 1015 q->priority = priority;
1026 q->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); 1016 q->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
1027 q->target = GNUNET_PEER_intern (target); 1017 q->target = GNUNET_PEER_intern (target);
1028 overhead = (NULL == target) ? sizeof (struct GNUNET_MESH_Multicast) : sizeof (struct GNUNET_MESH_Unicast); 1018 overhead =
1019 (NULL ==
1020 target) ? sizeof (struct GNUNET_MESH_Multicast) : sizeof (struct
1021 GNUNET_MESH_Unicast);
1029 q->size = notify_size + overhead; 1022 q->size = notify_size + overhead;
1030 q->notify = notify; 1023 q->notify = notify;
1031 q->notify_cls = notify_cls; 1024 q->notify_cls = notify_cls;
@@ -1043,21 +1036,18 @@ void
1043GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th) 1036GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
1044{ 1037{
1045 struct GNUNET_MESH_Handle *mesh; 1038 struct GNUNET_MESH_Handle *mesh;
1046 1039
1047 mesh = th->tunnel->mesh; 1040 mesh = th->tunnel->mesh;
1048 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1041 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1049 GNUNET_SCHEDULER_cancel (th->timeout_task); 1042 GNUNET_SCHEDULER_cancel (th->timeout_task);
1050 GNUNET_CONTAINER_DLL_remove (mesh->queue_head, 1043 GNUNET_CONTAINER_DLL_remove (mesh->queue_head, mesh->queue_tail, th);
1051 mesh->queue_tail,
1052 th);
1053 GNUNET_free (th); 1044 GNUNET_free (th);
1054 if ( (NULL == mesh->queue_head) && 1045 if ((NULL == mesh->queue_head) && (NULL != mesh->th))
1055 (NULL != mesh->th) ) 1046 {
1056 { 1047 /* queue empty, no point in asking for transmission */
1057 /* queue empty, no point in asking for transmission */ 1048 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th);
1058 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th); 1049 mesh->th = NULL;
1059 mesh->th = NULL; 1050 }
1060 }
1061} 1051}
1062 1052
1063 1053