/**
* @file core/test_core_api.c
* @brief testcase for core_api.c
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_arm_service.h"
{
if (NULL != p->ch)
{
- GNUNET_CORE_disconnect (p->ch);
+ GNUNET_CORE_disconnecT (p->ch);
p->ch = NULL;
}
if (NULL != p->ghh)
}
-static size_t
-transmit_ready (void *cls,
- size_t size,
- void *buf)
-{
- struct PeerContext *p = cls;
- struct GNUNET_MessageHeader *m;
-
- GNUNET_assert (ok == 4);
- OKPP;
- GNUNET_assert (p == &p1);
- GNUNET_assert (NULL != buf);
- m = (struct GNUNET_MessageHeader *) buf;
- m->type = htons (MTYPE);
- m->size = htons (sizeof (struct GNUNET_MessageHeader));
- return sizeof (struct GNUNET_MessageHeader);
-}
-
-
-static void
+static void *
connect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
struct PeerContext *pc = cls;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *msg;
if (0 == memcmp (&pc->id,
peer,
sizeof (struct GNUNET_PeerIdentity)))
- return;
+ return (void *) peer;
GNUNET_assert (pc->connect_status == 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypted connection established to peer `%s'\n",
pc->connect_status = 1;
if (pc == &p1)
{
+ uint64_t flags;
+ const void *extra;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking core (1) for transmission to peer `%s'\n",
GNUNET_i2s (&p2.id));
- if (NULL ==
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_YES,
- GNUNET_CORE_PRIO_BEST_EFFORT,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 145),
- &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 `%s'\n",
- GNUNET_i2s (&p2.id));
- }
+ env = GNUNET_MQ_msg (msg,
+ MTYPE);
+ /* enable corking for this test */
+ extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
+ GNUNET_CORE_PRIO_BEST_EFFORT,
+ &flags);
+ GNUNET_MQ_env_set_options (env,
+ flags,
+ extra);
+ /* now actually transmit message */
+ GNUNET_assert (ok == 4);
+ OKPP;
+ GNUNET_MQ_send (mq,
+ env);
}
+ return (void *) peer;
}
static void
disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ void *internal_cls)
{
struct PeerContext *pc = cls;
}
-static int
-inbound_notify (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core provides inbound data from `%s'.\n",
- GNUNET_i2s (other));
- return GNUNET_OK;
-}
-
-
-static int
-outbound_notify (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core notifies about outbound data for `%s'.\n",
- GNUNET_i2s (other));
- return GNUNET_OK;
-}
-
-
-static int
-process_mtype (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_test (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
+ const struct GNUNET_PeerIdentity *peer = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving message from `%s'.\n",
GNUNET_i2s (peer));
GNUNET_SCHEDULER_cancel (err_task);
err_task = GNUNET_SCHEDULER_add_now (&terminate_task,
NULL);
- return GNUNET_OK;
}
-static struct GNUNET_CORE_MessageHandler handlers[] = {
- {&process_mtype, MTYPE, sizeof (struct GNUNET_MessageHeader)},
- {NULL, 0, 0}
-};
-
-
static void
init_notify (void *cls,
const struct GNUNET_PeerIdentity *my_identity)
{
+ GNUNET_MQ_hd_fixed_size (test,
+ MTYPE,
+ struct GNUNET_MessageHeader);
struct PeerContext *p = cls;
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ make_test_handler (NULL),
+ GNUNET_MQ_handler_end ()
+ };
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core connection to `%s' established\n",
GNUNET_assert (ok == 2);
OKPP;
/* connect p2 */
- p2.ch = GNUNET_CORE_connect (p2.cfg,
+ p2.ch = GNUNET_CORE_connecT (p2.cfg,
&p2,
&init_notify,
&connect_notify,
&disconnect_notify,
- &inbound_notify, GNUNET_YES,
- &outbound_notify, GNUNET_YES,
handlers);
}
else
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ GNUNET_MQ_hd_fixed_size (test,
+ MTYPE,
+ struct GNUNET_MessageHeader);
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ make_test_handler (NULL),
+ GNUNET_MQ_handler_end ()
+ };
+
GNUNET_assert (ok == 1);
OKPP;
- setup_peer (&p1, "test_core_api_peer1.conf");
- setup_peer (&p2, "test_core_api_peer2.conf");
+ setup_peer (&p1,
+ "test_core_api_peer1.conf");
+ setup_peer (&p2,
+ "test_core_api_peer2.conf");
err_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 300),
&terminate_task_error, NULL);
p1.ch =
- GNUNET_CORE_connect (p1.cfg, &p1,
+ GNUNET_CORE_connecT (p1.cfg,
+ &p1,
&init_notify,
&connect_notify,
&disconnect_notify,
- &inbound_notify, GNUNET_YES,
- &outbound_notify, GNUNET_YES,
handlers);
}
static void
stop_arm (struct PeerContext *p)
{
- if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
+ if (0 != GNUNET_OS_process_kill (p->arm_proc,
+ GNUNET_TERM_SIG))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "kill");
+ if (GNUNET_OK !=
+ GNUNET_OS_process_wait (p->arm_proc))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_destroy (p->arm_proc);
p->arm_proc = NULL;
/*
This file is part of GNUnet.
- Copyright (C) 2009 GNUnet e.V.
+ Copyright (C) 2009, 2016 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
* @file transport/test_core_api_start_only.c
* @brief testcase for core_api.c that only starts two peers,
* connects to the core service and shuts down again
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_arm_service.h"
static int ok;
-static void
+static void *
connect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
+ return NULL;
}
static void
disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
-{
-}
-
-
-static int
-inbound_notify (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
- return GNUNET_OK;
-}
-
-
-static int
-outbound_notify (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_PeerIdentity *peer,
+ void *internal_cls)
{
- return GNUNET_OK;
}
-static struct GNUNET_CORE_MessageHandler handlers[] = {
- {NULL, 0, 0}
+static struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_handler_end ()
};
static void
shutdown_task (void *cls)
{
- GNUNET_CORE_disconnect (p1.ch);
+ GNUNET_CORE_disconnecT (p1.ch);
p1.ch = NULL;
- GNUNET_CORE_disconnect (p2.ch);
+ GNUNET_CORE_disconnecT (p2.ch);
p2.ch = NULL;
ok = 0;
}
if (p == &p1)
{
/* connect p2 */
- p2.ch =
- GNUNET_CORE_connect (p2.cfg,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- &inbound_notify, GNUNET_YES,
- &outbound_notify, GNUNET_YES,
- handlers);
+ p2.ch = GNUNET_CORE_connecT (p2.cfg,
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ handlers);
}
else
{
static void
timeout_task (void *cls)
{
- FPRINTF (stderr, "%s", "Timeout.\n");
+ FPRINTF (stderr,
+ "%s",
+ "Timeout.\n");
if (NULL != p1.ch)
{
- GNUNET_CORE_disconnect (p1.ch);
+ GNUNET_CORE_disconnecT (p1.ch);
p1.ch = NULL;
}
if (NULL != p2.ch)
{
- GNUNET_CORE_disconnect (p2.ch);
+ GNUNET_CORE_disconnecT (p2.ch);
p2.ch = NULL;
}
ok = 42;
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MINUTES,
TIMEOUT),
- &timeout_task, NULL);
- p1.ch = GNUNET_CORE_connect (p1.cfg,
+ &timeout_task,
+ NULL);
+ p1.ch = GNUNET_CORE_connecT (p1.cfg,
&p1,
&init_notify,
&connect_notify,
&disconnect_notify,
- &inbound_notify, GNUNET_YES,
- &outbound_notify, GNUNET_YES,
handlers);
}