From 32892c4aa7736eb8039f28d79b5cdb53cdc0061c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 24 Apr 2010 13:08:05 +0000 Subject: [PATCH] off-line hack fest --- TODO | 15 +- configure.ac | 2 + src/Makefile.am | 4 +- src/datacache/datacache.c | 4 +- src/datacache/perf_datacache.c | 2 +- src/datacache/plugin_datacache.h | 4 +- src/datacache/plugin_datacache_sqlite.c | 4 +- src/datacache/plugin_datacache_template.c | 4 +- src/datacache/test_datacache.c | 2 +- src/datastore/datastore_api.c | 4 +- src/datastore/gnunet-service-datastore.c | 8 +- src/datastore/perf_datastore_api.c | 2 +- src/datastore/perf_plugin_datastore.c | 2 +- src/datastore/plugin_datastore.h | 9 +- src/datastore/plugin_datastore_sqlite.c | 18 +- src/datastore/plugin_datastore_template.c | 40 +- src/datastore/test_datastore_api.c | 38 +- src/datastore/test_datastore_api_management.c | 18 +- src/fs/Makefile.am | 1 + src/fs/fs.h | 134 +------ src/fs/fs_download.c | 12 +- src/fs/fs_namespace.c | 2 +- src/fs/fs_publish.c | 10 +- src/fs/fs_search.c | 20 +- src/fs/fs_tree.c | 4 +- src/fs/fs_tree.h | 2 +- src/fs/fs_unindex.c | 4 +- src/fs/gnunet-service-fs.c | 296 ++++---------- src/fs/gnunet-service-fs_drq.c | 6 +- src/fs/gnunet-service-fs_drq.h | 2 +- src/fs/gnunet-service-fs_indexing.c | 4 +- src/fs/gnunet-service-fs_indexing.h | 3 +- src/include/gnunet_datacache_lib.h | 7 +- src/include/gnunet_datastore_service.h | 44 +- src/include/gnunet_dht_service.h | 2 +- src/migration/Makefile.am | 34 ++ src/migration/gnunet-daemon-migration | 148 +++++++ src/migration/gnunet-daemon-migration.c | 377 ++++++++++++++++++ .../test_gnunet_daemon_migration.c} | 10 +- .../test_gnunet_daemon_migration_data.conf} | 0 src/topology/Makefile.am | 10 +- src/topology/test_gnunet_daemon_topology.c | 182 +++++++++ .../test_gnunet_daemon_topology_data.conf | 37 ++ src/util/test_resolver_api.c | 3 +- 44 files changed, 1004 insertions(+), 530 deletions(-) create mode 100644 src/migration/Makefile.am create mode 100755 src/migration/gnunet-daemon-migration create mode 100644 src/migration/gnunet-daemon-migration.c rename src/{topology/test_gnunet_service_topology.c => migration/test_gnunet_daemon_migration.c} (94%) rename src/{topology/test_gnunet_service_topology_data.conf => migration/test_gnunet_daemon_migration_data.conf} (100%) create mode 100644 src/topology/test_gnunet_daemon_topology.c create mode 100644 src/topology/test_gnunet_daemon_topology_data.conf diff --git a/TODO b/TODO index 218e3b94a..b5d21b828 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,17 @@ 0.9.0pre1: +* MIGRATION [CG] + - on-demand encoding => move logic to block-library!? + - peer selection => how to consider latency/bw/etc? + - content transmission => how often the same block? + - how to select delay before next migration? + - testing * FS: [CG] + - migration (inbound) + - support for in-line files in directories (FIXME in fs_download) - bound parallelism (# fs downloads) - distinguish in performance tracking and event signalling between downloads that are actually running and those that are merely in the queue - persistence support (publish, unindex, search, download) - - active migration support (in fs or in datastore or new daemon?) - - support for in-line files in directories (FIXME in fs_download) - gnunet-service-fs (hot-path routing, load-based routing, nitpicks) - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used @@ -76,6 +82,8 @@ + download + search + unindex +* MIGRATION: + - improved content selection (not just 'get_random') 0.9.0pre3: * Determine RC bugs and fix those! @@ -183,4 +191,5 @@ Minor features: - add stats (# bytes available, # bytes used, # PUTs, # GETs, # GETs satisfied) * FS: - support inline data in directories for recursive file downloads (fs_download) - +* BLOCKS: + - testcase would be nice... diff --git a/configure.ac b/configure.ac index 1a9a3b50c..44469156e 100644 --- a/configure.ac +++ b/configure.ac @@ -645,6 +645,7 @@ m4/Makefile po/Makefile.in src/Makefile src/arm/Makefile +src/block/Makefile src/core/Makefile src/datacache/Makefile src/datastore/Makefile @@ -656,6 +657,7 @@ src/hello/Makefile src/include/Makefile src/include/gnunet_directories.h src/hostlist/Makefile +src/migration/Makefile src/nat/Makefile src/nat/libnatpmp/Makefile src/nat/miniupnp/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 94092e1a8..d54db16fe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ endif SUBDIRS = \ include $(INTLEMU_SUBDIRS) \ util \ + block \ statistics \ arm \ hello \ @@ -23,4 +24,5 @@ SUBDIRS = \ hostlist \ topology \ $(NAT_DIR) \ - fs + fs \ + migration diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index c8530055d..4c474e9ba 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c @@ -224,7 +224,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, const GNUNET_HashCode * key, uint32_t size, const char *data, - unsigned int type, + enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { uint32_t used; @@ -259,7 +259,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, unsigned int GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, const GNUNET_HashCode * key, - unsigned int type, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c index 818b6f816..45d2d008b 100644 --- a/src/datacache/perf_datacache.c +++ b/src/datacache/perf_datacache.c @@ -42,7 +42,7 @@ checkIt (void *cls, const GNUNET_HashCode * key, uint32_t size, const char *data, - uint32_t type) + enum GNUNET_BLOCK_Type type) { if ( (size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size)) ) diff --git a/src/datacache/plugin_datacache.h b/src/datacache/plugin_datacache.h index d3768cf44..c7360834b 100644 --- a/src/datacache/plugin_datacache.h +++ b/src/datacache/plugin_datacache.h @@ -116,7 +116,7 @@ struct GNUNET_DATACACHE_PluginFunctions { const GNUNET_HashCode * key, uint32_t size, const char *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time); @@ -133,7 +133,7 @@ struct GNUNET_DATACACHE_PluginFunctions { */ unsigned int (*get) (void *cls, const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls); diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 7595211c1..98bcae788 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -99,7 +99,7 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, const char *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { struct Plugin *plugin = cls; @@ -166,7 +166,7 @@ sqlite_plugin_put (void *cls, static unsigned int sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c index 163f72a7a..8488d5a32 100644 --- a/src/datacache/plugin_datacache_template.c +++ b/src/datacache/plugin_datacache_template.c @@ -56,7 +56,7 @@ template_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, const char *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { GNUNET_break (0); @@ -78,7 +78,7 @@ template_plugin_put (void *cls, static unsigned int template_plugin_get (void *cls, const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index c896b667b..babbff72e 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c @@ -39,7 +39,7 @@ checkIt (void *cls, const GNUNET_HashCode * key, uint32_t size, const char *data, - uint32_t type) + enum GNUNET_BLOCK_Type type) { if (size != sizeof (GNUNET_HashCode)) { diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 7e7bf02c8..1c50dabee 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -319,7 +319,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, @@ -668,7 +668,7 @@ transmit_for_result (struct GNUNET_DATASTORE_Handle *h, void GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h, const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATASTORE_Iterator iter, void *iter_cls, struct GNUNET_TIME_Relative timeout) { diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 79fcd70e9..6d0f29671 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -288,7 +288,7 @@ expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -375,7 +375,7 @@ manage (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -644,7 +644,7 @@ transmit_item (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -1094,7 +1094,7 @@ remove_callback (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 93e875c8c..b92fefe4d 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -198,7 +198,7 @@ delete_value (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index a23569875..ea1df5efa 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c @@ -140,7 +140,7 @@ iterateDummy (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute diff --git a/src/datastore/plugin_datastore.h b/src/datastore/plugin_datastore.h index 775a6641a..e8f433671 100644 --- a/src/datastore/plugin_datastore.h +++ b/src/datastore/plugin_datastore.h @@ -30,6 +30,7 @@ #ifndef PLUGIN_DATASTORE_H #define PLUGIN_DATASTORE_H +#include "gnunet_block_lib.h" #include "gnunet_configuration_lib.h" #include "gnunet_datastore_service.h" #include "gnunet_statistics_service.h" @@ -103,7 +104,7 @@ typedef int (*PluginIterator) (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -142,7 +143,7 @@ typedef int (*PluginPut) (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, @@ -173,7 +174,7 @@ typedef int (*PluginPut) (void *cls, typedef void (*PluginGet) (void *cls, const GNUNET_HashCode * key, const GNUNET_HashCode * vhash, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls); @@ -222,7 +223,7 @@ typedef int (*PluginUpdate) (void *cls, * @param iter_cls closure for iter */ typedef void (*PluginSelector) (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls); diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 0d4170e56..824b74ad2 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -719,7 +719,7 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, @@ -892,7 +892,7 @@ struct IterContext /** * Desired type for blocks returned by this iterator. */ - uint32_t type; + enum GNUNET_BLOCK_Type type; }; @@ -1026,7 +1026,7 @@ iter_next_prepare (void *cls, */ static void basic_iter (struct Plugin *plugin, - uint32_t type, + enum GNUNET_BLOCK_Type type, int is_asc, int is_prio, int is_migr, @@ -1110,7 +1110,7 @@ basic_iter (struct Plugin *plugin, */ static void sqlite_plugin_iter_low_priority (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { @@ -1137,7 +1137,7 @@ sqlite_plugin_iter_low_priority (void *cls, */ static void sqlite_plugin_iter_zero_anonymity (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { @@ -1176,7 +1176,7 @@ sqlite_plugin_iter_zero_anonymity (void *cls, */ static void sqlite_plugin_iter_ascending_expiration (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { @@ -1213,7 +1213,7 @@ sqlite_plugin_iter_ascending_expiration (void *cls, */ static void sqlite_plugin_iter_migration_order (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { @@ -1288,7 +1288,7 @@ all_next_prepare (void *cls, */ static void sqlite_plugin_iter_all_now (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { @@ -1439,7 +1439,7 @@ static void sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, const GNUNET_HashCode * vhash, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { struct Plugin *plugin = cls; diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index 6439bc019..7656f6a7d 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c @@ -70,12 +70,12 @@ static unsigned long long template_plugin_get_size (void *cls) */ static int template_plugin_put (void *cls, - const GNUNET_HashCode * key, - uint32_t size, - const void *data, - uint32_t type, - uint32_t priority, - uint32_t anonymity, + const GNUNET_HashCode * key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, char **msg) { @@ -126,7 +126,7 @@ static void template_plugin_get (void *cls, const GNUNET_HashCode * key, const GNUNET_HashCode * vhash, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { GNUNET_break (0); @@ -181,7 +181,7 @@ template_plugin_update (void *cls, */ static void template_plugin_iter_low_priority (void *cls, - uint32_t type, + enum GNUNET_BLOCK_Type type, PluginIterator iter, void *iter_cls) { @@ -203,9 +203,9 @@ template_plugin_iter_low_priority (void *cls, */ static void template_plugin_iter_zero_anonymity (void *cls, - uint32_t type, - PluginIterator iter, - void *iter_cls) + enum GNUNET_BLOCK_Type type, + PluginIterator iter, + void *iter_cls) { GNUNET_break (0); } @@ -225,9 +225,9 @@ template_plugin_iter_zero_anonymity (void *cls, */ static void template_plugin_iter_ascending_expiration (void *cls, - uint32_t type, - PluginIterator iter, - void *iter_cls) + enum GNUNET_BLOCK_Type type, + PluginIterator iter, + void *iter_cls) { GNUNET_break (0); } @@ -247,9 +247,9 @@ template_plugin_iter_ascending_expiration (void *cls, */ static void template_plugin_iter_migration_order (void *cls, - uint32_t type, - PluginIterator iter, - void *iter_cls) + enum GNUNET_BLOCK_Type type, + PluginIterator iter, + void *iter_cls) { GNUNET_break (0); } @@ -269,9 +269,9 @@ template_plugin_iter_migration_order (void *cls, */ static void template_plugin_iter_all_now (void *cls, - uint32_t type, - PluginIterator iter, - void *iter_cls) + enum GNUNET_BLOCK_Type type, + PluginIterator iter, + void *iter_cls) { GNUNET_break (0); } diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 74c2ae206..07f1dc426 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -174,7 +174,7 @@ check_value (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -209,14 +209,14 @@ check_value (void *cls, static void delete_value (void *cls, - const GNUNET_HashCode * key, - uint32_t size, - const void *data, - uint32_t type, - uint32_t priority, - uint32_t anonymity, - struct GNUNET_TIME_Absolute - expiration, uint64_t uid) + const GNUNET_HashCode * key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + struct GNUNET_TIME_Absolute + expiration, uint64_t uid) { struct CpsRunContext *crc = cls; if (key == NULL) @@ -239,14 +239,14 @@ delete_value (void *cls, static void check_nothing (void *cls, - const GNUNET_HashCode * key, - uint32_t size, - const void *data, - uint32_t type, - uint32_t priority, - uint32_t anonymity, - struct GNUNET_TIME_Absolute - expiration, uint64_t uid) + const GNUNET_HashCode * key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + struct GNUNET_TIME_Absolute + expiration, uint64_t uid) { struct CpsRunContext *crc = cls; GNUNET_assert (key == NULL); @@ -266,7 +266,7 @@ check_multiple (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -296,7 +296,7 @@ check_update (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index 62d1e5d26..169cef554 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -144,7 +144,7 @@ check_value (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -189,14 +189,14 @@ check_value (void *cls, static void check_nothing (void *cls, - const GNUNET_HashCode * key, - uint32_t size, - const void *data, - uint32_t type, - uint32_t priority, - uint32_t anonymity, - struct GNUNET_TIME_Absolute - expiration, uint64_t uid) + const GNUNET_HashCode * key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + struct GNUNET_TIME_Absolute + expiration, uint64_t uid) { struct CpsRunContext *crc = cls; diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index e1b85092a..3d825ff10 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -98,6 +98,7 @@ gnunet_service_fs_SOURCES = \ gnunet-service-fs_indexing.c gnunet-service-fs_indexing.h gnunet_service_fs_LDADD = \ $(top_builddir)/src/fs/libgnunetfs.la \ + $(top_builddir)/src/block/libgnunetblock.la \ $(top_builddir)/src/datastore/libgnunetdatastore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/core/libgnunetcore.la \ diff --git a/src/fs/fs.h b/src/fs/fs.h index a9a585a15..fdf501b44 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -29,6 +29,7 @@ #include "gnunet_constants.h" #include "gnunet_datastore_service.h" #include "gnunet_fs_service.h" +#include "gnunet_block_lib.h" /** * Size of the individual blocks used for file-sharing. @@ -1123,139 +1124,6 @@ struct GNUNET_FS_Namespace }; -/** - * @brief index block (indexing a DBlock that - * can be obtained directly from reading - * the plaintext file) - */ -struct OnDemandBlock -{ - /** - * Hash code of the entire content of the - * file that was indexed (used to uniquely - * identify the plaintext file). - */ - GNUNET_HashCode file_id; - - /** - * At which offset should we be able to find - * this on-demand encoded block? (in NBO) - */ - uint64_t offset GNUNET_PACKED; - -}; - - -/** - * @brief keyword block (advertising data under a keyword) - */ -struct KBlock -{ - - /** - * GNUNET_RSA_Signature using RSA-key generated from search keyword. - */ - struct GNUNET_CRYPTO_RsaSignature signature; - - /** - * What is being signed and why? - */ - struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; - - /** - * Key generated (!) from the H(keyword) as the seed! - */ - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace; - - /* 0-terminated URI here */ - - /* variable-size Meta-Data follows here */ - -}; - -/** - * @brief namespace content block (advertising data under an identifier in a namespace) - */ -struct SBlock -{ - - /** - * GNUNET_RSA_Signature using RSA-key of the namespace - */ - struct GNUNET_CRYPTO_RsaSignature signature; - - /** - * What is being signed and why? - */ - struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; - - /** - * Hash of the hash of the human-readable identifier used for - * this entry (the hash of the human-readable identifier is - * used as the key for decryption; the xor of this identifier - * and the hash of the "keyspace" is the datastore-query hash). - */ - GNUNET_HashCode identifier; - - /** - * Public key of the namespace. - */ - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace; - - /* 0-terminated update-identifier here */ - - /* 0-terminated URI here (except for NBlocks) */ - - /* variable-size Meta-Data follows here */ - -}; - - -/** - * @brief namespace advertisement block (advertising root of a namespace) - */ -struct NBlock -{ - - /** - * GNUNET_RSA_Signature using RSA-key generated from search keyword. - */ - struct GNUNET_CRYPTO_RsaSignature ksk_signature; - - /** - * What is being signed and why? - */ - struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose; - - /** - * Key generated (!) from the H(keyword) as the seed! - */ - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace; - - /** - * GNUNET_RSA_Signature using RSA-key of the namespace - */ - struct GNUNET_CRYPTO_RsaSignature ns_signature; - - /** - * What is being signed and why? - */ - struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose; - - /** - * Public key of the namespace. - */ - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace; - - /* from here on, data is encrypted with H(keyword) */ - - /* 0-terminated root identifier here */ - - /* variable-size Meta-Data follows here */ - -}; - - /** * Message sent from a GNUnet (fs) publishing activity to the * gnunet-fs-service to initiate indexing of a file. The service is diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 7bdf6902b..b179c70dc 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -219,7 +219,7 @@ struct ProcessResultClosure /** * Type of data. */ - uint32_t type; + enum GNUNET_BLOCK_Type type; /** * Flag to indicate if this block should be stored on disk. @@ -333,8 +333,8 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, prc.data = enc; prc.size = len; prc.type = (dc->treedepth == depth) - ? GNUNET_DATASTORE_BLOCKTYPE_DBLOCK - : GNUNET_DATASTORE_BLOCKTYPE_IBLOCK; + ? GNUNET_BLOCK_TYPE_DBLOCK + : GNUNET_BLOCK_TYPE_IBLOCK; prc.query = chk->query; prc.do_store = GNUNET_NO; /* useless */ process_result_with_request (&prc, @@ -1021,7 +1021,7 @@ process_result_with_request (void *cls, */ static void process_result (struct GNUNET_FS_DownloadContext *dc, - uint32_t type, + enum GNUNET_BLOCK_Type type, const void *data, size_t size) { @@ -1128,9 +1128,9 @@ transmit_download_request (void *cls, sm->header.size = htons (sizeof (struct SearchMessage)); sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); if (dc->pending->depth == dc->treedepth) - sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_DBLOCK); + sm->type = htonl (GNUNET_BLOCK_TYPE_DBLOCK); else - sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_IBLOCK); + sm->type = htonl (GNUNET_BLOCK_TYPE_IBLOCK); sm->anonymity_level = htonl (dc->anonymity); sm->target = dc->target.hashPubKey; sm->query = dc->pending->chk.query; diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 462080305..267a90228 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c @@ -199,7 +199,7 @@ advertisement_cont (void *cls, &query, ac->pt_size + sizeof (struct NBlock), ac->nb, - GNUNET_DATASTORE_BLOCKTYPE_NBLOCK, + GNUNET_BLOCK_TYPE_NBLOCK, ac->priority, ac->anonymity, ac->expiration, diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index fac75a848..1260d1c7c 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -451,7 +451,7 @@ static void block_proc (void *cls, const GNUNET_HashCode *query, uint64_t offset, - uint32_t type, + enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size) { @@ -480,7 +480,7 @@ block_proc (void *cls, dpc_cls->p = p; if ( (! p->is_directory) && (GNUNET_YES == p->data.file.do_index) && - (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) ) + (type == GNUNET_BLOCK_TYPE_DBLOCK) ) { #if DEBUG_PUBLISH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -496,7 +496,7 @@ block_proc (void *cls, query, sizeof(struct OnDemandBlock), &odb, - GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND, + GNUNET_BLOCK_TYPE_ONDEMAND, p->priority, p->anonymity, p->expirationTime, @@ -1281,7 +1281,7 @@ publish_ksk_cont (void *cls, sizeof (struct KBlock) + pkc->slen, pkc->cpy, - GNUNET_DATASTORE_BLOCKTYPE_KBLOCK, + GNUNET_BLOCK_TYPE_KBLOCK, pkc->priority, pkc->anonymity, pkc->expirationTime, @@ -1594,7 +1594,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, &sb_enc->identifier, size, sb_enc, - GNUNET_DATASTORE_BLOCKTYPE_SBLOCK, + GNUNET_BLOCK_TYPE_SBLOCK, priority, anonymity, expirationTime, diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 8674f824c..294d3d454 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -574,7 +574,7 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, */ static void process_result (struct GNUNET_FS_SearchContext *sc, - uint32_t type, + enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration, const void *data, size_t size) @@ -587,7 +587,7 @@ process_result (struct GNUNET_FS_SearchContext *sc, } switch (type) { - case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: + case GNUNET_BLOCK_TYPE_KBLOCK: if (! GNUNET_FS_uri_test_ksk (sc->uri)) { GNUNET_break (0); @@ -600,7 +600,7 @@ process_result (struct GNUNET_FS_SearchContext *sc, } process_kblock (sc, data, size); break; - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: + case GNUNET_BLOCK_TYPE_SBLOCK: if (! GNUNET_FS_uri_test_sks (sc->uri)) { GNUNET_break (0); @@ -613,7 +613,7 @@ process_result (struct GNUNET_FS_SearchContext *sc, } process_sblock (sc, data, size); break; - case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: + case GNUNET_BLOCK_TYPE_NBLOCK: if (! GNUNET_FS_uri_test_ksk (sc->uri)) { GNUNET_break (0); @@ -626,10 +626,10 @@ process_result (struct GNUNET_FS_SearchContext *sc, } process_nblock (sc, data, size); break; - case GNUNET_DATASTORE_BLOCKTYPE_ANY: - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_ANY: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_ONDEMAND: + case GNUNET_BLOCK_TYPE_IBLOCK: GNUNET_break (0); break; default: @@ -729,7 +729,7 @@ transmit_search_request (void *cls, { sm[i].header.size = htons (sizeof (struct SearchMessage)); sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); - sm[i].type = htonl (GNUNET_DATASTORE_BLOCKTYPE_ANY); + sm[i].type = htonl (GNUNET_BLOCK_TYPE_ANY); sm[i].anonymity_level = htonl (sc->anonymity); sm[i].query = sc->requests[i].query; } @@ -743,7 +743,7 @@ transmit_search_request (void *cls, memset (sm, 0, msize); sm->header.size = htons (sizeof (struct SearchMessage)); sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); - sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_SBLOCK); + sm->type = htonl (GNUNET_BLOCK_TYPE_SBLOCK); sm->anonymity_level = htonl (sc->anonymity); sm->target = sc->uri->data.sks.namespace; identifier = sc->uri->data.sks.identifier; diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c index ef7c560d6..15e13be21 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c @@ -389,8 +389,8 @@ void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te) &mychk->query, te->publish_offset, (te->current_depth == te->chk_tree_depth) - ? GNUNET_DATASTORE_BLOCKTYPE_DBLOCK - : GNUNET_DATASTORE_BLOCKTYPE_IBLOCK, + ? GNUNET_BLOCK_TYPE_DBLOCK + : GNUNET_BLOCK_TYPE_IBLOCK, enc, pt_size); if (NULL != te->progress) diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h index 82b897bd3..c8863589a 100644 --- a/src/fs/fs_tree.h +++ b/src/fs/fs_tree.h @@ -67,7 +67,7 @@ struct GNUNET_FS_TreeEncoder; typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls, const GNUNET_HashCode *query, uint64_t offset, - uint32_t type, + enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size); diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index 5d1e7c8f0..1b41e0c7a 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -198,7 +198,7 @@ static void unindex_process (void *cls, const GNUNET_HashCode *query, uint64_t offset, - uint32_t type, + enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size) { @@ -207,7 +207,7 @@ unindex_process (void *cls, const void *data; struct OnDemandBlock odb; - if (type != GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) + if (type != GNUNET_BLOCK_TYPE_DBLOCK) { size = block_size; data = block; diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 2c3e6e666..41be75e98 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -540,7 +540,7 @@ struct PendingRequest /** * Type of the content that this request is for. */ - uint32_t type; + enum GNUNET_BLOCK_Type type; /** * Remove this request after transmission of the current response. @@ -1680,14 +1680,14 @@ transmit_reply_continuation (void *cls, switch (pr->type) { - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_IBLOCK: /* only one reply expected, done with the request! */ destroy_pending_request (pr); break; - case GNUNET_DATASTORE_BLOCKTYPE_ANY: - case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: + case GNUNET_BLOCK_TYPE_ANY: + case GNUNET_BLOCK_TYPE_KBLOCK: + case GNUNET_BLOCK_TYPE_SBLOCK: break; default: GNUNET_break (0); @@ -1696,152 +1696,6 @@ transmit_reply_continuation (void *cls, } -/** - * Check if the given KBlock is well-formed. - * - * @param kb the kblock data (or at least "dsize" bytes claiming to be one) - * @param dsize size of "kb" in bytes; check for < sizeof(struct KBlock)! - * @param query where to store the query that this block answers - * @return GNUNET_OK if this is actually a well-formed KBlock - */ -static int -check_kblock (const struct KBlock *kb, - size_t dsize, - GNUNET_HashCode *query) -{ - if (dsize < sizeof (struct KBlock)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (dsize - sizeof (struct KBlock) != - ntohl (kb->purpose.size) - - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) - - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) ) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (GNUNET_OK != - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK, - &kb->purpose, - &kb->signature, - &kb->keyspace)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (query != NULL) - GNUNET_CRYPTO_hash (&kb->keyspace, - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), - query); - return GNUNET_OK; -} - - -/** - * Check if the given NBlock is well-formed. - * - * @param nb the nblock data (or at least "dsize" bytes claiming to be one) - * @param dsize size of "nb" in bytes; check for < sizeof(struct NBlock)! - * @param query where to store the query that this block answers - * @return GNUNET_OK if this is actually a well-formed NBlock - */ -static int -check_nblock (const struct NBlock *nb, - size_t dsize, - GNUNET_HashCode *query) -{ - if (dsize < sizeof (struct NBlock)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (dsize - sizeof (struct NBlock) != - ntohl (nb->ns_purpose.size) - - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) - - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) ) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (dsize != - ntohl (nb->ksk_purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (GNUNET_OK != - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG, - &nb->ksk_purpose, - &nb->ksk_signature, - &nb->keyspace)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (GNUNET_OK != - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK, - &nb->ns_purpose, - &nb->ns_signature, - &nb->subspace)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (query != NULL) - GNUNET_CRYPTO_hash (&nb->keyspace, - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), - query); - return GNUNET_OK; -} - - -/** - * Check if the given SBlock is well-formed. - * - * @param sb the sblock data (or at least "dsize" bytes claiming to be one) - * @param dsize size of "kb" in bytes; check for < sizeof(struct SBlock)! - * @param query where to store the query that this block answers - * @param namespace where to store the namespace that this block belongs to - * @return GNUNET_OK if this is actually a well-formed SBlock - */ -static int -check_sblock (const struct SBlock *sb, - size_t dsize, - GNUNET_HashCode *query, - GNUNET_HashCode *namespace) -{ - if (dsize < sizeof (struct SBlock)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (dsize != - ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (GNUNET_OK != - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK, - &sb->purpose, - &sb->signature, - &sb->subspace)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (query != NULL) - *query = sb->identifier; - if (namespace != NULL) - GNUNET_CRYPTO_hash (&sb->subspace, - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), - namespace); - return GNUNET_OK; -} - - /** * Transmit the given message by copying it to the target buffer * "buf". "buf" will be NULL and "size" zero if the socket was closed @@ -1931,7 +1785,7 @@ struct ProcessReplyClosure /** * Type of the block. */ - uint32_t type; + enum GNUNET_BLOCK_Type type; /** * How much was this reply worth to us? @@ -1979,8 +1833,8 @@ process_reply (void *cls, &chash); switch (prq->type) { - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_IBLOCK: /* only possible reply, stop requesting! */ while (NULL != pr->pending_head) destroy_pending_message_list_entry (pr->pending_head); @@ -2004,7 +1858,7 @@ process_reply (void *cls, key, pr)); break; - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: + case GNUNET_BLOCK_TYPE_SBLOCK: if (pr->namespace == NULL) { GNUNET_break (0); @@ -2019,8 +1873,8 @@ process_reply (void *cls, return GNUNET_YES; /* wrong namespace */ } /* then: fall-through! */ - case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: + case GNUNET_BLOCK_TYPE_KBLOCK: + case GNUNET_BLOCK_TYPE_NBLOCK: if (pr->bf != NULL) { mingle_hash (&chash, pr->mingle, &mhash); @@ -2156,10 +2010,11 @@ handle_p2p_put (void *cls, const struct PutMessage *put; uint16_t msize; size_t dsize; - uint32_t type; + enum GNUNET_BLOCK_Type type; struct GNUNET_TIME_Absolute expiration; GNUNET_HashCode query; struct ProcessReplyClosure prq; + const struct SBlock *sb; msize = ntohs (message->size); if (msize < sizeof (struct PutMessage)) @@ -2172,40 +2027,24 @@ handle_p2p_put (void *cls, type = ntohl (put->type); expiration = GNUNET_TIME_absolute_ntoh (put->expiration); - /* first, validate! */ - switch (type) + if (GNUNET_OK != + GNUNET_BLOCK_check_block (type, + &put[1], + dsize, + &query)) { - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: - GNUNET_CRYPTO_hash (&put[1], dsize, &query); - break; - case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: - if (GNUNET_OK != - check_kblock ((const struct KBlock*) &put[1], - dsize, - &query)) - return GNUNET_SYSERR; - break; - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: - if (GNUNET_OK != - check_sblock ((const struct SBlock*) &put[1], - dsize, - &query, - &prq.namespace)) - return GNUNET_SYSERR; - break; - case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: - if (GNUNET_OK != - check_nblock ((const struct NBlock*) &put[1], - dsize, - &query)) - return GNUNET_SYSERR; - return GNUNET_OK; - default: - /* unknown block type */ GNUNET_break_op (0); return GNUNET_SYSERR; } + if (type == GNUNET_BLOCK_TYPE_ONDEMAND) + return GNUNET_SYSERR; + if (GNUNET_BLOCK_TYPE_SBLOCK == type) + { + sb = (const struct SBlock*) &put[1]; + GNUNET_CRYPTO_hash (&sb->subspace, + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &prq.namespace); + } #if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2309,7 +2148,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -2319,6 +2158,7 @@ process_local_reply (void *cls, struct PendingRequest *pr = cls; struct ProcessReplyClosure prq; struct CheckDuplicateRequestClosure cdrc; + const struct SBlock *sb; GNUNET_HashCode dhash; GNUNET_HashCode mhash; GNUNET_HashCode query; @@ -2368,7 +2208,7 @@ process_local_reply (void *cls, GNUNET_h2s (key), type); #endif - if (type == GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND) + if (type == GNUNET_BLOCK_TYPE_ONDEMAND) { #if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2421,11 +2261,17 @@ process_local_reply (void *cls, prq.data = data; prq.expiration = expiration; prq.size = size; - if ( (type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) && - (GNUNET_OK != check_sblock ((const struct SBlock*) data, - size, - &query, - &prq.namespace)) ) + if (GNUNET_BLOCK_TYPE_SBLOCK == type) + { + sb = (const struct SBlock*) data; + GNUNET_CRYPTO_hash (&sb->subspace, + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &prq.namespace); + } + if (GNUNET_OK != GNUNET_BLOCK_check_block (type, + data, + size, + &query)) { GNUNET_break (0); /* FIXME: consider removing the block? */ @@ -2436,8 +2282,8 @@ process_local_reply (void *cls, prq.priority = priority; process_reply (&prq, key, pr); - if ( (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) || - (type == GNUNET_DATASTORE_BLOCKTYPE_IBLOCK) ) + if ( (type == GNUNET_BLOCK_TYPE_DBLOCK) || + (type == GNUNET_BLOCK_TYPE_IBLOCK) ) { GNUNET_FS_drq_get_next (GNUNET_NO); return; @@ -2538,7 +2384,7 @@ handle_p2p_get (void *cls, uint32_t bm; size_t bfsize; uint32_t ttl_decrement; - uint32_t type; + enum GNUNET_BLOCK_Type type; double preference; int have_ns; @@ -2552,11 +2398,11 @@ handle_p2p_get (void *cls, type = ntohl (gm->type); switch (type) { - case GNUNET_DATASTORE_BLOCKTYPE_ANY: - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: + case GNUNET_BLOCK_TYPE_ANY: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_KBLOCK: + case GNUNET_BLOCK_TYPE_SBLOCK: break; default: GNUNET_break_op (0); @@ -2579,7 +2425,7 @@ handle_p2p_get (void *cls, bfsize = msize - sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode); bm = ntohl (gm->hash_bitmap); if ( (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) && - (type != GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ) + (type != GNUNET_BLOCK_TYPE_SBLOCK) ) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -2764,8 +2610,8 @@ handle_p2p_get (void *cls, cps->inc_preference += preference; /* process locally */ - if (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) - type = GNUNET_DATASTORE_BLOCKTYPE_ANY; /* to get on-demand as well */ + if (type == GNUNET_BLOCK_TYPE_DBLOCK) + type = GNUNET_BLOCK_TYPE_ANY; /* to get on-demand as well */ timeout = GNUNET_TIME_relative_multiply (BASIC_DATASTORE_REQUEST_DELAY, (pr->priority + 1)); pr->drq = GNUNET_FS_drq_get (&gm->query, @@ -2778,8 +2624,8 @@ handle_p2p_get (void *cls, /* Are multiple results possible? If so, start processing remotely now! */ switch (pr->type) { - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_IBLOCK: /* only one result, wait for datastore */ break; default: @@ -2821,7 +2667,7 @@ handle_start_search (void *cls, struct PendingRequest *pr; uint16_t msize; unsigned int sc; - uint32_t type; + enum GNUNET_BLOCK_Type type; msize = ntohs (message->size); if ( (msize < sizeof (struct SearchMessage)) || @@ -2847,12 +2693,12 @@ handle_start_search (void *cls, #endif switch (type) { - case GNUNET_DATASTORE_BLOCKTYPE_ANY: - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: + case GNUNET_BLOCK_TYPE_ANY: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_KBLOCK: + case GNUNET_BLOCK_TYPE_SBLOCK: + case GNUNET_BLOCK_TYPE_NBLOCK: break; default: GNUNET_break (0); @@ -2874,9 +2720,9 @@ handle_start_search (void *cls, client_list = cl; } /* detect duplicate KBLOCK requests */ - if ( (type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) || - (type == GNUNET_DATASTORE_BLOCKTYPE_NBLOCK) || - (type == GNUNET_DATASTORE_BLOCKTYPE_ANY) ) + if ( (type == GNUNET_BLOCK_TYPE_KBLOCK) || + (type == GNUNET_BLOCK_TYPE_NBLOCK) || + (type == GNUNET_BLOCK_TYPE_ANY) ) { crl = cl->rl_head; while ( (crl != NULL) && @@ -2917,7 +2763,7 @@ handle_start_search (void *cls, 1, GNUNET_NO); pr = GNUNET_malloc (sizeof (struct PendingRequest) + - ((type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ? sizeof(GNUNET_HashCode) : 0)); + ((type == GNUNET_BLOCK_TYPE_SBLOCK) ? sizeof(GNUNET_HashCode) : 0)); crl = GNUNET_malloc (sizeof (struct ClientRequestList)); memset (crl, 0, sizeof (struct ClientRequestList)); crl->client_list = cl; @@ -2939,14 +2785,14 @@ handle_start_search (void *cls, pr->query = sm->query; switch (type) { - case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: - case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: + case GNUNET_BLOCK_TYPE_DBLOCK: + case GNUNET_BLOCK_TYPE_IBLOCK: if (0 != memcmp (&sm->target, &all_zeros, sizeof (GNUNET_HashCode))) pr->target_pid = GNUNET_PEER_intern ((const struct GNUNET_PeerIdentity*) &sm->target); break; - case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: + case GNUNET_BLOCK_TYPE_SBLOCK: pr->namespace = (GNUNET_HashCode*) &pr[1]; memcpy (&pr[1], &sm->target, sizeof (GNUNET_HashCode)); break; @@ -2957,8 +2803,8 @@ handle_start_search (void *cls, &sm->query, pr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - if (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) - type = GNUNET_DATASTORE_BLOCKTYPE_ANY; /* get on-demand blocks too! */ + if (type == GNUNET_BLOCK_TYPE_DBLOCK) + type = GNUNET_BLOCK_TYPE_ANY; /* get on-demand blocks too! */ pr->drq = GNUNET_FS_drq_get (&sm->query, type, &process_local_reply, diff --git a/src/fs/gnunet-service-fs_drq.c b/src/fs/gnunet-service-fs_drq.c index 8edcacf3d..fde34187a 100644 --- a/src/fs/gnunet-service-fs_drq.c +++ b/src/fs/gnunet-service-fs_drq.c @@ -83,7 +83,7 @@ struct DatastoreRequestQueue /** * Datastore entry type we are doing the 'get' for. */ - uint32_t type; + enum GNUNET_BLOCK_Type type; /** * Is this request at the head of the queue irrespective of its @@ -154,7 +154,7 @@ get_iterator (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -345,7 +345,7 @@ shutdown_task (void *cls, */ struct DatastoreRequestQueue * GNUNET_FS_drq_get (const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATASTORE_Iterator iter, void *iter_cls, struct GNUNET_TIME_Relative timeout, diff --git a/src/fs/gnunet-service-fs_drq.h b/src/fs/gnunet-service-fs_drq.h index ec86b99be..08a355370 100644 --- a/src/fs/gnunet-service-fs_drq.h +++ b/src/fs/gnunet-service-fs_drq.h @@ -54,7 +54,7 @@ struct DatastoreRequestQueue; */ struct DatastoreRequestQueue * GNUNET_FS_drq_get (const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATASTORE_Iterator iter, void *iter_cls, struct GNUNET_TIME_Relative timeout, diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index 3095092b8..a5ac0dda3 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -539,7 +539,7 @@ int GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -641,7 +641,7 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, key, nsize, edata, - GNUNET_DATASTORE_BLOCKTYPE_DBLOCK, + GNUNET_BLOCK_TYPE_DBLOCK, priority, anonymity, expiration, diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h index 9749b42a0..37df50042 100644 --- a/src/fs/gnunet-service-fs_indexing.h +++ b/src/fs/gnunet-service-fs_indexing.h @@ -26,6 +26,7 @@ #ifndef GNUNET_SERVICE_FS_INDEXING_H #define GNUNET_SERVICE_FS_INDEXING_H +#include "gnunet_block_lib.h" #include "gnunet_core_service.h" #include "gnunet_datastore_service.h" #include "gnunet_peer_lib.h" @@ -57,7 +58,7 @@ int GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h index 3bd76df32..e0866416d 100644 --- a/src/include/gnunet_datacache_lib.h +++ b/src/include/gnunet_datacache_lib.h @@ -32,6 +32,7 @@ #define GNUNET_DATACACHE_LIB_H #include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" #ifdef __cplusplus extern "C" @@ -86,7 +87,7 @@ typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, const GNUNET_HashCode * key, uint32_t size, const char *data, - uint32_t type); + enum GNUNET_BLOCK_Type type); /** @@ -105,7 +106,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, const GNUNET_HashCode * key, uint32_t size, const char *data, - unsigned int type, + enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time); @@ -123,7 +124,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, unsigned int GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, const GNUNET_HashCode * key, - unsigned int type, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls); diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 2bf0f8f34..bf18860a6 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -32,6 +32,7 @@ #define GNUNET_DATASTORE_SERVICE_H #include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" #ifdef __cplusplus extern "C" @@ -41,43 +42,6 @@ extern "C" #endif #endif -/** - * Any type of block, used as a wildcard when searching. Should - * never be attached to a specific block. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_ANY 0 - -/** - * Data block (leaf) in the CHK tree. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_DBLOCK 1 - -/** - * Inner block in the CHK tree. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_IBLOCK 2 - -/** - * Type of a block representing a keyword search result. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_KBLOCK 3 - -/** - * Type of a block that is used to advertise content in a namespace. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_SBLOCK 4 - -/** - * Type of a block representing a block to be encoded on demand from disk. - * Should never appear on the network directly. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND 5 - -/** - * Type of a block that is used to advertise a namespace. - */ -#define GNUNET_DATASTORE_BLOCKTYPE_NBLOCK 6 - /** * Handle to the datastore service. @@ -171,7 +135,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, @@ -239,7 +203,7 @@ typedef void (*GNUNET_DATASTORE_Iterator) (void *cls, const GNUNET_HashCode * key, uint32_t size, const void *data, - uint32_t type, + enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute @@ -264,7 +228,7 @@ typedef void (*GNUNET_DATASTORE_Iterator) (void *cls, void GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h, const GNUNET_HashCode * key, - uint32_t type, + enum GNUNET_BLOCK_Type type, GNUNET_DATASTORE_Iterator iter, void *iter_cls, struct GNUNET_TIME_Relative timeout); diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index d14606d70..dcbe3dc98 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -147,7 +147,7 @@ typedef void (*GNUNET_DHT_GetIterator)(void *cls, * @param handle handle to the DHT service * @param timeout timeout for this request to be sent to the * service (this is NOT a timeout for receiving responses) - * @param type expected type of the response object (GNUNET_DATASTORE_BLOCKTYPE_*) + * @param type expected type of the response object (GNUNET_BLOCK_TYPE_*) * @param key the key to look up * @param iter function to call on each result * @param iter_cls closure for iter diff --git a/src/migration/Makefile.am b/src/migration/Makefile.am new file mode 100644 index 000000000..2bc4a1d2d --- /dev/null +++ b/src/migration/Makefile.am @@ -0,0 +1,34 @@ +INCLUDES = -I$(top_srcdir)/src/include + +if MINGW + WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols +endif + +if USE_COVERAGE + AM_CFLAGS = --coverage -O0 + XLIBS = -lgcov +endif + +bin_PROGRAMS = \ + gnunet-daemon-migration + +gnunet_daemon_migration_SOURCES = \ + gnunet-daemon-migration.c +gnunet_daemon_migration_LDADD = \ + $(top_builddir)/src/datastore/libgnunetdatastore.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/core/libgnunetcore.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) + +check_PROGRAMS = test_gnunet_daemon_migration +#TESTS = $(check_PROGRAMS) + +test_gnunet_daemon_migration_SOURCES = \ + test_gnunet_daemon_migration.c +test_gnunet_daemon_migration_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/util/libgnunetutil.la + +EXTRA_DIST = \ + test_gnunet_daemon_migration_data.conf diff --git a/src/migration/gnunet-daemon-migration b/src/migration/gnunet-daemon-migration new file mode 100755 index 000000000..ff6f5cea1 --- /dev/null +++ b/src/migration/gnunet-daemon-migration @@ -0,0 +1,148 @@ +#! /bin/sh + +# gnunet-daemon-migration - temporary wrapper script for .libs/gnunet-daemon-migration +# Generated by ltmain.sh (GNU libtool) 2.2.6b Debian-2.2.6b-2 +# +# The gnunet-daemon-migration program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='/bin/sed -e 1s/^X//' +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="(cd /home/grothoff/svn/gnunet/src/migration; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/home/grothoff/bin:/home/grothoff/private/software/prevent-linux-4.3.0/bin/:/home/grothoff/bin:/usr/local/bin:/usr/bin:/bin:/usr/games; export PATH; gcc -fno-strict-aliasing -Wall -g -O0 -o \$progdir/\$file gnunet-daemon-migration.o -L/home/grothoff//lib ../../src/datastore/.libs/libgnunetdatastore.so ../../src/statistics/.libs/libgnunetstatistics.so ../../src/core/.libs/libgnunetcore.so ../../src/util/.libs/libgnunetutil.so -lm -ldl -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/datastore/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/statistics/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/core/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/util/.libs -Wl,-rpath -Wl,/home/grothoff/lib)" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.2.6b' + notinst_deplibs=' ../../src/datastore/libgnunetdatastore.la ../../src/statistics/libgnunetstatistics.la ../../src/core/libgnunetcore.la ../../src/util/libgnunetutil.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + ECHO="echo" + file="$0" + # Make sure echo works. + if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then + # Yippee, $ECHO works! + : + else + # Restart under the correct shell, and then maybe $ECHO will work. + exec /bin/sh "$0" --no-reexec ${1+"$@"} + fi + fi + + # Find the directory that this script lives in. + thisdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` + done + + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "X$thisdir" | $Xsed -e 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program=lt-'gnunet-daemon-migration' + progdir="$thisdir/.libs" + + if test ! -f "$progdir/$program" || + { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ + test "X$file" != "X$progdir/$program"; }; then + + file="$$-$program" + + if test ! -d "$progdir"; then + mkdir "$progdir" + else + rm -f "$progdir/$file" + fi + + # relink executable if necessary + if test -n "$relink_command"; then + if relink_command_output=`eval $relink_command 2>&1`; then : + else + echo "$relink_command_output" >&2 + rm -f "$progdir/$file" + exit 1 + fi + fi + + mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || + { rm -f "$progdir/$program"; + mv -f "$progdir/$file" "$progdir/$program"; } + rm -f "$progdir/$file" + fi + + if test -f "$progdir/$program"; then + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + echo "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/src/migration/gnunet-daemon-migration.c b/src/migration/gnunet-daemon-migration.c new file mode 100644 index 000000000..14f7461f6 --- /dev/null +++ b/src/migration/gnunet-daemon-migration.c @@ -0,0 +1,377 @@ +/* + This file is part of GNUnet. + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file migration/gnunet-daemon-migration.c + * @brief migrating (file-sharing) content through the network; this + * daemon is only responsible for pushing content out (not for + * processing inbound messages) + * @author Christian Grothoff + */ +#include +#include "platform.h" +#include "../fs/fs.h" +#include "gnunet_constants.h" +#include "gnunet_core_service.h" +#include "gnunet_datastore_service.h" +#include "gnunet_protocols.h" +#include "gnunet_statistics_service.h" +#include "gnunet_util_lib.h" + + +#define DEBUG_MIGRATION GNUNET_YES + +/** + * Information we keep per peer. + */ +struct Peer +{ + /** + * Last time we migrated data to this peer. + */ + struct GNUNET_TIME_Absolute last_migration; + +}; + + +/** + * Our scheduler. + */ +static struct GNUNET_SCHEDULER_Handle *sched; + +/** + * Our configuration. + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +/** + * Handle to the core API. + */ +static struct GNUNET_CORE_Handle *handle; + +/** + * Handle for reporting statistics. + */ +static struct GNUNET_STATISTICS_Handle *stats; + +/** + * Handle for the core service. +*/ +static struct GNUNET_CORE_Handle *handle; + +/** + * Handle to the datastore. + */ +static struct GNUNET_DATASTORE_Handle *datastore; + +/** + * Anonymity level for the current block. + */ +static unsigned int current_anonymity; + +/** + * Type of the current block. + */ +static enum GNUNET_BLOCK_Type current_type; + +/** + * Data of the current block (already encrypted). + */ +static char current_block[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + +/** + * Size of the current block. + */ +static size_t current_block_size; + +/** + * Key of the current block. + */ +static GNUNET_HashCode current_key; + +/** + * Task scheduled to receive content from the datastore (with some delay). + */ +static GNUNET_SCHEDULER_TaskIdentifier get_task; + + +/** + * Select a peer for transmitting the current block to. + */ +static void +select_peer () +{ + /* FIXME: select a peer for transmission... */ +} + + +/** + * Method called whenever a peer connects. + * + * @param cls closure + * @param peer peer identity this notification is about + * @param latency reported latency of the connection with 'other' + * @param distance reported distance (DV) to 'other' + */ +static void +connect_notify (void *cls, + const struct + GNUNET_PeerIdentity * peer, + struct GNUNET_TIME_Relative latency, + uint32_t distance) +{ + /* FIXME: track peer */ +} + + +/** + * Method called whenever a peer disconnects. + * + * @param cls closure + * @param peer peer identity this notification is about + */ +static void +disconnect_notify (void *cls, + const struct + GNUNET_PeerIdentity * peer) +{ + /* FIXME: untrack peer */ +} + + +/** + * Ask datastore for more content. + * @param cls closure + * @param tc scheduler context + */ +static void +get_content (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc); + + +/** + * An iterator over a set of items stored in the datastore. + * + * @param cls closure + * @param key key for the content + * @param size number of bytes in data + * @param data content stored + * @param type type of the content + * @param priority priority of the content + * @param anonymity anonymity-level for the content + * @param expiration expiration time for the content + * @param uid unique identifier for the datum; + * maybe 0 if no unique identifier is available + */ +static void +content_processor (void *cls, + const GNUNET_HashCode * key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + struct GNUNET_TIME_Absolute + expiration, uint64_t uid) +{ + if (key != NULL) + { + memcpy (current_block, data, size); + current_block_size = size; + current_type = type; + current_anonymity = anonymity; + current_key = *key; + return; + } + if (current_block_size == 0) + { + get_task = GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_UNIT_MINUTES, + &get_content, + NULL); + return; + } + if (current_type == GNUNET_BLOCK_TYPE_ONDEMAND) + { + /* FIXME: do on-demand encoding... */ + return; + } + select_peer (); +} + + +/** + * Ask datastore for more content. + * @param cls closure + * @param tc scheduler context + */ +static void +get_content (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + get_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_DATASTORE_get_random (datastore, + &content_processor, + NULL, + GNUNET_CONSTANTS_SERVICE_TIMEOUT); +} + + +/** + * Function called after GNUNET_CORE_connect has succeeded + * (or failed for good). + * + * @param cls closure + * @param server handle to the server, NULL if we failed + * @param my_id ID of this peer, NULL if we failed + * @param publicKey public key of this peer, NULL if we failed + */ +static void +core_init (void *cls, + struct GNUNET_CORE_Handle * server, + const struct GNUNET_PeerIdentity * + my_id, + const struct + GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * + publicKey) +{ + handle = server; + if (datastore != NULL) + get_task = GNUNET_SCHEDULER_add_now (sched, + &get_content, + NULL); +} + + +/** + * Last task run during shutdown. Disconnects us from + * the core. + * + * @param cls unused, NULL + * @param tc scheduler context + */ +static void +cleaning_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (get_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (sched, + get_task); + get_task = GNUNET_SCHEDULER_NO_TASK; + } + if (handle != NULL) + { + GNUNET_CORE_disconnect (handle); + handle = NULL; + } + if (datastore != NULL) + { + GNUNET_DATASTORE_disconnect (datastore, GNUNET_NO); + datastore = NULL; + } + if (stats != NULL) + { + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); + stats = NULL; + } +} + + +/** + * Main function that will be run. + * + * @param cls closure + * @param s the scheduler to use + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param c configuration + */ +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle * s, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle * c) +{ + struct GNUNET_CORE_MessageHandler handlers[] = + { + { NULL, 0, 0 } + }; + sched = s; + cfg = c; + stats = GNUNET_STATISTICS_create (sched, "topology", cfg); + handle = GNUNET_CORE_connect (sched, + cfg, + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, + &core_init, + &connect_notify, + &disconnect_notify, + NULL, GNUNET_NO, + NULL, GNUNET_NO, + handlers); + datastore = GNUNET_DATASTORE_connect (cfg, sched); + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &cleaning_task, NULL); + if ( (NULL == handle) || + (NULL == datastore) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to connect to `%s' service.\n"), + (NULL == handle) ? "core" : "datastore"); + GNUNET_SCHEDULER_shutdown (sched); + return; + } +} + + +/** + * gnunet-daemon-topology command line options. + */ +static struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END +}; + + +/** + * The main function for the topology 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) +{ + int ret; + + ret = (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "migration", + _("Content migration for anonymous file-sharing"), + options, + &run, NULL)) ? 0 : 1; + return ret; +} + +/* end of gnunet-daemon-migration.c */ diff --git a/src/topology/test_gnunet_service_topology.c b/src/migration/test_gnunet_daemon_migration.c similarity index 94% rename from src/topology/test_gnunet_service_topology.c rename to src/migration/test_gnunet_daemon_migration.c index 5f0f5cc91..a3f699935 100644 --- a/src/topology/test_gnunet_service_topology.c +++ b/src/migration/test_gnunet_daemon_migration.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2009 Christian Grothoff (and other contributing authors) + (C) 2010 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 @@ -18,8 +18,8 @@ Boston, MA 02111-1307, USA. */ /** - * @file topology/test_gnunet_service_topology.c - * @brief testcase for topology maintenance code + * @file topology/test_gnunet_daemon_migration.c + * @brief testcase for content migration code */ #include "platform.h" #include "gnunet_testing_lib.h" @@ -166,7 +166,7 @@ main (int argc, char *argv[]) { int ret; - GNUNET_log_setup ("test-gnunet-service-topology", + GNUNET_log_setup ("test-gnunet-daemon-migration", #if VERBOSE "DEBUG", #else @@ -179,4 +179,4 @@ main (int argc, char *argv[]) return ret; } -/* end of test_gnunet_service_topology.c */ +/* end of test_gnunet_daemon_migration.c */ diff --git a/src/topology/test_gnunet_service_topology_data.conf b/src/migration/test_gnunet_daemon_migration_data.conf similarity index 100% rename from src/topology/test_gnunet_service_topology_data.conf rename to src/migration/test_gnunet_daemon_migration_data.conf diff --git a/src/topology/Makefile.am b/src/topology/Makefile.am index 88d8800a1..7bedd0910 100644 --- a/src/topology/Makefile.am +++ b/src/topology/Makefile.am @@ -21,15 +21,15 @@ gnunet_daemon_topology_LDADD = \ check_PROGRAMS = \ - test_gnunet_service_topology + test_gnunet_daemon_topology TESTS = $(check_PROGRAMS) -test_gnunet_service_topology_SOURCES = \ - test_gnunet_service_topology.c -test_gnunet_service_topology_LDADD = \ +test_gnunet_daemon_topology_SOURCES = \ + test_gnunet_daemon_topology.c +test_gnunet_daemon_topology_LDADD = \ $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la EXTRA_DIST = \ - test_gnunet_service_topology_data.conf + test_gnunet_daemon_topology_data.conf diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c new file mode 100644 index 000000000..b181e7b2c --- /dev/null +++ b/src/topology/test_gnunet_daemon_topology.c @@ -0,0 +1,182 @@ +/* + 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 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file topology/test_gnunet_daemon_topology.c + * @brief testcase for topology maintenance code + */ +#include "platform.h" +#include "gnunet_testing_lib.h" + +#define VERBOSE GNUNET_YES + +#define NUM_PEERS 2 + +/** + * How long until we give up on connecting the peers? + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) + +#define CONNECT_ATTEMPTS 3 + + +static int ok; + +static int peers_left; + +static int connect_left; + +static struct GNUNET_TESTING_PeerGroup *pg; + +static struct GNUNET_TESTING_Daemon *first; + +static struct GNUNET_TESTING_Daemon *last; + +static struct GNUNET_SCHEDULER_Handle *sched; + + +static void +clean_up_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_TESTING_daemons_stop (pg); + ok = 0; +} + + +static void +notify_connect_complete(void *cls, + const struct GNUNET_PeerIdentity *first, + const struct GNUNET_PeerIdentity *second, + const struct GNUNET_CONFIGURATION_Handle *first_cfg, + const struct GNUNET_CONFIGURATION_Handle *second_cfg, + struct GNUNET_TESTING_Daemon *first_daemon, + struct GNUNET_TESTING_Daemon *second_daemon, + const char *emsg) +{ + if (NULL != emsg) + { + fprintf (stderr, + "Failed to connect two peers: %s\n", + emsg); + GNUNET_TESTING_daemons_stop (pg); + GNUNET_assert (0); + return; + } + connect_left--; + if (connect_left == 0) + { + /* FIXME: check that topology adds a few more links + in addition to those that were seeded */ + /* For now, sleep so we can have the daemon do some work */ + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + &clean_up_task, + NULL); + } +} + + +static void my_cb(void *cls, + const struct GNUNET_PeerIdentity *id, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Daemon *d, + const char *emsg) +{ + GNUNET_assert (id != NULL); + peers_left--; + if (first == NULL) + { + connect_left = NUM_PEERS; + first = d; + last = d; + return; + } + GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS, + ¬ify_connect_complete, + NULL); + if (peers_left == 0) + { + /* close circle */ + GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS, + ¬ify_connect_complete, + NULL); + } +} + + +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle *s, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + sched = s; + ok = 1; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting daemons.\n"); +#endif + peers_left = NUM_PEERS; + pg = GNUNET_TESTING_daemons_start (sched, cfg, + peers_left, + &my_cb, NULL, NULL, NULL, NULL); + GNUNET_assert (pg != NULL); +} + +static int +check () +{ + char *const argv[] = { "test-testing", + "-c", + "test_gnunet_daemon_topology_data.conf", +#if VERBOSE + "-L", "DEBUG", +#endif + NULL + }; + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, + argv, "test-gnunet-daemon-topology", "nohelp", + options, &run, &ok); + return ok; +} + +int +main (int argc, char *argv[]) +{ + int ret; + + GNUNET_log_setup ("test-gnunet-daemon-topology", +#if VERBOSE + "DEBUG", +#else + "WARNING", +#endif + NULL); + ret = check (); + sleep (1); /* FIXME: needed? */ + GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology"); + return ret; +} + +/* end of test_gnunet_daemon_topology.c */ diff --git a/src/topology/test_gnunet_daemon_topology_data.conf b/src/topology/test_gnunet_daemon_topology_data.conf new file mode 100644 index 000000000..d920e9e88 --- /dev/null +++ b/src/topology/test_gnunet_daemon_topology_data.conf @@ -0,0 +1,37 @@ +[PATHS] +SERVICEHOME = /tmp/test-gnunet-topology/ +# DEFAULTCONFIG = test_gnunet_service_topology_data.conf + +[resolver] +PORT = 2664 + +[transport] +PORT = 2665 +PLUGINS = tcp +# DEBUG = YES +#PREFIX = xterm -e xterm -T transport -e gdb -x cmd --args +#PREFIX = valgrind --tool=memcheck --log-file=logs%p + +[arm] +PORT = 2666 +DEFAULTSERVICES = peerinfo transport core topology + +[statistics] +PORT = 2667 + +[transport-tcp] +PORT = 2668 + +[peerinfo] +PORT = 2669 + +[core] +PORT = 2670 +# DEBUG = YES + +[topology] +# DEBUG = YES +#PREFIX = valgrind --tool=memcheck + +[testing] +WEAKRANDOM = YES diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index daf676d01..e6496e7ac 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c @@ -265,7 +265,8 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args, _("gethostbyname() could not lookup IP address: %s\n"), hstrerror (h_errno)); #endif - GNUNET_break(0); + fprintf (stderr, + "System seems to be off-line, will not run all DNS tests\n"); return; } -- 2.25.1