diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-12-23 14:33:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-12-23 14:33:46 +0000 |
commit | 5c95af3375a6924e5714263ff8ef746602391e26 (patch) | |
tree | 3becf121be059fcdf372449c5a77096e4a14d885 | |
parent | 8ebac00ebaf0656548c5a66d2519bfccdbb3e7db (diff) | |
download | gnunet-5c95af3375a6924e5714263ff8ef746602391e26.tar.gz gnunet-5c95af3375a6924e5714263ff8ef746602391e26.zip |
cleaning up core API with bugfix
-rw-r--r-- | src/core/core_api.c | 89 | ||||
-rw-r--r-- | src/include/gnunet_core_service.h | 15 | ||||
-rw-r--r-- | src/testing/testing.c | 8 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 4 | ||||
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 3 |
5 files changed, 61 insertions, 58 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c index d2308d845..c3d7fd798 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c | |||
@@ -129,12 +129,10 @@ struct ControlMessage | |||
129 | struct ControlMessage *prev; | 129 | struct ControlMessage *prev; |
130 | 130 | ||
131 | /** | 131 | /** |
132 | * Function to run after successful transmission (or call with | 132 | * Function to run after transmission failed/succeeded. |
133 | * reason 'TIMEOUT' on error); called with scheduler context 'NULL' | ||
134 | * on disconnect. | ||
135 | */ | 133 | */ |
136 | GNUNET_SCHEDULER_Task cont; | 134 | GNUNET_CORE_ControlContinuation cont; |
137 | 135 | ||
138 | /** | 136 | /** |
139 | * Closure for 'cont'. | 137 | * Closure for 'cont'. |
140 | */ | 138 | */ |
@@ -462,17 +460,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h) | |||
462 | struct ControlMessage *cm; | 460 | struct ControlMessage *cm; |
463 | struct PeerRecord *pr; | 461 | struct PeerRecord *pr; |
464 | 462 | ||
465 | while (NULL != (cm = h->control_pending_head)) | 463 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); |
466 | { | ||
467 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | ||
468 | h->control_pending_tail, | ||
469 | cm); | ||
470 | if (cm->th != NULL) | ||
471 | cm->th->cm = NULL; | ||
472 | if (cm->cont != NULL) | ||
473 | cm->cont (cm->cont_cls, NULL); | ||
474 | GNUNET_free (cm); | ||
475 | } | ||
476 | if (h->client != NULL) | 464 | if (h->client != NULL) |
477 | { | 465 | { |
478 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | 466 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
@@ -486,15 +474,24 @@ reconnect_later (struct GNUNET_CORE_Handle *h) | |||
486 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, | 474 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, |
487 | h->ready_peer_tail, | 475 | h->ready_peer_tail, |
488 | pr); | 476 | pr); |
489 | |||
490 | GNUNET_assert (h->control_pending_head == NULL); | ||
491 | h->currently_down = GNUNET_YES; | 477 | h->currently_down = GNUNET_YES; |
492 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); | ||
493 | h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | ||
494 | h->retry_backoff); | ||
495 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 478 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, |
496 | &reconnect_task, | 479 | &reconnect_task, |
497 | h); | 480 | h); |
481 | while (NULL != (cm = h->control_pending_head)) | ||
482 | { | ||
483 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | ||
484 | h->control_pending_tail, | ||
485 | cm); | ||
486 | if (cm->th != NULL) | ||
487 | cm->th->cm = NULL; | ||
488 | if (cm->cont != NULL) | ||
489 | cm->cont (cm->cont_cls, GNUNET_NO); | ||
490 | GNUNET_free (cm); | ||
491 | } | ||
492 | GNUNET_assert (h->control_pending_head == NULL); | ||
493 | h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | ||
494 | h->retry_backoff); | ||
498 | h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2); | 495 | h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2); |
499 | } | 496 | } |
500 | 497 | ||
@@ -636,6 +633,7 @@ transmit_message (void *cls, | |||
636 | uint16_t msize; | 633 | uint16_t msize; |
637 | size_t ret; | 634 | size_t ret; |
638 | 635 | ||
636 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); | ||
639 | h->cth = NULL; | 637 | h->cth = NULL; |
640 | if (buf == NULL) | 638 | if (buf == NULL) |
641 | { | 639 | { |
@@ -669,9 +667,7 @@ transmit_message (void *cls, | |||
669 | if (cm->th != NULL) | 667 | if (cm->th != NULL) |
670 | cm->th->cm = NULL; | 668 | cm->th->cm = NULL; |
671 | if (NULL != cm->cont) | 669 | if (NULL != cm->cont) |
672 | GNUNET_SCHEDULER_add_continuation (cm->cont, | 670 | cm->cont (cm->cont_cls, GNUNET_OK); |
673 | cm->cont_cls, | ||
674 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
675 | GNUNET_free (cm); | 671 | GNUNET_free (cm); |
676 | trigger_next_request (h, GNUNET_NO); | 672 | trigger_next_request (h, GNUNET_NO); |
677 | return msize; | 673 | return msize; |
@@ -1266,23 +1262,24 @@ main_notify_handler (void *cls, | |||
1266 | * Starts our 'receive' loop. | 1262 | * Starts our 'receive' loop. |
1267 | * | 1263 | * |
1268 | * @param cls the 'struct GNUNET_CORE_Handle' | 1264 | * @param cls the 'struct GNUNET_CORE_Handle' |
1269 | * @param tc task context | 1265 | * @param success were we successful |
1270 | */ | 1266 | */ |
1271 | static void | 1267 | static void |
1272 | init_done_task (void *cls, | 1268 | init_done_task (void *cls, |
1273 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1269 | int success) |
1274 | { | 1270 | { |
1275 | struct GNUNET_CORE_Handle *h = cls; | 1271 | struct GNUNET_CORE_Handle *h = cls; |
1276 | 1272 | ||
1277 | if (tc == NULL) | 1273 | if (success == GNUNET_SYSERR) |
1278 | return; /* error */ | 1274 | return; /* shutdown */ |
1279 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 1275 | if (success == GNUNET_NO) |
1280 | { | 1276 | { |
1281 | #if DEBUG_CORE | 1277 | #if DEBUG_CORE |
1282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1283 | "Failed to exchange INIT with core, retrying\n"); | 1279 | "Failed to exchange INIT with core, retrying\n"); |
1284 | #endif | 1280 | #endif |
1285 | reconnect_later (h); | 1281 | if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK) |
1282 | reconnect_later (h); | ||
1286 | return; | 1283 | return; |
1287 | } | 1284 | } |
1288 | GNUNET_CLIENT_receive (h->client, | 1285 | GNUNET_CLIENT_receive (h->client, |
@@ -1454,11 +1451,6 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) | |||
1454 | GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); | 1451 | GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); |
1455 | handle->client = NULL; | 1452 | handle->client = NULL; |
1456 | } | 1453 | } |
1457 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
1458 | { | ||
1459 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | ||
1460 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
1461 | } | ||
1462 | while (NULL != (cm = handle->control_pending_head)) | 1454 | while (NULL != (cm = handle->control_pending_head)) |
1463 | { | 1455 | { |
1464 | GNUNET_CONTAINER_DLL_remove (handle->control_pending_head, | 1456 | GNUNET_CONTAINER_DLL_remove (handle->control_pending_head, |
@@ -1467,9 +1459,14 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) | |||
1467 | if (cm->th != NULL) | 1459 | if (cm->th != NULL) |
1468 | cm->th->cm = NULL; | 1460 | cm->th->cm = NULL; |
1469 | if (cm->cont != NULL) | 1461 | if (cm->cont != NULL) |
1470 | cm->cont (cm->cont_cls, NULL); | 1462 | cm->cont (cm->cont_cls, GNUNET_SYSERR); |
1471 | GNUNET_free (cm); | 1463 | GNUNET_free (cm); |
1472 | } | 1464 | } |
1465 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
1466 | { | ||
1467 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | ||
1468 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
1469 | } | ||
1473 | GNUNET_CONTAINER_multihashmap_iterate (handle->peers, | 1470 | GNUNET_CONTAINER_multihashmap_iterate (handle->peers, |
1474 | &disconnect_and_free_peer_entry, | 1471 | &disconnect_and_free_peer_entry, |
1475 | handle); | 1472 | handle); |
@@ -1672,7 +1669,7 @@ struct GNUNET_CORE_PeerRequestHandle | |||
1672 | /** | 1669 | /** |
1673 | * Continuation to run when done. | 1670 | * Continuation to run when done. |
1674 | */ | 1671 | */ |
1675 | GNUNET_SCHEDULER_Task cont; | 1672 | GNUNET_CORE_ControlContinuation cont; |
1676 | 1673 | ||
1677 | /** | 1674 | /** |
1678 | * Closure for 'cont'. | 1675 | * Closure for 'cont'. |
@@ -1688,22 +1685,16 @@ struct GNUNET_CORE_PeerRequestHandle | |||
1688 | * resources. | 1685 | * resources. |
1689 | * | 1686 | * |
1690 | * @param cls the 'struct GNUNET_CORE_PeerRequestHandle' | 1687 | * @param cls the 'struct GNUNET_CORE_PeerRequestHandle' |
1691 | * @param tc scheduler context | 1688 | * @param success was the request transmitted? |
1692 | */ | 1689 | */ |
1693 | static void | 1690 | static void |
1694 | peer_request_connect_cont (void *cls, | 1691 | peer_request_connect_cont (void *cls, |
1695 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1692 | int success) |
1696 | { | 1693 | { |
1697 | struct GNUNET_CORE_PeerRequestHandle *ret = cls; | 1694 | struct GNUNET_CORE_PeerRequestHandle *ret = cls; |
1698 | 1695 | ||
1699 | if (ret->cont != NULL) | 1696 | if (ret->cont != NULL) |
1700 | { | 1697 | ret->cont (ret->cont_cls, success); |
1701 | if (tc == NULL) | ||
1702 | GNUNET_SCHEDULER_add_now (ret->cont, | ||
1703 | ret->cont_cls); | ||
1704 | else | ||
1705 | ret->cont (ret->cont_cls, tc); | ||
1706 | } | ||
1707 | GNUNET_free (ret); | 1698 | GNUNET_free (ret); |
1708 | } | 1699 | } |
1709 | 1700 | ||
@@ -1730,7 +1721,7 @@ struct GNUNET_CORE_PeerRequestHandle * | |||
1730 | GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, | 1721 | GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, |
1731 | struct GNUNET_TIME_Relative timeout, | 1722 | struct GNUNET_TIME_Relative timeout, |
1732 | const struct GNUNET_PeerIdentity * peer, | 1723 | const struct GNUNET_PeerIdentity * peer, |
1733 | GNUNET_SCHEDULER_Task cont, | 1724 | GNUNET_CORE_ControlContinuation cont, |
1734 | void *cont_cls) | 1725 | void *cont_cls) |
1735 | { | 1726 | { |
1736 | struct GNUNET_CORE_PeerRequestHandle *ret; | 1727 | struct GNUNET_CORE_PeerRequestHandle *ret; |
@@ -1822,11 +1813,11 @@ struct GNUNET_CORE_InformationRequestContext | |||
1822 | * CM was sent, remove link so we don't double-free. | 1813 | * CM was sent, remove link so we don't double-free. |
1823 | * | 1814 | * |
1824 | * @param cls the 'struct GNUNET_CORE_InformationRequestContext' | 1815 | * @param cls the 'struct GNUNET_CORE_InformationRequestContext' |
1825 | * @param tc scheduler context | 1816 | * @param success were we successful? |
1826 | */ | 1817 | */ |
1827 | static void | 1818 | static void |
1828 | change_preference_send_continuation (void *cls, | 1819 | change_preference_send_continuation (void *cls, |
1829 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1820 | int success) |
1830 | { | 1821 | { |
1831 | struct GNUNET_CORE_InformationRequestContext *irc = cls; | 1822 | struct GNUNET_CORE_InformationRequestContext *irc = cls; |
1832 | 1823 | ||
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index efbcda60d..897979066 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h | |||
@@ -242,6 +242,19 @@ struct GNUNET_CORE_PeerRequestHandle; | |||
242 | 242 | ||
243 | 243 | ||
244 | /** | 244 | /** |
245 | * Type of function called upon completion. | ||
246 | * | ||
247 | * @param cls closure | ||
248 | * @param success GNUNET_OK on success (which for request_connect | ||
249 | * ONLY means that we transmitted the connect request to CORE, | ||
250 | * it does not mean that we are actually now connected!); | ||
251 | * GNUNET_NO on timeout, | ||
252 | * GNUNET_SYSERR if core was shut down | ||
253 | */ | ||
254 | typedef void (*GNUNET_CORE_ControlContinuation)(void *cls, int success); | ||
255 | |||
256 | |||
257 | /** | ||
245 | * Request that the core should try to connect to a particular peer. | 258 | * Request that the core should try to connect to a particular peer. |
246 | * Once the request has been transmitted to the core, the continuation | 259 | * Once the request has been transmitted to the core, the continuation |
247 | * function will be called. Note that this does NOT mean that a | 260 | * function will be called. Note that this does NOT mean that a |
@@ -263,7 +276,7 @@ struct GNUNET_CORE_PeerRequestHandle * | |||
263 | GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, | 276 | GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, |
264 | struct GNUNET_TIME_Relative timeout, | 277 | struct GNUNET_TIME_Relative timeout, |
265 | const struct GNUNET_PeerIdentity * peer, | 278 | const struct GNUNET_PeerIdentity * peer, |
266 | GNUNET_SCHEDULER_Task cont, | 279 | GNUNET_CORE_ControlContinuation cont, |
267 | void *cont_cls); | 280 | void *cont_cls); |
268 | 281 | ||
269 | 282 | ||
diff --git a/src/testing/testing.c b/src/testing/testing.c index dd4b92a1b..75eab1a06 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -1504,17 +1504,15 @@ connect_notify_core2 (void *cls, | |||
1504 | * Task called once a core connect request has been transmitted. | 1504 | * Task called once a core connect request has been transmitted. |
1505 | * | 1505 | * |
1506 | * @param cls struct ConnectContext | 1506 | * @param cls struct ConnectContext |
1507 | * @param tc context information (why was this task triggered now) | 1507 | * @param success was the request successful? |
1508 | */ | 1508 | */ |
1509 | void | 1509 | void |
1510 | core_connect_request_cont (void *cls, | 1510 | core_connect_request_cont (void *cls, |
1511 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1511 | int success) |
1512 | { | 1512 | { |
1513 | struct ConnectContext *ctx = cls; | 1513 | struct ConnectContext *ctx = cls; |
1514 | 1514 | ||
1515 | if (tc->reason == GNUNET_SCHEDULER_REASON_PREREQ_DONE) | 1515 | ctx->connect_request_handle = NULL; |
1516 | ctx->connect_request_handle = NULL; | ||
1517 | return; | ||
1518 | } | 1516 | } |
1519 | 1517 | ||
1520 | static void | 1518 | static void |
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 880dff062..7a3743866 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -271,11 +271,11 @@ whitelist_peers () | |||
271 | * Function called by core when our attempt to connect succeeded. | 271 | * Function called by core when our attempt to connect succeeded. |
272 | * | 272 | * |
273 | * @param cls the 'struct Peer' for which we issued the connect request | 273 | * @param cls the 'struct Peer' for which we issued the connect request |
274 | * @param tc scheduler context | 274 | * @param success was the request transmitted |
275 | */ | 275 | */ |
276 | static void | 276 | static void |
277 | connect_completed_callback (void *cls, | 277 | connect_completed_callback (void *cls, |
278 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 278 | int success) |
279 | { | 279 | { |
280 | struct Peer *pos = cls; | 280 | struct Peer *pos = cls; |
281 | 281 | ||
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 99491f34c..acdb05ce1 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -487,7 +487,8 @@ port_in_ports (uint64_t ports, uint16_t port) | |||
487 | } | 487 | } |
488 | 488 | ||
489 | void | 489 | void |
490 | send_udp (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 490 | send_udp (void *cls, |
491 | int success) | ||
491 | { | 492 | { |
492 | struct GNUNET_PeerIdentity *peer = cls; | 493 | struct GNUNET_PeerIdentity *peer = cls; |
493 | struct GNUNET_MessageHeader *hdr = | 494 | struct GNUNET_MessageHeader *hdr = |