/*
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
/*
This file is part of GNUnet.
- Copyright (C) 2009, 2010, 2014 GNUnet e.V.
+ Copyright (C) 2009, 2010, 2014, 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
/**
* Handle for the client.
*/
-static struct GNUNET_CLIENT_Connection *cc;
+static struct GNUNET_MQ_Handle *mq;
/**
* Handle of the server for the client.
GNUNET_assert (7 == ok);
ok = 0;
GNUNET_SERVER_destroy (server);
- GNUNET_CLIENT_disconnect (cc);
+ GNUNET_MQ_destroy (mq);
GNUNET_CONFIGURATION_destroy (cfg);
}
}
-/**
- * The client connected to the server and is now allowed
- * to send a second message. We send one.
- *
- * @param cls NULL
- * @param size number of bytes that can be transmitted
- * @param buf where to copy the message
- * @return number of bytes copied to @a buf
- */
-static size_t
-transmit_second_message (void *cls,
- size_t size,
- void *buf)
-{
- struct GNUNET_MessageHeader msg;
-
- GNUNET_assert (5 == ok);
- ok = 6;
- GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
- msg.type = htons (MY_TYPE2);
- msg.size = htons (sizeof (struct GNUNET_MessageHeader));
- memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader));
- return sizeof (struct GNUNET_MessageHeader);
-}
-
-
/**
* We have received the reply from the server, check that we are at
* the right stage and queue the next message to the server. Cleans
* @param msg message we got from the server
*/
static void
-first_reply_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_reply (void *cls,
+ const struct GNUNET_MessageHeader *msg)
{
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *m;
+
GNUNET_assert (4 == ok);
- ok = 5;
- GNUNET_assert (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (cc,
- sizeof (struct GNUNET_MessageHeader),
- TIMEOUT,
- GNUNET_YES,
- &transmit_second_message,
- NULL));
+ ok = 6;
+ env = GNUNET_MQ_msg (m,
+ MY_TYPE2);
+ GNUNET_MQ_send (mq,
+ env);
}
GNUNET_assert (NULL !=
GNUNET_SERVER_notify_transmit_ready (client,
ntohs (message->size),
- TIMEOUT, &reply_msg,
+ TIMEOUT,
+ &reply_msg,
NULL));
}
-/**
- * The client connected to the server and is now allowed
- * to send a first message. We transmit a simple message,
- * ask for a second transmission and get ready to receive
- * a response.
- *
- * @param cls NULL
- * @param size number of bytes that can be transmitted
- * @param buf where to copy the message
- * @return number of bytes copied to @a buf
- */
-static size_t
-transmit_initial_message (void *cls,
- size_t size,
- void *buf)
-{
- struct GNUNET_MessageHeader msg;
-
- GNUNET_assert (1 == ok);
- ok = 2;
- GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
- msg.type = htons (MY_TYPE);
- msg.size = htons (sizeof (struct GNUNET_MessageHeader));
- memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader));
- GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT);
- return sizeof (struct GNUNET_MessageHeader);
-}
-
-
/**
* Message handlers for the server.
*/
};
+/**
+ * Generic error handler, called with the appropriate error code and
+ * the same closure specified at the creation of the message queue.
+ * Not every message queue implementation supports an error handler.
+ *
+ * @param cls closure with the `struct GNUNET_STATISTICS_Handle *`
+ * @param error error code
+ */
+static void
+mq_error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
+{
+ GNUNET_assert (0); /* should never happen */
+}
+
+
/**
* First task run by the scheduler. Initializes the server and
* a client and asks for a transmission from the client to the
struct sockaddr_in sa;
struct sockaddr *sap[2];
socklen_t slens[2];
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *msg;
+ GNUNET_MQ_hd_fixed_size (reply,
+ MY_TYPE,
+ struct GNUNET_MessageHeader);
+ struct GNUNET_MQ_MessageHandler chandlers[] = {
+ make_reply_handler (cls),
+ GNUNET_MQ_handler_end ()
+ };
+
sap[0] = (struct sockaddr *) &sa;
slens[0] = sizeof (sa);
"resolver",
"HOSTNAME",
"localhost");
- cc = GNUNET_CLIENT_connect ("test-server", cfg);
- GNUNET_assert (cc != NULL);
- GNUNET_assert (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (cc,
- sizeof (struct
- GNUNET_MessageHeader),
- TIMEOUT, GNUNET_YES,
- &transmit_initial_message,
- NULL));
+ mq = GNUNET_CLIENT_connecT (cfg,
+ "test-server",
+ chandlers,
+ &mq_error_handler,
+ NULL);
+ GNUNET_assert (NULL != mq);
+ ok = 2;
+ env = GNUNET_MQ_msg (msg,
+ MY_TYPE);
+ GNUNET_MQ_send (mq,
+ env);
}
/*
This file is part of GNUnet.
- Copyright (C) 2009, 2013 GNUnet e.V.
+ Copyright (C) 2009, 2013, 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
static int ok = 1;
-static struct GNUNET_CLIENT_Connection *client;
+static struct GNUNET_MQ_Handle *mq;
static void
do_stop (void *cls)
{
- if (NULL != client)
+ if (NULL != mq)
{
- GNUNET_CLIENT_disconnect (client);
- client = NULL;
+ GNUNET_MQ_destroy (mq);
+ mq = NULL;
}
if (NULL != sctx)
{
}
-static size_t
-build_msg (void *cls, size_t size, void *buf)
-{
- struct GNUNET_MessageHeader *msg = buf;
-
- if (size < sizeof (struct GNUNET_MessageHeader))
- {
- /* timeout */
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&do_stop, NULL);
- ok = 1;
- return 0;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected, transmitting\n");
- GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
- msg->type = htons (MY_TYPE);
- msg->size = htons (sizeof (struct GNUNET_MessageHeader));
- return sizeof (struct GNUNET_MessageHeader);
-}
-
-
static void
ready (void *cls,
int result)
{
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *msg;
GNUNET_assert (GNUNET_YES == result);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n");
- client = GNUNET_CLIENT_connect ("test_service", cfg);
- GNUNET_assert (client != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client connecting, waiting to transmit\n");
- GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
- &build_msg, NULL);
+ "Service confirmed running\n");
+ mq = GNUNET_CLIENT_connecT (cfg,
+ "test_service",
+ NULL,
+ NULL,
+ NULL);
+ GNUNET_assert (NULL != mq);
+ env = GNUNET_MQ_msg (msg,
+ MY_TYPE);
+ GNUNET_MQ_send (mq,
+ env);
}
static void
-recv_cb (void *cls, struct GNUNET_SERVER_Client *sc,
+recv_cb (void *cls,
+ struct GNUNET_SERVER_Client *sc,
const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (NULL != message);
static void
-runner (void *cls, struct GNUNET_SERVER_Handle *server,
+runner (void *cls,
+ struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n");
- GNUNET_SERVER_add_handlers (server, myhandlers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service initializing\n");
+ GNUNET_SERVER_add_handlers (server,
+ myhandlers);
GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS,
&ready, (void *) cfg);
}
int result)
{
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n");
GNUNET_assert (GNUNET_YES == result);
- client = GNUNET_CLIENT_connect ("test_service6", cfg);
- GNUNET_assert (client != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n");
- GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
- &build_msg, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "V6 ready\n");
+ mq = GNUNET_CLIENT_connecT (cfg,
+ "test_service6",
+ NULL,
+ NULL,
+ NULL);
+ GNUNET_assert (NULL != mq);
+ env = GNUNET_MQ_msg (msg,
+ MY_TYPE);
+ GNUNET_MQ_send (mq,
+ env);
}
static void
-runner6 (void *cls, struct GNUNET_SERVER_Handle *server,
+runner6 (void *cls,
+ struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
/*
This file is part of GNUnet.
- Copyright (C) 2015 GNUnet e.V.
+ Copyright (C) 2015, 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