diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/transport/gnunet-service-transport_hello.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/transport/gnunet-service-transport_hello.c')
-rw-r--r-- | src/transport/gnunet-service-transport_hello.c | 143 |
1 files changed, 64 insertions, 79 deletions
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index f05c0836a..a2d0d966c 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c | |||
@@ -90,7 +90,7 @@ static GST_HelloCallback hello_cb; | |||
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Closure for 'hello_cb'. | 92 | * Closure for 'hello_cb'. |
93 | */ | 93 | */ |
94 | static void *hello_cb_cls; | 94 | static void *hello_cb_cls; |
95 | 95 | ||
96 | /** | 96 | /** |
@@ -118,7 +118,7 @@ struct GeneratorContext | |||
118 | * Where are we in the DLL? | 118 | * Where are we in the DLL? |
119 | */ | 119 | */ |
120 | struct OwnAddressList *addr_pos; | 120 | struct OwnAddressList *addr_pos; |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * When do addresses expire? | 123 | * When do addresses expire? |
124 | */ | 124 | */ |
@@ -140,12 +140,11 @@ address_generator (void *cls, size_t max, void *buf) | |||
140 | size_t ret; | 140 | size_t ret; |
141 | 141 | ||
142 | if (NULL == gc->addr_pos) | 142 | if (NULL == gc->addr_pos) |
143 | return 0; | 143 | return 0; |
144 | ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, | 144 | ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, |
145 | gc->expiration, | 145 | gc->expiration, |
146 | &gc->addr_pos[1], | 146 | &gc->addr_pos[1], |
147 | gc->addr_pos->addrlen, | 147 | gc->addr_pos->addrlen, buf, max); |
148 | buf, max); | ||
149 | gc->addr_pos = gc->addr_pos->next; | 148 | gc->addr_pos = gc->addr_pos->next; |
150 | return ret; | 149 | return ret; |
151 | } | 150 | } |
@@ -159,34 +158,30 @@ address_generator (void *cls, size_t max, void *buf) | |||
159 | * @param tc scheduler context | 158 | * @param tc scheduler context |
160 | */ | 159 | */ |
161 | static void | 160 | static void |
162 | refresh_hello_task (void *cls, | 161 | refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
163 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
164 | { | 162 | { |
165 | struct GeneratorContext gc; | 163 | struct GeneratorContext gc; |
166 | 164 | ||
167 | hello_task = GNUNET_SCHEDULER_NO_TASK; | 165 | hello_task = GNUNET_SCHEDULER_NO_TASK; |
168 | gc.addr_pos = oal_head; | 166 | gc.addr_pos = oal_head; |
169 | gc.expiration = GNUNET_TIME_relative_to_absolute (GST_HELLO_ADDRESS_EXPIRATION); | 167 | gc.expiration = |
168 | GNUNET_TIME_relative_to_absolute (GST_HELLO_ADDRESS_EXPIRATION); | ||
170 | GNUNET_free (our_hello); | 169 | GNUNET_free (our_hello); |
171 | our_hello = GNUNET_HELLO_create (&GST_my_public_key, | 170 | our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc); |
172 | &address_generator, | ||
173 | &gc); | ||
174 | #if DEBUG_TRANSPORT | 171 | #if DEBUG_TRANSPORT |
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
176 | "Refreshed my `%s', new size is %d\n", "HELLO", | 173 | "Refreshed my `%s', new size is %d\n", "HELLO", |
177 | GNUNET_HELLO_size(our_hello)); | 174 | GNUNET_HELLO_size (our_hello)); |
178 | #endif | 175 | #endif |
179 | GNUNET_STATISTICS_update (GST_stats, | 176 | GNUNET_STATISTICS_update (GST_stats, |
180 | gettext_noop ("# refreshed my HELLO"), | 177 | gettext_noop ("# refreshed my HELLO"), |
181 | 1, | 178 | 1, GNUNET_NO); |
182 | GNUNET_NO); | ||
183 | if (NULL != hello_cb) | 179 | if (NULL != hello_cb) |
184 | hello_cb (hello_cb_cls, GST_hello_get()); | 180 | hello_cb (hello_cb_cls, GST_hello_get ()); |
185 | GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello); | 181 | GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello); |
186 | hello_task | 182 | hello_task |
187 | = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, | 183 | = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, |
188 | &refresh_hello_task, | 184 | &refresh_hello_task, NULL); |
189 | NULL); | ||
190 | 185 | ||
191 | } | 186 | } |
192 | 187 | ||
@@ -200,9 +195,7 @@ refresh_hello () | |||
200 | { | 195 | { |
201 | if (hello_task != GNUNET_SCHEDULER_NO_TASK) | 196 | if (hello_task != GNUNET_SCHEDULER_NO_TASK) |
202 | GNUNET_SCHEDULER_cancel (hello_task); | 197 | GNUNET_SCHEDULER_cancel (hello_task); |
203 | hello_task | 198 | hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, NULL); |
204 | = GNUNET_SCHEDULER_add_now (&refresh_hello_task, | ||
205 | NULL); | ||
206 | } | 199 | } |
207 | 200 | ||
208 | 201 | ||
@@ -212,14 +205,12 @@ refresh_hello () | |||
212 | * @param cb function to call whenever our HELLO changes | 205 | * @param cb function to call whenever our HELLO changes |
213 | * @param cb_cls closure for cb | 206 | * @param cb_cls closure for cb |
214 | */ | 207 | */ |
215 | void | 208 | void |
216 | GST_hello_start (GST_HelloCallback cb, | 209 | GST_hello_start (GST_HelloCallback cb, void *cb_cls) |
217 | void *cb_cls) | ||
218 | { | 210 | { |
219 | hello_cb = cb; | 211 | hello_cb = cb; |
220 | hello_cb_cls = cb_cls; | 212 | hello_cb_cls = cb_cls; |
221 | our_hello = GNUNET_HELLO_create (&GST_my_public_key, | 213 | our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL); |
222 | NULL, NULL); | ||
223 | refresh_hello (); | 214 | refresh_hello (); |
224 | } | 215 | } |
225 | 216 | ||
@@ -233,15 +224,15 @@ GST_hello_stop () | |||
233 | hello_cb = NULL; | 224 | hello_cb = NULL; |
234 | hello_cb_cls = NULL; | 225 | hello_cb_cls = NULL; |
235 | if (GNUNET_SCHEDULER_NO_TASK != hello_task) | 226 | if (GNUNET_SCHEDULER_NO_TASK != hello_task) |
236 | { | 227 | { |
237 | GNUNET_SCHEDULER_cancel (hello_task); | 228 | GNUNET_SCHEDULER_cancel (hello_task); |
238 | hello_task = GNUNET_SCHEDULER_NO_TASK; | 229 | hello_task = GNUNET_SCHEDULER_NO_TASK; |
239 | } | 230 | } |
240 | if (NULL != our_hello) | 231 | if (NULL != our_hello) |
241 | { | 232 | { |
242 | GNUNET_free (our_hello); | 233 | GNUNET_free (our_hello); |
243 | our_hello = NULL; | 234 | our_hello = NULL; |
244 | } | 235 | } |
245 | } | 236 | } |
246 | 237 | ||
247 | 238 | ||
@@ -253,7 +244,7 @@ GST_hello_stop () | |||
253 | const struct GNUNET_MessageHeader * | 244 | const struct GNUNET_MessageHeader * |
254 | GST_hello_get () | 245 | GST_hello_get () |
255 | { | 246 | { |
256 | return (struct GNUNET_MessageHeader*) our_hello; | 247 | return (struct GNUNET_MessageHeader *) our_hello; |
257 | } | 248 | } |
258 | 249 | ||
259 | 250 | ||
@@ -267,45 +258,39 @@ GST_hello_get () | |||
267 | */ | 258 | */ |
268 | void | 259 | void |
269 | GST_hello_modify_addresses (int addremove, | 260 | GST_hello_modify_addresses (int addremove, |
270 | const char *plugin_name, | 261 | const char *plugin_name, |
271 | const void *plugin_address, | 262 | const void *plugin_address, |
272 | size_t plugin_address_len) | 263 | size_t plugin_address_len) |
273 | { | 264 | { |
274 | struct OwnAddressList *al; | 265 | struct OwnAddressList *al; |
275 | 266 | ||
276 | #if DEBUG_TRANSPORT | 267 | #if DEBUG_TRANSPORT |
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
278 | (add_remove == GNUNET_YES) | 269 | (add_remove == GNUNET_YES) |
279 | ? "Adding `%s':%s to the set of our addresses\n" | 270 | ? "Adding `%s':%s to the set of our addresses\n" |
280 | : "Removing `%s':%s from the set of our addresses\n", | 271 | : "Removing `%s':%s from the set of our addresses\n", |
281 | GST_plugins_a2s (plugin_name, | 272 | GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name); |
282 | addr, addrlen), | ||
283 | p->short_name); | ||
284 | #endif | 273 | #endif |
285 | GNUNET_assert (plugin_address != NULL); | 274 | GNUNET_assert (plugin_address != NULL); |
286 | if (GNUNET_NO == addremove) | 275 | if (GNUNET_NO == addremove) |
287 | { | 276 | { |
288 | for (al = oal_head; al != NULL; al = al->next) | 277 | for (al = oal_head; al != NULL; al = al->next) |
289 | if ( (plugin_address_len == al->addrlen) && | 278 | if ((plugin_address_len == al->addrlen) && |
290 | (0 == strcmp (al->plugin_name, plugin_name)) && | 279 | (0 == strcmp (al->plugin_name, plugin_name)) && |
291 | (0 == memcmp (plugin_address, &al[1], plugin_address_len)) ) | 280 | (0 == memcmp (plugin_address, &al[1], plugin_address_len))) |
292 | { | 281 | { |
293 | GNUNET_CONTAINER_DLL_remove (oal_head, | 282 | GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al); |
294 | oal_tail, | 283 | GNUNET_free (al->plugin_name); |
295 | al); | 284 | GNUNET_free (al); |
296 | GNUNET_free (al->plugin_name); | 285 | refresh_hello (); |
297 | GNUNET_free (al); | 286 | return; |
298 | refresh_hello (); | 287 | } |
299 | return; | 288 | /* address to be removed not found!? */ |
300 | } | 289 | GNUNET_break (0); |
301 | /* address to be removed not found!? */ | 290 | return; |
302 | GNUNET_break (0); | 291 | } |
303 | return; | ||
304 | } | ||
305 | al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len); | 292 | al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len); |
306 | GNUNET_CONTAINER_DLL_insert (oal_head, | 293 | GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al); |
307 | oal_tail, | ||
308 | al); | ||
309 | al->plugin_name = GNUNET_strdup (plugin_name); | 294 | al->plugin_name = GNUNET_strdup (plugin_name); |
310 | al->addrlen = plugin_address_len; | 295 | al->addrlen = plugin_address_len; |
311 | memcpy (&al[1], plugin_address, plugin_address_len); | 296 | memcpy (&al[1], plugin_address, plugin_address_len); |
@@ -327,22 +312,22 @@ GST_hello_modify_addresses (int addremove, | |||
327 | */ | 312 | */ |
328 | int | 313 | int |
329 | GST_hello_test_address (const char *plugin_name, | 314 | GST_hello_test_address (const char *plugin_name, |
330 | const void *plugin_address, | 315 | const void *plugin_address, |
331 | size_t plugin_address_len, | 316 | size_t plugin_address_len, |
332 | struct GNUNET_CRYPTO_RsaSignature **sig, | 317 | struct GNUNET_CRYPTO_RsaSignature **sig, |
333 | struct GNUNET_TIME_Absolute **sig_expiration) | 318 | struct GNUNET_TIME_Absolute **sig_expiration) |
334 | { | 319 | { |
335 | struct OwnAddressList *al; | 320 | struct OwnAddressList *al; |
336 | 321 | ||
337 | for (al = oal_head; al != NULL; al = al->next) | 322 | for (al = oal_head; al != NULL; al = al->next) |
338 | if ( (plugin_address_len == al->addrlen) && | 323 | if ((plugin_address_len == al->addrlen) && |
339 | (0 == strcmp (al->plugin_name, plugin_name)) && | 324 | (0 == strcmp (al->plugin_name, plugin_name)) && |
340 | (0 == memcmp (plugin_address, &al[1], plugin_address_len)) ) | 325 | (0 == memcmp (plugin_address, &al[1], plugin_address_len))) |
341 | { | 326 | { |
342 | *sig = &al->pong_signature; | 327 | *sig = &al->pong_signature; |
343 | *sig_expiration = &al->pong_sig_expires; | 328 | *sig_expiration = &al->pong_sig_expires; |
344 | return GNUNET_YES; | 329 | return GNUNET_YES; |
345 | } | 330 | } |
346 | *sig = NULL; | 331 | *sig = NULL; |
347 | *sig_expiration = NULL; | 332 | *sig_expiration = NULL; |
348 | return GNUNET_NO; | 333 | return GNUNET_NO; |