*/
static unsigned int connection_count;
+/**
+ * Set if the user allows us to learn about new hostlists
+ * from the network.
+ */
+static int learning;
+
/**
* At what time MUST the current hostlist request be done?
*/
static struct GNUNET_TIME_Absolute end_time;
+/**
+ * Hashmap of PeerIdentities to "struct GNUNET_Hostlist"
+ * (for fast lookup). NULL until the library
+ * is actually being used.
+ */
+static struct GNUNET_CONTAINER_MultiHashMap *hostlist_hashmap;
/**
* Process downloaded bits by calling callback on each HELLO.
struct GNUNET_TIME_Relative latency,
uint32_t distance)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client recieved advertisement, checking message: %s\n");
+ if ( !learning )
+ return GNUNET_NO;
+
int size = ntohs (message->size);
int uri_size = size - sizeof ( struct GNUNET_HOSTLIST_ADV_Message );
- int type = ntohs (message->type);
char * uri = GNUNET_malloc ( uri_size );
+ struct GNUNET_Hostlist * hostlist;
- if ( type != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT)
+ if ( ntohs (message->type) != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT)
return GNUNET_NO;
const struct GNUNET_HOSTLIST_ADV_Message * incoming = (const struct GNUNET_HOSTLIST_ADV_Message *) message;
- //struct GNUNET_HOSTLIST_ADV_Message * msg = message;
memcpy ( uri, &incoming[1], uri_size );
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client recieved advertisement uri: %s\n", uri);
- #if DEBUG_HOSTLIST_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client recieved advertisement message, type %u, message size %u, headersize %u, uri length %u, uri: %s\n",type,size,sizeof( struct GNUNET_HOSTLIST_ADV_Message ),uri_size,uri);
-#endif
+ "Hostlist client recieved advertisement from peer '%4s' containing URI %s\n", GNUNET_i2s (peer), uri );
+
+ hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
+
+ /* 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->peer = (*peer);
+ hostlist->hello_count = 0;
+ hostlist->hostlist_uri = GNUNET_malloc ( uri_size);
+ memcpy ( hostlist->hostlist_uri, &incoming[1], uri_size );
+ hostlist->time_creation = GNUNET_TIME_absolute_get();
+ hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero();
- return GNUNET_YES;
+ return GNUNET_YES;
}
/**
"HOSTLISTFILE", "HOSTLIST");
return GNUNET_SYSERR;
}
+
+ /* add code to write hostlists to file using bio */
+
return GNUNET_OK;
}
&servers))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified in `%s' configuration, cannot save hostlist to file.\n"),
+ _("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"),
"HOSTLISTFILE", "HOSTLIST");
return GNUNET_SYSERR;
}
+ /* add code to write hostlists to file using bio */
return GNUNET_OK;
}
struct GNUNET_STATISTICS_Handle *st,
GNUNET_CORE_ConnectEventHandler *ch,
GNUNET_CORE_DisconnectEventHandler *dh,
- GNUNET_CORE_MessageCallback *msgh)
+ GNUNET_CORE_MessageCallback *msgh,
+ int learn)
{
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
{
*dh = &disconnect_handler;
*msgh = &advertisement_handler;
+ learning = learn;
+ if ( learning )
+ {
+ hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create (16);
+ }
load_hostlist_file ();
GNUNET_STATISTICS_get (stats,
#endif
save_hostlist_file ();
+ if ( learning )
+ {
+ GNUNET_CONTAINER_multihashmap_destroy ( hostlist_hashmap );
+ }
+
if (current_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (sched,
#include "gnunet_core_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_util_lib.h"
+#include "gnunet_time_lib.h"
+
+/*
+ * a single hostlist obtained by hostlist advertisements
+ */
+struct GNUNET_Hostlist
+{
+
+ struct GNUNET_PeerIdentity peer;
+ char * hostlist_uri;
+ unsigned long hello_count;
+ unsigned long times_used;
+ struct GNUNET_TIME_Absolute time_creation;
+ struct GNUNET_TIME_Absolute time_last_usage;
+ uint64_t quality;
+};
/**
* @param ch set to handler for connect notifications
* @param dh set to handler for disconnect notifications
* @param msgh set to handler for message handler notifications
+ * @param learn set if client is learning new hostlists
* @return GNUNET_OK on success
*/
int
struct GNUNET_STATISTICS_Handle *st,
GNUNET_CORE_ConnectEventHandler *ch,
GNUNET_CORE_DisconnectEventHandler *dh,
- GNUNET_CORE_MessageCallback *msgh);
+ GNUNET_CORE_MessageCallback *msgh,
+ int learn);
/**
*/
static int advertising;
+/*
+ * How many times was the hostlist advertised?
+ */
+static uint64_t hostlist_adv_count = 0;
+
+/*
+ * Buffer for the hostlist address
+ */
+char hostlist_uri[255];
+
+
/**
* Task that will produce a new response object.
*/
update_response (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc);
+
/**
* Function that assembles our response.
*/
return MHD_queue_response (connection, MHD_HTTP_OK, response);
}
-/*
- * Buffer for the hostlist address
- */
-char hostlist_uri[255];
-
/**
* Handler called by core when core is ready to transmit message
* @param cls closure
return transmission_size;
}
+ hostlist_adv_count++;
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop("# hostlist advertisements send"),
+ hostlist_adv_count,
+ GNUNET_YES);
+
GNUNET_free (adv_message );
return size;
}