diff options
Diffstat (limited to 'src/transport/transport_api2_core.c')
-rw-r--r-- | src/transport/transport_api2_core.c | 484 |
1 files changed, 243 insertions, 241 deletions
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c index 1d2d84bdf..cd8bacf3d 100644 --- a/src/transport/transport_api2_core.c +++ b/src/transport/transport_api2_core.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "gnunet_transport_core_service.h" | 32 | #include "gnunet_transport_core_service.h" |
33 | #include "transport.h" | 33 | #include "transport.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * How large to start with for the hashmap of neighbours. | 38 | * How large to start with for the hashmap of neighbours. |
@@ -53,7 +53,8 @@ | |||
53 | /** | 53 | /** |
54 | * Entry in hash table of all of our current (connected) neighbours. | 54 | * Entry in hash table of all of our current (connected) neighbours. |
55 | */ | 55 | */ |
56 | struct Neighbour { | 56 | struct Neighbour |
57 | { | ||
57 | /** | 58 | /** |
58 | * Identity of this neighbour. | 59 | * Identity of this neighbour. |
59 | */ | 60 | */ |
@@ -105,7 +106,8 @@ struct Neighbour { | |||
105 | * Handle for the transport service (includes all of the | 106 | * Handle for the transport service (includes all of the |
106 | * state for the transport service). | 107 | * state for the transport service). |
107 | */ | 108 | */ |
108 | struct GNUNET_TRANSPORT_CoreHandle { | 109 | struct GNUNET_TRANSPORT_CoreHandle |
110 | { | ||
109 | /** | 111 | /** |
110 | * Closure for the callbacks. | 112 | * Closure for the callbacks. |
111 | */ | 113 | */ |
@@ -173,7 +175,7 @@ struct GNUNET_TRANSPORT_CoreHandle { | |||
173 | * @param h transport service to reconnect | 175 | * @param h transport service to reconnect |
174 | */ | 176 | */ |
175 | static void | 177 | static void |
176 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); | 178 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); |
177 | 179 | ||
178 | 180 | ||
179 | /** | 181 | /** |
@@ -184,10 +186,10 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); | |||
184 | * @return NULL if no such peer entry exists | 186 | * @return NULL if no such peer entry exists |
185 | */ | 187 | */ |
186 | static struct Neighbour * | 188 | static struct Neighbour * |
187 | neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, | 189 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, |
188 | const struct GNUNET_PeerIdentity *peer) | 190 | const struct GNUNET_PeerIdentity *peer) |
189 | { | 191 | { |
190 | return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); | 192 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); |
191 | } | 193 | } |
192 | 194 | ||
193 | 195 | ||
@@ -202,27 +204,27 @@ neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, | |||
202 | * #GNUNET_NO if not. | 204 | * #GNUNET_NO if not. |
203 | */ | 205 | */ |
204 | static int | 206 | static int |
205 | neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 207 | neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
206 | { | 208 | { |
207 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; | 209 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; |
208 | struct Neighbour *n = value; | 210 | struct Neighbour *n = value; |
209 | 211 | ||
210 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 212 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
211 | "Dropping entry for neighbour `%s'.\n", | 213 | "Dropping entry for neighbour `%s'.\n", |
212 | GNUNET_i2s(key)); | 214 | GNUNET_i2s (key)); |
213 | if (NULL != handle->nd_cb) | 215 | if (NULL != handle->nd_cb) |
214 | handle->nd_cb(handle->cls, &n->id, n->handlers_cls); | 216 | handle->nd_cb (handle->cls, &n->id, n->handlers_cls); |
215 | if (NULL != n->env) | 217 | if (NULL != n->env) |
216 | { | 218 | { |
217 | GNUNET_MQ_send_cancel(n->env); | 219 | GNUNET_MQ_send_cancel (n->env); |
218 | n->env = NULL; | 220 | n->env = NULL; |
219 | } | 221 | } |
220 | GNUNET_MQ_destroy(n->mq); | 222 | GNUNET_MQ_destroy (n->mq); |
221 | GNUNET_assert(NULL == n->mq); | 223 | GNUNET_assert (NULL == n->mq); |
222 | GNUNET_assert( | 224 | GNUNET_assert ( |
223 | GNUNET_YES == | 225 | GNUNET_YES == |
224 | GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); | 226 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); |
225 | GNUNET_free(n); | 227 | GNUNET_free (n); |
226 | return GNUNET_YES; | 228 | return GNUNET_YES; |
227 | } | 229 | } |
228 | 230 | ||
@@ -237,13 +239,13 @@ neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
237 | * @param error error code | 239 | * @param error error code |
238 | */ | 240 | */ |
239 | static void | 241 | static void |
240 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 242 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
241 | { | 243 | { |
242 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 244 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
243 | 245 | ||
244 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 246 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
245 | "Error receiving from transport service, disconnecting temporarily.\n"); | 247 | "Error receiving from transport service, disconnecting temporarily.\n"); |
246 | disconnect_and_schedule_reconnect(h); | 248 | disconnect_and_schedule_reconnect (h); |
247 | } | 249 | } |
248 | 250 | ||
249 | 251 | ||
@@ -258,13 +260,13 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
258 | * @param cls the `struct Neighbour` where the message was sent | 260 | * @param cls the `struct Neighbour` where the message was sent |
259 | */ | 261 | */ |
260 | static void | 262 | static void |
261 | notify_send_done(void *cls) | 263 | notify_send_done (void *cls) |
262 | { | 264 | { |
263 | struct Neighbour *n = cls; | 265 | struct Neighbour *n = cls; |
264 | 266 | ||
265 | n->awaiting_done = GNUNET_NO; | 267 | n->awaiting_done = GNUNET_NO; |
266 | n->env = NULL; | 268 | n->env = NULL; |
267 | GNUNET_MQ_impl_send_continue(n->mq); | 269 | GNUNET_MQ_impl_send_continue (n->mq); |
268 | } | 270 | } |
269 | 271 | ||
270 | 272 | ||
@@ -275,18 +277,18 @@ notify_send_done(void *cls) | |||
275 | * @param n neighbour to perform transmission for | 277 | * @param n neighbour to perform transmission for |
276 | */ | 278 | */ |
277 | static void | 279 | static void |
278 | do_send(struct Neighbour *n) | 280 | do_send (struct Neighbour *n) |
279 | { | 281 | { |
280 | GNUNET_assert(0 < n->ready_window); | 282 | GNUNET_assert (0 < n->ready_window); |
281 | GNUNET_assert(NULL != n->env); | 283 | GNUNET_assert (NULL != n->env); |
282 | n->ready_window--; | 284 | n->ready_window--; |
283 | n->awaiting_done = GNUNET_YES; | 285 | n->awaiting_done = GNUNET_YES; |
284 | GNUNET_MQ_notify_sent(n->env, ¬ify_send_done, n); | 286 | GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); |
285 | GNUNET_MQ_send(n->h->mq, n->env); | 287 | GNUNET_MQ_send (n->h->mq, n->env); |
286 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 288 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
287 | "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", | 289 | "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", |
288 | ntohs(GNUNET_MQ_env_get_msg(n->env)->type), | 290 | ntohs (GNUNET_MQ_env_get_msg (n->env)->type), |
289 | GNUNET_i2s(&n->id)); | 291 | GNUNET_i2s (&n->id)); |
290 | } | 292 | } |
291 | 293 | ||
292 | 294 | ||
@@ -301,44 +303,44 @@ do_send(struct Neighbour *n) | |||
301 | * @param impl_state state of the implementation | 303 | * @param impl_state state of the implementation |
302 | */ | 304 | */ |
303 | static void | 305 | static void |
304 | mq_send_impl(struct GNUNET_MQ_Handle *mq, | 306 | mq_send_impl (struct GNUNET_MQ_Handle *mq, |
305 | const struct GNUNET_MessageHeader *msg, | 307 | const struct GNUNET_MessageHeader *msg, |
306 | void *impl_state) | 308 | void *impl_state) |
307 | { | 309 | { |
308 | struct Neighbour *n = impl_state; | 310 | struct Neighbour *n = impl_state; |
309 | struct OutboundMessage *obm; | 311 | struct OutboundMessage *obm; |
310 | uint16_t msize; | 312 | uint16_t msize; |
311 | 313 | ||
312 | msize = ntohs(msg->size); | 314 | msize = ntohs (msg->size); |
313 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) | 315 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) |
314 | { | 316 | { |
315 | GNUNET_break(0); | 317 | GNUNET_break (0); |
316 | GNUNET_MQ_impl_send_continue(mq); | 318 | GNUNET_MQ_impl_send_continue (mq); |
317 | return; | 319 | return; |
318 | } | 320 | } |
319 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 321 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
320 | "CORE requested transmission of message of type %u to neighbour `%s'.\n", | 322 | "CORE requested transmission of message of type %u to neighbour `%s'.\n", |
321 | ntohs(msg->type), | 323 | ntohs (msg->type), |
322 | GNUNET_i2s(&n->id)); | 324 | GNUNET_i2s (&n->id)); |
323 | 325 | ||
324 | GNUNET_assert(NULL == n->env); | 326 | GNUNET_assert (NULL == n->env); |
325 | n->env = | 327 | n->env = |
326 | GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); | 328 | GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); |
327 | n->env_size = ntohs(msg->size); | 329 | n->env_size = ntohs (msg->size); |
328 | { | 330 | { |
329 | struct GNUNET_MQ_Envelope *env; | 331 | struct GNUNET_MQ_Envelope *env; |
330 | 332 | ||
331 | env = GNUNET_MQ_get_current_envelope(mq); | 333 | env = GNUNET_MQ_get_current_envelope (mq); |
332 | obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); | 334 | obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); |
333 | } | 335 | } |
334 | obm->peer = n->id; | 336 | obm->peer = n->id; |
335 | if (0 == n->ready_window) | 337 | if (0 == n->ready_window) |
336 | { | 338 | { |
337 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 339 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Flow control delays transmission to CORE until we see SEND_OK.\n"); | 340 | "Flow control delays transmission to CORE until we see SEND_OK.\n"); |
339 | return; /* can't send yet, need to wait for SEND_OK */ | 341 | return; /* can't send yet, need to wait for SEND_OK */ |
340 | } | 342 | } |
341 | do_send(n); | 343 | do_send (n); |
342 | } | 344 | } |
343 | 345 | ||
344 | 346 | ||
@@ -350,11 +352,11 @@ mq_send_impl(struct GNUNET_MQ_Handle *mq, | |||
350 | * @param impl_state state of the implementation | 352 | * @param impl_state state of the implementation |
351 | */ | 353 | */ |
352 | static void | 354 | static void |
353 | mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) | 355 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
354 | { | 356 | { |
355 | struct Neighbour *n = impl_state; | 357 | struct Neighbour *n = impl_state; |
356 | 358 | ||
357 | GNUNET_assert(mq == n->mq); | 359 | GNUNET_assert (mq == n->mq); |
358 | n->mq = NULL; | 360 | n->mq = NULL; |
359 | } | 361 | } |
360 | 362 | ||
@@ -367,22 +369,22 @@ mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
367 | * @param impl_state state specific to the implementation | 369 | * @param impl_state state specific to the implementation |
368 | */ | 370 | */ |
369 | static void | 371 | static void |
370 | mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) | 372 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
371 | { | 373 | { |
372 | struct Neighbour *n = impl_state; | 374 | struct Neighbour *n = impl_state; |
373 | 375 | ||
374 | n->ready_window++; | 376 | n->ready_window++; |
375 | if (GNUNET_YES == n->awaiting_done) | 377 | if (GNUNET_YES == n->awaiting_done) |
376 | { | 378 | { |
377 | GNUNET_MQ_send_cancel(n->env); | 379 | GNUNET_MQ_send_cancel (n->env); |
378 | n->env = NULL; | 380 | n->env = NULL; |
379 | n->awaiting_done = GNUNET_NO; | 381 | n->awaiting_done = GNUNET_NO; |
380 | } | 382 | } |
381 | else | 383 | else |
382 | { | 384 | { |
383 | GNUNET_assert(0 == n->ready_window); | 385 | GNUNET_assert (0 == n->ready_window); |
384 | n->env = NULL; | 386 | n->env = NULL; |
385 | } | 387 | } |
386 | } | 388 | } |
387 | 389 | ||
388 | 390 | ||
@@ -395,11 +397,11 @@ mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
395 | * @param error error code | 397 | * @param error error code |
396 | */ | 398 | */ |
397 | static void | 399 | static void |
398 | peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 400 | peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
399 | { | 401 | { |
400 | /* struct Neighbour *n = cls; */ | 402 | /* struct Neighbour *n = cls; */ |
401 | 403 | ||
402 | GNUNET_break_op(0); | 404 | GNUNET_break_op (0); |
403 | } | 405 | } |
404 | 406 | ||
405 | 407 | ||
@@ -410,44 +412,44 @@ peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
410 | * @param cim message received | 412 | * @param cim message received |
411 | */ | 413 | */ |
412 | static void | 414 | static void |
413 | handle_connect(void *cls, const struct ConnectInfoMessage *cim) | 415 | handle_connect (void *cls, const struct ConnectInfoMessage *cim) |
414 | { | 416 | { |
415 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 417 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
416 | struct Neighbour *n; | 418 | struct Neighbour *n; |
417 | 419 | ||
418 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 420 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
419 | "Receiving CONNECT message for `%s'\n", | 421 | "Receiving CONNECT message for `%s'\n", |
420 | GNUNET_i2s(&cim->id)); | 422 | GNUNET_i2s (&cim->id)); |
421 | n = neighbour_find(h, &cim->id); | 423 | n = neighbour_find (h, &cim->id); |
422 | if (NULL != n) | 424 | if (NULL != n) |
423 | { | 425 | { |
424 | GNUNET_break(0); | 426 | GNUNET_break (0); |
425 | disconnect_and_schedule_reconnect(h); | 427 | disconnect_and_schedule_reconnect (h); |
426 | return; | 428 | return; |
427 | } | 429 | } |
428 | n = GNUNET_new(struct Neighbour); | 430 | n = GNUNET_new (struct Neighbour); |
429 | n->id = cim->id; | 431 | n->id = cim->id; |
430 | n->h = h; | 432 | n->h = h; |
431 | n->ready_window = SEND_WINDOW_SIZE; | 433 | n->ready_window = SEND_WINDOW_SIZE; |
432 | GNUNET_assert(GNUNET_OK == | 434 | GNUNET_assert (GNUNET_OK == |
433 | GNUNET_CONTAINER_multipeermap_put( | 435 | GNUNET_CONTAINER_multipeermap_put ( |
434 | h->neighbours, | 436 | h->neighbours, |
435 | &n->id, | 437 | &n->id, |
436 | n, | 438 | n, |
437 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 439 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
438 | 440 | ||
439 | n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, | 441 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, |
440 | &mq_destroy_impl, | 442 | &mq_destroy_impl, |
441 | &mq_cancel_impl, | 443 | &mq_cancel_impl, |
442 | n, | 444 | n, |
443 | h->handlers, | 445 | h->handlers, |
444 | &peer_mq_error_handler, | 446 | &peer_mq_error_handler, |
445 | n); | 447 | n); |
446 | if (NULL != h->nc_cb) | 448 | if (NULL != h->nc_cb) |
447 | { | 449 | { |
448 | n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); | 450 | n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); |
449 | GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); | 451 | GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); |
450 | } | 452 | } |
451 | } | 453 | } |
452 | 454 | ||
453 | 455 | ||
@@ -458,23 +460,23 @@ handle_connect(void *cls, const struct ConnectInfoMessage *cim) | |||
458 | * @param dim message received | 460 | * @param dim message received |
459 | */ | 461 | */ |
460 | static void | 462 | static void |
461 | handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) | 463 | handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) |
462 | { | 464 | { |
463 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 465 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
464 | struct Neighbour *n; | 466 | struct Neighbour *n; |
465 | 467 | ||
466 | GNUNET_break(ntohl(dim->reserved) == 0); | 468 | GNUNET_break (ntohl (dim->reserved) == 0); |
467 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 469 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
468 | "Receiving DISCONNECT message for `%s'.\n", | 470 | "Receiving DISCONNECT message for `%s'.\n", |
469 | GNUNET_i2s(&dim->peer)); | 471 | GNUNET_i2s (&dim->peer)); |
470 | n = neighbour_find(h, &dim->peer); | 472 | n = neighbour_find (h, &dim->peer); |
471 | if (NULL == n) | 473 | if (NULL == n) |
472 | { | 474 | { |
473 | GNUNET_break(0); | 475 | GNUNET_break (0); |
474 | disconnect_and_schedule_reconnect(h); | 476 | disconnect_and_schedule_reconnect (h); |
475 | return; | 477 | return; |
476 | } | 478 | } |
477 | GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); | 479 | GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); |
478 | } | 480 | } |
479 | 481 | ||
480 | 482 | ||
@@ -485,26 +487,26 @@ handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) | |||
485 | * @param okm message received | 487 | * @param okm message received |
486 | */ | 488 | */ |
487 | static void | 489 | static void |
488 | handle_send_ok(void *cls, const struct SendOkMessage *okm) | 490 | handle_send_ok (void *cls, const struct SendOkMessage *okm) |
489 | { | 491 | { |
490 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 492 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
491 | struct Neighbour *n; | 493 | struct Neighbour *n; |
492 | 494 | ||
493 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 495 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
494 | "Receiving SEND_OK message for transmission to %s\n", | 496 | "Receiving SEND_OK message for transmission to %s\n", |
495 | GNUNET_i2s(&okm->peer)); | 497 | GNUNET_i2s (&okm->peer)); |
496 | n = neighbour_find(h, &okm->peer); | 498 | n = neighbour_find (h, &okm->peer); |
497 | if (NULL == n) | 499 | if (NULL == n) |
498 | { | 500 | { |
499 | /* We should never get a 'SEND_OK' for a peer that we are not | 501 | /* We should never get a 'SEND_OK' for a peer that we are not |
500 | connected to */ | 502 | connected to */ |
501 | GNUNET_break(0); | 503 | GNUNET_break (0); |
502 | disconnect_and_schedule_reconnect(h); | 504 | disconnect_and_schedule_reconnect (h); |
503 | return; | 505 | return; |
504 | } | 506 | } |
505 | n->ready_window++; | 507 | n->ready_window++; |
506 | if ((NULL != n->env) && (1 == n->ready_window)) | 508 | if ((NULL != n->env) && (1 == n->ready_window)) |
507 | do_send(n); | 509 | do_send (n); |
508 | } | 510 | } |
509 | 511 | ||
510 | 512 | ||
@@ -515,23 +517,23 @@ handle_send_ok(void *cls, const struct SendOkMessage *okm) | |||
515 | * @param im message received | 517 | * @param im message received |
516 | */ | 518 | */ |
517 | static int | 519 | static int |
518 | check_recv(void *cls, const struct InboundMessage *im) | 520 | check_recv (void *cls, const struct InboundMessage *im) |
519 | { | 521 | { |
520 | const struct GNUNET_MessageHeader *imm; | 522 | const struct GNUNET_MessageHeader *imm; |
521 | uint16_t size; | 523 | uint16_t size; |
522 | 524 | ||
523 | size = ntohs(im->header.size) - sizeof(*im); | 525 | size = ntohs (im->header.size) - sizeof(*im); |
524 | if (size < sizeof(struct GNUNET_MessageHeader)) | 526 | if (size < sizeof(struct GNUNET_MessageHeader)) |
525 | { | 527 | { |
526 | GNUNET_break(0); | 528 | GNUNET_break (0); |
527 | return GNUNET_SYSERR; | 529 | return GNUNET_SYSERR; |
528 | } | 530 | } |
529 | imm = (const struct GNUNET_MessageHeader *)&im[1]; | 531 | imm = (const struct GNUNET_MessageHeader *) &im[1]; |
530 | if (ntohs(imm->size) != size) | 532 | if (ntohs (imm->size) != size) |
531 | { | 533 | { |
532 | GNUNET_break(0); | 534 | GNUNET_break (0); |
533 | return GNUNET_SYSERR; | 535 | return GNUNET_SYSERR; |
534 | } | 536 | } |
535 | return GNUNET_OK; | 537 | return GNUNET_OK; |
536 | } | 538 | } |
537 | 539 | ||
@@ -543,26 +545,26 @@ check_recv(void *cls, const struct InboundMessage *im) | |||
543 | * @param im message received | 545 | * @param im message received |
544 | */ | 546 | */ |
545 | static void | 547 | static void |
546 | handle_recv(void *cls, const struct InboundMessage *im) | 548 | handle_recv (void *cls, const struct InboundMessage *im) |
547 | { | 549 | { |
548 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 550 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
549 | const struct GNUNET_MessageHeader *imm = | 551 | const struct GNUNET_MessageHeader *imm = |
550 | (const struct GNUNET_MessageHeader *)&im[1]; | 552 | (const struct GNUNET_MessageHeader *) &im[1]; |
551 | struct Neighbour *n; | 553 | struct Neighbour *n; |
552 | 554 | ||
553 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 555 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
554 | "Received message of type %u with %u bytes from `%s'.\n", | 556 | "Received message of type %u with %u bytes from `%s'.\n", |
555 | (unsigned int)ntohs(imm->type), | 557 | (unsigned int) ntohs (imm->type), |
556 | (unsigned int)ntohs(imm->size), | 558 | (unsigned int) ntohs (imm->size), |
557 | GNUNET_i2s(&im->peer)); | 559 | GNUNET_i2s (&im->peer)); |
558 | n = neighbour_find(h, &im->peer); | 560 | n = neighbour_find (h, &im->peer); |
559 | if (NULL == n) | 561 | if (NULL == n) |
560 | { | 562 | { |
561 | GNUNET_break(0); | 563 | GNUNET_break (0); |
562 | disconnect_and_schedule_reconnect(h); | 564 | disconnect_and_schedule_reconnect (h); |
563 | return; | 565 | return; |
564 | } | 566 | } |
565 | GNUNET_MQ_inject_message(n->mq, imm); | 567 | GNUNET_MQ_inject_message (n->mq, imm); |
566 | } | 568 | } |
567 | 569 | ||
568 | 570 | ||
@@ -572,47 +574,47 @@ handle_recv(void *cls, const struct InboundMessage *im) | |||
572 | * @param cls the handle to the transport service | 574 | * @param cls the handle to the transport service |
573 | */ | 575 | */ |
574 | static void | 576 | static void |
575 | reconnect(void *cls) | 577 | reconnect (void *cls) |
576 | { | 578 | { |
577 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 579 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
578 | struct GNUNET_MQ_MessageHandler handlers[] = | 580 | struct GNUNET_MQ_MessageHandler handlers[] = |
579 | { GNUNET_MQ_hd_fixed_size(connect, | 581 | { GNUNET_MQ_hd_fixed_size (connect, |
580 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | 582 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, |
581 | struct ConnectInfoMessage, | 583 | struct ConnectInfoMessage, |
582 | h), | 584 | h), |
583 | GNUNET_MQ_hd_fixed_size(disconnect, | 585 | GNUNET_MQ_hd_fixed_size (disconnect, |
584 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, | 586 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, |
585 | struct DisconnectInfoMessage, | 587 | struct DisconnectInfoMessage, |
586 | h), | 588 | h), |
587 | GNUNET_MQ_hd_fixed_size(send_ok, | 589 | GNUNET_MQ_hd_fixed_size (send_ok, |
588 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, | 590 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, |
589 | struct SendOkMessage, | 591 | struct SendOkMessage, |
590 | h), | 592 | h), |
591 | GNUNET_MQ_hd_var_size(recv, | 593 | GNUNET_MQ_hd_var_size (recv, |
592 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, | 594 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, |
593 | struct InboundMessage, | 595 | struct InboundMessage, |
594 | h), | 596 | h), |
595 | GNUNET_MQ_handler_end() }; | 597 | GNUNET_MQ_handler_end () }; |
596 | struct GNUNET_MQ_Envelope *env; | 598 | struct GNUNET_MQ_Envelope *env; |
597 | struct StartMessage *s; | 599 | struct StartMessage *s; |
598 | uint32_t options; | 600 | uint32_t options; |
599 | 601 | ||
600 | h->reconnect_task = NULL; | 602 | h->reconnect_task = NULL; |
601 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); | 603 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); |
602 | GNUNET_assert(NULL == h->mq); | 604 | GNUNET_assert (NULL == h->mq); |
603 | h->mq = | 605 | h->mq = |
604 | GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); | 606 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); |
605 | if (NULL == h->mq) | 607 | if (NULL == h->mq) |
606 | return; | 608 | return; |
607 | env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 609 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
608 | options = 0; | 610 | options = 0; |
609 | if (h->check_self) | 611 | if (h->check_self) |
610 | options |= 1; | 612 | options |= 1; |
611 | if (NULL != h->handlers) | 613 | if (NULL != h->handlers) |
612 | options |= 2; | 614 | options |= 2; |
613 | s->options = htonl(options); | 615 | s->options = htonl (options); |
614 | s->self = h->self; | 616 | s->self = h->self; |
615 | GNUNET_MQ_send(h->mq, env); | 617 | GNUNET_MQ_send (h->mq, env); |
616 | } | 618 | } |
617 | 619 | ||
618 | 620 | ||
@@ -622,14 +624,14 @@ reconnect(void *cls) | |||
622 | * @param h transport service to reconnect | 624 | * @param h transport service to reconnect |
623 | */ | 625 | */ |
624 | static void | 626 | static void |
625 | disconnect(struct GNUNET_TRANSPORT_CoreHandle *h) | 627 | disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
626 | { | 628 | { |
627 | GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); | 629 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); |
628 | if (NULL != h->mq) | 630 | if (NULL != h->mq) |
629 | { | 631 | { |
630 | GNUNET_MQ_destroy(h->mq); | 632 | GNUNET_MQ_destroy (h->mq); |
631 | h->mq = NULL; | 633 | h->mq = NULL; |
632 | } | 634 | } |
633 | } | 635 | } |
634 | 636 | ||
635 | 637 | ||
@@ -640,16 +642,16 @@ disconnect(struct GNUNET_TRANSPORT_CoreHandle *h) | |||
640 | * @param h transport service to reconnect | 642 | * @param h transport service to reconnect |
641 | */ | 643 | */ |
642 | static void | 644 | static void |
643 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) | 645 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
644 | { | 646 | { |
645 | GNUNET_assert(NULL == h->reconnect_task); | 647 | GNUNET_assert (NULL == h->reconnect_task); |
646 | disconnect(h); | 648 | disconnect (h); |
647 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 649 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
648 | "Scheduling task to reconnect to transport service in %s.\n", | 650 | "Scheduling task to reconnect to transport service in %s.\n", |
649 | GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); | 651 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); |
650 | h->reconnect_task = | 652 | h->reconnect_task = |
651 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); | 653 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
652 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); | 654 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
653 | } | 655 | } |
654 | 656 | ||
655 | 657 | ||
@@ -661,12 +663,12 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) | |||
661 | * @return NULL if disconnected, otherwise message queue for @a peer | 663 | * @return NULL if disconnected, otherwise message queue for @a peer |
662 | */ | 664 | */ |
663 | struct GNUNET_MQ_Handle * | 665 | struct GNUNET_MQ_Handle * |
664 | GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, | 666 | GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, |
665 | const struct GNUNET_PeerIdentity *peer) | 667 | const struct GNUNET_PeerIdentity *peer) |
666 | { | 668 | { |
667 | struct Neighbour *n; | 669 | struct Neighbour *n; |
668 | 670 | ||
669 | n = neighbour_find(handle, peer); | 671 | n = neighbour_find (handle, peer); |
670 | if (NULL == n) | 672 | if (NULL == n) |
671 | return NULL; | 673 | return NULL; |
672 | return n->mq; | 674 | return n->mq; |
@@ -694,21 +696,21 @@ GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
694 | * @param pid which peer was the message from that was fully processed by CORE | 696 | * @param pid which peer was the message from that was fully processed by CORE |
695 | */ | 697 | */ |
696 | void | 698 | void |
697 | GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, | 699 | GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, |
698 | const struct GNUNET_PeerIdentity *pid) | 700 | const struct GNUNET_PeerIdentity *pid) |
699 | { | 701 | { |
700 | struct GNUNET_MQ_Envelope *env; | 702 | struct GNUNET_MQ_Envelope *env; |
701 | struct RecvOkMessage *rok; | 703 | struct RecvOkMessage *rok; |
702 | 704 | ||
703 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 705 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
704 | "Message for %s finished CORE processing, sending RECV_OK.\n", | 706 | "Message for %s finished CORE processing, sending RECV_OK.\n", |
705 | GNUNET_i2s(pid)); | 707 | GNUNET_i2s (pid)); |
706 | if (NULL == ch->mq) | 708 | if (NULL == ch->mq) |
707 | return; | 709 | return; |
708 | env = GNUNET_MQ_msg(rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); | 710 | env = GNUNET_MQ_msg (rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); |
709 | rok->increase_window_delta = htonl(1); | 711 | rok->increase_window_delta = htonl (1); |
710 | rok->peer = *pid; | 712 | rok->peer = *pid; |
711 | GNUNET_MQ_send(ch->mq, env); | 713 | GNUNET_MQ_send (ch->mq, env); |
712 | } | 714 | } |
713 | 715 | ||
714 | 716 | ||
@@ -726,46 +728,46 @@ GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, | |||
726 | * @return NULL on error | 728 | * @return NULL on error |
727 | */ | 729 | */ |
728 | struct GNUNET_TRANSPORT_CoreHandle * | 730 | struct GNUNET_TRANSPORT_CoreHandle * |
729 | GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 731 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
730 | const struct GNUNET_PeerIdentity *self, | 732 | const struct GNUNET_PeerIdentity *self, |
731 | const struct GNUNET_MQ_MessageHandler *handlers, | 733 | const struct GNUNET_MQ_MessageHandler *handlers, |
732 | void *cls, | 734 | void *cls, |
733 | GNUNET_TRANSPORT_NotifyConnect nc, | 735 | GNUNET_TRANSPORT_NotifyConnect nc, |
734 | GNUNET_TRANSPORT_NotifyDisconnect nd) | 736 | GNUNET_TRANSPORT_NotifyDisconnect nd) |
735 | { | 737 | { |
736 | struct GNUNET_TRANSPORT_CoreHandle *h; | 738 | struct GNUNET_TRANSPORT_CoreHandle *h; |
737 | unsigned int i; | 739 | unsigned int i; |
738 | 740 | ||
739 | h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); | 741 | h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); |
740 | if (NULL != self) | 742 | if (NULL != self) |
741 | { | 743 | { |
742 | h->self = *self; | 744 | h->self = *self; |
743 | h->check_self = GNUNET_YES; | 745 | h->check_self = GNUNET_YES; |
744 | } | 746 | } |
745 | h->cfg = cfg; | 747 | h->cfg = cfg; |
746 | h->cls = cls; | 748 | h->cls = cls; |
747 | h->nc_cb = nc; | 749 | h->nc_cb = nc; |
748 | h->nd_cb = nd; | 750 | h->nd_cb = nd; |
749 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 751 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
750 | if (NULL != handlers) | 752 | if (NULL != handlers) |
751 | { | 753 | { |
752 | for (i = 0; NULL != handlers[i].cb; i++) | 754 | for (i = 0; NULL != handlers[i].cb; i++) |
753 | ; | 755 | ; |
754 | h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); | 756 | h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); |
755 | GNUNET_memcpy(h->handlers, | 757 | GNUNET_memcpy (h->handlers, |
756 | handlers, | 758 | handlers, |
757 | i * sizeof(struct GNUNET_MQ_MessageHandler)); | 759 | i * sizeof(struct GNUNET_MQ_MessageHandler)); |
758 | } | 760 | } |
759 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); | 761 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); |
760 | reconnect(h); | 762 | reconnect (h); |
761 | if (NULL == h->mq) | 763 | if (NULL == h->mq) |
762 | { | 764 | { |
763 | GNUNET_free_non_null(h->handlers); | 765 | GNUNET_free_non_null (h->handlers); |
764 | GNUNET_free(h); | 766 | GNUNET_free (h); |
765 | return NULL; | 767 | return NULL; |
766 | } | 768 | } |
767 | h->neighbours = | 769 | h->neighbours = |
768 | GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); | 770 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); |
769 | return h; | 771 | return h; |
770 | } | 772 | } |
771 | 773 | ||
@@ -777,22 +779,22 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
777 | * #GNUNET_TRANSPORT_core_connect() | 779 | * #GNUNET_TRANSPORT_core_connect() |
778 | */ | 780 | */ |
779 | void | 781 | void |
780 | GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) | 782 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) |
781 | { | 783 | { |
782 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); | 784 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); |
783 | /* this disconnects all neighbours... */ | 785 | /* this disconnects all neighbours... */ |
784 | disconnect(handle); | 786 | disconnect (handle); |
785 | /* and now we stop trying to connect again... */ | 787 | /* and now we stop trying to connect again... */ |
786 | if (NULL != handle->reconnect_task) | 788 | if (NULL != handle->reconnect_task) |
787 | { | 789 | { |
788 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); | 790 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
789 | handle->reconnect_task = NULL; | 791 | handle->reconnect_task = NULL; |
790 | } | 792 | } |
791 | GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); | 793 | GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); |
792 | handle->neighbours = NULL; | 794 | handle->neighbours = NULL; |
793 | GNUNET_free_non_null(handle->handlers); | 795 | GNUNET_free_non_null (handle->handlers); |
794 | handle->handlers = NULL; | 796 | handle->handlers = NULL; |
795 | GNUNET_free(handle); | 797 | GNUNET_free (handle); |
796 | } | 798 | } |
797 | 799 | ||
798 | 800 | ||