gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r193 - in GNUnet/src: applications applications/fs/module a


From: grothoff
Subject: [GNUnet-SVN] r193 - in GNUnet/src: applications applications/fs/module applications/stats applications/testbed include
Date: Mon, 7 Feb 2005 05:50:30 -0800 (PST)

Author: grothoff
Date: 2005-02-07 05:50:29 -0800 (Mon, 07 Feb 2005)
New Revision: 193

Added:
   GNUnet/src/applications/stats/clientapi.c
   GNUnet/src/include/gnunet_stats_lib.h
Removed:
   GNUnet/src/applications/afs2/
   GNUnet/src/applications/common/
   GNUnet/src/applications/testbed/get-stats.c
   GNUnet/src/applications/testbed/get-stats.h
Modified:
   GNUnet/src/applications/Makefile.am
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/applications/stats/Makefile.am
   GNUnet/src/applications/stats/gnunet-stats.c
   GNUnet/src/applications/testbed/Makefile.am
   GNUnet/src/applications/testbed/commands.c
   GNUnet/src/applications/testbed/gnunet-testbed.c
   GNUnet/src/applications/testbed/testbed.c
   GNUnet/src/include/Makefile.am
Log:
making testbed compile, refactoring of stats code to add stats library

Modified: GNUnet/src/applications/Makefile.am
===================================================================
--- GNUnet/src/applications/Makefile.am 2005-02-06 13:07:43 UTC (rev 192)
+++ GNUnet/src/applications/Makefile.am 2005-02-07 13:50:29 UTC (rev 193)
@@ -14,6 +14,9 @@
  session \
  sqstore_mysql \
  stats \
+ tbench \
+ template \
+ testbed \
  topology_default \
  traffic \
  transport

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/fs/module/fs.c      2005-02-07 13:50:29 UTC (rev 
193)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing 
authors)
+     (C) 2001, 2002, 2003, 2004, 2005 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
@@ -360,7 +360,7 @@
 static int csHandleRequestIndex(ClientHandle sock,
                                const CS_HEADER * req) {
   int ret;
-  RequestIndex * ri;
+  const RequestIndex * ri;
   
   LOG(LOG_DEBUG,
       "Received index request from client\n");
@@ -368,7 +368,7 @@
     BREAK();
     return SYSERR;
   }
-  ri = (RequestIndex*) req;
+  ri = (const RequestIndex*) req;
   ret = ONDEMAND_index(datastore,
                       ntohl(ri->prio),
                       ntohll(ri->expiration),
@@ -376,7 +376,7 @@
                       ntohl(ri->anonymityLevel),
                       &ri->fileId,
                       ntohs(ri->header.size) - sizeof(RequestIndex),
-                      &ri[1]);
+                      (const char*) &ri[1]);
   LOG(LOG_DEBUG,
       "Sending confirmation of index request to client\n");
   return coreAPI->sendValueToClient(sock,

Modified: GNUnet/src/applications/stats/Makefile.am
===================================================================
--- GNUnet/src/applications/stats/Makefile.am   2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/stats/Makefile.am   2005-02-07 13:50:29 UTC (rev 
193)
@@ -8,13 +8,24 @@
 plugin_LTLIBRARIES = \
   libgnunetmodule_stats.la
 
+lib_LTLIBRARIES = \
+  libgnunetstats_api.la
+
 bin_PROGRAMS = \
  gnunet-stats
 
 
 gnunet_stats_SOURCES = \
  gnunet-stats.c        
+gnunet_stats_LDADD = \
+  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/util/libgnunetutil.la
 
+libgnunetstats_api_la_SOURCES = \
+  clientapi.c 
+libgnunetstats_api_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la
+
 libgnunetmodule_stats_la_SOURCES = \
   statistics.c \
   statistics.h
@@ -22,3 +33,4 @@
   $(top_builddir)/src/util/libgnunetutil.la
 libgnunetmodule_stats_la_LDFLAGS = \
   -export-dynamic -avoid-version -module
+

Added: GNUnet/src/applications/stats/clientapi.c
===================================================================
--- GNUnet/src/applications/stats/clientapi.c   2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/stats/clientapi.c   2005-02-07 13:50:29 UTC (rev 
193)
@@ -0,0 +1,262 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2004, 2005 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/stats/clientapi.c 
+ * @brief convenience API to the stats service
+ * @author Christian Grothoff
+ * @author Igor Wronsky
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_protocols.h"
+#include "gnunet_stats_lib.h"
+#include "statistics.h"
+
+/**
+ * Return a descriptive name for a p2p message type
+ */
+const char * p2pMessageName(unsigned short type) {
+  const char *name = NULL;
+
+  switch( type ) {
+  case p2p_PROTO_HELO : 
+    name = "p2p_PROTO_HELO";
+    break;
+  case p2p_PROTO_SKEY : 
+    name = "p2p_PROTO_SKEY";
+    break;
+  case p2p_PROTO_PING : 
+    name = "p2p_PROTO_PING";
+    break;
+  case p2p_PROTO_PONG : 
+    name = "p2p_PROTO_PONG";
+    break;
+  case p2p_PROTO_NOISE : 
+    name = "p2p_PROTO_NOISE";
+    break;
+  case p2p_PROTO_HANGUP : 
+    name = "p2p_PROTO_HANGUP";
+    break;
+  case CHAT_p2p_PROTO_MSG : 
+    name = "CHAT_p2p_PROTO_MSG";
+    break;
+  case TRACEKIT_p2p_PROTO_PROBE : 
+    name = "TRACEKIT_p2p_PROTO_PROBE";
+    break;
+  case TRACEKIT_p2p_PROTO_REPLY : 
+    name = "TRACEKIT_p2p_PROTO_REPLY";
+    break;
+  case TBENCH_p2p_PROTO_REQUEST        : 
+    name = "TBENCH_p2p_PROTO_REQUEST";
+    break;
+  case TBENCH_p2p_PROTO_REPLY  : 
+    name = "TBENCH_p2p_PROTO_REPLY";
+    break;
+  default:
+    name = NULL;
+    break;
+  }
+  return name;
+
+}
+
+/**
+ * Return a descriptive name for a client server message type
+ */
+const char *csMessageName(unsigned short type) {
+  const char *name = NULL;
+
+  switch( type ) {
+  case CS_PROTO_RETURN_VALUE : 
+    name = "CS_PROTO_RETURN_VALUE";
+    break;
+  case CS_PROTO_CLIENT_COUNT : 
+    name = "CS_PROTO_CLIENT_COUNT";
+    break;
+  case CS_PROTO_TRAFFIC_QUERY : 
+    name = "CS_PROTO_TRAFFIC_QUERY";
+    break;
+  case CS_PROTO_TRAFFIC_INFO : 
+    name = "CS_PROTO_TRAFFIC_INFO";
+    break;
+  case STATS_CS_PROTO_GET_STATISTICS : 
+    name = "STATS_CS_PROTO_GET_STATISTICS";
+    break;
+  case STATS_CS_PROTO_STATISTICS : 
+    name = "STATS_CS_PROTO_STATISTICS";
+    break;
+  case STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED : 
+    name = "STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED";
+    break;
+  case STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED : 
+    name = "STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED";
+    break;
+  case CHAT_CS_PROTO_MSG : 
+    name = "CHAT_CS_PROTO_MSG";
+    break;
+  case TRACEKIT_CS_PROTO_PROBE : 
+    name = "TRACEKIT_CS_PROTO_PROBE";
+    break;
+  case TRACEKIT_CS_PROTO_REPLY : 
+    name = "TRACEKIT_CS_PROTO_REPLY";
+    break;
+  case TBENCH_CS_PROTO_REQUEST : 
+    name = "TBENCH_CS_PROTO_REQUEST";
+    break;
+  case TBENCH_CS_PROTO_REPLY : 
+    name = "TBENCH_CS_PROTO_REPLY";
+    break;
+  default:
+    name = NULL;
+    break;    
+  }
+  return name;
+}
+
+/**
+ * Request statistics from TCP socket.
+ * @param sock the socket to use 
+ * @param processor function to call on each value
+ * @return OK on success, SYSERR on error
+ */
+int requestStatistics(GNUNET_TCP_SOCKET * sock,
+                     StatisticsProcessor processor,
+                     void * cls) {
+  STATS_CS_MESSAGE * statMsg;
+  CS_HEADER csHdr;
+  unsigned int count;
+  unsigned int i;
+  int mpos;
+  int ret;
+  
+  ret = OK;
+  csHdr.size 
+    = htons(sizeof(CS_HEADER));
+  csHdr.type
+    = htons(STATS_CS_PROTO_GET_STATISTICS);
+  if (SYSERR == writeToSocket(sock,
+                             &csHdr)) 
+    return SYSERR;  
+  statMsg 
+    = MALLOC(MAX_BUFFER_SIZE);
+  statMsg->totalCounters 
+    = htonl(1); /* to ensure we enter the loop */
+  count = 0;
+  while ( count < ntohl(statMsg->totalCounters) ) {
+    /* printf("reading from socket starting %u of %d\n",
+       count, ntohl(statMsg->totalCounters) );*/
+    if (SYSERR == readFromSocket(sock,
+                                (CS_HEADER**)&statMsg)) {
+      FREE(statMsg);
+      return SYSERR;    
+    }
+    if (ntohs(statMsg->header.size) < sizeof(STATS_CS_MESSAGE)) {
+      BREAK();
+      ret = SYSERR;
+      break;
+    }
+    mpos = sizeof(unsigned long long) * ntohl(statMsg->statCounters);
+    if (count == 0) {
+      ret = processor(_("Uptime (seconds)"),
+                     (unsigned long long) 
+                     ((cronTime(NULL) - 
ntohll(statMsg->startTime))/cronSECONDS),
+                     cls);
+    }
+    for (i=0;i<ntohl(statMsg->statCounters);i++) {
+      if 
(mpos+strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1 
> 
+         ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE)) {
+       BREAK();
+       ret = SYSERR;
+       break; /* out of bounds! */      
+      }
+      if (ret != SYSERR) {
+       char desc[61];
+       SNPRINTF(desc, 
+                61, 
+                "%60s", 
+                
&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos]);
+       ret = processor(desc,
+                       ntohll(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values[i]),
+                       cls);
+       FREE(desc);
+      }
+      mpos += 
strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1;
+    }    
+    count += ntohl(statMsg->statCounters);
+  } /* end while */
+  FREE(statMsg);
+  return ret;
+}
+
+
+/**
+ * Request available protocols from TCP socket.
+ * @param sock the socket to use 
+ * @param processor function to call on each value
+ * @return OK on success, SYSERR on error
+ */
+int requestAvailableProtocols(GNUNET_TCP_SOCKET * sock,
+                             ProtocolProcessor processor,
+                             void * cls) {
+  STATS_CS_GET_MESSAGE_SUPPORTED csStatMsg;
+  unsigned short i;
+  int supported;
+  int ret;
+
+  ret = OK;
+  csStatMsg.header.size 
+    = htons(sizeof(STATS_CS_GET_MESSAGE_SUPPORTED));
+  csStatMsg.header.type
+    = htons(STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED);
+  for (i=0;i<65535;i++) {
+    csStatMsg.type = htons(i);
+    if (SYSERR == writeToSocket(sock, 
+                               &csStatMsg.header)) 
+      return SYSERR;
+    if (SYSERR == readTCPResult(sock,
+                               &supported)) 
+      return SYSERR;
+    if (supported == YES) {
+      ret = processor(i, YES, cls);
+      if (ret != OK)
+       break;
+    }
+  }
+  csStatMsg.header.type
+    = htons(STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED);
+  for (i=0;i<65535;i++) {
+    csStatMsg.type = htons(i);
+    if (SYSERR == writeToSocket(sock, 
+                               &csStatMsg.header)) 
+      return SYSERR;   
+    if (SYSERR == readTCPResult(sock, &supported)) 
+      return SYSERR;
+    if (supported == YES) {
+      ret = processor(i, NO, cls);
+      if (ret != OK)
+       break;
+    }
+  }
+  return OK;
+}
+
+/* end of clientapi.c */

Modified: GNUnet/src/applications/stats/gnunet-stats.c
===================================================================
--- GNUnet/src/applications/stats/gnunet-stats.c        2005-02-06 13:07:43 UTC 
(rev 192)
+++ GNUnet/src/applications/stats/gnunet-stats.c        2005-02-07 13:50:29 UTC 
(rev 193)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2004 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2004, 2005 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
@@ -27,260 +27,56 @@
 
 #include "platform.h"
 #include "gnunet_util.h"
-#include "gnunet_protocols.h"
+#include "gnunet_stats_lib.h"
 #include "statistics.h"
 
-#define STATS_VERSION "3.0.0"
+static int printProtocolsSelected;
 
-static int printProtocols;
+static int lastIp2p = 42; /* not YES or NO */
 
 /**
- * Return a descriptive name for a p2p message type
- */
-static const char *p2pMessageName( unsigned short type ) {
-  const char *name = NULL;
-
-  switch( type ) {
-  case p2p_PROTO_HELO : 
-    name = "p2p_PROTO_HELO";
-    break;
-  case p2p_PROTO_SKEY : 
-    name = "p2p_PROTO_SKEY";
-    break;
-  case p2p_PROTO_PING : 
-    name = "p2p_PROTO_PING";
-    break;
-  case p2p_PROTO_PONG : 
-    name = "p2p_PROTO_PONG";
-    break;
-  case p2p_PROTO_NOISE : 
-    name = "p2p_PROTO_NOISE";
-    break;
-  case p2p_PROTO_HANGUP : 
-    name = "p2p_PROTO_HANGUP";
-    break;
-  case CHAT_p2p_PROTO_MSG : 
-    name = "CHAT_p2p_PROTO_MSG";
-    break;
-  case TRACEKIT_p2p_PROTO_PROBE : 
-    name = "TRACEKIT_p2p_PROTO_PROBE";
-    break;
-  case TRACEKIT_p2p_PROTO_REPLY : 
-    name = "TRACEKIT_p2p_PROTO_REPLY";
-    break;
-  case TBENCH_p2p_PROTO_REQUEST        : 
-    name = "TBENCH_p2p_PROTO_REQUEST";
-    break;
-  case TBENCH_p2p_PROTO_REPLY  : 
-    name = "TBENCH_p2p_PROTO_REPLY";
-    break;
-  default:
-    name = NULL;
-    break;
-  }
-  return name;
-
-}
-
-/**
- * Return a descriptive name for a client server message type
- */
-static const char *csMessageName( unsigned short type ) {
-  const char *name = NULL;
-
-  switch( type ) {
-  case CS_PROTO_RETURN_VALUE : 
-    name = "CS_PROTO_RETURN_VALUE";
-    break;
-  case CS_PROTO_CLIENT_COUNT : 
-    name = "CS_PROTO_CLIENT_COUNT";
-    break;
-  case CS_PROTO_TRAFFIC_QUERY : 
-    name = "CS_PROTO_TRAFFIC_QUERY";
-    break;
-  case CS_PROTO_TRAFFIC_INFO : 
-    name = "CS_PROTO_TRAFFIC_INFO";
-    break;
-  case STATS_CS_PROTO_GET_STATISTICS : 
-    name = "STATS_CS_PROTO_GET_STATISTICS";
-    break;
-  case STATS_CS_PROTO_STATISTICS : 
-    name = "STATS_CS_PROTO_STATISTICS";
-    break;
-  case STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED : 
-    name = "STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED";
-    break;
-  case STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED : 
-    name = "STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED";
-    break;
-  case CHAT_CS_PROTO_MSG : 
-    name = "CHAT_CS_PROTO_MSG";
-    break;
-  case TRACEKIT_CS_PROTO_PROBE : 
-    name = "TRACEKIT_CS_PROTO_PROBE";
-    break;
-  case TRACEKIT_CS_PROTO_REPLY : 
-    name = "TRACEKIT_CS_PROTO_REPLY";
-    break;
-  case TBENCH_CS_PROTO_REQUEST : 
-    name = "TBENCH_CS_PROTO_REQUEST";
-    break;
-  case TBENCH_CS_PROTO_REPLY : 
-    name = "TBENCH_CS_PROTO_REPLY";
-    break;
-  default:
-    name = NULL;
-    break;    
-  }
-  return name;
-}
-
-/**
- * Print statistics received from TCP socket.
+ * Print statistics received.
+ *
  * @param stream where to print the statistics
- * @param sock the socket to use 
  * @return OK on success, SYSERR on error
  */
-static int requestAndPrintStatistics(FILE * stream,
-                                    GNUNET_TCP_SOCKET * sock) {
-  STATS_CS_MESSAGE * statMsg;
-  CS_HEADER csHdr;
-  unsigned int count;
-  unsigned int i;
-  int mpos;
-  
-  csHdr.size 
-    = htons(sizeof(CS_HEADER));
-  csHdr.type
-    = htons(STATS_CS_PROTO_GET_STATISTICS);
-  if (SYSERR == writeToSocket(sock,
-                             &csHdr)) {
-    fprintf(stream,
-           _("Error sending request for statistics to gnunetd.\n"));
-    return SYSERR;
-  }
-  statMsg 
-    = MALLOC(MAX_BUFFER_SIZE);
-  statMsg->totalCounters 
-    = htonl(1); /* to ensure we enter the loop */
-  count = 0;
-  while ( count < ntohl(statMsg->totalCounters) ) {
-    /* printf("reading from socket starting %u of %d\n",
-       count, ntohl(statMsg->totalCounters) );*/
-    if (SYSERR == readFromSocket(sock,
-                                (CS_HEADER**)&statMsg)) {
-      fprintf(stream,
-             _("Error receiving reply for statistics from gnunetd.\n"));
-      FREE(statMsg);
-      return SYSERR;    
-    }
-    if (ntohs(statMsg->header.size) < sizeof(STATS_CS_MESSAGE)) {
-      BREAK();
-      break;
-    }
-    mpos = sizeof(unsigned long long) * ntohl(statMsg->statCounters);
-    if (count == 0) {
-      fprintf(stream,
-             "%-60s: %16u\n",
-             _("Uptime (seconds)"),
-             (unsigned int) 
-             ((cronTime(NULL) - ntohll(statMsg->startTime))/cronSECONDS));
-    }
-    for (i=0;i<ntohl(statMsg->statCounters);i++) {
-      if 
(mpos+strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1 
> 
-         ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE)) {
-       BREAK();
-       break; /* out of bounds! */      
-      }
-      fprintf(stream,
-             "%-60s: %16llu\n",
-             &((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos],
-             ntohll(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values[i]));
-      mpos += 
strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1;
-    }    
-    count += ntohl(statMsg->statCounters);
-  } /* end while */
-  FREE(statMsg);
+static int printStatistics(const char * name,
+                          unsigned long long value,
+                          FILE * stream) {
+  fprintf(stream,
+         "%-60s: %16llu\n",
+         name,
+         value);
   return OK;
 }
 
-/**
- * Queries the server for what protocol messages are
- * supported and prints a list of them
- * @param stream where to print the statistics
- * @param sock the socket to use 
- * @return OK on success, SYSERR on error
- */
-static int requestAndPrintProtocols(FILE * stream,
-                                    GNUNET_TCP_SOCKET * sock) {
-  STATS_CS_GET_MESSAGE_SUPPORTED csStatMsg;
-  int i = 0;
-  int supported = NO;
+static int printProtocols(unsigned short type,
+                         int isP2P,
+                         FILE * stream) {
   const char *name = NULL;
 
-  csStatMsg.header.size 
-    = htons(sizeof(STATS_CS_GET_MESSAGE_SUPPORTED));
-
-
-  fprintf(stream, 
-         _("Supported Peer to Peer messages:\n"));
-  csStatMsg.header.type
-    = htons(STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED);
-  for (i = 0; i < 500; ++ i)
-  {
-    csStatMsg.type = htons(i);
-
-    if (SYSERR == writeToSocket(sock, &csStatMsg.header)) {
-      fprintf(stream,
-             _("Error sending request for p2p protocol status to gnunetd.\n"));
-      return SYSERR;
-    }
-    if (SYSERR == readTCPResult(sock, &supported)) {
-      fprintf(stream,
-             _("Error reading p2p protocol status from gnunetd.\n"));
-      return SYSERR;
-    }
-
-    if (supported == YES)
-    {
-      fprintf(stream, "\t%d", i);
-      name = p2pMessageName( i );
-      if (name != NULL) {
-        fprintf(stream, "\t(%s)", name);
-      }
-      fprintf(stream, "\n");
-    }
+  if (isP2P != lastIp2p) {
+    if (isP2P)
+      fprintf(stream, 
+             _("Supported peer-to-peer messages:\n"));
+    else
+      fprintf(stream, 
+             _("Supported client-server messages:\n"));
+    lastIp2p = isP2P;
   }
-  fprintf(stream, 
-         _("Supported client-server messages:\n"));
-  csStatMsg.header.type
-    = htons(STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED);
-  for (i = 0; i < 500; ++ i)
-  {
-    csStatMsg.type = htons(i);
-
-    if (SYSERR == writeToSocket(sock, &csStatMsg.header)) {
-      fprintf(stream,
-             _("Error sending request for client-server protocol status to 
gnunetd.\n"));
-      return SYSERR;
-    }
-    if (SYSERR == readTCPResult(sock, &supported)) {
-      fprintf(stream,
-             _("Error reading client-server protocol status from gnunetd.\n"));
-      return SYSERR;
-    }
-
-    if (supported == YES)
-    {
-      fprintf(stream, "\t%d", i);
-      name = csMessageName( i );
-      if (name != NULL) {
-        fprintf(stream, "\t(%s)", name);
-      }
-      fprintf(stream, "\n");
-    }
-  }
-
+  if (isP2P)
+    name = p2pMessageName(type);
+  else
+    name = csMessageName(type);
+  if (name == NULL)
+    fprintf(stream, 
+           "\t%d\n",
+           type);
+  else
+    fprintf(stream, 
+           "\t%d\t(%s)\n", 
+           type,
+           name);
   return OK;
 }
 
@@ -340,7 +136,7 @@
       printhelp(); 
       return SYSERR;
     case 'p':
-      printProtocols = YES;
+      printProtocolsSelected = YES;
       break;
     default: 
       LOG(LOG_FAILURE,
@@ -362,19 +158,27 @@
   int res;
   GNUNET_TCP_SOCKET * sock;
 
-  printProtocols = NO;
-
   if (SYSERR == initUtil(argc, argv, &parseOptions))
     return 0;
   sock = getClientSocket();
-  res = requestAndPrintStatistics(stdout,
-                                 sock);
-  if ((printProtocols == YES) && (res == OK)) {
-    res = requestAndPrintProtocols(stdout,
-                                  sock);
+  if (sock == NULL) {
+    fprintf(stderr,
+           _("Error establishing connection with gnunetd.\n"));
+    return 1;
   }
-  if (sock != NULL)
-    releaseClientSocket(sock);
+  res = requestStatistics(sock,
+                         (StatisticsProcessor) &printStatistics,
+                         stdout);
+  if ((printProtocolsSelected == YES) && 
+      (res == OK)) {
+    res = requestAvailableProtocols(sock,
+                                   (ProtocolProcessor) &printProtocols,
+                                   stdout);
+  }
+  if (res != OK)
+    fprintf(stderr,
+           _("Error reading information from gnunetd.\n"));
+  releaseClientSocket(sock);
   doneUtil();
 
   return (res == OK) ? 0 : 1;

Modified: GNUnet/src/applications/testbed/Makefile.am
===================================================================
--- GNUnet/src/applications/testbed/Makefile.am 2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/testbed/Makefile.am 2005-02-07 13:50:29 UTC (rev 
193)
@@ -18,9 +18,11 @@
   socket.c \
   socket.h \
   commands.c \
-  get-stats.c \
-  get-stats.h \
   commands.h
+gnunet_testbed_LDADD = \
+  $(top_builddir)/src/applications/getoption/libgnunetgetoption_api.la \
+  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/util/libgnunetutil.la 
 
 
 libgnunetmodule_testbed_la_SOURCES = \

Modified: GNUnet/src/applications/testbed/commands.c
===================================================================
--- GNUnet/src/applications/testbed/commands.c  2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/testbed/commands.c  2005-02-07 13:50:29 UTC (rev 
193)
@@ -33,10 +33,12 @@
  */
 
 #include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_getoption_lib.h"
+#include "gnunet_stats_lib.h"
 #include "testbed.h"
 #include "commands.h"
 #include "socket.h"
-#include "get-stats.h"
 
 /**
  * @brief struct keeping per-peer information for the testbed
@@ -1066,6 +1068,16 @@
   }
 }
 
+static int printStatistic(const char * name,
+                         unsigned long long value,
+                         const char * arg) {
+  if (0 == strcmp(name,
+                 arg))
+    PRINTF("%llu\n",
+          value);
+  return OK;
+}
+
 /**
  * Obtain statistics from a peer.
  *
@@ -1082,8 +1094,9 @@
     return -1;
   }
   CHECK_PEER(peer, argv[0]);
-  res = requestAndPrintStatistic(&nodes[peer].sock,
-                                argv[1]);
+  res = requestStatistics(&nodes[peer].sock,
+                         (StatisticsProcessor) &printStatistic,
+                         argv[1]);
   if (res == OK)
     return 0;
   else
@@ -1091,6 +1104,49 @@
 }
 
 /**
+ * Print statistics received.
+ *
+ * @param stream where to print the statistics
+ * @return OK on success, SYSERR on error
+ */
+static int printStatistics(const char * name,
+                          unsigned long long value,
+                          void * unused) {
+  PRINTF("%-60s: %16llu\n",
+        name,
+        value);
+  return OK;
+}
+
+static int lastIp2p;
+
+static int printProtocols(unsigned short type,
+                         int isP2P,
+                         void * unused) {
+  const char *name = NULL;
+
+  if (isP2P != lastIp2p) {
+    if (isP2P)
+      PRINTF(_("Supported peer-to-peer messages:\n"));
+    else
+      PRINTF(_("Supported client-server messages:\n"));
+    lastIp2p = isP2P;
+  }
+  if (isP2P)
+    name = p2pMessageName(type);
+  else
+    name = csMessageName(type);
+  if (name == NULL)
+    PRINTF("\t%d\n",
+          type);
+  else
+    PRINTF("\t%d\t(%s)\n", 
+          type,
+          name);
+  return OK;
+}
+
+/**
  * Obtain statistics from a peer.
  *
  * @param argc number of arguments from the command line
@@ -1098,25 +1154,30 @@
  * @return 0 ok, 1 on error
  */   
 static int getStats(int argc, char ** argv) {
-  int res, peer, printProtocols;
+  int res, peer, printProtocolsOpt;
   
-  printProtocols = NO;
+  printProtocolsOpt = NO;
   if (argc == 2) {
     if (strcmp(argv[0], "-P")) {
       PRINTF("Syntax: get-stats [-P] PEERID\n");
       return -1;
     }
-    printProtocols = YES;
+    printProtocolsOpt = YES;
     CHECK_PEER(peer, argv[1]);
   } else if (argc != 1) {
     PRINTF("Syntax: get-stats [-P] PEERID\n");
     return -1;
   } else
     CHECK_PEER(peer, argv[0]);
-  res = requestAndPrintStatistics(&nodes[peer].sock);
-  if ( (printProtocols == YES) && 
+  res = requestStatistics(&nodes[peer].sock,
+                         (StatisticsProcessor) &printStatistics,
+                         NULL);
+  if ( (printProtocolsOpt == YES) && 
        (res == OK)) {
-    res = requestAndPrintProtocols(&nodes[peer].sock);
+ lastIp2p = 42; /* not YES or NO */
+    res = requestAvailableProtocols(&nodes[peer].sock,
+                                   (ProtocolProcessor) &printProtocols,
+                                   NULL);
   }
   if (res == OK)
     return 0;
@@ -1134,53 +1195,25 @@
  */   
 static int getOption(int argc, char ** argv) {
   int peer;
-  CS_GET_OPTION_REQUEST req;
-  CS_GET_OPTION_REPLY * reply;
-  int res;
+  char * opt;
   
   if (argc != 3) {
     PRINTF("Syntax: get-option PEERID SECTION OPTION\n");
     return -1;
-  }
+  }  
   CHECK_PEER(peer, argv[0]);
-  memset(&req,
-        0,
-        sizeof(CS_GET_OPTION_REQUEST));
-  req.header.type = htons(CS_PROTO_GET_OPTION_REQUEST);
-  req.header.size = htons(sizeof(CS_GET_OPTION_REQUEST));
-  if ( (strlen(argv[1]) >= CS_GET_OPTION_REQUEST_OPT_LEN) ||
-       (strlen(argv[2]) >= CS_GET_OPTION_REQUEST_OPT_LEN) ) {
-    PRINTF("Illegal length of arguments (>= %d characters)",
-          CS_GET_OPTION_REQUEST_OPT_LEN);
-    return -1;
-  }
-  strcpy(&req.section[0],
-        argv[1]);
-  strcpy(&req.option[0],
-        argv[2]);
-  res = writeToSocket(&nodes[peer].sock,
-                     &req.header);
-  if (res != OK) {
+  opt = getConfigurationOptionValue(&nodes[peer].sock,
+                                   argv[1],
+                                   argv[2]);
+  if (opt == NULL) {
     PRINTF("Error sending request to peer %d\n",
           peer);
     return -1;
   }
-  reply = NULL;
-  res = readFromSocket(&nodes[peer].sock,
-                      (CS_HEADER**)&reply);
-  if (res != OK) {
-    PRINTF("Error receiving reply from peer %d\n",
-          peer);
-    return -1;
-  }
-  PRINTF("%*s\n",
-        ntohs(reply->header.size) - sizeof(CS_HEADER),
-        &reply->value[0]);
-  FREE(reply);
-  if (res == OK)
-    return 0;
-  else
-    return -1;
+  PRINTF("%s\n",
+        opt);
+  FREE(opt);
+  return 0;
 }
 
 

Deleted: GNUnet/src/applications/testbed/get-stats.c
===================================================================
--- GNUnet/src/applications/testbed/get-stats.c 2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/testbed/get-stats.c 2005-02-07 13:50:29 UTC (rev 
193)
@@ -1,374 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2001, 2002 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/stats/gnunet-stats.c 
- * @brief tool to obtain statistics from gnunetd.
- * @author Christian Grothoff
- * @author Igor Wronsky
- */
-
-#include "gnunet_util.h"
-#include "platform.h"
-#include "socket.h"
-
-/**
- * Return a descriptive name for a p2p message type
- */
-static const char *p2pMessageName(unsigned short type) {
-  const char *name = NULL;
-  switch( type ) {
-  case p2p_PROTO_HELO : 
-    name = "p2p_PROTO_HELO";
-    break;
-  case p2p_PROTO_SKEY : 
-    name = "p2p_PROTO_SKEY";
-    break;
-  case p2p_PROTO_PING : 
-    name = "p2p_PROTO_PING";
-    break;
-  case p2p_PROTO_PONG : 
-    name = "p2p_PROTO_PONG";
-    break;
-  case p2p_PROTO_TIMESTAMP : 
-    name = "p2p_PROTO_TIMESTAMP";
-    break;
-  case p2p_PROTO_SEQUENCE : 
-    name = "p2p_PROTO_SEQUENCE";
-    break;
-  case p2p_PROTO_NOISE : 
-    name = "p2p_PROTO_NOISE";
-    break;
-  case p2p_PROTO_HANGUP : 
-    name = "p2p_PROTO_HANGUP";
-    break;
-  case AFS_p2p_PROTO_QUERY : 
-    name = "AFS_p2p_PROTO_QUERY";
-    break;
-  case AFS_p2p_PROTO_3HASH_RESULT : 
-    name = "AFS_p2p_PROTO_3HASH_RESULT";
-    break;
-  case AFS_p2p_PROTO_CHK_RESULT : 
-    name = "AFS_p2p_PROTO_CHK_RESULT";
-    break;
-  case CHAT_p2p_PROTO_MSG : 
-    name = "CHAT_p2p_PROTO_MSG";
-    break;
-  case TRACEKIT_p2p_PROTO_PROBE : 
-    name = "TRACEKIT_p2p_PROTO_PROBE";
-    break;
-  case TRACEKIT_p2p_PROTO_REPLY : 
-    name = "TRACEKIT_p2p_PROTO_REPLY";
-    break;
-  case TBENCH_p2p_PROTO_REQUEST        : 
-    name = "TBENCH_p2p_PROTO_REQUEST";
-    break;
-  case TBENCH_p2p_PROTO_REPLY  : 
-    name = "TBENCH_p2p_PROTO_REPLY";
-    break;
-  default:
-    name = NULL;
-    break;
-  }
-  return name;
-}
-
-/**
- * Return a descriptive name for a client server message type
- */
-static const char *csMessageName( unsigned short type ) {
-  const char *name = NULL;
-  
-  switch( type ) {
-  case CS_PROTO_RETURN_VALUE : 
-    name = "CS_PROTO_RETURN_VALUE";
-    break;
-  case CS_PROTO_CLIENT_COUNT : 
-    name = "CS_PROTO_CLIENT_COUNT";
-    break;
-  case CS_PROTO_TRAFFIC_QUERY : 
-    name = "CS_PROTO_TRAFFIC_QUERY";
-    break;
-  case CS_PROTO_TRAFFIC_INFO : 
-    name = "CS_PROTO_TRAFFIC_INFO";
-    break;
-  case STATS_CS_PROTO_GET_STATISTICS : 
-    name = "STATS_CS_PROTO_GET_STATISTICS";
-    break;
-  case STATS_CS_PROTO_STATISTICS : 
-    name = "STATS_CS_PROTO_STATISTICS";
-    break;
-  case STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED : 
-    name = "STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED";
-    break;
-  case STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED : 
-    name = "STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED";
-    break;
-  case AFS_CS_PROTO_QUERY: 
-    name = "AFS_CS_PROTO_QUERY";
-    break;
-  case AFS_CS_PROTO_RESULT_3HASH: 
-    name = "AFS_CS_PROTO_RESULT_3HASH";
-    break;
-  case AFS_CS_PROTO_RESULT_CHK: 
-    name = "AFS_CS_PROTO_RESULT_CHK";
-    break;
-  case AFS_CS_PROTO_INSERT_CHK: 
-    name = "AFS_CS_PROTO_INSERT_CHK";
-    break;
-  case AFS_CS_PROTO_INSERT_3HASH : 
-    name = "AFS_CS_PROTO_INSERT_3HASH";
-    break;
-  case AFS_CS_PROTO_INDEX_BLOCK : 
-    name = "AFS_CS_PROTO_INDEX_BLOCK";
-    break;
-  case AFS_CS_PROTO_INDEX_FILE : 
-    name = "AFS_CS_PROTO_INDEX_FILE";
-    break;
-  case AFS_CS_PROTO_INDEX_SUPER : 
-    name = "AFS_CS_PROTO_INDEX_SUPER";
-    break;
-  case CHAT_CS_PROTO_MSG : 
-    name = "CHAT_CS_PROTO_MSG";
-    break;
-  case TRACEKIT_CS_PROTO_PROBE : 
-    name = "TRACEKIT_CS_PROTO_PROBE";
-    break;
-  case TRACEKIT_CS_PROTO_REPLY : 
-    name = "TRACEKIT_CS_PROTO_REPLY";
-    break;
-  case TBENCH_CS_PROTO_REQUEST : 
-    name = "TBENCH_CS_PROTO_REQUEST";
-    break;
-  case TBENCH_CS_PROTO_REPLY : 
-    name = "TBENCH_CS_PROTO_REPLY";
-    break;
-  default:
-    name = NULL;
-    break;
-  }
-  return name;
-}
-
-/**
- * Print statistics received from TCP socket.
- * @param stream where to print the statistics
- * @param sock the socket to use 
- * @return OK on success, SYSERR on error
- */
-int requestAndPrintStatistics(GNUNET_TCP_SOCKET * sock) {
-  STATS_CS_MESSAGE * statMsg;
-  CS_HEADER csHdr;
-  unsigned int count;
-  unsigned int i;
-  int mpos;
-  
-  csHdr.size = htons(sizeof(CS_HEADER));
-  csHdr.type = htons(STATS_CS_PROTO_GET_STATISTICS);
-  if (SYSERR == writeToSocket(sock, &csHdr)) {
-    PRINTF(_("Error sending request for statistics to peer.\n"));
-    return SYSERR;
-  }
-  statMsg = MALLOC(MAX_BUFFER_SIZE);
-  statMsg->totalCounters = htonl(1); /* to ensure we enter the loop */
-  count = 0;
-  while ( count < ntohl(statMsg->totalCounters) ) {
-    /* printf("reading from socket starting %u of %d\n",
-       count, ntohl(statMsg->totalCounters) );*/
-    if (SYSERR == readFromSocket(sock,
-                                (CS_HEADER**)&statMsg)) {
-      PRINTF(_("Error receiving reply for statistics from peer.\n"));
-      FREE(statMsg);
-      return SYSERR;    
-    }
-    if (ntohs(statMsg->header.size) < sizeof(STATS_CS_MESSAGE)) {
-      LOG(LOG_WARNING,
-         _("Received malformed stats message (%d < %d)\n"),
-         ntohs(statMsg->header.size), 
-         sizeof(STATS_CS_MESSAGE) );
-      break;
-    }
-    mpos = sizeof(unsigned long long) * ntohl(statMsg->statCounters);
-    if (count == 0) {
-      PRINTF("%-60s: %16u\n",
-            _("Uptime (seconds)"),
-            (unsigned int) 
-            ((cronTime(NULL) - ntohll(statMsg->startTime))/
-             cronSECONDS));
-    }
-    for (i=0; i < ntohl(statMsg->statCounters); i++) {
-      if 
(mpos+strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1 
> 
-         ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE)) {
-       LOG(LOG_WARNING,
-           _("Received malformed stats message (%d > %d)\n"),
-           
mpos+strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1,
-           ntohs(statMsg->header.size)-sizeof(STATS_CS_MESSAGE));
-       break; /* out of bounds! */      
-      }
-      PRINTF("%-60s: %16llu\n",
-            &((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos],
-                  ntohll(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values[i]));
-      mpos += 
strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1;
-    }    
-    count += ntohl(statMsg->statCounters);
-  } /* end while */
-  FREE(statMsg);
-  return OK;
-}
-
-/**
- * Print statistics received from TCP socket.
- * @param stream where to print the statistics
- * @param sock the socket to use 
- * @return OK on success, SYSERR on error
- */
-int requestAndPrintStatistic(GNUNET_TCP_SOCKET * sock,
-                            char * name) {
-  STATS_CS_MESSAGE * statMsg;
-  CS_HEADER csHdr;
-  unsigned int count;
-  unsigned int i;
-  int mpos;
-  
-  csHdr.size = htons(sizeof(CS_HEADER));
-  csHdr.type = htons(STATS_CS_PROTO_GET_STATISTICS);
-  if (SYSERR == writeToSocket(sock, &csHdr)) {
-    PRINTF(_("Error sending request for statistics to peer.\n"));
-    return SYSERR;
-  }
-  statMsg = MALLOC(MAX_BUFFER_SIZE);
-  statMsg->totalCounters = htonl(1); /* to ensure we enter the loop */
-  count = 0;
-  while ( count < ntohl(statMsg->totalCounters) ) {
-    /* printf("reading from socket starting %u of %d\n",
-       count, ntohl(statMsg->totalCounters) );*/
-    if (SYSERR == readFromSocket(sock,
-                                (CS_HEADER**)&statMsg)) {
-      PRINTF(_("Error receiving reply for statistics from peer.\n"));
-      FREE(statMsg);
-      return SYSERR;    
-    }
-    if (ntohs(statMsg->header.size) < sizeof(STATS_CS_MESSAGE)) {
-      PRINTF(_("Error receiving reply for statistics from peer.\n"));
-      LOG(LOG_WARNING,
-         _("received malformed stats message (%d < %d)\n"),
-         ntohs(statMsg->header.size), 
-         sizeof(STATS_CS_MESSAGE) );
-      break;
-    }
-    mpos = sizeof(unsigned long long) * ntohl(statMsg->statCounters);
-    if (count == 0) {
-      if (0 == strcmp(name,
-                     _("Uptime (seconds)")))
-       PRINTF("%u\n",
-              (unsigned int) 
-              ((cronTime(NULL) - ntohll(statMsg->startTime))/
-               cronSECONDS));
-    }
-    for (i=0; i<ntohl(statMsg->statCounters); i++) {
-      if 
(mpos+strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1 
> 
-         ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE)) {
-       LOG(LOG_WARNING,
-           _("Received malformed stats message (%d > %d)\n"),
-           
mpos+strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1,
-           ntohs(statMsg->header.size)-sizeof(STATS_CS_MESSAGE));
-       break; /* out of bounds! */      
-      }
-      if (0 == strcmp(name,
-                     
&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos]))
-       PRINTF("%llu\n",
-              ntohll(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values[i]));
-      mpos += 
strlen(&((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1;
-    }    
-    count += ntohl(statMsg->statCounters);
-  } /* end while */
-  FREE(statMsg);
-  return OK;
-}
-
-/**
- * Queries the server for what protocol messages are
- * supported and prints a list of them
- * @param stream where to print the statistics
- * @param sock the socket to use 
- * @return OK on success, SYSERR on error
- */
-int requestAndPrintProtocols(GNUNET_TCP_SOCKET * sock) {
-  STATS_CS_GET_MESSAGE_SUPPORTED csStatMsg;
-  int i = 0;
-  int supported = NO;
-  const char *name = NULL;
-  
-  csStatMsg.header.size 
-    = htons(sizeof(STATS_CS_GET_MESSAGE_SUPPORTED));  
-  PRINTF(_("Supported Peer to Peer messages:\n"));
-  csStatMsg.header.type
-    = htons(STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED);
-  for (i=0;i<65536;i++) {
-    csStatMsg.type = htons(i);
-    
-    if (SYSERR == writeToSocket(sock, &csStatMsg.header)) {
-      PRINTF(_("Error sending request for p2p protocol "
-              "status to gnunetd.\n"));
-      return SYSERR;
-    }
-    if (SYSERR == readTCPResult(sock, &supported)) {
-      PRINTF(_("Error reading p2p protocol status from gnunetd.\n"));
-      return SYSERR;
-    }
-    
-    if (supported == YES) {
-      PRINTF("\t%d", i);
-      name = p2pMessageName( i );
-      if (name != NULL) {
-       PRINTF("\t(%s)", name);
-      }
-      PRINTF("\n");
-    }
-  }
-  PRINTF(_("Supported Client Server messages:\n"));
-  csStatMsg.header.type
-    = htons(STATS_CS_PROTO_GET_CS_MESSAGE_SUPPORTED);
-  for (i=0;i<65536;i++) {
-    csStatMsg.type = htons(i);   
-    if (SYSERR == writeToSocket(sock, &csStatMsg.header)) {
-      PRINTF(_("Error sending request for client-server "
-              "protocol status to gnunetd.\n"));
-      return SYSERR;
-    }
-    if (SYSERR == readTCPResult(sock, &supported)) {
-      PRINTF(_("Error reading client-server protocol "
-              "status from gnunetd.\n"));
-      return SYSERR;
-    }    
-    if (supported == YES) {
-      PRINTF("\t%d", i);
-      name = csMessageName( i );
-      if (name != NULL) {
-       PRINTF("\t(%s)", name);
-      }
-      PRINTF("\n");
-    }
-  }
-  return OK;
-}
-
-
-/* end of get-stats.c */

Deleted: GNUnet/src/applications/testbed/get-stats.h
===================================================================
--- GNUnet/src/applications/testbed/get-stats.h 2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/testbed/get-stats.h 2005-02-07 13:50:29 UTC (rev 
193)
@@ -1,4 +0,0 @@
-int requestAndPrintStatistics(GNUNET_TCP_SOCKET *sock);
-int requestAndPrintStatistic(GNUNET_TCP_SOCKET *sock,
-                            char * name);
-int requestAndPrintProtocols(GNUNET_TCP_SOCKET * sock);

Modified: GNUnet/src/applications/testbed/gnunet-testbed.c
===================================================================
--- GNUnet/src/applications/testbed/gnunet-testbed.c    2005-02-06 13:07:43 UTC 
(rev 192)
+++ GNUnet/src/applications/testbed/gnunet-testbed.c    2005-02-07 13:50:29 UTC 
(rev 193)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2003, 2004 Christian Grothoff (and other contributing authors)
+     (C) 2003, 2004, 2005 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
@@ -284,7 +284,7 @@
 /**
  * Configuration...
  */
-static CIDRNetwork * trustedNetworks_ = NULL;
+static struct CIDRNetwork * trustedNetworks_ = NULL;
 
 /**
  * Is this IP labeled as trusted for CS connections?

Modified: GNUnet/src/applications/testbed/testbed.c
===================================================================
--- GNUnet/src/applications/testbed/testbed.c   2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/applications/testbed/testbed.c   2005-02-07 13:50:29 UTC (rev 
193)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2003, 2004 Christian Grothoff (and other contributing authors)
+     (C) 2003, 2004, 2005 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
@@ -19,34 +19,35 @@
 */
 
 /**
- * Testbed CORE.  This is the code that is plugged
- * into the GNUnet core to enable transport profiling.
- *
+ * @file applications/testbed/testbed.c
  * @author Ronaldo Alves Ferreira
  * @author Christian Grothoff
  * @author Murali Khrisna Ramanathan
- * @file applications/testbed/testbed.c
+ * @brief Testbed CORE.  This is the code that is plugged
+ * into the GNUnet core to enable transport profiling.
  */
 
 
-#include "testbed.h"
 #include "platform.h"
+#include "testbed.h"
+#include "gnunet_protocols.h"
+#include "gnunet_identity_service.h"
 
-#include <sys/types.h>
-
 #define DEBUG_TESTBED YES
 
 #define GET_COMMAND "GET %s/%s.php3?trusted=%s&port=%s&secure=%s 
HTTP/1.0\r\n\r\n"
 #define HTTP_URL "http://";
 
 /* */
-static CoreAPIForApplication * coreAPI = NULL;
+static CoreAPIForApplication * coreAPI;
 
+static Identity_ServiceAPI * identity;
+
 static void sendAcknowledgement(ClientHandle client,
                                int ack) {
-  if (OK != coreAPI->sendTCPResultToClient(client, ack)) {
+  if (OK != coreAPI->sendValueToClient(client, ack)) {
     LOG(LOG_WARNING,
-       _("Could not send ack back to client.\n"));
+       _("Could not send acknowledgement back to client.\n"));
   }
 }
 
@@ -86,13 +87,13 @@
     return;
   }
   
-  coreAPI->bindAddress(&hm->helo);
+  identity->addHost(&hm->helo);
   noise.size = htons(sizeof(p2p_HEADER));
   noise.type = htons(p2p_PROTO_NOISE);
-  coreAPI->sendToNode(&hm->helo.senderIdentity,
-                     &noise,
-                     EXTREME_PRIORITY, 
-                     0);
+  coreAPI->unicast(&hm->helo.senderIdentity,
+                  &noise,
+                  EXTREME_PRIORITY, 
+                  0);
   sendAcknowledgement(client, OK);
 }
 
@@ -105,12 +106,18 @@
   sendAcknowledgement(client, OK);
 }
 
+static void doDisconnect(const PeerIdentity * id,
+                        void * unused) {
+  coreAPI->disconnectFromPeer(id);
+}
+
 /**
  * Disconnect from all other peers.
  */
 static void tb_DEL_ALL_PEERS(ClientHandle client,
                             TESTBED_DEL_ALL_PEERS_MESSAGE * msg) {
-  coreAPI->disconnectPeers(); 
+  coreAPI->forAllConnectedNodes(&doDisconnect,
+                               NULL);
   sendAcknowledgement(client, OK);
 }
 
@@ -122,10 +129,10 @@
   HELO_Message * helo;
   unsigned int proto = ntohs(msg->proto);
   
-  if (SYSERR == coreAPI->identity2Helo(coreAPI->myIdentity, 
-                                      proto,
-                                      NO, 
-                                      &helo)) {
+  if (SYSERR == identity->identity2Helo(coreAPI->myIdentity, 
+                                       proto,
+                                       NO, 
+                                       &helo)) {
     LOG(LOG_WARNING, 
        _("TESTBED could not generate HELO message for protocol %u\n"),
        proto);
@@ -157,16 +164,11 @@
  */
 static void tb_SET_TVALUE(ClientHandle client,
                          TESTBED_SET_TVALUE_MESSAGE * msg) {
-  int trust, chg;
+  int trust;
   
   trust = ntohl(msg->trust);
-  chg = coreAPI->changeTrust(&msg->otherPeer, trust);
-  if (chg != trust) {
-    LOG(LOG_WARNING,
-       _("trust change=%d, required=%d\n"),
-       chg,
-       trust);
-  }
+  identity->changeHostTrust(&msg->otherPeer, 
+                           trust);
   sendAcknowledgement(client, OK);
 }      
                  
@@ -177,7 +179,7 @@
                          TESTBED_GET_TVALUE_MESSAGE * msg) {    
   unsigned int trust;
   
-  trust = coreAPI->getTrust(&msg->otherPeer);
+  trust = identity->getHostTrust(&msg->otherPeer);
   sendAcknowledgement(client, trust);
 }      
 
@@ -283,20 +285,6 @@
  * peer (by making it drop a certain percentage of the messages at
  * random).
  */
-static void tb_SET_LOSS_RATE(ClientHandle client,
-                            TESTBED_SET_LOSS_RATE_MESSAGE * msg) {
-  coreAPI->setPercentRandomInboundDrop
-    (ntohl(msg->percentageLossInbound));
-  coreAPI->setPercentRandomOutboundDrop
-    (ntohl(msg->percentageLossOutbound));
-  sendAcknowledgement(client, OK);
-}
-
-/**
- * Set the reliability of the inbound and outbound transfers for this
- * peer (by making it drop a certain percentage of the messages at
- * random).
- */
 static void tb_DISABLE_AUTOCONNECT(ClientHandle client,
                                   TESTBED_DISABLE_AUTOCONNECT_MESSAGE * msg) {
   FREENONNULL(setConfigurationString("GNUNETD",
@@ -958,7 +946,6 @@
   TBSENTRY(GET_TVALUE), 
   TBSENTRY(undefined), 
   TBSENTRY(SET_BW), 
-  TBSENTRY(SET_LOSS_RATE),
   TBDENTRY(LOAD_MODULE),
   TBDENTRY(UNLOAD_MODULE),
   TBDENTRY(UPLOAD_FILE),
@@ -1345,7 +1332,6 @@
  */
 int initialize_module_testbed(CoreAPIForApplication * capi) {
   unsigned int i;
-  int ok = OK;
   
   /* some checks */
   for (i=0;i<TESTBED_MAX_MSG;i++)
@@ -1353,18 +1339,20 @@
         (handlers[i].handler != &tb_undefined) )
       GNUNET_ASSERT(0);
   GNUNET_ASSERT(handlers[TESTBED_MAX_MSG].handler == NULL);
+  identity = capi->requestService("identity");
+  if (identity == NULL)
+    return SYSERR;
+
   MUTEX_CREATE(&lock);
   LOG(LOG_DEBUG,
       "TESTBED registering handler %d!\n",
       TESTBED_CS_PROTO_REQUEST);
   coreAPI = capi;
-  if (SYSERR == capi->registerClientExitHandler(&testbedClientExitHandler))
-    ok = SYSERR;
-  if (SYSERR == capi->registerClientHandler(TESTBED_CS_PROTO_REQUEST,
-                                           (CSHandler)&csHandleTestbedRequest))
-    ok = SYSERR;
+  GNUNET_ASSERT(SYSERR != 
capi->registerClientExitHandler(&testbedClientExitHandler));
+  GNUNET_ASSERT(SYSERR != capi->registerClientHandler(TESTBED_CS_PROTO_REQUEST,
+                                                     
(CSHandler)&csHandleTestbedRequest));
   httpRegister("startup");
-  return ok;
+  return OK;
 }
 
 /**
@@ -1398,6 +1386,8 @@
   coreAPI->unregisterClientHandler(TESTBED_CS_PROTO_REQUEST,
                                   (CSHandler)&csHandleTestbedRequest);
   coreAPI->unregisterClientExitHandler(&testbedClientExitHandler);
+  coreAPI->releaseService(identity);
+  identity = NULL;
   coreAPI = NULL;
 }
 

Modified: GNUnet/src/include/Makefile.am
===================================================================
--- GNUnet/src/include/Makefile.am      2005-02-06 13:07:43 UTC (rev 192)
+++ GNUnet/src/include/Makefile.am      2005-02-07 13:50:29 UTC (rev 193)
@@ -31,6 +31,7 @@
   gnunet_rpc_service.h \
   gnunet_session_service.h \
   gnunet_sqstore_service.h \
+  gnunet_stats_lib.h \
   gnunet_stats_service.h \
   gnunet_topology_service.h \
   gnunet_traffic_lib.h \

Added: GNUnet/src/include/gnunet_stats_lib.h
===================================================================
--- GNUnet/src/include/gnunet_stats_lib.h       2005-02-06 13:07:43 UTC (rev 
192)
+++ GNUnet/src/include/gnunet_stats_lib.h       2005-02-07 13:50:29 UTC (rev 
193)
@@ -0,0 +1,84 @@
+/*
+      This file is part of GNUnet
+
+      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_stats_lib.h
+ * @brief convenience API to the STATS service
+ * @author Christian Grothoff
+ */
+
+#ifndef GNUNET_STATS_LIB_H
+#define GNUNET_STATS_LIB_H
+
+#include "gnunet_util.h"
+
+#define STATS_VERSION "3.0.0"
+
+/**
+ * Return a descriptive name for a p2p message type
+ */
+const char * p2pMessageName(unsigned short type);
+
+/**
+ * Return a descriptive name for a client server message type
+ */
+const char * csMessageName(unsigned short type);
+
+/**
+ * @param name the name of the datum
+ * @param value the value
+ * @return OK to continue, SYSERR to abort iteration
+ */
+typedef int (*StatisticsProcessor)(const char * name,
+                                  unsigned long long value,
+                                  void * cls);
+
+/**
+ * Request statistics from TCP socket.
+ * @param sock the socket to use 
+ * @param processor function to call on each value
+ * @return OK on success, SYSERR on error
+ */
+int requestStatistics(GNUNET_TCP_SOCKET * sock,
+                     StatisticsProcessor processor,
+                     void * cls);
+
+/**
+ * @param type the type ID of the message
+ * @param isP2P YES for P2P, NO for CS types
+ * @return OK to continue, SYSERR to abort iteration
+ */
+typedef int (*ProtocolProcessor)(unsigned short type,
+                                int isP2P,
+                                void * cls);
+
+/**
+ * Request available protocols from TCP socket.
+ * @param sock the socket to use 
+ * @param processor function to call on each value
+ * @return OK on success, SYSERR on error
+ */
+int requestAvailableProtocols(GNUNET_TCP_SOCKET * sock,
+                             ProtocolProcessor processor,
+                             void * cls);
+
+
+
+
+#endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]