aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c2
-rw-r--r--src/hostlist/hostlist-client.c62
-rw-r--r--src/hostlist/hostlist-client.h20
-rw-r--r--src/hostlist/hostlist-server.c23
-rw-r--r--src/hostlist/learning_data.conf2
-rw-r--r--src/hostlist/learning_peer1.conf2
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_peer1.conf7
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_peer2.conf10
8 files changed, 103 insertions, 25 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 9a12c98f1..3622e0e8f 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -306,7 +306,7 @@ run (void *cls,
306 if (bootstrapping) 306 if (bootstrapping)
307 { 307 {
308 GNUNET_HOSTLIST_client_start (cfg, sched, stats, 308 GNUNET_HOSTLIST_client_start (cfg, sched, stats,
309 &client_ch, &client_dh, &client_adv_handler); 309 &client_ch, &client_dh, &client_adv_handler, learning);
310 } 310 }
311 if (provide_hostlist) 311 if (provide_hostlist)
312 { 312 {
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 78eb8acaa..a5cc03912 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -112,10 +112,22 @@ static int bogus_url;
112static unsigned int connection_count; 112static unsigned int connection_count;
113 113
114/** 114/**
115 * Set if the user allows us to learn about new hostlists
116 * from the network.
117 */
118static int learning;
119
120/**
115 * At what time MUST the current hostlist request be done? 121 * At what time MUST the current hostlist request be done?
116 */ 122 */
117static struct GNUNET_TIME_Absolute end_time; 123static struct GNUNET_TIME_Absolute end_time;
118 124
125/**
126 * Hashmap of PeerIdentities to "struct GNUNET_Hostlist"
127 * (for fast lookup). NULL until the library
128 * is actually being used.
129 */
130static struct GNUNET_CONTAINER_MultiHashMap *hostlist_hashmap;
119 131
120/** 132/**
121 * Process downloaded bits by calling callback on each HELLO. 133 * Process downloaded bits by calling callback on each HELLO.
@@ -728,28 +740,37 @@ advertisement_handler (void *cls,
728 struct GNUNET_TIME_Relative latency, 740 struct GNUNET_TIME_Relative latency,
729 uint32_t distance) 741 uint32_t distance)
730{ 742{
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 743 if ( !learning )
732 "Hostlist client recieved advertisement, checking message: %s\n"); 744 return GNUNET_NO;
745
733 int size = ntohs (message->size); 746 int size = ntohs (message->size);
734 int uri_size = size - sizeof ( struct GNUNET_HOSTLIST_ADV_Message ); 747 int uri_size = size - sizeof ( struct GNUNET_HOSTLIST_ADV_Message );
735 int type = ntohs (message->type);
736 char * uri = GNUNET_malloc ( uri_size ); 748 char * uri = GNUNET_malloc ( uri_size );
749 struct GNUNET_Hostlist * hostlist;
737 750
738 if ( type != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT) 751 if ( ntohs (message->type) != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT)
739 return GNUNET_NO; 752 return GNUNET_NO;
740 753
741 const struct GNUNET_HOSTLIST_ADV_Message * incoming = (const struct GNUNET_HOSTLIST_ADV_Message *) message; 754 const struct GNUNET_HOSTLIST_ADV_Message * incoming = (const struct GNUNET_HOSTLIST_ADV_Message *) message;
742 //struct GNUNET_HOSTLIST_ADV_Message * msg = message;
743 memcpy ( uri, &incoming[1], uri_size ); 755 memcpy ( uri, &incoming[1], uri_size );
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "Hostlist client recieved advertisement uri: %s\n", uri); 757 "Hostlist client recieved advertisement from peer '%4s' containing URI %s\n", GNUNET_i2s (peer), uri );
746 #if DEBUG_HOSTLIST_CLIENT 758
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 759 hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) );
748 "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); 760
749#endif
750 761
762 /* search in map for peer identity */
763 if ( NULL != hostlist_hashmap)
764 /* GNUNET_CONTAINER_multihashmap_contains( hostlist_hashmap, )*/
765 /* if it is not existing in map, create new a hostlist */
766 hostlist->peer = (*peer);
767 hostlist->hello_count = 0;
768 hostlist->hostlist_uri = GNUNET_malloc ( uri_size);
769 memcpy ( hostlist->hostlist_uri, &incoming[1], uri_size );
770 hostlist->time_creation = GNUNET_TIME_absolute_get();
771 hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero();
751 772
752 return GNUNET_YES; 773 return GNUNET_YES;
753} 774}
754 775
755/** 776/**
@@ -806,6 +827,9 @@ static int load_hostlist_file ()
806 "HOSTLISTFILE", "HOSTLIST"); 827 "HOSTLISTFILE", "HOSTLIST");
807 return GNUNET_SYSERR; 828 return GNUNET_SYSERR;
808 } 829 }
830
831 /* add code to write hostlists to file using bio */
832
809 return GNUNET_OK; 833 return GNUNET_OK;
810} 834}
811 835
@@ -824,11 +848,12 @@ static int save_hostlist_file ()
824 &servers)) 848 &servers))
825 { 849 {
826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 850 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
827 _("No `%s' specified in `%s' configuration, cannot save hostlist to file.\n"), 851 _("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"),
828 "HOSTLISTFILE", "HOSTLIST"); 852 "HOSTLISTFILE", "HOSTLIST");
829 return GNUNET_SYSERR; 853 return GNUNET_SYSERR;
830 } 854 }
831 855
856 /* add code to write hostlists to file using bio */
832 857
833 return GNUNET_OK; 858 return GNUNET_OK;
834} 859}
@@ -842,7 +867,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
842 struct GNUNET_STATISTICS_Handle *st, 867 struct GNUNET_STATISTICS_Handle *st,
843 GNUNET_CORE_ConnectEventHandler *ch, 868 GNUNET_CORE_ConnectEventHandler *ch,
844 GNUNET_CORE_DisconnectEventHandler *dh, 869 GNUNET_CORE_DisconnectEventHandler *dh,
845 GNUNET_CORE_MessageCallback *msgh) 870 GNUNET_CORE_MessageCallback *msgh,
871 int learn)
846{ 872{
847 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 873 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
848 { 874 {
@@ -868,6 +894,11 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
868 *dh = &disconnect_handler; 894 *dh = &disconnect_handler;
869 *msgh = &advertisement_handler; 895 *msgh = &advertisement_handler;
870 896
897 learning = learn;
898 if ( learning )
899 {
900 hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create (16);
901 }
871 load_hostlist_file (); 902 load_hostlist_file ();
872 903
873 GNUNET_STATISTICS_get (stats, 904 GNUNET_STATISTICS_get (stats,
@@ -893,6 +924,11 @@ GNUNET_HOSTLIST_client_stop ()
893#endif 924#endif
894 save_hostlist_file (); 925 save_hostlist_file ();
895 926
927 if ( learning )
928 {
929 GNUNET_CONTAINER_multihashmap_destroy ( hostlist_hashmap );
930 }
931
896 if (current_task != GNUNET_SCHEDULER_NO_TASK) 932 if (current_task != GNUNET_SCHEDULER_NO_TASK)
897 { 933 {
898 GNUNET_SCHEDULER_cancel (sched, 934 GNUNET_SCHEDULER_cancel (sched,
diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h
index 378a91996..26cd73b52 100644
--- a/src/hostlist/hostlist-client.h
+++ b/src/hostlist/hostlist-client.h
@@ -30,6 +30,22 @@
30#include "gnunet_core_service.h" 30#include "gnunet_core_service.h"
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet_time_lib.h"
34
35/*
36 * a single hostlist obtained by hostlist advertisements
37 */
38struct GNUNET_Hostlist
39{
40
41 struct GNUNET_PeerIdentity peer;
42 char * hostlist_uri;
43 unsigned long hello_count;
44 unsigned long times_used;
45 struct GNUNET_TIME_Absolute time_creation;
46 struct GNUNET_TIME_Absolute time_last_usage;
47 uint64_t quality;
48};
33 49
34 50
35/** 51/**
@@ -41,6 +57,7 @@
41 * @param ch set to handler for connect notifications 57 * @param ch set to handler for connect notifications
42 * @param dh set to handler for disconnect notifications 58 * @param dh set to handler for disconnect notifications
43 * @param msgh set to handler for message handler notifications 59 * @param msgh set to handler for message handler notifications
60 * @param learn set if client is learning new hostlists
44 * @return GNUNET_OK on success 61 * @return GNUNET_OK on success
45 */ 62 */
46int 63int
@@ -49,7 +66,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
49 struct GNUNET_STATISTICS_Handle *st, 66 struct GNUNET_STATISTICS_Handle *st,
50 GNUNET_CORE_ConnectEventHandler *ch, 67 GNUNET_CORE_ConnectEventHandler *ch,
51 GNUNET_CORE_DisconnectEventHandler *dh, 68 GNUNET_CORE_DisconnectEventHandler *dh,
52 GNUNET_CORE_MessageCallback *msgh); 69 GNUNET_CORE_MessageCallback *msgh,
70 int learn);
53 71
54 72
55/** 73/**
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index bfd9ae729..92e5756ad 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -109,6 +109,17 @@ struct HostSet
109 */ 109 */
110static int advertising; 110static int advertising;
111 111
112/*
113 * How many times was the hostlist advertised?
114 */
115static uint64_t hostlist_adv_count = 0;
116
117/*
118 * Buffer for the hostlist address
119 */
120char hostlist_uri[255];
121
122
112/** 123/**
113 * Task that will produce a new response object. 124 * Task that will produce a new response object.
114 */ 125 */
@@ -116,6 +127,7 @@ static void
116update_response (void *cls, 127update_response (void *cls,
117 const struct GNUNET_SCHEDULER_TaskContext *tc); 128 const struct GNUNET_SCHEDULER_TaskContext *tc);
118 129
130
119/** 131/**
120 * Function that assembles our response. 132 * Function that assembles our response.
121 */ 133 */
@@ -361,11 +373,6 @@ access_handler_callback (void *cls,
361 return MHD_queue_response (connection, MHD_HTTP_OK, response); 373 return MHD_queue_response (connection, MHD_HTTP_OK, response);
362} 374}
363 375
364/*
365 * Buffer for the hostlist address
366 */
367char hostlist_uri[255];
368
369/** 376/**
370 * Handler called by core when core is ready to transmit message 377 * Handler called by core when core is ready to transmit message
371 * @param cls closure 378 * @param cls closure
@@ -407,6 +414,12 @@ adv_transmit_ready ( void *cls, size_t size, void *buf)
407 return transmission_size; 414 return transmission_size;
408 } 415 }
409 416
417 hostlist_adv_count++;
418 GNUNET_STATISTICS_set (stats,
419 gettext_noop("# hostlist advertisements send"),
420 hostlist_adv_count,
421 GNUNET_YES);
422
410 GNUNET_free (adv_message ); 423 GNUNET_free (adv_message );
411 return size; 424 return size;
412} 425}
diff --git a/src/hostlist/learning_data.conf b/src/hostlist/learning_data.conf
index 3cfc9c27d..2b9f63a6e 100644
--- a/src/hostlist/learning_data.conf
+++ b/src/hostlist/learning_data.conf
@@ -13,4 +13,4 @@ BINARY = gnunet-daemon-hostlist
13OPTIONS = -b -e 13OPTIONS = -b -e
14SERVERS = http://gnunet.org:8080/ 14SERVERS = http://gnunet.org:8080/
15# proxy for downloading hostlists 15# proxy for downloading hostlists
16HTTP-PROXY = 16HTTP-PROXY = \ No newline at end of file
diff --git a/src/hostlist/learning_peer1.conf b/src/hostlist/learning_peer1.conf
index 95b0d1850..51ac2caae 100644
--- a/src/hostlist/learning_peer1.conf
+++ b/src/hostlist/learning_peer1.conf
@@ -38,8 +38,10 @@ HTTPPORT = 12980
38SERVERS = http://localhost:12981/ 38SERVERS = http://localhost:12981/
39OPTIONS = -b -p -e -a 39OPTIONS = -b -p -e -a
40DEBUG = YES 40DEBUG = YES
41HOSTLISTFILE = hostlists.file
41#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist 42#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
42 43
44
43[topology] 45[topology]
44#DEBUG = YES 46#DEBUG = YES
45#PREFIX = valgrind --tool=memcheck 47#PREFIX = valgrind --tool=memcheck
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
index 8f3e8c91f..4ffd7f655 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
@@ -9,6 +9,7 @@ PORT = 12964
9PORT = 12965 9PORT = 12965
10PLUGINS = tcp 10PLUGINS = tcp
11#DEBUG = YES 11#DEBUG = YES
12DEBUG = NO
12 13
13[arm] 14[arm]
14PORT = 12966 15PORT = 12966
@@ -20,6 +21,7 @@ PORT = 12967
20 21
21[transport-tcp] 22[transport-tcp]
22PORT = 12968 23PORT = 12968
24DEBUG = NO
23 25
24[peerinfo] 26[peerinfo]
25PORT = 12969 27PORT = 12969
@@ -27,7 +29,8 @@ PORT = 12969
27[core] 29[core]
28PORT = 12970 30PORT = 12970
29#DEBUG = YES 31#DEBUG = YES
30#PREFIX = valgrind --tool=memcheck 32#PREFIX = valgrind --tool=memcheck\
33DEBUG = NO
31 34
32[testing] 35[testing]
33WEAKRANDOM = YES 36WEAKRANDOM = YES
@@ -38,7 +41,9 @@ SERVERS = http://localhost:12981/
38OPTIONS = -b -p 41OPTIONS = -b -p
39#DEBUG = YES 42#DEBUG = YES
40#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist 43#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
44DEBUG = NO
41 45
42[topology] 46[topology]
43#DEBUG = YES 47#DEBUG = YES
44#PREFIX = valgrind --tool=memcheck 48#PREFIX = valgrind --tool=memcheck
49DEBUG = NO \ No newline at end of file
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
index 9f66cf4d0..b689154de 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
@@ -4,29 +4,32 @@ DEFAULTCONFIG = test_gnunet_daemon_hostlist_peer2.conf
4 4
5[resolver] 5[resolver]
6PORT = 22964 6PORT = 22964
7DEBUG = NO
7 8
8[transport] 9[transport]
9PORT = 22965 10PORT = 22965
10PLUGINS = tcp 11PLUGINS = tcp
11#DEBUG = YES 12DEBUG = NO
12 13
13[arm] 14[arm]
14PORT = 22966 15PORT = 22966
15DEFAULTSERVICES = resolver transport core statistics topology 16DEFAULTSERVICES = resolver transport core statistics topology
16#GLOBAL_PREFIX = xterm -e gdb -x cmd --args 17#GLOBAL_PREFIX = xterm -e gdb -x cmd --args
18DEBUG = NO
17 19
18[statistics] 20[statistics]
19PORT = 22967 21PORT = 22967
20 22
21[transport-tcp] 23[transport-tcp]
22PORT = 22968 24PORT = 22968
25DEBUG = NO
23 26
24[peerinfo] 27[peerinfo]
25PORT = 22969 28PORT = 22969
26 29
27[core] 30[core]
28PORT = 22970 31PORT = 22970
29#DEBUG = YES 32DEBUG = NO
30#PREFIX = valgrind --tool=memcheck 33#PREFIX = valgrind --tool=memcheck
31 34
32[testing] 35[testing]
@@ -36,9 +39,10 @@ WEAKRANDOM = YES
36HTTPPORT = 12981 39HTTPPORT = 12981
37SERVERS = http://localhost:12980/ 40SERVERS = http://localhost:12980/
38OPTIONS = -b -p 41OPTIONS = -b -p
39#DEBUG = YES 42DEBUG = NO
40#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist 43#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
41 44
42[topology] 45[topology]
43#DEBUG = YES 46#DEBUG = YES
44#PREFIX = valgrind --tool=memcheck 47#PREFIX = valgrind --tool=memcheck
48DEBUG = NO