GNUnet  0.11.x
gnunet-service-cadet_connection.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001-2017 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
28 #include "platform.h"
29 #include "gnunet_signatures.h"
34 #include "gnunet_cadet_service.h"
36 #include "cadet_protocol.h"
37 
38 
39 #define LOG(level, ...) GNUNET_log_from (level, "cadet-con", __VA_ARGS__)
40 
41 
46 #define INITIAL_CONNECTION_CREATE_RETRY_DELAY \
47  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
48 
49 
54 {
59 
64 
69 
75 
80 };
81 
86 {
91 
96 
101 
106 
111 
116 
121 
126 
131 
136 
141 
146 
151 
156 
161 
165  unsigned int latency_datapoints;
166 
170  unsigned int off;
171 
176 };
177 
178 
185 struct CadetConnection *
187 {
189  &cid->connection_of_tunnel);
190 }
191 
192 
201 static void
203  enum CadetConnectionState new_state,
204  int new_mqm_ready)
205 {
206  int old_ready;
207  int new_ready;
208 
210  "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",
211  GCT_2s (cc->ct->t),
212  cc->state,
213  new_state,
214  cc->mqm_ready,
215  new_mqm_ready);
216 
217  if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
218  return; /* no change, nothing to do */
219  old_ready =
220  ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready));
221  new_ready =
222  ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
223  cc->state = new_state;
224  cc->mqm_ready = new_mqm_ready;
225 
227  "Updating connection state for %s having old_ready %d and new_rady %d\n",
228  GCT_2s (cc->ct->t),
229  old_ready,
230  new_ready);
231 
232  if (old_ready != new_ready)
233  cc->ready_cb (cc->ready_cb_cls, new_ready);
234 }
235 
236 
243 static void
245 {
246  LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc));
247  if (NULL != cc->mq_man)
248  {
249  GCP_request_mq_cancel (cc->mq_man, NULL);
250  cc->mq_man = NULL;
251  }
252  if (NULL != cc->task)
253  {
255  cc->task = NULL;
256  }
257  if (NULL != cc->keepalive_qe)
258  {
260  cc->keepalive_qe = NULL;
261  }
262  GCPP_del_connection (cc->path, cc->off, cc);
263  for (unsigned int i = 0; i < cc->off; i++)
265  GNUNET_assert (
266  GNUNET_YES ==
268  &GCC_get_id (cc)
269  ->connection_of_tunnel,
270  cc));
271  GNUNET_free (cc);
272 }
273 
274 
283 void
285 {
286  if (NULL != cc->ct)
287  {
288  GCT_connection_lost (cc->ct);
289  cc->ct = NULL;
290  }
291  GCC_destroy (cc);
292 }
293 
294 
302 void
304 {
305  cc->ct = NULL;
306  if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
307  {
308  struct GNUNET_MQ_Envelope *env;
309  struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
310 
311  /* Need to notify next hop that we are down. */
312  env =
314  destroy_msg->cid = cc->cid;
315  GCP_request_mq_cancel (cc->mq_man, env);
316  cc->mq_man = NULL;
317  }
318  GCC_destroy (cc);
319 }
320 
321 
328 struct CadetTConnection *
330 {
331  return cc->ct;
332 }
333 
334 
341 const struct CadetConnectionMetrics *
343 {
344  return &cc->metrics;
345 }
346 
347 
354 static void
355 send_keepalive (void *cls);
356 
357 
366 static void
367 keepalive_done (void *cls,
369 {
370  struct CadetConnection *cc = cls;
371 
372  cc->keepalive_qe = NULL;
373  if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
374  cc->task =
376 }
377 
378 
385 static void
386 send_keepalive (void *cls)
387 {
388  struct CadetConnection *cc = cls;
389  struct GNUNET_MessageHeader msg;
390 
391  cc->task = NULL;
392  if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t))
393  {
394  /* Tunnel not yet ready, wait with keepalives... */
395  cc->task =
397  return;
398  }
399  GNUNET_assert (NULL != cc->ct);
401  GNUNET_assert (NULL == cc->keepalive_qe);
403  "Sending KEEPALIVE on behalf of %s via %s\n",
404  GCC_2s (cc),
405  GCT_2s (cc->ct->t));
406  GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
407  msg.size = htons (sizeof(msg));
409 
410  cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc, NULL);
411 }
412 
413 
420 void
422 {
423  struct CadetConnection *cc;
424 
425  cc = GCC_lookup (cid);
426  if (NULL == cc)
427  return; /* whopise, connection alredy down? */
429 }
430 
431 
440 void
442 {
443  struct CadetConnection *cc;
444 
445  cc = GCC_lookup (cid);
446  if (NULL == cc)
447  return; /* whopise, connection alredy down? */
448  cc->metrics.num_successes++;
449 }
450 
451 
460 void
462  struct GNUNET_TIME_Relative latency)
463 {
464  struct CadetConnection *cc;
465  double weight;
466  double result;
467 
468  cc = GCC_lookup (cid);
469  if (NULL == cc)
470  return; /* whopise, connection alredy down? */
471  GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO);
472  cc->latency_datapoints++;
473  if (cc->latency_datapoints >= 7)
474  weight = 7.0;
475  else
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
479  measurements. */
480  result = (weight * cc->metrics.aged_latency.rel_value_us)
481  + 1.0 * latency.rel_value_us;
482  result /= (weight + 1.0);
483  cc->metrics.aged_latency.rel_value_us = (uint64_t) result;
484 }
485 
486 
494 void
496 {
498  "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
499  GCC_2s (cc),
500  cc->state,
501  (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
502  if (CADET_CONNECTION_READY == cc->state)
503  return; /* Duplicate ACK, ignore */
504  if (NULL != cc->task)
505  {
507  cc->task = NULL;
508  }
511  if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
512  (NULL == cc->task))
513  cc->task =
515 }
516 
517 
524 void
527 {
529  "Received KX message with ephermal %s on CC %s in state %d\n",
530  GNUNET_e2s (&msg->ephemeral_key),
532  cc->state);
533  if (CADET_CONNECTION_SENT == cc->state)
534  {
535  /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
536  clearly something is working, so pretend we got an ACK. */
538  "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
539  GCC_2s (cc));
541  }
542  GCT_handle_kx (cc->ct, msg);
543 }
544 
545 
552 void
555 {
557  "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
558  GNUNET_e2s (&msg->kx.ephemeral_key),
560  cc->state);
561  if (CADET_CONNECTION_SENT == cc->state)
562  {
563  /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
564  clearly something is working, so pretend we got an ACK. */
566  "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
567  GCC_2s (cc));
569  }
570  GCT_handle_kx_auth (cc->ct, msg);
571 }
572 
573 
580 void
583 {
584  if (CADET_CONNECTION_SENT == cc->state)
585  {
586  /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
587  clearly something is working, so pretend we got an ACK. */
589  "Faking connection ACK for %s due to ENCRYPTED payload\n",
590  GCC_2s (cc));
592  }
594  GCT_handle_encrypted (cc->ct, msg);
595 }
596 
597 
603 void
605 {
606 
607  struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
609  .purpose.size = htonl (sizeof(cp)),
610  .monotonic_time = msg->monotime};
611 
613  &msg->monotime_sig);
614 
615 }
616 
617 
624 static void
625 send_create (void *cls)
626 {
627  struct CadetConnection *cc = cls;
628  struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
629  struct GNUNET_PeerIdentity *pids;
630  struct GNUNET_MQ_Envelope *env;
631  struct CadetTunnel *t;
632 
633  cc->task = NULL;
635  env =
636  GNUNET_MQ_msg_extra (create_msg,
637  (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity),
639  // 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.
640  create_msg->options = 2;
641  create_msg->cid = cc->cid;
642 
643  // check for tunnel state and set signed monotime (xrs,t3ss)
645  if ((NULL != t) && (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
647  {
648  create_msg->has_monotime = GNUNET_YES;
649  create_msg->monotime = GNUNET_TIME_absolute_hton (
651  set_monotime_sig (create_msg);
652  }
653 
654  pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
655  pids[0] = my_full_id;
656  for (unsigned int i = 0; i <= cc->off; i++)
657  pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i));
659  "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
660  GCC_2s (cc),
661  cc->off + 2);
662  cc->env = env;
666  GCP_send (cc->mq_man, env);
667 }
668 
669 
675 static void
676 send_create_ack (void *cls)
677 {
678  struct CadetConnection *cc = cls;
680  struct GNUNET_MQ_Envelope *env;
681 
682  cc->task = NULL;
684  "Sending CONNECTION_CREATE_ACK message for %s\n",
685  GCC_2s (cc));
687  env =
689  ack_msg->cid = cc->cid;
690  cc->env = env;
695  if (CADET_CONNECTION_READY == cc->state)
696  cc->task =
698  GCP_send (cc->mq_man, env);
699 }
700 
701 
709 void
711 {
712  if (GNUNET_YES == cc->mqm_ready)
713  {
715  "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
716  GCC_2s (cc),
717  (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
718  /* Revert back to the state of having only received the 'CREATE',
719  and immediately proceed to send the CREATE_ACK. */
721  if (NULL != cc->task)
723  cc->task =
725  }
726  else
727  {
728  /* We are currently sending something else back, which
729  can only be an ACK or payload, either of which would
730  do. So actually no need to do anything. */
732  "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
733  GCC_2s (cc));
734  }
735 }
736 
737 
748 static void
749 manage_first_hop_mq (void *cls, int available)
750 {
751  struct CadetConnection *cc = cls;
752 
753  if (GNUNET_YES != available)
754  {
755  /* Connection is down, for now... */
756  LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc));
759  if (NULL != cc->task)
760  {
762  cc->task = NULL;
763  }
764  return;
765  }
766 
767  update_state (cc, cc->state, GNUNET_YES);
769  "Core MQ for %s became available in state %d\n",
770  GCC_2s (cc),
771  cc->state);
772  switch (cc->state)
773  {
775  /* Transmit immediately */
777  break;
778 
780  /* Should not be possible to be called in this state. */
781  GNUNET_assert (0);
782  break;
783 
785  /* Retry a bit later... */
787  break;
788 
790  /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
792  cc->task =
794  break;
795 
797  if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
798  (NULL == cc->task))
799  {
801  "Scheduling keepalive for %s in %s\n",
802  GCC_2s (cc),
804  GNUNET_YES));
805  cc->task =
807  }
808  break;
809  }
810 }
811 
812 
827 static struct CadetConnection *
829  struct CadetPeerPath *path,
830  unsigned int off,
831  struct CadetTConnection *ct,
833  enum CadetConnectionState init_state,
835  void *ready_cb_cls)
836 {
837  struct CadetConnection *cc;
838  struct CadetPeer *first_hop;
839 
840  cc = GNUNET_new (struct CadetConnection);
841  cc->state = init_state;
842  cc->ct = ct;
843  cc->destination = destination; /* xrs,t3ss,lurchi*/
844  cc->cid = *cid;
845  cc->retry_delay =
849  connections,
850  &GCC_get_id (cc)->connection_of_tunnel,
851  cc,
853  cc->ready_cb = ready_cb;
855  cc->path = path;
856  cc->off = off;
858  "Creating %s using path %s (offset: %u)\n",
859  GCC_2s (cc),
860  GCPP_2s (path),
861  off);
862  GCPP_add_connection (path, off, cc);
863  for (unsigned int i = 0; i < off; i++)
865  first_hop = GCPP_get_peer_at_offset (path, 0);
866  cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc);
867  return cc;
868 }
869 
870 
884 struct CadetConnection *
886  struct CadetPeerPath *path,
887  struct CadetTConnection *ct,
890  void *ready_cb_cls)
891 {
892  struct CadetConnection *cc;
893  unsigned int off;
894 
895  off = GCPP_find_peer (path, destination);
896  GNUNET_assert (UINT_MAX != off);
897  cc = GCPP_get_connection (path, destination, off);
898  if (NULL != cc)
899  {
900  int cmp;
901 
902  cmp = GNUNET_memcmp (cid, &cc->cid);
903  if (0 == cmp)
904  {
905  /* Two peers picked the SAME random connection identifier at the
906  same time for the same path? Must be malicious. Drop
907  connection (existing and inbound), even if it is the only
908  one. */
909  GNUNET_break_op (0);
910  GCT_connection_lost (cc->ct);
912  return NULL;
913  }
914  if (0 < cmp)
915  {
916  /* drop existing */
918  "Got two connections on %s, dropping my existing %s\n",
919  GCPP_2s (path),
920  GCC_2s (cc));
921  GCT_connection_lost (cc->ct);
923  }
924  else
925  {
926  /* keep existing */
928  "Got two connections on %s, keeping my existing %s\n",
929  GCPP_2s (path),
930  GCC_2s (cc));
931  return NULL;
932  }
933  }
934 
935  return connection_create (destination,
936  path,
937  off,
938  ct,
939  cid,
941  ready_cb,
942  ready_cb_cls);
943 }
944 
945 
958 struct CadetConnection *
960  struct CadetPeerPath *path,
961  unsigned int off,
962  struct CadetTConnection *ct,
964  void *ready_cb_cls)
965 {
967 
969  return connection_create (destination,
970  path,
971  off,
972  ct,
973  &cid,
975  ready_cb,
976  ready_cb_cls);
977 }
978 
979 
990 void
992 {
994  "Scheduling message for transmission on %s\n",
995  GCC_2s (cc));
999  cc->mqm_ready = GNUNET_NO;
1000  if (NULL != cc->task)
1001  {
1003  cc->task = NULL;
1004  }
1005  GCP_send (cc->mq_man, env);
1006 }
1007 
1008 
1016 struct CadetPeerPath *
1017 GCC_get_path (struct CadetConnection *cc, unsigned int *off)
1018 {
1019  *off = cc->off;
1020  return cc->path;
1021 }
1022 
1023 
1032 {
1033  return &cc->cid;
1034 }
1035 
1036 
1042 const char *
1043 GCC_2s (const struct CadetConnection *cc)
1044 {
1045  static char buf[128];
1046 
1047  if (NULL == cc)
1048  return "Connection(NULL)";
1049 
1050  if (NULL != cc->ct)
1051  {
1052  GNUNET_snprintf (buf,
1053  sizeof(buf),
1054  "Connection %s (%s)",
1056  GCT_2s (cc->ct->t));
1057  return buf;
1058  }
1059  GNUNET_snprintf (buf,
1060  sizeof(buf),
1061  "Connection %s",
1063  return buf;
1064 }
1065 
1066 
1067 #define LOG2(level, ...) \
1068  GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)
1069 
1070 
1077 void
1079 {
1080 #if ! defined(GNUNET_CULL_LOGGING)
1081  int do_log;
1082 
1084  "cadet-con",
1085  __FILE__,
1086  __FUNCTION__,
1087  __LINE__);
1088  if (0 == do_log)
1089  return;
1090  if (NULL == cc)
1091  {
1092  LOG2 (level, "Connection (NULL)\n");
1093  return;
1094  }
1095  LOG2 (level,
1096  "%s to %s via path %s in state %d is %s\n",
1097  GCC_2s (cc),
1098  GCP_2s (cc->destination),
1099  GCPP_2s (cc->path),
1100  cc->state,
1101  (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
1102 #endif
1103 }
1104 
1105 
1106 /* end of gnunet-service-cadet_connection.c */
int mqm_ready
Are we ready to transmit via mq_man right now?
Axolotl-encrypted tunnel message with application payload.
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...
#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 GCT_connection_lost(struct CadetTConnection *ct)
We lost a connection, remove it from our list and clean up the connection object itself.
int GCT_alice_or_betty(const struct GNUNET_PeerIdentity *other)
Am I Alice or Betty (some call her Bob), or talking to myself?
struct GNUNET_TIME_Absolute create_ack_at
Earliest time for re-trying CREATE_ACK.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const struct CadetConnectionMetrics * GCC_get_metrics(struct CadetConnection *cc)
Obtain performance metrics from cc.
Peer description.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_SCHEDULER_Task * task
Task for connection maintenance.
GNUnet CADET service with encryption.
Low-level connection to a destination.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static void send_keepalive(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the tunnel to prevent it from timing out...
Message to destroy a connection.
enum CadetTunnelEState GCT_get_estate(struct CadetTunnel *t)
Get the encryption state of a tunnel.
struct CadetTunnel * GCP_get_tunnel(struct CadetPeer *cp, int create)
Get the tunnel towards a peer.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
A connection is a live end-to-end messaging mechanism where the peers are identified by a path and kn...
static void send_create_ack(void *cls)
Send a CREATE_ACK message towards the origin.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
unsigned long long num_successes
Number of packets that were sent via this connection did actually receive an ACK? (Note: ACKs may be ...
void GCT_handle_encrypted(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Handle encrypted message.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
CadetConnectionState
All the states a connection can be in.
Data structure used to track whom we have to notify about changes to our message queue.
struct GNUNET_TIME_Absolute last_use
When was this connection last used? (by us sending or receiving a PAYLOAD message on it) ...
struct GNUNET_CADET_TunnelKeyExchangeMessage kx
Message header with key material.
struct GNUNET_PeerIdentity my_full_id
Local peer own ID.
static void update_state(struct CadetConnection *cc, enum CadetConnectionState new_state, int new_mqm_ready)
Update the connection state.
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:246
void GCC_destroy_without_core(struct CadetConnection *cc)
Destroy a connection, called when the CORE layer is already done (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Message for ack&#39;ing a connection.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose is GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR.
void GCT_send_cancel(struct CadetTunnelQueueEntry *tq)
Cancel a previously sent message while it&#39;s in the queue.
const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id(struct CadetConnection *cc)
Obtain unique ID for the connection.
struct CadetPeerPath * path
Path we are using to our destination.
We are an inbound connection, and received a CREATE.
void set_monotime_sig(struct GNUNET_CADET_ConnectionCreateMessage *msg)
Set the signature for a monotime value on a GNUNET_CADET_ConnectionCreateMessage. ...
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
void GCC_handle_kx(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
Handle KX message.
struct CadetPeer * destination
To which peer does this connection go?
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.
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...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
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 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.
static void send_create(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the first hop.
static void GCC_destroy(struct CadetConnection *cc)
Destroy a connection, part of the internal implementation.
Information we track per tunnel.
GNUNET_ErrorType
Types of errors.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GCP_send(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *env)
Send the message in env to cp.
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...
struct GNUNET_TIME_Absolute create_at
Earliest time for re-trying CREATE.
static struct GNUNET_SCHEDULER_Task * t
Main task.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
GCC_ReadyCallback ready_cb
Function to call once we are ready to transmit.
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...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_CONTAINER_MultiShortmap * connections
Map from struct GNUNET_CADET_ConnectionTunnelIdentifier hash codes to struct CadetConnection objects...
void GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level)
Log connection info.
#define LOG2(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
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.
struct CadetTunnel * t
Tunnel this connection belongs to.
unsigned int latency_datapoints
How many latency observations did we make for this connection?
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
#define LOG(level,...)
Performance metrics for a connection.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
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:1269
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
void GCP_remove_connection(struct CadetPeer *cp, struct CadetConnection *cc)
Remove a connection that went via this cp.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
Message for a Key eXchange for a tunnel, with authentication.
Purpose for the signature of a monotime.
Connection create message in queue, awaiting transmission by CORE.
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.
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:702
struct GNUNET_TIME_Relative retry_delay
How long do we wait before we try again with a CREATE message?
Randomness for IVs etc.
Connection confirmed, ready to carry traffic.
static char buf[2048]
struct GNUNET_MQ_Envelope * env
Pending message, NULL if we are ready to transmit.
static void keepalive_done(void *cls, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Keepalive was transmitted.
int 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.
struct GNUNET_TIME_Relative aged_latency
Our current best estimate of the latency, based on a weighted average of at least latency_datapoints ...
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
Request the creation of a connection.
static int result
Global testing status.
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:442
struct CadetTConnection * ct
Which tunnel is using this connection?
void GCC_destroy_without_tunnel(struct CadetConnection *cc)
Destroy a connection, called if the tunnel association with the connection was already broken...
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
Send origin an ACK that the connection is complete.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE
Announce connection is still alive (direction sensitive).
struct CadetTConnection * GCC_get_ct(struct CadetConnection *cc)
Return the tunnel associated with this connection.
void GCT_handle_kx(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
Handle KX message that lacks authentication (and which will thus only be considered authenticated aft...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void GCP_add_connection(struct CadetPeer *cp, struct CadetConnection *cc)
Add a connection to this cp.
struct CadetConnection * cc
Connection handle.
int has_monotime
This flag indicates the peer sending the connection create meassage likes to trigger a KX handshake...
void GCC_handle_duplicate_create(struct CadetConnection *cc)
We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have...
Struct containing all information regarding a tunnel to a peer.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
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.
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
struct GCP_MessageQueueManager * mq_man
Handle for calling GCP_request_mq_cancel() once we are finished.
Struct used to save messages in a non-ready tunnel to send once connected.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Connection create message sent, waiting for ACK.
Handshake completed: session key available.
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:807
struct CadetPeerPath * GCC_get_path(struct CadetConnection *cc, unsigned int *off)
Obtain the path used by this connection.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
P2P messages used by CADET.
unsigned int GCPP_find_peer(struct CadetPeerPath *path, struct CadetPeer *cp)
Find peer&#39;s offset on path.
void(* GCC_ReadyCallback)(void *cls, int is_ready)
Function called to notify tunnel about change in our readyness.
struct CadetTunnelQueueEntry * keepalive_qe
Queue entry for keepalive messages.
struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Own private key.
void GCT_handle_kx_auth(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
Handle KX_AUTH message.
struct CadetConnection * GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Lookup a connection by its identifier.
void GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
Transmit message msg via connection cc.
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.
Entry in list of connections used by tunnel, with metadata.
The identity of the host (wraps the signing key of the peer).
void * ready_cb_cls
Closure for ready_cb.
enum CadetConnectionState state
State of the connection.
Hash uniquely identifying a connection below a tunnel.
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.
void GCC_handle_encrypted(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Handle encrypted message.
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&#39;s offset off...
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
Request the destruction of a connection.
void GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *last_env)
Stops message queue change notifications.
Message for a Key eXchange for a tunnel.
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...
Entry in list of pending tasks.
Definition: scheduler.c:134
unsigned long long num_acked_transmissions
How many packets that ought to generate an ACK did we send via this connection?
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
struct GNUNET_TIME_Relative keepalive_period
How frequently do we send KEEPALIVE messages on idle connections?
Uninitialized status, we need to send KX.
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 cti...
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...
Header for all communications.
void GCC_handle_kx_auth(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
Handle KX_AUTH message.
Time for absolute times used by GNUnet, in microseconds.
Uninitialized status, we have not yet even gotten the message queue.
uint32_t options
Connection options in network byte order.
struct GNUNET_CRYPTO_EddsaSignature monotime_sig
We sign the monotime.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key
Sender&#39;s ephemeral public ECC key encoded in a format suitable for network transmission, as created using &#39;gcry_sexp_sprint&#39;.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
struct GNUNET_TIME_Absolute age
When was this connection first established? (by us sending or receiving the CREATE_ACK for the first ...
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:1246
Information regarding a possible path to reach a peer.
struct GNUNET_ShortHashCode connection_of_tunnel
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
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&#39;s offset off.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
Message for cadet connection creation.
#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR
Signature by a peer that like to create a connection.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
Time for relative time used by GNUnet, in microseconds.
struct GCP_MessageQueueManager * GCP_request_mq(struct CadetPeer *cp, GCP_MessageQueueNotificationCallback cb, void *cb_cls)
Start message queue change notifications.
unsigned int off
Offset of our destination in path.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972