[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r5869 - in GNUnet/src: applications/tracekit include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r5869 - in GNUnet/src: applications/tracekit include |
Date: |
Tue, 11 Dec 2007 23:42:38 -0700 (MST) |
Author: grothoff
Date: 2007-12-11 23:42:38 -0700 (Tue, 11 Dec 2007)
New Revision: 5869
Added:
GNUnet/src/applications/tracekit/clientapi.c
GNUnet/src/applications/tracekit/tracekittest.c
GNUnet/src/include/gnunet_tracekit_lib.h
Log:
tracekit refactoring
Added: GNUnet/src/applications/tracekit/clientapi.c
===================================================================
--- GNUnet/src/applications/tracekit/clientapi.c
(rev 0)
+++ GNUnet/src/applications/tracekit/clientapi.c 2007-12-12 06:42:38 UTC
(rev 5869)
@@ -0,0 +1,103 @@
+/*
+ This file is part of GNUnet.
+ (C) 2007 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 2, 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 applications/tracekit/clientapi.c
+ * @brief tool that sends a trace request and prints the received network
topology
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_util.h"
+#include "gnunet_tracekit_lib.h"
+#include "tracekit.h"
+
+/**
+ * Ask gnunetd to perform a network topology trace
+ *
+ * @param sock socket to query gnunetd over -- close the socket
+ * to abort the trace
+ * @param depth how deep should the probe go?
+ * @param priority what priority should the probe have?
+ * @param report callback function to call with the results
+ * @param cls extra argument to report function
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int GNUNET_TRACEKIT_run (struct GNUNET_ClientServerConnection *sock,
+ unsigned int depth,
+ unsigned int priority,
+ GNUNET_TRACEKIT_ReportCallback report,
+ void * cls) {
+ CS_tracekit_probe_MESSAGE probe;
+ CS_tracekit_reply_MESSAGE *reply;
+ int i;
+ int count;
+
+ probe.header.size = htons (sizeof (CS_tracekit_probe_MESSAGE));
+ probe.header.type = htons (GNUNET_CS_PROTO_TRACEKIT_PROBE);
+ probe.hops = htonl(depth);
+ probe.priority = htonl(priority);
+ if (GNUNET_SYSERR == GNUNET_client_connection_write (sock, &probe.header))
+ return GNUNET_SYSERR;
+ reply = NULL;
+ while (GNUNET_OK ==
+ GNUNET_client_connection_read (sock,
+ (GNUNET_MessageHeader **) &reply))
+ {
+ count =
+ ntohs (reply->header.size) - sizeof (CS_tracekit_reply_MESSAGE);
+ if ( (count < 0) ||
+ (0 != count % sizeof (GNUNET_PeerIdentity)) )
+ {
+ GNUNET_GE_BREAK (NULL, 0);
+ return GNUNET_SYSERR;
+ }
+ count = count / sizeof (GNUNET_PeerIdentity);
+ if (count == 0)
+ {
+ if (GNUNET_OK !=
+ report(cls,
+ &reply->responderId,
+ NULL) ) {
+ GNUNET_free(reply);
+ return GNUNET_OK; /* application aborted */
+ }
+ }
+ else
+ {
+ for (i=0;i<count;i++)
+ {
+ if (GNUNET_OK !=
+ report(cls,
+ &reply->responderId,
+ &((GNUNET_PeerIdentity*) &reply[1])[i]))
+ {
+ GNUNET_free(reply);
+ return GNUNET_OK; /* application aborted */
+ }
+ }
+ }
+ GNUNET_free (reply);
+ reply = NULL;
+ }
+ return GNUNET_OK;
+}
+
Property changes on: GNUnet/src/applications/tracekit/clientapi.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: GNUnet/src/applications/tracekit/tracekittest.c
===================================================================
--- GNUnet/src/applications/tracekit/tracekittest.c
(rev 0)
+++ GNUnet/src/applications/tracekit/tracekittest.c 2007-12-12 06:42:38 UTC
(rev 5869)
@@ -0,0 +1,98 @@
+/*
+ This file is part of GNUnet.
+ (C) 2005, 2006, 2007 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 2, 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file applications/tracekit/tracekittest.c
+ * @brief tracekit testcase, linear topology
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_tracekit_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util.h"
+
+#define START_PEERS 1
+
+#define PEER_COUNT 4
+
+#define SIZE 1024 * 1024 * 2
+
+static struct GNUNET_GE_Context *ectx;
+
+static struct GNUNET_GC_Configuration *cfg;
+
+/**
+ * Testcase to test tracekit
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, char **argv)
+{
+ struct GNUNET_TESTING_DaemonContext *peers;
+ int ret;
+ int i;
+ char buf[128];
+ GNUNET_CronTime start;
+
+ ret = 0;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+#if START_PEERS
+ peers = GNUNET_TESTING_start_daemons ("tcp",
+ "advertising topology tracekit stats",
+ "/tmp/gnunet-tracekit-test",
+ 2087, 10, PEER_COUNT);
+ if (peers == NULL)
+ {
+ fprintf (stderr, "Failed to start the gnunetd daemons!\n");
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+#endif
+ for (i = 1; i < PEER_COUNT; i++)
+ {
+ if (GNUNET_OK != GNUNET_TESTING_connect_daemons (2077 + (10 * i),
+ 2087 + (10 * i)))
+ {
+ GNUNET_TESTING_stop_daemons (peers);
+ fprintf (stderr, "Failed to connect the peers!\n");
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ }
+
+
+FAILURE:
+#if START_PEERS
+ GNUNET_TESTING_stop_daemons (peers);
+#endif
+
+ GNUNET_GC_free (cfg);
+ return ret;
+}
+
+/* end of tracekittest.c */
Property changes on: GNUnet/src/applications/tracekit/tracekittest.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: GNUnet/src/include/gnunet_tracekit_lib.h
===================================================================
--- GNUnet/src/include/gnunet_tracekit_lib.h (rev 0)
+++ GNUnet/src/include/gnunet_tracekit_lib.h 2007-12-12 06:42:38 UTC (rev
5869)
@@ -0,0 +1,80 @@
+/*
+ This file is part of GNUnet
+ (C) 2004, 2005, 2006, 2007 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 2, 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 include/gnunet_tracekit_lib.h
+ * @brief convenience API to the TRACEKIT service
+ * @author Christian Grothoff
+ */
+
+#ifndef GNUNET_TRACEKIT_LIB_H
+#define GNUNET_TRACEKIT_LIB_H
+
+#include "gnunet_util.h"
+#include "gnunet_util_network_client.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+/**
+ * Function signature for data gathering callback
+ *
+ * @param reporter identity of the peer reporting a connection
+ * @param link identity of another peer that the reporting peer
+ * is reported to be connected to, or NULL if the
+ * peer is reporting to have no connections at all
+ * @return GNUNET_OK to continue data gathering,
+ * GNUNET_SYSERR to abort
+ */
+typedef int (*GNUNET_TRACEKIT_ReportCallback)(void * cls,
+ const GNUNET_PeerIdentity *
reporter,
+ const GNUNET_PeerIdentity * link);
+
+/**
+ * Ask gnunetd to perform a network topology trace
+ *
+ * @param sock socket to query gnunetd over -- close the socket
+ * to abort the trace
+ * @param depth how deep should the probe go?
+ * @param priority what priority should the probe have?
+ * @param report callback function to call with the results
+ * @param cls extra argument to report function
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int GNUNET_TRACEKIT_run (struct GNUNET_ClientServerConnection *sock,
+ unsigned int depth,
+ unsigned int priority,
+ GNUNET_TRACEKIT_ReportCallback report,
+ void * cls);
+
+#if 0 /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
Property changes on: GNUnet/src/include/gnunet_tracekit_lib.h
___________________________________________________________________
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r5869 - in GNUnet/src: applications/tracekit include,
gnunet <=