[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10903 - gnunet/src/hostlist
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10903 - gnunet/src/hostlist |
Date: |
Wed, 14 Apr 2010 10:44:41 +0200 |
Author: wachs
Date: 2010-04-14 10:44:41 +0200 (Wed, 14 Apr 2010)
New Revision: 10903
Modified:
gnunet/src/hostlist/hostlist-client.c
gnunet/src/hostlist/hostlist-client.h
gnunet/src/hostlist/learning_peer1.conf
gnunet/src/hostlist/learning_peer2.conf
Log:
Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c 2010-04-14 08:32:48 UTC (rev
10902)
+++ gnunet/src/hostlist/hostlist-client.c 2010-04-14 08:44:41 UTC (rev
10903)
@@ -32,6 +32,8 @@
#include "gnunet_transport_service.h"
#include "gnunet-daemon-hostlist.h"
#include <curl/curl.h>
+#include "gnunet_common.h"
+#include "gnunet_bio_lib.h"
#define DEBUG_HOSTLIST_CLIENT GNUNET_YES
@@ -754,15 +756,31 @@
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 client recieved advertisement from '%s' containing URI
%s\n", GNUNET_i2s (peer), uri );
- hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
+ /* search in map for peer identity */
+ 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)? */
+ }
-
- /* search in map for peer identity */
- if ( NULL != hostlist_hashmap)
/* 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 @@
*/
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 @@
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 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 @@
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 @@
learning = learn;
if ( learning )
{
- hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create (16);
+ hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create (
MAX_NUMBER_HOSTLISTS );
}
load_hostlist_file ();
Modified: gnunet/src/hostlist/hostlist-client.h
===================================================================
--- gnunet/src/hostlist/hostlist-client.h 2010-04-14 08:32:48 UTC (rev
10902)
+++ gnunet/src/hostlist/hostlist-client.h 2010-04-14 08:44:41 UTC (rev
10903)
@@ -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
*/
Modified: gnunet/src/hostlist/learning_peer1.conf
===================================================================
--- gnunet/src/hostlist/learning_peer1.conf 2010-04-14 08:32:48 UTC (rev
10902)
+++ gnunet/src/hostlist/learning_peer1.conf 2010-04-14 08:44:41 UTC (rev
10903)
@@ -38,7 +38,7 @@
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
Modified: gnunet/src/hostlist/learning_peer2.conf
===================================================================
--- gnunet/src/hostlist/learning_peer2.conf 2010-04-14 08:32:48 UTC (rev
10902)
+++ gnunet/src/hostlist/learning_peer2.conf 2010-04-14 08:44:41 UTC (rev
10903)
@@ -38,6 +38,7 @@
SERVERS = http://localhost:12980/
OPTIONS = -b -p -e
DEBUG = YES
+HOSTLISTFILE = hostlists_peer2.file
#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
[topology]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10903 - gnunet/src/hostlist,
gnunet <=