*/
/**
* @file ats/test_ats_solver_add_address.c
- * @brief solver test: add address, request address and wait for suggest
+ * @brief solver test: add 2 addresses, request address, delete, expect alternative
* @author Christian Grothoff
* @author Matthias Wachs
*/
int second_address_suggested = GNUNET_YES;
-static const struct GNUNET_HELLO_Address *first_suggestion = NULL;
+static struct GNUNET_HELLO_Address *first_suggestion = NULL;
-static const struct GNUNET_HELLO_Address *second_suggestion = NULL;
+static struct GNUNET_HELLO_Address *second_suggestion = NULL;
static int
}
free_test_address (&test_addr);
-
+ GNUNET_free_non_null (first_suggestion);
+ GNUNET_free_non_null (second_suggestion);
ret = 0;
}
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+
die_task = GNUNET_SCHEDULER_NO_TASK;
end ( NULL, NULL);
ret = GNUNET_SYSERR;
}
+static void
+end_badly_now ()
+{
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+}
+
static void
address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
struct Session *session,
if ((NULL == address) || (NULL != session))
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
if ((ntohl(bandwidth_in.value__) == 0) ||
(ntohl(bandwidth_out.value__) == 0))
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received 1st sugggestion for peer `%s' : `%s'\n",
GNUNET_i2s (&address->peer), (char *) address->address);
- first_suggestion = address;
+ first_suggestion = GNUNET_HELLO_address_copy (address);
first_address_suggested = GNUNET_YES;
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 1st address for peer `%s' : `%s'\n",
GNUNET_i2s (&address->peer), (char *) address->address);
-
GNUNET_ATS_address_destroyed (sched_ats, address, session);
first_address_deleted = GNUNET_YES;
+
return;
}
}
if ((NULL == address) || (NULL != session))
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
if ((ntohl(bandwidth_in.value__) == 0) ||
(ntohl(bandwidth_out.value__) == 0))
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
- if (first_suggestion->address_length == address->address_length)
+ if (0 == memcmp (address->address, first_suggestion->address,
+ (first_suggestion->address_length < address->address_length) ? first_suggestion->address_length : address->address_length))
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleted address for peer `%s' was suggested after deletion: `%s'\n",
- GNUNET_i2s (&address->peer), (char *) address->address);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleted 1st address for peer `%s' was suggested after deletion: `%s' `%s'\n",
+ GNUNET_i2s (&address->peer), (char *) address->address, first_suggestion->address);
GNUNET_break (0);
- //GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received 2nd sugggestion for peer `%s' : `%s'\n",
GNUNET_i2s (&address->peer), (char *) address->address);
- second_suggestion = address;
+ second_suggestion = GNUNET_HELLO_address_copy (address);
second_address_suggested = GNUNET_YES;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer `%s' : `%s'\n",
second_address_deleted = GNUNET_YES;
return;
}
+
}
- if (GNUNET_YES ==second_address_deleted)
+ if (GNUNET_YES == second_address_deleted)
{
/* Expecting disconnect */
if ((ntohl(bandwidth_in.value__) == 0) &&
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Expected disconnect received address `%s' with bandwidth \n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Expected disconnect but received address `%s' with bandwidth \n",
(char *) address->address);
}
}
if (sched_ats == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p.id.hashPubKey))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ end_badly_now ();
return;
}
GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p.id)));