[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26467 - gnunet/src/dv
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26467 - gnunet/src/dv |
Date: |
Mon, 18 Mar 2013 11:36:29 +0100 |
Author: grothoff
Date: 2013-03-18 11:36:29 +0100 (Mon, 18 Mar 2013)
New Revision: 26467
Added:
gnunet/src/dv/gnunet-dv.c
Modified:
gnunet/src/dv/Makefile.am
gnunet/src/dv/gnunet-service-dv.c
Log:
-enable DV status monitoring
Modified: gnunet/src/dv/Makefile.am
===================================================================
--- gnunet/src/dv/Makefile.am 2013-03-18 10:08:44 UTC (rev 26466)
+++ gnunet/src/dv/Makefile.am 2013-03-18 10:36:29 UTC (rev 26467)
@@ -32,6 +32,9 @@
-version-info 0:0:0
+noinst_PROGRAMS = \
+ gnunet-dv
+
libexec_PROGRAMS = \
gnunet-service-dv
@@ -44,6 +47,13 @@
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
+gnunet_dv_SOURCES = \
+ gnunet-dv.c dv.h
+gnunet_dv_LDADD = \
+ libgnunetdv.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(GN_LIBINTL)
+
libgnunet_plugin_transport_dv_la_SOURCES = \
plugin_transport_dv.c
libgnunet_plugin_transport_dv_la_LIBADD = \
Added: gnunet/src/dv/gnunet-dv.c
===================================================================
--- gnunet/src/dv/gnunet-dv.c (rev 0)
+++ gnunet/src/dv/gnunet-dv.c 2013-03-18 10:36:29 UTC (rev 26467)
@@ -0,0 +1,184 @@
+/*
+ This file is part of GNUnet.
+ (C) 2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+/**
+ * @file dv/gnunet-dv.c
+ * @brief DV monitoring command line tool
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_dv_service.h"
+
+/**
+ * Handle to DV service.
+ */
+static struct GNUNET_DV_ServiceHandle *sh;
+
+/**
+ * Was verbose specified?
+ */
+static int verbose;
+
+
+/**
+ * Function called if DV starts to be able to talk to a peer.
+ *
+ * @param cls closure
+ * @param peer newly connected peer
+ * @param distance distance to the peer
+ */
+static void
+connect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ uint32_t distance)
+{
+ fprintf (stderr, "Connect: %s at %u\n",
+ GNUNET_i2s (peer),
+ (unsigned int) distance);
+}
+
+
+/**
+ * Function called if DV distance to a peer is changed.
+ *
+ * @param cls closure
+ * @param peer connected peer
+ * @param distance new distance to the peer
+ */
+static void
+change_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ uint32_t distance)
+{
+ fprintf (stderr, "Change: %s at %u\n",
+ GNUNET_i2s (peer),
+ (unsigned int) distance);
+}
+
+
+/**
+ * Function called if DV is no longer able to talk to a peer.
+ *
+ * @param cls closure
+ * @param peer peer that disconnected
+ */
+static void
+disconnect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ fprintf (stderr, "Disconnect: %s\n",
+ GNUNET_i2s (peer));
+}
+
+
+/**
+ * Function called if DV receives a message for this peer.
+ *
+ * @param cls closure
+ * @param sender sender of the message
+ * @param distance how far did the message travel
+ * @param msg actual message payload
+ */
+static void
+message_cb (void *cls,
+ const struct GNUNET_PeerIdentity *sender,
+ uint32_t distance,
+ const struct GNUNET_MessageHeader *msg)
+{
+ if (verbose)
+ fprintf (stderr, "Message: %s at %u sends %u bytes of type %u\n",
+ GNUNET_i2s (sender),
+ (unsigned int) distance,
+ (unsigned int) ntohs (msg->size),
+ (unsigned int) ntohs (msg->type));
+}
+
+
+/**
+ * Task run on shutdown.
+ *
+ * @param cls NULL
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_DV_service_disconnect (sh);
+ sh = NULL;
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ sh = GNUNET_DV_service_connect (cfg, NULL,
+ &connect_cb,
+ &change_cb,
+ &disconnect_cb,
+ &message_cb);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
+}
+
+
+/**
+ * The main function.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+ int res;
+
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ {'V', "verbose", NULL,
+ gettext_noop ("verbose output"),
+ 0, &GNUNET_GETOPT_set_one, &verbose},
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
+ res = GNUNET_PROGRAM_run (argc, argv, "gnunet-dv",
+ gettext_noop ("Print information about DV state"),
+ options, &run,
+ NULL);
+ GNUNET_free ((void *) argv);
+
+ if (GNUNET_OK != res)
+ return 1;
+ return 0;
+}
+
+/* end of gnunet-dv.c */
Modified: gnunet/src/dv/gnunet-service-dv.c
===================================================================
--- gnunet/src/dv/gnunet-service-dv.c 2013-03-18 10:08:44 UTC (rev 26466)
+++ gnunet/src/dv/gnunet-service-dv.c 2013-03-18 10:36:29 UTC (rev 26467)
@@ -52,6 +52,11 @@
#define MAX_QUEUE_SIZE 16
/**
+ * Maximum number of messages we queue towards the clients/plugin.
+ */
+#define MAX_QUEUE_SIZE_PLUGIN 1024
+
+/**
* The default fisheye depth, from how many hops away will
* we keep peers?
*/
@@ -317,28 +322,13 @@
static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
- * The client, the DV plugin connected to us. Hopefully
- * this client will never change, although if the plugin dies
- * and returns for some reason it may happen.
+ * The client, the DV plugin connected to us (or an event monitor).
+ * Hopefully this client will never change, although if the plugin
+ * dies and returns for some reason it may happen.
*/
-static struct GNUNET_SERVER_Client *client_handle;
+static struct GNUNET_SERVER_NotificationContext *nc;
/**
- * Transmit handle to the plugin.
- */
-static struct GNUNET_SERVER_TransmitHandle *plugin_transmit_handle;
-
-/**
- * Head of DLL for client messages
- */
-static struct PendingMessage *plugin_pending_head;
-
-/**
- * Tail of DLL for client messages
- */
-static struct PendingMessage *plugin_pending_tail;
-
-/**
* Handle for the statistics service.
*/
struct GNUNET_STATISTICS_Handle *stats;
@@ -366,51 +356,6 @@
/**
- * Function called to notify a client about the socket
- * begin ready to queue more data. "buf" will be
- * NULL and "size" zero if the socket was closed for
- * writing in the meantime.
- *
- * @param cls closure
- * @param size number of bytes available in buf
- * @param buf where the callee should write the message
- * @return number of bytes written to buf
- */
-static size_t
-transmit_to_plugin (void *cls, size_t size, void *buf)
-{
- char *cbuf = buf;
- struct PendingMessage *reply;
- size_t off;
- size_t msize;
-
- plugin_transmit_handle = NULL;
- if (NULL == buf)
- {
- /* client disconnected */
- return 0;
- }
- off = 0;
- while ( (NULL != (reply = plugin_pending_head)) &&
- (size >= off + (msize = ntohs (reply->msg->size))))
- {
- GNUNET_CONTAINER_DLL_remove (plugin_pending_head, plugin_pending_tail,
- reply);
- memcpy (&cbuf[off], reply->msg, msize);
- GNUNET_free (reply);
- off += msize;
- }
- if (NULL != plugin_pending_head)
- plugin_transmit_handle =
- GNUNET_SERVER_notify_transmit_ready (client_handle,
- msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_plugin, NULL);
- return off;
-}
-
-
-/**
* Forward a message from another peer to the plugin.
*
* @param message the message to send to the plugin
@@ -423,18 +368,8 @@
uint32_t distance)
{
struct GNUNET_DV_ReceivedMessage *received_msg;
- struct PendingMessage *pending_message;
size_t size;
- if (NULL == client_handle)
- {
- GNUNET_STATISTICS_update (stats,
- "# messages discarded (no plugin)",
- 1, GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Refusing to queue messages, DV plugin not active.\n"));
- return;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delivering message from peer `%s'\n",
GNUNET_i2s (origin));
@@ -445,21 +380,16 @@
GNUNET_break (0); /* too big */
return;
}
- pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + size);
- received_msg = (struct GNUNET_DV_ReceivedMessage *) &pending_message[1];
+ received_msg = GNUNET_malloc (size);
received_msg->header.size = htons (size);
received_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DV_RECV);
received_msg->distance = htonl (distance);
received_msg->sender = *origin;
memcpy (&received_msg[1], message, ntohs (message->size));
- GNUNET_CONTAINER_DLL_insert_tail (plugin_pending_head,
- plugin_pending_tail,
- pending_message);
- if (NULL == plugin_transmit_handle)
- plugin_transmit_handle =
- GNUNET_SERVER_notify_transmit_ready (client_handle, size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_plugin, NULL);
+ GNUNET_SERVER_notification_context_broadcast (nc,
+ &received_msg->header,
+ GNUNET_YES);
+ GNUNET_free (received_msg);
}
@@ -473,29 +403,9 @@
static void
send_control_to_plugin (const struct GNUNET_MessageHeader *message)
{
- struct PendingMessage *pending_message;
- size_t size;
-
- if (NULL == client_handle)
- {
- GNUNET_STATISTICS_update (stats,
- "# control messages discarded (no plugin)",
- 1, GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Refusing to queue messages, DV plugin not active.\n"));
- return;
- }
- size = ntohs (message->size);
- pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + size);
- memcpy (&pending_message[1], message, size);
- GNUNET_CONTAINER_DLL_insert_tail (plugin_pending_head,
- plugin_pending_tail,
- pending_message);
- if (NULL == plugin_transmit_handle)
- plugin_transmit_handle =
- GNUNET_SERVER_notify_transmit_ready (client_handle, size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_plugin, NULL);
+ GNUNET_SERVER_notification_context_broadcast (nc,
+ message,
+ GNUNET_NO);
}
@@ -561,8 +471,6 @@
{
struct GNUNET_DV_ConnectMessage cm;
- if (NULL == client_handle)
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delivering CONNECT about peer `%s'\n",
GNUNET_i2s (target));
@@ -584,8 +492,6 @@
{
struct GNUNET_DV_DisconnectMessage dm;
- if (NULL == client_handle)
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delivering DISCONNECT about peer `%s'\n",
GNUNET_i2s (target));
@@ -1535,7 +1441,6 @@
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct PendingMessage *pending;
unsigned int i;
GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
@@ -1548,13 +1453,8 @@
core_api = NULL;
GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
stats = NULL;
- while (NULL != (pending = plugin_pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
- plugin_pending_tail,
- pending);
- GNUNET_free (pending);
- }
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
for (i=0;i<DEFAULT_FISHEYE_DEPTH - 1;i++)
GNUNET_array_grow (consensi[i].targets,
consensi[i].array_length,
@@ -1563,6 +1463,36 @@
/**
+ * Notify newly connected client about an existing route.
+ *
+ * @param cls the 'struct GNUNET_SERVER_Client'
+ * @param key peer identity
+ * @param value the XXX.
+ * @return GNUNET_OK (continue to iterate)
+ */
+static int
+add_route (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct GNUNET_SERVER_Client *client = cls;
+ struct Route *route = value;
+ struct GNUNET_DV_ConnectMessage cm;
+
+ cm.header.size = htons (sizeof (cm));
+ cm.header.type = htons (GNUNET_MESSAGE_TYPE_DV_CONNECT);
+ cm.distance = htonl (route->target.distance);
+ cm.peer = route->target.peer;
+
+ GNUNET_SERVER_notification_context_unicast (nc,
+ client,
+ &cm.header,
+ GNUNET_NO);
+ return GNUNET_OK;
+}
+
+
+/**
* Handle START-message. This is the first message sent to us
* by the client (can only be one!).
*
@@ -1574,15 +1504,10 @@
handle_start (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- if (NULL != client_handle)
- {
- /* forcefully drop old client */
- GNUNET_SERVER_client_disconnect (client_handle);
- GNUNET_SERVER_client_drop (client_handle);
- }
- client_handle = client;
- GNUNET_SERVER_client_keep (client_handle);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_notification_context_add (nc, client);
+ GNUNET_CONTAINER_multihashmap_iterate (all_routes,
+ &add_route,
+ client);
}
@@ -1642,6 +1567,8 @@
if (NULL == core_api)
return;
+ nc = GNUNET_SERVER_notification_context_create (server,
+ MAX_QUEUE_SIZE_PLUGIN);
stats = GNUNET_STATISTICS_create ("dv", cfg);
GNUNET_SERVER_add_handlers (server, plugin_handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26467 - gnunet/src/dv,
gnunet <=