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

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 destionation. 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)
 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_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.

Referenced by consider_path_cb(), consider_peer_activate(), GCP_attach_path(), GCP_path_entry_remove(), maintain_connections_cb(), and path_heap_cleanup().

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 210 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 272 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 296 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 };
KX received and we sent KX_AUTH back, but we got no traffic yet, so we're waiting for either KX_AUTH ...
KX message sent, waiting for other peer's KX_AUTH.
Handshake completed: session key available.
KX message sent and received, trying to send back KX_AUTH.
Uninitialized status, we need to send KX.
KX message received, trying to send back KX_AUTH.

Function Documentation

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

References buf, CadetTunnel::destination, GCP_get_id(), GNUNET_i2s(), and GNUNET_snprintf().

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

518 {
519  static char buf[64];
520 
521  if (NULL == t)
522  return "Tunnel(NULL)";
523  GNUNET_snprintf (buf,
524  sizeof(buf),
525  "Tunnel %s",
527  return buf;
528 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static char buf[2048]
struct CadetPeer * destination
Destination of the tunnel.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
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 destionation.

Must only be called from within GCP_get_tunnel().

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

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

References CadetTunnel::ax, CadetTunnel::channels, decrypted_error_cb(), CadetTunnel::destination, GNUNET_assert, GNUNET_CONTAINER_multihashmap32_create(), GNUNET_CRYPTO_ecdhe_key_create2(), 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_OK, GNUNET_SCHEDULER_add_now(), handle_decrypted(), INITIAL_KX_RETRY_DELAY, CadetTunnelAxolotl::kx_0, CadetTunnel::kx_retry_delay, maintain_connections_cb(), CadetTunnel::maintain_connections_task, CadetTunnel::mq, CadetTunnel::mst, new_ephemeral(), and t.

Referenced by GCP_get_tunnel().

3164 {
3165  struct CadetTunnel *t = GNUNET_new (struct CadetTunnel);
3166  struct GNUNET_MQ_MessageHandler handlers[] = {
3167  GNUNET_MQ_hd_fixed_size (plaintext_keepalive,
3169  struct GNUNET_MessageHeader,
3170  t),
3171  GNUNET_MQ_hd_var_size (plaintext_data,
3174  t),
3175  GNUNET_MQ_hd_fixed_size (plaintext_data_ack,
3178  t),
3179  GNUNET_MQ_hd_fixed_size (plaintext_channel_open,
3182  t),
3183  GNUNET_MQ_hd_fixed_size (plaintext_channel_open_ack,
3186  t),
3187  GNUNET_MQ_hd_fixed_size (plaintext_channel_destroy,
3190  t),
3192  };
3193 
3195  new_ephemeral (&t->ax);
3198  t->destination = destination;
3202  t);
3203  t->mq = GNUNET_MQ_queue_for_callbacks (NULL,
3204  NULL,
3205  NULL,
3206  NULL,
3207  handlers,
3209  t);
3211  t);
3212  return t;
3213 }
struct CadetTunnelAxolotl ax
Axolotl info.
int GNUNET_CRYPTO_ecdhe_key_create2(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:630
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
struct GNUNET_MQ_Handle * mq
Dispatcher for decrypted messages only (do NOT use for sending!).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
Confirm the creation of a channel.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
Ask the cadet service to destroy a channel.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA
Payload data (inside an encrypted tunnel).
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
Ask the cadet service to create a new channel.
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:552
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
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:1280
#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...
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for decrypted messages.
Message for cadet data traffic.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE
Announce connection is still alive (direction sensitive).
Message handler for a specific message type.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
Struct containing all information regarding a tunnel to a peer.
Message to acknowledge end-to-end data.
static void decrypted_error_cb(void *cls, enum GNUNET_MQ_Error error)
Function called if we had an error processing an incoming decrypted message.
Message to acknowledge opening a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
Message to create a Channel.
Message to destroy a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
static void maintain_connections_cb(void *cls)
Function called to maintain the connections underlying our tunnel.
struct CadetPeer * destination
Destination of the tunnel.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
Confirm payload data end-to-end.
struct GNUNET_SCHEDULER_Task * maintain_connections_task
Task to trim connections if too many are present.
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...
struct GNUNET_TIME_Relative kx_retry_delay
How long do we wait until we retry the KX?
Header for all communications.
static void new_ephemeral(struct CadetTunnelAxolotl *ax)
Create a new Axolotl ephemeral (ratchet) key.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_CRYPTO_EcdhePrivateKey kx_0
ECDH for key exchange (A0 / B0).
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 2334 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::channels, destroy_remaining_channels(), CadetTunnel::destroy_task, destroy_tunnel(), GCT_count_channels(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, and shutting_down.

Referenced by destroy_tunnels_now().

2335 {
2339  t);
2340  GNUNET_assert (0 ==
2341  GCT_count_channels (t));
2342  if (NULL != t->destroy_task)
2343  {
2345  t->destroy_task = NULL;
2346  }
2347  destroy_tunnel (t);
2348 }
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
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.
struct GNUNET_SCHEDULER_Task * destroy_task
Task scheduled if there are no more channels using the 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 shutting_down
Signal that shutdown is happening: prevent recovery measures.
unsigned int GCT_count_channels(struct CadetTunnel *t)
Count channels of a tunnel.
#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:966
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 identifer 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 identifer 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 3227 of file gnunet-service-cadet_tunnels.c.

References CadetTConnection::cc, CadetTunnel::connection_busy_head, CadetTunnel::connection_busy_tail, connection_ready_cb(), CadetTConnection::created, CadetTunnel::destination, 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, CadetTunnel::num_busy_connections, t, and CadetTConnection::t.

Referenced by handle_connection_create().

3231 {
3232  struct CadetTConnection *ct;
3233 
3234  ct = GNUNET_new (struct CadetTConnection);
3236  ct->t = t;
3237  ct->cc = GCC_create_inbound (t->destination,
3238  path,
3239  ct,
3240  cid,
3242  ct);
3243  if (NULL == ct->cc)
3244  {
3246  "%s refused inbound %s (duplicate)\n",
3247  GCT_2s (t),
3248  GCC_2s (ct->cc));
3249  GNUNET_free (ct);
3250  return GNUNET_SYSERR;
3251  }
3252  /* FIXME: schedule job to kill connection (and path?) if it takes
3253  too long to get ready! (And track performance data on how long
3254  other connections took with the tunnel!)
3255  => Note: to be done within 'connection'-logic! */
3258  ct);
3259  t->num_busy_connections++;
3261  "%s has new %s\n",
3262  GCT_2s (t),
3263  GCC_2s (ct->cc));
3264  return GNUNET_OK;
3265 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * t
Main task.
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...
struct CadetTConnection * connection_busy_head
DLL of connections that we maintain that might be used to reach the destination peer.
struct CadetTunnel * t
Tunnel this connection belongs to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct CadetConnection * cc
Connection handle.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Entry in list of connections used by tunnel, with metadata.
struct CadetPeer * destination
Destination of the tunnel.
static void connection_ready_cb(void *cls, int is_ready)
A connection is is_ready for transmission.
struct GNUNET_TIME_Absolute created
Creation time, to keep oldest connection alive.
#define LOG(level,...)
unsigned int num_busy_connections
Number of connections in the connection_busy_head DLL.
struct CadetTConnection * connection_busy_tail
DLL of connections that we maintain that might be used to reach the destination peer.
#define GNUNET_free(ptr)
Wrapper around free.
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 2175 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::connection_busy_head, CadetTunnel::connection_busy_tail, CadetTunnel::connection_ready_head, CadetTunnel::connection_ready_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_YES, CadetTConnection::is_ready, CadetTunnel::num_busy_connections, CadetTunnel::num_ready_connections, and CadetTConnection::t.

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

2176 {
2177  struct CadetTunnel *t = ct->t;
2178 
2179  if (GNUNET_YES == ct->is_ready)
2180  {
2183  ct);
2184  t->num_ready_connections--;
2185  }
2186  else
2187  {
2190  ct);
2191  t->num_busy_connections--;
2192  }
2193  GNUNET_free (ct);
2194 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct CadetTConnection * connection_ready_tail
DLL of ready connections that are actively used to reach the destination peer.
int is_ready
Is the connection currently ready for transmission?
unsigned int num_ready_connections
Number of connections in the connection_ready_head DLL.
struct CadetTConnection * connection_ready_head
DLL of ready connections that are actively used to reach the destination peer.
static struct GNUNET_SCHEDULER_Task * t
Main task.
struct CadetTConnection * connection_busy_head
DLL of connections that we maintain that might be used to reach the destination peer.
struct CadetTunnel * t
Tunnel this connection belongs to.
Struct containing all information regarding a tunnel to a peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
unsigned int num_busy_connections
Number of connections in the connection_busy_head DLL.
struct CadetTConnection * connection_busy_tail
DLL of connections that we maintain that might be used to reach the destination peer.
#define GNUNET_free(ptr)
Wrapper around free.
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 580 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::destination.

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

581 {
582  return t->destination;
583 }
struct CadetPeer * destination
Destination of the tunnel.
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 2848 of file gnunet-service-cadet_tunnels.c.

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

Referenced by GCP_path_entry_add(), and GCP_set_mq().

2851 {
2853  "Considering %s for %s (offset %u)\n",
2854  GCPP_2s (p),
2855  GCT_2s (t),
2856  off);
2857  (void) consider_path_cb (t,
2858  p,
2859  off);
2860 }
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
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.
#define LOG(level,...)
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 2117 of file gnunet-service-cadet_tunnels.c.

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, ch, GCCH_2s(), GCCH_tunnel_up(), GCT_2s(), get_next_free_ctn(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, LOG, and retry_kx().

Referenced by GCCH_channel_local_new().

2119 {
2121 
2122  ctn = get_next_free_ctn (t);
2123  if (NULL != t->destroy_task)
2124  {
2126  t->destroy_task = NULL;
2127  }
2130  ntohl (ctn.cn),
2131  ch,
2134  "Adding %s to %s\n",
2135  GCCH_2s (ch),
2136  GCT_2s (t));
2137  switch (t->estate)
2138  {
2140  /* waiting for connection to start KX */
2141  break;
2142 
2146  /* we're currently waiting for KX to complete */
2147  break;
2148 
2150  /* waiting for OTHER peer to send us data,
2151  we might need to prompt more aggressively! */
2152  if (NULL == t->kx_task)
2153  t->kx_task
2155  &retry_kx,
2156  t);
2157  break;
2158 
2159  case CADET_TUNNEL_KEY_OK:
2160  /* We are ready. Tell the new channel that we are up. */
2161  GCCH_tunnel_up (ch);
2162  break;
2163  }
2164  return ctn;
2165 }
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
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...
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
KX received and we sent KX_AUTH back, but we got no traffic yet, so we're waiting for either KX_AUTH ...
KX message sent, waiting for other peer's KX_AUTH.
struct GNUNET_SCHEDULER_Task * destroy_task
Task scheduled if there are no more channels using the tunnel.
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.
struct GNUNET_SCHEDULER_Task * kx_task
Task to trigger KX.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TIME_Absolute next_kx_attempt
When do we try the next KX?
Handshake completed: session key available.
const char * GCCH_2s(const struct CadetChannel *ch)
Get the static string for identification of the channel.
KX message sent and received, trying to send back KX_AUTH.
Number identifying a CADET channel within a tunnel.
static void retry_kx(void *cls)
Try to redo the KX or KX_AUTH handshake, if we can.
Uninitialized status, we need to send KX.
#define LOG(level,...)
KX message received, trying to send back KX_AUTH.
#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:1230
enum CadetTunnelEState estate
State of the tunnel encryption.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
static struct GNUNET_CADET_ChannelTunnelNumber get_next_free_ctn(struct CadetTunnel *t)
Compute the next free channel tunnel number for this tunnel.
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 2283 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::channels, GNUNET_CADET_ChannelTunnelNumber::cn, CadetTunnel::destroy_task, 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, and LOG.

Referenced by channel_destroy().

2286 {
2288  "Removing %s from %s\n",
2289  GCCH_2s (ch),
2290  GCT_2s (t));
2293  ntohl (ctn.cn),
2294  ch));
2295  if ((0 ==
2296  GCT_count_channels (t)) &&
2297  (NULL == t->destroy_task))
2298  {
2299  t->destroy_task
2301  &destroy_tunnel,
2302  t);
2303  }
2304 }
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
uint32_t cn
Which number does this channel have that uniquely identfies it within its tunnel, in network byte ord...
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * destroy_task
Task scheduled if there are no more channels using the tunnel.
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
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:1253
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.
const char * GCCH_2s(const struct CadetChannel *ch)
Get the static string for identification of the channel.
unsigned int GCT_count_channels(struct CadetTunnel *t)
Count channels of a tunnel.
#define LOG(level,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
#define IDLE_DESTROY_DELAY
How long do we wait until tearing down an idle tunnel?
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 3024 of file gnunet-service-cadet_tunnels.c.

References GNUNET_CADET_ChannelTunnelNumber::cn, GNUNET_CADET_ChannelDestroyMessage::ctn, GCT_send(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, GNUNET_CADET_ChannelDestroyMessage::header, LOG, GNUNET_CADET_ChannelDestroyMessage::reserved, GNUNET_MessageHeader::size, 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().

3026 {
3028 
3030  "Sending DESTORY message for channel ID %u\n",
3031  ntohl (ctn.cn));
3032  msg.header.size = htons (sizeof(msg));
3034  msg.reserved = htonl (0);
3035  msg.ctn = ctn;
3036  GCT_send (t,
3037  &msg.header,
3038  NULL,
3039  NULL);
3040 }
uint32_t cn
Which number does this channel have that uniquely identfies it within its tunnel, in network byte ord...
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_CADET_ChannelTunnelNumber ctn
ID of the channel.
struct CadetTunnelQueueEntry * GCT_send(struct CadetTunnel *t, const struct GNUNET_MessageHeader *message, GCT_SendContinuation cont, void *cont_cls)
Sends an already built message on a tunnel, encrypting it and choosing the best connection if not pro...
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
Ask the cadet service to destroy a channel.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Message to destroy a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
#define LOG(level,...)
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 
)

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.
Returns
Handle to cancel message

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

References CadetTunnel::ax, GNUNET_CADET_TunnelEncryptedMessage::ax_header, CADET_TUNNEL_KEY_OK, CadetTunnelQueueEntry::cid, GNUNET_CADET_TunnelEncryptedMessage::cid, CadetTunnelQueueEntry::cont, CadetTunnelQueueEntry::cont_cls, CadetTunnelAxolotl::DHRs, GNUNET_CADET_AxHeader::DHRs, env, CadetTunnelQueueEntry::env, CadetTunnel::estate, 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(), CadetTunnelAxolotl::HKs, GNUNET_CADET_TunnelEncryptedMessage::hmac, LOG, CadetTunnelAxolotl::Ns, GNUNET_CADET_AxHeader::Ns, CadetTunnelAxolotl::PNs, GNUNET_CADET_AxHeader::PNs, CadetTunnel::send_task, GNUNET_MessageHeader::size, stats, t, CadetTunnelQueueEntry::t, t_ax_encrypt(), t_h_encrypt(), t_hmac(), CadetTunnel::tq_head, CadetTunnel::tq_tail, 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().

3464 {
3465  struct CadetTunnelQueueEntry *tq;
3466  uint16_t payload_size;
3467  struct GNUNET_MQ_Envelope *env;
3468  struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
3469 
3470  if (CADET_TUNNEL_KEY_OK != t->estate)
3471  {
3472  GNUNET_break (0);
3473  return NULL;
3474  }
3475  payload_size = ntohs (message->size);
3477  "Encrypting %u bytes for %s\n",
3478  (unsigned int) payload_size,
3479  GCT_2s (t));
3480  env = GNUNET_MQ_msg_extra (ax_msg,
3481  payload_size,
3483  t_ax_encrypt (&t->ax,
3484  &ax_msg[1],
3485  message,
3486  payload_size);
3488  "# encrypted bytes",
3489  payload_size,
3490  GNUNET_NO);
3491  ax_msg->ax_header.Ns = htonl (t->ax.Ns++);
3492  ax_msg->ax_header.PNs = htonl (t->ax.PNs);
3493  /* FIXME: we should do this once, not once per message;
3494  this is a point multiplication, and DHRs does not
3495  change all the time. */
3497  &ax_msg->ax_header.DHRs);
3498  t_h_encrypt (&t->ax,
3499  ax_msg);
3500  t_hmac (&ax_msg->ax_header,
3501  sizeof(struct GNUNET_CADET_AxHeader) + payload_size,
3502  0,
3503  &t->ax.HKs,
3504  &ax_msg->hmac);
3505 
3506  tq = GNUNET_malloc (sizeof(*tq));
3507  tq->t = t;
3508  tq->env = env;
3509  tq->cid = &ax_msg->cid; /* will initialize 'ax_msg->cid' once we know the connection */
3510  tq->cont = cont;
3511  tq->cont_cls = cont_cls;
3513  t->tq_tail,
3514  tq);
3515  if (NULL != t->send_task)
3517  t->send_task
3519  t);
3520  return tq;
3521 }
struct CadetTunnelAxolotl ax
Axolotl info.
Axolotl-encrypted tunnel message with application payload.
#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
Axolotl encrypted data.
uint32_t Ns
Number of messages sent with the current ratchet key.
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.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
uint32_t PNs
Previous message numbers (# of msgs sent under prev ratchet)
struct GNUNET_CRYPTO_EcdhePublicKey DHRs
Current ratchet key.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_CADET_AxHeader ax_header
Axolotl-header that specifies which keys to use in which ratchet to decrypt the body that follows...
Encrypted axolotl header with numbers that identify which keys in which ratchet are to be used to dec...
static struct GNUNET_SCHEDULER_Task * t
Main task.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CadetTunnelQueueEntry * tq_tail
Queued messages, to transmit once tunnel gets connected.
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...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
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:1280
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
uint32_t PNs
Number of messages sent with the previous ratchet 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:301
Struct used to save messages in a non-ready tunnel to send once connected.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct CadetTunnelQueueEntry * tq_head
Queued messages, to transmit once tunnel gets connected.
Handshake completed: session key available.
struct CadetTunnel * t
Tunnel these messages belong in.
void * cont_cls
Closure for cont.
struct GNUNET_ShortHashCode hmac
MAC of the encrypted message, used to verify message integrity.
struct GNUNET_MQ_Envelope * env
Envelope of message to send follows.
struct GNUNET_CRYPTO_EcdhePrivateKey DHRs
ECDH Ratchet key (our private key in the current DH).
struct GNUNET_CRYPTO_SymmetricSessionKey HKs
32-byte header key (currently used for sending).
static void t_h_encrypt(struct CadetTunnelAxolotl *ax, struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Encrypt header with the axolotl header key.
#define LOG(level,...)
struct GNUNET_SCHEDULER_Task * send_task
Task to send messages from queue (if possible).
static void t_ax_encrypt(struct CadetTunnelAxolotl *ax, void *dst, const void *src, size_t size)
Encrypt data with the axolotl tunnel key.
GCT_SendContinuation cont
Continuation to call once sent (on the channel layer).
enum CadetTunnelEState estate
State of the tunnel encryption.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint32_t Ns
Message number (reset to 0 with each new ratchet, next message to send).
struct GNUNET_CADET_ConnectionTunnelIdentifier * cid
Where to put the connection identifier into the payload of the message in env once we have it...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
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 3534 of file gnunet-service-cadet_tunnels.c.

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

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

3535 {
3536  struct CadetTunnel *t = tq->t;
3537 
3539  t->tq_tail,
3540  tq);
3541  GNUNET_MQ_discard (tq->env);
3542  GNUNET_free (tq);
3543 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_SCHEDULER_Task * t
Main task.
struct CadetTunnelQueueEntry * tq_tail
Queued messages, to transmit once tunnel gets connected.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
Struct containing all information regarding a tunnel to a peer.
struct CadetTunnelQueueEntry * tq_head
Queued messages, to transmit once tunnel gets connected.
struct CadetTunnel * t
Tunnel these messages belong in.
struct GNUNET_MQ_Envelope * env
Envelope of message to send follows.
#define GNUNET_free(ptr)
Wrapper around free.
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 594 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::channels, and GNUNET_CONTAINER_multihashmap32_size().

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

595 {
597 }
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
unsigned int GNUNET_CONTAINER_multihashmap32_size(const struct GNUNET_CONTAINER_MultiHashMap32 *map)
Get the number of key-value pairs in the map.
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 624 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::num_busy_connections, and CadetTunnel::num_ready_connections.

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

625 {
627 }
unsigned int num_ready_connections
Number of connections in the connection_ready_head DLL.
unsigned int num_busy_connections
Number of connections in the connection_busy_head DLL.
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 3554 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::connection_busy_head, CadetTunnel::connection_ready_head, and CadetTConnection::next.

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

3557 {
3558  struct CadetTConnection *n;
3559 
3560  for (struct CadetTConnection *ct = t->connection_ready_head;
3561  NULL != ct;
3562  ct = n)
3563  {
3564  n = ct->next;
3565  iter (iter_cls,
3566  ct);
3567  }
3568  for (struct CadetTConnection *ct = t->connection_busy_head;
3569  NULL != ct;
3570  ct = n)
3571  {
3572  n = ct->next;
3573  iter (iter_cls,
3574  ct);
3575  }
3576 }
struct CadetTConnection * connection_ready_head
DLL of ready connections that are actively used to reach the destination peer.
struct CadetTConnection * connection_busy_head
DLL of connections that we maintain that might be used to reach the destination peer.
Entry in list of connections used by tunnel, with metadata.
struct CadetTConnection * next
Next in DLL.
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 3626 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::channels, GNUNET_CONTAINER_multihashmap32_iterate(), ChanIterCls::iter, ChanIterCls::iter_cls, and iterate_channels_cb().

3629 {
3630  struct ChanIterCls ctx;
3631 
3632  ctx.iter = iter;
3633  ctx.iter_cls = iter_cls;
3636  &ctx);
3637 }
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
void * iter_cls
Closure for iter.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
GCT_ChannelIterator iter
Function to call.
Closure for iterate_channels_cb.
static int iterate_channels_cb(void *cls, uint32_t key, void *value)
Helper function for GCT_iterate_channels.
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 656 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::estate, and trigger_transmissions().

Referenced by get_all_tunnels_iterator(), and send_keepalive().

657 {
658  return t->estate;
659 }
enum CadetTunnelEState estate
State of the tunnel encryption.
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 1726 of file gnunet-service-cadet_tunnels.c.

References alice_or_betty(), CadetTunnel::ax, 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, CadetTunnel::destination, CadetTunnelAxolotl::DHRr, CadetTunnelAxolotl::DHRs, GNUNET_CADET_TunnelKeyExchangeMessage::ephemeral_key, CadetTunnel::estate, GCC_2s(), GCP_get_id(), GCT_2s(), GCT_change_estate(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, CadetTunnelAxolotl::kx_0, CadetTunnel::kx_task, CadetTunnelAxolotl::last_ephemeral, LOG, GNUNET_CADET_TunnelKeyExchangeMessage::ratchet_key, ret, retry_kx(), CadetTunnelAxolotl::RK, send_kx_auth(), CadetTunnelAxolotl::skipped_head, stats, t, CadetTConnection::t, CadetTunnel::unverified_attempts, CadetTunnel::unverified_ax, and update_ax_by_kx().

Referenced by GCC_handle_kx().

1728 {
1729  struct CadetTunnel *t = ct->t;
1730  int ret;
1731 
1733  "# KX received",
1734  1,
1735  GNUNET_NO);
1736  if (GNUNET_YES ==
1738  {
1739  /* Betty/Bob is not allowed to send KX! */
1740  GNUNET_break_op (0);
1741  return;
1742  }
1744  "Received KX message from %s with ephemeral %s from %s on connection %s\n",
1745  GCT_2s (t),
1746  GNUNET_e2s (&msg->ephemeral_key),
1748  GCC_2s (ct->cc));
1749 #if 1
1750  if ((0 ==
1751  memcmp (&t->ax.DHRr,
1752  &msg->ratchet_key,
1753  sizeof(msg->ratchet_key))) &&
1754  (0 ==
1755  memcmp (&t->ax.last_ephemeral,
1756  &msg->ephemeral_key,
1757  sizeof(msg->ephemeral_key))))
1758 
1759  {
1761  "# Duplicate KX received",
1762  1,
1763  GNUNET_NO);
1764  send_kx_auth (t,
1765  ct,
1766  &t->ax,
1767  GNUNET_NO);
1768  return;
1769  }
1770 #endif
1771  /* We only keep ONE unverified KX around, so if there is an existing one,
1772  clean it up. */
1773  if (NULL != t->unverified_ax)
1774  {
1775  if ((0 ==
1776  memcmp (&t->unverified_ax->DHRr,
1777  &msg->ratchet_key,
1778  sizeof(msg->ratchet_key))) &&
1779  (0 ==
1780  memcmp (&t->unverified_ax->last_ephemeral,
1781  &msg->ephemeral_key,
1782  sizeof(msg->ephemeral_key))))
1783  {
1785  "# Duplicate unverified KX received",
1786  1,
1787  GNUNET_NO);
1788 #if 1
1789  send_kx_auth (t,
1790  ct,
1791  t->unverified_ax,
1792  GNUNET_NO);
1793  return;
1794 #endif
1795  }
1797  "Dropping old unverified KX state.\n");
1799  "# Unverified KX dropped for fresh KX",
1800  1,
1801  GNUNET_NO);
1802  GNUNET_break (NULL == t->unverified_ax->skipped_head);
1803  memset (t->unverified_ax,
1804  0,
1805  sizeof(struct CadetTunnelAxolotl));
1806  }
1807  else
1808  {
1810  "Creating fresh unverified KX for %s\n",
1811  GCT_2s (t));
1813  "# Fresh KX setup",
1814  1,
1815  GNUNET_NO);
1817  }
1818  /* Set as the 'current' RK/DHRr the one we are currently using,
1819  so that the duplicate-detection logic of
1820  #update_ax_by_kx can work. */
1821  t->unverified_ax->RK = t->ax.RK;
1822  t->unverified_ax->DHRr = t->ax.DHRr;
1823  t->unverified_ax->DHRs = t->ax.DHRs;
1824  t->unverified_ax->kx_0 = t->ax.kx_0;
1825  t->unverified_attempts = 0;
1826 
1827  /* Update 'ax' by the new key material */
1828  ret = update_ax_by_kx (t->unverified_ax,
1829  GCP_get_id (t->destination),
1830  &msg->ephemeral_key,
1831  &msg->ratchet_key);
1832  GNUNET_break (GNUNET_SYSERR != ret);
1833  if (GNUNET_OK != ret)
1834  {
1836  "# Useless KX",
1837  1,
1838  GNUNET_NO);
1839  return; /* duplicate KX, nothing to do */
1840  }
1841  /* move ahead in our state machine */
1843  GCT_change_estate (t,
1845  else if (CADET_TUNNEL_KEY_AX_SENT == t->estate)
1846  GCT_change_estate (t,
1848 
1849  /* KX is still not done, try again our end. */
1850  if (CADET_TUNNEL_KEY_OK != t->estate)
1851  {
1852  if (NULL != t->kx_task)
1854  t->kx_task
1856  t);
1857  }
1858 }
struct CadetTunnelAxolotl ax
Axolotl info.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
static int alice_or_betty(const struct GNUNET_PeerIdentity *other)
Am I Alice or Betty (some call her Bob), or talking to myself?
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
KX message sent, waiting for other peer's KX_AUTH.
static struct GNUNET_SCHEDULER_Task * t
Main task.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SCHEDULER_Task * kx_task
Task to trigger KX.
struct CadetTunnel * t
Tunnel this connection belongs to.
struct CadetTunnelAxolotl * unverified_ax
Unverified Axolotl info, used only if we got a fresh KX (not a KX_AUTH) while our end of the tunnel w...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct GNUNET_CRYPTO_EcdhePublicKey last_ephemeral
Last ephemeral public key received from the other peer, for duplicate detection.
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:1280
unsigned int unverified_attempts
How often have we tried and failed to decrypt a message using the unverified KX material from unverif...
struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key
Sender's next ephemeral public ECC key encoded in a format suitable for network transmission, as created using 'gcry_sexp_sprint'.
struct CadetConnection * cc
Connection handle.
Struct containing all information regarding a tunnel to a peer.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Handshake completed: session key available.
void GCT_change_estate(struct CadetTunnel *t, enum CadetTunnelEState state)
Change the tunnel encryption state.
struct GNUNET_CRYPTO_SymmetricSessionKey RK
32-byte root key which gets updated by DH ratchet.
struct GNUNET_CRYPTO_EcdhePublicKey DHRr
ECDH Ratchet key (other peer's public key in the current DH).
KX message sent and received, trying to send back KX_AUTH.
struct CadetPeer * destination
Destination of the tunnel.
struct GNUNET_CRYPTO_EcdhePrivateKey DHRs
ECDH Ratchet key (our private key in the current DH).
Axolotl data, according to https://github.com/trevp/axolotl/wiki .
struct CadetTunnelSkippedKey * skipped_head
A (double linked) list of stored message keys and associated header keys for "skipped" messages...
static void send_kx_auth(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
Send a KX_AUTH message.
static void retry_kx(void *cls)
Try to redo the KX or KX_AUTH handshake, if we can.
Uninitialized status, we need to send KX.
#define LOG(level,...)
KX message received, trying to send back KX_AUTH.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key
Sender's ephemeral public ECC key encoded in a format suitable for network transmission, as created using 'gcry_sexp_sprint'.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
enum CadetTunnelEState estate
State of the tunnel encryption.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
struct GNUNET_CRYPTO_EcdhePrivateKey kx_0
ECDH for key exchange (A0 / B0).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
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 1936 of file gnunet-service-cadet_tunnels.c.

References GNUNET_CADET_TunnelKeyExchangeAuthMessage::auth, CadetTunnel::ax, 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(), CadetTunnel::destination, GNUNET_CADET_TunnelKeyExchangeMessage::ephemeral_key, CadetTunnel::estate, GNUNET_CADET_TunnelKeyExchangeMessage::flags, 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(), GNUNET_CADET_TunnelKeyExchangeAuthMessage::kx, CadetTunnelAxolotl::kx_0, CadetTunnel::kx_task, LOG, my_private_key, CadetTunnel::next_kx_attempt, GNUNET_CADET_TunnelKeyExchangeMessage::ratchet_key, ret, retry_kx(), CadetTunnelAxolotl::RK, send_kx_auth(), stats, t, CadetTConnection::t, CadetTunnel::unverified_ax, and update_ax_by_kx().

Referenced by GCC_handle_kx_auth().

1938 {
1939  struct CadetTunnel *t = ct->t;
1940  struct CadetTunnelAxolotl ax_tmp;
1941  struct GNUNET_HashCode kx_auth;
1942  int ret;
1943 
1945  "# KX_AUTH received",
1946  1,
1947  GNUNET_NO);
1948  if ((CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) ||
1950  {
1951  /* Confusing, we got a KX_AUTH before we even send our own
1952  KX. This should not happen. We'll send our own KX ASAP anyway,
1953  so let's ignore this here. */
1954  GNUNET_break_op (0);
1955  return;
1956  }
1958  "Handling KX_AUTH message from %s with ephemeral %s\n",
1959  GCT_2s (t),
1960  GNUNET_e2s (&msg->kx.ephemeral_key));
1961  /* We do everything in ax_tmp until we've checked the authentication
1962  so we don't clobber anything we care about by accident. */
1963  ax_tmp = t->ax;
1964 
1965  /* Update 'ax' by the new key material */
1966  ret = update_ax_by_kx (&ax_tmp,
1967  GCP_get_id (t->destination),
1968  &msg->kx.ephemeral_key,
1969  &msg->kx.ratchet_key);
1970  if (GNUNET_OK != ret)
1971  {
1972  if (GNUNET_NO == ret)
1974  "# redundant KX_AUTH received",
1975  1,
1976  GNUNET_NO);
1977  else
1978  GNUNET_break (0); /* connect to self!? */
1979  return;
1980  }
1981  GNUNET_CRYPTO_hash (&ax_tmp.RK,
1982  sizeof(ax_tmp.RK),
1983  &kx_auth);
1984  if (0 != GNUNET_memcmp (&kx_auth,
1985  &msg->auth))
1986  {
1987  /* This KX_AUTH is not using the latest KX/KX_AUTH data
1988  we transmitted to the sender, refuse it, try KX again. */
1990  "# KX_AUTH not using our last KX received (auth failure)",
1991  1,
1992  GNUNET_NO);
1994  "KX AUTH mismatch!\n");
1995 #if DEBUG_KX
1996  {
1997  struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
1998 
1999  GNUNET_CRYPTO_ecdhe_key_get_public (&ax_tmp.kx_0,
2000  &ephemeral_key);
2001  if (0 != GNUNET_memcmp (&ephemeral_key,
2002  &msg->r_ephemeral_key_XXX))
2003  {
2005  "My ephemeral is %s!\n",
2006  GNUNET_e2s (&ephemeral_key));
2008  "Response is for ephemeral %s!\n",
2009  GNUNET_e2s (&msg->r_ephemeral_key_XXX));
2010  }
2011  else
2012  {
2013  test_crypto_bug (&ax_tmp.kx_0,
2014  &msg->kx.ephemeral_key_XXX,
2016  &msg->kx.private_key_XXX);
2017  }
2018  }
2019 #endif
2020  if (NULL == t->kx_task)
2021  t->kx_task
2023  &retry_kx,
2024  t);
2025  return;
2026  }
2027  /* Yep, we're good. */
2028  t->ax = ax_tmp;
2029  if (NULL != t->unverified_ax)
2030  {
2031  /* We got some "stale" KX before, drop that. */
2034  t->unverified_ax = NULL;
2035  }
2036 
2037  /* move ahead in our state machine */
2038  switch (t->estate)
2039  {
2042  /* Checked above, this is impossible. */
2043  GNUNET_assert (0);
2044  break;
2045 
2046  case CADET_TUNNEL_KEY_AX_SENT: /* This is the normal case */
2047  case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: /* both peers started KX */
2048  case CADET_TUNNEL_KEY_AX_AUTH_SENT: /* both peers now did KX_AUTH */
2049  GCT_change_estate (t,
2051  break;
2052 
2053  case CADET_TUNNEL_KEY_OK:
2054  /* Did not expect another KX_AUTH, but so what, still acceptable.
2055  Nothing to do here. */
2056  break;
2057  }
2058  if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl (msg->kx.flags)))
2059  {
2060  send_kx_auth (t,
2061  NULL,
2062  &t->ax,
2063  GNUNET_NO);
2064  }
2065 }
struct CadetTunnelAxolotl ax
Axolotl info.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
struct GNUNET_CADET_TunnelKeyExchangeMessage kx
Message header with key material.
uint32_t flags
Flags for the key exchange in NBO, based on enum GNUNET_CADET_KX_Flags.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
KX received and we sent KX_AUTH back, but we got no traffic yet, so we're waiting for either KX_AUTH ...
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
KX message sent, waiting for other peer's KX_AUTH.
static struct GNUNET_SCHEDULER_Task * t
Main task.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SCHEDULER_Task * kx_task
Task to trigger KX.
struct CadetTunnel * t
Tunnel this connection belongs to.
struct CadetTunnelAxolotl * unverified_ax
Unverified Axolotl info, used only if we got a fresh KX (not a KX_AUTH) while our end of the tunnel w...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
A 512-bit hashcode.
struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key
Sender's next ephemeral public ECC key encoded in a format suitable for network transmission, as created using 'gcry_sexp_sprint'.
Struct containing all information regarding a tunnel to a peer.
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:301
struct GNUNET_TIME_Absolute next_kx_attempt
When do we try the next KX?
Handshake completed: session key available.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Own private key.
void GCT_change_estate(struct CadetTunnel *t, enum CadetTunnelEState state)
Change the tunnel encryption state.
KX message sent and received, trying to send back KX_AUTH.
struct CadetPeer * destination
Destination of the tunnel.
The peer should reply with its KX details?
Axolotl data, according to https://github.com/trevp/axolotl/wiki .
struct GNUNET_HashCode auth
KDF-proof that sender could compute the 3-DH, used in lieu of a signature or payload data...
static void send_kx_auth(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
Send a KX_AUTH message.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
static void retry_kx(void *cls)
Try to redo the KX or KX_AUTH handshake, if we can.
static void cleanup_ax(struct CadetTunnelAxolotl *ax)
Cleanup state used by ax.
Uninitialized status, we need to send KX.
#define LOG(level,...)
KX message received, trying to send back KX_AUTH.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key
Sender's ephemeral public ECC key encoded in a format suitable for network transmission, as created using 'gcry_sexp_sprint'.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
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:1230
enum CadetTunnelEState estate
State of the tunnel encryption.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
Here is the call graph for this function:
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 3275 of file gnunet-service-cadet_tunnels.c.

References CadetTunnel::ax, 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(), CadetTunnel::current_ct, CadetTunnel::estate, 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, GNUNET_CADET_TunnelEncryptedMessage::header, CadetTunnel::kx_task, LOG, MAX_UNVERIFIED_ATTEMPTS, CadetTunnel::mst, send_kx(), send_kx_auth(), CadetTunnel::send_task, size, GNUNET_MessageHeader::size, stats, CadetTConnection::t, t_ax_decrypt_and_validate(), trigger_transmissions(), CadetTunnel::unverified_attempts, and CadetTunnel::unverified_ax.

Referenced by GCC_handle_encrypted().

3277 {
3278  struct CadetTunnel *t = ct->t;
3279  uint16_t size = ntohs (msg->header.size);
3280  char cbuf [size] GNUNET_ALIGN;
3281  ssize_t decrypted_size;
3282 
3284  "%s received %u bytes of encrypted data in state %d\n",
3285  GCT_2s (t),
3286  (unsigned int) size,
3287  t->estate);
3288 
3289  switch (t->estate)
3290  {
3293  /* We did not even SEND our KX, how can the other peer
3294  send us encrypted data? Must have been that we went
3295  down and the other peer still things we are up.
3296  Let's send it KX back. */
3298  "# received encrypted without any KX",
3299  1,
3300  GNUNET_NO);
3301  if (NULL != t->kx_task)
3302  {
3304  t->kx_task = NULL;
3305  }
3306  send_kx (t,
3307  ct,
3308  &t->ax);
3309  return;
3310 
3312  /* We send KX, and other peer send KX to us at the same time.
3313  Neither KX is AUTH'ed, so let's try KX_AUTH this time. */
3315  "# received encrypted without KX_AUTH",
3316  1,
3317  GNUNET_NO);
3318  if (NULL != t->kx_task)
3319  {
3321  t->kx_task = NULL;
3322  }
3323  send_kx_auth (t,
3324  ct,
3325  &t->ax,
3326  GNUNET_YES);
3327  return;
3328 
3330  /* We did not get the KX of the other peer, but that
3331  might have been lost. Send our KX again immediately. */
3333  "# received encrypted without KX",
3334  1,
3335  GNUNET_NO);
3336  if (NULL != t->kx_task)
3337  {
3339  t->kx_task = NULL;
3340  }
3341  send_kx (t,
3342  ct,
3343  &t->ax);
3344  return;
3345 
3347  /* Great, first payload, we might graduate to OK! */
3348  case CADET_TUNNEL_KEY_OK:
3349  /* We are up and running, all good. */
3350  break;
3351  }
3352 
3353  decrypted_size = -1;
3354  if (CADET_TUNNEL_KEY_OK == t->estate)
3355  {
3356  /* We have well-established key material available,
3357  try that. (This is the common case.) */
3358  decrypted_size = t_ax_decrypt_and_validate (&t->ax,
3359  cbuf,
3360  msg,
3361  size);
3362  }
3363 
3364  if ((-1 == decrypted_size) &&
3365  (NULL != t->unverified_ax))
3366  {
3367  /* We have un-authenticated KX material available. We should try
3368  this as a back-up option, in case the sender crashed and
3369  switched keys. */
3370  decrypted_size = t_ax_decrypt_and_validate (t->unverified_ax,
3371  cbuf,
3372  msg,
3373  size);
3374  if (-1 != decrypted_size)
3375  {
3376  /* It worked! Treat this as authentication of the AX data! */
3377  cleanup_ax (&t->ax);
3378  t->ax = *t->unverified_ax;
3380  t->unverified_ax = NULL;
3381  }
3383  {
3384  /* First time it worked, move tunnel into production! */
3385  GCT_change_estate (t,
3387  if (NULL != t->send_task)
3390  t);
3391  }
3392  }
3393  if (NULL != t->unverified_ax)
3394  {
3395  /* We had unverified KX material that was useless; so increment
3396  counter and eventually move to ignore it. Note that we even do
3397  this increment if we successfully decrypted with the old KX
3398  material and thus didn't even both with the new one. This is
3399  the ideal case, as a malicious injection of bogus KX data
3400  basically only causes us to increment a counter a few times. */t->unverified_attempts++;
3402  "Failed to decrypt message with unverified KX data %u times\n",
3403  t->unverified_attempts);
3405  {
3408  t->unverified_ax = NULL;
3409  }
3410  }
3411 
3412  if (-1 == decrypted_size)
3413  {
3414  /* Decryption failed for good, complain. */
3416  "%s failed to decrypt and validate encrypted data, retrying KX\n",
3417  GCT_2s (t));
3419  "# unable to decrypt",
3420  1,
3421  GNUNET_NO);
3422  if (NULL != t->kx_task)
3423  {
3425  t->kx_task = NULL;
3426  }
3427  send_kx (t,
3428  ct,
3429  &t->ax);
3430  return;
3431  }
3433  "# decrypted bytes",
3434  decrypted_size,
3435  GNUNET_NO);
3436 
3437  /* The MST will ultimately call #handle_decrypted() on each message. */
3438  t->current_ct = ct;
3441  cbuf,
3442  decrypted_size,
3443  GNUNET_YES,
3444  GNUNET_NO));
3445  t->current_ct = NULL;
3446 }
struct CadetTunnelAxolotl ax
Axolotl info.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
KX received and we sent KX_AUTH back, but we got no traffic yet, so we're waiting for either KX_AUTH ...
static void send_kx(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax)
Send a KX message.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
KX message sent, waiting for other peer's KX_AUTH.
static struct GNUNET_SCHEDULER_Task * t
Main task.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_SCHEDULER_Task * kx_task
Task to trigger KX.
struct CadetTunnel * t
Tunnel this connection belongs to.
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 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...
struct CadetTunnelAxolotl * unverified_ax
Unverified Axolotl info, used only if we got a fresh KX (not a KX_AUTH) while our end of the tunnel w...
struct CadetTConnection * current_ct
Identification of the connection from which we are currently processing a message.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
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:1280
unsigned int unverified_attempts
How often have we tried and failed to decrypt a message using the unverified KX material from unverif...
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for decrypted messages.
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
Struct containing all information regarding a tunnel to a peer.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handshake completed: session key available.
void GCT_change_estate(struct CadetTunnel *t, enum CadetTunnelEState state)
Change the tunnel encryption state.
KX message sent and received, trying to send back KX_AUTH.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's...
#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_auth(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
Send a KX_AUTH message.
static void cleanup_ax(struct CadetTunnelAxolotl *ax)
Cleanup state used by ax.
Uninitialized status, we need to send KX.
#define LOG(level,...)
KX message received, trying to send back KX_AUTH.
struct GNUNET_SCHEDULER_Task * send_task
Task to send messages from queue (if possible).
#define GNUNET_YES
Definition: gnunet_common.h:77
enum CadetTunnelEState estate
State of the tunnel encryption.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
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 3672 of file gnunet-service-cadet_tunnels.c.

References CadetTConnection::cc, CadetTunnel::channels, CadetTunnel::connection_busy_head, CadetTunnel::connection_ready_head, debug_channel(), CadetTunnel::estate, 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 CadetTunnel::tq_len.

3674 {
3675 #if ! defined(GNUNET_CULL_LOGGING)
3676  struct CadetTConnection *iter_c;
3677  int do_log;
3678 
3680  "cadet-tun",
3681  __FILE__, __FUNCTION__, __LINE__);
3682  if (0 == do_log)
3683  return;
3684 
3685  LOG2 (level,
3686  "TTT TUNNEL TOWARDS %s in estate %s tq_len: %u #cons: %u\n",
3687  GCT_2s (t),
3688  estate2s (t->estate),
3689  t->tq_len,
3691  LOG2 (level,
3692  "TTT channels:\n");
3694  &debug_channel,
3695  &level);
3696  LOG2 (level,
3697  "TTT connections:\n");
3698  for (iter_c = t->connection_ready_head; NULL != iter_c; iter_c = iter_c->next)
3699  GCC_debug (iter_c->cc,
3700  level);
3701  for (iter_c = t->connection_busy_head; NULL != iter_c; iter_c = iter_c->next)
3702  GCC_debug (iter_c->cc,
3703  level);
3704 
3705  LOG2 (level,
3706  "TTT TUNNEL END\n");
3707 #endif
3708 }
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels inside this tunnel.
static const char * estate2s(enum CadetTunnelEState es)
Get string description for tunnel encryption state.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
unsigned int GCT_count_any_connections(const struct CadetTunnel *t)
Count all created connections of a tunnel.
struct CadetTConnection * connection_ready_head
DLL of ready connections that are actively used to reach the destination peer.
void GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level)
Log connection info.
struct CadetTConnection * connection_busy_head
DLL of connections that we maintain that might be used to reach the destination peer.
struct CadetConnection * cc
Connection handle.
#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.
Entry in list of connections used by tunnel, with metadata.
static int debug_channel(void *cls, uint32_t key, void *value)
Call GCCH_debug() on a channel.
struct CadetTConnection * next
Next in DLL.
unsigned int tq_len
Number of entries in the tq_head DLL.
enum CadetTunnelEState estate
State of the tunnel encryption.
Here is the call graph for this function: