aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-31 20:40:49 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-31 20:40:49 +0000
commit9d547cd3754656e231069bfe01dca01e0b15c48d (patch)
tree92b4842efe6617e487ac73909117a12b6ca8f72c /src
parentb5425d7bb119f63deca098aee74e8887ae47732a (diff)
downloadgnunet-9d547cd3754656e231069bfe01dca01e0b15c48d.tar.gz
gnunet-9d547cd3754656e231069bfe01dca01e0b15c48d.zip
adding code to ensure clean up of solicit state
Diffstat (limited to 'src')
-rw-r--r--src/core/core_api.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 2a04e2483..a6d729245 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -112,6 +112,17 @@ struct GNUNET_CORE_Handle
112 struct GNUNET_CORE_TransmitHandle *submitted; 112 struct GNUNET_CORE_TransmitHandle *submitted;
113 113
114 /** 114 /**
115 * Currently submitted request based on solicitation (or NULL)
116 */
117 struct GNUNET_CORE_TransmitHandle *solicit_transmit_req;
118
119 /**
120 * Buffer where we store a message for transmission in response
121 * to a traffic solicitation (or NULL).
122 */
123 char *solicit_buffer;
124
125 /**
115 * How long to wait until we time out the connection attempt? 126 * How long to wait until we time out the connection attempt?
116 */ 127 */
117 struct GNUNET_TIME_Absolute startup_timeout; 128 struct GNUNET_TIME_Absolute startup_timeout;
@@ -246,6 +257,8 @@ static size_t transmit_start (void *cls, size_t size, void *buf);
246/** 257/**
247 * Our current client connection went down. Clean it up 258 * Our current client connection went down. Clean it up
248 * and try to reconnect! 259 * and try to reconnect!
260 *
261 * @param h our handle to the core service
249 */ 262 */
250static void 263static void
251reconnect (struct GNUNET_CORE_Handle *h) 264reconnect (struct GNUNET_CORE_Handle *h)
@@ -362,9 +375,12 @@ trigger_next_request (struct GNUNET_CORE_Handle *h)
362static size_t 375static size_t
363copy_and_free (void *cls, size_t size, void *buf) 376copy_and_free (void *cls, size_t size, void *buf)
364{ 377{
365 char *cbuf = cls; 378 struct GNUNET_CORE_Handle *h = cls;
379 char *cbuf = h->solicit_buffer;
366 uint32_t have; 380 uint32_t have;
367 381
382 h->solicit_transmit_req = NULL;
383 h->solicit_buffer = NULL;
368 memcpy (&have, cbuf, sizeof (uint32_t)); 384 memcpy (&have, cbuf, sizeof (uint32_t));
369 if (have > size) 385 if (have > size)
370 { 386 {
@@ -380,6 +396,10 @@ copy_and_free (void *cls, size_t size, void *buf)
380 396
381/** 397/**
382 * Call bfc callback to solicit traffic for the given peer. 398 * Call bfc callback to solicit traffic for the given peer.
399 *
400 * @param h our handle to the core service
401 * @param peer peer for which traffic is solicited
402 * @param amount number of bytes that are being solicited
383 */ 403 */
384static void 404static void
385solicit_traffic (struct GNUNET_CORE_Handle *h, 405solicit_traffic (struct GNUNET_CORE_Handle *h,
@@ -389,22 +409,49 @@ solicit_traffic (struct GNUNET_CORE_Handle *h,
389 size_t have; 409 size_t have;
390 char *cbuf; 410 char *cbuf;
391 411
412 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
413 "Core solicited %u bytes of traffic for `%s'!\n",
414 amount,
415 GNUNET_i2s (peer));
416 if (NULL != h->solicit_transmit_req)
417 {
418 /* more than one solicitation pending */
419 GNUNET_break (0);
420 return;
421 }
392 have = h->bfc (h->cls, peer, buf, amount); 422 have = h->bfc (h->cls, peer, buf, amount);
393 if (have == 0) 423 if (have == 0)
394 return; 424 {
425 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
426 "Can not help with traffic solicitation for `%s'!\n",
427 GNUNET_i2s (peer));
428 return;
429 }
395 GNUNET_assert (have >= sizeof (struct GNUNET_MessageHeader)); 430 GNUNET_assert (have >= sizeof (struct GNUNET_MessageHeader));
396 cbuf = GNUNET_malloc (have + sizeof (uint32_t)); 431 cbuf = GNUNET_malloc (have + sizeof (uint32_t));
397 memcpy (cbuf, &have, sizeof (uint32_t)); 432 memcpy (cbuf, &have, sizeof (uint32_t));
398 memcpy (cbuf + sizeof (uint32_t), buf, have); 433 memcpy (cbuf + sizeof (uint32_t), buf, have);
399 GNUNET_CORE_notify_transmit_ready (h, 434 h->solicit_buffer = cbuf;
400 0, 435 h->solicit_transmit_req
401 GNUNET_TIME_UNIT_SECONDS, 436 = GNUNET_CORE_notify_transmit_ready (h,
402 peer, have, &copy_and_free, cbuf); 437 0,
438 GNUNET_TIME_UNIT_SECONDS,
439 peer, have, &copy_and_free, h);
440 if (h->solicit_transmit_req == NULL)
441 {
442 /* this should not happen */
443 GNUNET_break (0);
444 GNUNET_free (cbuf);
445 h->solicit_buffer = NULL;
446 }
403} 447}
404 448
405 449
406/** 450/**
407 * Handler for most messages received from the core. 451 * Handler for most messages received from the core.
452 *
453 * @param cls our "struct GNUNET_CORE_Handle"
454 * @param msg the message received from the core service
408 */ 455 */
409static void 456static void
410main_handler (void *cls, const struct GNUNET_MessageHeader *msg) 457main_handler (void *cls, const struct GNUNET_MessageHeader *msg)
@@ -845,9 +892,12 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
845{ 892{
846 if (handle->th != NULL) 893 if (handle->th != NULL)
847 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 894 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
895 if (handle->solicit_transmit_req != NULL)
896 GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
848 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 897 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
849 GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task); 898 GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
850 GNUNET_CLIENT_disconnect (handle->client); 899 GNUNET_CLIENT_disconnect (handle->client);
900 GNUNET_free_non_null (handle->solicit_buffer);
851 GNUNET_free (handle); 901 GNUNET_free (handle);
852} 902}
853 903