aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/hostlist-client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-13 15:25:50 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-13 15:25:50 +0000
commit9c8285667baa991e8fc4c411c94be8816512647f (patch)
treee7fd53e0f2b9fed05e030d1e9ab3ce212b51446a /src/hostlist/hostlist-client.c
parent9ed07b4513bb096304224a1ab8e948872d21ee93 (diff)
downloadgnunet-9c8285667baa991e8fc4c411c94be8816512647f.tar.gz
gnunet-9c8285667baa991e8fc4c411c94be8816512647f.zip
added some code for hostlist management
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r--src/hostlist/hostlist-client.c62
1 files changed, 49 insertions, 13 deletions
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,