aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/hostlist-client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-16 07:00:56 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-16 07:00:56 +0000
commitf0283fcff9e2f9b85eb5285325adcf451e361d92 (patch)
treec148c8a0ab4366f8756f9b23a898745216c5f7fc /src/hostlist/hostlist-client.c
parenta8b91d0bcb4a97b20a838f2007249cf37f0f22d8 (diff)
downloadgnunet-f0283fcff9e2f9b85eb5285325adcf451e361d92.tar.gz
gnunet-f0283fcff9e2f9b85eb5285325adcf451e361d92.zip
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r--src/hostlist/hostlist-client.c96
1 files changed, 47 insertions, 49 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 8e6850d7e..a0336ff2a 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -173,14 +173,14 @@ static unsigned int connection_count;
173 */ 173 */
174static struct GNUNET_TIME_Absolute end_time; 174static struct GNUNET_TIME_Absolute end_time;
175 175
176/* DLL_? */ 176/* Head of the linked list used to store hostlists */
177static struct Hostlist * dll_head; 177static struct Hostlist * linked_list_head;
178 178
179/* DLL_? */ 179/* Tail of the linked list used to store hostlists */
180static struct Hostlist * dll_tail; 180static struct Hostlist * linked_list_tail;
181 181
182/* DLL_? */ 182/* Size of the linke list used to store hostlists */
183static unsigned int dll_size; 183static unsigned int linked_list_size;
184 184
185/** 185/**
186 * Process downloaded bits by calling callback on each HELLO. 186 * Process downloaded bits by calling callback on each HELLO.
@@ -778,13 +778,17 @@ disconnect_handler (void *cls,
778} 778}
779 779
780 780
781/* DLL_? */ 781/**
782 * Method to check if URI is in hostlist linked list
783 * @param uri uri to check
784 * @return GNUNET_YES if existing in linked list, GNUNET_NO if not
785 */
782static int 786static int
783dll_contains (const char * uri) 787linked_list_contains (const char * uri)
784{ 788{
785 struct Hostlist * pos; 789 struct Hostlist * pos;
786 790
787 pos = dll_head; 791 pos = linked_list_head;
788 while (pos != NULL) 792 while (pos != NULL)
789 { 793 {
790 if (0 == strcmp(pos->hostlist_uri, uri) ) 794 if (0 == strcmp(pos->hostlist_uri, uri) )
@@ -795,17 +799,17 @@ dll_contains (const char * uri)
795} 799}
796 800
797 801
798/* DLL_? */ 802/* linked_list_? */
799static struct Hostlist * 803static struct Hostlist *
800dll_get_lowest_quality ( ) 804linked_list_get_lowest_quality ( )
801{ 805{
802 struct Hostlist * pos; 806 struct Hostlist * pos;
803 struct Hostlist * lowest; 807 struct Hostlist * lowest;
804 808
805 if (dll_size == 0) 809 if (linked_list_size == 0)
806 return NULL; 810 return NULL;
807 lowest = dll_head; 811 lowest = linked_list_head;
808 pos = dll_head->next; 812 pos = linked_list_head->next;
809 while (pos != NULL) 813 while (pos != NULL)
810 { 814 {
811 if (pos->quality < lowest->quality) 815 if (pos->quality < lowest->quality)
@@ -815,33 +819,25 @@ dll_get_lowest_quality ( )
815 return lowest; 819 return lowest;
816} 820}
817 821
818
819#if DUMMY
820/* TO BE REMOVED later */
821static void dll_insert ( struct Hostlist *hostlist)
822{
823 GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist);
824 dll_size++;
825}
826
827static void create_dummy_entries () 822static void create_dummy_entries ()
828{ 823{
829 824
830 /* test */ 825 /* test */
831 struct Hostlist * hostlist1; 826 struct Hostlist * hostlist1;
832 hostlist1 = GNUNET_malloc ( sizeof (struct Hostlist) ); 827 hostlist1 = GNUNET_malloc ( sizeof (struct Hostlist) );
833 char * str = "uri_1"; 828 char str[] = "uri_1";
834 829
835 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist1->peer.hashPubKey); 830 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist1->peer.hashPubKey);
836 hostlist1->hello_count = 0; 831 hostlist1->hello_count = 0;
837 hostlist1->hostlist_uri = GNUNET_malloc ( strlen(str) +1 ); 832 hostlist1->hostlist_uri = GNUNET_malloc ( strlen(str) +1 );
838 strcpy(hostlist1->hostlist_uri,str); 833 strcpy( (char *) hostlist1->hostlist_uri,str);
839 hostlist1->time_creation = GNUNET_TIME_absolute_get(); 834 hostlist1->time_creation = GNUNET_TIME_absolute_get();
840 hostlist1->time_last_usage = GNUNET_TIME_absolute_get_zero(); 835 hostlist1->time_last_usage = GNUNET_TIME_absolute_get_zero();
841 hostlist1->quality = HOSTLIST_INITIAL - 100; 836 hostlist1->quality = HOSTLIST_INITIAL - 100;
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
843 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist1->peer.hashPubKey) , hostlist1->hostlist_uri, hostlist1->quality); 838 "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); 839 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist1);
840 linked_list_size++;
845 841
846 struct Hostlist * hostlist2; 842 struct Hostlist * hostlist2;
847 hostlist2 = GNUNET_malloc ( sizeof (struct Hostlist) ); 843 hostlist2 = GNUNET_malloc ( sizeof (struct Hostlist) );
@@ -850,13 +846,14 @@ static void create_dummy_entries ()
850 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist2->peer.hashPubKey); 846 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist2->peer.hashPubKey);
851 hostlist2->hello_count = 0; 847 hostlist2->hello_count = 0;
852 hostlist2->hostlist_uri = GNUNET_malloc ( strlen(str2) +1 ); 848 hostlist2->hostlist_uri = GNUNET_malloc ( strlen(str2) +1 );
853 strcpy(hostlist2->hostlist_uri,str2); 849 strcpy( (char *) hostlist2->hostlist_uri,str2);
854 hostlist2->time_creation = GNUNET_TIME_absolute_get(); 850 hostlist2->time_creation = GNUNET_TIME_absolute_get();
855 hostlist2->time_last_usage = GNUNET_TIME_absolute_get_zero(); 851 hostlist2->time_last_usage = GNUNET_TIME_absolute_get_zero();
856 hostlist2->quality = HOSTLIST_INITIAL - 200; 852 hostlist2->quality = HOSTLIST_INITIAL - 200;
857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
858 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist2->peer.hashPubKey) , hostlist2->hostlist_uri, hostlist2->quality); 854 "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); 855 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist2);
856 linked_list_size++;
860 857
861 struct Hostlist * hostlist3; 858 struct Hostlist * hostlist3;
862 hostlist3 = GNUNET_malloc ( sizeof (struct Hostlist) ); 859 hostlist3 = GNUNET_malloc ( sizeof (struct Hostlist) );
@@ -865,13 +862,14 @@ static void create_dummy_entries ()
865 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist3->peer.hashPubKey); 862 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist3->peer.hashPubKey);
866 hostlist3->hello_count = 0; 863 hostlist3->hello_count = 0;
867 hostlist3->hostlist_uri = GNUNET_malloc ( strlen(str3) +1 ); 864 hostlist3->hostlist_uri = GNUNET_malloc ( strlen(str3) +1 );
868 strcpy(hostlist3->hostlist_uri,str3); 865 strcpy( (char *)hostlist3->hostlist_uri,str3);
869 hostlist3->time_creation = GNUNET_TIME_absolute_get(); 866 hostlist3->time_creation = GNUNET_TIME_absolute_get();
870 hostlist3->time_last_usage = GNUNET_TIME_absolute_get_zero(); 867 hostlist3->time_last_usage = GNUNET_TIME_absolute_get_zero();
871 hostlist3->quality = HOSTLIST_INITIAL - 300; 868 hostlist3->quality = HOSTLIST_INITIAL - 300;
872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
873 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist3->peer.hashPubKey) , hostlist3->hostlist_uri, hostlist3->quality); 870 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist3->peer.hashPubKey) , hostlist3->hostlist_uri, hostlist3->quality);
874 dll_insert (hostlist3); 871 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist3);
872 linked_list_size++;
875 873
876 874
877 struct Hostlist * hostlist4; 875 struct Hostlist * hostlist4;
@@ -881,15 +879,15 @@ static void create_dummy_entries ()
881 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist4->peer.hashPubKey); 879 GNUNET_CRYPTO_hash_create_random ( GNUNET_CRYPTO_QUALITY_WEAK , &hostlist4->peer.hashPubKey);
882 hostlist4->hello_count = 0; 880 hostlist4->hello_count = 0;
883 hostlist4->hostlist_uri = GNUNET_malloc ( strlen(str4) +1 ); 881 hostlist4->hostlist_uri = GNUNET_malloc ( strlen(str4) +1 );
884 strcpy(hostlist4->hostlist_uri,str4); 882 strcpy((char *) hostlist4->hostlist_uri,str4);
885 hostlist4->time_creation = GNUNET_TIME_absolute_get(); 883 hostlist4->time_creation = GNUNET_TIME_absolute_get();
886 hostlist4->time_last_usage = GNUNET_TIME_absolute_get_zero(); 884 hostlist4->time_last_usage = GNUNET_TIME_absolute_get_zero();
887 hostlist4->quality = HOSTLIST_INITIAL - 400; 885 hostlist4->quality = HOSTLIST_INITIAL - 400;
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
889 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist4->peer.hashPubKey) , hostlist4->hostlist_uri, hostlist4->quality); 887 "Adding test peer '%s' with URI %s and quality %u to dll \n", GNUNET_h2s (&hostlist4->peer.hashPubKey) , hostlist4->hostlist_uri, hostlist4->quality);
890 dll_insert (hostlist4); 888 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist4);
889 linked_list_size++;
891} 890}
892#endif
893 891
894/** 892/**
895 * Method called whenever an advertisement message arrives. 893 * Method called whenever an advertisement message arrives.
@@ -932,7 +930,7 @@ advertisement_handler (void *cls,
932 "Hostlist client recieved advertisement from `%s' containing URI `%s'\n", 930 "Hostlist client recieved advertisement from `%s' containing URI `%s'\n",
933 GNUNET_i2s (peer), 931 GNUNET_i2s (peer),
934 uri); 932 uri);
935 if (GNUNET_YES != dll_contains (uri)) 933 if (GNUNET_YES != linked_list_contains (uri))
936 return GNUNET_OK; 934 return GNUNET_OK;
937 hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); 935 hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
938 hostlist->peer = *peer; 936 hostlist->peer = *peer;
@@ -944,22 +942,22 @@ advertisement_handler (void *cls,
944#if DUMMY 942#if DUMMY
945 create_dummy_entries(); /* FIXME: remove later... */ 943 create_dummy_entries(); /* FIXME: remove later... */
946#endif 944#endif
947 GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist); 945 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist);
948 dll_size++; 946 linked_list_size++;
949 947
950 if (MAX_NUMBER_HOSTLISTS >= dll_size) 948 if (MAX_NUMBER_HOSTLISTS >= linked_list_size)
951 return GNUNET_OK; 949 return GNUNET_OK;
952 950
953 /* No free entries available, replace existing entry */ 951 /* No free entries available, replace existing entry */
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 "Removing lowest quality entry\n" ); 953 "Removing lowest quality entry\n" );
956 struct Hostlist * lowest_quality = dll_get_lowest_quality(); 954 struct Hostlist * lowest_quality = linked_list_get_lowest_quality();
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "Hostlist with URI `%s' has the worst quality of all with value %llu\n", 956 "Hostlist with URI `%s' has the worst quality of all with value %llu\n",
959 lowest_quality->hostlist_uri, 957 lowest_quality->hostlist_uri,
960 (unsigned long long) lowest_quality->quality); 958 (unsigned long long) lowest_quality->quality);
961 GNUNET_CONTAINER_DLL_remove (dll_head, dll_tail, lowest_quality); 959 GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, lowest_quality);
962 dll_size--; 960 linked_list_size--;
963 GNUNET_free (lowest_quality); 961 GNUNET_free (lowest_quality);
964 return GNUNET_OK; 962 return GNUNET_OK;
965} 963}
@@ -1056,8 +1054,8 @@ load_hostlist_file ()
1056 hostlist->quality = quality; 1054 hostlist->quality = quality;
1057 hostlist->time_creation.value = created; 1055 hostlist->time_creation.value = created;
1058 hostlist->time_last_usage.value = last_used; 1056 hostlist->time_last_usage.value = last_used;
1059 GNUNET_CONTAINER_DLL_insert(dll_head, dll_tail, hostlist); 1057 GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist);
1060 dll_size++; 1058 linked_list_size++;
1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1062 "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri); 1060 "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri);
1063 uri = NULL; 1061 uri = NULL;
@@ -1102,15 +1100,15 @@ static void save_hostlist_file ()
1102 return; 1100 return;
1103 } 1101 }
1104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1102 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1105 _("Writing hostlist URIs to `%s'\n"), 1103 _("Writing %u hostlist URIs to `%s'\n" ),
1106 filename); 1104 linked_list_size, filename);
1107 1105
1108 /* add code to write hostlists to file using bio */ 1106 /* add code to write hostlists to file using bio */
1109 ok = GNUNET_YES; 1107 ok = GNUNET_YES;
1110 while (NULL != (pos = dll_head)) 1108 while (NULL != (pos = linked_list_head))
1111 { 1109 {
1112 GNUNET_CONTAINER_DLL_remove (dll_head, dll_tail, pos); 1110 GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos);
1113 dll_size--; 1111 linked_list_size--;
1114 if (GNUNET_YES == ok) 1112 if (GNUNET_YES == ok)
1115 { 1113 {
1116 if ( (GNUNET_OK != 1114 if ( (GNUNET_OK !=
@@ -1179,8 +1177,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1179 *msgh = &advertisement_handler; 1177 *msgh = &advertisement_handler;
1180 else 1178 else
1181 *msgh = NULL; 1179 *msgh = NULL;
1182 dll_head = NULL; 1180 linked_list_head = NULL;
1183 dll_tail = NULL; 1181 linked_list_tail = NULL;
1184 load_hostlist_file (); 1182 load_hostlist_file ();
1185 1183
1186 GNUNET_STATISTICS_get (stats, 1184 GNUNET_STATISTICS_get (stats,