diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-05-17 17:42:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-05-17 17:42:56 +0000 |
commit | bb63c3f4a8db3ab978b93cb23d721f0a8dbef44c (patch) | |
tree | 00be2d8e9dd373a219baced01e975cce582bffc8 /src | |
parent | 85fceba1176722c570ce0542daf91d46b6706541 (diff) | |
download | gnunet-bb63c3f4a8db3ab978b93cb23d721f0a8dbef44c.tar.gz gnunet-bb63c3f4a8db3ab978b93cb23d721f0a8dbef44c.zip |
-fully abort and restart existing iteration on notify
Diffstat (limited to 'src')
-rw-r--r-- | src/hostlist/hostlist-server.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 987cbe713..b9e1e6cf1 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c | |||
@@ -79,11 +79,6 @@ static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v6; | |||
79 | static struct MHD_Response *response; | 79 | static struct MHD_Response *response; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * NULL if we are not currenlty iterating over peer information. | ||
83 | */ | ||
84 | static struct GNUNET_PEERINFO_IteratorContext *pitr; | ||
85 | |||
86 | /** | ||
87 | * Handle for accessing peerinfo service. | 82 | * Handle for accessing peerinfo service. |
88 | */ | 83 | */ |
89 | static struct GNUNET_PEERINFO_Handle *peerinfo; | 84 | static struct GNUNET_PEERINFO_Handle *peerinfo; |
@@ -99,7 +94,6 @@ static int advertising; | |||
99 | static char *hostlist_uri; | 94 | static char *hostlist_uri; |
100 | 95 | ||
101 | 96 | ||
102 | |||
103 | /** | 97 | /** |
104 | * Context for host processor. | 98 | * Context for host processor. |
105 | */ | 99 | */ |
@@ -108,23 +102,32 @@ struct HostSet | |||
108 | unsigned int size; | 102 | unsigned int size; |
109 | 103 | ||
110 | char *data; | 104 | char *data; |
105 | |||
106 | struct GNUNET_PEERINFO_IteratorContext *pitr; | ||
111 | }; | 107 | }; |
112 | 108 | ||
113 | 109 | ||
110 | /** | ||
111 | * NULL if we are not currenlty iterating over peer information. | ||
112 | */ | ||
113 | static struct HostSet *builder; | ||
114 | |||
115 | |||
116 | |||
114 | 117 | ||
115 | /** | 118 | /** |
116 | * Function that assembles our response. | 119 | * Function that assembles our response. |
117 | */ | 120 | */ |
118 | static void | 121 | static void |
119 | finish_response (struct HostSet *results) | 122 | finish_response () |
120 | { | 123 | { |
121 | if (NULL != response) | 124 | if (NULL != response) |
122 | MHD_destroy_response (response); | 125 | MHD_destroy_response (response); |
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
124 | "Creating hostlist response with %u bytes\n", | 127 | "Creating hostlist response with %u bytes\n", |
125 | (unsigned int) results->size); | 128 | (unsigned int) builder->size); |
126 | response = | 129 | response = |
127 | MHD_create_response_from_data (results->size, results->data, MHD_YES, | 130 | MHD_create_response_from_data (builder->size, builder->data, MHD_YES, |
128 | MHD_NO); | 131 | MHD_NO); |
129 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) | 132 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) |
130 | { | 133 | { |
@@ -132,8 +135,9 @@ finish_response (struct HostSet *results) | |||
132 | response = NULL; | 135 | response = NULL; |
133 | } | 136 | } |
134 | GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"), | 137 | GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"), |
135 | results->size, GNUNET_YES); | 138 | builder->size, GNUNET_YES); |
136 | GNUNET_free (results); | 139 | GNUNET_free (builder); |
140 | builder = NULL; | ||
137 | } | 141 | } |
138 | 142 | ||
139 | 143 | ||
@@ -171,7 +175,6 @@ static void | |||
171 | host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | 175 | host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, |
172 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 176 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
173 | { | 177 | { |
174 | struct HostSet *results = cls; | ||
175 | size_t old; | 178 | size_t old; |
176 | size_t s; | 179 | size_t s; |
177 | int has_addr; | 180 | int has_addr; |
@@ -179,7 +182,9 @@ host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
179 | if (NULL != err_msg) | 182 | if (NULL != err_msg) |
180 | { | 183 | { |
181 | GNUNET_assert (NULL == peer); | 184 | GNUNET_assert (NULL == peer); |
182 | pitr = NULL; | 185 | builder->pitr = NULL; |
186 | GNUNET_free_non_null (builder->data); | ||
187 | GNUNET_free (builder); | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
184 | _("Error in communication with PEERINFO service: %s\n"), | 189 | _("Error in communication with PEERINFO service: %s\n"), |
185 | err_msg); | 190 | err_msg); |
@@ -187,8 +192,8 @@ host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
187 | } | 192 | } |
188 | if (NULL == peer) | 193 | if (NULL == peer) |
189 | { | 194 | { |
190 | pitr = NULL; | 195 | builder->pitr = NULL; |
191 | finish_response (results); | 196 | finish_response (); |
192 | return; | 197 | return; |
193 | } | 198 | } |
194 | if (NULL == hello) | 199 | if (NULL == hello) |
@@ -206,7 +211,7 @@ host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
206 | 1, GNUNET_NO); | 211 | 1, GNUNET_NO); |
207 | return; | 212 | return; |
208 | } | 213 | } |
209 | old = results->size; | 214 | old = builder->size; |
210 | s = GNUNET_HELLO_size (hello); | 215 | s = GNUNET_HELLO_size (hello); |
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
212 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", | 217 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", |
@@ -223,8 +228,8 @@ host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
223 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 228 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
224 | "Adding peer `%s' to hostlist (%u bytes)\n", GNUNET_i2s (peer), | 229 | "Adding peer `%s' to hostlist (%u bytes)\n", GNUNET_i2s (peer), |
225 | (unsigned int) s); | 230 | (unsigned int) s); |
226 | GNUNET_array_grow (results->data, results->size, old + s); | 231 | GNUNET_array_grow (builder->data, builder->size, old + s); |
227 | memcpy (&results->data[old], hello, s); | 232 | memcpy (&builder->data[old], hello, s); |
228 | } | 233 | } |
229 | 234 | ||
230 | 235 | ||
@@ -412,21 +417,28 @@ static void | |||
412 | process_notify (void *cls, const struct GNUNET_PeerIdentity *peer, | 417 | process_notify (void *cls, const struct GNUNET_PeerIdentity *peer, |
413 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 418 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
414 | { | 419 | { |
415 | struct HostSet *results; | ||
416 | |||
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
418 | "Peerinfo is notifying us to rebuild our hostlist\n"); | 421 | "Peerinfo is notifying us to rebuild our hostlist\n"); |
419 | if (NULL != err_msg) | 422 | if (NULL != err_msg) |
420 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 423 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
421 | _("Error in communication with PEERINFO service: %s\n"), | 424 | _("Error in communication with PEERINFO service: %s\n"), |
422 | err_msg); | 425 | err_msg); |
423 | if (NULL != pitr) | 426 | if (NULL != builder) |
424 | return; /* re-build already in progress ... */ | 427 | { |
425 | results = GNUNET_malloc (sizeof (struct HostSet)); | 428 | /* restart re-build already in progress ... */ |
429 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); | ||
430 | GNUNET_free_non_null (builder->data); | ||
431 | builder->size = 0; | ||
432 | builder->data = NULL; | ||
433 | } | ||
434 | else | ||
435 | { | ||
436 | builder = GNUNET_malloc (sizeof (struct HostSet)); | ||
437 | } | ||
426 | GNUNET_assert (NULL != peerinfo); | 438 | GNUNET_assert (NULL != peerinfo); |
427 | pitr = | 439 | builder->pitr = |
428 | GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, GNUNET_TIME_UNIT_MINUTES, | 440 | GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, GNUNET_TIME_UNIT_MINUTES, |
429 | &host_processor, results); | 441 | &host_processor, NULL); |
430 | } | 442 | } |
431 | 443 | ||
432 | 444 | ||
@@ -716,10 +728,12 @@ GNUNET_HOSTLIST_server_stop () | |||
716 | GNUNET_PEERINFO_notify_cancel (notify); | 728 | GNUNET_PEERINFO_notify_cancel (notify); |
717 | notify = NULL; | 729 | notify = NULL; |
718 | } | 730 | } |
719 | if (NULL != pitr) | 731 | if (NULL != builder) |
720 | { | 732 | { |
721 | GNUNET_PEERINFO_iterate_cancel (pitr); | 733 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); |
722 | pitr = NULL; | 734 | builder->pitr = NULL; |
735 | GNUNET_free_non_null (builder->data); | ||
736 | GNUNET_free (builder); | ||
723 | } | 737 | } |
724 | if (NULL != peerinfo) | 738 | if (NULL != peerinfo) |
725 | { | 739 | { |