summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-17 15:39:23 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-17 15:39:23 +0000
commitce4ebee5643eeff8ba5888247205bb8426ccf362 (patch)
tree24c9a4713e4ca4e7dd2c73340f9185c9f37f8bfa
parentb90fdb9329d445cb2829205cc134b06689f1fe7b (diff)
more error checks
-rw-r--r--src/core/core_api.c27
-rw-r--r--src/core/gnunet-service-core.c1
-rw-r--r--src/core/test_core_api_preferences.c48
3 files changed, 54 insertions, 22 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 5b90a11ed..af46c6e63 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -417,17 +417,6 @@ disconnect_and_free_peer_entry (void *cls,
GNUNET_CORE_PeerConfigurationInfoCallback pcic;
void *pcic_cls;
- if (NULL != (pcic = pr->pcic))
- {
- pcic_cls = pr->pcic_cls;
- GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
- pcic (pcic_cls,
- &pr->peer,
- zero,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- 0);
- }
if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (pr->timeout_task);
@@ -449,6 +438,18 @@ disconnect_and_free_peer_entry (void *cls,
&pr->peer);
/* all requests should have been cancelled, clean up anyway, just in case */
GNUNET_break (pr->queue_size == 0);
+ if (NULL != (pcic = pr->pcic))
+ {
+ GNUNET_break (0);
+ pcic_cls = pr->pcic_cls;
+ GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
+ pcic (pcic_cls,
+ &pr->peer,
+ zero,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ 0);
+ }
while (NULL != (th = pr->pending_head))
{
GNUNET_break (0);
@@ -460,6 +461,7 @@ disconnect_and_free_peer_entry (void *cls,
th->cm->th = NULL;
GNUNET_free (th);
}
+ /* done with 'voluntary' cleanups, now on to normal freeing */
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (h->peers,
key,
@@ -1512,6 +1514,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
}
GNUNET_CONTAINER_multihashmap_destroy (handle->peers);
+ handle->peers = NULL;
GNUNET_break (handle->ready_peer_head == NULL);
GNUNET_free (handle);
}
@@ -1942,7 +1945,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
if (NULL == pr)
{
/* attempt to change preference on peer that is not connected */
- GNUNET_break (0);
+ GNUNET_assert (0);
return NULL;
}
if (pr->pcic != NULL)
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 1b0a93d6a..7a444847c 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -3883,6 +3883,7 @@ send_p2p_message_to_client (struct Neighbour *sender,
struct NotifyTrafficMessage *ntm;
struct GNUNET_TRANSPORT_ATS_Information *ats;
+ GNUNET_assert (GNUNET_YES == sender->is_connected);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c
index b0b23776f..c725543b0 100644
--- a/src/core/test_core_api_preferences.c
+++ b/src/core/test_core_api_preferences.c
@@ -66,6 +66,8 @@ static int ok;
static struct GNUNET_CORE_InformationRequestContext *irc;
+static struct GNUNET_CORE_TransmitHandle *th;
+
static GNUNET_SCHEDULER_TaskIdentifier irc_task;
static GNUNET_SCHEDULER_TaskIdentifier ask_task;
@@ -99,9 +101,15 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
#endif
GNUNET_break (0);
if (NULL != irc)
- GNUNET_CORE_peer_change_preference_cancel (irc);
+ {
+ GNUNET_CORE_peer_change_preference_cancel (irc);
+ irc = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != irc_task)
- GNUNET_SCHEDULER_cancel (irc_task);
+ {
+ GNUNET_SCHEDULER_cancel (irc_task);
+ irc_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != ask_task)
{
GNUNET_SCHEDULER_cancel (ask_task);
@@ -121,6 +129,7 @@ transmit_ready (void *cls, size_t size, void *buf)
struct PeerContext *p = cls;
struct GNUNET_MessageHeader *m;
+ th = NULL;
GNUNET_assert (ok == 4);
OKPP;
GNUNET_assert (p == &p1);
@@ -203,13 +212,13 @@ preference_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking core (1) for transmission to peer `%4s'\n",
GNUNET_i2s (&p2.id));
- if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_YES,
- 0,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45),
- &p2.id,
- sizeof (struct GNUNET_MessageHeader),
- &transmit_ready, &p1))
+ if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_YES,
+ 0,
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45),
+ &p2.id,
+ sizeof (struct GNUNET_MessageHeader),
+ &transmit_ready, &p1)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -261,8 +270,27 @@ disconnect_notify (void *cls,
sizeof (struct GNUNET_PeerIdentity)))
return;
pc->connect_status = 0;
+ if (GNUNET_SCHEDULER_NO_TASK != irc_task)
+ {
+ GNUNET_SCHEDULER_cancel (irc_task);
+ irc_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ if (irc != NULL)
+ {
+ GNUNET_CORE_peer_change_preference_cancel (irc);
+ irc = NULL;
+ }
+ if (th != NULL)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (th);
+ th = NULL;
+ }
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer));
+ "Encrypted connection to `%4s' cut\n",
+ GNUNET_i2s (peer));
}