aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/core_api.c84
1 files changed, 34 insertions, 50 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 10c465a89..1e17d0f5f 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -88,7 +88,7 @@ struct GNUNET_CORE_Handle
88 /** 88 /**
89 * Handle for our current transmission request. 89 * Handle for our current transmission request.
90 */ 90 */
91 struct GNUNET_CLIENT_TransmitHandle *th; 91 struct GNUNET_CLIENT_TransmitHandle *cth;
92 92
93 /** 93 /**
94 * Head of doubly-linked list of pending requests. 94 * Head of doubly-linked list of pending requests.
@@ -260,12 +260,12 @@ reconnect (struct GNUNET_CORE_Handle *h)
260 &reconnect_task, 260 &reconnect_task,
261 h); 261 h);
262 else 262 else
263 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications, 263 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
264 sizeof (struct InitMessage) + 264 sizeof (struct InitMessage) +
265 sizeof (uint16_t) * h->hcnt, 265 sizeof (uint16_t) * h->hcnt,
266 GNUNET_TIME_UNIT_SECONDS, 266 GNUNET_TIME_UNIT_SECONDS,
267 GNUNET_NO, 267 GNUNET_NO,
268 &transmit_start, h); 268 &transmit_start, h);
269} 269}
270 270
271 271
@@ -302,19 +302,13 @@ request_start (void *cls, size_t size, void *buf)
302 struct GNUNET_CORE_TransmitHandle *th; 302 struct GNUNET_CORE_TransmitHandle *th;
303 size_t ret; 303 size_t ret;
304 304
305 h->th = NULL; 305 h->cth = NULL;
306 th = h->pending_head; 306 th = h->pending_head;
307 if (buf == NULL) 307 if (buf == NULL)
308 { 308 {
309 timeout_request (th, NULL); 309 timeout_request (th, NULL);
310 return 0; 310 return 0;
311 } 311 }
312 /* create new timeout task (in case core takes too long to respond!) */
313 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->timeout_task);
314 th->timeout_task = GNUNET_SCHEDULER_add_delayed (h->sched,
315 GNUNET_TIME_absolute_get_remaining
316 (th->timeout),
317 &timeout_request, th);
318 GNUNET_CONTAINER_DLL_remove (h->pending_head, 312 GNUNET_CONTAINER_DLL_remove (h->pending_head,
319 h->pending_tail, 313 h->pending_tail,
320 th); 314 th);
@@ -346,19 +340,14 @@ trigger_next_request (struct GNUNET_CORE_Handle *h)
346 } 340 }
347 if (NULL == (th = h->pending_head)) 341 if (NULL == (th = h->pending_head))
348 return; /* no requests pending */ 342 return; /* no requests pending */
349 GNUNET_assert (NULL == h->th); 343 GNUNET_assert (NULL == h->cth);
350 if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) 344 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
351 { 345 th->msize,
352 GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task); 346 GNUNET_TIME_absolute_get_remaining
353 th->timeout_task = GNUNET_SCHEDULER_NO_TASK; 347 (th->timeout),
354 } 348 GNUNET_NO,
355 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications, 349 &request_start,
356 th->msize, 350 h);
357 GNUNET_TIME_absolute_get_remaining
358 (th->timeout),
359 GNUNET_NO,
360 &request_start,
361 h);
362} 351}
363 352
364 353
@@ -616,7 +605,7 @@ transmit_start (void *cls, size_t size, void *buf)
616 unsigned int hpos; 605 unsigned int hpos;
617 struct GNUNET_TIME_Relative delay; 606 struct GNUNET_TIME_Relative delay;
618 607
619 h->th = NULL; 608 h->cth = NULL;
620 if (size == 0) 609 if (size == 0)
621 { 610 {
622 if ((h->init == NULL) || 611 if ((h->init == NULL) ||
@@ -749,7 +738,7 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
749 "Trying to connect to core service in next %llu ms.\n", 738 "Trying to connect to core service in next %llu ms.\n",
750 timeout.value); 739 timeout.value);
751#endif 740#endif
752 h->th = 741 h->cth =
753 GNUNET_CLIENT_notify_transmit_ready (h->client_notifications, 742 GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
754 sizeof (struct InitMessage) + 743 sizeof (struct InitMessage) +
755 sizeof (uint16_t) * h->hcnt, timeout, 744 sizeof (uint16_t) * h->hcnt, timeout,
@@ -767,8 +756,8 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
767void 756void
768GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) 757GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
769{ 758{
770 if (handle->th != NULL) 759 if (handle->cth != NULL)
771 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 760 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
772 if (handle->solicit_transmit_req != NULL) 761 if (handle->solicit_transmit_req != NULL)
773 GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req); 762 GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
774 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 763 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
@@ -812,7 +801,6 @@ produce_send (void *cls, size_t size, void *buf)
812 "Preparing for P2P transmission to `%4s'.\n", 801 "Preparing for P2P transmission to `%4s'.\n",
813 GNUNET_i2s(&th->peer)); 802 GNUNET_i2s(&th->peer));
814#endif 803#endif
815 GNUNET_assert (th->timeout_task != GNUNET_SCHEDULER_NO_TASK);
816 sm = (struct SendMessage *) buf; 804 sm = (struct SendMessage *) buf;
817 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); 805 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
818 sm->priority = htonl (th->priority); 806 sm->priority = htonl (th->priority);
@@ -896,7 +884,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
896 th->msize = sizeof (struct SendMessage) + notify_size; 884 th->msize = sizeof (struct SendMessage) + notify_size;
897 /* was the request queue previously empty? */ 885 /* was the request queue previously empty? */
898 if ( (handle->pending_head == th) && 886 if ( (handle->pending_head == th) &&
899 (handle->th == NULL) ) 887 (handle->cth == NULL) )
900 trigger_next_request (handle); 888 trigger_next_request (handle);
901 return th; 889 return th;
902} 890}
@@ -905,27 +893,23 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
905/** 893/**
906 * Cancel the specified transmission-ready notification. 894 * Cancel the specified transmission-ready notification.
907 * 895 *
908 * @param h handle that was returned by "notify_transmit_ready". 896 * @param th handle that was returned by "notify_transmit_ready".
909 */ 897 */
910void 898void
911GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle 899GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
912 *h) 900 *th)
913{ 901{
914 struct GNUNET_CORE_Handle *handle = h->ch; 902 struct GNUNET_CORE_Handle *h = th->ch;
915 903
916 if (handle->submitted == h) 904 if (h->submitted == th)
917 { 905 h->submitted = NULL;
918 handle->submitted = NULL; 906 else
919 } 907 GNUNET_CONTAINER_DLL_remove (h->pending_head,
920 else 908 h->pending_tail,
921 { 909 th);
922 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 910 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
923 handle->pending_tail, 911 GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task);
924 h); 912 GNUNET_free (th);
925 }
926 if (h->timeout_task != GNUNET_SCHEDULER_NO_TASK)
927 GNUNET_SCHEDULER_cancel (handle->sched, h->timeout_task);
928 GNUNET_free (h);
929} 913}
930 914
931 915