GNUnet  0.10.x
Data Structures | Typedefs | Functions
gnunet-service-cadet_connection.h File Reference

A connection is a live end-to-end messaging mechanism where the peers are identified by a path and know how to forward along the route using a connection identifier for routing the data. More...

#include "gnunet_util_lib.h"
#include "gnunet-service-cadet.h"
#include "gnunet-service-cadet_peer.h"
#include "cadet_protocol.h"
Include dependency graph for gnunet-service-cadet_connection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CadetConnectionMetrics
 Performance metrics for a connection. More...
 

Typedefs

typedef void(* GCC_ReadyCallback) (void *cls, int is_ready)
 Function called to notify tunnel about change in our readyness. More...
 

Functions

void GCC_destroy_without_core (struct CadetConnection *cc)
 Destroy a connection, called when the CORE layer is already done (i.e. More...
 
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. More...
 
struct CadetConnectionGCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
 Lookup a connection by its identifier. More...
 
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. More...
 
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. More...
 
void GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
 Transmit message msg via connection cc. More...
 
void GCC_handle_connection_create_ack (struct CadetConnection *cc)
 A CREATE_ACK was received for this connection, process it. More...
 
void GCC_handle_duplicate_create (struct CadetConnection *cc)
 We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have. More...
 
void GCC_handle_kx (struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
 Handle KX message. More...
 
void GCC_handle_kx_auth (struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
 Handle KX_AUTH message. More...
 
const struct CadetConnectionMetricsGCC_get_metrics (struct CadetConnection *cc)
 Obtain performance metrics from cc. More...
 
void GCC_handle_encrypted (struct CadetConnection *cc, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
 Handle encrypted message. More...
 
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. More...
 
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. More...
 
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. More...
 
struct CadetTConnectionGCC_get_ct (struct CadetConnection *cc)
 Return the tunnel associated with this connection. More...
 
struct CadetPeerPathGCC_get_path (struct CadetConnection *cc, unsigned int *off)
 Obtain the path used by this connection. More...
 
const struct GNUNET_CADET_ConnectionTunnelIdentifierGCC_get_id (struct CadetConnection *cc)
 Obtain unique ID for the connection. More...
 
const char * GCC_2s (const struct CadetConnection *cc)
 Get a (static) string for a connection. More...
 
void GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level)
 Log connection info. More...
 

Detailed Description

A connection is a live end-to-end messaging mechanism where the peers are identified by a path and know how to forward along the route using a connection identifier for routing the data.

Author
Bartlomiej Polot
Christian Grothoff

Definition in file gnunet-service-cadet_connection.h.

Typedef Documentation

◆ GCC_ReadyCallback

typedef void(* GCC_ReadyCallback) (void *cls, int is_ready)

Function called to notify tunnel about change in our readyness.

Parameters
clsclosure
is_readyGNUNET_YES if the connection is now ready for transmission, GNUNET_NO if the connection is no longer ready for transmission

Definition at line 47 of file gnunet-service-cadet_connection.h.

Function Documentation

◆ 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 267 of file gnunet-service-cadet_connection.c.

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

Referenced by handle_connection_broken(), and handle_connection_destroy().

268 {
269  if (NULL != cc->ct)
270  {
271  GCT_connection_lost(cc->ct);
272  cc->ct = NULL;
273  }
274  GCC_destroy(cc);
275 }
void GCT_connection_lost(struct CadetTConnection *ct)
We lost a connection, remove it from our list and clean up the connection object itself.
static void GCC_destroy(struct CadetConnection *cc)
Destroy a connection, part of the internal implementation.
struct CadetTConnection * ct
Which tunnel is using this connection?
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 286 of file gnunet-service-cadet_connection.c.

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

Referenced by destroy_t_connection(), and GCC_create_inbound().

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 }
Message to destroy a connection.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static void GCC_destroy(struct CadetConnection *cc)
Destroy a connection, part of the internal implementation.
Connection create message in queue, awaiting transmission by CORE.
struct CadetTConnection * ct
Which tunnel is using this connection?
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct GCP_MessageQueueManager * mq_man
Handle for calling GCP_request_mq_cancel() once we are finished.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
enum CadetConnectionState state
State of the connection.
#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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 184 of file gnunet-service-cadet_connection.c.

References 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().

185 {
187  &cid->connection_of_tunnel);
188 }
struct GNUNET_CONTAINER_MultiShortmap * connections
Map from struct GNUNET_CADET_ConnectionTunnelIdentifier hash codes to struct CadetConnection objects...
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.
struct GNUNET_ShortHashCode connection_of_tunnel
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
Parameters
destinationwhere to go
pathwhich path to take (may not be the full path)
offoffset of destination on path
cttunnel that uses the connection
ready_cbfunction to call when ready to transmit
ready_cb_clsclosure for cb
Returns
handle to the connection

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

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

Referenced by consider_path_cb().

914 {
916 
918  return connection_create(destination,
919  path,
920  off,
921  ct,
922  &cid,
924  ready_cb,
925  ready_cb_cls);
926 }
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...
Randomness for IVs etc.
Hash uniquely identifying a connection below a tunnel.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
Uninitialized status, we have not yet even gotten the message queue.
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 834 of file gnunet-service-cadet_connection.c.

References CADET_CONNECTION_CREATE_RECEIVED, CadetConnection::cid, connection_create(), CadetConnection::ct, 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, and CadetConnection::off.

Referenced by GCT_add_inbound_connection().

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 }
void GCT_connection_lost(struct CadetTConnection *ct)
We lost a connection, remove it from our list and clean up the connection object itself.
Low-level connection to a destination.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
We are an inbound connection, and received a CREATE.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
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...
GCC_ReadyCallback ready_cb
Function to call once we are ready to transmit.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
#define LOG(level,...)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int GCPP_find_peer(struct CadetPeerPath *path, struct CadetPeer *cp)
Find peer&#39;s offset on path.
void * ready_cb_cls
Closure for ready_cb.
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...
unsigned int off
Offset of our destination in path.
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; the #GNUNET_MQ_notify_send() must not have yet been used for the envelope. Also, the message better match the connection identifier of this connection...

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 940 of file gnunet-service-cadet_connection.c.

References CADET_CONNECTION_READY, 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().

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 }
int mqm_ready
Are we ready to transmit via mq_man right now?
struct GNUNET_SCHEDULER_Task * task
Task for connection maintenance.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct GNUNET_TIME_Absolute last_use
When was this connection last used? (by us sending or receiving a PAYLOAD message on it) ...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GCP_send(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *env)
Send the message in env to cp.
#define LOG(level,...)
Connection confirmed, ready to carry traffic.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
struct GCP_MessageQueueManager * mq_man
Handle for calling GCP_request_mq_cancel() once we are finished.
enum CadetConnectionState state
State of the connection.
#define GNUNET_YES
Definition: gnunet_common.h:77
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 CREATE_ACK was received for this connection, process it.

Parameters
ccthe connection that got the ACK.

A CREATE_ACK was received for this connection, process it.

Process it.

Parameters
ccthe connection that got the ACK.

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

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, 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().

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 }
int mqm_ready
Are we ready to transmit via mq_man right now?
struct GNUNET_SCHEDULER_Task * task
Task for connection maintenance.
static void send_keepalive(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the tunnel to prevent it from timing out...
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
static void update_state(struct CadetConnection *cc, enum CadetConnectionState new_state, int new_mqm_ready)
Update the connection state.
#define LOG(level,...)
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
Connection confirmed, ready to carry traffic.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
struct CadetTunnelQueueEntry * keepalive_qe
Queue entry for keepalive messages.
enum CadetConnectionState state
State of the connection.
struct GNUNET_TIME_Relative keepalive_period
How frequently do we send KEEPALIVE messages on idle connections?
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Absolute age
When was this connection first established? (by us sending or receiving the CREATE_ACK for the first ...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 660 of file gnunet-service-cadet_connection.c.

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().

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 }
int mqm_ready
Are we ready to transmit via mq_man right now?
struct GNUNET_TIME_Absolute create_ack_at
Earliest time for re-trying CREATE_ACK.
struct GNUNET_SCHEDULER_Task * task
Task for connection maintenance.
static void send_create_ack(void *cls)
Send a CREATE_ACK message towards the origin.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
static void update_state(struct CadetConnection *cc, enum CadetConnectionState new_state, int new_mqm_ready)
Update the connection state.
We are an inbound connection, and received a CREATE.
#define LOG(level,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
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
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 508 of file gnunet-service-cadet_connection.c.

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

Referenced by handle_tunnel_kx().

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 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
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 LOG(level,...)
struct CadetTConnection * ct
Which tunnel is using 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...
Connection create message sent, waiting for ACK.
enum CadetConnectionState state
State of the connection.
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_ShortHashCode connection_of_tunnel
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 536 of file gnunet-service-cadet_connection.c.

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

Referenced by handle_tunnel_kx_auth().

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 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct GNUNET_CADET_TunnelKeyExchangeMessage kx
Message header with key material.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
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 LOG(level,...)
struct CadetTConnection * ct
Which tunnel is using this connection?
Connection create message sent, waiting for ACK.
void GCT_handle_kx_auth(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
Handle KX_AUTH message.
enum CadetConnectionState state
State of the connection.
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_ShortHashCode connection_of_tunnel
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 325 of file gnunet-service-cadet_connection.c.

References CadetConnection::metrics, and send_keepalive().

Referenced by data_sent_cb(), and evaluate_connection().

326 {
327  return &cc->metrics;
328 }
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
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 564 of file gnunet-service-cadet_connection.c.

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, and CadetConnection::state.

Referenced by handle_tunnel_encrypted().

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 }
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.
struct GNUNET_TIME_Absolute last_use
When was this connection last used? (by us sending or receiving a PAYLOAD message on it) ...
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 LOG(level,...)
struct CadetTConnection * ct
Which tunnel is using this connection?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
Connection create message sent, waiting for ACK.
enum CadetConnectionState state
State of the connection.
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 404 of file gnunet-service-cadet_connection.c.

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

Referenced by data_sent_cb().

405 {
406  struct CadetConnection *cc;
407 
408  cc = GCC_lookup(cid);
409  if (NULL == cc)
410  return; /* whopise, connection alredy down? */
412 }
Low-level connection to a destination.
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
struct CadetConnection * GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Lookup a connection by its identifier.
unsigned long long num_acked_transmissions
How many packets that ought to generate an ACK did we send via this connection?
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 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).
cticonnection 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 424 of file gnunet-service-cadet_connection.c.

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

Referenced by handle_matching_ack().

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 }
Low-level connection to a destination.
unsigned long long num_successes
Number of packets that were sent via this connection did actually receive an ACK? (Note: ACKs may be ...
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
struct CadetConnection * GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Lookup a connection by its identifier.
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 cid,
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

(The same connection was taken in both directions.)

Parameters
cidconnection identifier where we measured latency
latencythe observed latency

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

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

Referenced by handle_matching_ack().

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 }
static struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
Low-level connection to a destination.
uint64_t rel_value_us
The actual value.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned int latency_datapoints
How many latency observations did we make for this connection?
struct GNUNET_TIME_Relative aged_latency
Our current best estimate of the latency, based on a weighted average of at least latency_datapoints ...
static int result
Global testing status.
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
struct CadetConnection * GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Lookup a connection by its identifier.
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 312 of file gnunet-service-cadet_connection.c.

References CadetConnection::ct.

313 {
314  return cc->ct;
315 }
struct CadetTConnection * ct
Which tunnel is using this connection?

◆ GCC_get_path()

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

Obtain the path used by this connection.

Parameters
ccconnection
off[out]set to offset in this path where the connection cc ends
Returns
path to cc
Parameters
ccconnection
off[out]set to the length of the path we use
Returns
path to cc

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

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().

967 {
968  *off = cc->off;
969  return cc->path;
970 }
struct CadetPeerPath * path
Path we are using to our destination.
unsigned int off
Offset of our destination in path.
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 980 of file gnunet-service-cadet_connection.c.

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().

981 {
982  return &cc->cid;
983 }
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
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 992 of file gnunet-service-cadet_connection.c.

References buf, 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(), 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(), send_create_ack(), send_keepalive(), and try_send_normal_payload().

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 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct CadetTunnel * t
Tunnel this connection belongs to.
static char buf[2048]
struct CadetTConnection * ct
Which tunnel is using this connection?
struct GNUNET_ShortHashCode connection_of_tunnel
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 1027 of file gnunet-service-cadet_connection.c.

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().

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 }
int mqm_ready
Are we ready to transmit via mq_man right now?
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct CadetPeerPath * path
Path we are using to our destination.
struct CadetPeer * destination
To which peer does this connection go?
#define LOG2(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
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.
enum CadetConnectionState state
State of the connection.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function: