From 57479e3227639e2e7a6eda9c31ca6b65528d3739 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 14 Apr 2010 08:44:41 +0000 Subject: [PATCH] --- src/hostlist/hostlist-client.c | 69 +++++++++++++++++++++++++++----- src/hostlist/hostlist-client.h | 2 + src/hostlist/learning_peer1.conf | 2 +- src/hostlist/learning_peer2.conf | 1 + 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index a5cc03912..e11595352 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -32,6 +32,8 @@ #include "gnunet_transport_service.h" #include "gnunet-daemon-hostlist.h" #include +#include "gnunet_common.h" +#include "gnunet_bio_lib.h" #define DEBUG_HOSTLIST_CLIENT GNUNET_YES @@ -754,15 +756,31 @@ advertisement_handler (void *cls, const struct GNUNET_HOSTLIST_ADV_Message * incoming = (const struct GNUNET_HOSTLIST_ADV_Message *) message; memcpy ( uri, &incoming[1], uri_size ); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist client recieved advertisement from peer '%4s' containing URI %s\n", GNUNET_i2s (peer), uri ); - - hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); - + "Hostlist client recieved advertisement from '%s' containing URI %s\n", GNUNET_i2s (peer), uri ); /* search in map for peer identity */ - if ( NULL != hostlist_hashmap) + GNUNET_HashCode * peer_ident_hash = (GNUNET_HashCode * ) &(peer->hashPubKey); + if ( GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (hostlist_hashmap, peer_ident_hash) ) + { + if ( MAX_NUMBER_HOSTLISTS > GNUNET_CONTAINER_multihashmap_size (hostlist_hashmap) ) + { + /* Entries available, add hostlist to hashmap */ + } + else + { + /* No free entries available, replace existing entry */ + } + } + else + { + /* hostlist entry already existing in hashmap */ + /* compare uri to new uri ? */ + /* update recieved date (vs using last download time to check reachability)? */ + } + /* GNUNET_CONTAINER_multihashmap_contains( hostlist_hashmap, )*/ /* if it is not existing in map, create new a hostlist */ + hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); hostlist->peer = (*peer); hostlist->hello_count = 0; hostlist->hostlist_uri = GNUNET_malloc ( uri_size); @@ -814,13 +832,13 @@ process_stat (void *cls, */ static int load_hostlist_file () { - char *servers; + char *filename; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "HOSTLISTFILE", - &servers)) + &filename)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"), @@ -828,8 +846,23 @@ static int load_hostlist_file () return GNUNET_SYSERR; } - /* add code to write hostlists to file using bio */ + struct GNUNET_BIO_ReadHandle * rh = GNUNET_BIO_read_open (filename); + if ( NULL == rh) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + ("Could not open file %s for reading to load hostlists\n"), filename); + return GNUNET_SYSERR; + } + + /* add code to read hostlists to file using bio */ + char * buffer = GNUNET_malloc (100 * sizeof (char)); + GNUNET_BIO_read_string (rh, NULL , &buffer, 100); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + ("Read from file %s : %s \n"), filename, buffer); + if ( GNUNET_OK != GNUNET_BIO_read_close ( rh , &buffer) ) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + ("Error while closing file %s\n"), filename); return GNUNET_OK; } @@ -839,13 +872,13 @@ static int load_hostlist_file () */ static int save_hostlist_file () { - char *servers; + char *filename; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "HOSTLISTFILE", - &servers)) + &filename)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"), @@ -853,8 +886,22 @@ static int save_hostlist_file () return GNUNET_SYSERR; } + struct GNUNET_BIO_WriteHandle * wh = GNUNET_BIO_write_open (filename); + if ( NULL == wh) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + ("Could not open file %s for writing to save hostlists\n"), + filename); + return GNUNET_SYSERR; + } + /* add code to write hostlists to file using bio */ + GNUNET_BIO_write_string ( wh, "DUMMY TEXT"); + if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + ("Error while closing file %s\n"), + filename); return GNUNET_OK; } @@ -897,7 +944,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, learning = learn; if ( learning ) { - hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create (16); + hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create ( MAX_NUMBER_HOSTLISTS ); } load_hostlist_file (); diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h index 26cd73b52..054a1c589 100644 --- a/src/hostlist/hostlist-client.h +++ b/src/hostlist/hostlist-client.h @@ -32,6 +32,8 @@ #include "gnunet_util_lib.h" #include "gnunet_time_lib.h" +#define MAX_NUMBER_HOSTLISTS 16 + /* * a single hostlist obtained by hostlist advertisements */ diff --git a/src/hostlist/learning_peer1.conf b/src/hostlist/learning_peer1.conf index 51ac2caae..fe02e1964 100644 --- a/src/hostlist/learning_peer1.conf +++ b/src/hostlist/learning_peer1.conf @@ -38,7 +38,7 @@ HTTPPORT = 12980 SERVERS = http://localhost:12981/ OPTIONS = -b -p -e -a DEBUG = YES -HOSTLISTFILE = hostlists.file +HOSTLISTFILE = hostlists_peer1.file #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist diff --git a/src/hostlist/learning_peer2.conf b/src/hostlist/learning_peer2.conf index 6d109455e..f4419f61d 100644 --- a/src/hostlist/learning_peer2.conf +++ b/src/hostlist/learning_peer2.conf @@ -38,6 +38,7 @@ HTTPPORT = 12981 SERVERS = http://localhost:12980/ OPTIONS = -b -p -e DEBUG = YES +HOSTLISTFILE = hostlists_peer2.file #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist [topology] -- 2.25.1