diff options
-rw-r--r-- | src/arm/gnunet-arm.c | 91 | ||||
-rw-r--r-- | src/consensus/gnunet-consensus.c | 42 | ||||
-rw-r--r-- | src/util/client.c | 13 | ||||
-rw-r--r-- | src/util/speedup.c | 5 |
4 files changed, 85 insertions, 66 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index a37a78a26..ca4193837 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -128,12 +128,12 @@ static struct GNUNET_TIME_Relative timeout; | |||
128 | /** | 128 | /** |
129 | * Do we want to give our stdout to gnunet-service-arm? | 129 | * Do we want to give our stdout to gnunet-service-arm? |
130 | */ | 130 | */ |
131 | static unsigned int no_stdout = 0; | 131 | static unsigned int no_stdout; |
132 | 132 | ||
133 | /** | 133 | /** |
134 | * Do we want to give our stderr to gnunet-service-arm? | 134 | * Do we want to give our stderr to gnunet-service-arm? |
135 | */ | 135 | */ |
136 | static unsigned int no_stderr = 0; | 136 | static unsigned int no_stderr; |
137 | 137 | ||
138 | 138 | ||
139 | /** | 139 | /** |
@@ -206,8 +206,7 @@ confirm_cb (void *cls, | |||
206 | FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n")); | 206 | FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n")); |
207 | break; | 207 | break; |
208 | } | 208 | } |
209 | GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, | 209 | GNUNET_SCHEDULER_add_now (&cps_loop, NULL); |
210 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
211 | } | 210 | } |
212 | 211 | ||
213 | 212 | ||
@@ -237,6 +236,50 @@ list_cb (void *cls, int result, unsigned int count, const char *const*list) | |||
237 | 236 | ||
238 | 237 | ||
239 | /** | 238 | /** |
239 | * Attempts to delete configuration file and SERVICEHOME | ||
240 | * on arm shutdown provided the end and delete options | ||
241 | * were specified when gnunet-arm was run. | ||
242 | */ | ||
243 | static void | ||
244 | delete_files () | ||
245 | { | ||
246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
247 | "Will attempt to remove configuration file %s and service directory %s\n", | ||
248 | config_file, dir); | ||
249 | |||
250 | if (UNLINK (config_file) != 0) | ||
251 | { | ||
252 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
253 | _("Failed to remove configuration file %s\n"), config_file); | ||
254 | } | ||
255 | |||
256 | if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK) | ||
257 | { | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
259 | _("Failed to remove servicehome directory %s\n"), dir); | ||
260 | |||
261 | } | ||
262 | } | ||
263 | |||
264 | |||
265 | /** | ||
266 | * Main continuation-passing-style loop. Runs the various | ||
267 | * jobs that we've been asked to do in order. | ||
268 | * | ||
269 | * @param cls closure, unused | ||
270 | * @param tc context, unused | ||
271 | */ | ||
272 | static void | ||
273 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
274 | { | ||
275 | GNUNET_ARM_disconnect (h); | ||
276 | h = NULL; | ||
277 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) | ||
278 | delete_files (); | ||
279 | } | ||
280 | |||
281 | |||
282 | /** | ||
240 | * Main function that will be run by the scheduler. | 283 | * Main function that will be run by the scheduler. |
241 | * | 284 | * |
242 | * @param cls closure | 285 | * @param cls closure |
@@ -264,35 +307,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
264 | ret = 1; | 307 | ret = 1; |
265 | return; | 308 | return; |
266 | } | 309 | } |
267 | GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, | 310 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
268 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 311 | &shutdown_task, NULL); |
269 | } | 312 | GNUNET_SCHEDULER_add_now (&cps_loop, NULL); |
270 | |||
271 | |||
272 | /** | ||
273 | * Attempts to delete configuration file and SERVICEHOME | ||
274 | * on arm shutdown provided the end and delete options | ||
275 | * were specified when gnunet-arm was run. | ||
276 | */ | ||
277 | static void | ||
278 | delete_files () | ||
279 | { | ||
280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
281 | "Will attempt to remove configuration file %s and service directory %s\n", | ||
282 | config_file, dir); | ||
283 | |||
284 | if (UNLINK (config_file) != 0) | ||
285 | { | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
287 | _("Failed to remove configuration file %s\n"), config_file); | ||
288 | } | ||
289 | |||
290 | if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK) | ||
291 | { | ||
292 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
293 | _("Failed to remove servicehome directory %s\n"), dir); | ||
294 | |||
295 | } | ||
296 | } | 313 | } |
297 | 314 | ||
298 | 315 | ||
@@ -306,6 +323,10 @@ delete_files () | |||
306 | static void | 323 | static void |
307 | cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 324 | cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
308 | { | 325 | { |
326 | if (NULL == h) | ||
327 | return; | ||
328 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
329 | return; | ||
309 | while (1) | 330 | while (1) |
310 | { | 331 | { |
311 | switch (phase++) | 332 | switch (phase++) |
@@ -393,9 +414,7 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
393 | } | 414 | } |
394 | /* Fall through */ | 415 | /* Fall through */ |
395 | default: /* last phase */ | 416 | default: /* last phase */ |
396 | GNUNET_ARM_disconnect (h); | 417 | GNUNET_SCHEDULER_shutdown (); |
397 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) | ||
398 | delete_files (); | ||
399 | return; | 418 | return; |
400 | } | 419 | } |
401 | } | 420 | } |
diff --git a/src/consensus/gnunet-consensus.c b/src/consensus/gnunet-consensus.c index 12d0965e9..bc518657e 100644 --- a/src/consensus/gnunet-consensus.c +++ b/src/consensus/gnunet-consensus.c | |||
@@ -48,12 +48,6 @@ static struct GNUNET_DISK_FileHandle *stdin_fh; | |||
48 | */ | 48 | */ |
49 | static GNUNET_SCHEDULER_TaskIdentifier stdin_tid = GNUNET_SCHEDULER_NO_TASK; | 49 | static GNUNET_SCHEDULER_TaskIdentifier stdin_tid = GNUNET_SCHEDULER_NO_TASK; |
50 | 50 | ||
51 | /** | ||
52 | * Element currently being sent to the service | ||
53 | */ | ||
54 | static struct GNUNET_CONSENSUS_Element *element; | ||
55 | |||
56 | |||
57 | 51 | ||
58 | static void | 52 | static void |
59 | stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 53 | stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
@@ -76,23 +70,22 @@ conclude_cb (void *cls, | |||
76 | } | 70 | } |
77 | 71 | ||
78 | 72 | ||
79 | |||
80 | static void | 73 | static void |
81 | insert_done_cb (void *cls, | 74 | insert_done_cb (void *cls, |
82 | int success) | 75 | int success) |
83 | { | 76 | { |
77 | struct GNUNET_CONSENSUS_Element *element = cls; | ||
78 | |||
79 | GNUNET_free (element); | ||
84 | if (GNUNET_YES != success) | 80 | if (GNUNET_YES != success) |
85 | { | 81 | { |
86 | printf ("insert failed\n"); | 82 | printf ("insert failed\n"); |
87 | GNUNET_SCHEDULER_shutdown (); | 83 | GNUNET_SCHEDULER_shutdown (); |
84 | return; | ||
88 | } | 85 | } |
89 | |||
90 | GNUNET_free (element); | ||
91 | |||
92 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == stdin_tid); | 86 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == stdin_tid); |
93 | |||
94 | stdin_tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fh, | 87 | stdin_tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fh, |
95 | &stdin_cb, NULL); | 88 | &stdin_cb, NULL); |
96 | } | 89 | } |
97 | 90 | ||
98 | 91 | ||
@@ -107,10 +100,12 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
107 | { | 100 | { |
108 | char buf[1024]; | 101 | char buf[1024]; |
109 | char *ret; | 102 | char *ret; |
110 | ret = fgets (buf, 1024, stdin); | 103 | struct GNUNET_CONSENSUS_Element *element; |
111 | 104 | ||
112 | stdin_tid = GNUNET_SCHEDULER_NO_TASK; | 105 | stdin_tid = GNUNET_SCHEDULER_NO_TASK; |
113 | 106 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | |
107 | return; /* we're done here */ | ||
108 | ret = fgets (buf, 1024, stdin); | ||
114 | if (NULL == ret) | 109 | if (NULL == ret) |
115 | { | 110 | { |
116 | if (feof (stdin)) | 111 | if (feof (stdin)) |
@@ -118,10 +113,6 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
118 | printf ("concluding ...\n"); | 113 | printf ("concluding ...\n"); |
119 | GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, conclude_cb, NULL); | 114 | GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, conclude_cb, NULL); |
120 | } | 115 | } |
121 | else | ||
122 | { | ||
123 | GNUNET_SCHEDULER_shutdown (); | ||
124 | } | ||
125 | return; | 116 | return; |
126 | } | 117 | } |
127 | 118 | ||
@@ -131,11 +122,11 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
131 | element->type = 0; | 122 | element->type = 0; |
132 | element->size = strlen(buf) + 1; | 123 | element->size = strlen(buf) + 1; |
133 | element->data = &element[1]; | 124 | element->data = &element[1]; |
134 | strcpy((char *) &element[1], buf); | 125 | strcpy ((char *) &element[1], buf); |
135 | 126 | GNUNET_CONSENSUS_insert (consensus, element, &insert_done_cb, element); | |
136 | GNUNET_CONSENSUS_insert (consensus, element, insert_done_cb, NULL); | ||
137 | } | 127 | } |
138 | 128 | ||
129 | |||
139 | /** | 130 | /** |
140 | * Called when a new element was received from another peer, or an error occured. | 131 | * Called when a new element was received from another peer, or an error occured. |
141 | * | 132 | * |
@@ -157,6 +148,7 @@ cb (void *cls, | |||
157 | return GNUNET_YES; | 148 | return GNUNET_YES; |
158 | } | 149 | } |
159 | 150 | ||
151 | |||
160 | /** | 152 | /** |
161 | * Function run on shutdown to clean up. | 153 | * Function run on shutdown to clean up. |
162 | * | 154 | * |
@@ -166,14 +158,12 @@ cb (void *cls, | |||
166 | static void | 158 | static void |
167 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 159 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
168 | { | 160 | { |
169 | |||
170 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "shutting down\n"); | 161 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "shutting down\n"); |
171 | if (NULL == consensus) | 162 | if (NULL != consensus) |
172 | { | 163 | { |
173 | return; | 164 | GNUNET_CONSENSUS_destroy (consensus); |
165 | consensus = NULL; | ||
174 | } | 166 | } |
175 | |||
176 | GNUNET_CONSENSUS_destroy (consensus); | ||
177 | } | 167 | } |
178 | 168 | ||
179 | 169 | ||
diff --git a/src/util/client.c b/src/util/client.c index 81c696a7b..69380c9b0 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -943,8 +943,16 @@ client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
943 | { | 943 | { |
944 | struct GNUNET_CLIENT_TransmitHandle *th = cls; | 944 | struct GNUNET_CLIENT_TransmitHandle *th = cls; |
945 | struct GNUNET_TIME_Relative delay; | 945 | struct GNUNET_TIME_Relative delay; |
946 | 946 | ||
947 | th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 947 | th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
948 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
949 | { | ||
950 | /* give up, was shutdown */ | ||
951 | th->client->th = NULL; | ||
952 | th->notify (th->notify_cls, 0, NULL); | ||
953 | GNUNET_free (th); | ||
954 | return; | ||
955 | } | ||
948 | th->client->connection = | 956 | th->client->connection = |
949 | do_connect (th->client->service_name, th->client->cfg, th->client->attempts++); | 957 | do_connect (th->client->service_name, th->client->cfg, th->client->attempts++); |
950 | th->client->first_message = GNUNET_YES; | 958 | th->client->first_message = GNUNET_YES; |
@@ -1006,7 +1014,8 @@ client_notify (void *cls, size_t size, void *buf) | |||
1006 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); | 1014 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); |
1007 | delay.rel_value /= 2; | 1015 | delay.rel_value /= 2; |
1008 | if ((GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) || | 1016 | if ((GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) || |
1009 | (delay.rel_value < 1)) | 1017 | (delay.rel_value < 1)|| |
1018 | (0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | ||
1010 | { | 1019 | { |
1011 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1020 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1012 | "Transmission failed %u times, giving up.\n", | 1021 | "Transmission failed %u times, giving up.\n", |
diff --git a/src/util/speedup.c b/src/util/speedup.c index 0a005c035..e5f71d063 100644 --- a/src/util/speedup.c +++ b/src/util/speedup.c | |||
@@ -83,8 +83,9 @@ GNUNET_SPEEDUP_stop_ ( ) | |||
83 | GNUNET_SCHEDULER_cancel (speedup_task); | 83 | GNUNET_SCHEDULER_cancel (speedup_task); |
84 | speedup_task = GNUNET_SCHEDULER_NO_TASK; | 84 | speedup_task = GNUNET_SCHEDULER_NO_TASK; |
85 | } | 85 | } |
86 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 86 | if ((0 != interval.rel_value) && (0 != delta.rel_value)) |
87 | "Stopped execution speed up\n"); | 87 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
88 | "Stopped execution speed up\n"); | ||
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||