aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/hostlist-client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-16 07:34:22 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-16 07:34:22 +0000
commitb09ccc6d3a24229af41b2ac0253262c8532e0e38 (patch)
tree0d8dc280ef56ef82b5d98c26665c40bee1726311 /src/hostlist/hostlist-client.c
parent03aa372c5691b7de7f0728a71fa38bb891a8f375 (diff)
downloadgnunet-b09ccc6d3a24229af41b2ac0253262c8532e0e38.tar.gz
gnunet-b09ccc6d3a24229af41b2ac0253262c8532e0e38.zip
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r--src/hostlist/hostlist-client.c111
1 files changed, 26 insertions, 85 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 5fbee02bc..9fc1eb71e 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -819,76 +819,6 @@ linked_list_get_lowest_quality ( )
819 return lowest; 819 return lowest;
820} 820}
821 821
822static void create_dummy_entries ()
823{
824
825 /* test */
826 struct Hostlist * hostlist1;
827 hostlist1 = GNUNET_malloc ( sizeof (struct Hostlist) );
828 char str[] = "uri_1";
829
830 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist1->peer.hashPubKey);
831 hostlist1->hello_count = 0;
832 hostlist1->hostlist_uri = GNUNET_malloc ( strlen(str) +1 );
833 strcpy( (char *) hostlist1->hostlist_uri,str);
834 hostlist1->time_creation = GNUNET_TIME_absolute_get();
835 hostlist1->time_last_usage = GNUNET_TIME_absolute_get_zero();
836 hostlist1->quality = HOSTLIST_INITIAL - 100;
837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
838 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist1->peer.hashPubKey) , hostlist1->hostlist_uri, hostlist1->quality);
839 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist1);
840 linked_list_size++;
841
842 struct Hostlist * hostlist2;
843 hostlist2 = GNUNET_malloc ( sizeof (struct Hostlist) );
844 char * str2 = "uri_2";
845
846 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist2->peer.hashPubKey);
847 hostlist2->hello_count = 0;
848 hostlist2->hostlist_uri = GNUNET_malloc ( strlen(str2) +1 );
849 strcpy( (char *) hostlist2->hostlist_uri,str2);
850 hostlist2->time_creation = GNUNET_TIME_absolute_get();
851 hostlist2->time_last_usage = GNUNET_TIME_absolute_get_zero();
852 hostlist2->quality = HOSTLIST_INITIAL - 200;
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist2->peer.hashPubKey) , hostlist2->hostlist_uri, hostlist2->quality);
855 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist2);
856 linked_list_size++;
857
858 struct Hostlist * hostlist3;
859 hostlist3 = GNUNET_malloc ( sizeof (struct Hostlist) );
860 char * str3 = "uri_3";
861
862 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist3->peer.hashPubKey);
863 hostlist3->hello_count = 0;
864 hostlist3->hostlist_uri = GNUNET_malloc ( strlen(str3) +1 );
865 strcpy( (char *)hostlist3->hostlist_uri,str3);
866 hostlist3->time_creation = GNUNET_TIME_absolute_get();
867 hostlist3->time_last_usage = GNUNET_TIME_absolute_get_zero();
868 hostlist3->quality = HOSTLIST_INITIAL - 300;
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
870 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist3->peer.hashPubKey) , hostlist3->hostlist_uri, hostlist3->quality);
871 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist3);
872 linked_list_size++;
873
874
875 struct Hostlist * hostlist4;
876 hostlist4 = GNUNET_malloc ( sizeof (struct Hostlist) );
877 char * str4 = "uri_4";
878
879 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist4->peer.hashPubKey);
880 hostlist4->hello_count = 0;
881 hostlist4->hostlist_uri = GNUNET_malloc ( strlen(str4) +1 );
882 strcpy((char *) hostlist4->hostlist_uri,str4);
883 hostlist4->time_creation = GNUNET_TIME_absolute_get();
884 hostlist4->time_last_usage = GNUNET_TIME_absolute_get_zero();
885 hostlist4->quality = HOSTLIST_INITIAL - 400;
886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
887 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist4->peer.hashPubKey) , hostlist4->hostlist_uri, hostlist4->quality);
888 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist4);
889 linked_list_size++;
890
891}
892 822
893/** 823/**
894 * Method called whenever an advertisement message arrives. 824 * Method called whenever an advertisement message arrives.
@@ -945,9 +875,7 @@ advertisement_handler (void *cls,
945 hostlist->time_creation = GNUNET_TIME_absolute_get(); 875 hostlist->time_creation = GNUNET_TIME_absolute_get();
946 hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero(); 876 hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero();
947 hostlist->quality = HOSTLIST_INITIAL; 877 hostlist->quality = HOSTLIST_INITIAL;
948#if DUMMY 878
949 create_dummy_entries(); /* FIXME: remove later... */
950#endif
951 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); 879 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist);
952 linked_list_size++; 880 linked_list_size++;
953 881
@@ -1014,6 +942,13 @@ load_hostlist_file ()
1014 char *uri; 942 char *uri;
1015 char *emsg; 943 char *emsg;
1016 struct Hostlist * hostlist; 944 struct Hostlist * hostlist;
945 uri = NULL;
946 uint32_t times_used;
947 uint32_t hellos_returned;
948 uint64_t quality;
949 uint64_t last_used;
950 uint64_t created;
951 uint32_t counter;
1017 952
1018 if (GNUNET_OK != 953 if (GNUNET_OK !=
1019 GNUNET_CONFIGURATION_get_value_string (cfg, 954 GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -1027,6 +962,9 @@ load_hostlist_file ()
1027 return; 962 return;
1028 } 963 }
1029 964
965 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
966 _("Loading saved hostlist entries from file `%s' \n"), filename);
967
1030 struct GNUNET_BIO_ReadHandle * rh = GNUNET_BIO_read_open (filename); 968 struct GNUNET_BIO_ReadHandle * rh = GNUNET_BIO_read_open (filename);
1031 if (NULL == rh) 969 if (NULL == rh)
1032 { 970 {
@@ -1038,13 +976,6 @@ load_hostlist_file ()
1038 return; 976 return;
1039 } 977 }
1040 978
1041 /* add code to read hostlists to file using bio */
1042 uri = NULL;
1043 uint32_t times_used;
1044 uint32_t hellos_returned;
1045 uint64_t quality;
1046 uint64_t last_used;
1047 uint64_t created;
1048 979
1049 while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) && 980 while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) &&
1050 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used)) && 981 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used)) &&
@@ -1065,7 +996,12 @@ load_hostlist_file ()
1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1066 "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri); 997 "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri);
1067 uri = NULL; 998 uri = NULL;
999 counter++;
1068 } 1000 }
1001
1002 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1003 _("%u hostlist URIs loaded from file\n"), counter);
1004
1069 GNUNET_free_non_null (uri); 1005 GNUNET_free_non_null (uri);
1070 emsg = NULL; 1006 emsg = NULL;
1071 GNUNET_BIO_read_close (rh, &emsg); 1007 GNUNET_BIO_read_close (rh, &emsg);
@@ -1077,8 +1013,9 @@ load_hostlist_file ()
1077 1013
1078/** 1014/**
1079 * Method to load persistent hostlist file during hostlist client shutdown 1015 * Method to load persistent hostlist file during hostlist client shutdown
1016 * @param shutdown set if called because of shutdown, entries in linked list will be destroyed
1080 */ 1017 */
1081static void save_hostlist_file () 1018static void save_hostlist_file ( int shutdown )
1082{ 1019{
1083 char *filename; 1020 char *filename;
1084 struct Hostlist *pos; 1021 struct Hostlist *pos;
@@ -1113,8 +1050,11 @@ static void save_hostlist_file ()
1113 ok = GNUNET_YES; 1050 ok = GNUNET_YES;
1114 while (NULL != (pos = linked_list_head)) 1051 while (NULL != (pos = linked_list_head))
1115 { 1052 {
1116 GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); 1053 if ( GNUNET_YES == shutdown)
1117 linked_list_size--; 1054 {
1055 GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos);
1056 linked_list_size--;
1057 }
1118 if (GNUNET_YES == ok) 1058 if (GNUNET_YES == ok)
1119 { 1059 {
1120 if ( (GNUNET_OK != 1060 if ( (GNUNET_OK !=
@@ -1136,7 +1076,8 @@ static void save_hostlist_file ()
1136 ok = GNUNET_NO; 1076 ok = GNUNET_NO;
1137 } 1077 }
1138 } 1078 }
1139 GNUNET_free (pos); 1079 if ( GNUNET_YES == shutdown)
1080 GNUNET_free (pos);
1140 } 1081 }
1141 if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) 1082 if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) )
1142 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1083 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1208,7 +1149,7 @@ GNUNET_HOSTLIST_client_stop ()
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "Hostlist client shutdown\n"); 1150 "Hostlist client shutdown\n");
1210#endif 1151#endif
1211 save_hostlist_file (); 1152 save_hostlist_file ( GNUNET_YES );
1212 1153
1213 if (current_task != GNUNET_SCHEDULER_NO_TASK) 1154 if (current_task != GNUNET_SCHEDULER_NO_TASK)
1214 { 1155 {