2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file cadet/gnunet-service-cadet-new_connection.c
23 * @brief management of CORE-level end-to-end connections; establishes
24 * end-to-end routes and transmits messages along the route
25 * @author Bartlomiej Polot
26 * @author Christian Grothoff
29 #include "gnunet-service-cadet-new.h"
30 #include "gnunet-service-cadet-new_channel.h"
31 #include "gnunet-service-cadet-new_connection.h"
32 #include "gnunet-service-cadet-new_paths.h"
33 #include "gnunet-service-cadet-new_peer.h"
34 #include "gnunet-service-cadet-new_tunnels.h"
35 #include "gnunet_cadet_service.h"
36 #include "gnunet_statistics_service.h"
37 #include "cadet_protocol.h"
40 #define LOG(level, ...) GNUNET_log_from(level,"cadet-con",__VA_ARGS__)
44 * All the states a connection can be in.
46 enum CadetConnectionState
49 * Uninitialized status, we have not yet even gotten the message queue.
54 * Connection create message in queue, awaiting transmission by CORE.
56 CADET_CONNECTION_SENDING_CREATE,
59 * Connection create message sent, waiting for ACK.
61 CADET_CONNECTION_SENT,
64 * We are an inbound connection, and received a CREATE. Need to
65 * send an CREATE_ACK back.
67 CADET_CONNECTION_CREATE_RECEIVED,
70 * Connection confirmed, ready to carry traffic.
72 CADET_CONNECTION_READY
78 * Low-level connection to a destination.
80 struct CadetConnection
84 * ID of the connection.
86 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
89 * To which peer does this connection go?
91 struct CadetPeer *destination;
94 * Which tunnel is using this connection?
96 struct CadetTConnection *ct;
99 * Path we are using to our destination.
101 struct CadetPeerPath *path;
104 * Pending message, NULL if we are ready to transmit.
106 struct GNUNET_MQ_Envelope *env;
109 * Handle for calling #GCP_request_mq_cancel() once we are finished.
111 struct GCP_MessageQueueManager *mq_man;
114 * Task for connection maintenance.
116 struct GNUNET_SCHEDULER_Task *task;
119 * Queue entry for keepalive messages.
121 struct CadetTunnelQueueEntry *keepalive_qe;
124 * Function to call once we are ready to transmit.
126 GCC_ReadyCallback ready_cb;
129 * Closure for @e ready_cb.
134 * How long do we wait before we try again with a CREATE message?
136 struct GNUNET_TIME_Relative retry_delay;
139 * Performance metrics for this connection.
141 struct CadetConnectionMetrics metrics;
144 * State of the connection.
146 enum CadetConnectionState state;
149 * Options for the route, control buffering.
151 enum GNUNET_CADET_ChannelOption options;
154 * How many latency observations did we make for this connection?
156 unsigned int latency_datapoints;
159 * Offset of our @e destination in @e path.
164 * Are we ready to transmit via @e mq_man right now?
172 * Lookup a connection by its identifier.
174 * @param cid identifier to resolve
175 * @return NULL if connection was not found
177 struct CadetConnection *
178 GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
180 return GNUNET_CONTAINER_multishortmap_get (connections,
181 &cid->connection_of_tunnel);
186 * Update the connection state. Also triggers the necessary
189 * @param cc connection to update the state for
190 * @param new_state new state for @a cc
191 * @param new_mqm_ready new `mqm_ready` state for @a cc
194 update_state (struct CadetConnection *cc,
195 enum CadetConnectionState new_state,
201 if ( (new_state == cc->state) &&
202 (new_mqm_ready == cc->mqm_ready) )
203 return; /* no change, nothing to do */
204 old_ready = ( (CADET_CONNECTION_READY == cc->state) &&
205 (GNUNET_YES == cc->mqm_ready) );
206 new_ready = ( (CADET_CONNECTION_READY == new_state) &&
207 (GNUNET_YES == new_mqm_ready) );
208 cc->state = new_state;
209 cc->mqm_ready = new_mqm_ready;
210 if (old_ready != new_ready)
211 cc->ready_cb (cc->ready_cb_cls,
217 * Destroy a connection, part of the internal implementation. Called
218 * only from #GCC_destroy_from_core() or #GCC_destroy_from_tunnel().
220 * @param cc connection to destroy
223 GCC_destroy (struct CadetConnection *cc)
225 LOG (GNUNET_ERROR_TYPE_DEBUG,
228 if (NULL != cc->mq_man)
230 GCP_request_mq_cancel (cc->mq_man,
234 if (NULL != cc->task)
236 GNUNET_SCHEDULER_cancel (cc->task);
239 if (NULL != cc->keepalive_qe)
241 GCT_send_cancel (cc->keepalive_qe);
242 cc->keepalive_qe = NULL;
244 GCPP_del_connection (cc->path,
247 for (unsigned int i=0;i<cc->off;i++)
248 GCP_remove_connection (GCPP_get_peer_at_offset (cc->path,
251 GNUNET_assert (GNUNET_YES ==
252 GNUNET_CONTAINER_multishortmap_remove (connections,
253 &GCC_get_id (cc)->connection_of_tunnel,
261 * Destroy a connection, called when the CORE layer is already done
262 * (i.e. has received a BROKEN message), but if we still have to
263 * communicate the destruction of the connection to the tunnel (if one
266 * @param cc connection to destroy
269 GCC_destroy_without_core (struct CadetConnection *cc)
273 GCT_connection_lost (cc->ct);
281 * Destroy a connection, called if the tunnel association with the
282 * connection was already broken, but we still need to notify the CORE
283 * layer about the breakage.
285 * @param cc connection to destroy
288 GCC_destroy_without_tunnel (struct CadetConnection *cc)
291 if ( (CADET_CONNECTION_SENDING_CREATE != cc->state) &&
292 (NULL != cc->mq_man) )
294 struct GNUNET_MQ_Envelope *env;
295 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
297 /* Need to notify next hop that we are down. */
298 env = GNUNET_MQ_msg (destroy_msg,
299 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY);
300 destroy_msg->cid = cc->cid;
301 GCP_request_mq_cancel (cc->mq_man,
310 * Return the tunnel associated with this connection.
312 * @param cc connection to query
313 * @return corresponding entry in the tunnel's connection list
315 struct CadetTConnection *
316 GCC_get_ct (struct CadetConnection *cc)
323 * Obtain performance @a metrics from @a cc.
325 * @param cc connection to query
326 * @return the metrics
328 const struct CadetConnectionMetrics *
329 GCC_get_metrics (struct CadetConnection *cc)
336 * Send a #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the
337 * tunnel to prevent it from timing out.
339 * @param cls the `struct CadetConnection` to keep alive.
342 send_keepalive (void *cls);
346 * Keepalive was transmitted. Remember this, and possibly
347 * schedule the next one.
349 * @param cls the `struct CadetConnection` to keep alive.
350 * @param cid identifier of the connection within the tunnel, NULL
351 * if transmission failed
354 keepalive_done (void *cls,
355 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
357 struct CadetConnection *cc = cls;
359 cc->keepalive_qe = NULL;
360 if ( (GNUNET_YES == cc->mqm_ready) &&
362 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period,
369 * Send a #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the
370 * tunnel to prevent it from timing out.
372 * @param cls the `struct CadetConnection` to keep alive.
375 send_keepalive (void *cls)
377 struct CadetConnection *cc = cls;
378 struct GNUNET_MessageHeader msg;
381 if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t))
383 /* Tunnel not yet ready, wait with keepalives... */
384 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period,
389 GNUNET_assert (NULL != cc->ct);
390 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
391 GNUNET_assert (NULL == cc->keepalive_qe);
392 LOG (GNUNET_ERROR_TYPE_INFO,
393 "Sending KEEPALIVE on behalf of %s via %s\n",
396 GNUNET_STATISTICS_update (stats,
400 msg.size = htons (sizeof (msg));
401 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE);
404 = GCT_send (cc->ct->t,
412 * We sent a message for which we expect to receive an ACK via
413 * the connection identified by @a cti.
415 * @param cid connection identifier where we expect an ACK
418 GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
420 struct CadetConnection *cc;
422 cc = GCC_lookup (cid);
424 return; /* whopise, connection alredy down? */
425 cc->metrics.num_acked_transmissions++;
430 * We observed an ACK for a message that was originally sent via
431 * the connection identified by @a cti.
433 * @param cti connection identifier where we got an ACK for a message
434 * that was originally sent via this connection (the ACK
435 * may have gotten back to us via a different connection).
438 GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
440 struct CadetConnection *cc;
442 cc = GCC_lookup (cid);
444 return; /* whopise, connection alredy down? */
445 cc->metrics.num_successes++;
450 * We observed some the given @a latency on the connection
451 * identified by @a cti. (The same connection was taken
452 * in both directions.)
454 * @param cid connection identifier where we measured latency
455 * @param latency the observed latency
458 GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
459 struct GNUNET_TIME_Relative latency)
461 struct CadetConnection *cc;
465 cc = GCC_lookup (cid);
467 return; /* whopise, connection alredy down? */
468 GNUNET_STATISTICS_update (stats,
469 "# latencies observed",
472 cc->latency_datapoints++;
473 if (cc->latency_datapoints >= 7)
476 weight = cc->latency_datapoints;
477 /* Compute weighted average, giving at MOST weight 7 to the
478 existing values, or less if that value is based on fewer than 7
480 result = (weight * cc->metrics.aged_latency.rel_value_us) + 1.0 * latency.rel_value_us;
481 result /= (weight + 1.0);
482 cc->metrics.aged_latency.rel_value_us = (uint64_t) result;
487 * A #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for this connection, implying
488 * that the end-to-end connection is up. Process it.
490 * @param cc the connection that got the ACK.
493 GCC_handle_connection_create_ack (struct CadetConnection *cc)
495 LOG (GNUNET_ERROR_TYPE_DEBUG,
496 "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
499 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
500 if (CADET_CONNECTION_READY == cc->state)
501 return; /* Duplicate ACK, ignore */
502 if (NULL != cc->task)
504 GNUNET_SCHEDULER_cancel (cc->task);
507 cc->metrics.age = GNUNET_TIME_absolute_get ();
509 CADET_CONNECTION_READY,
511 if ( (NULL == cc->keepalive_qe) &&
512 (GNUNET_YES == cc->mqm_ready) &&
514 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period,
523 * @param cc connection that received encrypted message
524 * @param msg the key exchange message
527 GCC_handle_kx (struct CadetConnection *cc,
528 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
530 if (CADET_CONNECTION_SENT == cc->state)
532 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
533 clearly something is working, so pretend we got an ACK. */
534 LOG (GNUNET_ERROR_TYPE_DEBUG,
535 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
537 GCC_handle_connection_create_ack (cc);
539 GCT_handle_kx (cc->ct,
545 * Handle KX_AUTH message.
547 * @param cc connection that received encrypted message
548 * @param msg the key exchange message
551 GCC_handle_kx_auth (struct CadetConnection *cc,
552 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
554 if (CADET_CONNECTION_SENT == cc->state)
556 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
557 clearly something is working, so pretend we got an ACK. */
558 LOG (GNUNET_ERROR_TYPE_DEBUG,
559 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
561 GCC_handle_connection_create_ack (cc);
563 GCT_handle_kx_auth (cc->ct,
569 * Handle encrypted message.
571 * @param cc connection that received encrypted message
572 * @param msg the encrypted message to decrypt
575 GCC_handle_encrypted (struct CadetConnection *cc,
576 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
578 if (CADET_CONNECTION_SENT == cc->state)
580 /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
581 clearly something is working, so pretend we got an ACK. */
582 LOG (GNUNET_ERROR_TYPE_DEBUG,
583 "Faking connection ACK for %s due to ENCRYPTED payload\n",
585 GCC_handle_connection_create_ack (cc);
587 cc->metrics.last_use = GNUNET_TIME_absolute_get ();
588 GCT_handle_encrypted (cc->ct,
594 * Send a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the
597 * @param cls the `struct CadetConnection` to initiate
600 send_create (void *cls)
602 struct CadetConnection *cc = cls;
603 struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
604 struct GNUNET_PeerIdentity *pids;
605 struct GNUNET_MQ_Envelope *env;
606 unsigned int path_length;
609 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
610 path_length = GCPP_get_length (cc->path);
611 env = GNUNET_MQ_msg_extra (create_msg,
612 (1 + path_length) * sizeof (struct GNUNET_PeerIdentity),
613 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE);
614 create_msg->options = htonl ((uint32_t) cc->options);
615 create_msg->cid = cc->cid;
616 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
617 pids[0] = my_full_id;
618 for (unsigned int i=0;i<path_length;i++)
619 pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path,
621 LOG (GNUNET_ERROR_TYPE_DEBUG,
622 "Sending CADET_CONNECTION_CREATE message for %s\n",
626 CADET_CONNECTION_SENT,
628 GCP_send (cc->mq_man,
634 * Send a CREATE_ACK message towards the origin.
636 * @param cls the `struct CadetConnection` to initiate
639 send_create_ack (void *cls)
641 struct CadetConnection *cc = cls;
642 struct GNUNET_CADET_ConnectionCreateAckMessage *ack_msg;
643 struct GNUNET_MQ_Envelope *env;
646 GNUNET_assert (CADET_CONNECTION_CREATE_RECEIVED == cc->state);
647 LOG (GNUNET_ERROR_TYPE_DEBUG,
648 "Sending CONNECTION_CREATE_ACK message for %s\n",
650 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
651 env = GNUNET_MQ_msg (ack_msg,
652 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK);
653 ack_msg->cid = cc->cid;
656 CADET_CONNECTION_READY,
658 GCP_send (cc->mq_man,
664 * We got a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a
665 * connection that we already have. Either our ACK got lost
666 * or something is fishy. Consider retransmitting the ACK.
668 * @param cc connection that got the duplicate CREATE
671 GCC_handle_duplicate_create (struct CadetConnection *cc)
673 if (GNUNET_YES == cc->mqm_ready)
675 LOG (GNUNET_ERROR_TYPE_DEBUG,
676 "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
678 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
679 /* Revert back to the state of having only received the 'CREATE',
680 and immediately proceed to send the CREATE_ACK. */
682 CADET_CONNECTION_CREATE_RECEIVED,
684 if (NULL != cc->task)
685 GNUNET_SCHEDULER_cancel (cc->task);
686 cc->task = GNUNET_SCHEDULER_add_now (&send_create_ack,
691 /* We are currently sending something else back, which
692 can only be an ACK or payload, either of which would
693 do. So actually no need to do anything. */
694 LOG (GNUNET_ERROR_TYPE_DEBUG,
695 "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
702 * There has been a change in the message queue existence for our
703 * peer at the first hop. Adjust accordingly.
705 * @param cls the `struct CadetConnection`
706 * @param available #GNUNET_YES if sending is now possible,
707 * #GNUNET_NO if sending is no longer possible
708 * #GNUNET_SYSERR if sending is no longer possible
709 * and the last envelope was discarded
712 manage_first_hop_mq (void *cls,
715 struct CadetConnection *cc = cls;
717 if (GNUNET_YES != available)
719 /* Connection is down, for now... */
720 LOG (GNUNET_ERROR_TYPE_DEBUG,
721 "Core MQ for %s went down\n",
724 CADET_CONNECTION_NEW,
726 cc->retry_delay = GNUNET_TIME_UNIT_ZERO;
727 if (NULL != cc->task)
729 GNUNET_SCHEDULER_cancel (cc->task);
738 LOG (GNUNET_ERROR_TYPE_DEBUG,
739 "Core MQ for %s became available in state %d\n",
744 case CADET_CONNECTION_NEW:
745 /* Transmit immediately */
746 cc->task = GNUNET_SCHEDULER_add_now (&send_create,
749 case CADET_CONNECTION_SENDING_CREATE:
750 /* Should not be possible to be called in this state. */
753 case CADET_CONNECTION_SENT:
754 /* Retry a bit later... */
755 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
756 cc->task = GNUNET_SCHEDULER_add_delayed (cc->retry_delay,
760 case CADET_CONNECTION_CREATE_RECEIVED:
761 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
762 cc->metrics.age = GNUNET_TIME_absolute_get ();
763 cc->task = GNUNET_SCHEDULER_add_now (&send_create_ack,
766 case CADET_CONNECTION_READY:
767 if ( (NULL == cc->keepalive_qe) &&
768 (GNUNET_YES == cc->mqm_ready) &&
771 LOG (GNUNET_ERROR_TYPE_DEBUG,
772 "Scheduling keepalive for %s in %s\n",
774 GNUNET_STRINGS_relative_time_to_string (keepalive_period,
776 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period,
786 * Create a connection to @a destination via @a path and notify @a cb
787 * whenever we are ready for more data. Shared logic independent of
788 * who is initiating the connection.
790 * @param destination where to go
791 * @param path which path to take (may not be the full path)
792 * @param off offset of @a destination on @a path
793 * @param options options for the connection
794 * @param ct which tunnel uses this connection
795 * @param init_state initial state for the connection
796 * @param ready_cb function to call when ready to transmit
797 * @param ready_cb_cls closure for @a cb
798 * @return handle to the connection
800 static struct CadetConnection *
801 connection_create (struct CadetPeer *destination,
802 struct CadetPeerPath *path,
804 enum GNUNET_CADET_ChannelOption options,
805 struct CadetTConnection *ct,
806 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
807 enum CadetConnectionState init_state,
808 GCC_ReadyCallback ready_cb,
811 struct CadetConnection *cc;
812 struct CadetPeer *first_hop;
814 cc = GNUNET_new (struct CadetConnection);
815 cc->options = options;
816 cc->state = init_state;
819 GNUNET_assert (GNUNET_OK ==
820 GNUNET_CONTAINER_multishortmap_put (connections,
821 &GCC_get_id (cc)->connection_of_tunnel,
823 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
824 cc->ready_cb = ready_cb;
825 cc->ready_cb_cls = ready_cb_cls;
828 LOG (GNUNET_ERROR_TYPE_DEBUG,
829 "Creating %s using path %s\n",
832 GCPP_add_connection (path,
835 for (unsigned int i=0;i<off;i++)
836 GCP_add_connection (GCPP_get_peer_at_offset (path,
840 first_hop = GCPP_get_peer_at_offset (path,
842 cc->mq_man = GCP_request_mq (first_hop,
843 &manage_first_hop_mq,
850 * Create a connection to @a destination via @a path and
851 * notify @a cb whenever we are ready for more data. This
852 * is an inbound tunnel, so we must use the existing @a cid
854 * @param destination where to go
855 * @param path which path to take (may not be the full path)
856 * @param options options for the connection
857 * @param ct which tunnel uses this connection
858 * @param ready_cb function to call when ready to transmit
859 * @param ready_cb_cls closure for @a cb
860 * @return handle to the connection, NULL if we already have
861 * a connection that takes precedence on @a path
863 struct CadetConnection *
864 GCC_create_inbound (struct CadetPeer *destination,
865 struct CadetPeerPath *path,
866 enum GNUNET_CADET_ChannelOption options,
867 struct CadetTConnection *ct,
868 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
869 GCC_ReadyCallback ready_cb,
872 struct CadetConnection *cc;
875 off = GCPP_find_peer (path,
877 GNUNET_assert (UINT_MAX != off);
878 cc = GCPP_get_connection (path,
890 /* Two peers picked the SAME random connection identifier at the
891 same time for the same path? Must be malicious. Drop
892 connection (existing and inbound), even if it is the only
895 GCT_connection_lost (cc->ct);
896 GCC_destroy_without_tunnel (cc);
902 LOG (GNUNET_ERROR_TYPE_DEBUG,
903 "Got two connections on %s, dropping my existing %s\n",
906 GCT_connection_lost (cc->ct);
907 GCC_destroy_without_tunnel (cc);
912 LOG (GNUNET_ERROR_TYPE_DEBUG,
913 "Got two connections on %s, keeping my existing %s\n",
920 return connection_create (destination,
926 CADET_CONNECTION_CREATE_RECEIVED,
933 * Create a connection to @a destination via @a path and
934 * notify @a cb whenever we are ready for more data.
936 * @param destination where to go
937 * @param path which path to take (may not be the full path)
938 * @param off offset of @a destination on @a path
939 * @param options options for the connection
940 * @param ct tunnel that uses the connection
941 * @param ready_cb function to call when ready to transmit
942 * @param ready_cb_cls closure for @a cb
943 * @return handle to the connection
945 struct CadetConnection *
946 GCC_create (struct CadetPeer *destination,
947 struct CadetPeerPath *path,
949 enum GNUNET_CADET_ChannelOption options,
950 struct CadetTConnection *ct,
951 GCC_ReadyCallback ready_cb,
954 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
956 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
959 return connection_create (destination,
965 CADET_CONNECTION_NEW,
972 * Transmit message @a msg via connection @a cc. Must only be called
973 * (once) after the connection has signalled that it is ready via the
974 * `ready_cb`. Clients can also use #GCC_is_ready() to check if the
975 * connection is right now ready for transmission.
977 * @param cc connection identification
978 * @param env envelope with message to transmit; must NOT
979 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
982 GCC_transmit (struct CadetConnection *cc,
983 struct GNUNET_MQ_Envelope *env)
985 LOG (GNUNET_ERROR_TYPE_DEBUG,
986 "Scheduling message for transmission on %s\n",
988 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
989 GNUNET_assert (CADET_CONNECTION_READY == cc->state);
990 cc->metrics.last_use = GNUNET_TIME_absolute_get ();
991 cc->mqm_ready = GNUNET_NO;
992 if (NULL != cc->task)
994 GNUNET_SCHEDULER_cancel (cc->task);
997 GCP_send (cc->mq_man,
1003 * Obtain the path used by this connection.
1005 * @param cc connection
1006 * @return path to @a cc
1008 struct CadetPeerPath *
1009 GCC_get_path (struct CadetConnection *cc)
1016 * Obtain unique ID for the connection.
1018 * @param cc connection.
1019 * @return unique number of the connection
1021 const struct GNUNET_CADET_ConnectionTunnelIdentifier *
1022 GCC_get_id (struct CadetConnection *cc)
1029 * Get a (static) string for a connection.
1031 * @param cc Connection.
1034 GCC_2s (const struct CadetConnection *cc)
1036 static char buf[128];
1039 return "Connection(NULL)";
1043 GNUNET_snprintf (buf,
1045 "Connection %s (%s)",
1046 GNUNET_sh2s (&cc->cid.connection_of_tunnel),
1047 GCT_2s (cc->ct->t));
1050 GNUNET_snprintf (buf,
1053 GNUNET_sh2s (&cc->cid.connection_of_tunnel));
1058 #define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-con",__VA_ARGS__)
1062 * Log connection info.
1064 * @param cc connection
1065 * @param level Debug level to use.
1068 GCC_debug (struct CadetConnection *cc,
1069 enum GNUNET_ErrorType level)
1073 do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
1075 __FILE__, __FUNCTION__, __LINE__);
1081 "Connection (NULL)\n");
1085 "%s to %s via path %s in state %d is %s\n",
1087 GCP_2s (cc->destination),
1090 (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
1093 /* end of gnunet-service-cadet-new_connection.c */