GNUnet 0.26.2-113-ged4734898
 
Loading...
Searching...
No Matches
gnunet-service-cadet_connection.c File Reference

management of CORE-level end-to-end connections; establishes end-to-end routes and transmits messages along the route More...

Include dependency graph for gnunet-service-cadet_connection.c:

Go to the source code of this file.

Data Structures

struct  CadetConnection
 Low-level connection to a destination. More...
 

Macros

#define LOG(level, ...)   GNUNET_log_from (level, "cadet-con", __VA_ARGS__)
 
#define INITIAL_CONNECTION_CREATE_RETRY_DELAY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
 How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have connection-level RTT data!
 
#define LOG2(level, ...)    GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)
 

Enumerations

enum  CadetConnectionState {
  CADET_CONNECTION_NEW , CADET_CONNECTION_SENDING_CREATE , CADET_CONNECTION_SENT , CADET_CONNECTION_CREATE_RECEIVED ,
  CADET_CONNECTION_READY
}
 All the states a connection can be in. More...
 

Functions

struct CadetConnectionGCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
 Lookup a connection by its identifier.
 
static void update_state (struct CadetConnection *cc, enum CadetConnectionState new_state, int new_mqm_ready)
 Update the connection state.
 
static void GCC_destroy (struct CadetConnection *cc)
 Destroy a connection, part of the internal implementation.
 
void GCC_destroy_without_core (struct CadetConnection *cc)
 Destroy a connection, called when the CORE layer is already done (i.e.
 
void GCC_destroy_without_tunnel (struct CadetConnection *cc)
 Destroy a connection, called if the tunnel association with the connection was already broken, but we still need to notify the CORE layer about the breakage.
 
struct CadetTConnectionGCC_get_ct (struct CadetConnection *cc)
 Return the tunnel associated with this connection.
 
const struct CadetConnectionMetricsGCC_get_metrics (struct CadetConnection *cc)
 Obtain performance metrics from cc.
 
static void send_keepalive (void *cls)
 Send a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the tunnel to prevent it from timing out.
 
static void keepalive_done (void *cls, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
 Keepalive was transmitted.
 
void GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
 We sent a message for which we expect to receive an ACK via the connection identified by cti.
 
void GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
 We observed an ACK for a message that was originally sent via the connection identified by cid.
 
void GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, struct GNUNET_TIME_Relative latency)
 We observed some the given latency on the connection identified by cti.
 
void GCC_handle_connection_create_ack (struct CadetConnection *cc)
 A GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for this connection, implying that the end-to-end connection is up.
 
void GCC_handle_kx (struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
 Handle KX message.
 
void GCC_handle_kx_auth (struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
 Handle KX_AUTH message.
 
void GCC_handle_encrypted (struct CadetConnection *cc, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
 Handle encrypted message.
 
static void cont_send_create (void *cls, const struct GNUNET_PeerIdentity *my_identity, const struct GNUNET_CRYPTO_EddsaSignature *signature)
 
static void send_create (void *cls)
 Send a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the first hop.
 
static void send_create_ack (void *cls)
 Send a CREATE_ACK message towards the origin.
 
void GCC_handle_duplicate_create (struct CadetConnection *cc)
 We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have.
 
static void manage_first_hop_mq (void *cls, int available)
 There has been a change in the message queue existence for our peer at the first hop.
 
static struct CadetConnectionconnection_create (struct CadetPeer *destination, struct CadetPeerPath *path, unsigned int off, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, enum CadetConnectionState init_state, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
 Create a connection to destination via path and notify cb whenever we are ready for more data.
 
struct CadetConnectionGCC_create_inbound (struct CadetPeer *destination, struct CadetPeerPath *path, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
 Create a connection to destination via path and notify cb whenever we are ready for more data.
 
struct CadetConnectionGCC_create (struct CadetPeer *destination, struct CadetPeerPath *path, unsigned int off, struct CadetTConnection *ct, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
 Create a connection to destination via path and notify cb whenever we are ready for more data.
 
void GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
 Transmit message msg via connection cc.
 
struct CadetPeerPathGCC_get_path (struct CadetConnection *cc, unsigned int *off)
 Obtain the path used by this connection.
 
const struct GNUNET_CADET_ConnectionTunnelIdentifierGCC_get_id (struct CadetConnection *cc)
 Obtain unique ID for the connection.
 
const char * GCC_2s (const struct CadetConnection *cc)
 Get a (static) string for a connection.
 
void GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level)
 Log connection info.
 

Detailed Description

management of CORE-level end-to-end connections; establishes end-to-end routes and transmits messages along the route

Author
Bartlomiej Polot
Christian Grothoff

Definition in file gnunet-service-cadet_connection.c.

Macro Definition Documentation

◆ LOG

#define LOG (   level,
  ... 
)    GNUNET_log_from (level, "cadet-con", __VA_ARGS__)

Definition at line 43 of file gnunet-service-cadet_connection.c.

◆ INITIAL_CONNECTION_CREATE_RETRY_DELAY

#define INITIAL_CONNECTION_CREATE_RETRY_DELAY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)

How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have connection-level RTT data!

Definition at line 50 of file gnunet-service-cadet_connection.c.

57{
62
67
72
78
83};
84
88struct CadetConnection
89{
94
98 struct CadetPeer *destination;
99
103 struct CadetTConnection *ct;
104
108 struct CadetPeerPath *path;
109
113 struct GNUNET_MQ_Envelope *env;
114
119
124
129
134
139
144
148 void *ready_cb_cls;
149
154
159
164
169
174
178 unsigned int latency_datapoints;
179
183 unsigned int off;
184
188 int mqm_ready;
189};
190
191
198struct CadetConnection *
200{
203}
204
205
214static void
215update_state (struct CadetConnection *cc,
217 int new_mqm_ready)
218{
219 int old_ready;
220 int new_ready;
221
223 "Trying to update connection state for %s having old state %d to new %d and mqm_ready old %d to mqm_ready new %d\n",
224 GCT_2s (cc->ct->t),
225 cc->state,
226 new_state,
227 cc->mqm_ready,
229
230 if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
231 return; /* no change, nothing to do */
232 old_ready =
233 ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready));
234 new_ready =
236 cc->state = new_state;
238
240 "Updating connection state for %s having old_ready %d and new_rady %d\n",
241 GCT_2s (cc->ct->t),
242 old_ready,
243 new_ready);
244
245 if (old_ready != new_ready)
247}
248
249
256static void
257GCC_destroy (struct CadetConnection *cc)
258{
259 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc));
260 if (NULL != cc->mq_man)
261 {
263 cc->mq_man = NULL;
264 }
265 if (NULL != cc->task)
266 {
268 cc->task = NULL;
269 }
270 if (NULL != cc->sign_op)
271 {
273 cc->sign_op = NULL;
274 }
275 if (NULL != cc->keepalive_qe)
276 {
278 cc->keepalive_qe = NULL;
279 }
280 GCPP_del_connection (cc->path, cc->off, cc);
281 for (unsigned int i = 0; i < cc->off; i++)
284 GNUNET_YES ==
286 &GCC_get_id (cc)
287 ->connection_of_tunnel,
288 cc));
289 GNUNET_free (cc);
290}
291
292
301void
303{
304 if (NULL != cc->ct)
305 {
307 cc->ct = NULL;
308 }
309 GCC_destroy (cc);
310}
311
312
320void
322{
323 cc->ct = NULL;
324 if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
325 {
326 struct GNUNET_MQ_Envelope *env;
327 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
328
329 /* Need to notify next hop that we are down. */
330 env =
332 destroy_msg->cid = cc->cid;
334 cc->mq_man = NULL;
335 }
336 GCC_destroy (cc);
337}
338
339
346struct CadetTConnection *
348{
349 return cc->ct;
350}
351
352
359const struct CadetConnectionMetrics *
361{
362 return &cc->metrics;
363}
364
365
372static void
373send_keepalive (void *cls);
374
375
384static void
385keepalive_done (void *cls,
387{
388 struct CadetConnection *cc = cls;
389
390 cc->keepalive_qe = NULL;
391 if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
392 cc->task =
394}
395
396
403static void
404send_keepalive (void *cls)
405{
406 struct CadetConnection *cc = cls;
408
409 cc->task = NULL;
411 {
412 /* Tunnel not yet ready, wait with keepalives... */
413 cc->task =
415 return;
416 }
417 GNUNET_assert (NULL != cc->ct);
419 GNUNET_assert (NULL == cc->keepalive_qe);
421 "Sending KEEPALIVE on behalf of %s via %s\n",
422 GCC_2s (cc),
423 GCT_2s (cc->ct->t));
424 GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
425 msg.size = htons (sizeof(msg));
427
428 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc, NULL);
429}
430
431
438void
440{
441 struct CadetConnection *cc;
442
443 cc = GCC_lookup (cid);
444 if (NULL == cc)
445 return; /* whopise, connection already down? */
447}
448
449
458void
460{
461 struct CadetConnection *cc;
462
463 cc = GCC_lookup (cid);
464 if (NULL == cc)
465 return; /* whopise, connection already down? */
467}
468
469
470void
472 struct GNUNET_TIME_Relative latency)
473{
474 struct CadetConnection *cc;
475 double weight;
476 double result;
477
478 cc = GCC_lookup (cid);
479 if (NULL == cc)
480 return; /* whopise, connection already down? */
481 GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO);
482 cc->latency_datapoints++;
483 if (cc->latency_datapoints >= 7)
484 weight = 7.0;
485 else
486 weight = cc->latency_datapoints;
487 /* Compute weighted average, giving at MOST weight 7 to the
488 existing values, or less if that value is based on fewer than 7
489 measurements. */
490 result = (weight * cc->metrics.aged_latency.rel_value_us)
491 + 1.0 * latency.rel_value_us;
492 result /= (weight + 1.0);
494}
495
496
497void
499{
501 "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
502 GCC_2s (cc),
503 cc->state,
504 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
505 if (CADET_CONNECTION_READY == cc->state)
506 return; /* Duplicate ACK, ignore */
507 if (NULL != cc->task)
508 {
510 cc->task = NULL;
511 }
514 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
515 (NULL == cc->task))
516 cc->task =
518}
519
520
527void
530{
532 "Received KX message with ephermal %s on CC %s in state %d\n",
533 GNUNET_e2s (&msg->ephemeral_key),
535 cc->state);
536 if (CADET_CONNECTION_SENT == cc->state)
537 {
538 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
539 clearly something is working, so pretend we got an ACK. */
541 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
542 GCC_2s (cc));
544 }
545 GCT_handle_kx (cc->ct, msg);
546}
547
548
555void
558{
560 "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
561 GNUNET_e2s (&msg->kx.ephemeral_key),
563 cc->state);
564 if (CADET_CONNECTION_SENT == cc->state)
565 {
566 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
567 clearly something is working, so pretend we got an ACK. */
569 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
570 GCC_2s (cc));
572 }
574}
575
576
583void
586{
587 if (CADET_CONNECTION_SENT == cc->state)
588 {
589 /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
590 clearly something is working, so pretend we got an ACK. */
592 "Faking connection ACK for %s due to ENCRYPTED payload\n",
593 GCC_2s (cc));
595 }
598}
599
600
601static void
602cont_send_create (void *cls,
603 const struct GNUNET_PeerIdentity *my_identity,
604 const struct GNUNET_CRYPTO_EddsaSignature *signature)
605{
606 struct CadetConnection *cc = cls;
607 struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
608 struct GNUNET_PeerIdentity *pids;
609 struct GNUNET_MQ_Envelope *env;
610
611 cc->sign_op = NULL;
612
614
615 env =
616 GNUNET_MQ_msg_extra (create_msg,
617 (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity),
619 // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed.
620 create_msg->options = 2;
621 create_msg->cid = cc->cid;
622
623 if (signature)
624 {
625 create_msg->has_monotime = GNUNET_YES;
626 create_msg->monotime = GNUNET_TIME_absolute_hton (cc->monotime);
627 create_msg->monotime_sig = *signature;
628 }
629
630 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
631 pids[0] = *my_identity;
632 for (unsigned int i = 0; i <= cc->off; i++)
633 pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i));
635 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
636 GCC_2s (cc),
637 cc->off + 2);
638 cc->env = env;
642 GCP_send (cc->mq_man, env);
643}
644
645
652static void
653send_create (void *cls)
654{
655 struct CadetConnection *cc = cls;
656 struct CadetTunnel *t;
657
658 cc->task = NULL;
660
661 // check for tunnel state and set signed monotime (xrs,t3ss)
663 if ((NULL != t) && (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
665 {
666 struct CadetConnectionCreatePS cp;
667
669
670 cp.purpose.purpose = htonl (
672 cp.purpose.size = htonl (sizeof(cp));
673 cp.monotonic_time = GNUNET_TIME_absolute_hton (cc->monotime);
674
675 if (NULL != cc->sign_op)
677
679 &cont_send_create, cc);
680 }
681 else
683}
684
685
691static void
692send_create_ack (void *cls)
693{
694 struct CadetConnection *cc = cls;
696 struct GNUNET_MQ_Envelope *env;
697
698 cc->task = NULL;
700 "Sending CONNECTION_CREATE_ACK message for %s\n",
701 GCC_2s (cc));
703 env =
705 ack_msg->cid = cc->cid;
706 cc->env = env;
711 if (CADET_CONNECTION_READY == cc->state)
712 cc->task =
714 GCP_send (cc->mq_man, env);
715}
716
717
725void
727{
728 if (GNUNET_YES == cc->mqm_ready)
729 {
731 "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
732 GCC_2s (cc),
733 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
734 /* Revert back to the state of having only received the 'CREATE',
735 and immediately proceed to send the CREATE_ACK. */
737 if (NULL != cc->task)
739 cc->task =
741 }
742 else
743 {
744 /* We are currently sending something else back, which
745 can only be an ACK or payload, either of which would
746 do. So actually no need to do anything. */
748 "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
749 GCC_2s (cc));
750 }
751}
752
753
764static void
765manage_first_hop_mq (void *cls, int available)
766{
767 struct CadetConnection *cc = cls;
768
769 if (GNUNET_YES != available)
770 {
771 /* Connection is down, for now... */
772 LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc));
775 if (NULL != cc->task)
776 {
778 cc->task = NULL;
779 }
780 return;
781 }
782
783 update_state (cc, cc->state, GNUNET_YES);
785 "Core MQ for %s became available in state %d\n",
786 GCC_2s (cc),
787 cc->state);
788 switch (cc->state)
789 {
791 /* Transmit immediately */
793 break;
794
796 /* Should not be possible to be called in this state. */
797 GNUNET_assert (0);
798 break;
799
801 /* Retry a bit later... */
803 break;
804
806 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
808 cc->task =
810 break;
811
813 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
814 (NULL == cc->task))
815 {
817 "Scheduling keepalive for %s in %s\n",
818 GCC_2s (cc),
820 GNUNET_YES));
821 cc->task =
823 }
824 break;
825 }
826}
827
828
843static struct CadetConnection *
845 struct CadetPeerPath *path,
846 unsigned int off,
847 struct CadetTConnection *ct,
851 void *ready_cb_cls)
852{
853 struct CadetConnection *cc;
854 struct CadetPeer *first_hop;
855
856 cc = GNUNET_new (struct CadetConnection);
857 cc->state = init_state;
858 cc->ct = ct;
859 cc->destination = destination; /* xrs,t3ss,lurchi*/
860 cc->cid = *cid;
861 cc->retry_delay =
866 &GCC_get_id (cc)->connection_of_tunnel,
867 cc,
869 cc->ready_cb = ready_cb;
870 cc->ready_cb_cls = ready_cb_cls;
871 cc->path = path;
872 cc->off = off;
874 "Creating %s using path %s (offset: %u)\n",
875 GCC_2s (cc),
876 GCPP_2s (path),
877 off);
878 GCPP_add_connection (path, off, cc);
879 for (unsigned int i = 0; i < off; i++)
881 first_hop = GCPP_get_peer_at_offset (path, 0);
882 cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc);
883 return cc;
884}
885
886
900struct CadetConnection *
902 struct CadetPeerPath *path,
903 struct CadetTConnection *ct,
906 void *ready_cb_cls)
907{
908 struct CadetConnection *cc;
909 unsigned int off;
910
914 if (NULL != cc)
915 {
916 int cmp;
917
918 cmp = GNUNET_memcmp (cid, &cc->cid);
919 if (0 == cmp)
920 {
921 /* Two peers picked the SAME random connection identifier at the
922 same time for the same path? Must be malicious. Drop
923 connection (existing and inbound), even if it is the only
924 one. */
925 GNUNET_break_op (0);
928 return NULL;
929 }
930 if (0 < cmp)
931 {
932 /* drop existing */
934 "Got two connections on %s, dropping my existing %s\n",
935 GCPP_2s (path),
936 GCC_2s (cc));
939 }
940 else
941 {
942 /* keep existing */
944 "Got two connections on %s, keeping my existing %s\n",
945 GCPP_2s (path),
946 GCC_2s (cc));
947 return NULL;
948 }
949 }
950
952 path,
953 off,
954 ct,
955 cid,
957 ready_cb,
959}
960
961
962struct CadetConnection *
964 struct CadetPeerPath *path,
965 unsigned int off,
966 struct CadetTConnection *ct,
968 void *ready_cb_cls)
969{
971
973 return connection_create (destination,
974 path,
975 off,
976 ct,
977 &cid,
979 ready_cb,
980 ready_cb_cls);
981}
982
983
994void
996{
998 "Scheduling message for transmission on %s\n",
999 GCC_2s (cc));
1003 cc->mqm_ready = GNUNET_NO;
1004 if (NULL != cc->task)
1005 {
1007 cc->task = NULL;
1008 }
1009 GCP_send (cc->mq_man, env);
1010}
1011
1012
1020struct CadetPeerPath *
1021GCC_get_path (struct CadetConnection *cc, unsigned int *off)
1022{
1023 *off = cc->off;
1024 return cc->path;
1025}
1026
1027
1035GCC_get_id (struct CadetConnection *cc)
1036{
1037 return &cc->cid;
1038}
1039
1040
1046const char *
1047GCC_2s (const struct CadetConnection *cc)
1048{
1049 static char buf[128];
1050
1051 if (NULL == cc)
1052 return "Connection(NULL)";
1053
1054 if (NULL != cc->ct)
1055 {
1056 GNUNET_snprintf (buf,
1057 sizeof(buf),
1058 "Connection %s (%s)",
1060 GCT_2s (cc->ct->t));
1061 return buf;
1062 }
1063 GNUNET_snprintf (buf,
1064 sizeof(buf),
1065 "Connection %s",
1067 return buf;
1068}
1069
1070
1071#define LOG2(level, ...) \
1072 GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)
1073
1074
1081void
1082GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level)
1083{
1084#if ! defined(GNUNET_CULL_LOGGING)
1085 int do_log;
1086
1088 "cadet-con",
1089 __FILE__,
1090 __FUNCTION__,
1091 __LINE__);
1092 if (0 == do_log)
1093 return;
1094 if (NULL == cc)
1095 {
1096 LOG2 (level, "Connection (NULL)\n");
1097 return;
1098 }
1099 LOG2 (level,
1100 "%s to %s via path %s in state %d is %s\n",
1101 GCC_2s (cc),
1102 GCP_2s (cc->destination),
1103 GCPP_2s (cc->path),
1104 cc->state,
1105 (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
1106#endif
1107}
1108
1109
1110/* end of gnunet-service-cadet_connection.c */
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_SCHEDULER_Task * t
Main task.
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
static int result
Global testing status.
struct GNUNET_CONTAINER_MultiShortmap * connections
Map from struct GNUNET_CADET_ConnectionTunnelIdentifier hash codes to struct CadetConnection objects.
struct GNUNET_TIME_Relative keepalive_period
How frequently do we send KEEPALIVE messages on idle connections?
static struct CadetConnection * connection_create(struct CadetPeer *destination, struct CadetPeerPath *path, unsigned int off, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, enum CadetConnectionState init_state, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
static void cont_send_create(void *cls, const struct GNUNET_PeerIdentity *my_identity, const struct GNUNET_CRYPTO_EddsaSignature *signature)
static void manage_first_hop_mq(void *cls, int available)
There has been a change in the message queue existence for our peer at the first hop.
void GCC_handle_encrypted(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Handle encrypted message.
struct CadetPeerPath * GCC_get_path(struct CadetConnection *cc, unsigned int *off)
Obtain the path used by this connection.
#define INITIAL_CONNECTION_CREATE_RETRY_DELAY
How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have co...
void GCC_handle_connection_create_ack(struct CadetConnection *cc)
A GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for this connection,...
CadetConnectionState
All the states a connection can be in.
@ CADET_CONNECTION_NEW
Uninitialized status, we have not yet even gotten the message queue.
@ CADET_CONNECTION_READY
Connection confirmed, ready to carry traffic.
@ CADET_CONNECTION_SENDING_CREATE
Connection create message in queue, awaiting transmission by CORE.
@ CADET_CONNECTION_CREATE_RECEIVED
We are an inbound connection, and received a CREATE.
@ CADET_CONNECTION_SENT
Connection create message sent, waiting for ACK.
#define LOG2(level,...)
void GCC_handle_kx(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
Handle KX message.
void GCC_destroy_without_core(struct CadetConnection *cc)
Destroy a connection, called when the CORE layer is already done (i.e.
static void update_state(struct CadetConnection *cc, enum CadetConnectionState new_state, int new_mqm_ready)
Update the connection state.
void GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, struct GNUNET_TIME_Relative latency)
We observed some the given latency on the connection identified by cti.
void GCC_handle_kx_auth(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
Handle KX_AUTH message.
static void keepalive_done(void *cls, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Keepalive was transmitted.
static void GCC_destroy(struct CadetConnection *cc)
Destroy a connection, part of the internal implementation.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct CadetConnection * GCC_create_inbound(struct CadetPeer *destination, struct CadetPeerPath *path, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
static void send_keepalive(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the tunnel to prevent it from timing out.
static void send_create_ack(void *cls)
Send a CREATE_ACK message towards the origin.
void GCC_handle_duplicate_create(struct CadetConnection *cc)
We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have.
void GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
We observed an ACK for a message that was originally sent via the connection identified by cid.
struct CadetTConnection * GCC_get_ct(struct CadetConnection *cc)
Return the tunnel associated with this connection.
static void send_create(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the first hop.
void GCC_destroy_without_tunnel(struct CadetConnection *cc)
Destroy a connection, called if the tunnel association with the connection was already broken,...
#define LOG(level,...)
struct CadetConnection * GCC_create(struct CadetPeer *destination, struct CadetPeerPath *path, unsigned int off, struct CadetTConnection *ct, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
void GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
Transmit message msg via connection cc.
void GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level)
Log connection info.
const struct CadetConnectionMetrics * GCC_get_metrics(struct CadetConnection *cc)
Obtain performance metrics from cc.
void GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
We sent a message for which we expect to receive an ACK via the connection identified by cti.
struct CadetConnection * GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Lookup a connection by its identifier.
const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id(struct CadetConnection *cc)
Obtain unique ID for the connection.
void(* GCC_ReadyCallback)(void *cls, int is_ready)
Function called to notify tunnel about change in our readiness.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
struct CadetConnection * GCPP_get_connection(struct CadetPeerPath *path, struct CadetPeer *destination, unsigned int off)
Return connection to destination using path, or return NULL if no such connection exists.
void GCPP_del_connection(struct CadetPeerPath *path, unsigned int off, struct CadetConnection *cc)
Notify path that it is no longer used for connection cc which ended at the path's offset off.
void GCPP_add_connection(struct CadetPeerPath *path, unsigned int off, struct CadetConnection *cc)
Notify path that it is used for connection cc which ends at the path's offset off.
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
unsigned int GCPP_find_peer(struct CadetPeerPath *path, struct CadetPeer *cp)
Find peer's offset on path.
void GCP_add_connection(struct CadetPeer *cp, struct CadetConnection *cc)
Add a connection to this cp.
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
struct CadetTunnel * GCP_get_tunnel(struct CadetPeer *cp, int create)
Get the tunnel towards a peer.
void GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *last_env)
Stops message queue change notifications.
void GCP_send(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *env)
Send the message in env to cp.
void GCP_remove_connection(struct CadetPeer *cp, struct CadetConnection *cc)
Remove a connection that went via this cp.
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct GCP_MessageQueueManager * GCP_request_mq(struct CadetPeer *cp, GCP_MessageQueueNotificationCallback cb, void *cb_cls)
Start message queue change notifications.
void GCT_handle_kx(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
Continue to handle KX message.
void GCT_send_cancel(struct CadetTunnelQueueEntry *tq)
Cancel a previously sent message while it's in the queue.
void GCT_handle_kx_auth(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
Handle KX_AUTH message.
void GCT_handle_encrypted(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Handle encrypted message.
struct CadetTunnelQueueEntry * GCT_send(struct CadetTunnel *t, const struct GNUNET_MessageHeader *message, GCT_SendContinuation cont, void *cont_cls, struct GNUNET_CADET_ChannelTunnelNumber *ctn)
Sends an already built message on a tunnel, encrypting it and choosing the best connection if not pro...
void GCT_connection_lost(struct CadetTConnection *ct)
We lost a connection, remove it from our list and clean up the connection object itself.
enum CadetTunnelEState GCT_get_estate(struct CadetTunnel *t)
Get the encryption state of a tunnel.
int GCT_alice_or_betty(const struct GNUNET_PeerIdentity *other)
Am I Alice or Betty (some call her Bob), or talking to myself?
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
@ CADET_TUNNEL_KEY_UNINITIALIZED
Uninitialized status, we need to send KX.
@ CADET_TUNNEL_KEY_OK
Handshake completed: session key available.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
Definition pils_api.c:623
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition pils_api.c:528
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR
Signature by a peer that like to create a connection.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
int GNUNET_get_log_call_status(int caller_level, const char *comp, const char *file, const char *function, int line)
Decides whether a particular logging call should or should not be allowed to be made.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
GNUNET_ErrorType
Types of errors.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
Send origin an ACK that the connection is complete.
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
Request the destruction of a connection.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE
Announce connection is still alive (direction sensitive).
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
Request the creation of a connection.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition scheduler.c:1260
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition strings.c:604
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition time.c:486
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition time.c:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Purpose for the signature of a monotime.
Performance metrics for a connection.
struct GNUNET_TIME_Relative aged_latency
Our current best estimate of the latency, based on a weighted average of at least latency_datapoints ...
unsigned long long num_acked_transmissions
How many packets that ought to generate an ACK did we send via this connection?
struct GNUNET_TIME_Absolute age
When was this connection first established? (by us sending or receiving the CREATE_ACK for the first ...
unsigned long long num_successes
Number of packets that were sent via this connection did actually receive an ACK? (Note: ACKs may be ...
struct GNUNET_TIME_Absolute last_use
When was this connection last used? (by us sending or receiving a PAYLOAD message on it)
Low-level connection to a destination.
struct CadetTConnection * ct
Which tunnel is using this connection?
struct GNUNET_MQ_Envelope * env
Pending message, NULL if we are ready to transmit.
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
GCC_ReadyCallback ready_cb
Function to call once we are ready to transmit.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct GNUNET_SCHEDULER_Task * task
Task for connection maintenance.
struct GNUNET_TIME_Absolute create_at
Earliest time for re-trying CREATE.
unsigned int latency_datapoints
How many latency observations did we make for this connection?
struct GNUNET_TIME_Relative retry_delay
How long do we wait before we try again with a CREATE message?
struct GNUNET_TIME_Absolute create_ack_at
Earliest time for re-trying CREATE_ACK.
void * ready_cb_cls
Closure for ready_cb.
struct GNUNET_TIME_Absolute monotime
Latest monotonic timestamp to be signed.
enum CadetConnectionState state
State of the connection.
struct CadetPeerPath * path
Path we are using to our destination.
struct GNUNET_PILS_Operation * sign_op
Operation for signature handling.
unsigned int off
Offset of our destination in path.
int mqm_ready
Are we ready to transmit via mq_man right now?
struct GCP_MessageQueueManager * mq_man
Handle for calling GCP_request_mq_cancel() once we are finished.
struct CadetPeer * destination
To which peer does this connection go?
struct CadetTunnelQueueEntry * keepalive_qe
Queue entry for keepalive messages.
Information regarding a possible path to reach a peer.
Struct containing all information regarding a given peer.
Entry in list of connections used by tunnel, with metadata.
struct CadetConnection * cc
Connection handle.
struct CadetTunnel * t
Tunnel this connection belongs to.
Struct used to save messages in a non-ready tunnel to send once connected.
Struct containing all information regarding a tunnel to a peer.
Data structure used to track whom we have to notify about changes to our message queue.
Message for ack'ing a connection.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
Message for cadet connection creation.
int has_monotime
This flag indicates the peer sending the connection create message likes to trigger a KX handshake.
uint32_t options
Connection options in network byte order.
struct GNUNET_CRYPTO_EddsaSignature monotime_sig
We sign the monotime.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct GNUNET_TIME_AbsoluteNBO monotime
This monotonic time is set, if a peer likes to trigger a KX, but is not the peer that should start th...
Message to destroy a connection.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
Hash uniquely identifying a connection below a tunnel.
struct GNUNET_ShortHashCode connection_of_tunnel
Axolotl-encrypted tunnel message with application payload.
Message for a Key eXchange for a tunnel, with authentication.
Message for a Key eXchange for a tunnel.
an ECC signature using EdDSA.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:141
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

◆ LOG2

#define LOG2 (   level,
  ... 
)     GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)

Definition at line 1072 of file gnunet-service-cadet_connection.c.

Enumeration Type Documentation

◆ CadetConnectionState

All the states a connection can be in.

Enumerator
CADET_CONNECTION_NEW 

Uninitialized status, we have not yet even gotten the message queue.

CADET_CONNECTION_SENDING_CREATE 

Connection create message in queue, awaiting transmission by CORE.

CADET_CONNECTION_SENT 

Connection create message sent, waiting for ACK.

CADET_CONNECTION_CREATE_RECEIVED 

We are an inbound connection, and received a CREATE.

Need to send an CREATE_ACK back.

CADET_CONNECTION_READY 

Connection confirmed, ready to carry traffic.

Definition at line 57 of file gnunet-service-cadet_connection.c.

Function Documentation

◆ GCC_lookup()

struct CadetConnection * GCC_lookup ( const struct GNUNET_CADET_ConnectionTunnelIdentifier cid)

Lookup a connection by its identifier.

Parameters
cididentifier to resolve
Returns
NULL if connection was not found

Definition at line 200 of file gnunet-service-cadet_connection.c.

References CadetConnection::cid, GNUNET_CADET_ConnectionTunnelIdentifier::connection_of_tunnel, connections, and GNUNET_CONTAINER_multishortmap_get().

Referenced by data_sent_cb(), GCC_ack_expected(), GCC_ack_observed(), GCC_latency_observed(), handle_connection_broken(), handle_connection_create(), handle_connection_create_ack(), handle_connection_destroy(), handle_tunnel_encrypted(), handle_tunnel_kx(), and handle_tunnel_kx_auth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_state()

static void update_state ( struct CadetConnection cc,
enum CadetConnectionState  new_state,
int  new_mqm_ready 
)
static

Update the connection state.

Also triggers the necessary MQM notifications.

Parameters
ccconnection to update the state for
new_statenew state for cc
new_mqm_readynew mqm_ready state for cc

Definition at line 216 of file gnunet-service-cadet_connection.c.

219{
220 int old_ready;
221 int new_ready;
222
224 "Trying to update connection state for %s having old state %d to new %d and mqm_ready old %d to mqm_ready new %d\n",
225 GCT_2s (cc->ct->t),
226 cc->state,
227 new_state,
228 cc->mqm_ready,
229 new_mqm_ready);
230
231 if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
232 return; /* no change, nothing to do */
233 old_ready =
234 ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready));
235 new_ready =
236 ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
237 cc->state = new_state;
238 cc->mqm_ready = new_mqm_ready;
239
241 "Updating connection state for %s having old_ready %d and new_rady %d\n",
242 GCT_2s (cc->ct->t),
243 old_ready,
244 new_ready);
245
246 if (old_ready != new_ready)
247 cc->ready_cb (cc->ready_cb_cls, new_ready);
248}

References CADET_CONNECTION_READY, CadetConnection::ct, GCT_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, LOG, CadetConnection::mqm_ready, CadetConnection::off, CadetConnection::ready_cb, CadetConnection::ready_cb_cls, CadetConnection::state, and CadetTConnection::t.

Referenced by cont_send_create(), GCC_handle_connection_create_ack(), GCC_handle_duplicate_create(), manage_first_hop_mq(), and send_create_ack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_destroy()

static void GCC_destroy ( struct CadetConnection cc)
static

Destroy a connection, part of the internal implementation.

Called only from #GCC_destroy_from_core() or #GCC_destroy_from_tunnel().

Parameters
ccconnection to destroy

Definition at line 258 of file gnunet-service-cadet_connection.c.

259{
260 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc));
261 if (NULL != cc->mq_man)
262 {
263 GCP_request_mq_cancel (cc->mq_man, NULL);
264 cc->mq_man = NULL;
265 }
266 if (NULL != cc->task)
267 {
269 cc->task = NULL;
270 }
271 if (NULL != cc->sign_op)
272 {
274 cc->sign_op = NULL;
275 }
276 if (NULL != cc->keepalive_qe)
277 {
279 cc->keepalive_qe = NULL;
280 }
281 GCPP_del_connection (cc->path, cc->off, cc);
282 for (unsigned int i = 0; i < cc->off; i++)
285 GNUNET_YES ==
287 &GCC_get_id (cc)
288 ->connection_of_tunnel,
289 cc));
290 GNUNET_free (cc);
291}

References connections, GCC_2s(), GCC_get_id(), GCP_remove_connection(), GCP_request_mq_cancel(), GCPP_del_connection(), GCPP_get_peer_at_offset(), GCT_send_cancel(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_PILS_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, CadetConnection::keepalive_qe, LOG, CadetConnection::mq_man, CadetConnection::off, CadetConnection::path, CadetConnection::sign_op, and CadetConnection::task.

Referenced by GCC_destroy_without_core(), and GCC_destroy_without_tunnel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_destroy_without_core()

void GCC_destroy_without_core ( struct CadetConnection cc)

Destroy a connection, called when the CORE layer is already done (i.e.

has received a BROKEN message), but if we still have to communicate the destruction of the connection to the tunnel (if one exists).

Parameters
ccconnection to destroy

Definition at line 303 of file gnunet-service-cadet_connection.c.

304{
305 if (NULL != cc->ct)
306 {
308 cc->ct = NULL;
309 }
310 GCC_destroy (cc);
311}

References CadetConnection::ct, GCC_destroy(), GCT_connection_lost(), and CadetConnection::off.

Referenced by handle_connection_broken(), and handle_connection_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_destroy_without_tunnel()

void GCC_destroy_without_tunnel ( struct CadetConnection cc)

Destroy a connection, called if the tunnel association with the connection was already broken, but we still need to notify the CORE layer about the breakage.

Parameters
ccconnection to destroy

Definition at line 322 of file gnunet-service-cadet_connection.c.

323{
324 cc->ct = NULL;
325 if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
326 {
327 struct GNUNET_MQ_Envelope *env;
328 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
329
330 /* Need to notify next hop that we are down. */
331 env =
333 destroy_msg->cid = cc->cid;
335 cc->mq_man = NULL;
336 }
337 GCC_destroy (cc);
338}

References CADET_CONNECTION_SENDING_CREATE, GNUNET_CADET_ConnectionDestroyMessage::cid, CadetConnection::cid, CadetConnection::ct, env, GCC_destroy(), GCP_request_mq_cancel(), GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, GNUNET_MQ_msg, CadetConnection::mq_man, CadetConnection::off, and CadetConnection::state.

Referenced by destroy_t_connection(), and GCC_create_inbound().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_get_ct()

struct CadetTConnection * GCC_get_ct ( struct CadetConnection cc)

Return the tunnel associated with this connection.

Parameters
ccconnection to query
Returns
corresponding entry in the tunnel's connection list

Definition at line 348 of file gnunet-service-cadet_connection.c.

349{
350 return cc->ct;
351}

References CadetTConnection::cc, and CadetConnection::ct.

◆ GCC_get_metrics()

const struct CadetConnectionMetrics * GCC_get_metrics ( struct CadetConnection cc)

Obtain performance metrics from cc.

Parameters
ccconnection to query
Returns
the metrics

Definition at line 361 of file gnunet-service-cadet_connection.c.

362{
363 return &cc->metrics;
364}

References CadetConnection::metrics.

Referenced by data_sent_cb(), and evaluate_connection().

Here is the caller graph for this function:

◆ send_keepalive()

static void send_keepalive ( void *  cls)
static

Send a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the tunnel to prevent it from timing out.

Parameters
clsthe struct CadetConnection to keep alive.

Definition at line 405 of file gnunet-service-cadet_connection.c.

406{
407 struct CadetConnection *cc = cls;
409
410 cc->task = NULL;
412 {
413 /* Tunnel not yet ready, wait with keepalives... */
414 cc->task =
416 return;
417 }
418 GNUNET_assert (NULL != cc->ct);
420 GNUNET_assert (NULL == cc->keepalive_qe);
422 "Sending KEEPALIVE on behalf of %s via %s\n",
423 GCC_2s (cc),
424 GCT_2s (cc->ct->t));
425 GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
426 msg.size = htons (sizeof(msg));
428
429 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc, NULL);
430}

References CADET_TUNNEL_KEY_OK, CadetConnection::ct, GCC_2s(), GCT_2s(), GCT_get_estate(), GCT_send(), GNUNET_assert, GNUNET_ERROR_TYPE_INFO, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_YES, keepalive_done(), keepalive_period, CadetConnection::keepalive_qe, LOG, CadetConnection::mqm_ready, msg, send_keepalive(), GNUNET_MessageHeader::size, stats, CadetTConnection::t, CadetConnection::task, and GNUNET_MessageHeader::type.

Referenced by GCC_handle_connection_create_ack(), keepalive_done(), manage_first_hop_mq(), send_create_ack(), and send_keepalive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ keepalive_done()

static void keepalive_done ( void *  cls,
const struct GNUNET_CADET_ConnectionTunnelIdentifier cid 
)
static

Keepalive was transmitted.

Remember this, and possibly schedule the next one.

Parameters
clsthe struct CadetConnection to keep alive.
cididentifier of the connection within the tunnel, NULL if transmission failed

Definition at line 386 of file gnunet-service-cadet_connection.c.

388{
389 struct CadetConnection *cc = cls;
390
391 cc->keepalive_qe = NULL;
392 if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
393 cc->task =
395}

References GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, keepalive_period, CadetConnection::keepalive_qe, CadetConnection::mqm_ready, CadetConnection::off, send_keepalive(), and CadetConnection::task.

Referenced by send_keepalive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_ack_expected()

void GCC_ack_expected ( const struct GNUNET_CADET_ConnectionTunnelIdentifier cid)

We sent a message for which we expect to receive an ACK via the connection identified by cti.

Parameters
cidconnection identifier where we expect an ACK

Definition at line 440 of file gnunet-service-cadet_connection.c.

441{
442 struct CadetConnection *cc;
443
444 cc = GCC_lookup (cid);
445 if (NULL == cc)
446 return; /* whopise, connection already down? */
448}

References CadetConnection::cid, GCC_lookup(), CadetConnection::metrics, CadetConnectionMetrics::num_acked_transmissions, and CadetConnection::off.

Referenced by data_sent_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_ack_observed()

void GCC_ack_observed ( const struct GNUNET_CADET_ConnectionTunnelIdentifier cid)

We observed an ACK for a message that was originally sent via the connection identified by cid.

We observed an ACK for a message that was originally sent via the connection identified by cti.

Parameters
cidconnection identifier where we got an ACK for a message that was originally sent via this connection (the ACK may have gotten back to us via a different connection).

Definition at line 460 of file gnunet-service-cadet_connection.c.

461{
462 struct CadetConnection *cc;
463
464 cc = GCC_lookup (cid);
465 if (NULL == cc)
466 return; /* whopise, connection already down? */
468}

References CadetConnection::cid, GCC_lookup(), CadetConnection::metrics, CadetConnectionMetrics::num_successes, and CadetConnection::off.

Referenced by handle_matching_ack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_latency_observed()

void GCC_latency_observed ( const struct GNUNET_CADET_ConnectionTunnelIdentifier cti,
struct GNUNET_TIME_Relative  latency 
)

We observed some the given latency on the connection identified by cti.

(The same connection was taken in both directions.)

Parameters
cticonnection identifier where we measured latency
latencythe observed latency

Definition at line 472 of file gnunet-service-cadet_connection.c.

474{
475 struct CadetConnection *cc;
476 double weight;
477 double result;
478
479 cc = GCC_lookup (cid);
480 if (NULL == cc)
481 return; /* whopise, connection already down? */
482 GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO);
483 cc->latency_datapoints++;
484 if (cc->latency_datapoints >= 7)
485 weight = 7.0;
486 else
487 weight = cc->latency_datapoints;
488 /* Compute weighted average, giving at MOST weight 7 to the
489 existing values, or less if that value is based on fewer than 7
490 measurements. */
491 result = (weight * cc->metrics.aged_latency.rel_value_us)
492 + 1.0 * latency.rel_value_us;
493 result /= (weight + 1.0);
495}

References CadetConnectionMetrics::aged_latency, CadetConnection::cid, GCC_lookup(), GNUNET_NO, GNUNET_STATISTICS_update(), CadetConnection::latency_datapoints, CadetConnection::metrics, CadetConnection::off, GNUNET_TIME_Relative::rel_value_us, result, and stats.

Referenced by handle_matching_ack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_handle_connection_create_ack()

void GCC_handle_connection_create_ack ( struct CadetConnection cc)

A GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for this connection, implying that the end-to-end connection is up.

Process it.

Parameters
ccthe connection that got the ACK.

Definition at line 499 of file gnunet-service-cadet_connection.c.

500{
502 "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
503 GCC_2s (cc),
504 cc->state,
505 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
506 if (CADET_CONNECTION_READY == cc->state)
507 return; /* Duplicate ACK, ignore */
508 if (NULL != cc->task)
509 {
511 cc->task = NULL;
512 }
515 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
516 (NULL == cc->task))
517 cc->task =
519}

References CadetConnectionMetrics::age, CADET_CONNECTION_READY, GCC_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get(), GNUNET_YES, keepalive_period, CadetConnection::keepalive_qe, LOG, CadetConnection::metrics, CadetConnection::mqm_ready, CadetConnection::off, send_keepalive(), CadetConnection::state, CadetConnection::task, and update_state().

Referenced by GCC_handle_encrypted(), GCC_handle_kx(), GCC_handle_kx_auth(), and handle_connection_create_ack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_handle_kx()

void GCC_handle_kx ( struct CadetConnection cc,
const struct GNUNET_CADET_TunnelKeyExchangeMessage msg 
)

Handle KX message.

Parameters
ccconnection that received encrypted message
msgthe key exchange message

Definition at line 529 of file gnunet-service-cadet_connection.c.

531{
533 "Received KX message with ephermal %s on CC %s in state %d\n",
534 GNUNET_e2s (&msg->ephemeral_key),
536 cc->state);
537 if (CADET_CONNECTION_SENT == cc->state)
538 {
539 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
540 clearly something is working, so pretend we got an ACK. */
542 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
543 GCC_2s (cc));
545 }
546 GCT_handle_kx (cc->ct, msg);
547}

References CADET_CONNECTION_SENT, CadetConnection::cid, GNUNET_CADET_ConnectionTunnelIdentifier::connection_of_tunnel, CadetConnection::ct, GCC_2s(), GCC_handle_connection_create_ack(), GCT_handle_kx(), GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_sh2s(), LOG, msg, and CadetConnection::state.

Referenced by handle_tunnel_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_handle_kx_auth()

void GCC_handle_kx_auth ( struct CadetConnection cc,
const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage msg 
)

Handle KX_AUTH message.

Parameters
ccconnection that received encrypted message
msgthe key exchange message

Definition at line 557 of file gnunet-service-cadet_connection.c.

559{
561 "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
562 GNUNET_e2s (&msg->kx.ephemeral_key),
564 cc->state);
565 if (CADET_CONNECTION_SENT == cc->state)
566 {
567 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
568 clearly something is working, so pretend we got an ACK. */
570 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
571 GCC_2s (cc));
573 }
575}

References CADET_CONNECTION_SENT, CadetConnection::cid, GNUNET_CADET_ConnectionTunnelIdentifier::connection_of_tunnel, CadetConnection::ct, GCC_2s(), GCC_handle_connection_create_ack(), GCT_handle_kx_auth(), GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_sh2s(), LOG, msg, and CadetConnection::state.

Referenced by handle_tunnel_kx_auth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_handle_encrypted()

void GCC_handle_encrypted ( struct CadetConnection cc,
const struct GNUNET_CADET_TunnelEncryptedMessage msg 
)

Handle encrypted message.

Parameters
ccconnection that received encrypted message
msgthe encrypted message to decrypt

Definition at line 585 of file gnunet-service-cadet_connection.c.

587{
588 if (CADET_CONNECTION_SENT == cc->state)
589 {
590 /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
591 clearly something is working, so pretend we got an ACK. */
593 "Faking connection ACK for %s due to ENCRYPTED payload\n",
594 GCC_2s (cc));
596 }
599}

References CADET_CONNECTION_SENT, CadetConnection::ct, GCC_2s(), GCC_handle_connection_create_ack(), GCT_handle_encrypted(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_TIME_absolute_get(), CadetConnectionMetrics::last_use, LOG, CadetConnection::metrics, msg, and CadetConnection::state.

Referenced by handle_tunnel_encrypted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cont_send_create()

static void cont_send_create ( void *  cls,
const struct GNUNET_PeerIdentity my_identity,
const struct GNUNET_CRYPTO_EddsaSignature signature 
)
static

Definition at line 603 of file gnunet-service-cadet_connection.c.

606{
607 struct CadetConnection *cc = cls;
608 struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
609 struct GNUNET_PeerIdentity *pids;
610 struct GNUNET_MQ_Envelope *env;
611
612 cc->sign_op = NULL;
613
615
616 env =
617 GNUNET_MQ_msg_extra (create_msg,
618 (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity),
620 // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed.
621 create_msg->options = 2;
622 create_msg->cid = cc->cid;
623
624 if (signature)
625 {
626 create_msg->has_monotime = GNUNET_YES;
627 create_msg->monotime = GNUNET_TIME_absolute_hton (cc->monotime);
628 create_msg->monotime_sig = *signature;
629 }
630
631 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
632 pids[0] = *my_identity;
633 for (unsigned int i = 0; i <= cc->off; i++)
634 pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i));
636 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
637 GCC_2s (cc),
638 cc->off + 2);
639 cc->env = env;
643 GCP_send (cc->mq_man, env);
644}

References CADET_CONNECTION_SENT, GNUNET_CADET_ConnectionCreateMessage::cid, CadetConnection::cid, CadetConnection::create_at, env, CadetConnection::env, GCC_2s(), GCP_get_id(), GCP_send(), GCPP_get_peer_at_offset(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, GNUNET_MQ_msg_extra, GNUNET_NO, GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, GNUNET_CADET_ConnectionCreateMessage::has_monotime, LOG, GNUNET_CADET_ConnectionCreateMessage::monotime, CadetConnection::monotime, GNUNET_CADET_ConnectionCreateMessage::monotime_sig, CadetConnection::mq_man, my_identity, CadetConnection::off, GNUNET_CADET_ConnectionCreateMessage::options, CadetConnection::path, CadetConnection::retry_delay, CadetConnection::sign_op, and update_state().

Referenced by send_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_create()

static void send_create ( void *  cls)
static

Send a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the first hop.

Parameters
clsthe struct CadetConnection to initiate

Definition at line 654 of file gnunet-service-cadet_connection.c.

655{
656 struct CadetConnection *cc = cls;
657 struct CadetTunnel *t;
658
659 cc->task = NULL;
661
662 // check for tunnel state and set signed monotime (xrs,t3ss)
664 if ((NULL != t) && (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
666 {
667 struct CadetConnectionCreatePS cp;
668
670
671 cp.purpose.purpose = htonl (
673 cp.purpose.size = htonl (sizeof(cp));
674 cp.monotonic_time = GNUNET_TIME_absolute_hton (cc->monotime);
675
676 if (NULL != cc->sign_op)
678
680 &cont_send_create, cc);
681 }
682 else
684}

References CADET_TUNNEL_KEY_UNINITIALIZED, cfg, cont_send_create(), CadetConnection::destination, GCP_get_id(), GCP_get_tunnel(), GCT_alice_or_betty(), GCT_get_estate(), GNUNET_assert, GNUNET_NO, GNUNET_PILS_cancel(), GNUNET_PILS_get_identity(), GNUNET_PILS_sign_by_peer_identity(), GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), GNUNET_YES, CadetConnection::monotime, CadetConnectionCreatePS::monotonic_time, CadetConnection::mqm_ready, pils, GNUNET_CRYPTO_SignaturePurpose::purpose, CadetConnectionCreatePS::purpose, CadetConnection::sign_op, GNUNET_CRYPTO_SignaturePurpose::size, t, and CadetConnection::task.

Referenced by manage_first_hop_mq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_create_ack()

static void send_create_ack ( void *  cls)
static

Send a CREATE_ACK message towards the origin.

Parameters
clsthe struct CadetConnection to initiate

Definition at line 693 of file gnunet-service-cadet_connection.c.

694{
695 struct CadetConnection *cc = cls;
697 struct GNUNET_MQ_Envelope *env;
698
699 cc->task = NULL;
701 "Sending CONNECTION_CREATE_ACK message for %s\n",
702 GCC_2s (cc));
704 env =
706 ack_msg->cid = cc->cid;
707 cc->env = env;
712 if (CADET_CONNECTION_READY == cc->state)
713 cc->task =
715 GCP_send (cc->mq_man, env);
716}

References CADET_CONNECTION_CREATE_RECEIVED, CADET_CONNECTION_READY, GNUNET_CADET_ConnectionCreateAckMessage::cid, CadetConnection::cid, CadetConnection::create_ack_at, env, CadetConnection::env, GCC_2s(), GCP_send(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, GNUNET_MQ_msg, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, keepalive_period, LOG, CadetConnection::mq_man, CadetConnection::mqm_ready, CadetConnection::retry_delay, send_keepalive(), CadetConnection::state, CadetConnection::task, and update_state().

Referenced by GCC_handle_duplicate_create(), and manage_first_hop_mq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_handle_duplicate_create()

void GCC_handle_duplicate_create ( struct CadetConnection cc)

We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have.

Either our ACK got lost or something is fishy. Consider retransmitting the ACK.

Parameters
ccconnection that got the duplicate CREATE

Definition at line 727 of file gnunet-service-cadet_connection.c.

728{
729 if (GNUNET_YES == cc->mqm_ready)
730 {
732 "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
733 GCC_2s (cc),
734 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
735 /* Revert back to the state of having only received the 'CREATE',
736 and immediately proceed to send the CREATE_ACK. */
738 if (NULL != cc->task)
740 cc->task =
742 }
743 else
744 {
745 /* We are currently sending something else back, which
746 can only be an ACK or payload, either of which would
747 do. So actually no need to do anything. */
749 "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
750 GCC_2s (cc));
751 }
752}

References CADET_CONNECTION_CREATE_RECEIVED, CadetConnection::create_ack_at, GCC_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, LOG, CadetConnection::mqm_ready, send_create_ack(), CadetConnection::task, and update_state().

Referenced by handle_connection_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manage_first_hop_mq()

static void manage_first_hop_mq ( void *  cls,
int  available 
)
static

There has been a change in the message queue existence for our peer at the first hop.

Adjust accordingly.

Parameters
clsthe struct CadetConnection
availableGNUNET_YES if sending is now possible, GNUNET_NO if sending is no longer possible GNUNET_SYSERR if sending is no longer possible and the last envelope was discarded

Definition at line 766 of file gnunet-service-cadet_connection.c.

767{
768 struct CadetConnection *cc = cls;
769
770 if (GNUNET_YES != available)
771 {
772 /* Connection is down, for now... */
773 LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc));
776 if (NULL != cc->task)
777 {
779 cc->task = NULL;
780 }
781 return;
782 }
783
784 update_state (cc, cc->state, GNUNET_YES);
786 "Core MQ for %s became available in state %d\n",
787 GCC_2s (cc),
788 cc->state);
789 switch (cc->state)
790 {
792 /* Transmit immediately */
794 break;
795
797 /* Should not be possible to be called in this state. */
798 GNUNET_assert (0);
799 break;
800
802 /* Retry a bit later... */
804 break;
805
807 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
809 cc->task =
811 break;
812
814 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
815 (NULL == cc->task))
816 {
818 "Scheduling keepalive for %s in %s\n",
819 GCC_2s (cc),
821 GNUNET_YES));
822 cc->task =
824 }
825 break;
826 }
827}

References CadetConnectionMetrics::age, CADET_CONNECTION_CREATE_RECEIVED, CADET_CONNECTION_NEW, CADET_CONNECTION_READY, CADET_CONNECTION_SENDING_CREATE, CADET_CONNECTION_SENT, CadetConnection::create_ack_at, CadetConnection::create_at, GCC_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_YES, INITIAL_CONNECTION_CREATE_RETRY_DELAY, keepalive_period, CadetConnection::keepalive_qe, LOG, CadetConnection::metrics, CadetConnection::mqm_ready, CadetConnection::off, CadetConnection::retry_delay, send_create(), send_create_ack(), send_keepalive(), CadetConnection::state, CadetConnection::task, and update_state().

Referenced by connection_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_create()

static struct CadetConnection * connection_create ( struct CadetPeer destination,
struct CadetPeerPath path,
unsigned int  off,
struct CadetTConnection ct,
const struct GNUNET_CADET_ConnectionTunnelIdentifier cid,
enum CadetConnectionState  init_state,
GCC_ReadyCallback  ready_cb,
void *  ready_cb_cls 
)
static

Create a connection to destination via path and notify cb whenever we are ready for more data.

Shared logic independent of who is initiating the connection.

Parameters
destinationwhere to go
pathwhich path to take (may not be the full path)
offoffset of destination on path
ctwhich tunnel uses this connection
init_stateinitial state for the connection
ready_cbfunction to call when ready to transmit
ready_cb_clsclosure for cb
Returns
handle to the connection

Definition at line 845 of file gnunet-service-cadet_connection.c.

853{
854 struct CadetConnection *cc;
855 struct CadetPeer *first_hop;
856
857 cc = GNUNET_new (struct CadetConnection);
858 cc->state = init_state;
859 cc->ct = ct;
860 cc->destination = destination; /* xrs,t3ss,lurchi*/
861 cc->cid = *cid;
862 cc->retry_delay =
867 &GCC_get_id (cc)->connection_of_tunnel,
868 cc,
870 cc->ready_cb = ready_cb;
871 cc->ready_cb_cls = ready_cb_cls;
872 cc->path = path;
873 cc->off = off;
875 "Creating %s using path %s (offset: %u)\n",
876 GCC_2s (cc),
877 GCPP_2s (path),
878 off);
879 GCPP_add_connection (path, off, cc);
880 for (unsigned int i = 0; i < off; i++)
882 first_hop = GCPP_get_peer_at_offset (path, 0);
883 cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc);
884 return cc;
885}

References CadetConnection::cid, connections, CadetConnection::ct, CadetConnection::destination, GCC_2s(), GCC_get_id(), GCP_add_connection(), GCP_request_mq(), GCPP_2s(), GCPP_add_connection(), GCPP_get_peer_at_offset(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multishortmap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_OK, GNUNET_TIME_relative_multiply(), INITIAL_CONNECTION_CREATE_RETRY_DELAY, LOG, manage_first_hop_mq(), CadetConnection::mq_man, CadetConnection::off, CadetConnection::path, CadetConnection::ready_cb, CadetConnection::ready_cb_cls, CadetConnection::retry_delay, and CadetConnection::state.

Referenced by GCC_create(), GCC_create_inbound(), and GCO_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_create_inbound()

struct CadetConnection * GCC_create_inbound ( struct CadetPeer destination,
struct CadetPeerPath path,
struct CadetTConnection ct,
const struct GNUNET_CADET_ConnectionTunnelIdentifier cid,
GCC_ReadyCallback  ready_cb,
void *  ready_cb_cls 
)

Create a connection to destination via path and notify cb whenever we are ready for more data.

This is an inbound tunnel, so we must use the existing cid

Parameters
destinationwhere to go
pathwhich path to take (may not be the full path)
ctwhich tunnel uses this connection
ready_cbfunction to call when ready to transmit
ready_cb_clsclosure for cb
Returns
handle to the connection, NULL if we already have a connection that takes precedence on path

Definition at line 902 of file gnunet-service-cadet_connection.c.

908{
909 struct CadetConnection *cc;
910 unsigned int off;
911
915 if (NULL != cc)
916 {
917 int cmp;
918
919 cmp = GNUNET_memcmp (cid, &cc->cid);
920 if (0 == cmp)
921 {
922 /* Two peers picked the SAME random connection identifier at the
923 same time for the same path? Must be malicious. Drop
924 connection (existing and inbound), even if it is the only
925 one. */
926 GNUNET_break_op (0);
929 return NULL;
930 }
931 if (0 < cmp)
932 {
933 /* drop existing */
935 "Got two connections on %s, dropping my existing %s\n",
936 GCPP_2s (path),
937 GCC_2s (cc));
940 }
941 else
942 {
943 /* keep existing */
945 "Got two connections on %s, keeping my existing %s\n",
946 GCPP_2s (path),
947 GCC_2s (cc));
948 return NULL;
949 }
950 }
951
953 path,
954 off,
955 ct,
956 cid,
958 ready_cb,
960}

References CADET_CONNECTION_CREATE_RECEIVED, CadetConnection::cid, connection_create(), CadetConnection::ct, CadetConnection::destination, GCC_2s(), GCC_destroy_without_tunnel(), GCPP_2s(), GCPP_find_peer(), GCPP_get_connection(), GCT_connection_lost(), GNUNET_assert, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcmp, LOG, CadetConnection::off, CadetConnection::path, CadetConnection::ready_cb, and CadetConnection::ready_cb_cls.

Referenced by GCT_add_inbound_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_create()

struct CadetConnection * GCC_create ( struct CadetPeer destination,
struct CadetPeerPath path,
unsigned int  off,
struct CadetTConnection ct,
GCC_ReadyCallback  ready_cb,
void *  ready_cb_cls 
)

Create a connection to destination via path and notify cb whenever we are ready for more data.

Parameters
destinationwhere to go
pathwhich path to take (may not be the full path)
offoffset of destination on path
ctwhich tunnel uses this connection
ready_cbfunction to call when ready to transmit
ready_cb_clsclosure for cb
Returns
handle to the connection

Definition at line 964 of file gnunet-service-cadet_connection.c.

970{
972
974 return connection_create (destination,
975 path,
976 off,
977 ct,
978 &cid,
980 ready_cb,
981 ready_cb_cls);
982}

References CADET_CONNECTION_NEW, connection_create(), GNUNET_CRYPTO_QUALITY_NONCE, and GNUNET_CRYPTO_random_block().

Referenced by consider_path_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_transmit()

void GCC_transmit ( struct CadetConnection cc,
struct GNUNET_MQ_Envelope env 
)

Transmit message msg via connection cc.

Must only be called (once) after the connection has signalled that it is ready via the ready_cb. Clients can also use #GCC_is_ready() to check if the connection is right now ready for transmission.

Parameters
ccconnection identification
envenvelope with message to transmit; must NOT yet have a GNUNET_MQ_notify_sent() callback attached to it

Definition at line 996 of file gnunet-service-cadet_connection.c.

997{
999 "Scheduling message for transmission on %s\n",
1000 GCC_2s (cc));
1004 cc->mqm_ready = GNUNET_NO;
1005 if (NULL != cc->task)
1006 {
1008 cc->task = NULL;
1009 }
1010 GCP_send (cc->mq_man, env);
1011}

References CADET_CONNECTION_READY, env, GCC_2s(), GCP_send(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get(), GNUNET_YES, CadetConnectionMetrics::last_use, LOG, CadetConnection::metrics, CadetConnection::mq_man, CadetConnection::mqm_ready, CadetConnection::state, and CadetConnection::task.

Referenced by send_kx(), send_kx_auth(), and try_send_normal_payload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_get_path()

struct CadetPeerPath * GCC_get_path ( struct CadetConnection cc,
unsigned int *  off 
)

Obtain the path used by this connection.

Parameters
ccconnection
[out]offset to the length of the path we use
Returns
path to cc

Definition at line 1022 of file gnunet-service-cadet_connection.c.

1023{
1024 *off = cc->off;
1025 return cc->path;
1026}

References CadetConnection::off, and CadetConnection::path.

Referenced by evaluate_connection(), handle_connection_broken(), handle_connection_create_ack(), handle_connection_destroy(), handle_tunnel_encrypted(), handle_tunnel_kx(), and handle_tunnel_kx_auth().

Here is the caller graph for this function:

◆ GCC_get_id()

const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id ( struct CadetConnection cc)

Obtain unique ID for the connection.

Parameters
ccconnection.
Returns
unique number of the connection

Definition at line 1036 of file gnunet-service-cadet_connection.c.

1037{
1038 return &cc->cid;
1039}

References CadetConnection::cid.

Referenced by connection_create(), GCC_destroy(), GCP_add_connection(), GCP_remove_connection(), handle_plaintext_channel_destroy(), handle_plaintext_channel_open(), handle_plaintext_channel_open_ack(), handle_plaintext_data(), handle_plaintext_data_ack(), send_kx(), send_kx_auth(), and try_send_normal_payload().

Here is the caller graph for this function:

◆ GCC_2s()

const char * GCC_2s ( const struct CadetConnection cc)

Get a (static) string for a connection.

Parameters
ccConnection.

Definition at line 1048 of file gnunet-service-cadet_connection.c.

1049{
1050 static char buf[128];
1051
1052 if (NULL == cc)
1053 return "Connection(NULL)";
1054
1055 if (NULL != cc->ct)
1056 {
1057 GNUNET_snprintf (buf,
1058 sizeof(buf),
1059 "Connection %s (%s)",
1061 GCT_2s (cc->ct->t));
1062 return buf;
1063 }
1064 GNUNET_snprintf (buf,
1065 sizeof(buf),
1066 "Connection %s",
1068 return buf;
1069}

References CadetConnection::cid, GNUNET_CADET_ConnectionTunnelIdentifier::connection_of_tunnel, CadetConnection::ct, GCT_2s(), GNUNET_sh2s(), GNUNET_snprintf(), and CadetTConnection::t.

Referenced by connection_create(), connection_ready_cb(), consider_path_cb(), cont_send_create(), evaluate_connection(), GCC_create_inbound(), GCC_debug(), GCC_destroy(), GCC_handle_connection_create_ack(), GCC_handle_duplicate_create(), GCC_handle_encrypted(), GCC_handle_kx(), GCC_handle_kx_auth(), GCC_transmit(), GCP_add_connection(), GCP_remove_connection(), GCPP_add_connection(), GCPP_del_connection(), GCT_add_inbound_connection(), GCT_handle_kx(), manage_first_hop_mq(), send_create_ack(), send_keepalive(), and try_send_normal_payload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCC_debug()

void GCC_debug ( struct CadetConnection cc,
enum GNUNET_ErrorType  level 
)

Log connection info.

Parameters
ccconnection
levelDebug level to use.

Definition at line 1083 of file gnunet-service-cadet_connection.c.

1084{
1085#if ! defined(GNUNET_CULL_LOGGING)
1086 int do_log;
1087
1089 "cadet-con",
1090 __FILE__,
1091 __FUNCTION__,
1092 __LINE__);
1093 if (0 == do_log)
1094 return;
1095 if (NULL == cc)
1096 {
1097 LOG2 (level, "Connection (NULL)\n");
1098 return;
1099 }
1100 LOG2 (level,
1101 "%s to %s via path %s in state %d is %s\n",
1102 GCC_2s (cc),
1103 GCP_2s (cc->destination),
1104 GCPP_2s (cc->path),
1105 cc->state,
1106 (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
1107#endif
1108}

References CadetConnection::destination, GCC_2s(), GCP_2s(), GCPP_2s(), GNUNET_ERROR_TYPE_BULK, GNUNET_get_log_call_status(), GNUNET_YES, LOG2, CadetConnection::mqm_ready, CadetConnection::path, and CadetConnection::state.

Referenced by GCT_debug().

Here is the call graph for this function:
Here is the caller graph for this function: