summaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet-new_connection.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-18 19:24:33 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-18 19:24:33 +0100
commitdfde8ea01a08a32340a47df29ffc2571c031488b (patch)
tree81abde784965de4a4d3f32f882a39353cc96a88d /src/cadet/gnunet-service-cadet-new_connection.c
parent3edc21c27d208e45dc1af76131a480a3ebf1e8d3 (diff)
downloadgnunet-dfde8ea01a08a32340a47df29ffc2571c031488b.tar.gz
gnunet-dfde8ea01a08a32340a47df29ffc2571c031488b.zip
create matching connection objects for inbound connections
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_connection.c')
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.c92
1 files changed, 80 insertions, 12 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_connection.c b/src/cadet/gnunet-service-cadet-new_connection.c
index 440d64fb6..5123f9d45 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.c
+++ b/src/cadet/gnunet-service-cadet-new_connection.c
@@ -376,22 +376,24 @@ manage_first_hop_mq (void *cls,
376 376
377 377
378/** 378/**
379 * Create a connection to @a destination via @a path and 379 * Create a connection to @a destination via @a path and notify @a cb
380 * notify @a cb whenever we are ready for more data. 380 * whenever we are ready for more data. Shared logic independent of
381 * who is initiating the connection.
381 * 382 *
382 * @param destination where to go 383 * @param destination where to go
383 * @param path which path to take (may not be the full path) 384 * @param path which path to take (may not be the full path)
384 * @param ct tunnel that uses the connection 385 * @param ct which tunnel uses this connection
385 * @param ready_cb function to call when ready to transmit 386 * @param ready_cb function to call when ready to transmit
386 * @param ready_cb_cls closure for @a cb 387 * @param ready_cb_cls closure for @a cb
387 * @return handle to the connection 388 * @return handle to the connection
388 */ 389 */
389struct CadetConnection * 390static struct CadetConnection *
390GCC_create (struct CadetPeer *destination, 391connection_create (struct CadetPeer *destination,
391 struct CadetPeerPath *path, 392 struct CadetPeerPath *path,
392 struct CadetTConnection *ct, 393 struct CadetTConnection *ct,
393 GNUNET_SCHEDULER_TaskCallback ready_cb, 394 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
394 void *ready_cb_cls) 395 GNUNET_SCHEDULER_TaskCallback ready_cb,
396 void *ready_cb_cls)
395{ 397{
396 struct CadetConnection *cc; 398 struct CadetConnection *cc;
397 struct CadetPeer *first_hop; 399 struct CadetPeer *first_hop;
@@ -402,9 +404,7 @@ GCC_create (struct CadetPeer *destination,
402 GNUNET_assert (UINT_MAX > off); 404 GNUNET_assert (UINT_MAX > off);
403 cc = GNUNET_new (struct CadetConnection); 405 cc = GNUNET_new (struct CadetConnection);
404 cc->ct = ct; 406 cc->ct = ct;
405 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 407 cc->cid = *cid;
406 &cc->cid,
407 sizeof (cc->cid));
408 GNUNET_assert (GNUNET_OK == 408 GNUNET_assert (GNUNET_OK ==
409 GNUNET_CONTAINER_multishortmap_put (connections, 409 GNUNET_CONTAINER_multishortmap_put (connections,
410 &GCC_get_id (cc)->connection_of_tunnel, 410 &GCC_get_id (cc)->connection_of_tunnel,
@@ -432,6 +432,74 @@ GCC_create (struct CadetPeer *destination,
432 432
433 433
434/** 434/**
435 * Create a connection to @a destination via @a path and
436 * notify @a cb whenever we are ready for more data. This
437 * is an inbound tunnel, so we must use the existing @a cid
438 *
439 * @param destination where to go
440 * @param path which path to take (may not be the full path)
441 * @param ct which tunnel uses this connection
442 * @param ready_cb function to call when ready to transmit
443 * @param ready_cb_cls closure for @a cb
444 * @return handle to the connection
445 */
446struct CadetConnection *
447GCC_create_inbound (struct CadetPeer *destination,
448 struct CadetPeerPath *path,
449 struct CadetTConnection *ct,
450 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
451 GNUNET_SCHEDULER_TaskCallback ready_cb,
452 void *ready_cb_cls)
453{
454 struct CadetConnection *cc;
455
456 cc = connection_create (destination,
457 path,
458 ct,
459 cid,
460 ready_cb,
461 ready_cb_cls);
462 /* FIXME: send CREATE_ACK? */
463 return cc;
464}
465
466
467/**
468 * Create a connection to @a destination via @a path and
469 * notify @a cb whenever we are ready for more data.
470 *
471 * @param destination where to go
472 * @param path which path to take (may not be the full path)
473 * @param ct tunnel that uses the connection
474 * @param ready_cb function to call when ready to transmit
475 * @param ready_cb_cls closure for @a cb
476 * @return handle to the connection
477 */
478struct CadetConnection *
479GCC_create (struct CadetPeer *destination,
480 struct CadetPeerPath *path,
481 struct CadetTConnection *ct,
482 GNUNET_SCHEDULER_TaskCallback ready_cb,
483 void *ready_cb_cls)
484{
485 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
486 struct CadetConnection *cc;
487
488 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
489 &cid,
490 sizeof (cid));
491 cc = connection_create (destination,
492 path,
493 ct,
494 &cid,
495 ready_cb,
496 ready_cb_cls);
497 /* FIXME: send CREATE? */
498 return cc;
499}
500
501
502/**
435 * We finished transmission of a message, if we are still ready, tell 503 * We finished transmission of a message, if we are still ready, tell
436 * the tunnel! 504 * the tunnel!
437 * 505 *