From cffaa8b4a6591c02325a368dcc7cd3b999d1ef60 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 16 Dec 2014 20:57:09 +0000 Subject: removing experimentation: replaced by sensors --- configure.ac | 2 - src/Makefile.am | 2 - src/experimentation/Makefile.am | 72 -- src/experimentation/experimentation.conf.in | 11 - .../gnunet-daemon-experimentation.c | 124 --- .../gnunet-daemon-experimentation.h | 499 --------- .../gnunet-daemon-experimentation_capabilities.c | 172 --- .../gnunet-daemon-experimentation_experiments.c | 503 --------- .../gnunet-daemon-experimentation_nodes.c | 1157 -------------------- .../gnunet-daemon-experimentation_scheduler.c | 448 -------- .../gnunet-daemon-experimentation_storage.c | 53 - .../test_experimentation_clique.conf | 43 - .../test_experimentation_clique_connect.c | 416 ------- .../test_experimentation_clique_run.c | 389 ------- src/experimentation/test_experiments.exp | 9 - 15 files changed, 3900 deletions(-) delete mode 100644 src/experimentation/Makefile.am delete mode 100644 src/experimentation/experimentation.conf.in delete mode 100644 src/experimentation/gnunet-daemon-experimentation.c delete mode 100644 src/experimentation/gnunet-daemon-experimentation.h delete mode 100644 src/experimentation/gnunet-daemon-experimentation_capabilities.c delete mode 100644 src/experimentation/gnunet-daemon-experimentation_experiments.c delete mode 100644 src/experimentation/gnunet-daemon-experimentation_nodes.c delete mode 100644 src/experimentation/gnunet-daemon-experimentation_scheduler.c delete mode 100644 src/experimentation/gnunet-daemon-experimentation_storage.c delete mode 100644 src/experimentation/test_experimentation_clique.conf delete mode 100644 src/experimentation/test_experimentation_clique_connect.c delete mode 100644 src/experimentation/test_experimentation_clique_run.c delete mode 100644 src/experimentation/test_experiments.exp diff --git a/configure.ac b/configure.ac index 1db9b1b76..4391b20a7 100644 --- a/configure.ac +++ b/configure.ac @@ -1443,8 +1443,6 @@ src/dv/Makefile src/dv/dv.conf src/env/Makefile src/exit/Makefile -src/experimentation/Makefile -src/experimentation/experimentation.conf src/fragmentation/Makefile src/fs/Makefile src/fs/fs.conf diff --git a/src/Makefile.am b/src/Makefile.am index 0902d259f..0452a4ad3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,7 +7,6 @@ if HAVE_TESTING TESTBED = testbed CONSENSUS = consensus SECRETSHARING = secretsharing - EXPERIMENTATION = experimentation SENSOR = sensor SENSORDASHBOARD = sensordashboard endif @@ -23,7 +22,6 @@ if HAVE_EXPERIMENTAL social \ $(CONSENSUS) \ $(SECRETSHARING) \ - $(EXPERIMENTATION) \ $(SENSOR) \ $(SENSORDASHBOARD) endif diff --git a/src/experimentation/Makefile.am b/src/experimentation/Makefile.am deleted file mode 100644 index 26a467393..000000000 --- a/src/experimentation/Makefile.am +++ /dev/null @@ -1,72 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/src/include - -pkgcfgdir= $(pkgdatadir)/config.d/ - -libexecdir= $(pkglibdir)/libexec/ - -pkgcfg_DATA = \ - experimentation.conf - -if MINGW - WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -liconv -lstdc++ -lcomdlg32 -lgdi32 -endif - -if USE_COVERAGE - AM_CFLAGS = --coverage -O0 - XLIB = -lgcov -endif - - -if HAVE_EXPERIMENTAL - TEXT_EXP_CLIQUE = test_experimentation_clique_connect test_experimentation_clique_run -endif - -check_PROGRAMS = \ - $(TEXT_EXP_CLIQUE) - -if ENABLE_TEST_RUN - AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; - TESTS = \ - $(TEXT_EXP_CLIQUE) -endif - -libexec_PROGRAMS = \ - gnunet-daemon-experimentation - -gnunet_daemon_experimentation_SOURCES = \ - gnunet-daemon-experimentation.c gnunet-daemon-experimentation.h \ - gnunet-daemon-experimentation_capabilities.c \ - gnunet-daemon-experimentation_nodes.c \ - gnunet-daemon-experimentation_scheduler.c \ - gnunet-daemon-experimentation_experiments.c \ - gnunet-daemon-experimentation_storage.c -gnunet_daemon_experimentation_LDADD = \ - $(top_builddir)/src/core/libgnunetcore.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ - $(top_builddir)/src/util/libgnunetutil.la - -test_experimentation_clique_connect_SOURCES = \ - test_experimentation_clique_connect.c -test_experimentation_clique_connect_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ - $(top_builddir)/src/testbed/libgnunettestbed.la - -test_experimentation_clique_run_SOURCES = \ - test_experimentation_clique_run.c -test_experimentation_clique_run_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ - $(top_builddir)/src/testbed/libgnunettestbed.la - -#test_experimentation_clique_run_SOURCES = \ -# test_experimentation_clique_run.c -#test_experimentation_clique_run_LDADD = \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(top_builddir)/src/statistics/libgnunetstatistics.la \ -# $(top_builddir)/src/testbed/libgnunettestbed.la - - -EXTRA_DIST = \ - test_experimentation_clique.conf \ - test_experiments.exp \ No newline at end of file diff --git a/src/experimentation/experimentation.conf.in b/src/experimentation/experimentation.conf.in deleted file mode 100644 index 6b3974684..000000000 --- a/src/experimentation/experimentation.conf.in +++ /dev/null @@ -1,11 +0,0 @@ -[experimentation] -AUTOSTART = NO -# PORT = 2106 -HOSTNAME = localhost -BINARY = gnunet-daemon-experimentation -ACCEPT_FROM = 127.0.0.1; -ACCEPT_FROM6 = ::1; -UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-daemon-experimentation.sock -UNIX_MATCH_UID = YES -UNIX_MATCH_GID = YES -ISSUERS = TFRM29O2RQNKLVBQIGODJ6GD58LSQ2NM9TNFBC6N48BRJHQO38Q73N2OM3V4CLKDM6CILQV4CU8PMJDRG0FNB0PDI057DBRANMLPLRG diff --git a/src/experimentation/gnunet-daemon-experimentation.c b/src/experimentation/gnunet-daemon-experimentation.c deleted file mode 100644 index e0ebdf365..000000000 --- a/src/experimentation/gnunet-daemon-experimentation.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009 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 experimentation/gnunet-daemon-experimentation.c - * @brief experimentation daemon - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet-daemon-experimentation.h" - - -/** - * Statistics handle shared between components - */ -struct GNUNET_STATISTICS_Handle *GED_stats; - - -/** - * Configuration handle shared between components - */ -struct GNUNET_CONFIGURATION_Handle *GED_cfg; - - -/** - * Task run during shutdown to stop all submodules of the experimentation daemon. - * - * @param cls unused - * @param tc unused - */ -static void -shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Experimentation daemon shutting down ...\n")); - - GED_scheduler_stop (); - GED_nodes_stop (); - GED_experiments_stop (); - GED_storage_stop (); - GED_capabilities_stop (); -} - - -/** - * Function starting all submodules of the experimentation daemon. - * - * @param cls always NULL - * @param args temaining command line arguments - * @param cfgfile configuration file used - * @param cfg configuration handle - */ -static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Experimentation daemon starting ...\n")); - - GED_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; - GED_stats = GNUNET_STATISTICS_create ("experimentation", cfg); - if (NULL == GED_stats) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to create statistics!\n")); - return; - } - - GED_capabilities_start (); - - GED_storage_start (); - - if (GNUNET_SYSERR == GED_experiments_start ()) - { - GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); - return; - } - - GED_nodes_start (); - GED_scheduler_start (); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, - NULL); -} - - -/** - * The main function for the experimentation daemon. - * - * @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) -{ - static const struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - return (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "experimentation", - _("GNUnet experimentation daemon"), options, - &run, NULL)) ? 0 : 1; -} - -/* end of gnunet-daemon-experimentation.c */ diff --git a/src/experimentation/gnunet-daemon-experimentation.h b/src/experimentation/gnunet-daemon-experimentation.h deleted file mode 100644 index 977d663e8..000000000 --- a/src/experimentation/gnunet-daemon-experimentation.h +++ /dev/null @@ -1,499 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009 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 experimentation/gnunet-daemon-experimentation.h - * @brief experimentation daemon - * @author Christian Grothoff - * @author Matthias Wachs - */ -#ifndef GNUNET_DAEMON_EXPERIMENTATION_H -#define GNUNET_DAEMON_EXPERIMENTATION_H -#include "platform.h" -#include "gnunet_getopt_lib.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" - - -/** - * Timeout between request and expected response - */ -#define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - -/** - * Default experiment frequency - */ -#define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 6) - -/** - * Default experiment duration - */ -#define EXP_DEFAULT_EXP_DUR GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - -/** - * Statistics handle shared between components - */ -extern struct GNUNET_STATISTICS_Handle *GED_stats; - -/** - * Configuration handle shared between components - */ -extern struct GNUNET_CONFIGURATION_Handle *GED_cfg; - -/** - * Capability value shared between components - */ -extern uint32_t GSE_node_capabilities; - - -/** - * Capabilities a node has or an experiment requires - */ -enum GNUNET_EXPERIMENTATION_capabilities -{ - NONE = 0, - PLUGIN_TCP = 1, - PLUGIN_UDP = 2, - PLUGIN_UNIX = 4, - PLUGIN_HTTP_CLIENT = 8, - PLUGIN_HTTP_SERVER = 16, - PLUGIN_HTTPS_CLIENT = 32, - PLUGIN_HTTPS_SERVER = 64, - PLUGIN_WLAN = 128, - HAVE_IPV6 = 256, - BEHIND_NAT = 512 -}; - - -/** - * Struct to store information about a specific experiment - */ -struct Experiment -{ - /* Header */ - /* ----------------- */ - char *name; - - /** - * Experiment issuer - */ - struct GNUNET_CRYPTO_EddsaPublicKey issuer; - - /** - * Experiment version as timestamp of creation - */ - struct GNUNET_TIME_Absolute version; - - /** - * Description - */ - char *description; - - /** - * Required capabilities - */ - uint32_t required_capabilities; - - /* Experiment timing */ - /* ----------------- */ - - /** - * When to start experiment - */ - struct GNUNET_TIME_Absolute start; - - /** - * When to end experiment - */ - struct GNUNET_TIME_Absolute stop; - - /** - * How often to run experiment - */ - struct GNUNET_TIME_Relative frequency; - - /** - * How long to run each execution - */ - struct GNUNET_TIME_Relative duration; - - - /* Experiment itself */ - /* ----------------- */ - - /* TBD */ -}; - - -/** - * A experimentation node - */ -struct Node -{ - /** - * Peer id - */ - struct GNUNET_PeerIdentity id; - - /** - * Task for response timeout - */ - GNUNET_SCHEDULER_TaskIdentifier timeout_task; - - /** - * Core transmission handle - */ - struct GNUNET_CORE_TransmitHandle *cth; - - /** - * Node capabilities - */ - uint32_t capabilities; - - /** - * Experiment version as timestamp of creation - */ - struct GNUNET_TIME_Absolute version; - - struct NodeComCtx *e_req_head; - - struct NodeComCtx *e_req_tail; - - /** - * Array of issuers accepted by this neighbor. - */ - struct GNUNET_CRYPTO_EddsaPublicKey *issuer_id; - - unsigned int issuer_count; - -}; - - -GNUNET_NETWORK_STRUCT_BEGIN - -/** - * Experimentation request message - * Used to detect experimentation capability - * - * This struct is followed by issuer identities: - * (issuer_count * struct GNUNET_CRYPTO_EddsaPublicKey) - * - */ -struct Experimentation_Request -{ - struct GNUNET_MessageHeader msg; - - uint32_t capabilities GNUNET_PACKED; - - uint32_t issuer_count GNUNET_PACKED; -}; - - -/** - * Experimentation response message - * Sent if peer is running the daemon - * - * This struct is followed by issuer identities: - * (issuer_count * struct GNUNET_CRYPTO_EddsaPublicKey) - */ -struct Experimentation_Response -{ - struct GNUNET_MessageHeader msg; - - uint32_t capabilities GNUNET_PACKED; - - uint32_t issuer_count GNUNET_PACKED; -}; - - -/** - * Struct to store information about an experiment issuer - */ -struct Issuer -{ - struct GNUNET_CRYPTO_EddsaPublicKey pubkey; -}; - - -/** - * Hashmap containing valid experiment issuers - * (the key is the hash of the respective public key, - * the values are of type `struct Issuer'). - */ -struct GNUNET_CONTAINER_MultiHashMap *valid_issuers; - -/** - * Experiment start message - * - * struct is followed by string with length len_name - */ -struct GED_start_message -{ - struct GNUNET_MessageHeader header; - - /** - * String length of experiment name following the struct - */ - uint32_t len_name GNUNET_PACKED; - - /** - * Experiment issuer - */ - struct GNUNET_CRYPTO_EddsaPublicKey issuer; - - /** - * Experiment version as timestamp of creation - */ - struct GNUNET_TIME_AbsoluteNBO version_nbo; -}; - - -struct GED_start_ack_message -{ - struct GNUNET_MessageHeader header; - - /** - * String length of experiment name following the struct - */ - uint32_t len_name GNUNET_PACKED; - - /** - * Experiment issuer - */ - struct GNUNET_CRYPTO_EddsaPublicKey issuer; - - /** - * Experiment version as timestamp of creation - */ - struct GNUNET_TIME_AbsoluteNBO version_nbo; -}; - - -struct GED_stop_message -{ - struct GNUNET_MessageHeader header; - - /** - * String length of experiment name following the struct - */ - uint32_t len_name GNUNET_PACKED; - - /** - * Experiment issuer - */ - struct GNUNET_CRYPTO_EddsaPublicKey issuer; - - /** - * Experiment version as timestamp of creation - */ - struct GNUNET_TIME_AbsoluteNBO version_nbo; -}; - -GNUNET_NETWORK_STRUCT_END - - -int -GED_nodes_rts (struct Node *n); - - -int -GED_nodes_send_start (struct Node *n, struct Experiment *e); - - -/** - * Confirm a experiment START with a node - * - * @return #GNUNET_NO if core was busy with sending, #GNUNET_OK otherwise - */ -int -GED_nodes_send_start_ack (struct Node *n, struct Experiment *e); - -/** - * Start the nodes management - */ -void -GED_nodes_start (void); - - -/** - * Stop the nodes management - */ -void -GED_nodes_stop (void); - - -/** - * Print a single capability value - * - * @param cap capability value - * @return the string to print - */ -const char * -GED_capability_to_str (uint32_t cap); - - -/** - * Are the capabilities provided? - * - * @param have bitstring containing the provided capabilities - * @param desired bitstring containing the desired capabilities\ - * @return #GNUNET_YES or #GNUNET_NO - */ -int -GED_capabilities_have (uint32_t have, uint32_t desired); - - -/** - * Start the detecting capabilities - */ -void -GED_capabilities_start (void); - - -/** - * Stop the detecting capabilities - */ -void -GED_capabilities_stop (void); - - -/** - * Start experiments management - * - * @return #GNUNET_YES or #GNUNET_NO - */ -int -GED_experiments_issuer_accepted (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer_ID); - - -/* - * Find an experiment based on issuer name and version - * - * @param issuer the issuer - * @param name experiment name - * @param version experiment version - * @return the experiment or NULL if not found - */ -struct Experiment * -GED_experiments_find (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer, - const char *name, - const struct GNUNET_TIME_Absolute version); - - -typedef void (*GNUNET_EXPERIMENTATION_experiments_get_cb) (struct Node *n, - struct Experiment *e); - - -void -GED_experiments_get (struct Node *n, - struct GNUNET_CRYPTO_EddsaPublicKey *issuer, - GNUNET_EXPERIMENTATION_experiments_get_cb get_cb); - - -/** - * Start experiments management - * - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int -GED_experiments_start (void); - - -/** - * Stop experiments management - */ -void -GED_experiments_stop (void); - - -/** - * Handle a START message from a remote node - * - * @param n the node - * @param e the experiment - */ -void -GED_scheduler_handle_start (struct Node *n, struct Experiment *e); - - -/** - * Handle a START_ACL message from a remote node - * - * @param n the node - * @param e the experiment - */ -void -GED_scheduler_handle_start_ack (struct Node *n, struct Experiment *e); - - -/** - * Handle a STOP message from a remote node - * - * @param n the node - * @param e the experiment - */ -void -GED_scheduler_handle_stop (struct Node *n, struct Experiment *e); - - -/** - * Add a new experiment for a node - * - * @param n the node - * @param e the experiment - * @param outbound are we initiator (#GNUNET_YES) or client (#GNUNET_NO)? - */ -void -GED_scheduler_add (struct Node *n, - struct Experiment *e, - int outbound); - - -/** - * Start the scheduler component - */ -void -GED_scheduler_start (void); - - -/** - * Stop the scheduler component - */ -void -GED_scheduler_stop (void); - - -/** - * Start the storage component - */ -void -GED_storage_start (void); - - -/** - * Stop the storage component - */ -void -GED_storage_stop (void); - - -#endif /* #ifndef GNUNET_DAEMON_EXPERIMENTATION_H */ -/* end of gnunet-daemon-experimentation.h */ diff --git a/src/experimentation/gnunet-daemon-experimentation_capabilities.c b/src/experimentation/gnunet-daemon-experimentation_capabilities.c deleted file mode 100644 index 7d74c2827..000000000 --- a/src/experimentation/gnunet-daemon-experimentation_capabilities.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009 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 experimentation/gnunet-daemon-experimentation_capabilities.c - * @brief experimentation daemon: capabilities management - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet-daemon-experimentation.h" - - -/** - * Capability value shared between components - */ -uint32_t GSE_node_capabilities; - - -/** - * Capabilities defined at the moment - */ -#define GNUNET_EXPERIMENTATION_capabilities_count 11 - - -/** - * Capabilities a node has or an experiment requires string - */ -#define GNUNET_EXPERIMENTATION_capabilities_string {"NONE", "PLUGIN_TCP", "PLUGIN_UDP", "PLUGIN_UNIX", "PLUGIN_HTTP_CLIENT", "PLUGIN_HTTP_SERVER", "PLUGIN_HTTPS_CLIENT", "PLUGIN_HTTPS_SERVER", "PLUGIN_WLAN", "HAVE_IPV6", "BEHIND_NAT"} - - -/** - * Print a single capability value - * - * @param cap capability value - * @return the string to print - */ -const char * -GED_capability_to_str (uint32_t cap) -{ - char * capstr[] = GNUNET_EXPERIMENTATION_capabilities_string; - unsigned index = 0; - uint32_t test = 0; - - if (0 == cap) - return capstr[0]; - - index = (log(cap) / log (2)) + 1; - - test = 1 << (index - 1); - if (test != cap) - return "UNDEFINED"; - - if (index < GNUNET_EXPERIMENTATION_capabilities_count) - return capstr[index]; - else - return "UNDEFINED"; - - -} - - -/** - * Are the capabilities provided? - * - * @param have bitstring containing the provided capabilities - * @param desired bitstring containing the desired capabilities\ - * @return GNUNET_YES or GNUNET_NO - */ -int -GED_capabilities_have (uint32_t have, uint32_t desired) -{ - if (desired == (desired & have)) - return GNUNET_YES; - else - return GNUNET_NO; -} - - -/** - * Start the detecting capabilities - */ -void -GED_capabilities_start () -{ - char *plugins; - char *pos; - unsigned int c1; - uint32_t index; - GSE_node_capabilities = NONE; - - /* Plugins configured */ - - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (GED_cfg, - "TRANSPORT", "PLUGINS", &plugins)) - { - for (pos = strtok (plugins, " "); pos != NULL; pos = strtok (NULL, " ")) - { - if (0 == strcmp (pos, "tcp")) - GSE_node_capabilities |= PLUGIN_TCP; - else if (0 == strcmp (pos, "udp")) - GSE_node_capabilities |= PLUGIN_UDP; - else if (0 == strcmp (pos, "unix")) - GSE_node_capabilities |= PLUGIN_UNIX; - else if (0 == strcmp (pos, "http_client")) - GSE_node_capabilities |= PLUGIN_HTTP_CLIENT; - else if (0 == strcmp (pos, "http_server")) - GSE_node_capabilities |= PLUGIN_HTTP_SERVER; - else if (0 == strcmp (pos, "https_client")) - GSE_node_capabilities |= PLUGIN_HTTP_CLIENT; - else if (0 == strcmp (pos, "https_server")) - GSE_node_capabilities |= PLUGIN_HTTPS_SERVER; - else if (0 == strcmp (pos, "wlan")) - GSE_node_capabilities |= PLUGIN_WLAN; - } - GNUNET_free (plugins); - } - - /* IPv6 enabled - * FIXE: just having it not enabled is not really sufficient */ - if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (GED_cfg, - "NAT", "DISABLEV6")) - GSE_node_capabilities |= HAVE_IPV6; - - /* Behind NAT */ - if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (GED_cfg, - "NAT", "BEHIND_NAT")) - GSE_node_capabilities |= BEHIND_NAT; - - for (c1 = 0 ; c1 < 32; c1++) - { - index = 1; - index = index << c1; - if (GNUNET_YES == GED_capabilities_have (GSE_node_capabilities, index)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We have `%s'\n", - GED_capability_to_str(index)); - } - } -} - - -/** - * Stop the detecting capabilities - */ -void -GED_capabilities_stop () -{ - -} - -/* end of gnunet-daemon-experimentation_capabilities.c */ diff --git a/src/experimentation/gnunet-daemon-experimentation_experiments.c b/src/experimentation/gnunet-daemon-experimentation_experiments.c deleted file mode 100644 index 471a7bfdc..000000000 --- a/src/experimentation/gnunet-daemon-experimentation_experiments.c +++ /dev/null @@ -1,503 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2012,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 experimentation/gnunet-daemon-experimentation_experiments.c - * @brief experimentation daemon: experiment management - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet-daemon-experimentation.h" - - -/** - * Hashmap containing valid experiment issuers. - */ -struct GNUNET_CONTAINER_MultiHashMap *valid_issuers; - -/** - * Hashmap containing valid experiments - */ -static struct GNUNET_CONTAINER_MultiHashMap *experiments; - - -/** - * Verify experiment signature - * - * @param i issuer - * @param e experiment - * @return #GNUNET_OK or #GNUNET_SYSERR - */ -static int -experiment_verify (struct Issuer *i, struct Experiment *e) -{ - GNUNET_assert (NULL != i); - GNUNET_assert (NULL != e); - - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Verification: to be implemented\n"); - return GNUNET_OK; -} - - -static int -free_experiment (void *cls, - const struct GNUNET_HashCode * key, - void *value) -{ - struct Experiment *e = value; - - GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (experiments, key, value)); - GNUNET_free_non_null (e->description); - GNUNET_free_non_null (e->name); - GNUNET_free (e); - return GNUNET_OK; -} - - -/** - * Free issuer element - * - * @param cls unused - * @param key the key - * @param value the issuer element to free - * @return GNUNET_OK to continue - */ -static int -free_issuer (void *cls, - const struct GNUNET_HashCode * key, - void *value) -{ - struct Issuer *i = value; - - GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (valid_issuers, - key, - i)); - GNUNET_free (i); - return GNUNET_OK; -} - - -/** - * Is peer a valid issuer - * - * @return #GNUNET_YES or #GNUNET_NO - */ -int -GED_experiments_issuer_accepted (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer_id) -{ - struct GNUNET_HashCode hash; - - GNUNET_CRYPTO_hash (issuer_id, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey), &hash); - if (GNUNET_CONTAINER_multihashmap_contains (valid_issuers, &hash)) - return GNUNET_YES; - return GNUNET_NO; -} - - -/** - * Get the key under which the given experiment is stored in the - * experiment map. - */ -static void -get_experiment_key (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer, - const char *name, - const struct GNUNET_TIME_Absolute version, - struct GNUNET_HashCode *key) -{ - GNUNET_assert (GNUNET_YES == - GNUNET_CRYPTO_kdf (key, sizeof (struct GNUNET_HashCode), - issuer, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey), - name, strlen (name), - &version, sizeof (version), - NULL, 0)); -} - - -/** - * Find an experiment based on issuer name and version - * - * @param issuer the issuer - * @param name experiment name - * @param version experiment version - * @return the experiment or NULL if not found - */ -struct Experiment * -GED_experiments_find (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer, - const char *name, - const struct GNUNET_TIME_Absolute version) -{ - struct GNUNET_HashCode hc; - - get_experiment_key (issuer, - name, - version, - &hc); - return GNUNET_CONTAINER_multihashmap_get (experiments, - &hc); -} - - -struct GetCtx -{ - struct Node *n; - - GNUNET_EXPERIMENTATION_experiments_get_cb get_cb; - - struct GNUNET_CRYPTO_EddsaPublicKey *issuer; -}; - - -static int -get_it (void *cls, - const struct GNUNET_HashCode *key, - void *value) -{ - struct GetCtx *get_ctx = cls; - struct Experiment *e = value; - - if (0 == memcmp (&e->issuer, - get_ctx->issuer, - sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) - get_ctx->get_cb (get_ctx->n, e); - return GNUNET_OK; -} - - -void -GED_experiments_get (struct Node *n, - struct GNUNET_CRYPTO_EddsaPublicKey *issuer, - GNUNET_EXPERIMENTATION_experiments_get_cb get_cb) -{ - struct GetCtx get_ctx; - - GNUNET_assert (NULL != n); - GNUNET_assert (NULL != experiments); - GNUNET_assert (NULL != get_cb); - get_ctx.n = n; - get_ctx.get_cb = get_cb; - get_ctx.issuer = issuer; - GNUNET_CONTAINER_multihashmap_iterate (experiments, - &get_it, &get_ctx); - get_cb (n, NULL); // FIXME: ugly, end is easily signalled as we return: synchronous API! -} - - -/** - * Add a new experiment - */ -int -GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i, - const char *name, - const struct GNUNET_CRYPTO_EddsaPublicKey *issuer_id, - struct GNUNET_TIME_Absolute version, - char *description, - uint32_t required_capabilities, - struct GNUNET_TIME_Absolute start, - struct GNUNET_TIME_Relative frequency, - struct GNUNET_TIME_Relative duration, - struct GNUNET_TIME_Absolute stop) -{ - struct Experiment *e; - struct GNUNET_HashCode hc; - - e = GNUNET_new (struct Experiment); - e->name = GNUNET_strdup (name); - e->issuer = *issuer_id; - e->version = version; - if (NULL != description) - e->description = GNUNET_strdup (description); - e->required_capabilities = required_capabilities; - e->start = start; - e->frequency = frequency; - e->duration = duration; - e->stop = stop; - - /* verify experiment */ - if (GNUNET_SYSERR == experiment_verify (i, e)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Experiment signature is invalid\n"), - name); - GNUNET_free (e); - GNUNET_free_non_null (e->name); - GNUNET_free_non_null (e->description); - return GNUNET_SYSERR; - } - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Adding experiment `%s' running from `%s' to `%s' every %llu sec. for %llu sec. \n"), - e->name, - GNUNET_STRINGS_absolute_time_to_string (start), - GNUNET_STRINGS_absolute_time_to_string (stop), - (long long unsigned int) frequency.rel_value_us / 1000000LL, - (long long unsigned int) duration.rel_value_us / 1000000LL); - get_experiment_key (&e->issuer, - name, - version, - &hc); - GNUNET_CONTAINER_multihashmap_put (experiments, - &hc, - e, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_STATISTICS_set (GED_stats, - "# experiments", - GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO); - - return GNUNET_OK; -} - - -/** - * Parse a configuration section containing experiments - * - * @param cls configuration handle - * @param name section name - */ -static void -exp_file_iterator (void *cls, - const char *name) -{ - struct GNUNET_CONFIGURATION_Handle *exp = cls; - struct Issuer *i; - char *val; - unsigned long long number; - /* Experiment values */ - struct GNUNET_CRYPTO_EddsaPublicKey issuer; - struct GNUNET_TIME_Absolute version; - char *description; - uint32_t required_capabilities; - struct GNUNET_TIME_Absolute start ; - struct GNUNET_TIME_Absolute stop; - struct GNUNET_TIME_Relative frequency; - struct GNUNET_TIME_Relative duration; - struct GNUNET_HashCode phash; - - /* Mandatory fields */ - - /* Issuer */ - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (exp, name, "ISSUER", &val)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Issuer missing\n"), name); - return; - } - if (GNUNET_SYSERR == - GNUNET_CRYPTO_eddsa_public_key_from_string (val, - strlen (val), - &issuer)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Issuer invalid\n"), name); - GNUNET_free (val); - return; - } - GNUNET_CRYPTO_hash (&issuer, sizeof (issuer), &phash); - if (NULL == (i = GNUNET_CONTAINER_multihashmap_get (valid_issuers, &phash))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Issuer not accepted!\n"), name); - GNUNET_free (val); - return; - } - GNUNET_free (val); - - /* Version */ - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, name, "VERSION", &number)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Version missing or invalid \n"), name); - return; - } - version.abs_value_us = number; // FIXME: what is this supposed to be? Version != TIME!??? - - /* Required capabilities */ - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, name, "CAPABILITIES", &number)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Required capabilities missing \n"), name); - return; - } - if (number > UINT32_MAX) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Experiment `%s': Required capabilities invalid \n"), name); - return; - } - required_capabilities = number; - - /* Optional fields */ - - /* Description */ - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (exp, name, "DESCRIPTION", &description)) - description = NULL; - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, name, "START", (long long unsigned int *) &start.abs_value_us)) - start = GNUNET_TIME_UNIT_ZERO_ABS; - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (exp, name, "FREQUENCY", &frequency)) - frequency = EXP_DEFAULT_EXP_FREQ; - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (exp, name, "DURATION", &duration)) - duration = EXP_DEFAULT_EXP_DUR; - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, name, "STOP", (long long unsigned int *)&stop.abs_value_us)) - stop = GNUNET_TIME_UNIT_FOREVER_ABS; - - GNUNET_EXPERIMENTATION_experiments_add (i, name, &issuer, version, - description, required_capabilities, - start, frequency, duration, stop); - GNUNET_free_non_null (description); -} - - -/** - * Load experiments from file - * - * @param file source file - */ -static void -load_file (const char * file) -{ - struct GNUNET_CONFIGURATION_Handle *exp = GNUNET_CONFIGURATION_create(); - - if (NULL == exp) - return; - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (exp, file)) - { - GNUNET_CONFIGURATION_destroy (exp); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to parse file `%s'\n"), - file); - return; - } - GNUNET_CONFIGURATION_iterate_sections (exp, &exp_file_iterator, exp); - GNUNET_CONFIGURATION_destroy (exp); -} - - -/** - * Start experiments management - */ -int -GED_experiments_start () -{ - struct Issuer *i; - char *issuers; - char *file; - char *pos; - struct GNUNET_CRYPTO_EddsaPublicKey issuer_ID; - struct GNUNET_HashCode hash; - - /* Load valid issuer */ - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (GED_cfg, - "EXPERIMENTATION", - "ISSUERS", - &issuers)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("No valid experiment issuers configured! Set value to public keys of issuers! Exiting.\n")); - GED_experiments_stop (); - return GNUNET_SYSERR; - } - - valid_issuers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); - for (pos = strtok (issuers, " "); pos != NULL; pos = strtok (NULL, " ")) - { - if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_public_key_from_string (pos, - strlen (pos), - &issuer_ID)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - "EXPERIMENTATION", - "ISSUERS", - _("Invalid value for public key\n")); - GED_experiments_stop (); - GNUNET_free (issuers); - return GNUNET_SYSERR; - } - i = GNUNET_new (struct Issuer); - i->pubkey = issuer_ID; - GNUNET_CRYPTO_hash( &issuer_ID, sizeof (issuer_ID), &hash); - GNUNET_CONTAINER_multihashmap_put (valid_issuers, - &hash, - i, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - } - GNUNET_free (issuers); - if (0 == GNUNET_CONTAINER_multihashmap_size (valid_issuers)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("No valid experiment issuers configured! Set value to public keys of issuers! Exiting.\n")); - GED_experiments_stop (); - return GNUNET_SYSERR; - } - GNUNET_STATISTICS_set (GED_stats, - "# issuer", - GNUNET_CONTAINER_multihashmap_size (valid_issuers), - GNUNET_NO); - - experiments = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); - /* Load experiments from file */ - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (GED_cfg, - "EXPERIMENTATION", - "EXPERIMENTS", - &file)) - return GNUNET_OK; - - if (GNUNET_YES != GNUNET_DISK_file_test (file)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Cannot read experiments file `%s'\n"), file); - GNUNET_free (file); - return GNUNET_OK; - } - load_file (file); - GNUNET_free (file); - return GNUNET_OK; -} - - -/** - * Stop experiments management - */ -void -GED_experiments_stop () -{ - if (NULL != valid_issuers) - { - GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &free_issuer, NULL); - GNUNET_CONTAINER_multihashmap_destroy (valid_issuers); - } - valid_issuers = NULL; - if (NULL != experiments) - { - GNUNET_CONTAINER_multihashmap_iterate (experiments, &free_experiment, NULL); - GNUNET_CONTAINER_multihashmap_destroy (experiments); - } - experiments = NULL; -} - -/* end of gnunet-daemon-experimentation_experiments.c */ diff --git a/src/experimentation/gnunet-daemon-experimentation_nodes.c b/src/experimentation/gnunet-daemon-experimentation_nodes.c deleted file mode 100644 index 1c4152793..000000000 --- a/src/experimentation/gnunet-daemon-experimentation_nodes.c +++ /dev/null @@ -1,1157 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2012-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 experimentation/gnunet-daemon-experimentation_nodes.c - * @brief experimentation daemon: node management - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet-daemon-experimentation.h" - - -#define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - -/** - * Core handle - */ -static struct GNUNET_CORE_Handle *ch; - -/** - * Peer's own identity - */ -static struct GNUNET_PeerIdentity me; - -/** - * Nodes with a pending request - */ -static struct GNUNET_CONTAINER_MultiPeerMap *nodes_requested; - -/** - * Active experimentation nodes - */ -static struct GNUNET_CONTAINER_MultiPeerMap *nodes_active; - -/** - * Inactive experimentation nodes - * To be excluded from future requests - */ -static struct GNUNET_CONTAINER_MultiPeerMap *nodes_inactive; - - -struct NodeComCtx -{ - struct NodeComCtx *prev; - struct NodeComCtx *next; - - struct Node *n; - struct Experiment *e; - - size_t size; - GNUNET_CONNECTION_TransmitReadyNotify notify; - void *notify_cls; -}; - - -/** - * Update statistics - * - * @param m peermap to update values from - */ -static void -update_stats (struct GNUNET_CONTAINER_MultiPeerMap *m) -{ - GNUNET_assert (NULL != m); - GNUNET_assert (NULL != GED_stats); - - if (m == nodes_active) - { - GNUNET_STATISTICS_set (GED_stats, "# nodes active", - GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO); - } - else if (m == nodes_inactive) - { - GNUNET_STATISTICS_set (GED_stats, "# nodes inactive", - GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO); - } - else if (m == nodes_requested) - { - GNUNET_STATISTICS_set (GED_stats, "# nodes requested", - GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO); - } - else - GNUNET_break (0); -} - - -/** - * Clean up node - * - * @param cls the peermap to clean up - * @param key key of the current node - * @param value related node object - * @return always #GNUNET_OK - */ -static int -cleanup_node (void *cls, - const struct GNUNET_PeerIdentity * key, - void *value) -{ - struct Node *n; - struct NodeComCtx *e_cur; - struct NodeComCtx *e_next; - struct GNUNET_CONTAINER_MultiPeerMap *cur = cls; - - n = value; - if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) - { - GNUNET_SCHEDULER_cancel (n->timeout_task); - n->timeout_task = GNUNET_SCHEDULER_NO_TASK; - } - - if (NULL != n->cth) - { - GNUNET_CORE_notify_transmit_ready_cancel (n->cth); - n->cth = NULL; - } - e_next = n->e_req_head; - while (NULL != (e_cur = e_next)) - { - e_next = e_cur->next; - GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail, e_cur); - GNUNET_free (e_cur); - } - GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (cur, key, value)); - GNUNET_free (value); - return GNUNET_OK; -} - - -/** - * Check if id passed is my id - * - * @param id the id to check - * @return GNUNET_YES or GNUNET_NO - */ -static int -is_me (const struct GNUNET_PeerIdentity *id) -{ - if (0 == memcmp (&me, id, sizeof (me))) - return GNUNET_YES; - else - return GNUNET_NO; -} - - -/** - * Core startup callback - * - * @param cls unused - * @param my_identity my id - */ -static void -core_startup_handler (void *cls, - const struct GNUNET_PeerIdentity *my_identity) -{ - me = *my_identity; -} - - -static void -schedule_transmisson (struct NodeComCtx *e_ctx); - - -static size_t -transmit_read_wrapper (void *cls, size_t bufsize, void *buf) -{ - struct NodeComCtx *e_ctx = cls; - struct NodeComCtx *next; - - size_t res = e_ctx->notify (e_ctx->notify_cls, bufsize, buf); - e_ctx->n->cth = NULL; - - GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head, e_ctx->n->e_req_tail, e_ctx); - next = e_ctx->n->e_req_head; - GNUNET_free (e_ctx); - - if (NULL != next) - { - /* Schedule next message */ - schedule_transmisson (next); - } - return res; -} - - -static void -schedule_transmisson (struct NodeComCtx *e_ctx) -{ - if (NULL != e_ctx->n->cth) - return; - - e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, - GNUNET_CORE_PRIO_BEST_EFFORT, - FAST_TIMEOUT, - &e_ctx->n->id, e_ctx->size, - transmit_read_wrapper, e_ctx); - if (NULL == e_ctx->n->cth) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Cannot send message to peer `%s' for experiment `%s'\n"), - GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name); - GNUNET_free (e_ctx); - } -} - - -/** - * Remove experimentation request due to timeout - * - * @param cls the related node - * @param tc scheduler's task context - */ -static void -remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct Node *n = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing request for peer %s due to timeout\n", - GNUNET_i2s (&n->id)); - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested, &n->id)) - { - GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, &n->id, n)); - update_stats (nodes_requested); - GNUNET_CONTAINER_multipeermap_put (nodes_inactive, &n->id, n, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - update_stats (nodes_inactive); - } - n->timeout_task = GNUNET_SCHEDULER_NO_TASK; -} - - -static int -append_public_key (void *cls, - const struct GNUNET_HashCode *key, - void *value) -{ - struct GNUNET_CRYPTO_EddsaPublicKey **issuers = cls; - struct Issuer *issuer = value; - - *issuers[0] = issuer->pubkey; - *issuers = &((*issuers)[1]); - return GNUNET_OK; -} - - -/** - * Core's transmit notify callback to send request - * - * @param cls the related node - * @param bufsize buffer size - * @param buf the buffer to copy to - * @return bytes passed - */ -static size_t -send_experimentation_request_cb (void *cls, size_t bufsize, void *buf) -{ - struct Node *n = cls; - struct Experimentation_Request msg; - unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers); - size_t msg_size = sizeof (msg); - size_t ri_size = sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) * my_issuer_count; - size_t total_size = msg_size + ri_size; - struct GNUNET_CRYPTO_EddsaPublicKey *issuers; - - n->cth = NULL; - if (NULL == buf) - { - /* client disconnected */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client disconnected\n"); - if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) - GNUNET_SCHEDULER_cancel (n->timeout_task); - GNUNET_SCHEDULER_add_now (&remove_request, n); - return 0; - } - GNUNET_assert (bufsize >= total_size); - msg.msg.size = htons (total_size); - msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST); - msg.capabilities = htonl (GSE_node_capabilities); - msg.issuer_count = htonl (my_issuer_count); - memcpy (buf, &msg, msg_size); - issuers = (struct GNUNET_CRYPTO_EddsaPublicKey *) buf + msg_size; - GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, - &append_public_key, - &issuers); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Sending experimentation request to peer %s\n"), - GNUNET_i2s (&n->id)); - return total_size; -} - - -/** - * Send request to peer to start add him to to the set of experimentation nodes - * - * @param peer the peer to send to - */ -static void -send_experimentation_request (const struct GNUNET_PeerIdentity *peer) -{ - struct Node *n; - struct NodeComCtx *e_ctx; - size_t size; - size_t c_issuers; - - c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers); - size = sizeof (struct Experimentation_Request) + - c_issuers * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey); - n = GNUNET_new (struct Node); - n->id = *peer; - n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n); - n->capabilities = NONE; - - e_ctx = GNUNET_new (struct NodeComCtx); - e_ctx->n = n; - e_ctx->e = NULL; - e_ctx->size = size; - e_ctx->notify = &send_experimentation_request_cb; - e_ctx->notify_cls = n; - GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx); - schedule_transmisson (e_ctx); - - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (nodes_requested, - peer, n, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - update_stats (nodes_requested); -} - - -/** - * Core's transmit notify callback to send response - * - * @param cls the related node - * @param bufsize buffer size - * @param buf the buffer to copy to - * @return bytes passed - */ -static size_t -send_response_cb (void *cls, size_t bufsize, void *buf) -{ - struct Node *n = cls; - struct Experimentation_Response msg; - size_t c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers); - size_t ri_size = c_issuers * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey); - size_t msg_size = sizeof (msg); - size_t total_size = msg_size + ri_size; - struct GNUNET_CRYPTO_EddsaPublicKey *issuers; - - n->cth = NULL; - if (buf == NULL) - { - /* client disconnected */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client disconnected\n"); - return 0; - } - GNUNET_assert (bufsize >= total_size); - - msg.msg.size = htons (total_size); - msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE); - msg.capabilities = htonl (GSE_node_capabilities); - msg.issuer_count = htonl (c_issuers); - memcpy (buf, &msg, msg_size); - issuers = (struct GNUNET_CRYPTO_EddsaPublicKey *) buf + msg_size; - GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, - &append_public_key, - &issuers); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending response to peer %s\n", - GNUNET_i2s (&n->id)); - return total_size; -} - - -static void -get_experiments_cb (struct Node *n, struct Experiment *e) -{ - static int counter = 0; - if (NULL == e) - return; /* Done */ - - /* Tell the scheduler to add a node with an experiment */ - GED_scheduler_add (n, e, GNUNET_YES); - counter ++; -} - - -struct Node * -get_node (const struct GNUNET_PeerIdentity *id) -{ - struct Node * res; - struct Node * tmp; - - res = NULL; - tmp = NULL; - tmp = GNUNET_CONTAINER_multipeermap_get (nodes_active, id); - if (res == NULL) - res = tmp; - - tmp = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, id); - if (res == NULL) - res = tmp; - else - GNUNET_break (0); /* Multiple instances */ - - tmp = GNUNET_CONTAINER_multipeermap_get (nodes_requested, id); - if (res == NULL) - res = tmp; - else - GNUNET_break (0); /* Multiple instances */ - - return res; -} - - -/** - * Set a specific node as active - * - * @param n the node - */ -static void -node_make_active (struct Node *n) -{ - int c1; - - GNUNET_CONTAINER_multipeermap_put (nodes_active, - &n->id, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - update_stats (nodes_active); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Added peer `%s' as active node\n"), - GNUNET_i2s (&n->id)); - /* Request experiments for this node to start them */ - for (c1 = 0; c1 < n->issuer_count; c1++) - { - GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb); - } -} - - -/** - * Handle a request and send a response - * - * @param peer the source - * @param message the message - */ -static void -handle_request (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message) -{ - struct Node *n; - struct NodeComCtx *e_ctx; - const struct Experimentation_Request *rm = (const struct Experimentation_Request *) message; - const struct GNUNET_CRYPTO_EddsaPublicKey *rmi = (const struct GNUNET_CRYPTO_EddsaPublicKey *) &rm[1]; - unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers); - int c1; - int c2; - uint32_t ic; - uint32_t ic_accepted; - int make_active; - - if (ntohs (message->size) < sizeof (struct Experimentation_Request)) - { - GNUNET_break (0); - return; - } - ic = ntohl (rm->issuer_count); - if (ntohs (message->size) != - sizeof (struct Experimentation_Request) + ic * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) - { - GNUNET_break (0); - return; - } - - make_active = GNUNET_NO; - if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer))) - { - /* Nothing to do */ - } - else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer))) - { - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n)); - if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) - { - GNUNET_SCHEDULER_cancel (n->timeout_task); - n->timeout_task = GNUNET_SCHEDULER_NO_TASK; - } - update_stats (nodes_requested); - make_active = GNUNET_YES; - } - else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer))) - { - GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive, peer, n)); - update_stats (nodes_inactive); - make_active = GNUNET_YES; - } - else - { - /* Create new node */ - n = GNUNET_new (struct Node); - n->id = *peer; - n->capabilities = NONE; - make_active = GNUNET_YES; - } - - /* Update node */ - n->capabilities = ntohl (rm->capabilities); - - /* Filter accepted issuer */ - ic_accepted = 0; - for (c1 = 0; c1 < ic; c1++) - { - if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1])) - ic_accepted ++; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Request from peer `%s' with %u issuers, we accepted %u issuer \n", - GNUNET_i2s (peer), ic, ic_accepted); - GNUNET_free_non_null (n->issuer_id); - n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); - c2 = 0; - for (c1 = 0; c1 < ic; c1++) - { - if (GNUNET_YES == GED_experiments_issuer_accepted (&rmi[c1])) - { - n->issuer_id[c2] = rmi[c1]; - c2 ++; - } - } - n->issuer_count = ic_accepted; - - if (GNUNET_YES == make_active) - node_make_active (n); - - /* Send response */ - e_ctx = GNUNET_new (struct NodeComCtx); - e_ctx->n = n; - e_ctx->e = NULL; - e_ctx->size = sizeof (struct Experimentation_Response) + - my_issuer_count * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey); - e_ctx->notify = &send_response_cb; - e_ctx->notify_cls = n; - - GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx); - schedule_transmisson (e_ctx); -} - - -/** - * Handle a response - * - * @param peer the source - * @param message the message - */ -static void handle_response (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message) -{ - struct Node *n; - const struct Experimentation_Response *rm = (const struct Experimentation_Response *) message; - const struct GNUNET_CRYPTO_EddsaPublicKey *rmi = (const struct GNUNET_CRYPTO_EddsaPublicKey *) &rm[1]; - uint32_t ic; - uint32_t ic_accepted; - int make_active; - unsigned int c1; - unsigned int c2; - - if (ntohs (message->size) < sizeof (struct Experimentation_Response)) - { - GNUNET_break (0); - return; - } - ic = ntohl (rm->issuer_count); - if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) - { - GNUNET_break (0); - return; - } - - make_active = GNUNET_NO; - if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received %s from %s peer `%s'\n", - "RESPONSE", "active", GNUNET_i2s (peer)); - } - else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n", - "RESPONSE", "requested", GNUNET_i2s (peer)); - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n)); - if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) - { - GNUNET_SCHEDULER_cancel (n->timeout_task); - n->timeout_task = GNUNET_SCHEDULER_NO_TASK; - } - update_stats (nodes_requested); - make_active = GNUNET_YES; - } - else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received %s from peer `%s'\n", - "RESPONSE", "inactive", GNUNET_i2s (peer)); - GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive, peer, n)); - update_stats (nodes_inactive); - make_active = GNUNET_YES; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n", - "RESPONSE", "unknown", GNUNET_i2s (peer)); - return; - } - - /* Update */ - n->capabilities = ntohl (rm->capabilities); - - /* Filter accepted issuer */ - ic_accepted = 0; - for (c1 = 0; c1 < ic; c1++) - { - if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1])) - ic_accepted ++; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Response from peer `%s' with %u issuers, we accepted %u issuer \n", - GNUNET_i2s (peer), ic, ic_accepted); - GNUNET_free_non_null (n->issuer_id); - n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity)); - c2 = 0; - for (c1 = 0; c1 < ic; c1++) - { - if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1])) - { - n->issuer_id[c2] = rmi[c1]; - c2 ++; - } - } - n->issuer_count = ic_accepted; - - if (GNUNET_YES == make_active) - node_make_active (n); -} - - -/** - * Handle a response - * - * @param peer the source - * @param message the message - */ -static void -handle_start (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message) -{ - uint16_t size; - uint32_t name_len; - const struct GED_start_message *msg; - const char *name; - struct Node *n; - struct Experiment *e; - - if (NULL == peer) - { - GNUNET_break (0); - return; - } - if (NULL == message) - { - GNUNET_break (0); - return; - } - - size = ntohs (message->size); - if (size < sizeof (struct GED_start_message)) - { - GNUNET_break (0); - return; - } - msg = (const struct GED_start_message *) message; - name_len = ntohl (msg->len_name); - if (size != sizeof (struct GED_start_message) + name_len) - { - GNUNET_break (0); - return; - } - - n = get_node (peer); - if (NULL == n) - { - GNUNET_break (0); - return; - } - name = (const char *) &msg[1]; - if (name[name_len-1] != '\0') - { - GNUNET_break (0); - return; - } - if (name_len != strlen (name) + 1) - { - GNUNET_break (0); - return; - } - e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo)); - if (NULL == e) - { - GNUNET_break (0); - return; - } - GED_scheduler_handle_start (n, e); -} - - -/** - * Handle a response - * - * @param peer the source - * @param message the message - */ -static void -handle_start_ack (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message) -{ - uint16_t size; - uint32_t name_len; - const struct GED_start_ack_message *msg; - const char *name; - struct Node *n; - struct Experiment *e; - - if (NULL == peer) - { - GNUNET_break (0); - return; - } - if (NULL == message) - { - GNUNET_break (0); - return; - } - - size = ntohs (message->size); - if (size < sizeof (struct GED_start_ack_message)) - { - GNUNET_break (0); - return; - } - msg = (const struct GED_start_ack_message *) message; - name_len = ntohl (msg->len_name); - if (size != sizeof (struct GED_start_message) + name_len) - { - GNUNET_break (0); - return; - } - - n = get_node (peer); - if (NULL == n) - { - GNUNET_break (0); - return; - } - name = (const char *) &msg[1]; - if (name[name_len-1] != '\0') - { - GNUNET_break (0); - return; - } - if (name_len != strlen (name) + 1) - { - GNUNET_break (0); - return; - } - - e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo)); - if (NULL == e) - { - GNUNET_break (0); - return; - } - GED_scheduler_handle_start_ack (n, e); -} - - -/** - * Handle a response - * - * @param peer the source - * @param message the message - */ -static void -handle_stop (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message) -{ - uint16_t size; - uint32_t name_len; - const struct GED_stop_message *msg; - const char *name; - struct Node *n; - struct Experiment *e; - - if (NULL == peer) - { - GNUNET_break (0); - return; - } - if (NULL == message) - { - GNUNET_break (0); - return; - } - - size = ntohs (message->size); - if (size < sizeof (struct GED_stop_message)) - { - GNUNET_break (0); - return; - } - msg = (const struct GED_stop_message *) message; - name_len = ntohl (msg->len_name); - if (size != sizeof (struct GED_start_message) + name_len) - { - GNUNET_break (0); - return; - } - - n = get_node (peer); - if (NULL == n) - { - GNUNET_break (0); - return; - } - name = (const char *) &msg[1]; - if (name[name_len-1] != '\0') - { - GNUNET_break (0); - return; - } - - if (name_len != strlen (name) + 1) - { - GNUNET_break (0); - return; - } - - e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo)); - if (NULL == e) - { - GNUNET_break (0); - return; - } - GED_scheduler_handle_stop (n, e); -} - - -/** - * Method called whenever a given peer connects. - * - * @param cls closure - * @param peer peer identity this notification is about - */ -static void -core_connect_handler (void *cls, - const struct GNUNET_PeerIdentity *peer) -{ - if (GNUNET_YES == is_me(peer)) - return; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"), - GNUNET_i2s (peer)); - - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested, peer)) - return; /* We already sent a request */ - - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_active, peer)) - return; /* This peer is known as active */ - - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_inactive, peer)) - return; /* This peer is known as inactive */ - - send_experimentation_request (peer); -} - - -/** - * Method called whenever a given peer disconnects. - * - * @param cls closure - * @param peer peer identity this notification is about - */ -static void -core_disconnect_handler (void *cls, - const struct GNUNET_PeerIdentity * peer) -{ - struct Node *n; - if (GNUNET_YES == is_me(peer)) - return; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"), - GNUNET_i2s (peer)); - - if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer))) - cleanup_node (nodes_requested, peer, n); - - if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer))) - cleanup_node (nodes_active, peer, n); - - if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer))) - cleanup_node (nodes_inactive, peer, n); -} - - -/** - * Handle a request and send a response - * - * @param cls unused - * @param other the sender - * @param message the message - * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error - */ -static int -core_receive_handler (void *cls, - const struct GNUNET_PeerIdentity *other, - const struct GNUNET_MessageHeader *message) -{ - if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - - switch (ntohs (message->type)) { - case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST: - handle_request (other, message); - break; - case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE: - handle_response (other, message); - break; - case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START: - handle_start (other, message); - break; - case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK: - handle_start_ack (other, message); - break; - case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP: - handle_stop (other, message); - break; - default: - break; - } - - return GNUNET_OK; -} - - -static size_t -node_experiment_start_cb (void *cls, size_t bufsize, void *buf) -{ - struct NodeComCtx *e_ctx = cls; - struct GED_start_message *msg; - size_t name_len; - size_t size; - - if (NULL == buf) - return 0; - - name_len = strlen(e_ctx->e->name) + 1; - size = sizeof (struct GED_start_message) + name_len; - - msg = GNUNET_malloc (size); - msg->header.size = htons (size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START); - msg->issuer = e_ctx->e->issuer; - msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version); - msg->len_name = htonl (name_len); - memcpy (&msg[1], e_ctx->e->name, name_len); - - memcpy (buf, msg, size); - GNUNET_free (msg); - return size; -} - - -static size_t -node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf) -{ - struct NodeComCtx *e_ctx = cls; - struct GED_start_ack_message *msg; - size_t name_len; - size_t size; - if (NULL == buf) - return 0; - - name_len = strlen(e_ctx->e->name) + 1; - size = sizeof (struct GED_start_ack_message) + name_len; - - msg = GNUNET_malloc (size); - msg->header.size = htons (size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK); - msg->issuer = e_ctx->e->issuer; - msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version); - msg->len_name = htonl (name_len); - memcpy (&msg[1], e_ctx->e->name, name_len); - - memcpy (buf, msg, size); - GNUNET_free (msg); - return size; -} - - - - -/** - * Confirm a experiment START with a node - * - * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise - */ -int -GED_nodes_send_start_ack (struct Node *n, struct Experiment *e) -{ - struct NodeComCtx *e_ctx; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending %s for experiment request to peer `%s' for experiment `%s'\n", - "START_ACK" ,GNUNET_i2s(&n->id), e->name); - - e_ctx = GNUNET_new (struct NodeComCtx); - e_ctx->n = n; - e_ctx->e = e; - e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1; - e_ctx->notify = &node_experiment_start_ack_cb; - e_ctx->notify_cls = e_ctx; - - GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx); - schedule_transmisson (e_ctx); - return GNUNET_OK; -} - - -/** - * Request a experiment to start with a node - * - * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise - */ -int -GED_nodes_send_start (struct Node *n, struct Experiment *e) -{ - struct NodeComCtx *e_ctx; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending %s for experiment request to peer `%s' for experiment `%s'\n", - "START", GNUNET_i2s(&n->id), e->name); - - e_ctx = GNUNET_new (struct NodeComCtx); - e_ctx->n = n; - e_ctx->e = e; - e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1; - e_ctx->notify = &node_experiment_start_cb; - e_ctx->notify_cls = e_ctx; - - GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx); - schedule_transmisson (e_ctx); - return GNUNET_OK; -} - - -/** - * Start the nodes management - */ -void -GED_nodes_start () -{ - /* Connecting to core service to find partners */ - ch = GNUNET_CORE_connect (GED_cfg, NULL, - &core_startup_handler, - &core_connect_handler, - &core_disconnect_handler, - &core_receive_handler, - GNUNET_NO, NULL, GNUNET_NO, NULL); - if (NULL == ch) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n")); - return; - } - - nodes_requested = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); - nodes_active = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); - nodes_inactive = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); -} - - -/** - * Stop the nodes management - */ -void -GED_nodes_stop () -{ - if (NULL != ch) - { - GNUNET_CORE_disconnect (ch); - ch = NULL; - } - - if (NULL != nodes_requested) - { - GNUNET_CONTAINER_multipeermap_iterate (nodes_requested, - &cleanup_node, - nodes_requested); - update_stats (nodes_requested); - GNUNET_CONTAINER_multipeermap_destroy (nodes_requested); - nodes_requested = NULL; - } - - if (NULL != nodes_active) - { - GNUNET_CONTAINER_multipeermap_iterate (nodes_active, - &cleanup_node, - nodes_active); - update_stats (nodes_active); - GNUNET_CONTAINER_multipeermap_destroy (nodes_active); - nodes_active = NULL; - } - - if (NULL != nodes_inactive) - { - GNUNET_CONTAINER_multipeermap_iterate (nodes_inactive, - &cleanup_node, - nodes_inactive); - update_stats (nodes_inactive); - GNUNET_CONTAINER_multipeermap_destroy (nodes_inactive); - nodes_inactive = NULL; - } -} - -/* end of gnunet-daemon-experimentation_nodes.c */ diff --git a/src/experimentation/gnunet-daemon-experimentation_scheduler.c b/src/experimentation/gnunet-daemon-experimentation_scheduler.c deleted file mode 100644 index c13434e9b..000000000 --- a/src/experimentation/gnunet-daemon-experimentation_scheduler.c +++ /dev/null @@ -1,448 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009 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 experimentation/gnunet-daemon-experimentation_scheduler.c - * @brief experimentation daemon: execute experiments - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet-daemon-experimentation.h" - -/** - * An experiment is added during startup as not running NOT_RUNNING - * - * The scheduler then decides to schedule it and sends a request to the - * remote peer, if core cannot send since it is busy we wait for some time - * and change state to BUSY, if we can send we change to REQUESTED and wait - * for remote peers ACK. - * - * When we receive an ACK we change to STARTED and when scheduler decides that - * the experiment is finished we change to STOPPED. - */ - -enum ExperimentState -{ - /* Experiment is added and waiting to be executed */ - NOT_RUNNING, - /* Cannot send request to remote peer, core is busy*/ - BUSY, - /* We requested experiment and wait for remote peer to ACK */ - REQUESTED, - /* Experiment is running */ - STARTED, - /* Experiment is done */ - STOPPED -}; - -struct ScheduledExperiment { - struct ScheduledExperiment *next; - struct ScheduledExperiment *prev; - - struct Experiment *e; - struct Node *n; - int state; - int outbound; - GNUNET_SCHEDULER_TaskIdentifier task; -}; - -struct ScheduledExperiment *waiting_in_head; -struct ScheduledExperiment *waiting_in_tail; - -struct ScheduledExperiment *running_in_head; -struct ScheduledExperiment *running_in_tail; - -struct ScheduledExperiment *waiting_out_head; -struct ScheduledExperiment *waiting_out_tail; - -struct ScheduledExperiment *running_out_head; -struct ScheduledExperiment *running_out_tail; - - -static unsigned int experiments_scheduled; -static unsigned int experiments_outbound_running; -static unsigned int experiments_inbound_running; -static unsigned int experiments_requested; - - -static struct ScheduledExperiment * -find_experiment (struct ScheduledExperiment *head, struct ScheduledExperiment *tail, - struct Node *n, struct Experiment *e, int outbound) -{ - struct ScheduledExperiment *cur; - for (cur = head; NULL != cur; cur = cur->next) - { - if ((cur->n == n) && (cur->e == e) && (cur->outbound == outbound)) /* Node and experiment are equal */ - break; - } - return cur; -} - -static void -request_timeout (void *cls,const struct GNUNET_SCHEDULER_TaskContext* tc) -{ - struct ScheduledExperiment *se = cls; - se->task = GNUNET_SCHEDULER_NO_TASK; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Peer `%s' did not respond to request for experiment `%s'\n"), - GNUNET_i2s (&se->n->id), se->e->name); - - GNUNET_CONTAINER_DLL_remove (waiting_out_head, waiting_out_tail, se); - GNUNET_free (se); - - /* Remove experiment */ - GNUNET_assert (experiments_requested > 0); - experiments_requested --; - GNUNET_STATISTICS_set (GED_stats, "# experiments requested", experiments_requested, GNUNET_NO); -} - -static void run_experiment_inbound (void *cls,const struct GNUNET_SCHEDULER_TaskContext* tc) -{ - struct ScheduledExperiment *se = cls; - struct GNUNET_TIME_Relative start; - struct GNUNET_TIME_Relative end; - - se->task = GNUNET_SCHEDULER_NO_TASK; - - switch (se->state) { - case NOT_RUNNING: - /* Send START_ACK message */ - GED_nodes_send_start_ack (se->n, se->e); - se->state = REQUESTED; - /* Schedule to run */ - start = GNUNET_TIME_absolute_get_remaining(se->e->start); - if (0 == start.rel_value_us) - se->task = GNUNET_SCHEDULER_add_now (&run_experiment_inbound, se); - else - se->task = GNUNET_SCHEDULER_add_delayed (start, &run_experiment_inbound, se); - break; - case REQUESTED: - experiments_inbound_running ++; - GNUNET_STATISTICS_set (GED_stats, "# experiments inbound running", experiments_inbound_running, GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting inbound experiment `%s' with peer `%s'\n"), - se->e->name, GNUNET_i2s (&se->n->id)); - se->state = STARTED; - se->task = GNUNET_SCHEDULER_add_now (&run_experiment_inbound, se); - break; - case STARTED: - /* Experiment is running */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running %s experiment `%s' peer for `%s'\n", - "inbound", GNUNET_i2s (&se->n->id), se->e->name); - - /* do work here */ - - /* Reschedule */ - end = GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add (se->e->stop, se->e->frequency)); - if (0 == end.rel_value_us) - { - se->state = STOPPED; - return; /* End of experiment is reached */ - } - /* Reschedule */ - se->task = GNUNET_SCHEDULER_add_delayed (se->e->frequency, &run_experiment_inbound, se); - break; - case STOPPED: - /* Experiment expired */ - break; - default: - break; - } - -} - -static void run_experiment_outbound (void *cls,const struct GNUNET_SCHEDULER_TaskContext* tc) -{ - struct ScheduledExperiment *se = cls; - struct GNUNET_TIME_Relative end; - - se->task = GNUNET_SCHEDULER_NO_TASK; - - switch (se->state) { - case NOT_RUNNING: - /* Send START message */ - GED_nodes_send_start (se->n, se->e); - se->state = REQUESTED; - se->task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &request_timeout, se); - experiments_requested ++; - GNUNET_STATISTICS_set (GED_stats, "# experiments requested", experiments_requested, GNUNET_NO); - break; - case REQUESTED: - /* Expecting START_ACK */ - GNUNET_break (0); - break; - case STARTED: - /* Experiment is running */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running %s experiment `%s' peer for `%s'\n", - "outbound", GNUNET_i2s (&se->n->id), se->e->name); - - /* do work here */ - - /* Reschedule */ - end = GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add (se->e->stop, se->e->frequency)); - if (0 == end.rel_value_us) - { - se->state = STOPPED; - return; /* End of experiment is reached */ - } - /* Reschedule */ - se->task = GNUNET_SCHEDULER_add_delayed (se->e->frequency, &run_experiment_outbound, se); - break; - case STOPPED: - /* Experiment expired */ - break; - default: - break; - } -} - - -/** - * Handle a START message from a remote node - * - * @param n the node - * @param e the experiment - */ -void -GED_scheduler_handle_start (struct Node *n, struct Experiment *e) -{ - if ((NULL != find_experiment (waiting_in_head, waiting_in_tail, n, e, GNUNET_NO)) || - (NULL != find_experiment (running_in_head, running_in_tail, n, e, GNUNET_NO))) - { - GNUNET_break_op (0); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received %s message from peer %s for experiment `%s'\n", - "START", GNUNET_i2s (&n->id), e->name); - GED_scheduler_add (n, e, GNUNET_NO); -} - - -/** - * Handle a START_ACK message from a remote node - * - * @param n the node - * @param e the experiment - */ -void -GED_scheduler_handle_start_ack (struct Node *n, struct Experiment *e) -{ - struct ScheduledExperiment *se; - - if (NULL == (se = find_experiment (waiting_out_head, waiting_out_tail, n, e, GNUNET_YES))) - { - GNUNET_break (0); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s message from peer %s for requested experiment `%s'\n", - "START_ACK", GNUNET_i2s (&n->id), e->name); - - if (GNUNET_SCHEDULER_NO_TASK != se->task) - { - GNUNET_SCHEDULER_cancel (se->task); /* *Canceling timeout task */ - se->task = GNUNET_SCHEDULER_NO_TASK; - } - - /* Remove from waiting list, add to running list */ - GNUNET_CONTAINER_DLL_remove (waiting_out_head, waiting_out_tail, se); - GNUNET_CONTAINER_DLL_insert (running_out_head, running_out_tail, se); - - /* Change state and schedule to run */ - experiments_outbound_running ++; - GNUNET_STATISTICS_set (GED_stats, "# experiments outbound running", experiments_outbound_running, GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting outbound experiment `%s' with peer `%s'\n"), - e->name, GNUNET_i2s (&n->id)); - se->state = STARTED; - se->task = GNUNET_SCHEDULER_add_now (&run_experiment_outbound, se); -} - - -/** - * Handle a STOP message from a remote node - * - * @param n the node - * @param e the experiment - */ -void -GED_scheduler_handle_stop (struct Node *n, struct Experiment *e) -{ - struct ScheduledExperiment *se; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Received %s message from peer %s for experiment `%s'\n"), - "STOP", GNUNET_i2s (&n->id), e->name); - - if (NULL != (se = find_experiment (waiting_in_head, waiting_in_tail, n, e, GNUNET_NO))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s message from peer %s for waiting experiment `%s'\n", - "STOP", GNUNET_i2s (&n->id), e->name); - } - - if (NULL != (se = find_experiment (running_in_head, running_in_tail, n, e, GNUNET_NO))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s message from peer %s for running experiment `%s'\n", - "STOP", GNUNET_i2s (&n->id), e->name); - } - -} - -/** - * Add a new experiment for a node - * - * @param n the node - * @param e the experiment - * @param outbound are we initiator (GNUNET_YES) or client (GNUNET_NO)? - */ -void -GED_scheduler_add (struct Node *n, struct Experiment *e, int outbound) -{ - struct ScheduledExperiment *se; - struct GNUNET_TIME_Relative start; - struct GNUNET_TIME_Relative end; - - GNUNET_assert ((GNUNET_YES == outbound) || (GNUNET_NO == outbound)); - - start = GNUNET_TIME_absolute_get_remaining(e->start); - end = GNUNET_TIME_absolute_get_remaining(e->stop); - if (0 == end.rel_value_us) - return; /* End of experiment is reached */ - - /* Add additional checks here if required */ - se = GNUNET_new (struct ScheduledExperiment); - se->state = NOT_RUNNING; - se->outbound = outbound; - se->e = e; - se->n = n; - - if (GNUNET_YES == outbound) - { - if (0 == start.rel_value_us) - se->task = GNUNET_SCHEDULER_add_now (&run_experiment_outbound, se); - else - se->task = GNUNET_SCHEDULER_add_delayed (start, &run_experiment_outbound, se); - GNUNET_CONTAINER_DLL_insert (waiting_out_head, waiting_out_tail, se); - } - else - { - if (0 == start.rel_value_us) - se->task = GNUNET_SCHEDULER_add_now (&run_experiment_inbound, se); - else - se->task = GNUNET_SCHEDULER_add_delayed (start, &run_experiment_inbound, se); - GNUNET_CONTAINER_DLL_insert (waiting_in_head, waiting_in_tail, se); - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added %s experiment `%s' for node to be scheduled\n", - (GNUNET_YES == outbound) ? "outbound" : "inbound", e->name, GNUNET_i2s(&se->n->id)); - experiments_scheduled ++; - GNUNET_STATISTICS_set (GED_stats, "# experiments scheduled", experiments_scheduled, GNUNET_NO); - -} - -/** - * Start the scheduler component - */ -void -GED_scheduler_start () -{ - experiments_requested = 0; - experiments_scheduled = 0; -} - - -/** - * Stop the scheduler component - */ -void -GED_scheduler_stop () -{ - struct ScheduledExperiment *cur; - struct ScheduledExperiment *next; - - next = waiting_in_head; - while (NULL != (cur = next)) - { - next = cur->next; - GNUNET_CONTAINER_DLL_remove (waiting_in_head, waiting_in_tail, cur); - if (GNUNET_SCHEDULER_NO_TASK != cur->task) - { - GNUNET_SCHEDULER_cancel (cur->task); - cur->task = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_free (cur); - GNUNET_assert (experiments_scheduled > 0); - experiments_scheduled --; - GNUNET_STATISTICS_set (GED_stats, "# experiments scheduled", experiments_scheduled, GNUNET_NO); - } - - next = running_in_head; - while (NULL != (cur = next)) - { - next = cur->next; - GNUNET_CONTAINER_DLL_remove (running_in_head, running_in_tail, cur); - if (GNUNET_SCHEDULER_NO_TASK != cur->task) - { - GNUNET_SCHEDULER_cancel (cur->task); - cur->task = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_free (cur); - GNUNET_assert (experiments_outbound_running > 0); - experiments_inbound_running --; - GNUNET_STATISTICS_set (GED_stats, "# experiments inbound running", experiments_inbound_running, GNUNET_NO); - } - - next = waiting_out_head; - while (NULL != (cur = next)) - { - next = cur->next; - GNUNET_CONTAINER_DLL_remove (waiting_out_head, waiting_out_tail, cur); - if (GNUNET_SCHEDULER_NO_TASK != cur->task) - { - GNUNET_SCHEDULER_cancel (cur->task); - cur->task = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_free (cur); - GNUNET_assert (experiments_scheduled > 0); - experiments_scheduled --; - GNUNET_STATISTICS_set (GED_stats, "# experiments scheduled", experiments_scheduled, GNUNET_NO); - } - - next = running_out_head; - while (NULL != (cur = next)) - { - next = cur->next; - GNUNET_CONTAINER_DLL_remove (running_out_head, running_out_tail, cur); - if (GNUNET_SCHEDULER_NO_TASK != cur->task) - { - GNUNET_SCHEDULER_cancel (cur->task); - cur->task = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_free (cur); - GNUNET_assert (experiments_outbound_running > 0); - experiments_outbound_running --; - GNUNET_STATISTICS_set (GED_stats, "# experiments outbound running", experiments_outbound_running, GNUNET_NO); - } -} - -/* end of gnunet-daemon-experimentation_scheduler.c */ diff --git a/src/experimentation/gnunet-daemon-experimentation_storage.c b/src/experimentation/gnunet-daemon-experimentation_storage.c deleted file mode 100644 index 8c6214c7b..000000000 --- a/src/experimentation/gnunet-daemon-experimentation_storage.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009 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 experimentation/gnunet-daemon-experimentation_storage.c - * @brief experimentation daemon: store results - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_core_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet-daemon-experimentation.h" - - -/** - * Start the storage component - */ -void -GED_storage_start () -{ - -} - - -/** - * Stop the storage component - */ -void -GED_storage_stop () -{ - -} - -/* end of gnunet-daemon-experimentation_storage.c */ diff --git a/src/experimentation/test_experimentation_clique.conf b/src/experimentation/test_experimentation_clique.conf deleted file mode 100644 index 1ab9aa2dd..000000000 --- a/src/experimentation/test_experimentation_clique.conf +++ /dev/null @@ -1,43 +0,0 @@ -[testbed] -AUTOSTART = NO -PORT = 12113 -ACCEPT_FROM = 127.0.0.1; -HOSTNAME = localhost -NEIGHBOUR_LIMIT = 100 -TOPOLOGY = RANDOM -#PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args - -[dhtcache] -QUOTA = 1 MB -DATABASE = heap - -[transport] -PLUGINS = udp -ACCEPT_FROM6 = ::1; -ACCEPT_FROM = 127.0.0.1; -NEIGHBOUR_LIMIT = 50 -PORT = 12365 - -[experimentation] -#PREFIX = valgrind --leak-check=full -ISSUERS = TFRM29O2RQNKLVBQIGODJ6GD58LSQ2NM9TNFBC6N48BRJHQO38Q73N2OM3V4CLKDM6CILQV4CU8PMJDRG0FNB0PDI057DBRANMLPLRG -EXPERIMENTS = test_experiments.exp - -[ats] -WAN_QUOTA_OUT = 3932160 -WAN_QUOTA_IN = 3932160 - -[core] -USE_EPHEMERAL_KEYS = NO - -[transport-udp] -TIMEOUT = 300 s - -[PATHS] -GNUNET_TEST_HOME = /tmp/test-experimentation/ - -[nat] -RETURN_LOCAL_ADDRESSES = YES - -[peerinfo] -NO_IO = YES diff --git a/src/experimentation/test_experimentation_clique_connect.c b/src/experimentation/test_experimentation_clique_connect.c deleted file mode 100644 index f7fa02df5..000000000 --- a/src/experimentation/test_experimentation_clique_connect.c +++ /dev/null @@ -1,416 +0,0 @@ -/* - This file is part of GNUnet - (C) 2008--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 src/experimentation/test_experimentation_clique_connect.c - * @brief test case to connect experimentation daemons in a clique - * @author Sree Harsha Totakura - * @author Matthias Wachs - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" - - -/** - * Number of peers we want to start - */ -#define NUM_PEERS 2 - -#define NUM_ISSUER 1 - -#define NUM_EXPERIMENTS 2 - -#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, (5 * NUM_PEERS) + 20) - -/** - * Array of peers - */ -static struct GNUNET_TESTBED_Peer **peers; - -/** - * Operation handle - */ -static struct GNUNET_TESTBED_Operation *op; - -/** - * Shutdown task - */ -static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; - -/** - * Testing result - */ -static int result; - -/** - * Counter for counting overlay connections - */ -static unsigned int overlay_connects; - -/** - * Information we track for a peer in the testbed. - */ -struct ExperimentationPeer -{ - /** - * Handle with testbed. - */ - struct GNUNET_TESTBED_Peer *daemon; - - /** - * Testbed operation to connect to statistics service - */ - struct GNUNET_TESTBED_Operation *stat_op; - - /** - * Handle to the statistics service - */ - struct GNUNET_STATISTICS_Handle *sh; - - unsigned int active_nodes; - unsigned int requested_nodes; - unsigned int inactive_nodes; - unsigned int issuer; - unsigned int experiments; -}; - - -struct ExperimentationPeer bp_slaves[NUM_PEERS]; - -/** - * Shutdown nicely - * - * @param cls NULL - * @param tc the task context - */ -static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - unsigned int peer; - shutdown_task = GNUNET_SCHEDULER_NO_TASK; - - for (peer = 0; peer < NUM_PEERS; peer++) - { - if (NULL != bp_slaves[peer].stat_op) - GNUNET_TESTBED_operation_done (bp_slaves[peer].stat_op); - bp_slaves[peer].stat_op = NULL; - } - - if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - -/** - * Controller event callback - * - * @param cls NULL - * @param event the controller event - */ -static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) -{ - switch (event->type) - { - case GNUNET_TESTBED_ET_CONNECT: - overlay_connects++; - if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) - { - result = GNUNET_OK; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All %u peers connected \n", NUM_PEERS); - if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) - { - GNUNET_SCHEDULER_cancel (shutdown_task); - } - shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, do_shutdown, NULL); - } - break; - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - break; - default: - GNUNET_break (0); - result = GNUNET_SYSERR; - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } -} - -static void -check_end () -{ - static int last_active_value = 0; - static int last_issuer_value = 0; - static int last_experiments_value = 0; - unsigned int peer; - unsigned int total_active = 0; - unsigned int total_inactive = 0; - unsigned int total_requested = 0; - unsigned int issuer = 0; - unsigned int experiments = 0; - - for (peer = 0; peer < NUM_PEERS; peer++) - { - total_active += bp_slaves[peer].active_nodes; - total_requested += bp_slaves[peer].requested_nodes; - total_inactive += bp_slaves[peer].inactive_nodes; - if (NUM_ISSUER == bp_slaves[peer].issuer) - issuer ++; - if (NUM_EXPERIMENTS == bp_slaves[peer].experiments) - experiments ++; - } - if ((last_issuer_value < issuer) && (issuer == NUM_PEERS)) - fprintf (stderr, "I"); - last_issuer_value = issuer; - - if ((last_experiments_value < experiments) && (experiments == NUM_PEERS)) - fprintf (stderr, "E"); - last_experiments_value = experiments; - - if (last_active_value < total_active) - fprintf (stderr, "."); - last_active_value = total_active; - - - if ((total_active == (NUM_PEERS * (NUM_PEERS -1))) && - (total_requested == 0) && (total_inactive == 0) && - (issuer == NUM_PEERS) && (experiments == NUM_PEERS)) - { - fprintf (stderr, "\n"); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All %u peers active in a clique\n", NUM_PEERS); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } -} - - - -/** - * Callback function to process statistic values. - * - * @param cls struct StatsContext - * @param subsystem name of subsystem that created the statistic - * @param name the name of the datum - * @param value the current value - * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not - * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration - */ -static int -stat_iterator (void *cls, const char *subsystem, const char *name, - uint64_t value, int is_persistent) -{ - struct ExperimentationPeer *peer = cls; - - if (0 == strcmp (name, "# nodes active")) - { - peer->active_nodes = value; - } - if (0 == strcmp (name, "# nodes inactive")) - { - peer->inactive_nodes = value; - } - if (0 == strcmp (name, "# nodes requested")) - { - peer->requested_nodes = value; - } - if (0 == strcmp (name, "# issuer")) - { - peer->issuer = value; - } - if (0 == strcmp (name, "# experiments")) - { - peer->experiments = value; - } - - check_end (); - - return GNUNET_OK; -} - -/** - * Called after successfully opening a connection to a peer's statistics - * service; we register statistics monitoring here. - * - * @param cls the callback closure from functions generating an operation - * @param op the operation that has been finished - * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() - * @param emsg error message in case the operation has failed; will be NULL if - * operation has executed successfully. - */ -static void -stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, - void *ca_result, const char *emsg ) -{ - struct GNUNET_STATISTICS_Handle *sh = ca_result; - struct ExperimentationPeer *peer = cls; - - if (NULL != emsg) - { - GNUNET_break (0); - return; - } - - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (sh, "experimentation", "# nodes active", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (sh, "experimentation", "# nodes inactive", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (sh, "experimentation", "# nodes requested", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (sh, "experimentation", "# issuer", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (sh, "experimentation", "# experiments", - stat_iterator, peer)); -} - -/** - * Called to open a connection to the peer's statistics - * - * @param cls peer context - * @param cfg configuration of the peer to connect to; will be available until - * GNUNET_TESTBED_operation_done() is called on the operation returned - * from GNUNET_TESTBED_service_connect() - * @return service handle to return in 'op_result', NULL on error - */ -static void * -stat_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - struct ExperimentationPeer *peer = cls; - peer->sh = GNUNET_STATISTICS_create ("experimentation", cfg); - if (NULL == peer->sh) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create statistics \n"); - return peer->sh; -} - - -/** - * Called to disconnect from peer's statistics service - * - * @param cls peer context - * @param op_result service handle returned from the connect adapter - */ -static void -stat_disconnect_adapter (void *cls, void *op_result) -{ - struct ExperimentationPeer *peer = cls; - - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# nodes active", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# nodes inactive", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# nodes requested", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# issuer", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# experiments", - stat_iterator, peer)); - GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); - peer->sh = NULL; -} - - - -/** - * Signature of a main function for a testcase. - * - * @param cls closure - * @param h the run handle - * @param num_peers number of peers in 'peers' - * @param peers_ handle to peers run in the testbed - * @param links_succeeded the number of overlay link connection attempts that - * succeeded - * @param links_failed the number of overlay link connection attempts that - * failed - */ -static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) -{ - unsigned int peer; - - GNUNET_assert (NULL == cls); - GNUNET_assert (NUM_PEERS == num_peers); - GNUNET_assert (NULL != peers_); - for (peer = 0; peer < num_peers; peer++) - { - GNUNET_assert (NULL != peers_[peer]); - /* Connect to peer's statistic service */ - bp_slaves[peer].stat_op = GNUNET_TESTBED_service_connect (NULL, - peers_[peer], "statistics", - &stat_comp_cb, &bp_slaves[peer], - &stat_connect_adapter, - &stat_disconnect_adapter, - &bp_slaves[peer]); - - } - peers = peers_; - overlay_connects = 0; - op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, - NULL, - NULL, - GNUNET_TESTBED_TOPOLOGY_CLIQUE, - /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ - /* NUM_PEERS, */ - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - GNUNET_assert (NULL != op); - shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, do_shutdown, NULL); -} - - -/** - * Main function - */ -int -main (int argc, char **argv) -{ - uint64_t event_mask; - - result = GNUNET_SYSERR; - event_mask = 0; - event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); - event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - (void) GNUNET_TESTBED_test_run ("test_experimentation_clique_connect", - "test_experimentation_clique.conf", NUM_PEERS, - event_mask, &controller_event_cb, NULL, - &test_master, NULL); - if (GNUNET_OK != result) - return 1; - return 0; -} - -/* end of test_experimentation_clique_connect.c */ diff --git a/src/experimentation/test_experimentation_clique_run.c b/src/experimentation/test_experimentation_clique_run.c deleted file mode 100644 index 875e7501d..000000000 --- a/src/experimentation/test_experimentation_clique_run.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - This file is part of GNUnet - (C) 2008--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 src/experimentation/test_experimentation_clique_run.c - * @brief test case to run experiments with experimentation daemons in a clique - * @author Sree Harsha Totakura - * @author Matthias Wachs - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" - - -/** - * Number of peers we want to start - */ -#define NUM_PEERS 2 - -#define NUM_ISSUER 1 - -#define NUM_EXPERIMENTS 2 - -#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, (5 * NUM_PEERS) + 20) - -/** - * Array of peers - */ -static struct GNUNET_TESTBED_Peer **peers; - -/** - * Operation handle - */ -static struct GNUNET_TESTBED_Operation *op; - -/** - * Shutdown task - */ -static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; - -/** - * Testing result - */ -static int result; - -/** - * Counter for counting overlay connections - */ -static unsigned int overlay_connects; - -/** - * Information we track for a peer in the testbed. - */ -struct ExperimentationPeer -{ - /** - * Handle with testbed. - */ - struct GNUNET_TESTBED_Peer *daemon; - - /** - * Testbed operation to connect to statistics service - */ - struct GNUNET_TESTBED_Operation *stat_op; - - /** - * Handle to the statistics service - */ - struct GNUNET_STATISTICS_Handle *sh; - - unsigned int active_nodes; - unsigned int requested_nodes; - unsigned int inactive_nodes; - unsigned int issuer; - unsigned int experiments_active; - unsigned int experiments_outbound_running; - unsigned int experiments_inbound_running; -}; - - -struct ExperimentationPeer bp_slaves[NUM_PEERS]; - -/** - * Shutdown nicely - * - * @param cls NULL - * @param tc the task context - */ -static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - unsigned int peer; - shutdown_task = GNUNET_SCHEDULER_NO_TASK; - - for (peer = 0; peer < NUM_PEERS; peer++) - { - if (NULL != bp_slaves[peer].stat_op) - GNUNET_TESTBED_operation_done (bp_slaves[peer].stat_op); - bp_slaves[peer].stat_op = NULL; - } - - if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - -/** - * Controller event callback - * - * @param cls NULL - * @param event the controller event - */ -static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) -{ - switch (event->type) - { - case GNUNET_TESTBED_ET_CONNECT: - overlay_connects++; - if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) - { - result = GNUNET_OK; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All %u peers connected \n", NUM_PEERS); - if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) - { - GNUNET_SCHEDULER_cancel (shutdown_task); - } - shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, do_shutdown, NULL); - } - break; - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - break; - default: - GNUNET_break (0); - result = GNUNET_SYSERR; - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } -} - -static void -check_end () -{ - static int last_in_experiments_value = 0; - static int last_out_experiments_value = 0; - unsigned int peer; - unsigned int t_running_outbound_experiments = 0; - unsigned int t_running_inbound_experiments = 0; - - for (peer = 0; peer < NUM_PEERS; peer++) - { - t_running_outbound_experiments += bp_slaves[peer].experiments_outbound_running; - t_running_inbound_experiments += bp_slaves[peer].experiments_inbound_running; - - } - - //fprintf (stderr, "%u %u \n", t_running_outbound_experiments, t_running_inbound_experiments); - if (last_in_experiments_value < t_running_inbound_experiments) - fprintf (stderr, "."); - last_in_experiments_value = t_running_inbound_experiments; - if (last_out_experiments_value < t_running_outbound_experiments) - fprintf (stderr, "."); - last_out_experiments_value = t_running_outbound_experiments; - - - - if ((t_running_inbound_experiments == (NUM_PEERS * NUM_EXPERIMENTS)) && - (t_running_outbound_experiments == (NUM_PEERS * NUM_EXPERIMENTS))) - { - fprintf (stderr, "\n"); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All %u peers are running experiments\n", NUM_PEERS); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } -} - - - -/** - * Callback function to process statistic values. - * - * @param cls struct StatsContext - * @param subsystem name of subsystem that created the statistic - * @param name the name of the datum - * @param value the current value - * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not - * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration - */ -static int -stat_iterator (void *cls, const char *subsystem, const char *name, - uint64_t value, int is_persistent) -{ - struct ExperimentationPeer *peer = cls; - - if (0 == strcmp (name, "# experiments active")) - { - peer->experiments_active = value; - } - - if (0 == strcmp (name, "# experiments outbound running")) - { - peer->experiments_outbound_running = value; - } - - if (0 == strcmp (name, "# experiments inbound running")) - { - peer->experiments_inbound_running = value; - } - - - check_end (); - - return GNUNET_OK; -} - -/** - * Called after successfully opening a connection to a peer's statistics - * service; we register statistics monitoring here. - * - * @param cls the callback closure from functions generating an operation - * @param op the operation that has been finished - * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() - * @param emsg error message in case the operation has failed; will be NULL if - * operation has executed successfully. - */ -static void -stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, - void *ca_result, const char *emsg ) -{ - //struct GNUNET_STATISTICS_Handle *sh = ca_result; - struct ExperimentationPeer *peer = cls; - - if (NULL != emsg) - { - GNUNET_break (0); - return; - } - - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (peer->sh, "experimentation", "# experiments active", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (peer->sh, "experimentation", "# experiments outbound running", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch - (peer->sh, "experimentation", "# experiments inbound running", - stat_iterator, peer)); -} - -/** - * Called to open a connection to the peer's statistics - * - * @param cls peer context - * @param cfg configuration of the peer to connect to; will be available until - * GNUNET_TESTBED_operation_done() is called on the operation returned - * from GNUNET_TESTBED_service_connect() - * @return service handle to return in 'op_result', NULL on error - */ -static void * -stat_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - struct ExperimentationPeer *peer = cls; - peer->sh = GNUNET_STATISTICS_create ("experimentation", cfg); - if (NULL == peer->sh) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create statistics \n"); - return peer->sh; -} - - -/** - * Called to disconnect from peer's statistics service - * - * @param cls peer context - * @param op_result service handle returned from the connect adapter - */ -static void -stat_disconnect_adapter (void *cls, void *op_result) -{ - struct ExperimentationPeer *peer = cls; - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# experiments active", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# experiments outbound running", - stat_iterator, peer)); - GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel - (peer->sh, "experimentation", "# experiments inbound running", - stat_iterator, peer)); - GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); - peer->sh = NULL; -} - - - -/** - * Signature of a main function for a testcase. - * - * @param cls closure - * @param h the run handle - * @param num_peers number of peers in 'peers' - * @param peers_ handle to peers run in the testbed - * @param links_succeeded the number of overlay link connection attempts that - * succeeded - * @param links_failed the number of overlay link connection attempts that - * failed - */ -static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) -{ - unsigned int peer; - - GNUNET_assert (NULL == cls); - GNUNET_assert (NUM_PEERS == num_peers); - GNUNET_assert (NULL != peers_); - for (peer = 0; peer < num_peers; peer++) - { - GNUNET_assert (NULL != peers_[peer]); - /* Connect to peer's statistic service */ - bp_slaves[peer].stat_op = GNUNET_TESTBED_service_connect (NULL, - peers_[peer], "statistics", - &stat_comp_cb, &bp_slaves[peer], - &stat_connect_adapter, - &stat_disconnect_adapter, - &bp_slaves[peer]); - - } - peers = peers_; - overlay_connects = 0; - op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, - NULL, - NULL, - GNUNET_TESTBED_TOPOLOGY_CLIQUE, - /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ - /* NUM_PEERS, */ - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - GNUNET_assert (NULL != op); - shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, do_shutdown, NULL); -} - - -/** - * Main function - */ -int -main (int argc, char **argv) -{ - uint64_t event_mask; - - result = GNUNET_SYSERR; - event_mask = 0; - event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); - event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - (void) GNUNET_TESTBED_test_run ("test_experimentation_clique_run", - "test_experimentation_clique.conf", NUM_PEERS, - event_mask, &controller_event_cb, NULL, - &test_master, NULL); - if (GNUNET_OK != result) - return 1; - return 0; -} - -/* end of test_experimentation_clique_run.c */ diff --git a/src/experimentation/test_experiments.exp b/src/experimentation/test_experiments.exp deleted file mode 100644 index 035ac4b24..000000000 --- a/src/experimentation/test_experiments.exp +++ /dev/null @@ -1,9 +0,0 @@ -[test-experiment-1] -ISSUER = TFRM29O2RQNKLVBQIGODJ6GD58LSQ2NM9TNFBC6N48BRJHQO38Q73N2OM3V4CLKDM6CILQV4CU8PMJDRG0FNB0PDI057DBRANMLPLRG -VERSION = 1 -CAPABILITIES = 0 - -[test-experiment-2] -ISSUER = TFRM29O2RQNKLVBQIGODJ6GD58LSQ2NM9TNFBC6N48BRJHQO38Q73N2OM3V4CLKDM6CILQV4CU8PMJDRG0FNB0PDI057DBRANMLPLRG -VERSION = 1 -CAPABILITIES = 0 \ No newline at end of file -- cgit v1.2.3