/*
This file is part of GNUnet.
- Copyright (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009, 2010, 2015 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file core/test_core_api.c
#include "platform.h"
#include "gnunet_arm_service.h"
#include "gnunet_core_service.h"
-#include "gnunet_getopt_lib.h"
-#include "gnunet_os_lib.h"
-#include "gnunet_program_lib.h"
-#include "gnunet_scheduler_lib.h"
+#include "gnunet_util_lib.h"
#include "gnunet_transport_service.h"
+#include "gnunet_ats_service.h"
#define MTYPE 12345
struct GNUNET_PeerIdentity id;
struct GNUNET_TRANSPORT_Handle *th;
struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
+ struct GNUNET_ATS_ConnectivityHandle *ats;
+ struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
struct GNUNET_MessageHeader *hello;
int connect_status;
struct GNUNET_OS_Process *arm_proc;
static struct PeerContext p2;
-static struct GNUNET_SCHEDULER_Task * err_task;
-
-static struct GNUNET_SCHEDULER_Task * con_task;
+static struct GNUNET_SCHEDULER_Task *err_task;
static int ok;
static void
-terminate_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+terminate_peer (struct PeerContext *p)
{
- GNUNET_assert (ok == 6);
- GNUNET_CORE_disconnect (p1.ch);
- p1.ch = NULL;
- GNUNET_CORE_disconnect (p2.ch);
- p2.ch = NULL;
- GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
- p1.ghh = NULL;
- GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
- p2.ghh = NULL;
- GNUNET_TRANSPORT_disconnect (p1.th);
- p1.th = NULL;
- GNUNET_TRANSPORT_disconnect (p2.th);
- p2.th = NULL;
- if (NULL != con_task)
+ if (NULL != p->ch)
{
- GNUNET_SCHEDULER_cancel (con_task);
- con_task = NULL;
+ GNUNET_CORE_disconnect (p->ch);
+ p->ch = NULL;
}
+ if (NULL != p->th)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
+ GNUNET_TRANSPORT_disconnect (p->th);
+ p->th = NULL;
+ }
+ if (NULL != p->ats_sh)
+ {
+ GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh);
+ p->ats_sh = NULL;
+ }
+ if (NULL != p->ats)
+ {
+ GNUNET_ATS_connectivity_done (p->ats);
+ p->ats = NULL;
+ }
+}
+
+
+static void
+terminate_task (void *cls)
+{
+ GNUNET_assert (ok == 6);
+ terminate_peer (&p1);
+ terminate_peer (&p2);
ok = 0;
}
static void
-terminate_task_error (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+terminate_task_error (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"ENDING ANGRILY %u\n",
ok);
GNUNET_break (0);
- if (NULL != p1.ch)
- {
- GNUNET_CORE_disconnect (p1.ch);
- p1.ch = NULL;
- }
- if (NULL != p2.ch)
- {
- GNUNET_CORE_disconnect (p2.ch);
- p2.ch = NULL;
- }
- if (p1.th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
- GNUNET_TRANSPORT_disconnect (p1.th);
- p1.th = NULL;
- }
- if (p2.th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
- GNUNET_TRANSPORT_disconnect (p2.th);
- p2.th = NULL;
- }
- if (NULL != con_task)
- {
- GNUNET_SCHEDULER_cancel (con_task);
- con_task = NULL;
- }
+ terminate_peer (&p1);
+ terminate_peer (&p2);
ok = 42;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypted connection established to peer `%4s'\n",
GNUNET_i2s (peer));
- if (NULL != con_task)
- {
- GNUNET_SCHEDULER_cancel (con_task);
- con_task = NULL;
- }
pc->connect_status = 1;
if (pc == &p1)
{
};
-static void
-connect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- con_task = NULL;
- return;
- }
- con_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &connect_task,
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking transport (1) to connect to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- GNUNET_TRANSPORT_try_connect (p1.th, &p2.id, NULL, NULL); /*FIXME TRY_CONNECT change */
-}
-
-
static void
init_notify (void *cls,
const struct GNUNET_PeerIdentity *my_identity)
GNUNET_assert (ok == 3);
OKPP;
GNUNET_assert (cls == &p2);
- con_task = GNUNET_SCHEDULER_add_now (&connect_task, NULL);
+ p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats,
+ &p2.id,
+ 1);
}
}
"-c", cfgname, NULL);
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
- GNUNET_assert (p->th != NULL);
+ GNUNET_assert (NULL != p->th);
+ p->ats = GNUNET_ATS_connectivity_init (p->cfg);
+ GNUNET_assert (NULL != p->ats);
p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
GNUNET_free (binary);
}