GNUnet  0.10.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"
33 #include "gnunet_cadet_service.h"
35 #include "cadet_protocol.h"
36 
37 
38 #define LOG(level, ...) GNUNET_log_from(level, "cadet-con", __VA_ARGS__)
39 
40 
45 #define INITIAL_CONNECTION_CREATE_RETRY_DELAY \
46  GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200)
47 
48 
57 
62 
67 
73 
78 };
79 
80 
89 
94 
99 
104 
109 
114 
119 
124 
129 
134 
139 
144 
149 
154 
159 
163  unsigned int latency_datapoints;
164 
168  unsigned int off;
169 
174 };
175 
176 
183 struct CadetConnection *
185 {
187  &cid->connection_of_tunnel);
188 }
189 
190 
199 static void
201  enum CadetConnectionState new_state,
202  int new_mqm_ready)
203 {
204  int old_ready;
205  int new_ready;
206 
207  if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
208  return; /* no change, nothing to do */
209  old_ready =
210  ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready));
211  new_ready =
212  ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
213  cc->state = new_state;
214  cc->mqm_ready = new_mqm_ready;
215  if (old_ready != new_ready)
216  cc->ready_cb(cc->ready_cb_cls, new_ready);
217 }
218 
219 
226 static void
228 {
229  LOG(GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s(cc));
230  if (NULL != cc->mq_man)
231  {
232  GCP_request_mq_cancel(cc->mq_man, NULL);
233  cc->mq_man = NULL;
234  }
235  if (NULL != cc->task)
236  {
238  cc->task = NULL;
239  }
240  if (NULL != cc->keepalive_qe)
241  {
243  cc->keepalive_qe = NULL;
244  }
245  GCPP_del_connection(cc->path, cc->off, cc);
246  for (unsigned int i = 0; i < cc->off; i++)
249  GNUNET_YES ==
251  &GCC_get_id(cc)
252  ->connection_of_tunnel,
253  cc));
254  GNUNET_free(cc);
255 }
256 
257 
266 void
268 {
269  if (NULL != cc->ct)
270  {
271  GCT_connection_lost(cc->ct);
272  cc->ct = NULL;
273  }
274  GCC_destroy(cc);
275 }
276 
277 
285 void
287 {
288  cc->ct = NULL;
289  if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
290  {
291  struct GNUNET_MQ_Envelope *env;
292  struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
293 
294  /* Need to notify next hop that we are down. */
295  env =
297  destroy_msg->cid = cc->cid;
298  GCP_request_mq_cancel(cc->mq_man, env);
299  cc->mq_man = NULL;
300  }
301  GCC_destroy(cc);
302 }
303 
304 
311 struct CadetTConnection *
313 {
314  return cc->ct;
315 }
316 
317 
324 const struct CadetConnectionMetrics *
326 {
327  return &cc->metrics;
328 }
329 
330 
337 static void
338 send_keepalive(void *cls);
339 
340 
349 static void
350 keepalive_done(void *cls,
352 {
353  struct CadetConnection *cc = cls;
354 
355  cc->keepalive_qe = NULL;
356  if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
357  cc->task =
359 }
360 
361 
368 static void
369 send_keepalive(void *cls)
370 {
371  struct CadetConnection *cc = cls;
372  struct GNUNET_MessageHeader msg;
373 
374  cc->task = NULL;
375  if (CADET_TUNNEL_KEY_OK != GCT_get_estate(cc->ct->t))
376  {
377  /* Tunnel not yet ready, wait with keepalives... */
378  cc->task =
380  return;
381  }
382  GNUNET_assert(NULL != cc->ct);
384  GNUNET_assert(NULL == cc->keepalive_qe);
386  "Sending KEEPALIVE on behalf of %s via %s\n",
387  GCC_2s(cc),
388  GCT_2s(cc->ct->t));
389  GNUNET_STATISTICS_update(stats, "# keepalives sent", 1, GNUNET_NO);
390  msg.size = htons(sizeof(msg));
392 
393  cc->keepalive_qe = GCT_send(cc->ct->t, &msg, &keepalive_done, cc);
394 }
395 
396 
403 void
405 {
406  struct CadetConnection *cc;
407 
408  cc = GCC_lookup(cid);
409  if (NULL == cc)
410  return; /* whopise, connection alredy down? */
412 }
413 
414 
423 void
425 {
426  struct CadetConnection *cc;
427 
428  cc = GCC_lookup(cid);
429  if (NULL == cc)
430  return; /* whopise, connection alredy down? */
431  cc->metrics.num_successes++;
432 }
433 
434 
443 void
445  struct GNUNET_TIME_Relative latency)
446 {
447  struct CadetConnection *cc;
448  double weight;
449  double result;
450 
451  cc = GCC_lookup(cid);
452  if (NULL == cc)
453  return; /* whopise, connection alredy down? */
454  GNUNET_STATISTICS_update(stats, "# latencies observed", 1, GNUNET_NO);
455  cc->latency_datapoints++;
456  if (cc->latency_datapoints >= 7)
457  weight = 7.0;
458  else
459  weight = cc->latency_datapoints;
460  /* Compute weighted average, giving at MOST weight 7 to the
461  existing values, or less if that value is based on fewer than 7
462  measurements. */
463  result = (weight * cc->metrics.aged_latency.rel_value_us) +
464  1.0 * latency.rel_value_us;
465  result /= (weight + 1.0);
466  cc->metrics.aged_latency.rel_value_us = (uint64_t)result;
467 }
468 
469 
477 void
479 {
481  "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
482  GCC_2s(cc),
483  cc->state,
484  (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
485  if (CADET_CONNECTION_READY == cc->state)
486  return; /* Duplicate ACK, ignore */
487  if (NULL != cc->task)
488  {
490  cc->task = NULL;
491  }
494  if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
495  (NULL == cc->task))
496  cc->task =
498 }
499 
500 
507 void
510 {
512  "Received KX message with ephermal %s on CC %s in state %d\n",
513  GNUNET_e2s(&msg->ephemeral_key),
515  cc->state);
516  if (CADET_CONNECTION_SENT == cc->state)
517  {
518  /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
519  clearly something is working, so pretend we got an ACK. */
521  "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
522  GCC_2s(cc));
524  }
525  GCT_handle_kx(cc->ct, msg);
526 }
527 
528 
535 void
538 {
540  "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
541  GNUNET_e2s(&msg->kx.ephemeral_key),
543  cc->state);
544  if (CADET_CONNECTION_SENT == cc->state)
545  {
546  /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
547  clearly something is working, so pretend we got an ACK. */
549  "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
550  GCC_2s(cc));
552  }
553  GCT_handle_kx_auth(cc->ct, msg);
554 }
555 
556 
563 void
566 {
567  if (CADET_CONNECTION_SENT == cc->state)
568  {
569  /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
570  clearly something is working, so pretend we got an ACK. */
572  "Faking connection ACK for %s due to ENCRYPTED payload\n",
573  GCC_2s(cc));
575  }
577  GCT_handle_encrypted(cc->ct, msg);
578 }
579 
580 
587 static void
588 send_create(void *cls)
589 {
590  struct CadetConnection *cc = cls;
591  struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
592  struct GNUNET_PeerIdentity *pids;
593  struct GNUNET_MQ_Envelope *env;
594 
595  cc->task = NULL;
597  env =
598  GNUNET_MQ_msg_extra(create_msg,
599  (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity),
601  //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.
602  create_msg->options = 2;
603  create_msg->cid = cc->cid;
604  pids = (struct GNUNET_PeerIdentity *)&create_msg[1];
605  pids[0] = my_full_id;
606  for (unsigned int i = 0; i <= cc->off; i++)
607  pids[i + 1] = *GCP_get_id(GCPP_get_peer_at_offset(cc->path, i));
609  "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
610  GCC_2s(cc),
611  cc->off + 2);
612  cc->env = env;
616  GCP_send(cc->mq_man, env);
617 }
618 
619 
625 static void
626 send_create_ack(void *cls)
627 {
628  struct CadetConnection *cc = cls;
630  struct GNUNET_MQ_Envelope *env;
631 
632  cc->task = NULL;
634  "Sending CONNECTION_CREATE_ACK message for %s\n",
635  GCC_2s(cc));
637  env =
639  ack_msg->cid = cc->cid;
640  cc->env = env;
645  if (CADET_CONNECTION_READY == cc->state)
646  cc->task =
648  GCP_send(cc->mq_man, env);
649 }
650 
651 
659 void
661 {
662  if (GNUNET_YES == cc->mqm_ready)
663  {
665  "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
666  GCC_2s(cc),
667  (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
668  /* Revert back to the state of having only received the 'CREATE',
669  and immediately proceed to send the CREATE_ACK. */
671  if (NULL != cc->task)
673  cc->task =
675  }
676  else
677  {
678  /* We are currently sending something else back, which
679  can only be an ACK or payload, either of which would
680  do. So actually no need to do anything. */
682  "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
683  GCC_2s(cc));
684  }
685 }
686 
687 
698 static void
699 manage_first_hop_mq(void *cls, int available)
700 {
701  struct CadetConnection *cc = cls;
702 
703  if (GNUNET_YES != available)
704  {
705  /* Connection is down, for now... */
706  LOG(GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s(cc));
709  if (NULL != cc->task)
710  {
712  cc->task = NULL;
713  }
714  return;
715  }
716 
717  update_state(cc, cc->state, GNUNET_YES);
719  "Core MQ for %s became available in state %d\n",
720  GCC_2s(cc),
721  cc->state);
722  switch (cc->state)
723  {
725  /* Transmit immediately */
727  break;
728 
730  /* Should not be possible to be called in this state. */
731  GNUNET_assert(0);
732  break;
733 
735  /* Retry a bit later... */
737  break;
738 
740  /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
742  cc->task =
744  break;
745 
747  if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
748  (NULL == cc->task))
749  {
751  "Scheduling keepalive for %s in %s\n",
752  GCC_2s(cc),
754  GNUNET_YES));
755  cc->task =
757  }
758  break;
759  }
760 }
761 
762 
777 static struct CadetConnection *
779  struct CadetPeerPath *path,
780  unsigned int off,
781  struct CadetTConnection *ct,
783  enum CadetConnectionState init_state,
785  void *ready_cb_cls)
786 {
787  struct CadetConnection *cc;
788  struct CadetPeer *first_hop;
789 
790  cc = GNUNET_new(struct CadetConnection);
791  cc->state = init_state;
792  cc->ct = ct;
793  cc->cid = *cid;
794  cc->retry_delay =
798  connections,
799  &GCC_get_id(cc)->connection_of_tunnel,
800  cc,
802  cc->ready_cb = ready_cb;
804  cc->path = path;
805  cc->off = off;
807  "Creating %s using path %s (offset: %u)\n",
808  GCC_2s(cc),
809  GCPP_2s(path),
810  off);
811  GCPP_add_connection(path, off, cc);
812  for (unsigned int i = 0; i < off; i++)
814  first_hop = GCPP_get_peer_at_offset(path, 0);
815  cc->mq_man = GCP_request_mq(first_hop, &manage_first_hop_mq, cc);
816  return cc;
817 }
818 
819 
833 struct CadetConnection *
835  struct CadetPeerPath *path,
836  struct CadetTConnection *ct,
839  void *ready_cb_cls)
840 {
841  struct CadetConnection *cc;
842  unsigned int off;
843 
844  off = GCPP_find_peer(path, destination);
845  GNUNET_assert(UINT_MAX != off);
846  cc = GCPP_get_connection(path, destination, off);
847  if (NULL != cc)
848  {
849  int cmp;
850 
851  cmp = GNUNET_memcmp(cid, &cc->cid);
852  if (0 == cmp)
853  {
854  /* Two peers picked the SAME random connection identifier at the
855  same time for the same path? Must be malicious. Drop
856  connection (existing and inbound), even if it is the only
857  one. */
858  GNUNET_break_op(0);
859  GCT_connection_lost(cc->ct);
861  return NULL;
862  }
863  if (0 < cmp)
864  {
865  /* drop existing */
867  "Got two connections on %s, dropping my existing %s\n",
868  GCPP_2s(path),
869  GCC_2s(cc));
870  GCT_connection_lost(cc->ct);
872  }
873  else
874  {
875  /* keep existing */
877  "Got two connections on %s, keeping my existing %s\n",
878  GCPP_2s(path),
879  GCC_2s(cc));
880  return NULL;
881  }
882  }
883 
884  return connection_create(destination,
885  path,
886  off,
887  ct,
888  cid,
890  ready_cb,
891  ready_cb_cls);
892 }
893 
894 
907 struct CadetConnection *
909  struct CadetPeerPath *path,
910  unsigned int off,
911  struct CadetTConnection *ct,
913  void *ready_cb_cls)
914 {
916 
918  return connection_create(destination,
919  path,
920  off,
921  ct,
922  &cid,
924  ready_cb,
925  ready_cb_cls);
926 }
927 
928 
939 void
941 {
943  "Scheduling message for transmission on %s\n",
944  GCC_2s(cc));
948  cc->mqm_ready = GNUNET_NO;
949  if (NULL != cc->task)
950  {
952  cc->task = NULL;
953  }
954  GCP_send(cc->mq_man, env);
955 }
956 
957 
965 struct CadetPeerPath *
966 GCC_get_path(struct CadetConnection *cc, unsigned int *off)
967 {
968  *off = cc->off;
969  return cc->path;
970 }
971 
972 
981 {
982  return &cc->cid;
983 }
984 
985 
991 const char *
992 GCC_2s(const struct CadetConnection *cc)
993 {
994  static char buf[128];
995 
996  if (NULL == cc)
997  return "Connection(NULL)";
998 
999  if (NULL != cc->ct)
1000  {
1001  GNUNET_snprintf(buf,
1002  sizeof(buf),
1003  "Connection %s (%s)",
1005  GCT_2s(cc->ct->t));
1006  return buf;
1007  }
1008  GNUNET_snprintf(buf,
1009  sizeof(buf),
1010  "Connection %s",
1012  return buf;
1013 }
1014 
1015 
1016 #define LOG2(level, ...) \
1017  GNUNET_log_from_nocheck(level, "cadet-con", __VA_ARGS__)
1018 
1019 
1026 void
1028 {
1029 #if !defined(GNUNET_CULL_LOGGING)
1030  int do_log;
1031 
1033  "cadet-con",
1034  __FILE__,
1035  __FUNCTION__,
1036  __LINE__);
1037  if (0 == do_log)
1038  return;
1039  if (NULL == cc)
1040  {
1041  LOG2(level, "Connection (NULL)\n");
1042  return;
1043  }
1044  LOG2(level,
1045  "%s to %s via path %s in state %d is %s\n",
1046  GCC_2s(cc),
1047  GCP_2s(cc->destination),
1048  GCPP_2s(cc->path),
1049  cc->state,
1050  (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
1051 #endif
1052 }
1053 
1054 /* 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.
static struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#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.
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.
uint64_t rel_value_us
The actual value.
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.
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 ...
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
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.
struct CadetTunnelQueueEntry * GCT_send(struct CadetTunnel *t, const struct GNUNET_MessageHeader *message, GCT_SendContinuation cont, void *cont_cls)
Sends an already built message on a tunnel, encrypting it and choosing the best connection if not pro...
Message for ack&#39;ing a connection.
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.
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
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.
#define GNUNET_NO
Definition: gnunet_common.h:78
static void send_create(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the first hop.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
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.
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:1237
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.
Message for a Key eXchange for a tunnel, with authentication.
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:686
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:440
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.
void GCC_handle_duplicate_create(struct CadetConnection *cc)
We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have...
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 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.
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 destuction 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:131
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?
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.
#define GNUNET_YES
Definition: gnunet_common.h:77
Uninitialized status, we have not yet even gotten the message queue.
uint32_t options
Connection options in network byte order.
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:1214
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_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
Message for cadet connection creation.
#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:956