diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-15 17:12:57 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-15 17:12:57 +0000 |
commit | 1122dc4f084dafd390a81eda0b8739d873229202 (patch) | |
tree | 5018c14d9bef2e6e26985f636598162bd770095e /src/hostlist/hostlist-client.c | |
parent | e12c75e08bfe443be2b72749a3c65ba47521b9aa (diff) | |
download | gnunet-1122dc4f084dafd390a81eda0b8739d873229202.tar.gz gnunet-1122dc4f084dafd390a81eda0b8739d873229202.zip |
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r-- | src/hostlist/hostlist-client.c | 86 |
1 files changed, 51 insertions, 35 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index d882cdfbd..fc100a84c 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c | |||
@@ -49,11 +49,11 @@ | |||
49 | /** | 49 | /** |
50 | * A single hostlist obtained by hostlist advertisements | 50 | * A single hostlist obtained by hostlist advertisements |
51 | */ | 51 | */ |
52 | struct GNUNET_Hostlist | 52 | struct Hostlist |
53 | { | 53 | { |
54 | struct GNUNET_Hostlist * prev; | 54 | struct Hostlist * prev; |
55 | 55 | ||
56 | struct GNUNET_Hostlist * next; | 56 | struct Hostlist * next; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * URI where hostlist can be obtained | 59 | * URI where hostlist can be obtained |
@@ -174,10 +174,10 @@ static unsigned int connection_count; | |||
174 | static struct GNUNET_TIME_Absolute end_time; | 174 | static struct GNUNET_TIME_Absolute end_time; |
175 | 175 | ||
176 | /* DLL_? */ | 176 | /* DLL_? */ |
177 | static struct GNUNET_Hostlist * dll_head; | 177 | static struct Hostlist * dll_head; |
178 | 178 | ||
179 | /* DLL_? */ | 179 | /* DLL_? */ |
180 | static struct GNUNET_Hostlist * dll_tail; | 180 | static struct Hostlist * dll_tail; |
181 | 181 | ||
182 | /* DLL_? */ | 182 | /* DLL_? */ |
183 | static unsigned int dll_size; | 183 | static unsigned int dll_size; |
@@ -782,7 +782,7 @@ disconnect_handler (void *cls, | |||
782 | static int | 782 | static int |
783 | dll_contains (const char * uri) | 783 | dll_contains (const char * uri) |
784 | { | 784 | { |
785 | struct GNUNET_Hostlist * pos; | 785 | struct Hostlist * pos; |
786 | 786 | ||
787 | pos = dll_head; | 787 | pos = dll_head; |
788 | while (pos != NULL) | 788 | while (pos != NULL) |
@@ -796,11 +796,11 @@ dll_contains (const char * uri) | |||
796 | 796 | ||
797 | 797 | ||
798 | /* DLL_? */ | 798 | /* DLL_? */ |
799 | static struct GNUNET_Hostlist * | 799 | static struct Hostlist * |
800 | dll_get_lowest_quality ( ) | 800 | dll_get_lowest_quality ( ) |
801 | { | 801 | { |
802 | struct GNUNET_Hostlist * pos; | 802 | struct Hostlist * pos; |
803 | struct GNUNET_Hostlist * lowest; | 803 | struct Hostlist * lowest; |
804 | 804 | ||
805 | if (dll_size == 0) | 805 | if (dll_size == 0) |
806 | return NULL; | 806 | return NULL; |
@@ -818,7 +818,7 @@ dll_get_lowest_quality ( ) | |||
818 | 818 | ||
819 | #if DUMMY | 819 | #if DUMMY |
820 | /* TO BE REMOVED later */ | 820 | /* TO BE REMOVED later */ |
821 | static void dll_insert ( struct GNUNET_Hostlist *hostlist) | 821 | static void dll_insert ( struct Hostlist *hostlist) |
822 | { | 822 | { |
823 | GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist); | 823 | GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist); |
824 | dll_size++; | 824 | dll_size++; |
@@ -828,8 +828,8 @@ static void create_dummy_entries () | |||
828 | { | 828 | { |
829 | 829 | ||
830 | /* test */ | 830 | /* test */ |
831 | struct GNUNET_Hostlist * hostlist1; | 831 | struct Hostlist * hostlist1; |
832 | hostlist1 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | 832 | hostlist1 = GNUNET_malloc ( sizeof (struct Hostlist) ); |
833 | char * str = "uri_1"; | 833 | char * str = "uri_1"; |
834 | 834 | ||
835 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist1->peer.hashPubKey); | 835 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist1->peer.hashPubKey); |
@@ -843,8 +843,8 @@ static void create_dummy_entries () | |||
843 | "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist1->peer.hashPubKey) , hostlist1->hostlist_uri, hostlist1->quality); | 843 | "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist1->peer.hashPubKey) , hostlist1->hostlist_uri, hostlist1->quality); |
844 | dll_insert (hostlist1); | 844 | dll_insert (hostlist1); |
845 | 845 | ||
846 | struct GNUNET_Hostlist * hostlist2; | 846 | struct Hostlist * hostlist2; |
847 | hostlist2 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | 847 | hostlist2 = GNUNET_malloc ( sizeof (struct Hostlist) ); |
848 | char * str2 = "uri_2"; | 848 | char * str2 = "uri_2"; |
849 | 849 | ||
850 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist2->peer.hashPubKey); | 850 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist2->peer.hashPubKey); |
@@ -858,8 +858,8 @@ static void create_dummy_entries () | |||
858 | "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist2->peer.hashPubKey) , hostlist2->hostlist_uri, hostlist2->quality); | 858 | "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist2->peer.hashPubKey) , hostlist2->hostlist_uri, hostlist2->quality); |
859 | dll_insert (hostlist2); | 859 | dll_insert (hostlist2); |
860 | 860 | ||
861 | struct GNUNET_Hostlist * hostlist3; | 861 | struct Hostlist * hostlist3; |
862 | hostlist3 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | 862 | hostlist3 = GNUNET_malloc ( sizeof (struct Hostlist) ); |
863 | char * str3 = "uri_3"; | 863 | char * str3 = "uri_3"; |
864 | 864 | ||
865 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist3->peer.hashPubKey); | 865 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist3->peer.hashPubKey); |
@@ -874,8 +874,8 @@ static void create_dummy_entries () | |||
874 | dll_insert (hostlist3); | 874 | dll_insert (hostlist3); |
875 | 875 | ||
876 | 876 | ||
877 | struct GNUNET_Hostlist * hostlist4; | 877 | struct Hostlist * hostlist4; |
878 | hostlist4 = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | 878 | hostlist4 = GNUNET_malloc ( sizeof (struct Hostlist) ); |
879 | char * str4 = "uri_4"; | 879 | char * str4 = "uri_4"; |
880 | 880 | ||
881 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist4->peer.hashPubKey); | 881 | GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist4->peer.hashPubKey); |
@@ -911,7 +911,7 @@ advertisement_handler (void *cls, | |||
911 | size_t uri_size; | 911 | size_t uri_size; |
912 | const struct GNUNET_MessageHeader * incoming; | 912 | const struct GNUNET_MessageHeader * incoming; |
913 | const char *uri; | 913 | const char *uri; |
914 | struct GNUNET_Hostlist * hostlist; | 914 | struct Hostlist * hostlist; |
915 | 915 | ||
916 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 916 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
917 | size = ntohs (message->size); | 917 | size = ntohs (message->size); |
@@ -934,7 +934,7 @@ advertisement_handler (void *cls, | |||
934 | uri); | 934 | uri); |
935 | if (GNUNET_YES != dll_contains (uri)) | 935 | if (GNUNET_YES != dll_contains (uri)) |
936 | return GNUNET_OK; | 936 | return GNUNET_OK; |
937 | hostlist = GNUNET_malloc (sizeof (struct GNUNET_Hostlist) + uri_size); | 937 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); |
938 | hostlist->peer = *peer; | 938 | hostlist->peer = *peer; |
939 | hostlist->hostlist_uri = (const char*) &hostlist[1]; | 939 | hostlist->hostlist_uri = (const char*) &hostlist[1]; |
940 | memcpy (&hostlist[1], uri, uri_size); | 940 | memcpy (&hostlist[1], uri, uri_size); |
@@ -953,7 +953,7 @@ advertisement_handler (void *cls, | |||
953 | /* No free entries available, replace existing entry */ | 953 | /* No free entries available, replace existing entry */ |
954 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 954 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
955 | "Removing lowest quality entry\n" ); | 955 | "Removing lowest quality entry\n" ); |
956 | struct GNUNET_Hostlist * lowest_quality = dll_get_lowest_quality(); | 956 | struct Hostlist * lowest_quality = dll_get_lowest_quality(); |
957 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 957 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
958 | "Hostlist with URI `%s' has the worst quality of all with value %llu\n", | 958 | "Hostlist with URI `%s' has the worst quality of all with value %llu\n", |
959 | lowest_quality->hostlist_uri, | 959 | lowest_quality->hostlist_uri, |
@@ -1009,6 +1009,7 @@ load_hostlist_file () | |||
1009 | char *filename; | 1009 | char *filename; |
1010 | char *uri; | 1010 | char *uri; |
1011 | char *emsg; | 1011 | char *emsg; |
1012 | struct Hostlist * hostlist; | ||
1012 | 1013 | ||
1013 | if (GNUNET_OK != | 1014 | if (GNUNET_OK != |
1014 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1015 | GNUNET_CONFIGURATION_get_value_string (cfg, |
@@ -1035,21 +1036,29 @@ load_hostlist_file () | |||
1035 | 1036 | ||
1036 | /* add code to read hostlists to file using bio */ | 1037 | /* add code to read hostlists to file using bio */ |
1037 | uri = NULL; | 1038 | uri = NULL; |
1039 | uint32_t times_used; | ||
1040 | uint32_t hellos_returned; | ||
1041 | uint64_t quality; | ||
1042 | uint64_t last_used; | ||
1043 | uint64_t created; | ||
1044 | |||
1038 | while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) && | 1045 | while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) && |
1039 | #if 0 | ||
1040 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && | 1046 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && |
1041 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) && | 1047 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && |
1042 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used.value)) && | 1048 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && |
1043 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created.value)) && | 1049 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && |
1044 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) | 1050 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) ) |
1045 | #else | ||
1046 | (1) | ||
1047 | #endif | ||
1048 | ) | ||
1049 | { | 1051 | { |
1050 | #if 0 | 1052 | hostlist = GNUNET_malloc ( sizeof (struct Hostlist)); |
1051 | hostlist = GNUNET_malloc (...); | 1053 | hostlist->hello_count = hellos_returned; |
1052 | #endif | 1054 | strcpy(hostlist->hostlist_uri, uri); |
1055 | hostlist->quality = quality; | ||
1056 | hostlist->time_creation.value = created; | ||
1057 | hostlist->time_last_usage.value = last_used; | ||
1058 | GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist); | ||
1059 | dll_size++; | ||
1060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1061 | "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri); | ||
1053 | uri = NULL; | 1062 | uri = NULL; |
1054 | } | 1063 | } |
1055 | GNUNET_free_non_null (uri); | 1064 | GNUNET_free_non_null (uri); |
@@ -1067,7 +1076,7 @@ load_hostlist_file () | |||
1067 | static void save_hostlist_file () | 1076 | static void save_hostlist_file () |
1068 | { | 1077 | { |
1069 | char *filename; | 1078 | char *filename; |
1070 | struct GNUNET_Hostlist *pos; | 1079 | struct Hostlist *pos; |
1071 | struct GNUNET_BIO_WriteHandle * wh; | 1080 | struct GNUNET_BIO_WriteHandle * wh; |
1072 | int ok; | 1081 | int ok; |
1073 | 1082 | ||
@@ -1107,7 +1116,14 @@ static void save_hostlist_file () | |||
1107 | GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | 1116 | GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || |
1108 | (GNUNET_OK != | 1117 | (GNUNET_OK != |
1109 | GNUNET_BIO_write_int32 (wh, pos->times_used)) || | 1118 | GNUNET_BIO_write_int32 (wh, pos->times_used)) || |
1110 | (0) ) | 1119 | (GNUNET_OK != |
1120 | GNUNET_BIO_write_int64 (wh, pos->quality)) || | ||
1121 | (GNUNET_OK != | ||
1122 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.value)) || | ||
1123 | (GNUNET_OK != | ||
1124 | GNUNET_BIO_write_int64 (wh, pos->time_creation.value)) || | ||
1125 | (GNUNET_OK != | ||
1126 | GNUNET_BIO_write_int32 (wh, pos->hello_count))) | ||
1111 | { | 1127 | { |
1112 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1128 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1113 | _("Error writing hostlist URIs to file `%s'\n"), | 1129 | _("Error writing hostlist URIs to file `%s'\n"), |