GNUnet  0.11.x
Data Structures | Macros | Functions
gnunet-service-cadet_tunnels.c File Reference

Information we track per tunnel. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_signatures.h"
#include "cadet_protocol.h"
#include "gnunet-service-cadet_channel.h"
#include "gnunet-service-cadet_connection.h"
#include "gnunet-service-cadet_tunnels.h"
#include "gnunet-service-cadet_peer.h"
#include "gnunet-service-cadet_paths.h"
Include dependency graph for gnunet-service-cadet_tunnels.c:

Go to the source code of this file.

Data Structures

struct  CadetTunnelSkippedKey
 Struct to old keys for skipped messages while advancing the Axolotl ratchet. More...
 
struct  CadetTunnelAxolotl
 Axolotl data, according to https://github.com/trevp/axolotl/wiki . More...
 
struct  CadetTunnelQueueEntry
 Struct used to save messages in a non-ready tunnel to send once connected. More...
 
struct  CadetTunnel
 Struct containing all information regarding a tunnel to a peer. More...
 
struct  EvaluationSummary
 Closure for evaluate_connection. More...
 
struct  ChanIterCls
 Closure for iterate_channels_cb. More...
 

Macros

#define LOG(level, ...)   GNUNET_log_from (level, "cadet-tun", __VA_ARGS__)
 
#define MAX_UNVERIFIED_ATTEMPTS   16
 How often do we try to decrypt payload with unverified key material? Used to limit CPU increase upon receiving bogus KX. More...
 
#define IDLE_DESTROY_DELAY
 How long do we wait until tearing down an idle tunnel? More...
 
#define INITIAL_KX_RETRY_DELAY
 How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have connection-level RTT data! More...
 
#define MAX_SKIPPED_KEYS   64
 Maximum number of skipped keys we keep in memory per tunnel. More...
 
#define MAX_KEY_GAP   256
 Maximum number of keys (and thus ratchet steps) we are willing to skip before we decide this is either a bogus packet or a DoS-attempt. More...
 
#define HIGH_BIT   0x8000000
 
#define LOG2(level, ...)
 

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...
 
static void mark_connection_unready (struct CadetTConnection *ct)
 Connection ct is now unready, clear it's ready flag and move it from the ready DLL to the busy DLL. More...
 
const char * GCT_2s (const struct CadetTunnel *t)
 Get the static string for the peer this tunnel is directed. More...
 
static const char * estate2s (enum CadetTunnelEState es)
 Get string description for tunnel encryption state. More...
 
struct CadetPeerGCT_get_destination (struct CadetTunnel *t)
 Return the peer to which this tunnel goes. More...
 
unsigned int GCT_count_channels (struct CadetTunnel *t)
 Count channels of a tunnel. More...
 
struct CadetChannellookup_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
 Lookup a channel by its ctn. More...
 
unsigned int GCT_count_any_connections (const struct CadetTunnel *t)
 Count all created connections of a tunnel. More...
 
static struct CadetTConnectionget_ready_connection (struct CadetTunnel *t)
 Find first connection that is ready in the list of our connections. More...
 
enum CadetTunnelEState GCT_get_estate (struct CadetTunnel *t)
 Get the encryption state of a tunnel. More...
 
static void trigger_transmissions (void *cls)
 Called when either we have a new connection, or a new message in the queue, or some existing connection has transmission capacity. More...
 
static void new_ephemeral (struct CadetTunnelAxolotl *ax)
 Create a new Axolotl ephemeral (ratchet) key. More...
 
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. More...
 
static void t_ax_hmac_hash (const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hash, const void *source, unsigned int len)
 Perform a HMAC. More...
 
static void t_hmac_derive_key (const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *out, const void *source, unsigned int len)
 Derive a symmetric encryption key from an HMAC-HASH. More...
 
static void t_ax_encrypt (struct CadetTunnelAxolotl *ax, void *dst, const void *src, size_t size)
 Encrypt data with the axolotl tunnel key. More...
 
static void t_ax_decrypt (struct CadetTunnelAxolotl *ax, void *dst, const void *src, size_t size)
 Decrypt data with the axolotl tunnel key. More...
 
static void t_h_encrypt (struct CadetTunnelAxolotl *ax, struct GNUNET_CADET_TunnelEncryptedMessage *msg)
 Encrypt header with the axolotl header key. More...
 
static void t_h_decrypt (struct CadetTunnelAxolotl *ax, const struct GNUNET_CADET_TunnelEncryptedMessage *src, struct GNUNET_CADET_TunnelEncryptedMessage *dst)
 Decrypt header with the current axolotl header key. More...
 
static void delete_skipped_key (struct CadetTunnelAxolotl *ax, struct CadetTunnelSkippedKey *key)
 Delete a key from the list of skipped keys. More...
 
static ssize_t try_old_ax_keys (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 since it was sent by the remote peer. More...
 
static void store_skipped_key (struct CadetTunnelAxolotl *ax, const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr)
 Delete a key from the list of skipped keys. More...
 
static int store_ax_keys (struct CadetTunnelAxolotl *ax, const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr, uint32_t Np)
 Stage skipped AX keys and calculate the message key. More...
 
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 since it was sent by the remote peer. More...
 
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. More...
 
void GCT_change_estate (struct CadetTunnel *t, enum CadetTunnelEState state)
 Change the tunnel encryption state. More...
 
static void send_kx (struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax)
 Send a KX message. More...
 
static void send_kx_auth (struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
 Send a KX_AUTH message. More...
 
static void cleanup_ax (struct CadetTunnelAxolotl *ax)
 Cleanup state used by ax. More...
 
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. More...
 
static void retry_kx (void *cls)
 Try to redo the KX or KX_AUTH handshake, if we can. More...
 
void GCT_handle_kx (struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
 Handle KX message that lacks authentication (and which will thus only be considered authenticated after we respond with our own KX_AUTH and finally successfully decrypt payload). More...
 
void GCT_handle_kx_auth (struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
 Handle KX_AUTH message. More...
 
static struct GNUNET_CADET_ChannelTunnelNumber get_next_free_ctn (struct CadetTunnel *t)
 Compute the next free channel tunnel number for this tunnel. More...
 
struct GNUNET_CADET_ChannelTunnelNumber GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch)
 Add a channel to a tunnel, and notify channel that we are ready for transmission if we are already up. 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...
 
static void destroy_t_connection (void *cls, struct CadetTConnection *ct)
 Clean up connection ct of a tunnel. More...
 
static void destroy_tunnel (void *cls)
 This tunnel is no longer used, destroy it. More...
 
void GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch, struct GNUNET_CADET_ChannelTunnelNumber ctn)
 Remove a channel from a tunnel. More...
 
static int destroy_remaining_channels (void *cls, uint32_t key, void *value)
 Destroy remaining channels during shutdown. More...
 
void GCT_destroy_tunnel_now (struct CadetTunnel *t)
 Destroys the tunnel t now, without delay. More...
 
static void try_send_normal_payload (struct CadetTunnel *t, struct CadetTConnection *ct)
 Send normal payload from queue in t via connection ct. More...
 
static void connection_ready_cb (void *cls, int is_ready)
 A connection is is_ready for transmission. More...
 
static void evaluate_connection (void *cls, struct CadetTConnection *ct)
 Evaluate a connection, updating our summary information in cls about what kinds of connections we have. More...
 
static int consider_path_cb (void *cls, struct CadetPeerPath *path, unsigned int off)
 Consider using the path p for the tunnel t. More...
 
static void maintain_connections_cb (void *cls)
 Function called to maintain the connections underlying our tunnel. More...
 
void GCT_consider_path (struct CadetTunnel *t, struct CadetPeerPath *p, unsigned int off)
 Consider using the path p for the tunnel t. More...
 
static void handle_plaintext_keepalive (void *cls, const struct GNUNET_MessageHeader *msg)
 We got a keepalive. More...
 
static int check_plaintext_data (void *cls, const struct GNUNET_CADET_ChannelAppDataMessage *msg)
 Check that msg is well-formed. More...
 
static void handle_plaintext_data (void *cls, const struct GNUNET_CADET_ChannelAppDataMessage *msg)
 We received payload data for a channel. More...
 
static void handle_plaintext_data_ack (void *cls, const struct GNUNET_CADET_ChannelDataAckMessage *ack)
 We received an acknowledgement for data we sent on a channel. More...
 
static void handle_plaintext_channel_open (void *cls, const struct GNUNET_CADET_ChannelOpenMessage *copen)
 We have received a request to open a channel to a port from another peer. More...
 
void GCT_send_channel_destroy (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
 Send a DESTROY message via the tunnel. More...
 
static void handle_plaintext_channel_open_ack (void *cls, const struct GNUNET_CADET_ChannelOpenAckMessage *cm)
 We have received confirmation from the target peer that the given channel could be established (the port is open). More...
 
static void handle_plaintext_channel_destroy (void *cls, const struct GNUNET_CADET_ChannelDestroyMessage *cm)
 We received a message saying that a channel should be destroyed. More...
 
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). More...
 
static void decrypted_error_cb (void *cls, enum GNUNET_MQ_Error error)
 Function called if we had an error processing an incoming decrypted message. More...
 
struct CadetTunnelGCT_create_tunnel (struct CadetPeer *destination)
 Create a tunnel to destination. 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_handle_encrypted (struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
 Handle encrypted message. 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 *tq)
 Cancel a previously sent message while it's in the queue. More...
 
void GCT_iterate_connections (struct CadetTunnel *t, GCT_ConnectionIterator iter, void *iter_cls)
 Iterate over all connections of a tunnel. More...
 
static int iterate_channels_cb (void *cls, uint32_t key, void *value)
 Helper function for GCT_iterate_channels. More...
 
void GCT_iterate_channels (struct CadetTunnel *t, GCT_ChannelIterator iter, void *iter_cls)
 Iterate over all channels of a tunnel. More...
 
static int debug_channel (void *cls, uint32_t key, void *value)
 Call GCCH_debug() on a channel. 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

FIXME:

Definition in file gnunet-service-cadet_tunnels.c.

Macro Definition Documentation

◆ LOG

#define LOG (   level,
  ... 
)    GNUNET_log_from (level, "cadet-tun", __VA_ARGS__)

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

◆ MAX_UNVERIFIED_ATTEMPTS

#define MAX_UNVERIFIED_ATTEMPTS   16

How often do we try to decrypt payload with unverified key material? Used to limit CPU increase upon receiving bogus KX.

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

◆ IDLE_DESTROY_DELAY

#define IDLE_DESTROY_DELAY
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311

How long do we wait until tearing down an idle tunnel?

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

◆ INITIAL_KX_RETRY_DELAY

#define INITIAL_KX_RETRY_DELAY
Value:
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.

How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have connection-level RTT data!

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

◆ MAX_SKIPPED_KEYS

#define MAX_SKIPPED_KEYS   64

Maximum number of skipped keys we keep in memory per tunnel.

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

◆ MAX_KEY_GAP

#define MAX_KEY_GAP   256

Maximum number of keys (and thus ratchet steps) we are willing to skip before we decide this is either a bogus packet or a DoS-attempt.

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

◆ HIGH_BIT

#define HIGH_BIT   0x8000000

◆ LOG2

#define LOG2 (   level,
  ... 
)
Value:
GNUNET_log_from_nocheck (level, "cadet-tun", \
__VA_ARGS__)
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.

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

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:

◆ mark_connection_unready()

static void mark_connection_unready ( struct CadetTConnection ct)
static

Connection ct is now unready, clear it's ready flag and move it from the ready DLL to the busy DLL.

Parameters
ctconnection to move to unready status

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

492 {
493  struct CadetTunnel *t = ct->t;
494 
496  GNUNET_CONTAINER_DLL_remove (t->connection_ready_head,
497  t->connection_ready_tail,
498  ct);
499  GNUNET_assert (0 < t->num_ready_connections);
500  t->num_ready_connections--;
501  ct->is_ready = GNUNET_NO;
502  GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
503  t->connection_busy_tail,
504  ct);
505  t->num_busy_connections++;
506 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int is_ready
Is the connection currently ready for transmission?
struct CadetTunnel * t
Tunnel this connection belongs to.
Struct containing all information regarding a tunnel to a peer.

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_NO, GNUNET_YES, CadetTConnection::is_ready, CadetTConnection::t, and t.

Referenced by connection_ready_cb(), send_kx(), send_kx_auth(), and try_send_normal_payload().

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]
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:

◆ estate2s()

static const char* estate2s ( enum CadetTunnelEState  es)
static

Get string description for tunnel encryption state.

Parameters
esTunnel state.
Returns
String representation.

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

540 {
541  static char buf[32];
542 
543  switch (es)
544  {
546  return "CADET_TUNNEL_KEY_UNINITIALIZED";
548  return "CADET_TUNNEL_KEY_AX_RECV";
550  return "CADET_TUNNEL_KEY_AX_SENT";
552  return "CADET_TUNNEL_KEY_AX_SENT_AND_RECV";
554  return "CADET_TUNNEL_KEY_AX_AUTH_SENT";
555  case CADET_TUNNEL_KEY_OK:
556  return "CADET_TUNNEL_KEY_OK";
557  }
559  sizeof(buf),
560  "%u (UNKNOWN STATE)",
561  es);
562  return buf;
563 }
@ 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.

References buf, 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, and GNUNET_snprintf().

Referenced by connection_ready_cb(), GCT_change_estate(), GCT_debug(), retry_kx(), and send_kx().

Here is the call graph for this function:
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_count_channels()

unsigned int GCT_count_channels ( struct CadetTunnel t)

Count channels of a 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:

◆ lookup_channel()

struct CadetChannel* lookup_channel ( struct CadetTunnel t,
struct GNUNET_CADET_ChannelTunnelNumber  ctn 
)

Lookup a channel by its ctn.

Parameters
ttunnel to look in
ctnnumber of channel to find
Returns
NULL if channel does not exist

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

603 {
604  return GNUNET_CONTAINER_multihashmap32_get (t->channels,
605  ntohl (ctn.cn));
606 }
void * GNUNET_CONTAINER_multihashmap32_get(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Given a key find a value in the map matching the key.
uint32_t cn
Which number does this channel have that uniquely identfies it within its tunnel, in network byte ord...

References GNUNET_CADET_ChannelTunnelNumber::cn, CadetChannel::ctn, GNUNET_CONTAINER_multihashmap32_get(), and t.

Referenced by GCT_send(), handle_plaintext_channel_destroy(), 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_count_any_connections()

unsigned int GCT_count_any_connections ( const struct CadetTunnel t)

Count all created connections of a 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:

◆ get_ready_connection()

static struct CadetTConnection* get_ready_connection ( struct CadetTunnel t)
static

Find first connection that is ready in the list of our connections.

Picks ready connections round-robin.

Parameters
ttunnel to search
Returns
NULL if we have no connection that is ready

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

632 {
633  struct CadetTConnection *hd = t->connection_ready_head;
634 
635  GNUNET_assert ((NULL == hd) ||
636  (GNUNET_YES == hd->is_ready));
637  return hd;
638 }
Entry in list of connections used by tunnel, with metadata.

Referenced by send_kx(), send_kx_auth(), and trigger_transmissions().

Here is the caller 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:

◆ trigger_transmissions()

static void trigger_transmissions ( void *  cls)
static

Called when either we have a new connection, or a new message in the queue, or some existing connection has transmission capacity.

Looks at our message queue and if there is a message, picks a connection to send it on.

Parameters
clsthe struct CadetTunnel to process messages on

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

2514 {
2515  struct CadetTunnel *t = cls;
2516  struct CadetTConnection *ct;
2517 
2518  t->send_task = NULL;
2519  if (NULL == t->tq_head)
2520  return; /* no messages pending right now */
2521  ct = get_ready_connection (t);
2522  if (NULL == ct)
2523  return; /* no connections ready */
2525  ct);
2526 }
static void try_send_normal_payload(struct CadetTunnel *t, struct CadetTConnection *ct)
Send normal payload from queue in t via connection ct.
static struct CadetTConnection * get_ready_connection(struct CadetTunnel *t)
Find first connection that is ready in the list of our connections.

References get_ready_connection(), t, and try_send_normal_payload().

Referenced by GCT_change_estate(), GCT_handle_encrypted(), and GCT_send().

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

◆ new_ephemeral()

static void new_ephemeral ( struct CadetTunnelAxolotl ax)
static

Create a new Axolotl ephemeral (ratchet) key.

Parameters
axkey material to update

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

677 {
679  "Creating new ephemeral ratchet key (DHRs)\n");
681 }
#define LOG(level,...)
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:435
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_CRYPTO_EcdhePrivateKey DHRs
ECDH Ratchet key (our private key in the current DH).

References CadetTunnelAxolotl::DHRs, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by GCT_create_tunnel(), and t_ax_encrypt().

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

◆ t_hmac()

static void t_hmac ( const void *  plaintext,
size_t  size,
uint32_t  iv,
const struct GNUNET_CRYPTO_SymmetricSessionKey key,
struct GNUNET_ShortHashCode hmac 
)
static

Calculate HMAC.

Parameters
plaintextContent to HMAC.
sizeSize of plaintext.
ivInitialization vector for the message.
keyKey to use.
hmac[out]Destination to store the HMAC.

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

699 {
700  static const char ctx[] = "cadet authentication key";
701  struct GNUNET_CRYPTO_AuthKey auth_key;
702  struct GNUNET_HashCode hash;
703 
705  key,
706  &iv, sizeof(iv),
707  key, sizeof(*key),
708  ctx, sizeof(ctx),
709  NULL);
710  /* Two step: GNUNET_ShortHash is only 256 bits,
711  GNUNET_HashCode is 512, so we truncate. */
712  GNUNET_CRYPTO_hmac (&auth_key,
713  plaintext,
714  size,
715  &hash);
716  GNUNET_memcpy (hmac,
717  &hash,
718  sizeof(*hmac));
719 }
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
Definition: crypto_hash.c:301
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
Definition: crypto_hash.c:246
static unsigned int size
Size of the "table".
Definition: peer.c:67
type for (message) authentication keys
A 512-bit hashcode.

References ctx, GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_hmac_derive_key(), GNUNET_memcpy, key, and size.

Referenced by GCT_send(), t_ax_decrypt_and_validate(), and try_old_ax_keys().

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

◆ t_ax_hmac_hash()

static void t_ax_hmac_hash ( const struct GNUNET_CRYPTO_SymmetricSessionKey key,
struct GNUNET_HashCode hash,
const void *  source,
unsigned int  len 
)
static

Perform a HMAC.

Parameters
keyKey to use.
[out]hashResulting HMAC.
sourceSource key material (data to HMAC).
lenLength of source.

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

735 {
736  static const char ctx[] = "axolotl HMAC-HASH";
737  struct GNUNET_CRYPTO_AuthKey auth_key;
738 
740  key,
741  ctx, sizeof(ctx),
742  NULL);
743  GNUNET_CRYPTO_hmac (&auth_key,
744  source,
745  len,
746  hash);
747 }
static GstElement * source
Appsrc instance into which we write data for the pipeline.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...

References ctx, GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_hmac_derive_key(), key, len, and source.

Referenced by t_ax_decrypt_and_validate(), t_ax_encrypt(), and t_hmac_derive_key().

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

◆ t_hmac_derive_key()

static void t_hmac_derive_key ( const struct GNUNET_CRYPTO_SymmetricSessionKey key,
struct GNUNET_CRYPTO_SymmetricSessionKey out,
const void *  source,
unsigned int  len 
)
static

Derive a symmetric encryption key from an HMAC-HASH.

Parameters
keyKey to use for the HMAC.
[out]outKey to generate.
sourceSource key material (data to HMAC).
lenLength of source.

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

763 {
764  static const char ctx[] = "axolotl derive key";
765  struct GNUNET_HashCode h;
766 
768  &h,
769  source,
770  len);
771  GNUNET_CRYPTO_kdf (out, sizeof(*out),
772  ctx, sizeof(ctx),
773  &h, sizeof(h),
774  NULL);
775 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static void t_ax_hmac_hash(const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hash, const void *source, unsigned int len)
Perform a HMAC.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90

References ctx, GNUNET_CRYPTO_kdf(), h, key, len, source, and t_ax_hmac_hash().

Referenced by store_skipped_key(), t_ax_decrypt(), and t_ax_encrypt().

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

◆ t_ax_encrypt()

static void t_ax_encrypt ( struct CadetTunnelAxolotl ax,
void *  dst,
const void *  src,
size_t  size 
)
static

Encrypt data with the axolotl tunnel key.

Parameters
axkey material to use.
dstDestination with size bytes for the encrypted data.
srcSource of the plaintext. Can overlap with dst, must contain size bytes
sizeSize of the buffers at src and dst

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

791 {
794  size_t out_size;
795 
796  ax->ratchet_counter++;
797  if ((GNUNET_YES == ax->ratchet_allowed) &&
798  ((ratchet_messages <= ax->ratchet_counter) ||
801  {
802  ax->ratchet_flag = GNUNET_YES;
803  }
804  if (GNUNET_YES == ax->ratchet_flag)
805  {
806  /* Advance ratchet */
807  struct GNUNET_CRYPTO_SymmetricSessionKey keys[3];
808  struct GNUNET_HashCode dh;
809  struct GNUNET_HashCode hmac;
810  static const char ctx[] = "axolotl ratchet";
811 
812  new_ephemeral (ax);
813  ax->HKs = ax->NHKs;
814 
815  /* RK, NHKs, CKs = KDF( HMAC-HASH(RK, DH(DHRs, DHRr)) ) */
817  &ax->DHRr,
818  &dh);
819  t_ax_hmac_hash (&ax->RK,
820  &hmac,
821  &dh,
822  sizeof(dh));
823  GNUNET_CRYPTO_kdf (keys, sizeof(keys),
824  ctx, sizeof(ctx),
825  &hmac, sizeof(hmac),
826  NULL);
827  ax->RK = keys[0];
828  ax->NHKs = keys[1];
829  ax->CKs = keys[2];
830 
831  ax->PNs = ax->Ns;
832  ax->Ns = 0;
833  ax->ratchet_flag = GNUNET_NO;
835  ax->ratchet_counter = 0;
838  ratchet_time);
839  }
840 
841  t_hmac_derive_key (&ax->CKs,
842  &MK,
843  "0",
844  1);
846  &MK,
847  NULL, 0,
848  NULL);
849 
850  out_size = GNUNET_CRYPTO_symmetric_encrypt (src,
851  size,
852  &MK,
853  &iv,
854  dst);
855  GNUNET_assert (size == out_size);
856  t_hmac_derive_key (&ax->CKs,
857  &ax->CKs,
858  "1",
859  1);
860 }
struct GNUNET_TIME_Relative ratchet_time
How long until we trigger a ratched advance due to time.
static void new_ephemeral(struct CadetTunnelAxolotl *ax)
Create a new Axolotl ephemeral (ratchet) key.
static void t_hmac_derive_key(const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *out, const void *source, unsigned int len)
Derive a symmetric encryption key from an HMAC-HASH.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a public and a private ECC key.
Definition: crypto_ecc.c:705
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
void GNUNET_CRYPTO_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:277
uint32_t PNs
Previous message numbers (# of msgs sent under prev ratchet)
struct GNUNET_CRYPTO_SymmetricSessionKey HKs
32-byte header key (currently used for sending).
struct GNUNET_TIME_Absolute ratchet_expiration
Time when the current ratchet expires and a new one is triggered (if ratchet_allowed is GNUNET_YES).
struct GNUNET_CRYPTO_EcdhePublicKey DHRr
ECDH Ratchet key (other peer's public key in the current DH).
uint32_t Ns
Message number (reset to 0 with each new ratchet, next message to send).
struct GNUNET_CRYPTO_SymmetricSessionKey RK
32-byte root key which gets updated by DH ratchet.
int ratchet_allowed
True (GNUNET_YES) if we have received a message from the other peer that uses the keys from our last ...
int ratchet_flag
True (GNUNET_YES) if we have to send a new ratchet key in next msg.
struct GNUNET_CRYPTO_SymmetricSessionKey CKs
32-byte chain keys (used for forward-secrecy) for sending messages.
unsigned int ratchet_counter
Number of messages received since our last ratchet advance.
struct GNUNET_CRYPTO_SymmetricSessionKey NHKs
32-byte next header key (for sending), used once the ratchet advances.
uint64_t rel_value_us
The actual value.

References CadetTunnelAxolotl::CKs, ctx, CadetTunnelAxolotl::DHRr, CadetTunnelAxolotl::DHRs, GNUNET_assert, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_kdf(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_NO, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, CadetTunnelAxolotl::HKs, new_ephemeral(), CadetTunnelAxolotl::NHKs, CadetTunnelAxolotl::Ns, CadetTunnelAxolotl::PNs, CadetTunnelAxolotl::ratchet_allowed, CadetTunnelAxolotl::ratchet_counter, CadetTunnelAxolotl::ratchet_expiration, CadetTunnelAxolotl::ratchet_flag, ratchet_time, GNUNET_TIME_Relative::rel_value_us, CadetTunnelAxolotl::RK, size, t_ax_hmac_hash(), and t_hmac_derive_key().

Referenced by GCT_send().

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

◆ t_ax_decrypt()

static void t_ax_decrypt ( struct CadetTunnelAxolotl ax,
void *  dst,
const void *  src,
size_t  size 
)
static

Decrypt data with the axolotl tunnel key.

Parameters
axkey material to use.
dstDestination for the decrypted data, must contain size bytes.
srcSource of the ciphertext. Can overlap with dst, must contain size bytes.
sizeSize of the src and dst buffers

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

876 {
879  size_t out_size;
880 
881  t_hmac_derive_key (&ax->CKr,
882  &MK,
883  "0",
884  1);
886  &MK,
887  NULL, 0,
888  NULL);
889  GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader));
890  out_size = GNUNET_CRYPTO_symmetric_decrypt (src,
891  size,
892  &MK,
893  &iv,
894  dst);
895  GNUNET_assert (out_size == size);
896  t_hmac_derive_key (&ax->CKr,
897  &ax->CKr,
898  "1",
899  1);
900 }
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
struct GNUNET_CRYPTO_SymmetricSessionKey CKr
32-byte chain keys (used for forward-secrecy) for receiving messages.
Header for all communications.

References CadetTunnelAxolotl::CKr, GNUNET_assert, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_CRYPTO_symmetric_derive_iv(), size, and t_hmac_derive_key().

Referenced by t_ax_decrypt_and_validate().

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

◆ t_h_encrypt()

static void t_h_encrypt ( struct CadetTunnelAxolotl ax,
struct GNUNET_CADET_TunnelEncryptedMessage msg 
)
static

Encrypt header with the axolotl header key.

Parameters
axkey material to use.
[in|out]msg Message whose header to encrypt.

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

912 {
914  size_t out_size;
915 
917  &ax->HKs,
918  NULL, 0,
919  NULL);
920  out_size = GNUNET_CRYPTO_symmetric_encrypt (&msg->ax_header,
921  sizeof(struct
923  &ax->HKs,
924  &iv,
925  &msg->ax_header);
926  GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == out_size);
927 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Encrypted axolotl header with numbers that identify which keys in which ratchet are to be used to dec...

References GNUNET_assert, GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_CRYPTO_symmetric_encrypt(), CadetTunnelAxolotl::HKs, and msg.

Referenced by GCT_send().

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

◆ t_h_decrypt()

static void t_h_decrypt ( struct CadetTunnelAxolotl ax,
const struct GNUNET_CADET_TunnelEncryptedMessage src,
struct GNUNET_CADET_TunnelEncryptedMessage dst 
)
static

Decrypt header with the current axolotl header key.

Parameters
axkey material to use.
srcMessage whose header to decrypt.
dstWhere to decrypt header to.

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

941 {
943  size_t out_size;
944 
946  &ax->HKr,
947  NULL, 0,
948  NULL);
949  out_size = GNUNET_CRYPTO_symmetric_decrypt (&src->ax_header.Ns,
950  sizeof(struct
952  &ax->HKr,
953  &iv,
954  &dst->ax_header.Ns);
955  GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == out_size);
956 }
struct GNUNET_CRYPTO_SymmetricSessionKey HKr
32-byte header key (currently used for receiving)
uint32_t Ns
Number of messages sent with the current ratchet key.
struct GNUNET_CADET_AxHeader ax_header
Axolotl-header that specifies which keys to use in which ratchet to decrypt the body that follows.

References GNUNET_CADET_TunnelEncryptedMessage::ax_header, GNUNET_assert, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_CRYPTO_symmetric_derive_iv(), CadetTunnelAxolotl::HKr, and GNUNET_CADET_AxHeader::Ns.

Referenced by t_ax_decrypt_and_validate().

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

◆ delete_skipped_key()

static void delete_skipped_key ( struct CadetTunnelAxolotl ax,
struct CadetTunnelSkippedKey key 
)
static

Delete a key from the list of skipped keys.

Parameters
axkey material to delete key from.
keyKey to delete.

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

968 {
970  ax->skipped_tail,
971  key);
972  GNUNET_free (key);
973  ax->skipped--;
974 }
#define GNUNET_free(ptr)
Wrapper around free.
unsigned int skipped
Number of elements in skipped_head <-> skipped_tail.
struct CadetTunnelSkippedKey * skipped_tail
Skipped messages' keys DLL, tail.
struct CadetTunnelSkippedKey * skipped_head
A (double linked) list of stored message keys and associated header keys for "skipped" messages,...

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, key, CadetTunnelAxolotl::skipped, CadetTunnelAxolotl::skipped_head, and CadetTunnelAxolotl::skipped_tail.

Referenced by cleanup_ax(), store_ax_keys(), and try_old_ax_keys().

Here is the caller graph for this function:

◆ try_old_ax_keys()

static ssize_t try_old_ax_keys ( struct CadetTunnelAxolotl ax,
void *  dst,
const struct GNUNET_CADET_TunnelEncryptedMessage src,
size_t  size 
)
static

Decrypt and verify data with the appropriate tunnel key and verify that the data has not been altered since it was sent by the remote peer.

Parameters
axkey material to use.
dstDestination for the plaintext.
srcSource of the message. Can overlap with dst.
sizeSize of the message.
Returns
Size of the decrypted data, -1 if an error was encountered.

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

992 {
993  struct CadetTunnelSkippedKey *key;
994  struct GNUNET_ShortHashCode *hmac;
996  struct GNUNET_CADET_TunnelEncryptedMessage plaintext_header;
997  struct GNUNET_CRYPTO_SymmetricSessionKey *valid_HK;
998  size_t esize;
999  size_t res;
1000  size_t len;
1001  unsigned int N;
1002 
1004  "Trying skipped keys\n");
1005  hmac = &plaintext_header.hmac;
1006  esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
1007 
1008  /* Find a correct Header Key */
1009  valid_HK = NULL;
1010  for (key = ax->skipped_head; NULL != key; key = key->next)
1011  {
1012  t_hmac (&src->ax_header,
1013  sizeof(struct GNUNET_CADET_AxHeader) + esize,
1014  0,
1015  &key->HK,
1016  hmac);
1017  if (0 == GNUNET_memcmp (hmac,
1018  &src->hmac))
1019  {
1020  valid_HK = &key->HK;
1021  break;
1022  }
1023  }
1024  if (NULL == key)
1025  return -1;
1026 
1027  /* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */
1029  len = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
1030  GNUNET_assert (len >= sizeof(struct GNUNET_MessageHeader));
1031 
1032  /* Decrypt header */
1034  &key->HK,
1035  NULL, 0,
1036  NULL);
1038  sizeof(struct GNUNET_CADET_AxHeader),
1039  &key->HK,
1040  &iv,
1041  &plaintext_header.ax_header.Ns);
1042  GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == res);
1043 
1044  /* Find the correct message key */
1045  N = ntohl (plaintext_header.ax_header.Ns);
1046  while ((NULL != key) &&
1047  (N != key->Kn))
1048  key = key->next;
1049  if ((NULL == key) ||
1050  (0 != GNUNET_memcmp (&key->HK,
1051  valid_HK)))
1052  return -1;
1053 
1054  /* Decrypt payload */
1056  &key->MK,
1057  NULL,
1058  0,
1059  NULL);
1061  len,
1062  &key->MK,
1063  &iv,
1064  dst);
1065  delete_skipped_key (ax,
1066  key);
1067  return res;
1068 }
static int res
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.
static void delete_skipped_key(struct CadetTunnelAxolotl *ax, struct CadetTunnelSkippedKey *key)
Delete a key from the list of skipped keys.
#define N
Struct to old keys for skipped messages while advancing the Axolotl ratchet.
Axolotl-encrypted tunnel message with application payload.
struct GNUNET_ShortHashCode hmac
MAC of the encrypted message, used to verify message integrity.
A 256-bit hashcode.

References GNUNET_CADET_TunnelEncryptedMessage::ax_header, delete_skipped_key(), GNUNET_assert, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcmp, GNUNET_CADET_TunnelEncryptedMessage::hmac, key, len, LOG, N, GNUNET_CADET_AxHeader::Ns, res, size, CadetTunnelAxolotl::skipped_head, and t_hmac().

Referenced by t_ax_decrypt_and_validate().

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

◆ store_skipped_key()

static void store_skipped_key ( struct CadetTunnelAxolotl ax,
const struct GNUNET_CRYPTO_SymmetricSessionKey HKr 
)
static

Delete a key from the list of skipped keys.

Parameters
axkey material to delete from.
HKrHeader Key to use.

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

1080 {
1081  struct CadetTunnelSkippedKey *key;
1082 
1084  key->timestamp = GNUNET_TIME_absolute_get ();
1085  key->Kn = ax->Nr;
1086  key->HK = ax->HKr;
1087  t_hmac_derive_key (&ax->CKr,
1088  &key->MK,
1089  "0",
1090  1);
1091  t_hmac_derive_key (&ax->CKr,
1092  &ax->CKr,
1093  "1",
1094  1);
1096  ax->skipped_tail,
1097  key);
1098  ax->skipped++;
1099  ax->Nr++;
1100 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t Nr
Message number (reset to 0 with each new ratchet, next message to recv).

References CadetTunnelAxolotl::CKr, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_TIME_absolute_get(), CadetTunnelAxolotl::HKr, key, CadetTunnelAxolotl::Nr, CadetTunnelAxolotl::skipped, CadetTunnelAxolotl::skipped_head, CadetTunnelAxolotl::skipped_tail, and t_hmac_derive_key().

Referenced by store_ax_keys().

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

◆ store_ax_keys()

static int store_ax_keys ( struct CadetTunnelAxolotl ax,
const struct GNUNET_CRYPTO_SymmetricSessionKey HKr,
uint32_t  Np 
)
static

Stage skipped AX keys and calculate the message key.

Stores each HK and MK for skipped messages.

Parameters
axkey material to use
HKrHeader key.
NpReceived meesage number.
Returns
GNUNET_OK if keys were stored. GNUNET_SYSERR if an error occurred (Np not expected).

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

1117 {
1118  int gap;
1119 
1120  gap = Np - ax->Nr;
1122  "Storing skipped keys [%u, %u)\n",
1123  ax->Nr,
1124  Np);
1125  if (MAX_KEY_GAP < gap)
1126  {
1127  /* Avoid DoS (forcing peer to do more than #MAX_KEY_GAP HMAC operations) */
1128  /* TODO: start new key exchange on return */
1129  GNUNET_break_op (0);
1131  "Got message %u, expected %u+\n",
1132  Np,
1133  ax->Nr);
1134  return GNUNET_SYSERR;
1135  }
1136  if (0 > gap)
1137  {
1138  /* Delayed message: don't store keys, flag to try old keys. */
1139  return GNUNET_SYSERR;
1140  }
1141 
1142  while (ax->Nr < Np)
1143  store_skipped_key (ax,
1144  HKr);
1145 
1146  while (ax->skipped > MAX_SKIPPED_KEYS)
1147  delete_skipped_key (ax,
1148  ax->skipped_tail);
1149  return GNUNET_OK;
1150 }
#define MAX_KEY_GAP
Maximum number of keys (and thus ratchet steps) we are willing to skip before we decide this is eithe...
static void store_skipped_key(struct CadetTunnelAxolotl *ax, const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr)
Delete a key from the list of skipped keys.
#define MAX_SKIPPED_KEYS
Maximum number of skipped keys we keep in memory per tunnel.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_ERROR_TYPE_WARNING

References delete_skipped_key(), GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, GNUNET_SYSERR, LOG, MAX_KEY_GAP, MAX_SKIPPED_KEYS, CadetTunnelAxolotl::Nr, CadetTunnelAxolotl::skipped, CadetTunnelAxolotl::skipped_tail, and store_skipped_key().

Referenced by t_ax_decrypt_and_validate().

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

◆ t_ax_decrypt_and_validate()

static ssize_t t_ax_decrypt_and_validate ( struct CadetTunnelAxolotl ax,
void *  dst,
const struct GNUNET_CADET_TunnelEncryptedMessage src,
size_t  size 
)
static

Decrypt and verify data with the appropriate tunnel key and verify that the data has not been altered since it was sent by the remote peer.

Parameters
axkey material to use
dstDestination for the plaintext.
srcSource of the message. Can overlap with dst.
sizeSize of the message.
Returns
Size of the decrypted data, -1 if an error was encountered.

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

1169 {
1170  struct GNUNET_ShortHashCode msg_hmac;
1171  struct GNUNET_HashCode hmac;
1172  struct GNUNET_CADET_TunnelEncryptedMessage plaintext_header;
1173  uint32_t Np;
1174  uint32_t PNp;
1175  size_t esize; /* Size of encryped payload */
1176 
1177  esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
1178 
1179  /* Try current HK */
1180  t_hmac (&src->ax_header,
1181  sizeof(struct GNUNET_CADET_AxHeader) + esize,
1182  0, &ax->HKr,
1183  &msg_hmac);
1184  if (0 != GNUNET_memcmp (&msg_hmac,
1185  &src->hmac))
1186  {
1187  static const char ctx[] = "axolotl ratchet";
1188  struct GNUNET_CRYPTO_SymmetricSessionKey keys[3]; /* RKp, NHKp, CKp */
1190  struct GNUNET_HashCode dh;
1191  struct GNUNET_CRYPTO_EcdhePublicKey *DHRp;
1192 
1193  /* Try Next HK */
1194  t_hmac (&src->ax_header,
1195  sizeof(struct GNUNET_CADET_AxHeader) + esize,
1196  0,
1197  &ax->NHKr,
1198  &msg_hmac);
1199  if (0 != GNUNET_memcmp (&msg_hmac,
1200  &src->hmac))
1201  {
1202  /* Try the skipped keys, if that fails, we're out of luck. */
1203  return try_old_ax_keys (ax,
1204  dst,
1205  src,
1206  size);
1207  }
1208  HK = ax->HKr;
1209  ax->HKr = ax->NHKr;
1210  t_h_decrypt (ax,
1211  src,
1212  &plaintext_header);
1213  Np = ntohl (plaintext_header.ax_header.Ns);
1214  PNp = ntohl (plaintext_header.ax_header.PNs);
1215  DHRp = &plaintext_header.ax_header.DHRs;
1216  store_ax_keys (ax,
1217  &HK,
1218  PNp);
1219 
1220  /* RKp, NHKp, CKp = KDF (HMAC-HASH (RK, DH (DHRp, DHRs))) */
1222  DHRp,
1223  &dh);
1224  t_ax_hmac_hash (&ax->RK,
1225  &hmac,
1226  &dh, sizeof(dh));
1227  GNUNET_CRYPTO_kdf (keys, sizeof(keys),
1228  ctx, sizeof(ctx),
1229  &hmac, sizeof(hmac),
1230  NULL);
1231 
1232  /* Commit "purported" keys */
1233  ax->RK = keys[0];
1234  ax->NHKr = keys[1];
1235  ax->CKr = keys[2];
1236  ax->DHRr = *DHRp;
1237  ax->Nr = 0;
1239  }
1240  else
1241  {
1242  t_h_decrypt (ax,
1243  src,
1244  &plaintext_header);
1245  Np = ntohl (plaintext_header.ax_header.Ns);
1246  PNp = ntohl (plaintext_header.ax_header.PNs);
1247  }
1248  if ((Np != ax->Nr) &&
1249  (GNUNET_OK != store_ax_keys (ax,
1250  &ax->HKr,
1251  Np)))
1252  {
1253  /* Try the skipped keys, if that fails, we're out of luck. */
1254  return try_old_ax_keys (ax,
1255  dst,
1256  src,
1257  size);
1258  }
1259 
1260  t_ax_decrypt (ax,
1261  dst,
1262  &src[1],
1263  esize);
1264  ax->Nr = Np + 1;
1265  return esize;
1266 }
static void t_h_decrypt(struct CadetTunnelAxolotl *ax, const struct GNUNET_CADET_TunnelEncryptedMessage *src, struct GNUNET_CADET_TunnelEncryptedMessage *dst)
Decrypt header with the current axolotl header key.
static void t_ax_decrypt(struct CadetTunnelAxolotl *ax, void *dst, const void *src, size_t size)
Decrypt data with the axolotl tunnel key.
static int store_ax_keys(struct CadetTunnelAxolotl *ax, const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr, uint32_t Np)
Stage skipped AX keys and calculate the message key.
static ssize_t try_old_ax_keys(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 GNUNET_CRYPTO_SymmetricSessionKey NHKr
32-byte next header key (for receiving).
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...

References GNUNET_CADET_TunnelEncryptedMessage::ax_header, CadetTunnelAxolotl::CKr, ctx, CadetTunnelAxolotl::DHRr, GNUNET_CADET_AxHeader::DHRs, CadetTunnelAxolotl::DHRs, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_kdf(), GNUNET_memcmp, GNUNET_OK, GNUNET_YES, CadetTunnelAxolotl::HKr, GNUNET_CADET_TunnelEncryptedMessage::hmac, CadetTunnelAxolotl::NHKr, CadetTunnelAxolotl::Nr, GNUNET_CADET_AxHeader::Ns, GNUNET_CADET_AxHeader::PNs, CadetTunnelAxolotl::ratchet_allowed, CadetTunnelAxolotl::RK, size, store_ax_keys(), t_ax_decrypt(), t_ax_hmac_hash(), t_h_decrypt(), t_hmac(), and try_old_ax_keys().

Referenced by GCT_handle_encrypted().

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

◆ notify_tunnel_up_cb()

static int notify_tunnel_up_cb ( void *  cls,
uint32_t  key,
void *  value 
)
static

Our tunnel became ready for the first time, notify channels that have been waiting.

Parameters
clsour tunnel, not used
keyunique ID of the channel, not used
valuethe struct CadetChannel to notify
Returns
GNUNET_OK (continue to iterate)

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

1282 {
1283  struct CadetChannel *ch = value;
1284 
1285  GCCH_tunnel_up (ch);
1286  return GNUNET_OK;
1287 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static char * value
Value of the record to add/remove.
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...
Struct containing all information regarding a channel to a remote client.

References ch, GCCH_tunnel_up(), GNUNET_OK, and value.

Referenced by GCT_change_estate().

Here is the call graph for this function:
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.
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
static const char * estate2s(enum CadetTunnelEState es)
Get string description for tunnel encryption state.
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...
CadetTunnelEState
All the encryption states a tunnel can be in.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
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
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972

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:

◆ send_kx()

static void send_kx ( struct CadetTunnel t,
struct CadetTConnection ct,
struct CadetTunnelAxolotl ax 
)
static

Send a KX message.

Parameters
ttunnel on which to send the KX_AUTH
ctTunnel and connection on which to send the KX_AUTH, NULL if we are to find one that is ready.
axaxolotl key context to use

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

1342 {
1343  struct CadetConnection *cc;
1344  struct GNUNET_MQ_Envelope *env;
1347 
1348  if (GNUNET_YES != GCT_alice_or_betty (GCP_get_id (t->destination)))
1349  return; /* only Alice may send KX */
1350  if ((NULL == ct) ||
1351  (GNUNET_NO == ct->is_ready))
1352  ct = get_ready_connection (t);
1353  if (NULL == ct)
1354  {
1356  "Wanted to send %s in state %s, but no connection is ready, deferring\n",
1357  GCT_2s (t),
1358  estate2s (t->estate));
1359  t->next_kx_attempt = GNUNET_TIME_absolute_get ();
1360  return;
1361  }
1362  cc = ct->cc;
1363  env = GNUNET_MQ_msg (msg,
1365  flags = GNUNET_CADET_KX_FLAG_FORCE_REPLY; /* always for KX */
1366  msg->flags = htonl (flags);
1367  msg->cid = *GCC_get_id (cc);
1369  &msg->ephemeral_key);
1370 #if DEBUG_KX
1371  msg->ephemeral_key_XXX = ax->kx_0;
1372  msg->private_key_XXX = *my_private_key;
1373 #endif
1375  "Sending KX message to %s with ephemeral %s on CID %s\n",
1376  GCT_2s (t),
1377  GNUNET_e2s (&msg->ephemeral_key),
1378  GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1380  &msg->ratchet_key);
1382  t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
1383  t->next_kx_attempt = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
1384  if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
1387  else if (CADET_TUNNEL_KEY_AX_RECV == t->estate)
1390  GCC_transmit (cc,
1391  env);
1393  "# KX transmitted",
1394  1,
1395  GNUNET_NO);
1396 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_CADET_KX_Flags
Flags to be used in GNUNET_CADET_KX.
@ GNUNET_CADET_KX_FLAG_FORCE_REPLY
The peer should reply with its KX details?
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Own private key.
void GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
Transmit message msg via connection cc.
const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id(struct CadetConnection *cc)
Obtain unique ID for the connection.
static void mark_connection_unready(struct CadetTConnection *ct)
Connection ct is now unready, clear it's ready flag and move it from the ready DLL to the busy DLL.
void GCT_change_estate(struct CadetTunnel *t, enum CadetTunnelEState state)
Change the tunnel encryption state.
int GCT_alice_or_betty(const struct GNUNET_PeerIdentity *other)
Am I Alice or Betty (some call her Bob), or talking to myself?
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
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX
Axolotl key exchange.
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_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:181
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Low-level connection to a destination.
struct CadetConnection * cc
Connection handle.
struct GNUNET_CRYPTO_EcdhePrivateKey kx_0
ECDH for key exchange (A0 / B0).
Message for a Key eXchange for a tunnel.
uint32_t flags
Flags for the key exchange in NBO, based on enum GNUNET_CADET_KX_Flags.

References CADET_TUNNEL_KEY_AX_RECV, CADET_TUNNEL_KEY_AX_SENT, CADET_TUNNEL_KEY_AX_SENT_AND_RECV, CADET_TUNNEL_KEY_UNINITIALIZED, CadetTConnection::cc, CadetTunnelAxolotl::DHRs, env, estate2s(), GNUNET_CADET_TunnelKeyExchangeMessage::flags, GCC_get_id(), GCC_transmit(), GCP_get_id(), GCT_2s(), GCT_alice_or_betty(), GCT_change_estate(), get_ready_connection(), GNUNET_CADET_KX_FLAG_FORCE_REPLY, GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, GNUNET_MQ_msg, GNUNET_NO, GNUNET_sh2s(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, CadetTConnection::is_ready, CadetTunnelAxolotl::kx_0, LOG, mark_connection_unready(), msg, my_private_key, stats, and t.

Referenced by connection_ready_cb(), GCT_handle_encrypted(), and retry_kx().

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

◆ send_kx_auth()

static void send_kx_auth ( struct CadetTunnel t,
struct CadetTConnection ct,
struct CadetTunnelAxolotl ax,
int  force_reply 
)
static

Send a KX_AUTH message.

Parameters
ttunnel on which to send the KX_AUTH
ctTunnel and connection on which to send the KX_AUTH, NULL if we are to find one that is ready.
axaxolotl key context to use
force_replyForce the other peer to reply with a KX_AUTH message (set if we would like to transmit right now, but cannot)

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

1414 {
1415  struct CadetConnection *cc;
1416  struct GNUNET_MQ_Envelope *env;
1418  enum GNUNET_CADET_KX_Flags flags;
1419 
1420  if ((NULL == ct) ||
1421  (GNUNET_NO == ct->is_ready))
1422  ct = get_ready_connection (t);
1423  if (NULL == ct)
1424  {
1426  "Wanted to send KX_AUTH on %s, but no connection is ready, deferring\n",
1427  GCT_2s (t));
1428  t->next_kx_attempt = GNUNET_TIME_absolute_get ();
1429  t->kx_auth_requested = GNUNET_YES; /* queue KX_AUTH independent of estate */
1430  return;
1431  }
1432  t->kx_auth_requested = GNUNET_NO; /* clear flag */
1433  cc = ct->cc;
1434  env = GNUNET_MQ_msg (msg,
1436  flags = GNUNET_CADET_KX_FLAG_NONE;
1437  if (GNUNET_YES == force_reply)
1439  msg->kx.flags = htonl (flags);
1440  msg->kx.cid = *GCC_get_id (cc);
1442  &msg->kx.ephemeral_key);
1444  &msg->kx.ratchet_key);
1445 #if DEBUG_KX
1446  msg->kx.ephemeral_key_XXX = ax->kx_0;
1447  msg->kx.private_key_XXX = *my_private_key;
1448  msg->r_ephemeral_key_XXX = ax->last_ephemeral;
1449 #endif
1451  "Sending KX_AUTH message to %s with ephemeral %s on CID %s\n",
1452  GCT_2s (t),
1453  GNUNET_e2s (&msg->kx.ephemeral_key),
1454  GNUNET_sh2s (&msg->kx.cid.connection_of_tunnel));
1455 
1456  /* Compute authenticator (this is the main difference to #send_kx()) */
1457  GNUNET_CRYPTO_hash (&ax->RK,
1458  sizeof(ax->RK),
1459  &msg->auth);
1460  /* Compute when to be triggered again; actual job will
1461  be scheduled via #connection_ready_cb() */
1462  t->kx_retry_delay
1463  = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
1464  t->next_kx_attempt
1465  = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
1466 
1467  /* Send via cc, mark it as unready */
1469 
1470  /* Update state machine, unless we are already OK */
1471  if (CADET_TUNNEL_KEY_OK != t->estate)
1474  GCC_transmit (cc,
1475  env);
1477  "# KX_AUTH transmitted",
1478  1,
1479  GNUNET_NO);
1480 }
@ GNUNET_CADET_KX_FLAG_NONE
Should the peer reply with its KX details?
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
#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH
Axolotl key exchange response with authentication.
struct GNUNET_CRYPTO_EcdhePublicKey last_ephemeral
Last ephemeral public key received from the other peer, for duplicate detection.
Message for a Key eXchange for a tunnel, with authentication.

References CADET_TUNNEL_KEY_AX_AUTH_SENT, CADET_TUNNEL_KEY_OK, CadetTConnection::cc, CadetTunnelAxolotl::DHRs, env, GCC_get_id(), GCC_transmit(), GCT_2s(), GCT_change_estate(), get_ready_connection(), GNUNET_CADET_KX_FLAG_FORCE_REPLY, GNUNET_CADET_KX_FLAG_NONE, GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, GNUNET_MQ_msg, GNUNET_NO, GNUNET_sh2s(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, CadetTConnection::is_ready, CadetTunnelAxolotl::kx_0, CadetTunnelAxolotl::last_ephemeral, LOG, mark_connection_unready(), msg, my_private_key, CadetTunnelAxolotl::RK, stats, and t.

Referenced by connection_ready_cb(), GCT_add_channel(), GCT_handle_encrypted(), GCT_handle_kx(), and retry_kx().

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

◆ cleanup_ax()

static void cleanup_ax ( struct CadetTunnelAxolotl ax)
static

Cleanup state used by ax.

Parameters
axstate to free, but not memory of ax itself

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

1490 {
1491  while (NULL != ax->skipped_head)
1492  delete_skipped_key (ax,
1493  ax->skipped_head);
1494  GNUNET_assert (0 == ax->skipped);
1497 }
void GNUNET_CRYPTO_ecdhe_key_clear(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:414

References delete_skipped_key(), CadetTunnelAxolotl::DHRs, GNUNET_assert, GNUNET_CRYPTO_ecdhe_key_clear(), CadetTunnelAxolotl::kx_0, CadetTunnelAxolotl::skipped, and CadetTunnelAxolotl::skipped_head.

Referenced by destroy_tunnel(), GCT_add_channel(), and GCT_handle_encrypted().

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

◆ update_ax_by_kx()

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 
)
static

Update our Axolotl key state based on the KX data we received.

Computes the new chain keys, and root keys, etc, and also checks whether this is a replay of the current chain.

Parameters
[in|out]axolotl chain key state to recompute
pidpeer identity of the other peer
ephemeral_keyephemeral public key of the other peer
ratchet_keysenders next ephemeral public key
Returns
GNUNET_OK on success, GNUNET_NO if the resulting root key is already in ax and thus the KX is useless; GNUNET_SYSERR on hard errors (i.e. pid is my_full_id)

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

1518 {
1519  struct GNUNET_HashCode key_material[3];
1520  struct GNUNET_CRYPTO_SymmetricSessionKey keys[5];
1521  const char salt[] = "CADET Axolotl salt";
1522  int am_I_alice;
1523 
1524  if (GNUNET_SYSERR == (am_I_alice = GCT_alice_or_betty (pid)))
1525  {
1526  GNUNET_break_op (0);
1527  return GNUNET_SYSERR;
1528  }
1529  if (0 == GNUNET_memcmp (&ax->DHRr,
1530  ratchet_key))
1531  {
1533  "# Ratchet key already known",
1534  1,
1535  GNUNET_NO);
1537  "Ratchet key already known. Ignoring KX.\n");
1538  return GNUNET_NO;
1539  }
1540 
1541  ax->DHRr = *ratchet_key;
1542  ax->last_ephemeral = *ephemeral_key;
1543  /* ECDH A B0 */
1544  if (GNUNET_YES == am_I_alice)
1545  {
1547  ephemeral_key, /* B0 */
1548  &key_material[0]);
1549  }
1550  else
1551  {
1552  GNUNET_CRYPTO_ecdh_eddsa (&ax->kx_0, /* b0 */
1553  &pid->public_key, /* A */
1554  &key_material[0]);
1555  }
1556  /* ECDH A0 B */
1557  if (GNUNET_YES == am_I_alice)
1558  {
1559  GNUNET_CRYPTO_ecdh_eddsa (&ax->kx_0, /* a0 */
1560  &pid->public_key, /* B */
1561  &key_material[1]);
1562  }
1563  else
1564  {
1566  ephemeral_key, /* A0 */
1567  &key_material[1]);
1568  }
1569 
1570  /* ECDH A0 B0 */
1571  GNUNET_CRYPTO_ecc_ecdh (&ax->kx_0, /* a0 or b0 */
1572  ephemeral_key, /* B0 or A0 */
1573  &key_material[2]);
1574  /* KDF */
1575  GNUNET_CRYPTO_kdf (keys, sizeof(keys),
1576  salt, sizeof(salt),
1577  &key_material, sizeof(key_material),
1578  NULL);
1579 
1580  if (0 == memcmp (&ax->RK,
1581  &keys[0],
1582  sizeof(ax->RK)))
1583  {
1585  "Root key already known. Ignoring KX.\n");
1587  "# Root key already known",
1588  1,
1589  GNUNET_NO);
1590  return GNUNET_NO;
1591  }
1592 
1593  ax->RK = keys[0];
1594  if (GNUNET_YES == am_I_alice)
1595  {
1596  ax->HKr = keys[1];
1597  ax->NHKs = keys[2];
1598  ax->NHKr = keys[3];
1599  ax->CKr = keys[4];
1600  ax->ratchet_flag = GNUNET_YES;
1601  }
1602  else
1603  {
1604  ax->HKs = keys[1];
1605  ax->NHKr = keys[2];
1606  ax->NHKs = keys[3];
1607  ax->CKs = keys[4];
1608  ax->ratchet_flag = GNUNET_NO;
1609  ax->ratchet_expiration
1611  ratchet_time);
1612  }
1613  return GNUNET_OK;
1614 }
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calcualations.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private EdDSA key.
Definition: crypto_ecc.c:718
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
Definition: crypto_ecc.c:758
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References CadetTunnelAxolotl::CKr, CadetTunnelAxolotl::CKs, CadetTunnelAxolotl::DHRr, GCT_alice_or_betty(), GNUNET_break_op, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_CRYPTO_kdf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcmp, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_YES, CadetTunnelAxolotl::HKr, CadetTunnelAxolotl::HKs, CadetTunnelAxolotl::kx_0, CadetTunnelAxolotl::last_ephemeral, LOG, my_private_key, CadetTunnelAxolotl::NHKr, CadetTunnelAxolotl::NHKs, pid, GNUNET_PeerIdentity::public_key, CadetTunnelAxolotl::ratchet_expiration, CadetTunnelAxolotl::ratchet_flag, ratchet_time, CadetTunnelAxolotl::RK, salt, and stats.

Referenced by GCT_add_channel(), and GCT_handle_kx().

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

◆ retry_kx()

static void retry_kx ( void *  cls)
static

Try to redo the KX or KX_AUTH handshake, if we can.

Parameters
clsthe struct CadetTunnel to do KX for.

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

1624 {
1625  struct CadetTunnel *t = cls;
1626  struct CadetTunnelAxolotl *ax;
1627 
1628  t->kx_task = NULL;
1630  "Trying to make KX progress on %s in state %s\n",
1631  GCT_2s (t),
1632  estate2s (t->estate));
1633  switch (t->estate)
1634  {
1635  case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */
1636  case CADET_TUNNEL_KEY_AX_SENT: /* trying again */
1637  send_kx (t,
1638  NULL,
1639  &t->ax);
1640  break;
1641 
1644  /* We are responding, so only require reply
1645  if WE have a channel waiting. */
1646  if (NULL != t->unverified_ax)
1647  {
1648  /* Send AX_AUTH so we might get this one verified */
1649  ax = t->unverified_ax;
1650  }
1651  else
1652  {
1653  /* How can this be? */
1654  GNUNET_break (0);
1655  ax = &t->ax;
1656  }
1657  send_kx_auth (t,
1658  NULL,
1659  ax,
1660  (0 == GCT_count_channels (t))
1661  ? GNUNET_NO
1662  : GNUNET_YES);
1663  break;
1664 
1666  /* We are responding, so only require reply
1667  if WE have a channel waiting. */
1668  if (NULL != t->unverified_ax)
1669  {
1670  /* Send AX_AUTH so we might get this one verified */
1671  ax = t->unverified_ax;
1672  }
1673  else
1674  {
1675  /* How can this be? */
1676  GNUNET_break (0);
1677  ax = &t->ax;
1678  }
1679  send_kx_auth (t,
1680  NULL,
1681  ax,
1682  (0 == GCT_count_channels (t))
1683  ? GNUNET_NO
1684  : GNUNET_YES);
1685  break;
1686 
1687  case CADET_TUNNEL_KEY_OK:
1688  /* Must have been the *other* peer asking us to
1689  respond with a KX_AUTH. */
1690  if (NULL != t->unverified_ax)
1691  {
1692  /* Sending AX_AUTH in response to AX so we might get this one verified */
1693  ax = t->unverified_ax;
1694  }
1695  else
1696  {
1697  /* Sending AX_AUTH in response to AX_AUTH */
1698  ax = &t->ax;
1699  }
1700  send_kx_auth (t,
1701  NULL,
1702  ax,
1703  GNUNET_NO);
1704  break;
1705  }
1706 }
static void send_kx(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax)
Send a KX message.
unsigned int GCT_count_channels(struct CadetTunnel *t)
Count channels of a tunnel.
static void send_kx_auth(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
Send a KX_AUTH message.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
Axolotl data, according to https://github.com/trevp/axolotl/wiki .

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, estate2s(), GCT_2s(), GCT_count_channels(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, send_kx(), send_kx_auth(), and t.

Referenced by connection_ready_cb(), GCT_add_channel(), and GCT_handle_kx().

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 that lacks authentication (and which will thus only be considered authenticated after we respond with our own KX_AUTH and finally successfully decrypt payload).

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
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
static void retry_kx(void *cls)
Try to redo the KX or KX_AUTH handshake, if we can.
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.

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 }
static void cleanup_ax(struct CadetTunnelAxolotl *ax)
Cleanup state used by ax.
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

Referenced by GCC_handle_kx_auth().

Here is the caller graph for this function:

◆ get_next_free_ctn()

static struct GNUNET_CADET_ChannelTunnelNumber get_next_free_ctn ( struct CadetTunnel t)
static

Compute the next free channel tunnel number for this tunnel.

Parameters
tthe tunnel
Returns
unused number that can uniquely identify a channel in the tunnel

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

2071 {
2072 #define HIGH_BIT 0x8000000
2074  uint32_t ctn;
2075  int cmp;
2076  uint32_t highbit;
2077 
2078  cmp = GNUNET_memcmp (&my_full_id,
2080  if (0 < cmp)
2081  highbit = HIGH_BIT;
2082  else if (0 > cmp)
2083  highbit = 0;
2084  else
2085  GNUNET_assert (0); // loopback must never go here!
2086  ctn = ntohl (t->next_ctn.cn);
2087  while (NULL !=
2089  ctn | highbit))
2090  {
2091  ctn = ((ctn + 1) & (~HIGH_BIT));
2092  }
2093  t->next_ctn.cn = htonl ((ctn + 1) & (~HIGH_BIT));
2094  ret.cn = htonl (ctn | highbit);
2095  return ret;
2096 }
#define HIGH_BIT
struct CadetPeer * GCT_get_destination(struct CadetTunnel *t)
Return the peer to which this tunnel goes.
Number identifying a CADET channel within a tunnel.

◆ GCT_add_channel()

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

Add a channel to a tunnel, and notify channel that we are ready for transmission if we are already up.

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 }
const char * GCCH_2s(const struct CadetChannel *ch)
Get the static string for identification of the channel.
static struct GNUNET_CADET_ChannelTunnelNumber get_next_free_ctn(struct CadetTunnel *t)
Compute the next free channel tunnel number for this 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.
@ 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...

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_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 }

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:

◆ destroy_t_connection()

static void destroy_t_connection ( void *  cls,
struct CadetTConnection ct 
)
static

Clean up connection ct of a tunnel.

Parameters
clsthe struct CadetTunnel
ctconnection to clean up

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

2199 {
2200  struct CadetTunnel *t = cls;
2201  struct CadetConnection *cc = ct->cc;
2202 
2203  GNUNET_assert (ct->t == t);
2206 }
void GCC_destroy_without_tunnel(struct CadetConnection *cc)
Destroy a connection, called if the tunnel association with the connection was already broken,...
void GCT_connection_lost(struct CadetTConnection *ct)
We lost a connection, remove it from our list and clean up the connection object itself.
struct CadetTConnection * ct
Which tunnel is using this connection?

References CadetTConnection::cc, CadetConnection::ct, GCC_destroy_without_tunnel(), GCT_connection_lost(), GNUNET_assert, CadetTConnection::t, and t.

Referenced by destroy_tunnel(), and maintain_connections_cb().

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

◆ destroy_tunnel()

static void destroy_tunnel ( void *  cls)
static

This tunnel is no longer used, destroy it.

Parameters
clsthe idle tunnel

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

2216 {
2217  struct CadetTunnel *t = cls;
2218  struct CadetTunnelQueueEntry *tq;
2219 
2220  t->destroy_task = NULL;
2222  "Destroying idle %s\n",
2223  GCT_2s (t));
2227  t);
2228  GNUNET_assert (NULL == t->connection_ready_head);
2229  GNUNET_assert (NULL == t->connection_busy_head);
2230  while (NULL != (tq = t->tq_head))
2231  {
2232  if (NULL != tq->cont)
2233  tq->cont (tq->cont_cls,
2234  NULL);
2235  GCT_send_cancel (tq);
2236  }
2237  GCP_drop_tunnel (t->destination,
2238  t);
2240  if (NULL != t->maintain_connections_task)
2241  {
2242  GNUNET_SCHEDULER_cancel (t->maintain_connections_task);
2243  t->maintain_connections_task = NULL;
2244  }
2245  if (NULL != t->send_task)
2246  {
2247  GNUNET_SCHEDULER_cancel (t->send_task);
2248  t->send_task = NULL;
2249  }
2250  if (NULL != t->kx_task)
2251  {
2252  GNUNET_SCHEDULER_cancel (t->kx_task);
2253  t->kx_task = NULL;
2254  }
2255  GNUNET_MST_destroy (t->mst);
2256  GNUNET_MQ_destroy (t->mq);
2257  if (NULL != t->unverified_ax)
2258  {
2259  cleanup_ax (t->unverified_ax);
2260  GNUNET_free (t->unverified_ax);
2261  }
2262  cleanup_ax (&t->ax);
2263  GNUNET_assert (NULL == t->destroy_task);
2264  GNUNET_free (t);
2265 }
void GCP_drop_tunnel(struct CadetPeer *cp, struct CadetTunnel *t)
The tunnel to the given peer no longer exists, remove it from our data structures,...
void GCT_send_cancel(struct CadetTunnelQueueEntry *tq)
Cancel a previously sent message while it's in the queue.
void GCT_iterate_connections(struct CadetTunnel *t, GCT_ConnectionIterator iter, void *iter_cls)
Iterate over all connections of a tunnel.
static void destroy_t_connection(void *cls, struct CadetTConnection *ct)
Clean up connection ct of a tunnel.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
Struct used to save messages in a non-ready tunnel to send once connected.
GCT_SendContinuation cont
Continuation to call once sent (on the channel layer).
void * cont_cls
Closure for cont.

References cleanup_ax(), CadetTunnelQueueEntry::cont, CadetTunnelQueueEntry::cont_cls, destroy_t_connection(), GCP_drop_tunnel(), GCT_2s(), GCT_count_channels(), GCT_iterate_connections(), GCT_send_cancel(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_MST_destroy(), GNUNET_SCHEDULER_cancel(), LOG, and t.

Referenced by callback_room_connect(), connection_ready_cb(), enter_room_at(), GCT_destroy_tunnel_now(), GCT_remove_channel(), and iterate_destroy_tunnels().

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?
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
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

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:

◆ destroy_remaining_channels()

static int destroy_remaining_channels ( void *  cls,
uint32_t  key,
void *  value 
)
static

Destroy remaining channels during shutdown.

Parameters
clsthe struct CadetTunnel of the channel
keykey of the channel
valuethe struct CadetChannel
Returns
GNUNET_OK (continue to iterate)

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

2312 {
2313  struct CadetChannel *ch = value;
2314 
2316  NULL);
2317  return GNUNET_OK;
2318 }
void GCCH_handle_remote_destroy(struct CadetChannel *ch, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
Destroy channel, based on the other peer closing the connection.

References ch, GCCH_handle_remote_destroy(), GNUNET_OK, and value.

Referenced by GCT_destroy_tunnel_now().

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.
static int destroy_remaining_channels(void *cls, uint32_t key, void *value)
Destroy remaining channels during shutdown.

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:

◆ try_send_normal_payload()

static void try_send_normal_payload ( struct CadetTunnel t,
struct CadetTConnection ct 
)
static

Send normal payload from queue in t via connection ct.

Does nothing if our payload queue is empty.

Parameters
ttunnel to send data from
ctconnection to use for transmission (is ready)

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

2354 {
2355  struct CadetTunnelQueueEntry *tq;
2356 
2358  tq = t->tq_head;
2359  if (NULL == tq)
2360  {
2361  /* no messages pending right now */
2363  "Not sending payload of %s on ready %s (nothing pending)\n",
2364  GCT_2s (t),
2365  GCC_2s (ct->cc));
2366  return;
2367  }
2368  /* ready to send message 'tq' on tunnel 'ct' */
2369  GNUNET_assert (t == tq->t);
2370  GNUNET_CONTAINER_DLL_remove (t->tq_head,
2371  t->tq_tail,
2372  tq);
2373  if (NULL != tq->cid)
2374  *tq->cid = *GCC_get_id (ct->cc);
2377  "Sending payload of %s on %s\n",
2378  GCT_2s (t),
2379  GCC_2s (ct->cc));
2380  GCC_transmit (ct->cc,
2381  tq->env);
2382  if (NULL != tq->cont)
2383  tq->cont (tq->cont_cls,
2384  GCC_get_id (ct->cc));
2385  GNUNET_free (tq);
2386 }
struct GNUNET_MQ_Envelope * env
Envelope of message to send follows.
struct GNUNET_CADET_ConnectionTunnelIdentifier * cid
Where to put the connection identifier into the payload of the message in env once we have it?
struct CadetTunnel * t
Tunnel these messages belong in.

References CadetTConnection::cc, CadetTunnelQueueEntry::cid, CadetTunnelQueueEntry::cont, CadetTunnelQueueEntry::cont_cls, CadetTunnelQueueEntry::env, GCC_2s(), GCC_get_id(), GCC_transmit(), GCT_2s(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_YES, CadetTConnection::is_ready, LOG, mark_connection_unready(), CadetTunnelQueueEntry::t, and t.

Referenced by connection_ready_cb(), and trigger_transmissions().

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

◆ connection_ready_cb()

static void connection_ready_cb ( void *  cls,
int  is_ready 
)
static

A connection is is_ready for transmission.

Looks at our message queue and if there is a message, sends it out via the connection.

Parameters
clsthe struct CadetTConnection that is is_ready
is_readyGNUNET_YES if connection are now ready, GNUNET_NO if connection are no longer ready

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

2400 {
2401  struct CadetTConnection *ct = cls;
2402  struct CadetTunnel *t = ct->t;
2403 
2404  if (GNUNET_NO == is_ready)
2405  {
2407  "%s no longer ready for %s\n",
2408  GCC_2s (ct->cc),
2409  GCT_2s (t));
2411  return;
2412  }
2413  GNUNET_assert (GNUNET_NO == ct->is_ready);
2414  GNUNET_CONTAINER_DLL_remove (t->connection_busy_head,
2415  t->connection_busy_tail,
2416  ct);
2417  GNUNET_assert (0 < t->num_busy_connections);
2418  t->num_busy_connections--;
2419  ct->is_ready = GNUNET_YES;
2420  GNUNET_CONTAINER_DLL_insert_tail (t->connection_ready_head,
2421  t->connection_ready_tail,
2422  ct);
2423  t->num_ready_connections++;
2424 
2426  "%s now ready for %s in state %s\n",
2427  GCC_2s (ct->cc),
2428  GCT_2s (t),
2429  estate2s (t->estate));
2430  switch (t->estate)
2431  {
2434  "Do not begin KX for %s if WE have no channels waiting. Retrying after %llu\n",
2435  GCT_2s (t),
2436  (unsigned long long) GNUNET_TIME_absolute_get_remaining (
2437  t->next_kx_attempt).rel_value_us);
2438  /* Do not begin KX if WE have no channels waiting! */
2440  t->next_kx_attempt).rel_value_us)
2441  return; /* wait for timeout before retrying */
2442  /* We are uninitialized, just transmit immediately,
2443  without undue delay. */
2444 
2446  "Why for %s \n",
2447  GCT_2s (t));
2448 
2449  if (NULL != t->kx_task)
2450  {
2451  GNUNET_SCHEDULER_cancel (t->kx_task);
2452  t->kx_task = NULL;
2453  }
2454  send_kx (t,
2455  ct,
2456  &t->ax);
2457  if ((0 ==
2458  GCT_count_channels (t)) &&
2459  (NULL == t->destroy_task))
2460  {
2461  t->destroy_task
2463  &destroy_tunnel,
2464  t);
2465  }
2466  break;
2467 
2472  /* we're currently waiting for KX to complete, schedule job */
2473  if (NULL == t->kx_task)
2474  t->kx_task
2475  = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2476  &retry_kx,
2477  t);
2478  break;
2479 
2480  case CADET_TUNNEL_KEY_OK:
2481  if (GNUNET_YES == t->kx_auth_requested)
2482  {
2484  t->next_kx_attempt).rel_value_us)
2485  return; /* wait for timeout */
2486  if (NULL != t->kx_task)
2487  {
2488  GNUNET_SCHEDULER_cancel (t->kx_task);
2489  t->kx_task = NULL;
2490  }
2491  send_kx_auth (t,
2492  ct,
2493  &t->ax,
2494  GNUNET_NO);
2495  return;
2496  }
2498  ct);
2499  break;
2500  }
2501 }
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.

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, CadetTConnection::cc, destroy_tunnel(), estate2s(), GCC_2s(), GCT_2s(), GCT_count_channels(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, IDLE_DESTROY_DELAY, CadetTConnection::is_ready, LOG, mark_connection_unready(), GNUNET_TIME_Relative::rel_value_us, retry_kx(), send_kx(), send_kx_auth(), CadetTConnection::t, t, and try_send_normal_payload().

Referenced by consider_path_cb(), and GCT_add_inbound_connection().

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

◆ evaluate_connection()

static void evaluate_connection ( void *  cls,
struct CadetTConnection ct 
)
static

Evaluate a connection, updating our summary information in cls about what kinds of connections we have.

Parameters
clsthe struct EvaluationSummary * to update
cta connection to include in the summary

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

2588 {
2589  struct EvaluationSummary *es = cls;
2590  struct CadetConnection *cc = ct->cc;
2591  unsigned int ct_length;
2592  struct CadetPeerPath *ps;
2593  const struct CadetConnectionMetrics *metrics;
2594  GNUNET_CONTAINER_HeapCostType ct_desirability;
2595  struct GNUNET_TIME_Relative uptime;
2596  struct GNUNET_TIME_Relative last_use;
2597  double score;
2598  double success_rate;
2599 
2600  ps = GCC_get_path (cc,
2601  &ct_length);
2603  "Evaluating path %s of existing %s\n",
2604  GCPP_2s (ps),
2605  GCC_2s (cc));
2606  if (ps == es->path)
2607  {
2609  "Ignoring duplicate path %s.\n",
2610  GCPP_2s (es->path));
2611  es->duplicate = GNUNET_YES;
2612  return;
2613  }
2614  if (NULL != es->path)
2615  {
2616  int duplicate = GNUNET_YES;
2617 
2618  for (unsigned int i = 0; i < ct_length; i++)
2619  {
2620  GNUNET_assert (GCPP_get_length (es->path) > i);
2621  if (GCPP_get_peer_at_offset (es->path,
2622  i) !=
2624  i))
2625  {
2626  duplicate = GNUNET_NO;
2627  break;
2628  }
2629  }
2630  if (GNUNET_YES == duplicate)
2631  {
2633  "Ignoring overlapping path %s.\n",
2634  GCPP_2s (es->path));
2635  es->duplicate = GNUNET_YES;
2636  return;
2637  }
2638  else
2639  {
2641  "Known path %s differs from proposed path\n",
2642  GCPP_2s (ps));
2643  }
2644  }
2645 
2646  ct_desirability = GCPP_get_desirability (ps);
2647  metrics = GCC_get_metrics (cc);
2648  uptime = GNUNET_TIME_absolute_get_duration (metrics->age);
2649  last_use = GNUNET_TIME_absolute_get_duration (metrics->last_use);
2650  /* We add 1.0 here to avoid division by zero. */
2651  success_rate = (metrics->num_acked_transmissions + 1.0)
2652  / (metrics->num_successes + 1.0);
2653  score
2654  = ct_desirability
2655  + 100.0 / (1.0 + ct_length) /* longer paths = better */
2656  + sqrt (uptime.rel_value_us / 60000000LL) /* larger uptime = better */
2657  - last_use.rel_value_us / 1000L; /* longer idle = worse */
2658  score *= success_rate; /* weigh overall by success rate */
2659 
2660  if ((NULL == es->worst) ||
2661  (score < es->worst_score))
2662  {
2663  es->worst = ct;
2664  es->worst_score = score;
2665  }
2666  es->min_length = GNUNET_MIN (es->min_length,
2667  ct_length);
2668  es->max_length = GNUNET_MAX (es->max_length,
2669  ct_length);
2670  es->min_desire = GNUNET_MIN (es->min_desire,
2671  ct_desirability);
2672  es->max_desire = GNUNET_MAX (es->max_desire,
2673  ct_desirability);
2674 }
const struct CadetConnectionMetrics * GCC_get_metrics(struct CadetConnection *cc)
Obtain performance metrics from cc.
struct CadetPeerPath * GCC_get_path(struct CadetConnection *cc, unsigned int *off)
Obtain the path used by this connection.
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
unsigned int GCPP_get_length(struct CadetPeerPath *path)
Return the length of the path.
GNUNET_CONTAINER_HeapCostType GCPP_get_desirability(const struct CadetPeerPath *path)
Return how much we like keeping the path.
#define GNUNET_MAX(a, b)
#define GNUNET_MIN(a, b)
uint64_t GNUNET_CONTAINER_HeapCostType
Cost by which elements in a heap can be ordered.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:263
Performance metrics for a connection.
unsigned long long num_acked_transmissions
How many packets that ought to generate an ACK did we send via this connection?
struct GNUNET_TIME_Absolute age
When was this connection first established? (by us sending or receiving the CREATE_ACK for the first ...
unsigned long long num_successes
Number of packets that were sent via this connection did actually receive an ACK? (Note: ACKs may be ...
struct GNUNET_TIME_Absolute last_use
When was this connection last used? (by us sending or receiving a PAYLOAD message on it)
Information regarding a possible path to reach a peer.
Closure for evaluate_connection.
unsigned int max_length
Maximum length of any of our connections, 0 if we have none.
int duplicate
Set to GNUNET_YES if we have a connection over path already.
GNUNET_CONTAINER_HeapCostType min_desire
Minimum desirability of any of our connections, UINT64_MAX if we have none.
struct CadetTConnection * worst
Connection deemed the "worst" so far encountered by evaluate_connection, NULL if we did not yet encou...
unsigned int min_length
Minimum length of any of our connections, UINT_MAX if we have none.
GNUNET_CONTAINER_HeapCostType max_desire
Maximum desirability of any of our connections, 0 if we have none.
double worst_score
Numeric score of worst, only set if worst is non-NULL.
struct CadetPeerPath * path
Path we are comparing against for evaluate_connection, can be NULL.
Time for relative time used by GNUnet, in microseconds.

References CadetConnectionMetrics::age, CadetTConnection::cc, CadetConnection::ct, EvaluationSummary::duplicate, GCC_2s(), GCC_get_metrics(), GCC_get_path(), GCPP_2s(), GCPP_get_desirability(), GCPP_get_length(), GCPP_get_peer_at_offset(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MAX, GNUNET_MIN, GNUNET_NO, GNUNET_TIME_absolute_get_duration(), GNUNET_YES, CadetConnectionMetrics::last_use, LOG, EvaluationSummary::max_desire, EvaluationSummary::max_length, EvaluationSummary::min_desire, EvaluationSummary::min_length, CadetConnectionMetrics::num_acked_transmissions, CadetConnectionMetrics::num_successes, EvaluationSummary::path, GNUNET_TIME_Relative::rel_value_us, EvaluationSummary::worst, and EvaluationSummary::worst_score.

Referenced by consider_path_cb(), and maintain_connections_cb().

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

◆ consider_path_cb()

static int consider_path_cb ( void *  cls,
struct CadetPeerPath path,
unsigned int  off 
)
static

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
Returns
GNUNET_YES (should keep iterating)

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

2690 {
2691  struct CadetTunnel *t = cls;
2692  struct EvaluationSummary es;
2693  struct CadetTConnection *ct;
2694 
2695  GNUNET_assert (off < GCPP_get_length (path));
2697  off) == t->destination);
2698  es.min_length = UINT_MAX;
2699  es.max_length = 0;
2700  es.max_desire = 0;
2701  es.min_desire = UINT64_MAX;
2702  es.path = path;
2703  es.duplicate = GNUNET_NO;
2704  es.worst = NULL;
2705 
2706  /* Compute evaluation summary over existing connections. */
2708  "Evaluating proposed path %s for target %s\n",
2709  GCPP_2s (path),
2710  GCT_2s (t));
2711  /* FIXME: suspect this does not ACTUALLY iterate
2712  over all existing paths, otherwise dup detection
2713  should work!!! */
2716  &es);
2717  if (GNUNET_YES == es.duplicate)
2718  return GNUNET_YES;
2719 
2720  /* FIXME: not sure we should really just count
2721  'num_connections' here, as they may all have
2722  consistently failed to connect. */
2723 
2724  /* We iterate by increasing path length; if we have enough paths and
2725  this one is more than twice as long than what we are currently
2726  using, then ignore all of these super-long ones! */
2728  (es.min_length * 2 < off) &&
2729  (es.max_length < off))
2730  {
2732  "Ignoring paths of length %u, they are way too long.\n",
2733  es.min_length * 2);
2734  return GNUNET_NO;
2735  }
2736  /* If we have enough paths and this one looks no better, ignore it. */
2738  (es.min_length < GCPP_get_length (path)) &&
2739  (es.min_desire > GCPP_get_desirability (path)) &&
2740  (es.max_length < off))
2741  {
2743  "Ignoring path (%u/%llu) to %s, got something better already.\n",
2744  GCPP_get_length (path),
2745  (unsigned long long) GCPP_get_desirability (path),
2746  GCP_2s (t->destination));
2747  return GNUNET_YES;
2748  }
2749 
2750  /* Path is interesting (better by some metric, or we don't have
2751  enough paths yet). */
2752  ct = GNUNET_new (struct CadetTConnection);
2754  ct->t = t;
2755  ct->cc = GCC_create (t->destination,
2756  path,
2757  off,
2758  ct,
2760  ct);
2761 
2762  /* FIXME: schedule job to kill connection (and path?) if it takes
2763  too long to get ready! (And track performance data on how long
2764  other connections took with the tunnel!)
2765  => Note: to be done within 'connection'-logic! */
2766  GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
2767  t->connection_busy_tail,
2768  ct);
2769  t->num_busy_connections++;
2771  "Found interesting path %s for %s, created %s\n",
2772  GCPP_2s (path),
2773  GCT_2s (t),
2774  GCC_2s (ct->cc));
2775  return GNUNET_YES;
2776 }
struct CadetConnection * GCC_create(struct CadetPeer *destination, struct CadetPeerPath *path, unsigned int off, struct CadetTConnection *ct, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
unsigned int GCT_count_any_connections(const struct CadetTunnel *t)
Count all created connections of a tunnel.
static void connection_ready_cb(void *cls, int is_ready)
A connection is is_ready for transmission.
static void evaluate_connection(void *cls, struct CadetTConnection *ct)
Evaluate a connection, updating our summary information in cls about what kinds of connections we hav...
#define DESIRED_CONNECTIONS_PER_TUNNEL
How many connections would we like to have per tunnel?
struct GNUNET_TIME_Absolute created
Creation time, to keep oldest connection alive.

References CadetTConnection::cc, connection_ready_cb(), CadetTConnection::created, DESIRED_CONNECTIONS_PER_TUNNEL, EvaluationSummary::duplicate, evaluate_connection(), GCC_2s(), GCC_create(), GCP_2s(), GCPP_2s(), GCPP_get_desirability(), GCPP_get_length(), GCPP_get_peer_at_offset(), GCT_2s(), GCT_count_any_connections(), GCT_iterate_connections(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_NO, GNUNET_TIME_absolute_get(), GNUNET_YES, LOG, EvaluationSummary::max_desire, EvaluationSummary::max_length, EvaluationSummary::min_desire, EvaluationSummary::min_length, EvaluationSummary::path, CadetTConnection::t, t, and EvaluationSummary::worst.

Referenced by GCT_consider_path(), and maintain_connections_cb().

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

◆ maintain_connections_cb()

static void maintain_connections_cb ( void *  cls)
static

Function called to maintain the connections underlying our tunnel.

Tries to maintain (incl. tear down) connections for the tunnel, and if there is a significant change, may trigger transmissions.

Basically, needs to check if there are connections that perform badly, and if so eventually kill them and trigger a replacement. The strategy is to open one more connection than DESIRED_CONNECTIONS_PER_TUNNEL, and then periodically kick out the least-performing one, and then inquire for new ones.

Parameters
clsthe struct CadetTunnel

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

2794 {
2795  struct CadetTunnel *t = cls;
2796  struct GNUNET_TIME_Relative delay;
2797  struct EvaluationSummary es;
2798 
2799  t->maintain_connections_task = NULL;
2801  "Performing connection maintenance for %s.\n",
2802  GCT_2s (t));
2803 
2804  es.min_length = UINT_MAX;
2805  es.max_length = 0;
2806  es.max_desire = 0;
2807  es.min_desire = UINT64_MAX;
2808  es.path = NULL;
2809  es.worst = NULL;
2810  es.duplicate = GNUNET_NO;
2813  &es);
2814  if ((NULL != es.worst) &&
2816  {
2817  /* Clear out worst-performing connection 'es.worst'. */
2819  es.worst);
2820  }
2821 
2822  /* Consider additional paths */
2823  (void) GCP_iterate_paths (t->destination,
2825  t);
2826 
2827  /* FIXME: calculate when to try again based on how well we are doing;
2828  in particular, if we have to few connections, we might be able
2829  to do without this (as PATHS should tell us whenever a new path
2830  is available instantly; however, need to make sure this job is
2831  restarted after that happens).
2832  Furthermore, if the paths we do know are in a reasonably narrow
2833  quality band and are plentyful, we might also consider us stabilized
2834  and then reduce the frequency accordingly. */delay = GNUNET_TIME_UNIT_MINUTES;
2835  t->maintain_connections_task
2838  t);
2839 }
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
unsigned int GCP_iterate_paths(struct CadetPeer *cp, GCP_PathIterator callback, void *callback_cls)
Iterate over the paths to a peer.
static int consider_path_cb(void *cls, struct CadetPeerPath *path, unsigned int off)
Consider using the path p for the tunnel t.
static void maintain_connections_cb(void *cls)
Function called to maintain the connections underlying our tunnel.
#define GNUNET_TIME_UNIT_MINUTES
One minute.

References consider_path_cb(), delay, DESIRED_CONNECTIONS_PER_TUNNEL, destroy_t_connection(), EvaluationSummary::duplicate, evaluate_connection(), GCP_iterate_paths(), GCT_2s(), GCT_count_any_connections(), GCT_iterate_connections(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_MINUTES, LOG, EvaluationSummary::max_desire, EvaluationSummary::max_length, EvaluationSummary::min_desire, EvaluationSummary::min_length, EvaluationSummary::path, t, and EvaluationSummary::worst.

Referenced by GCT_create_tunnel().

Here is the call graph for this function:
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

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:

◆ handle_plaintext_keepalive()

static void handle_plaintext_keepalive ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

We got a keepalive.

Track in statistics.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
msgthe message we received on the tunnel

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

2875 {
2876  struct CadetTunnel *t = cls;
2877 
2879  "Received KEEPALIVE on %s\n",
2880  GCT_2s (t));
2882  "# keepalives received",
2883  1,
2884  GNUNET_NO);
2885 }

References GCT_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, stats, and t.

Here is the call graph for this function:

◆ check_plaintext_data()

static int check_plaintext_data ( void *  cls,
const struct GNUNET_CADET_ChannelAppDataMessage msg 
)
static

Check that msg is well-formed.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
msgthe message we received on the tunnel
Returns
GNUNET_OK (any variable-size payload goes)

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

2898 {
2899  return GNUNET_OK;
2900 }

References GNUNET_OK.

◆ handle_plaintext_data()

static void handle_plaintext_data ( void *  cls,
const struct GNUNET_CADET_ChannelAppDataMessage msg 
)
static

We received payload data for a channel.

Locate the channel and process the data, or return an error if the channel is unknown.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
msgthe message we received on the tunnel

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

2913 {
2914  struct CadetTunnel *t = cls;
2915  struct CadetChannel *ch;
2916 
2917  ch = lookup_channel (t,
2918  msg->ctn);
2919  if (NULL == ch)
2920  {
2921  /* We don't know about such a channel, might have been destroyed on our
2922  end in the meantime, or never existed. Send back a DESTROY. */
2924  "Received %u bytes of application data for unknown channel %u, sending DESTROY\n",
2925  (unsigned int) (ntohs (msg->header.size) - sizeof(*msg)),
2926  ntohl (msg->ctn.cn));
2928  msg->ctn);
2929  return;
2930  }
2932  GCC_get_id (t->current_ct->cc),
2933  msg);
2934 }
void GCCH_handle_channel_plaintext_data(struct CadetChannel *ch, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, const struct GNUNET_CADET_ChannelAppDataMessage *msg)
We got payload data for a channel.
void GCT_send_channel_destroy(struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
Send a DESTROY message via the tunnel.
struct CadetChannel * lookup_channel(struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
Lookup a channel by its ctn.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References ch, GCC_get_id(), GCCH_handle_channel_plaintext_data(), GCT_send_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, LOG, lookup_channel(), msg, GNUNET_MessageHeader::size, and t.

Here is the call graph for this function:

◆ handle_plaintext_data_ack()

static void handle_plaintext_data_ack ( void *  cls,
const struct GNUNET_CADET_ChannelDataAckMessage ack 
)
static

We received an acknowledgement for data we sent on a channel.

Locate the channel and process it, or return an error if the channel is unknown.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
ackthe message we received on the tunnel

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

2948 {
2949  struct CadetTunnel *t = cls;
2950  struct CadetChannel *ch;
2951 
2952  ch = lookup_channel (t,
2953  ack->ctn);
2954  if (NULL == ch)
2955  {
2956  /* We don't know about such a channel, might have been destroyed on our
2957  end in the meantime, or never existed. Send back a DESTROY. */
2959  "Received DATA_ACK for unknown channel %u, sending DESTROY\n",
2960  ntohl (ack->ctn.cn));
2962  ack->ctn);
2963  return;
2964  }
2966  GCC_get_id (t->current_ct->cc),
2967  ack);
2968 }
void GCCH_handle_channel_plaintext_data_ack(struct CadetChannel *ch, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, const struct GNUNET_CADET_ChannelDataAckMessage *ack)
We got an acknowledgement for payload data for a channel.
struct GNUNET_CADET_ChannelTunnelNumber ctn
ID of the channel.

References ch, GNUNET_CADET_ChannelTunnelNumber::cn, GNUNET_CADET_ChannelDataAckMessage::ctn, GCC_get_id(), GCCH_handle_channel_plaintext_data_ack(), GCT_send_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, LOG, lookup_channel(), and t.

Here is the call graph for this function:

◆ handle_plaintext_channel_open()

static void handle_plaintext_channel_open ( void *  cls,
const struct GNUNET_CADET_ChannelOpenMessage copen 
)
static

We have received a request to open a channel to a port from another peer.

Creates the incoming channel.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
copenthe message we received on the tunnel

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

2982 {
2983  struct CadetTunnel *t = cls;
2984  struct CadetChannel *ch;
2985 
2987  ntohl (copen->ctn.cn));
2988  if (NULL != ch)
2989  {
2991  "Received duplicate channel CHANNEL_OPEN on h_port %s from %s (%s), resending ACK\n",
2992  GNUNET_h2s (&copen->h_port),
2993  GCT_2s (t),
2994  GCCH_2s (ch));
2996  GCC_get_id (t->current_ct->cc));
2997  return;
2998  }
3000  "Received CHANNEL_OPEN on h_port %s from %s\n",
3001  GNUNET_h2s (&copen->h_port),
3002  GCT_2s (t));
3004  copen->ctn,
3005  &copen->h_port,
3006  ntohl (copen->opt));
3007  if (NULL != t->destroy_task)
3008  {
3009  GNUNET_SCHEDULER_cancel (t->destroy_task);
3010  t->destroy_task = NULL;
3011  }
3014  ntohl (copen->ctn.cn),
3015  ch,
3017 }
void GCCH_handle_duplicate_open(struct CadetChannel *ch, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
We got a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN message again for this channel.
struct CadetChannel * GCCH_channel_incoming_new(struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn, const struct GNUNET_HashCode *h_port, uint32_t options)
Create a new channel based on a request coming in over the network.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_HashCode h_port
Hash of destination port and listener.
struct GNUNET_CADET_ChannelTunnelNumber ctn
ID of the channel within the tunnel.
uint32_t opt
Channel options.

References ch, GNUNET_CADET_ChannelTunnelNumber::cn, GNUNET_CADET_ChannelOpenMessage::ctn, GCC_get_id(), GCCH_2s(), GCCH_channel_incoming_new(), GCCH_handle_duplicate_open(), GCT_2s(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_get(), GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_CADET_ChannelOpenMessage::h_port, LOG, GNUNET_CADET_ChannelOpenMessage::opt, and t.

Here is the call 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 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...
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
Ask the cadet service to destroy a channel.
Message to destroy a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
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.

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:

◆ handle_plaintext_channel_open_ack()

static void handle_plaintext_channel_open_ack ( void *  cls,
const struct GNUNET_CADET_ChannelOpenAckMessage cm 
)
static

We have received confirmation from the target peer that the given channel could be established (the port is open).

Tell the client.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
cmthe message we received on the tunnel

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

3059 {
3060  struct CadetTunnel *t = cls;
3061  struct CadetChannel *ch;
3062 
3063  ch = lookup_channel (t,
3064  cm->ctn);
3065  if (NULL == ch)
3066  {
3067  /* We don't know about such a channel, might have been destroyed on our
3068  end in the meantime, or never existed. Send back a DESTROY. */
3070  "Received channel OPEN_ACK for unknown channel %u, sending DESTROY\n",
3071  ntohl (cm->ctn.cn));
3073  cm->ctn);
3074  return;
3075  }
3077  "Received channel OPEN_ACK on channel %s from %s\n",
3078  GCCH_2s (ch),
3079  GCT_2s (t));
3081  GCC_get_id (t->current_ct->cc),
3082  &cm->port);
3083 }
void GCCH_handle_channel_open_ack(struct CadetChannel *ch, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, const struct GNUNET_HashCode *port)
We got an acknowledgement for the creation of the channel (the port is open on the other side).
struct GNUNET_HashCode port
Port number of the channel, used to prove to the initiator that the receiver knows the port.
struct GNUNET_CADET_ChannelTunnelNumber ctn
ID of the channel.

References ch, GNUNET_CADET_ChannelTunnelNumber::cn, GNUNET_CADET_ChannelOpenAckMessage::ctn, GCC_get_id(), GCCH_2s(), GCCH_handle_channel_open_ack(), GCT_2s(), GCT_send_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, LOG, lookup_channel(), GNUNET_CADET_ChannelOpenAckMessage::port, and t.

Here is the call graph for this function:

◆ handle_plaintext_channel_destroy()

static void handle_plaintext_channel_destroy ( void *  cls,
const struct GNUNET_CADET_ChannelDestroyMessage cm 
)
static

We received a message saying that a channel should be destroyed.

Pass it on to the correct channel.

Parameters
clsthe struct CadetTunnel for which we decrypted the message
cmthe message we received on the tunnel

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

3097 {
3098  struct CadetTunnel *t = cls;
3099  struct CadetChannel *ch;
3100 
3101  ch = lookup_channel (t,
3102  cm->ctn);
3103  if (NULL == ch)
3104  {
3105  /* We don't know about such a channel, might have been destroyed on our
3106  end in the meantime, or never existed. */
3108  "Received channel DESTROY for unknown channel %u. Ignoring.\n",
3109  ntohl (cm->ctn.cn));
3110  return;
3111  }
3113  "Received channel DESTROY on %s from %s\n",
3114  GCCH_2s (ch),
3115  GCT_2s (t));
3117  GCC_get_id (t->current_ct->cc));
3118 }

References ch, GNUNET_CADET_ChannelTunnelNumber::cn, GNUNET_CADET_ChannelDestroyMessage::ctn, GCC_get_id(), GCCH_2s(), GCCH_handle_remote_destroy(), GCT_2s(), GNUNET_ERROR_TYPE_DEBUG, LOG, lookup_channel(), and t.

Here is the call graph for this function:

◆ handle_decrypted()

static int handle_decrypted ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handles a message we decrypted, by injecting it into our message queue (which will do the dispatching).

Parameters
clsthe struct CadetTunnel that got the message
msgthe message
Returns
GNUNET_OK on success (always) GNUNET_NO to stop further processing (no error) GNUNET_SYSERR to stop further processing with error

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

3134 {
3135  struct CadetTunnel *t = cls;
3136 
3137  GNUNET_assert (NULL != t->current_ct);
3139  msg);
3140  return GNUNET_OK;
3141 }
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
Definition: mq.c:202

References GNUNET_assert, GNUNET_MQ_inject_message(), GNUNET_OK, msg, and t.

Referenced by GCT_create_tunnel().

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

◆ decrypted_error_cb()

static void decrypted_error_cb ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Function called if we had an error processing an incoming decrypted message.

Parameters
clsthe struct CadetTunnel
errorerror code

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

3154 {
3155  GNUNET_break_op (0);
3156 }

References GNUNET_break_op.

Referenced by GCT_create_tunnel().

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 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.
#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_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
#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_OPEN_ACK
Confirm the creation of a channel.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
Message for cadet data traffic.
Message to acknowledge end-to-end data.
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.

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_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
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 }
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.

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_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 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

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_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.
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 }
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_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.
#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.
struct GNUNET_CADET_ChannelTunnelNumber ctn
Number identifying this channel in its tunnel.
uint32_t PNs
Number of messages sent with the previous ratchet key.
struct GNUNET_CRYPTO_EcdhePublicKey DHRs
Current ratchet key.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.

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
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_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:

◆ iterate_channels_cb()

static int iterate_channels_cb ( void *  cls,
uint32_t  key,
void *  value 
)
static

Helper function for GCT_iterate_channels.

Parameters
clsthe struct ChanIterCls
keyunused
valuea struct CadetChannel
Returns
GNUNET_OK

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

3625 {
3626  struct ChanIterCls *ctx = cls;
3627  struct CadetChannel *ch = value;
3628 
3629  ctx->iter (ctx->iter_cls,
3630  ch);
3631  return GNUNET_OK;
3632 }
Closure for iterate_channels_cb.

References ch, ctx, GNUNET_OK, and value.

Referenced by GCT_iterate_channels().

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

◆ debug_channel()

static int debug_channel ( void *  cls,
uint32_t  key,
void *  value 
)
static

Call GCCH_debug() on a channel.

Parameters
clspoints to the log level to use
keyunused
valuethe struct CadetChannel to dump
Returns
GNUNET_OK (continue iteration)

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

3669 {
3670  const enum GNUNET_ErrorType *level = cls;
3671  struct CadetChannel *ch = value;
3672 
3673  GCCH_debug (ch, *level);
3674  return GNUNET_OK;
3675 }
void GCCH_debug(struct CadetChannel *ch, enum GNUNET_ErrorType level)
Log channel info.
GNUNET_ErrorType
Types of errors.

References ch, GCCH_debug(), GNUNET_OK, and value.

Referenced by GCT_debug().

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.
#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: