[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3184 - in GNUnet: . src/applications/session src/applicati
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3184 - in GNUnet: . src/applications/session src/applications/stats src/include |
Date: |
Sun, 30 Jul 2006 14:41:02 -0700 (PDT) |
Author: grothoff
Date: 2006-07-30 14:40:59 -0700 (Sun, 30 Jul 2006)
New Revision: 3184
Modified:
GNUnet/src/applications/session/connect.c
GNUnet/src/applications/stats/Makefile.am
GNUnet/src/applications/stats/clientapi.c
GNUnet/src/applications/stats/gnunet-stats.c
GNUnet/src/applications/stats/statistics.c
GNUnet/src/applications/stats/statistics.h
GNUnet/src/include/gnunet_stats_lib.h
GNUnet/todo
Log:
stats compiles
Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c 2006-07-30 06:22:18 UTC (rev
3183)
+++ GNUnet/src/applications/session/connect.c 2006-07-30 21:40:59 UTC (rev
3184)
@@ -772,10 +772,11 @@
= stats->create(gettext_noop("# sessions established"));
}
- GE_LOG(ectx, GE_DEBUG | GE_USER | GE_REQUEST,
- _("`%s' registering handler %d (plaintext and ciphertext)\n"),
- "session",
- P2P_PROTO_setkey);
+ GE_LOG(ectx,
+ GE_INFO | GE_USER | GE_REQUEST,
+ _("`%s' registering handler %d (plaintext and ciphertext)\n"),
+ "session",
+ P2P_PROTO_setkey);
coreAPI->registerPlaintextHandler(P2P_PROTO_setkey,
&acceptSessionKey);
coreAPI->registerHandler(P2P_PROTO_setkey,
Modified: GNUnet/src/applications/stats/Makefile.am
===================================================================
--- GNUnet/src/applications/stats/Makefile.am 2006-07-30 06:22:18 UTC (rev
3183)
+++ GNUnet/src/applications/stats/Makefile.am 2006-07-30 21:40:59 UTC (rev
3184)
@@ -19,7 +19,9 @@
gnunet-stats.c
gnunet_stats_LDADD = \
$(top_builddir)/src/applications/stats/libgnunetstats_api.la \
- $(top_builddir)/src/util/libgnunetutil.la
+ $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la
libgnunetstats_api_la_SOURCES = \
clientapi.c
Modified: GNUnet/src/applications/stats/clientapi.c
===================================================================
--- GNUnet/src/applications/stats/clientapi.c 2006-07-30 06:22:18 UTC (rev
3183)
+++ GNUnet/src/applications/stats/clientapi.c 2006-07-30 21:40:59 UTC (rev
3184)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing
authors)
+ (C) 2001, 2002, 2004, 2005, 2006 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
@@ -138,11 +138,12 @@
* @param processor function to call on each value
* @return OK on success, SYSERR on error
*/
-int requestStatistics(GNUNET_TCP_SOCKET * sock,
+int requestStatistics(struct GE_Context * ectx,
+ struct ClientServerConnection * sock,
StatisticsProcessor processor,
void * cls) {
CS_stats_reply_MESSAGE * statMsg;
- CS_MESSAGE_HEADER csHdr;
+ MESSAGE_HEADER csHdr;
unsigned int count;
unsigned int i;
int mpos;
@@ -150,11 +151,11 @@
ret = OK;
csHdr.size
- = htons(sizeof(CS_MESSAGE_HEADER));
+ = htons(sizeof(MESSAGE_HEADER));
csHdr.type
= htons(CS_PROTO_stats_GET_STATISTICS);
- if (SYSERR == writeToSocket(sock,
- &csHdr))
+ if (SYSERR == connection_write(sock,
+ &csHdr))
return SYSERR;
statMsg
= MALLOC(MAX_BUFFER_SIZE);
@@ -164,13 +165,13 @@
while ( count < ntohl(statMsg->totalCounters) ) {
/* printf("reading from socket starting %u of %d\n",
count, ntohl(statMsg->totalCounters) );*/
- if (SYSERR == readFromSocket(sock,
- (CS_MESSAGE_HEADER**)&statMsg)) {
+ if (SYSERR == connection_read(sock,
+ (MESSAGE_HEADER**)&statMsg)) {
FREE(statMsg);
return SYSERR;
}
if (ntohs(statMsg->header.size) < sizeof(CS_stats_reply_MESSAGE)) {
- BREAK();
+ GE_BREAK(ectx, 0);
ret = SYSERR;
break;
}
@@ -178,13 +179,13 @@
if (count == 0) {
ret = processor(_("Uptime (seconds)"),
(unsigned long long)
- ((cronTime(NULL) -
ntohll(statMsg->startTime))/cronSECONDS),
+ ((get_time() - ntohll(statMsg->startTime))/cronSECONDS),
cls);
}
for (i=0;i<ntohl(statMsg->statCounters);i++) {
if
(mpos+strlen(&((char*)(((CS_stats_reply_MESSAGE_GENERIC*)statMsg)->values))[mpos])+1
>
ntohs(statMsg->header.size) - sizeof(CS_stats_reply_MESSAGE)) {
- BREAK();
+ GE_BREAK(ectx, 0);
ret = SYSERR;
break; /* out of bounds! */
}
@@ -208,7 +209,8 @@
* @param processor function to call on each value
* @return OK on success, SYSERR on error
*/
-int requestAvailableProtocols(GNUNET_TCP_SOCKET * sock,
+int requestAvailableProtocols(struct GE_Context * ectx,
+ struct ClientServerConnection * sock,
ProtocolProcessor processor,
void * cls) {
CS_stats_get_supported_MESSAGE csStatMsg;
@@ -226,11 +228,11 @@
csStatMsg.handlerType = htons(j);
for (i=0;i<65535;i++) {
csStatMsg.type = htons(i);
- if (SYSERR == writeToSocket(sock,
- &csStatMsg.header))
+ if (SYSERR == connection_write(sock,
+ &csStatMsg.header))
return SYSERR;
- if (SYSERR == readTCPResult(sock,
- &supported))
+ if (SYSERR == connection_read_result(sock,
+ &supported))
return SYSERR;
if (supported == YES) {
ret = processor(i,
Modified: GNUnet/src/applications/stats/gnunet-stats.c
===================================================================
--- GNUnet/src/applications/stats/gnunet-stats.c 2006-07-30 06:22:18 UTC
(rev 3183)
+++ GNUnet/src/applications/stats/gnunet-stats.c 2006-07-30 21:40:59 UTC
(rev 3184)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing
authors)
+ (C) 2001, 2002, 2004, 2005, 2006 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,11 +27,11 @@
#include "platform.h"
#include "gnunet_util.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_error_loggers.h"
#include "gnunet_stats_lib.h"
#include "statistics.h"
-static int printProtocolsSelected;
-
static int lastIp2p = 42; /* not YES or NO */
/**
@@ -81,73 +81,21 @@
}
/**
- * Prints the usage information for this command if the user errs.
- * Aborts the program.
+ * All gnunet-transport-check command line options
*/
-static void printhelp() {
- static Help help[] = {
- HELP_CONFIG,
- HELP_HELP,
- HELP_HOSTNAME,
- HELP_LOGLEVEL,
- { 'p', "protocols", NULL,
- gettext_noop("prints supported protocol messages") },
- HELP_VERSION,
- HELP_END,
- };
- formatHelp("gnunet-stats [OPTIONS]",
- _("Print statistics about GNUnet operations."),
- help);
-}
+static struct CommandLineOption gnunetstatsOptions[] = {
+ COMMAND_LINE_OPTION_CFG_FILE, /* -c */
+ COMMAND_LINE_OPTION_HELP(gettext_noop("Print statistics about GNUnet
operations.")), /* -h */
+ COMMAND_LINE_OPTION_HOSTNAME, /* -H */
+ COMMAND_LINE_OPTION_LOGGING, /* -L */
+ { 'p', "protocols", NULL,
+ gettext_noop("prints supported protocol messages"),
+ 0, &gnunet_getopt_configure_set_option, "STATS:PRINT-PROTOCOLS=YES" },
+ COMMAND_LINE_OPTION_VERSION(PACKAGE_VERSION), /* -v */
+ COMMAND_LINE_OPTION_END,
+};
-/**
- * Parse the options.
- *
- * @param argc the number of options
- * @param argv the option list (including keywords)
- * @return SYSERR if we should abort, OK to continue
- */
-static int parseOptions(int argc,
- char ** argv) {
- int option_index;
- int c;
- while (1) {
- static struct GNoption long_options[] = {
- LONG_DEFAULT_OPTIONS,
- { "protocols", 0, 0, 'p' },
- { 0,0,0,0 }
- };
- option_index = 0;
- c = GNgetopt_long(argc,
- argv,
- "c:dhHL:pv",
- long_options,
- &option_index);
- if (c == -1)
- break; /* No more flags to process */
- if (YES == parseDefaultOptions(c, GNoptarg))
- continue;
- switch(c) {
- case 'v':
- printf("GNUnet v%s, gnunet-stats v%s\n",
- VERSION, STATS_VERSION);
- return SYSERR;
- case 'h':
- printhelp();
- return SYSERR;
- case 'p':
- printProtocolsSelected = YES;
- break;
- default:
- LOG(LOG_FAILURE,
- _("Use --help to get a list of options.\n"));
- return -1;
- } /* end of parsing commandline */
- } /* while (1) */
- return OK;
-}
-
/**
* The main function to obtain statistics from gnunetd.
*
@@ -155,32 +103,57 @@
* @param argv command line arguments
* @return 0 ok, 1 on error
*/
-int main(int argc, char ** argv) {
+int main(int argc,
+ const char ** argv) {
int res;
- GNUNET_TCP_SOCKET * sock;
+ struct ClientServerConnection * sock;
+ struct GC_Configuration * cfg;
+ struct GE_Context * ectx;
- if (SYSERR == initUtil(argc, argv, &parseOptions))
- return 0;
- sock = getClientSocket();
+ ectx = GE_create_context_stderr(NO,
+ GE_WARNING | GE_ERROR | GE_FATAL |
+ GE_USER | GE_ADMIN | GE_DEVELOPER |
+ GE_IMMEDIATE | GE_BULK);
+ GE_setDefaultContext(ectx);
+ cfg = GC_create_C_impl();
+ GE_ASSERT(ectx, cfg != NULL);
+ if (-1 == gnunet_parse_options("gnunet-stats",
+ ectx,
+ cfg,
+ gnunetstatsOptions,
+ (unsigned int) argc,
+ argv)) {
+ GC_free(cfg);
+ GE_free_context(ectx);
+ return -1;
+ }
+ sock = client_connection_create(ectx,
+ cfg);
if (sock == NULL) {
fprintf(stderr,
_("Error establishing connection with gnunetd.\n"));
return 1;
}
- res = requestStatistics(sock,
+ res = requestStatistics(ectx,
+ sock,
(StatisticsProcessor) &printStatistics,
stdout);
- if ((printProtocolsSelected == YES) &&
- (res == OK)) {
- res = requestAvailableProtocols(sock,
+ if ( (YES == GC_get_configuration_value_yesno(cfg,
+ "STATS",
+ "PRINT-PROTOCOLS",
+ NO)) &&
+ (res == OK) ) {
+ res = requestAvailableProtocols(ectx,
+ sock,
(ProtocolProcessor) &printProtocols,
stdout);
}
if (res != OK)
fprintf(stderr,
_("Error reading information from gnunetd.\n"));
- releaseClientSocket(sock);
- doneUtil();
+ connection_destroy(sock);
+ GC_free(cfg);
+ GE_free_context(ectx);
return (res == OK) ? 0 : 1;
}
Modified: GNUnet/src/applications/stats/statistics.c
===================================================================
--- GNUnet/src/applications/stats/statistics.c 2006-07-30 06:22:18 UTC (rev
3183)
+++ GNUnet/src/applications/stats/statistics.c 2006-07-30 21:40:59 UTC (rev
3184)
@@ -66,7 +66,7 @@
/**
* lock for the stat module
*/
-static Mutex statLock;
+static struct MUTEX * statLock;
/**
* The core API.
@@ -81,11 +81,11 @@
*/
static int statHandle(const char * name) {
int i;
- GNUNET_ASSERT(name != NULL);
- MUTEX_LOCK(&statLock);
+ GE_ASSERT(NULL, name != NULL);
+ MUTEX_LOCK(statLock);
for (i=0;i<statCounters;i++)
if (0 == strcmp(descriptions[i], name)) {
- MUTEX_UNLOCK(&statLock);
+ MUTEX_UNLOCK(statLock);
return i;
}
@@ -97,7 +97,7 @@
statCounters,
statCounters+1);
descriptions[statCounters-1] = STRDUP(name);
- MUTEX_UNLOCK(&statLock);
+ MUTEX_UNLOCK(statLock);
return statCounters-1;
}
@@ -110,28 +110,28 @@
*/
static void statSet(const int handle,
const unsigned long long value) {
- MUTEX_LOCK(&statLock);
+ MUTEX_LOCK(statLock);
if ( (handle < 0) ||
(handle >= statCounters) ) {
- BREAK();
- MUTEX_UNLOCK(&statLock);
+ GE_BREAK(NULL, 0);
+ MUTEX_UNLOCK(statLock);
return;
}
values[handle] = value;
- MUTEX_UNLOCK(&statLock);
+ MUTEX_UNLOCK(statLock);
}
static unsigned long long statGet(const int handle) {
unsigned long long ret;
- MUTEX_LOCK(&statLock);
+ MUTEX_LOCK(statLock);
if ( (handle < 0) ||
(handle >= statCounters) ) {
- BREAK();
- MUTEX_UNLOCK(&statLock);
+ GE_BREAK(NULL, 0);
+ MUTEX_UNLOCK(statLock);
return -1;
}
ret = values[handle];
- MUTEX_UNLOCK(&statLock);
+ MUTEX_UNLOCK(statLock);
return ret;
}
@@ -144,15 +144,15 @@
*/
static void statChange(const int handle,
const int delta) {
- MUTEX_LOCK(&statLock);
+ MUTEX_LOCK(statLock);
if ( (handle < 0) ||
(handle >= statCounters) ) {
- BREAK();
- MUTEX_UNLOCK(&statLock);
+ GE_BREAK(NULL, 0);
+ MUTEX_UNLOCK(statLock);
return;
}
values[handle] += delta;
- MUTEX_UNLOCK(&statLock);
+ MUTEX_UNLOCK(statLock);
}
@@ -162,7 +162,7 @@
void release_module_stats() {
int i;
- MUTEX_DESTROY(&statLock);
+ MUTEX_DESTROY(statLock);
for (i=0;i<statCounters;i++)
FREE(descriptions[i]);
FREENONNULL(descriptions);
@@ -184,8 +184,8 @@
api.set = &statSet;
api.change = &statChange;
api.get = &statGet;
- cronTime(&startTime);
- MUTEX_CREATE_RECURSIVE(&statLock);
+ startTime = get_time();
+ statLock = MUTEX_CREATE(YES);
return &api;
}
@@ -215,9 +215,15 @@
}
static void immediateUpdates() {
- statSet(stat_handle_cpu_load, getCPULoad());
- statSet(stat_handle_network_load_up, getNetworkLoadUp());
- statSet(stat_handle_network_load_down, getNetworkLoadDown());
+ statSet(stat_handle_cpu_load,
+ os_cpu_get_load(coreAPI->ectx,
+ coreAPI->cfg));
+ statSet(stat_handle_network_load_up,
+ os_network_monitor_get_load(coreAPI->load_monitor,
+ Upload));
+ statSet(stat_handle_network_load_down,
+ os_network_monitor_get_load(coreAPI->load_monitor,
+ Download));
statSet(stat_connected,
coreAPI->forAllConnectedNodes(NULL, NULL));
}
@@ -229,8 +235,8 @@
*
* @param originalRequestMessage ignored at this point.
*/
-static int sendStatistics(ClientHandle sock,
- const CS_MESSAGE_HEADER * originalRequestMessage) {
+static int sendStatistics(struct ClientHandle * sock,
+ const MESSAGE_HEADER * originalRequestMessage) {
CS_stats_reply_MESSAGE * statMsg;
int pos; /* position in the values-descriptions */
int start;
@@ -273,7 +279,7 @@
mpos += strlen(descriptions[pos])+1;
}
statMsg->statCounters = htonl(end - start);
- GNUNET_ASSERT(mpos + sizeof(CS_stats_reply_MESSAGE) < MAX_BUFFER_SIZE);
+ GE_ASSERT(NULL, mpos + sizeof(CS_stats_reply_MESSAGE) < MAX_BUFFER_SIZE);
statMsg->header.size = htons(mpos + sizeof(CS_stats_reply_MESSAGE));
/* printf("writing message of size %d with stats %d to %d out of %d to
socket\n",
@@ -291,15 +297,15 @@
/**
* Handle a request to see if a particular p2p message is supported.
*/
-static int handleMessageSupported(ClientHandle sock,
- const CS_MESSAGE_HEADER * message) {
+static int handleMessageSupported(struct ClientHandle * sock,
+ const MESSAGE_HEADER * message) {
unsigned short type;
unsigned short htype;
int supported;
CS_stats_get_supported_MESSAGE * cmsg;
if (ntohs(message->size) != sizeof(CS_stats_get_supported_MESSAGE)) {
- BREAK();
+ GE_BREAK(NULL, 0);
return SYSERR;
}
cmsg = (CS_stats_get_supported_MESSAGE *) message;
@@ -317,10 +323,10 @@
* @param msg the request from the client
* @returns OK if ok, SYSERR if not.
*/
-static int processGetConnectionCountRequest(ClientHandle client,
- const CS_MESSAGE_HEADER * msg) {
- if (ntohs(msg->size) != sizeof(CS_MESSAGE_HEADER)) {
- BREAK();
+static int processGetConnectionCountRequest(struct ClientHandle * client,
+ const MESSAGE_HEADER * msg) {
+ if (ntohs(msg->size) != sizeof(MESSAGE_HEADER)) {
+ GE_BREAK(NULL, 0);
return SYSERR;
}
return coreAPI->sendValueToClient
@@ -332,7 +338,7 @@
* Handler for processing noise.
*/
static int processNoise(const PeerIdentity * sender,
- const P2P_MESSAGE_HEADER * msg) {
+ const MESSAGE_HEADER * msg) {
statChange(stat_bytes_noise_received,
ntohs(msg->size));
return OK;
@@ -343,22 +349,24 @@
static CoreAPIForApplication * myCoreAPI;
int initialize_module_stats(CoreAPIForApplication * capi) {
- GNUNET_ASSERT(myCoreAPI == NULL);
+ GE_ASSERT(capi->ectx,
+ myCoreAPI == NULL);
myCoreAPI = capi;
myApi = capi->requestService("stats");
if (myApi == NULL) {
- BREAK();
+ GE_BREAK(capi->ectx, 0);
myCoreAPI = NULL;
return SYSERR;
}
initializeStats();
- LOG(LOG_DEBUG,
- "`%s' registering client handlers %d %d %d and p2p handler %d\n",
- "stats",
- CS_PROTO_traffic_COUNT,
- CS_PROTO_stats_GET_STATISTICS,
- CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,
- P2P_PROTO_noise);
+ GE_LOG(capi->ectx,
+ GE_INFO | GE_USER | GE_REQUEST,
+ _("`%s' registering client handlers %d %d %d and p2p handler %d\n"),
+ "stats",
+ CS_PROTO_traffic_COUNT,
+ CS_PROTO_stats_GET_STATISTICS,
+ CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,
+ P2P_PROTO_noise);
capi->registerClientHandler(CS_PROTO_stats_GET_STATISTICS,
&sendStatistics);
capi->registerClientHandler(CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,
@@ -369,14 +377,17 @@
&processGetConnectionCountRequest);
capi->registerHandler(P2P_PROTO_noise,
&processNoise);
- setConfigurationString("ABOUT",
- "stats",
- gettext_noop("keeps statistics about gnunetd's
operation"));
+ GE_ASSERT(capi->ectx,
+ 0 == GC_set_configuration_value_string(capi->cfg,
+ capi->ectx,
+ "ABOUT",
+ "stats",
+ gettext_noop("keeps
statistics about gnunetd's operation")));
return OK;
}
int done_module_stats() {
- GNUNET_ASSERT(myCoreAPI != NULL);
+ GE_ASSERT(NULL, myCoreAPI != NULL);
coreAPI->unregisterClientHandler(CS_PROTO_stats_GET_STATISTICS,
&sendStatistics);
coreAPI->unregisterClientHandler(CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,
Modified: GNUnet/src/applications/stats/statistics.h
===================================================================
--- GNUnet/src/applications/stats/statistics.h 2006-07-30 06:22:18 UTC (rev
3183)
+++ GNUnet/src/applications/stats/statistics.h 2006-07-30 21:40:59 UTC (rev
3184)
@@ -33,7 +33,7 @@
* numbers. If needed, several messages are used.
*/
typedef struct {
- CS_MESSAGE_HEADER header;
+ MESSAGE_HEADER header;
/**
* For 64-bit alignment...
*/
@@ -69,7 +69,7 @@
* the message we are requesting the status of.
*/
typedef struct {
- CS_MESSAGE_HEADER header;
+ MESSAGE_HEADER header;
/**
* The type of the message (XX_CS_PROTO_XXXX)
Modified: GNUnet/src/include/gnunet_stats_lib.h
===================================================================
--- GNUnet/src/include/gnunet_stats_lib.h 2006-07-30 06:22:18 UTC (rev
3183)
+++ GNUnet/src/include/gnunet_stats_lib.h 2006-07-30 21:40:59 UTC (rev
3184)
@@ -28,6 +28,7 @@
#define GNUNET_STATS_LIB_H
#include "gnunet_util.h"
+#include "gnunet_util_network_client.h"
#ifdef __cplusplus
extern "C" {
@@ -63,7 +64,8 @@
* @param processor function to call on each value
* @return OK on success, SYSERR on error
*/
-int requestStatistics(GNUNET_TCP_SOCKET * sock,
+int requestStatistics(struct GE_Context * ectx,
+ struct ClientServerConnection * sock,
StatisticsProcessor processor,
void * cls);
@@ -82,7 +84,8 @@
* @param processor function to call on each value
* @return OK on success, SYSERR on error
*/
-int requestAvailableProtocols(GNUNET_TCP_SOCKET * sock,
+int requestAvailableProtocols(struct GE_Context * ectx,
+ struct ClientServerConnection * sock,
ProtocolProcessor processor,
void * cls);
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-07-30 06:22:18 UTC (rev 3183)
+++ GNUnet/todo 2006-07-30 21:40:59 UTC (rev 3184)
@@ -25,8 +25,8 @@
* server:
+ needs testing, also likely to be missing features
* applications:
- + fragmentation, identity, pingpong, session, transport compile
- + for core: topology_default, stats
+ + fragmentation, identity, pingpong, session, transport, stats compile
+ + for core: topology_default
+ for basics: advertising, bootstrap_http, state, getoption, traffic
+ for fs: datastore, fs, gap, sqstore_sqlite
+ rest: sqstore_mysql, dht, chat, kvstore_sqlite,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3184 - in GNUnet: . src/applications/session src/applications/stats src/include,
grothoff <=