aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/hostlist-client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-16 10:15:52 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-16 10:15:52 +0000
commitc3344a3aa2dd696d73129a0528b4867f78b60299 (patch)
treef31ded3fc8f53ea672ae95461856b8e7b2347227 /src/hostlist/hostlist-client.c
parente3ba93b28f79cd7dd16a605e1077a95490bf132c (diff)
downloadgnunet-c3344a3aa2dd696d73129a0528b4867f78b60299.tar.gz
gnunet-c3344a3aa2dd696d73129a0528b4867f78b60299.zip
added safety check in writing and saving hostlists to stop uncontrolled writing
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r--src/hostlist/hostlist-client.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 9ad65fe35..7370899bd 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -155,6 +155,11 @@ static CURLM *multi;
155static GNUNET_SCHEDULER_TaskIdentifier current_task; 155static GNUNET_SCHEDULER_TaskIdentifier current_task;
156 156
157/** 157/**
158 * ID of the current hostlist saving task scheduled.
159 */
160static GNUNET_SCHEDULER_TaskIdentifier saving_task;
161
162/**
158 * Amount of time we wait between hostlist downloads. 163 * Amount of time we wait between hostlist downloads.
159 */ 164 */
160static struct GNUNET_TIME_Relative hostlist_delay; 165static struct GNUNET_TIME_Relative hostlist_delay;
@@ -363,6 +368,11 @@ get_url ()
363static void 368static void
364schedule_hostlist_task (void); 369schedule_hostlist_task (void);
365 370
371/**
372 * Method to load persistent hostlist file during hostlist client shutdown
373 * @param shutdown set if called because of shutdown, entries in linked list will be destroyed
374 */
375static void save_hostlist_file ( int shutdown );
366 376
367/** 377/**
368 * Clean up the state from the task that downloaded the 378 * Clean up the state from the task that downloaded the
@@ -736,6 +746,47 @@ schedule_hostlist_task ()
736 NULL); 746 NULL);
737} 747}
738 748
749/**
750 * Compute when we should save the hostlist entries the next time;
751 * then schedule the task accordingly.
752 */
753static void
754schedule_hostlist_saving_task ();
755
756/**
757 * Task that checks if we should try to download a hostlist.
758 * If so, we initiate the download, otherwise we schedule
759 * this task again for a later time.
760 */
761static void
762hostlist_saving_task (void *cls,
763 const struct GNUNET_SCHEDULER_TaskContext *tc)
764{
765 saving_task = GNUNET_SCHEDULER_NO_TASK;
766 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
767 return;
768 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
769 _("Scheduled saving of hostlists\n"));
770 save_hostlist_file ( GNUNET_NO );
771 /*schedule_hostlist_saving_task ();*/
772}
773
774/**
775 * Compute when we should save the hostlist entries the next time;
776 * then schedule the task accordingly.
777 */
778static void
779schedule_hostlist_saving_task ()
780{
781
782 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
783 _("Hostlists will be saved to file again in %llums\n"),
784 (unsigned long long) SAVING_INTERVALL.value);
785 saving_task = GNUNET_SCHEDULER_add_delayed (sched,
786 SAVING_INTERVALL,
787 &hostlist_saving_task,
788 NULL);
789}
739 790
740/** 791/**
741 * Method called whenever a given peer connects. 792 * Method called whenever a given peer connects.
@@ -997,10 +1048,15 @@ load_hostlist_file ()
997 "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri); 1048 "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri);
998 uri = NULL; 1049 uri = NULL;
999 counter++; 1050 counter++;
1051 if ( counter >= MAX_NUMBER_HOSTLISTS ) break;
1000 } 1052 }
1001 1053
1002 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1054 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1003 _("%u hostlist URIs loaded from file\n"), counter); 1055 _("%u hostlist URIs loaded from file\n"), counter);
1056 GNUNET_STATISTICS_set (stats,
1057 gettext_noop("# hostlis URIs read from file"),
1058 counter,
1059 GNUNET_YES);
1004 1060
1005 GNUNET_free_non_null (uri); 1061 GNUNET_free_non_null (uri);
1006 emsg = NULL; 1062 emsg = NULL;
@@ -1021,6 +1077,7 @@ static void save_hostlist_file ( int shutdown )
1021 struct Hostlist *pos; 1077 struct Hostlist *pos;
1022 struct GNUNET_BIO_WriteHandle * wh; 1078 struct GNUNET_BIO_WriteHandle * wh;
1023 int ok; 1079 int ok;
1080 uint32_t counter;
1024 1081
1025 if (GNUNET_OK != 1082 if (GNUNET_OK !=
1026 GNUNET_CONFIGURATION_get_value_string (cfg, 1083 GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -1048,6 +1105,7 @@ static void save_hostlist_file ( int shutdown )
1048 1105
1049 /* add code to write hostlists to file using bio */ 1106 /* add code to write hostlists to file using bio */
1050 ok = GNUNET_YES; 1107 ok = GNUNET_YES;
1108 counter = 0;
1051 while (NULL != (pos = linked_list_head)) 1109 while (NULL != (pos = linked_list_head))
1052 { 1110 {
1053 if ( GNUNET_YES == shutdown) 1111 if ( GNUNET_YES == shutdown)
@@ -1076,9 +1134,17 @@ static void save_hostlist_file ( int shutdown )
1076 ok = GNUNET_NO; 1134 ok = GNUNET_NO;
1077 } 1135 }
1078 } 1136 }
1137
1079 if ( GNUNET_YES == shutdown) 1138 if ( GNUNET_YES == shutdown)
1080 GNUNET_free (pos); 1139 GNUNET_free (pos);
1140 counter ++;
1141 if ( counter >= MAX_NUMBER_HOSTLISTS) break;
1081 } 1142 }
1143 GNUNET_STATISTICS_set (stats,
1144 gettext_noop("# hostlist URIs written to file"),
1145 counter,
1146 GNUNET_YES);
1147
1082 if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) 1148 if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) )
1083 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1149 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1084 _("Error writing hostlist URIs to file `%s'\n"), 1150 _("Error writing hostlist URIs to file `%s'\n"),
@@ -1127,6 +1193,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1127 linked_list_head = NULL; 1193 linked_list_head = NULL;
1128 linked_list_tail = NULL; 1194 linked_list_tail = NULL;
1129 load_hostlist_file (); 1195 load_hostlist_file ();
1196 // schedule_hostlist_saving_task ();
1130 1197
1131 GNUNET_STATISTICS_get (stats, 1198 GNUNET_STATISTICS_get (stats,
1132 "hostlist", 1199 "hostlist",