GNUnet  0.11.x
Macros | Typedefs | Enumerations | Functions
gnunet-service-cadet_tunnels.h File Reference

Information we track per tunnel. More...

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

Go to the source code of this file.

Macros

#define DESIRED_CONNECTIONS_PER_TUNNEL   3
 How many connections would we like to have per tunnel? More...
 

Typedefs

typedef void(* GCT_SendContinuation) (void *cls, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
 Function called when a transmission requested using GCT_send is done. More...
 
typedef void(* GCT_ConnectionIterator) (void *cls, struct CadetTConnection *ct)
 Iterator over connections. More...
 
typedef void(* GCT_ChannelIterator) (void *cls, struct CadetChannel *ch)
 Iterator over channels. More...
 

Enumerations

enum  CadetTunnelEState {
  CADET_TUNNEL_KEY_UNINITIALIZED , CADET_TUNNEL_KEY_AX_SENT , CADET_TUNNEL_KEY_AX_RECV , CADET_TUNNEL_KEY_AX_SENT_AND_RECV ,
  CADET_TUNNEL_KEY_AX_AUTH_SENT , CADET_TUNNEL_KEY_OK
}
 All the encryption states a tunnel can be in. More...
 

Functions

int GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other)
 Am I Alice or Betty (some call her Bob), or talking to myself? More...
 
const char * GCT_2s (const struct CadetTunnel *t)
 Get the static string for the peer this tunnel is directed. More...
 
struct CadetTunnelGCT_create_tunnel (struct CadetPeer *destination)
 Create a tunnel to destination. More...
 
void GCT_destroy_tunnel_now (struct CadetTunnel *t)
 Destroys the tunnel t now, without delay. More...
 
int GCT_add_inbound_connection (struct CadetTunnel *t, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, struct CadetPeerPath *path)
 Add a connection to the tunnel. More...
 
void GCT_connection_lost (struct CadetTConnection *ct)
 We lost a connection, remove it from our list and clean up the connection object itself. More...
 
struct CadetPeerGCT_get_destination (struct CadetTunnel *t)
 Return the peer to which this tunnel goes. More...
 
void GCT_consider_path (struct CadetTunnel *t, struct CadetPeerPath *p, unsigned int off)
 Consider using the path p for the tunnel t. More...
 
struct GNUNET_CADET_ChannelTunnelNumber GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch)
 Add a channel to a tunnel. More...
 
void GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch, struct GNUNET_CADET_ChannelTunnelNumber ctn)
 Remove a channel from a tunnel. More...
 
void GCT_send_channel_destroy (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
 Send a DESTROY message via the tunnel. More...
 
struct CadetTunnelQueueEntryGCT_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 provided. More...
 
void GCT_send_cancel (struct CadetTunnelQueueEntry *q)
 Cancel a previously sent message while it's in the queue. More...
 
unsigned int GCT_count_channels (struct CadetTunnel *t)
 Return the number of channels using a tunnel. More...
 
unsigned int GCT_count_any_connections (const struct CadetTunnel *t)
 Return the number of connections available for a tunnel. More...
 
void GCT_iterate_connections (struct CadetTunnel *t, GCT_ConnectionIterator iter, void *iter_cls)
 Iterate over all connections of a tunnel. More...
 
void GCT_iterate_channels (struct CadetTunnel *t, GCT_ChannelIterator iter, void *iter_cls)
 Iterate over all channels of a tunnel. More...
 
enum CadetTunnelEState GCT_get_estate (struct CadetTunnel *t)
 Get the encryption state of a tunnel. More...
 
void GCT_change_estate (struct CadetTunnel *t, enum CadetTunnelEState state)
 Change the tunnel encryption state. More...
 
void GCT_handle_kx (struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
 Handle KX message. More...
 
void GCT_handle_kx_auth (struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
 Handle KX_AUTH message. More...
 
void GCT_handle_encrypted (struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
 Handle encrypted message. More...
 
void GCT_debug (const struct CadetTunnel *t, enum GNUNET_ErrorType level)
 Log all possible info about the tunnel state. More...
 

Detailed Description

Information we track per tunnel.

Author
Bartlomiej Polot
Christian Grothoff

Definition in file gnunet-service-cadet_tunnels.h.

Macro Definition Documentation

◆ DESIRED_CONNECTIONS_PER_TUNNEL

#define DESIRED_CONNECTIONS_PER_TUNNEL   3

How many connections would we like to have per tunnel?

Definition at line 37 of file gnunet-service-cadet_tunnels.h.

Typedef Documentation

◆ GCT_SendContinuation

typedef void(* GCT_SendContinuation) (void *cls, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)

Function called when a transmission requested using GCT_send is done.

Parameters
clsclosure
ctnidentifier of the connection used for transmission, NULL if the transmission failed (to be used to match ACKs to the respective connection for connection performance evaluation)

Definition at line 217 of file gnunet-service-cadet_tunnels.h.

◆ GCT_ConnectionIterator

typedef void(* GCT_ConnectionIterator) (void *cls, struct CadetTConnection *ct)

Iterator over connections.

Parameters
clsclosure
ctone of the connections

Definition at line 280 of file gnunet-service-cadet_tunnels.h.

◆ GCT_ChannelIterator

typedef void(* GCT_ChannelIterator) (void *cls, struct CadetChannel *ch)

Iterator over channels.

Parameters
clsclosure
chone of the channels

Definition at line 304 of file gnunet-service-cadet_tunnels.h.

Enumeration Type Documentation

◆ CadetTunnelEState

All the encryption states a tunnel can be in.

Enumerator
CADET_TUNNEL_KEY_UNINITIALIZED 

Uninitialized status, we need to send KX.

We will stay in this state until the first connection is up.

CADET_TUNNEL_KEY_AX_SENT 

KX message sent, waiting for other peer's KX_AUTH.

CADET_TUNNEL_KEY_AX_RECV 

KX message received, trying to send back KX_AUTH.

CADET_TUNNEL_KEY_AX_SENT_AND_RECV 

KX message sent and received, trying to send back KX_AUTH.

CADET_TUNNEL_KEY_AX_AUTH_SENT 

KX received and we sent KX_AUTH back, but we got no traffic yet, so we're waiting for either KX_AUTH or ENCRYPED traffic from the other peer.

We will not yet send traffic, as this might have been a replay. The other (initiating) peer should send a CHANNEL_OPEN next anyway, and then we are in business!

CADET_TUNNEL_KEY_OK 

Handshake completed: session key available.

Definition at line 43 of file gnunet-service-cadet_tunnels.h.

44 {
50 
55 
60 
65 
76 
81 };
@ CADET_TUNNEL_KEY_AX_AUTH_SENT
KX received and we sent KX_AUTH back, but we got no traffic yet, so we're waiting for either KX_AUTH ...
@ CADET_TUNNEL_KEY_AX_SENT
KX message sent, waiting for other peer's KX_AUTH.
@ CADET_TUNNEL_KEY_UNINITIALIZED
Uninitialized status, we need to send KX.
@ CADET_TUNNEL_KEY_AX_SENT_AND_RECV
KX message sent and received, trying to send back KX_AUTH.
@ CADET_TUNNEL_KEY_OK
Handshake completed: session key available.
@ CADET_TUNNEL_KEY_AX_RECV
KX message received, trying to send back KX_AUTH.

Function Documentation

◆ GCT_alice_or_betty()

int GCT_alice_or_betty ( const struct GNUNET_PeerIdentity other)

Am I Alice or Betty (some call her Bob), or talking to myself?

Parameters
otherthe other peer
Returns
GNUNET_YES for Alice, GNUNET_NO for Betty, GNUNET_SYSERR if talking to myself

Definition at line 468 of file gnunet-service-cadet_tunnels.c.

469 {
470  if (0 > GNUNET_memcmp (&my_full_id,
471  other))
472  return GNUNET_YES;
473  else if (0 < GNUNET_memcmp (&my_full_id,
474  other))
475  return GNUNET_NO;
476  else
477  {
478  GNUNET_break_op (0);
479  return GNUNET_SYSERR;
480  }
481 }
struct GNUNET_PeerIdentity my_full_id
Local peer own ID.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.

References GNUNET_break_op, GNUNET_memcmp, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, and my_full_id.

Referenced by GCT_handle_kx(), send_create(), send_kx(), and update_ax_by_kx().

Here is the caller graph for this function:

◆ GCT_2s()

const char* GCT_2s ( const struct CadetTunnel t)

Get the static string for the peer this tunnel is directed.

Parameters
tTunnel.
Returns
Static string the destination peer's ID.

Definition at line 517 of file gnunet-service-cadet_tunnels.c.

518 {
519  static char buf[64];
520 
521  if (NULL == t)
522  return "Tunnel(NULL)";
524  sizeof(buf),
525  "Tunnel %s",
526  GNUNET_i2s (GCP_get_id (t->destination)));
527  return buf;
528 }
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
static char buf[2048]
static struct GNUNET_SCHEDULER_Task * t
Main task.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.

References buf, GCP_get_id(), GNUNET_i2s(), GNUNET_snprintf(), and t.

Referenced by connection_ready_cb(), consider_path_cb(), destroy_tunnel(), GCC_2s(), GCCH_bind(), GCCH_channel_local_new(), GCCH_debug(), GCP_drop_tunnel(), GCT_add_channel(), GCT_add_inbound_connection(), GCT_change_estate(), GCT_consider_path(), GCT_debug(), GCT_handle_encrypted(), GCT_handle_kx(), GCT_remove_channel(), GCT_send(), handle_plaintext_channel_destroy(), handle_plaintext_channel_open(), handle_plaintext_channel_open_ack(), handle_plaintext_keepalive(), maintain_connections_cb(), retry_kx(), send_keepalive(), send_kx(), send_kx_auth(), try_send_normal_payload(), and update_state().

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

◆ GCT_create_tunnel()

struct CadetTunnel* GCT_create_tunnel ( struct CadetPeer destination)

Create a tunnel to destination.

Must only be called from within GCP_get_tunnel().

Parameters
destinationwhere to create the tunnel to
Returns
new tunnel to destination

Definition at line 3167 of file gnunet-service-cadet_tunnels.c.

3168 {
3169  struct CadetTunnel *t = GNUNET_new (struct CadetTunnel);
3170  struct GNUNET_MQ_MessageHandler handlers[] = {
3171  GNUNET_MQ_hd_fixed_size (plaintext_keepalive,
3173  struct GNUNET_MessageHeader,
3174  t),
3175  GNUNET_MQ_hd_var_size (plaintext_data,
3178  t),
3179  GNUNET_MQ_hd_fixed_size (plaintext_data_ack,
3182  t),
3183  GNUNET_MQ_hd_fixed_size (plaintext_channel_open,
3186  t),
3187  GNUNET_MQ_hd_fixed_size (plaintext_channel_open_ack,
3190  t),
3191  GNUNET_MQ_hd_fixed_size (plaintext_channel_destroy,
3194  t),
3196  };
3197 
3198  t->kx_retry_delay = INITIAL_KX_RETRY_DELAY;
3199  new_ephemeral (&t->ax);
3200  GNUNET_CRYPTO_ecdhe_key_create (&t->ax.kx_0);
3201  t->destination = destination;
3202  t->channels = GNUNET_CONTAINER_multihashmap32_create (8);
3203  t->maintain_connections_task
3205  t);
3206  t->mq = GNUNET_MQ_queue_for_callbacks (NULL,
3207  NULL,
3208  NULL,
3209  NULL,
3210  handlers,
3212  t);
3214  t);
3215  return t;
3216 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static void new_ephemeral(struct CadetTunnelAxolotl *ax)
Create a new Axolotl ephemeral (ratchet) key.
static int handle_decrypted(void *cls, const struct GNUNET_MessageHeader *msg)
Handles a message we decrypted, by injecting it into our message queue (which will do the dispatching...
static void decrypted_error_cb(void *cls, enum GNUNET_MQ_Error error)
Function called if we had an error processing an incoming decrypted message.
static void maintain_connections_cb(void *cls)
Function called to maintain the connections underlying our tunnel.
#define INITIAL_KX_RETRY_DELAY
How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have co...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:435
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:565
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
Ask the cadet service to create a new channel.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
Confirm payload data end-to-end.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA
Payload data (inside an encrypted tunnel).
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE
Announce connection is still alive (direction sensitive).
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
Ask the cadet service to destroy a channel.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
Confirm the creation of a channel.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
Struct containing all information regarding a tunnel to a peer.
Message for cadet data traffic.
Message to acknowledge end-to-end data.
Message to destroy a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
Message to acknowledge opening a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
Message to create a Channel.
Message handler for a specific message type.
Header for all communications.

References decrypted_error_cb(), GNUNET_CONTAINER_multihashmap32_create(), GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_queue_for_callbacks(), GNUNET_MST_create(), GNUNET_new, GNUNET_SCHEDULER_add_now(), handle_decrypted(), handlers, INITIAL_KX_RETRY_DELAY, maintain_connections_cb(), new_ephemeral(), and t.

Referenced by GCP_get_tunnel().

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

◆ GCT_destroy_tunnel_now()

void GCT_destroy_tunnel_now ( struct CadetTunnel t)

Destroys the tunnel t now, without delay.

Used during shutdown.

Parameters
ttunnel to destroy

Definition at line 2327 of file gnunet-service-cadet_tunnels.c.

2328 {
2332  t);
2333  GNUNET_assert (0 ==
2334  GCT_count_channels (t));
2335  if (NULL != t->destroy_task)
2336  {
2337  GNUNET_SCHEDULER_cancel (t->destroy_task);
2338  t->destroy_task = NULL;
2339  }
2340  destroy_tunnel (t);
2341 }
int shutting_down
Signal that shutdown is happening: prevent recovery measures.
unsigned int GCT_count_channels(struct CadetTunnel *t)
Count channels of a tunnel.
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
static int destroy_remaining_channels(void *cls, uint32_t key, void *value)
Destroy remaining channels during shutdown.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972

References destroy_remaining_channels(), destroy_tunnel(), GCT_count_channels(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, shutting_down, and t.

Referenced by destroy_tunnels_now().

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

◆ GCT_add_inbound_connection()

int GCT_add_inbound_connection ( struct CadetTunnel t,
const struct GNUNET_CADET_ConnectionTunnelIdentifier cid,
struct CadetPeerPath path 
)

Add a connection to the tunnel.

Parameters
ta tunnel
cidconnection identifier to use for the connection
pathpath to use for the connection
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure (duplicate connection)
Parameters
ta tunnel
cidconnection identifier to use for the connection
optionsoptions for the connection
pathpath to use for the connection
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure (duplicate connection)

Definition at line 3230 of file gnunet-service-cadet_tunnels.c.

3234 {
3235  struct CadetTConnection *ct;
3236 
3237  ct = GNUNET_new (struct CadetTConnection);
3239  ct->t = t;
3240  ct->cc = GCC_create_inbound (t->destination,
3241  path,
3242  ct,
3243  cid,
3245  ct);
3246  if (NULL == ct->cc)
3247  {
3249  "%s refused inbound %s (duplicate)\n",
3250  GCT_2s (t),
3251  GCC_2s (ct->cc));
3252  GNUNET_free (ct);
3253  return GNUNET_SYSERR;
3254  }
3255  /* FIXME: schedule job to kill connection (and path?) if it takes
3256  too long to get ready! (And track performance data on how long
3257  other connections took with the tunnel!)
3258  => Note: to be done within 'connection'-logic! */
3259  GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
3260  t->connection_busy_tail,
3261  ct);
3262  t->num_busy_connections++;
3264  "%s has new %s\n",
3265  GCT_2s (t),
3266  GCC_2s (ct->cc));
3267  return GNUNET_OK;
3268 }
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct CadetConnection * GCC_create_inbound(struct CadetPeer *destination, struct CadetPeerPath *path, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
static void connection_ready_cb(void *cls, int is_ready)
A connection is is_ready for transmission.
#define LOG(level,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
Entry in list of connections used by tunnel, with metadata.
struct CadetConnection * cc
Connection handle.
struct GNUNET_TIME_Absolute created
Creation time, to keep oldest connection alive.
struct CadetTunnel * t
Tunnel this connection belongs to.

References CadetTConnection::cc, connection_ready_cb(), CadetTConnection::created, GCC_2s(), GCC_create_inbound(), GCT_2s(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_get(), LOG, CadetTConnection::t, and t.

Referenced by handle_connection_create().

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

◆ GCT_connection_lost()

void GCT_connection_lost ( struct CadetTConnection ct)

We lost a connection, remove it from our list and clean up the connection object itself.

Parameters
ctbinding of connection to tunnel of the connection that was lost.

Definition at line 2168 of file gnunet-service-cadet_tunnels.c.

2169 {
2170  struct CadetTunnel *t = ct->t;
2171 
2172  if (GNUNET_YES == ct->is_ready)
2173  {
2174  GNUNET_CONTAINER_DLL_remove (t->connection_ready_head,
2175  t->connection_ready_tail,
2176  ct);
2177  t->num_ready_connections--;
2178  }
2179  else
2180  {
2181  GNUNET_CONTAINER_DLL_remove (t->connection_busy_head,
2182  t->connection_busy_tail,
2183  ct);
2184  t->num_busy_connections--;
2185  }
2186  GNUNET_free (ct);
2187 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int is_ready
Is the connection currently ready for transmission?

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_YES, CadetTConnection::is_ready, CadetTConnection::t, and t.

Referenced by destroy_t_connection(), GCC_create_inbound(), and GCC_destroy_without_core().

Here is the caller graph for this function:

◆ GCT_get_destination()

struct CadetPeer* GCT_get_destination ( struct CadetTunnel t)

Return the peer to which this tunnel goes.

Parameters
ta tunnel
Returns
the destination of the tunnel

Definition at line 573 of file gnunet-service-cadet_tunnels.c.

574 {
575  return t->destination;
576 }

References t.

Referenced by GCCH_2s(), GCCH_bind(), GCCH_channel_incoming_new(), and timeout_closed_cb().

Here is the caller graph for this function:

◆ GCT_consider_path()

void GCT_consider_path ( struct CadetTunnel t,
struct CadetPeerPath p,
unsigned int  off 
)

Consider using the path p for the tunnel t.

The tunnel destination is at offset off in path p.

Parameters
clsour tunnel
patha path to our destination
offoffset of the destination on path path

Definition at line 2851 of file gnunet-service-cadet_tunnels.c.

2854 {
2856  "Considering %s for %s (offset %u)\n",
2857  GCPP_2s (p),
2858  GCT_2s (t),
2859  off);
2860  (void) consider_path_cb (t,
2861  p,
2862  off);
2863 }
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
static int consider_path_cb(void *cls, struct CadetPeerPath *path, unsigned int off)
Consider using the path p for the tunnel t.

References consider_path_cb(), GCPP_2s(), GCT_2s(), GNUNET_ERROR_TYPE_DEBUG, LOG, p, and t.

Referenced by GCP_path_entry_add(), and GCP_set_mq().

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

◆ GCT_add_channel()

struct GNUNET_CADET_ChannelTunnelNumber GCT_add_channel ( struct CadetTunnel t,
struct CadetChannel ch 
)

Add a channel to a tunnel.

Parameters
tTunnel.
chChannel
Returns
unique number identifying ch within t

Add a channel to a tunnel.

Otherwise that notification will be done later in notify_tunnel_up_cb().

Parameters
tTunnel.
chChannel
Returns
unique number identifying ch within t

Definition at line 1928 of file gnunet-service-cadet_tunnels.c.

2111 {
2113 
2114  ctn = get_next_free_ctn (t);
2115  if (NULL != t->destroy_task)
2116  {
2117  GNUNET_SCHEDULER_cancel (t->destroy_task);
2118  t->destroy_task = NULL;
2119  }
2122  ntohl (ctn.cn),
2123  ch,
2126  "Adding %s to %s with state %d\n",
2127  GCCH_2s (ch),
2128  GCT_2s (t),
2129  t->estate);
2130  switch (t->estate)
2131  {
2133  /* waiting for connection to start KX */
2134  break;
2135 
2139  /* we're currently waiting for KX to complete */
2140  break;
2141 
2143  /* waiting for OTHER peer to send us data,
2144  we might need to prompt more aggressively! */
2145  if (NULL == t->kx_task)
2146  t->kx_task
2147  = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2148  &retry_kx,
2149  t);
2150  break;
2151 
2152  case CADET_TUNNEL_KEY_OK:
2153  /* We are ready. Tell the new channel that we are up. */
2154  GCCH_tunnel_up (ch);
2155  break;
2156  }
2157  return ctn;
2158 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
const char * GCCH_2s(const struct CadetChannel *ch)
Get the static string for identification of the channel.
void GCCH_tunnel_up(struct CadetChannel *ch)
Function called once and only once after a channel was bound to its tunnel via GCT_add_channel() is r...
static struct GNUNET_CADET_ChannelTunnelNumber get_next_free_ctn(struct CadetTunnel *t)
Compute the next free channel tunnel number for this tunnel.
static void retry_kx(void *cls)
Try to redo the KX or KX_AUTH handshake, if we can.
int GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
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
Number identifying a CADET channel within a tunnel.

References CADET_TUNNEL_KEY_AX_AUTH_SENT, CADET_TUNNEL_KEY_AX_RECV, CADET_TUNNEL_KEY_AX_SENT, CADET_TUNNEL_KEY_AX_SENT_AND_RECV, CADET_TUNNEL_KEY_OK, CADET_TUNNEL_KEY_UNINITIALIZED, cleanup_ax(), GCP_get_id(), GCT_2s(), GCT_change_estate(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CADET_KX_FLAG_FORCE_REPLY, GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_at(), GNUNET_STATISTICS_update(), CadetTunnelAxolotl::kx_0, LOG, msg, my_private_key, ret, retry_kx(), CadetTunnelAxolotl::RK, send_kx_auth(), stats, CadetTConnection::t, t, and update_ax_by_kx().

Referenced by GCCH_channel_local_new().

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

◆ GCT_remove_channel()

void GCT_remove_channel ( struct CadetTunnel t,
struct CadetChannel ch,
struct GNUNET_CADET_ChannelTunnelNumber  ctn 
)

Remove a channel from a tunnel.

Parameters
tTunnel.
chChannel
ctnunique number identifying ch within t

Definition at line 2276 of file gnunet-service-cadet_tunnels.c.

2279 {
2281  "Removing %s from %s\n",
2282  GCCH_2s (ch),
2283  GCT_2s (t));
2286  ntohl (ctn.cn),
2287  ch));
2288  if ((0 ==
2289  GCT_count_channels (t)) &&
2290  (NULL == t->destroy_task))
2291  {
2292  t->destroy_task
2294  &destroy_tunnel,
2295  t);
2296  }
2297 }
#define IDLE_DESTROY_DELAY
How long do we wait until tearing down an idle tunnel?
int GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
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
uint32_t cn
Which number does this channel have that uniquely identfies it within its tunnel, in network byte ord...

References ch, GNUNET_CADET_ChannelTunnelNumber::cn, destroy_tunnel(), GCCH_2s(), GCT_2s(), GCT_count_channels(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, IDLE_DESTROY_DELAY, LOG, and t.

Referenced by channel_destroy().

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

◆ GCT_send_channel_destroy()

void GCT_send_channel_destroy ( struct CadetTunnel t,
struct GNUNET_CADET_ChannelTunnelNumber  ctn 
)

Send a DESTROY message via the tunnel.

Parameters
tthe tunnel to transmit over
ctnID of the channel to destroy

Definition at line 3027 of file gnunet-service-cadet_tunnels.c.

3029 {
3031 
3033  "Sending DESTROY message for channel ID %u\n",
3034  ntohl (ctn.cn));
3035  msg.header.size = htons (sizeof(msg));
3037  msg.reserved = htonl (0);
3038  msg.ctn = ctn;
3039  GCT_send (t,
3040  &msg.header,
3041  NULL,
3042  NULL,
3043  &ctn);
3044 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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...
struct GNUNET_CADET_ChannelTunnelNumber ctn
ID of the channel.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References GNUNET_CADET_ChannelTunnelNumber::cn, GNUNET_CADET_ChannelDestroyMessage::ctn, GCT_send(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, LOG, msg, GNUNET_MessageHeader::size, t, and GNUNET_MessageHeader::type.

Referenced by GCCH_channel_local_destroy(), GCCH_handle_channel_plaintext_data(), GCCH_handle_local_ack(), handle_plaintext_channel_open_ack(), handle_plaintext_data(), and handle_plaintext_data_ack().

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

◆ GCT_send()

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 provided.

Parameters
messageMessage to send. Function modifies it.
tTunnel on which this message is transmitted.
contContinuation to call once message is really sent.
cont_clsClosure for cont.
Returns
Handle to cancel message.
Parameters
messageMessage to send. Function modifies it.
tTunnel on which this message is transmitted.
contContinuation to call once message is really sent.
cont_clsClosure for cont.
TheID of the channel we are using for sending.
Returns
Handle to cancel message

Definition at line 3464 of file gnunet-service-cadet_tunnels.c.

3469 {
3470  struct CadetTunnelQueueEntry *tq;
3471  uint16_t payload_size;
3472  struct GNUNET_MQ_Envelope *env;
3473  struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
3474  struct CadetChannel *ch;
3475 
3476  if (NULL != ctn)
3477  {
3478  ch = lookup_channel (t,
3479  *ctn);
3480  if ((NULL != ch) && GCCH_is_type_to_drop (ch, message))
3481  {
3482  GNUNET_break (0);
3483  return NULL;
3484  }
3485  }
3486 
3487  if (CADET_TUNNEL_KEY_OK != t->estate)
3488  {
3489  GNUNET_break (0);
3490  return NULL;
3491  }
3492  payload_size = ntohs (message->size);
3494  "Encrypting %u bytes for %s\n",
3495  (unsigned int) payload_size,
3496  GCT_2s (t));
3497  env = GNUNET_MQ_msg_extra (ax_msg,
3498  payload_size,
3500  t_ax_encrypt (&t->ax,
3501  &ax_msg[1],
3502  message,
3503  payload_size);
3505  "# encrypted bytes",
3506  payload_size,
3507  GNUNET_NO);
3508  ax_msg->ax_header.Ns = htonl (t->ax.Ns++);
3509  ax_msg->ax_header.PNs = htonl (t->ax.PNs);
3510  /* FIXME: we should do this once, not once per message;
3511  this is a point multiplication, and DHRs does not
3512  change all the time. */
3514  &ax_msg->ax_header.DHRs);
3515  t_h_encrypt (&t->ax,
3516  ax_msg);
3517  t_hmac (&ax_msg->ax_header,
3518  sizeof(struct GNUNET_CADET_AxHeader) + payload_size,
3519  0,
3520  &t->ax.HKs,
3521  &ax_msg->hmac);
3522 
3523  tq = GNUNET_malloc (sizeof(*tq));
3524  tq->t = t;
3525  tq->env = env;
3526  tq->cid = &ax_msg->cid; /* will initialize 'ax_msg->cid' once we know the connection */
3527  tq->cont = cont;
3528  tq->cont_cls = cont_cls;
3530  t->tq_tail,
3531  tq);
3532  if (NULL != t->send_task)
3533  GNUNET_SCHEDULER_cancel (t->send_task);
3534  t->send_task
3536  t);
3537  return tq;
3538 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
int GCCH_is_type_to_drop(struct CadetChannel *ch, const struct GNUNET_MessageHeader *message)
Check if type of message is the one to drop.
static void t_hmac(const void *plaintext, size_t size, uint32_t iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_ShortHashCode *hmac)
Calculate HMAC.
struct CadetChannel * lookup_channel(struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
Lookup a channel by its ctn.
static void trigger_transmissions(void *cls)
Called when either we have a new connection, or a new message in the queue, or some existing connecti...
static void t_h_encrypt(struct CadetTunnelAxolotl *ax, struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Encrypt header with the axolotl header key.
static void t_ax_encrypt(struct CadetTunnelAxolotl *ax, void *dst, const void *src, size_t size)
Encrypt data with the axolotl tunnel key.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:213
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_malloc(size)
Wrapper around malloc.
#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
#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
Axolotl encrypted 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 containing all information regarding a channel to a remote client.
struct GNUNET_CADET_ChannelTunnelNumber ctn
Number identifying this channel in its tunnel.
Struct used to save messages in a non-ready tunnel to send once connected.
struct GNUNET_MQ_Envelope * env
Envelope of message to send follows.
GCT_SendContinuation cont
Continuation to call once sent (on the channel layer).
struct GNUNET_CADET_ConnectionTunnelIdentifier * cid
Where to put the connection identifier into the payload of the message in env once we have it?
void * cont_cls
Closure for cont.
struct CadetTunnel * t
Tunnel these messages belong in.
Encrypted axolotl header with numbers that identify which keys in which ratchet are to be used to dec...
uint32_t PNs
Number of messages sent with the previous ratchet key.
struct GNUNET_CRYPTO_EcdhePublicKey DHRs
Current ratchet key.
uint32_t Ns
Number of messages sent with the current ratchet key.
Axolotl-encrypted tunnel message with application payload.
struct GNUNET_CADET_AxHeader ax_header
Axolotl-header that specifies which keys to use in which ratchet to decrypt the body that follows.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct GNUNET_ShortHashCode hmac
MAC of the encrypted message, used to verify message integrity.

References GNUNET_CADET_TunnelEncryptedMessage::ax_header, CADET_TUNNEL_KEY_OK, ch, GNUNET_CADET_TunnelEncryptedMessage::cid, CadetTunnelQueueEntry::cid, CadetTunnelQueueEntry::cont, CadetTunnelQueueEntry::cont_cls, CadetChannel::ctn, GNUNET_CADET_AxHeader::DHRs, env, CadetTunnelQueueEntry::env, GCCH_is_type_to_drop(), GCT_2s(), GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, GNUNET_MQ_msg_extra, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_CADET_TunnelEncryptedMessage::hmac, LOG, lookup_channel(), GNUNET_CADET_AxHeader::Ns, GNUNET_CADET_AxHeader::PNs, GNUNET_MessageHeader::size, stats, CadetTunnelQueueEntry::t, t, t_ax_encrypt(), t_h_encrypt(), t_hmac(), and trigger_transmissions().

Referenced by GCCH_handle_local_data(), GCT_send_channel_destroy(), retry_transmission(), send_channel_data_ack(), send_channel_open(), send_keepalive(), and send_open_ack().

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

◆ GCT_send_cancel()

void GCT_send_cancel ( struct CadetTunnelQueueEntry tq)

Cancel a previously sent message while it's in the queue.

ONLY can be called before the continuation given to the send function is called. Once the continuation is called, the message is no longer in the queue!

Parameters
qHandle to the queue entry to cancel.

ONLY can be called before the continuation given to the send function is called. Once the continuation is called, the message is no longer in the queue!

Parameters
tqHandle to the queue entry to cancel.

Definition at line 3551 of file gnunet-service-cadet_tunnels.c.

3552 {
3553  struct CadetTunnel *t = tq->t;
3554 
3555  GNUNET_CONTAINER_DLL_remove (t->tq_head,
3556  t->tq_tail,
3557  tq);
3558  GNUNET_MQ_discard (tq->env);
3559  GNUNET_free (tq);
3560 }
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:323

References CadetTunnelQueueEntry::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), CadetTunnelQueueEntry::t, and t.

Referenced by channel_destroy(), destroy_tunnel(), GCC_destroy(), handle_matching_ack(), send_channel_data_ack(), send_channel_open(), and send_open_ack().

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

◆ GCT_count_channels()

unsigned int GCT_count_channels ( struct CadetTunnel t)

Return the number of channels using a tunnel.

Parameters
ttunnel to count obtain the number of channels for
Returns
number of channels using the tunnel

Return the number of channels using a tunnel.

Parameters
tTunnel on which to count.
Returns
Number of channels.

Definition at line 587 of file gnunet-service-cadet_tunnels.c.

588 {
589  return GNUNET_CONTAINER_multihashmap32_size (t->channels);
590 }
unsigned int GNUNET_CONTAINER_multihashmap32_size(const struct GNUNET_CONTAINER_MultiHashMap32 *map)
Get the number of key-value pairs in the map.

References GNUNET_CONTAINER_multihashmap32_size(), and t.

Referenced by connection_ready_cb(), destroy_tunnel(), GCT_destroy_tunnel_now(), GCT_remove_channel(), get_all_tunnels_iterator(), and retry_kx().

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

◆ GCT_count_any_connections()

unsigned int GCT_count_any_connections ( const struct CadetTunnel t)

Return the number of connections available for a tunnel.

Parameters
ttunnel to count obtain the number of connections for
Returns
number of connections available for the tunnel

Return the number of connections available for a tunnel.

Not necessarily ready connections!

Parameters
tTunnel on which to count.
Returns
Number of connections created, either being established or ready.

Definition at line 617 of file gnunet-service-cadet_tunnels.c.

618 {
619  return t->num_ready_connections + t->num_busy_connections;
620 }

References t.

Referenced by consider_path_cb(), GCT_debug(), get_all_tunnels_iterator(), and maintain_connections_cb().

Here is the caller graph for this function:

◆ GCT_iterate_connections()

void GCT_iterate_connections ( struct CadetTunnel t,
GCT_ConnectionIterator  iter,
void *  iter_cls 
)

Iterate over all connections of a tunnel.

Parameters
tTunnel whose connections to iterate.
iterIterator.
iter_clsClosure for iter.

Definition at line 3571 of file gnunet-service-cadet_tunnels.c.

3574 {
3575  struct CadetTConnection *n;
3576 
3577  for (struct CadetTConnection *ct = t->connection_ready_head;
3578  NULL != ct;
3579  ct = n)
3580  {
3581  n = ct->next;
3582  iter (iter_cls,
3583  ct);
3584  }
3585  for (struct CadetTConnection *ct = t->connection_busy_head;
3586  NULL != ct;
3587  ct = n)
3588  {
3589  n = ct->next;
3590  iter (iter_cls,
3591  ct);
3592  }
3593 }
struct CadetTConnection * next
Next in DLL.

References CadetTConnection::next, and t.

Referenced by consider_path_cb(), destroy_tunnel(), and maintain_connections_cb().

Here is the caller graph for this function:

◆ GCT_iterate_channels()

void GCT_iterate_channels ( struct CadetTunnel t,
GCT_ChannelIterator  iter,
void *  iter_cls 
)

Iterate over all channels of a tunnel.

Parameters
tTunnel whose channels to iterate.
iterIterator.
iter_clsClosure for iter.

Definition at line 3643 of file gnunet-service-cadet_tunnels.c.

3646 {
3647  struct ChanIterCls ctx;
3648 
3649  ctx.iter = iter;
3650  ctx.iter_cls = iter_cls;
3653  &ctx);
3654 }
static int iterate_channels_cb(void *cls, uint32_t key, void *value)
Helper function for GCT_iterate_channels.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Closure for iterate_channels_cb.
void * iter_cls
Closure for iter.
GCT_ChannelIterator iter
Function to call.

References ctx, GNUNET_CONTAINER_multihashmap32_iterate(), ChanIterCls::iter, ChanIterCls::iter_cls, iterate_channels_cb(), and t.

Here is the call graph for this function:

◆ GCT_get_estate()

enum CadetTunnelEState GCT_get_estate ( struct CadetTunnel t)

Get the encryption state of a tunnel.

Parameters
tTunnel.
Returns
Tunnel's encryption state.

Definition at line 631 of file gnunet-service-cadet_tunnels.c.

650 {
651  return t->estate;
652 }

References GNUNET_assert, GNUNET_YES, CadetTConnection::is_ready, and t.

Referenced by get_all_tunnels_iterator(), handle_connection_create(), send_create(), and send_keepalive().

Here is the caller graph for this function:

◆ GCT_change_estate()

void GCT_change_estate ( struct CadetTunnel t,
enum CadetTunnelEState  state 
)

Change the tunnel encryption state.

If the encryption state changes to OK, stop the rekey task.

Parameters
tTunnel whose encryption state to change, or NULL.
stateNew encryption state.

Definition at line 1298 of file gnunet-service-cadet_tunnels.c.

1300 {
1301  enum CadetTunnelEState old = t->estate;
1302 
1303  t->estate = state;
1305  "%s estate changed from %s to %s\n",
1306  GCT_2s (t),
1307  estate2s (old),
1308  estate2s (state));
1309 
1310  if ((CADET_TUNNEL_KEY_OK != old) &&
1311  (CADET_TUNNEL_KEY_OK == t->estate))
1312  {
1313  if (NULL != t->kx_task)
1314  {
1315  GNUNET_SCHEDULER_cancel (t->kx_task);
1316  t->kx_task = NULL;
1317  }
1318  /* notify all channels that have been waiting */
1321  t);
1322  if (NULL != t->send_task)
1323  GNUNET_SCHEDULER_cancel (t->send_task);
1325  t);
1326  }
1327 }
enum State state
current state of profiling
static int notify_tunnel_up_cb(void *cls, uint32_t key, void *value)
Our tunnel became ready for the first time, notify channels that have been waiting.
static const char * estate2s(enum CadetTunnelEState es)
Get string description for tunnel encryption state.
CadetTunnelEState
All the encryption states a tunnel can be in.

References CADET_TUNNEL_KEY_OK, estate2s(), GCT_2s(), GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), LOG, notify_tunnel_up_cb(), state, t, and trigger_transmissions().

Referenced by GCT_add_channel(), GCT_handle_encrypted(), GCT_handle_kx(), handle_connection_create(), send_kx(), and send_kx_auth().

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

◆ GCT_handle_kx()

void GCT_handle_kx ( struct CadetTConnection ct,
const struct GNUNET_CADET_TunnelKeyExchangeMessage msg 
)

Handle KX message.

Parameters
ctconnection/tunnel combo that received encrypted message
msgthe key exchange message

Handle KX message.

Parameters
ctconnection/tunnel combo that received encrypted message
msgthe key exchange message

Definition at line 1718 of file gnunet-service-cadet_tunnels.c.

1720 {
1721  struct CadetTunnel *t = ct->t;
1722  int ret;
1723 
1725  "# KX received",
1726  1,
1727  GNUNET_NO);
1728  if (GNUNET_YES ==
1729  GCT_alice_or_betty (GCP_get_id (t->destination)))
1730  {
1731  /* Betty/Bob is not allowed to send KX! */
1732  GNUNET_break_op (0);
1733  return;
1734  }
1736  "Received KX message from %s with ephemeral %s from %s on connection %s\n",
1737  GCT_2s (t),
1738  GNUNET_e2s (&msg->ephemeral_key),
1739  GNUNET_i2s (GCP_get_id (t->destination)),
1740  GCC_2s (ct->cc));
1741 #if 1
1742  if ((0 ==
1743  memcmp (&t->ax.DHRr,
1744  &msg->ratchet_key,
1745  sizeof(msg->ratchet_key))) &&
1746  (0 ==
1747  memcmp (&t->ax.last_ephemeral,
1748  &msg->ephemeral_key,
1749  sizeof(msg->ephemeral_key))))
1750 
1751  {
1753  "# Duplicate KX received",
1754  1,
1755  GNUNET_NO);
1756  send_kx_auth (t,
1757  ct,
1758  &t->ax,
1759  GNUNET_NO);
1760  return;
1761  }
1762 #endif
1763  /* We only keep ONE unverified KX around, so if there is an existing one,
1764  clean it up. */
1765  if (NULL != t->unverified_ax)
1766  {
1767  if ((0 ==
1768  memcmp (&t->unverified_ax->DHRr,
1769  &msg->ratchet_key,
1770  sizeof(msg->ratchet_key))) &&
1771  (0 ==
1772  memcmp (&t->unverified_ax->last_ephemeral,
1773  &msg->ephemeral_key,
1774  sizeof(msg->ephemeral_key))))
1775  {
1777  "# Duplicate unverified KX received",
1778  1,
1779  GNUNET_NO);
1780 #if 1
1781  send_kx_auth (t,
1782  ct,
1783  t->unverified_ax,
1784  GNUNET_NO);
1785  return;
1786 #endif
1787  }
1789  "Dropping old unverified KX state.\n");
1791  "# Unverified KX dropped for fresh KX",
1792  1,
1793  GNUNET_NO);
1794  GNUNET_break (NULL == t->unverified_ax->skipped_head);
1795  memset (t->unverified_ax,
1796  0,
1797  sizeof(struct CadetTunnelAxolotl));
1798  }
1799  else
1800  {
1802  "Creating fresh unverified KX for %s\n",
1803  GCT_2s (t));
1805  "# Fresh KX setup",
1806  1,
1807  GNUNET_NO);
1808  t->unverified_ax = GNUNET_new (struct CadetTunnelAxolotl);
1809  }
1810  /* Set as the 'current' RK/DHRr the one we are currently using,
1811  so that the duplicate-detection logic of
1812  #update_ax_by_kx can work. */
1813  t->unverified_ax->RK = t->ax.RK;
1814  t->unverified_ax->DHRr = t->ax.DHRr;
1815  t->unverified_ax->DHRs = t->ax.DHRs;
1816  t->unverified_ax->kx_0 = t->ax.kx_0;
1817  t->unverified_attempts = 0;
1818 
1819  /* Update 'ax' by the new key material */
1820  ret = update_ax_by_kx (t->unverified_ax,
1821  GCP_get_id (t->destination),
1822  &msg->ephemeral_key,
1823  &msg->ratchet_key);
1825  if (GNUNET_OK != ret)
1826  {
1828  "# Useless KX",
1829  1,
1830  GNUNET_NO);
1831  return; /* duplicate KX, nothing to do */
1832  }
1833  /* move ahead in our state machine */
1834  if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
1837  else if (CADET_TUNNEL_KEY_AX_SENT == t->estate)
1840 
1841  /* KX is still not done, try again our end. */
1842  if (CADET_TUNNEL_KEY_OK != t->estate)
1843  {
1844  if (NULL != t->kx_task)
1845  GNUNET_SCHEDULER_cancel (t->kx_task);
1846  t->kx_task
1848  t);
1849  }
1850 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
void GCT_change_estate(struct CadetTunnel *t, enum CadetTunnelEState state)
Change the tunnel encryption state.
static void send_kx_auth(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
Send a KX_AUTH message.
static int update_ax_by_kx(struct CadetTunnelAxolotl *ax, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral_key, const struct GNUNET_CRYPTO_EcdhePublicKey *ratchet_key)
Update our Axolotl key state based on the KX data we received.
int GCT_alice_or_betty(const struct GNUNET_PeerIdentity *other)
Am I Alice or Betty (some call her Bob), or talking to myself?
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
Axolotl data, according to https://github.com/trevp/axolotl/wiki .

References CADET_TUNNEL_KEY_AX_RECV, CADET_TUNNEL_KEY_AX_SENT, CADET_TUNNEL_KEY_AX_SENT_AND_RECV, CADET_TUNNEL_KEY_OK, CADET_TUNNEL_KEY_UNINITIALIZED, CadetTConnection::cc, GCC_2s(), GCP_get_id(), GCT_2s(), GCT_alice_or_betty(), GCT_change_estate(), GNUNET_break, GNUNET_break_op, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, LOG, msg, ret, retry_kx(), send_kx_auth(), stats, CadetTConnection::t, t, and update_ax_by_kx().

Referenced by GCC_handle_kx().

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

◆ GCT_handle_kx_auth()

void GCT_handle_kx_auth ( struct CadetTConnection ct,
const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage msg 
)

Handle KX_AUTH message.

Parameters
ctconnection/tunnel combo that received encrypted message
msgthe key exchange message

Definition at line 1928 of file gnunet-service-cadet_tunnels.c.

1930 {
1931  struct CadetTunnel *t = ct->t;
1932  struct CadetTunnelAxolotl ax_tmp;
1933  struct GNUNET_HashCode kx_auth;
1934  int ret;
1935 
1937  "# KX_AUTH received",
1938  1,
1939  GNUNET_NO);
1940  if ((CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) ||
1941  (CADET_TUNNEL_KEY_AX_RECV == t->estate))
1942  {
1943  /* Confusing, we got a KX_AUTH before we even send our own
1944  KX. This should not happen. We'll send our own KX ASAP anyway,
1945  so let's ignore this here. */
1946  GNUNET_break_op (0);
1947  return;
1948  }
1950  "Handling KX_AUTH message from %s with ephemeral %s\n",
1951  GCT_2s (t),
1952  GNUNET_e2s (&msg->kx.ephemeral_key));
1953  /* We do everything in ax_tmp until we've checked the authentication
1954  so we don't clobber anything we care about by accident. */
1955  ax_tmp = t->ax;
1956 
1957  /* Update 'ax' by the new key material */
1958  ret = update_ax_by_kx (&ax_tmp,
1959  GCP_get_id (t->destination),
1960  &msg->kx.ephemeral_key,
1961  &msg->kx.ratchet_key);
1962  if (GNUNET_OK != ret)
1963  {
1964  if (GNUNET_NO == ret)
1966  "# redundant KX_AUTH received",
1967  1,
1968  GNUNET_NO);
1969  else
1970  GNUNET_break (0); /* connect to self!? */
1971  return;
1972  }
1973  GNUNET_CRYPTO_hash (&ax_tmp.RK,
1974  sizeof(ax_tmp.RK),
1975  &kx_auth);
1976  if (0 != GNUNET_memcmp (&kx_auth,
1977  &msg->auth))
1978  {
1979  /* This KX_AUTH is not using the latest KX/KX_AUTH data
1980  we transmitted to the sender, refuse it, try KX again. */
1982  "# KX_AUTH not using our last KX received (auth failure)",
1983  1,
1984  GNUNET_NO);
1986  "KX AUTH mismatch!\n");
1987 #if DEBUG_KX
1988  {
1989  struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
1990 
1991  GNUNET_CRYPTO_ecdhe_key_get_public (&ax_tmp.kx_0,
1992  &ephemeral_key);
1993  if (0 != GNUNET_memcmp (&ephemeral_key,
1994  &msg->r_ephemeral_key_XXX))
1995  {
1997  "My ephemeral is %s!\n",
1998  GNUNET_e2s (&ephemeral_key));
2000  "Response is for ephemeral %s!\n",
2001  GNUNET_e2s (&msg->r_ephemeral_key_XXX));
2002  }
2003  else
2004  {
2005  test_crypto_bug (&ax_tmp.kx_0,
2006  &msg->kx.ephemeral_key_XXX,
2008  &msg->kx.private_key_XXX);
2009  }
2010  }
2011 #endif
2012  if (NULL == t->kx_task)
2013  t->kx_task
2014  = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2015  &retry_kx,
2016  t);
2017  return;
2018  }
2019  /* Yep, we're good. */
2020  t->ax = ax_tmp;
2021  if (NULL != t->unverified_ax)
2022  {
2023  /* We got some "stale" KX before, drop that. */
2024  cleanup_ax (t->unverified_ax);
2025  GNUNET_free (t->unverified_ax);
2026  t->unverified_ax = NULL;
2027  }
2028 
2029  /* move ahead in our state machine */
2030  switch (t->estate)
2031  {
2034  /* Checked above, this is impossible. */
2035  GNUNET_assert (0);
2036  break;
2037 
2038  case CADET_TUNNEL_KEY_AX_SENT: /* This is the normal case */
2039  case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: /* both peers started KX */
2040  case CADET_TUNNEL_KEY_AX_AUTH_SENT: /* both peers now did KX_AUTH */
2043  break;
2044 
2045  case CADET_TUNNEL_KEY_OK:
2046  /* Did not expect another KX_AUTH, but so what, still acceptable.
2047  Nothing to do here. */
2048  break;
2049  }
2050  if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl (msg->kx.flags)))
2051  {
2052  send_kx_auth (t,
2053  NULL,
2054  &t->ax,
2055  GNUNET_NO);
2056  }
2057 }
@ GNUNET_CADET_KX_FLAG_FORCE_REPLY
The peer should reply with its KX details?
struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Own private key.
static void cleanup_ax(struct CadetTunnelAxolotl *ax)
Cleanup state used by ax.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
@ GNUNET_ERROR_TYPE_WARNING
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
A 512-bit hashcode.

Referenced by GCC_handle_kx_auth().

Here is the caller graph for this function:

◆ GCT_handle_encrypted()

void GCT_handle_encrypted ( struct CadetTConnection ct,
const struct GNUNET_CADET_TunnelEncryptedMessage msg 
)

Handle encrypted message.

Parameters
ctconnection/tunnel combo that received encrypted message
msgthe encrypted message to decrypt

Definition at line 3278 of file gnunet-service-cadet_tunnels.c.

3280 {
3281  struct CadetTunnel *t = ct->t;
3282  uint16_t size = ntohs (msg->header.size);
3283  char cbuf[size] GNUNET_ALIGN;
3284  ssize_t decrypted_size;
3285 
3287  "%s received %u bytes of encrypted data in state %d\n",
3288  GCT_2s (t),
3289  (unsigned int) size,
3290  t->estate);
3291 
3292  switch (t->estate)
3293  {
3296  /* We did not even SEND our KX, how can the other peer
3297  send us encrypted data? Must have been that we went
3298  down and the other peer still things we are up.
3299  Let's send it KX back. */
3301  "# received encrypted without any KX",
3302  1,
3303  GNUNET_NO);
3304  if (NULL != t->kx_task)
3305  {
3306  GNUNET_SCHEDULER_cancel (t->kx_task);
3307  t->kx_task = NULL;
3308  }
3309  send_kx (t,
3310  ct,
3311  &t->ax);
3312  return;
3313 
3315  /* We send KX, and other peer send KX to us at the same time.
3316  Neither KX is AUTH'ed, so let's try KX_AUTH this time. */
3318  "# received encrypted without KX_AUTH",
3319  1,
3320  GNUNET_NO);
3321  if (NULL != t->kx_task)
3322  {
3323  GNUNET_SCHEDULER_cancel (t->kx_task);
3324  t->kx_task = NULL;
3325  }
3326  send_kx_auth (t,
3327  ct,
3328  &t->ax,
3329  GNUNET_YES);
3330  return;
3331 
3333  /* We did not get the KX of the other peer, but that
3334  might have been lost. Send our KX again immediately. */
3336  "# received encrypted without KX",
3337  1,
3338  GNUNET_NO);
3339  if (NULL != t->kx_task)
3340  {
3341  GNUNET_SCHEDULER_cancel (t->kx_task);
3342  t->kx_task = NULL;
3343  }
3344  send_kx (t,
3345  ct,
3346  &t->ax);
3347  return;
3348 
3350  /* Great, first payload, we might graduate to OK! */
3351  case CADET_TUNNEL_KEY_OK:
3352  /* We are up and running, all good. */
3353  break;
3354  }
3355 
3356  decrypted_size = -1;
3357  if (CADET_TUNNEL_KEY_OK == t->estate)
3358  {
3359  /* We have well-established key material available,
3360  try that. (This is the common case.) */
3361  decrypted_size = t_ax_decrypt_and_validate (&t->ax,
3362  cbuf,
3363  msg,
3364  size);
3365  }
3366 
3367  if ((-1 == decrypted_size) &&
3368  (NULL != t->unverified_ax))
3369  {
3370  /* We have un-authenticated KX material available. We should try
3371  this as a back-up option, in case the sender crashed and
3372  switched keys. */
3373  decrypted_size = t_ax_decrypt_and_validate (t->unverified_ax,
3374  cbuf,
3375  msg,
3376  size);
3377  if (-1 != decrypted_size)
3378  {
3379  /* It worked! Treat this as authentication of the AX data! */
3380  cleanup_ax (&t->ax);
3381  t->ax = *t->unverified_ax;
3382  GNUNET_free (t->unverified_ax);
3383  t->unverified_ax = NULL;
3384  }
3385  if (CADET_TUNNEL_KEY_AX_AUTH_SENT == t->estate)
3386  {
3387  /* First time it worked, move tunnel into production! */
3390  if (NULL != t->send_task)
3391  GNUNET_SCHEDULER_cancel (t->send_task);
3393  t);
3394  }
3395  }
3396  if (NULL != t->unverified_ax)
3397  {
3398  /* We had unverified KX material that was useless; so increment
3399  counter and eventually move to ignore it. Note that we even do
3400  this increment if we successfully decrypted with the old KX
3401  material and thus didn't even both with the new one. This is
3402  the ideal case, as a malicious injection of bogus KX data
3403  basically only causes us to increment a counter a few times. */t->unverified_attempts++;
3405  "Failed to decrypt message with unverified KX data %u times\n",
3406  t->unverified_attempts);
3407  if (t->unverified_attempts > MAX_UNVERIFIED_ATTEMPTS)
3408  {
3409  cleanup_ax (t->unverified_ax);
3410  GNUNET_free (t->unverified_ax);
3411  t->unverified_ax = NULL;
3412  }
3413  }
3414 
3415  if (-1 == decrypted_size)
3416  {
3417  /* Decryption failed for good, complain. */
3419  "%s failed to decrypt and validate encrypted data, retrying KX\n",
3420  GCT_2s (t));
3422  "# unable to decrypt",
3423  1,
3424  GNUNET_NO);
3425  if (NULL != t->kx_task)
3426  {
3427  GNUNET_SCHEDULER_cancel (t->kx_task);
3428  t->kx_task = NULL;
3429  }
3430  send_kx (t,
3431  ct,
3432  &t->ax);
3433  return;
3434  }
3436  "# decrypted bytes",
3437  decrypted_size,
3438  GNUNET_NO);
3439 
3440  /* The MST will ultimately call #handle_decrypted() on each message. */
3441  t->current_ct = ct;
3443  GNUNET_MST_from_buffer (t->mst,
3444  cbuf,
3445  decrypted_size,
3446  GNUNET_YES,
3447  GNUNET_NO));
3448  t->current_ct = NULL;
3449 }
#define MAX_UNVERIFIED_ATTEMPTS
How often do we try to decrypt payload with unverified key material? Used to limit CPU increase upon ...
static void send_kx(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax)
Send a KX message.
static ssize_t t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax, void *dst, const struct GNUNET_CADET_TunnelEncryptedMessage *src, size_t size)
Decrypt and verify data with the appropriate tunnel key and verify that the data has not been altered...
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:114
static unsigned int size
Size of the "table".
Definition: peer.c:67

References CADET_TUNNEL_KEY_AX_AUTH_SENT, CADET_TUNNEL_KEY_AX_RECV, CADET_TUNNEL_KEY_AX_SENT, CADET_TUNNEL_KEY_AX_SENT_AND_RECV, CADET_TUNNEL_KEY_OK, CADET_TUNNEL_KEY_UNINITIALIZED, cleanup_ax(), GCT_2s(), GCT_change_estate(), GNUNET_ALIGN, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, LOG, MAX_UNVERIFIED_ATTEMPTS, msg, send_kx(), send_kx_auth(), GNUNET_MessageHeader::size, size, stats, CadetTConnection::t, t, t_ax_decrypt_and_validate(), and trigger_transmissions().

Referenced by GCC_handle_encrypted().

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

◆ GCT_debug()

void GCT_debug ( const struct CadetTunnel t,
enum GNUNET_ErrorType  level 
)

Log all possible info about the tunnel state.

Parameters
tTunnel to debug.
levelDebug level to use.

Definition at line 3689 of file gnunet-service-cadet_tunnels.c.

3691 {
3692 #if ! defined(GNUNET_CULL_LOGGING)
3693  struct CadetTConnection *iter_c;
3694  int do_log;
3695 
3697  "cadet-tun",
3698  __FILE__, __FUNCTION__, __LINE__);
3699  if (0 == do_log)
3700  return;
3701 
3702  LOG2 (level,
3703  "TTT TUNNEL TOWARDS %s in estate %s tq_len: %u #cons: %u\n",
3704  GCT_2s (t),
3705  estate2s (t->estate),
3706  t->tq_len,
3708  LOG2 (level,
3709  "TTT channels:\n");
3711  &debug_channel,
3712  &level);
3713  LOG2 (level,
3714  "TTT connections:\n");
3715  for (iter_c = t->connection_ready_head; NULL != iter_c; iter_c = iter_c->next)
3716  GCC_debug (iter_c->cc,
3717  level);
3718  for (iter_c = t->connection_busy_head; NULL != iter_c; iter_c = iter_c->next)
3719  GCC_debug (iter_c->cc,
3720  level);
3721 
3722  LOG2 (level,
3723  "TTT TUNNEL END\n");
3724 #endif
3725 }
void GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level)
Log connection info.
static int debug_channel(void *cls, uint32_t key, void *value)
Call GCCH_debug() on a channel.
unsigned int GCT_count_any_connections(const struct CadetTunnel *t)
Count all created connections of a tunnel.
#define LOG2(level,...)
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.
@ GNUNET_ERROR_TYPE_BULK

References CadetTConnection::cc, debug_channel(), estate2s(), GCC_debug(), GCT_2s(), GCT_count_any_connections(), GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_ERROR_TYPE_BULK, GNUNET_get_log_call_status(), LOG2, CadetTConnection::next, and t.

Here is the call graph for this function: