/**
* A single hostlist obtained by hostlist advertisements
*/
-struct GNUNET_Hostlist
+struct Hostlist
{
- struct GNUNET_Hostlist * prev;
+ struct Hostlist * prev;
- struct GNUNET_Hostlist * next;
+ struct Hostlist * next;
/**
* URI where hostlist can be obtained
static struct GNUNET_TIME_Absolute end_time;
/* DLL_? */
-static struct GNUNET_Hostlist * dll_head;
+static struct Hostlist * dll_head;
/* DLL_? */
-static struct GNUNET_Hostlist * dll_tail;
+static struct Hostlist * dll_tail;
/* DLL_? */
static unsigned int dll_size;
static int
dll_contains (const char * uri)
{
- struct GNUNET_Hostlist * pos;
+ struct Hostlist * pos;
pos = dll_head;
while (pos != NULL)
/* DLL_? */
-static struct GNUNET_Hostlist *
+static struct Hostlist *
dll_get_lowest_quality ( )
{
- struct GNUNET_Hostlist * pos;
- struct GNUNET_Hostlist * lowest;
+ struct Hostlist * pos;
+ struct Hostlist * lowest;
if (dll_size == 0)
return NULL;
#if DUMMY
/* TO BE REMOVED later */
-static void dll_insert ( struct GNUNET_Hostlist *hostlist)
+static void dll_insert ( struct Hostlist *hostlist)
{
GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist);
dll_size++;
{
/* test */
- struct GNUNET_Hostlist * hostlist1;
- hostlist1 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
+ struct Hostlist * hostlist1;
+ hostlist1 = GNUNET_malloc ( sizeof (struct Hostlist) );
char * str = "uri_1";
GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist1->peer.hashPubKey);
"Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist1->peer.hashPubKey) , hostlist1->hostlist_uri, hostlist1->quality);
dll_insert (hostlist1);
- struct GNUNET_Hostlist * hostlist2;
- hostlist2 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
+ struct Hostlist * hostlist2;
+ hostlist2 = GNUNET_malloc ( sizeof (struct Hostlist) );
char * str2 = "uri_2";
GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist2->peer.hashPubKey);
"Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist2->peer.hashPubKey) , hostlist2->hostlist_uri, hostlist2->quality);
dll_insert (hostlist2);
- struct GNUNET_Hostlist * hostlist3;
- hostlist3 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
+ struct Hostlist * hostlist3;
+ hostlist3 = GNUNET_malloc ( sizeof (struct Hostlist) );
char * str3 = "uri_3";
GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist3->peer.hashPubKey);
dll_insert (hostlist3);
- struct GNUNET_Hostlist * hostlist4;
- hostlist4 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
+ struct Hostlist * hostlist4;
+ hostlist4 = GNUNET_malloc ( sizeof (struct Hostlist) );
char * str4 = "uri_4";
GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist4->peer.hashPubKey);
size_t uri_size;
const struct GNUNET_MessageHeader * incoming;
const char *uri;
- struct GNUNET_Hostlist * hostlist;
+ struct Hostlist * hostlist;
GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
size = ntohs (message->size);
uri);
if (GNUNET_YES != dll_contains (uri))
return GNUNET_OK;
- hostlist = GNUNET_malloc (sizeof (struct GNUNET_Hostlist) + uri_size);
+ hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
hostlist->peer = *peer;
hostlist->hostlist_uri = (const char*) &hostlist[1];
memcpy (&hostlist[1], uri, uri_size);
/* No free entries available, replace existing entry */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Removing lowest quality entry\n" );
- struct GNUNET_Hostlist * lowest_quality = dll_get_lowest_quality();
+ struct Hostlist * lowest_quality = dll_get_lowest_quality();
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlist with URI `%s' has the worst quality of all with value %llu\n",
lowest_quality->hostlist_uri,
char *filename;
char *uri;
char *emsg;
+ struct Hostlist * hostlist;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
/* add code to read hostlists to file using bio */
uri = NULL;
+ uint32_t times_used;
+ uint32_t hellos_returned;
+ uint64_t quality;
+ uint64_t last_used;
+ uint64_t created;
+
while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) &&
-#if 0
(GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) &&
- (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used.value)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created.value)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality))
-#else
- (1)
-#endif
-)
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) )
{
-#if 0
- hostlist = GNUNET_malloc (...);
-#endif
+ hostlist = GNUNET_malloc ( sizeof (struct Hostlist));
+ hostlist->hello_count = hellos_returned;
+ strcpy(hostlist->hostlist_uri, uri);
+ hostlist->quality = quality;
+ hostlist->time_creation.value = created;
+ hostlist->time_last_usage.value = last_used;
+ GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist);
+ dll_size++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri);
uri = NULL;
}
GNUNET_free_non_null (uri);
static void save_hostlist_file ()
{
char *filename;
- struct GNUNET_Hostlist *pos;
+ struct Hostlist *pos;
struct GNUNET_BIO_WriteHandle * wh;
int ok;
GNUNET_BIO_write_string (wh, pos->hostlist_uri)) ||
(GNUNET_OK !=
GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
- (0) )
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, pos->quality)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, pos->time_last_usage.value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, pos->time_creation.value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, pos->hello_count)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Error writing hostlist URIs to file `%s'\n"),