/**
* @file core/test_core_api.c
* @brief testcase for core_api.c
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_arm_service.h"
}
-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)
+static void
+handle_test (void *cls,
+ 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;
-}
+ const struct GNUNET_PeerIdentity *peer = cls;
-
-static int
-process_mtype (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
-{
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)
{
struct PeerContext *p = cls;
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_fixed_size (test,
+ MTYPE,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ()
+ };
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core connection to `%s' established\n",
&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)
{
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_fixed_size (test,
+ MTYPE,
+ struct GNUNET_MessageHeader,
+ 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;