GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
gnunet-service-cadet_tunnels.h File Reference

Information we track per tunnel. More...

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

Go to the source code of this file.

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Detailed Description

Information we track per tunnel.

Author
Bartlomiej Polot
Christian Grothoff

Definition in file gnunet-service-cadet_tunnels.h.

Macro Definition Documentation

◆ DESIRED_CONNECTIONS_PER_TUNNEL

#define DESIRED_CONNECTIONS_PER_TUNNEL   3

How many connections would we like to have per tunnel?

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

Typedef Documentation

◆ GCT_SendContinuation

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

Function called when a transmission requested using GCT_send is done.

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

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

◆ GCT_ConnectionIterator

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

Iterator over connections.

Parameters
clsclosure
ctone of the connections

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

◆ GCT_ChannelIterator

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

Iterator over channels.

Parameters
clsclosure
chone of the channels

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

Enumeration Type Documentation

◆ CadetTunnelEState

All the encryption states a tunnel can be in.

Enumerator
CADET_TUNNEL_KEY_UNINITIALIZED 

Uninitialized status, we need to send KX.

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

CADET_TUNNEL_KEY_AX_SENT 

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

CADET_TUNNEL_KEY_AX_RECV 

KX message received, trying to send back KX_AUTH.

CADET_TUNNEL_KEY_AX_SENT_AND_RECV 

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

CADET_TUNNEL_KEY_AX_AUTH_SENT 

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

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

CADET_TUNNEL_KEY_OK 

Handshake completed: session key available.

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

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

Function Documentation

◆ GCT_alice_or_betty()

int GCT_alice_or_betty ( const struct GNUNET_PeerIdentity other)

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

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

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

541{
542 const struct GNUNET_PeerIdentity *my_identity;
543
546
547 if (0 > GNUNET_memcmp (my_identity, other))
548 return GNUNET_YES;
549 else if (0 < GNUNET_memcmp (my_identity, other))
550 return GNUNET_NO;
551 else
552 {
553 GNUNET_break_op (0);
554 return GNUNET_SYSERR;
555 }
556}
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The identity of the host (wraps the signing key of the peer).

References GNUNET_assert, GNUNET_break_op, GNUNET_memcmp, GNUNET_NO, GNUNET_PILS_get_identity(), GNUNET_SYSERR, GNUNET_YES, my_identity, and pils.

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

Here is the call graph for this function:
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 592 of file gnunet-service-cadet_tunnels.c.

593{
594 static char buf[64];
595
596 if (NULL == t)
597 return "Tunnel(NULL)";
598 GNUNET_snprintf (buf,
599 sizeof(buf),
600 "Tunnel %s",
601 GNUNET_i2s (GCP_get_id (t->destination)));
602 return buf;
603}
static struct GNUNET_SCHEDULER_Task * t
Main task.
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
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 GCP_get_id(), GNUNET_i2s(), GNUNET_snprintf(), and t.

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

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

◆ GCT_create_tunnel()

struct CadetTunnel * GCT_create_tunnel ( struct CadetPeer destination)

Create a tunnel to destination.

Must only be called from within GCP_get_tunnel().

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

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

3245{
3246 struct CadetTunnel *t = GNUNET_new (struct CadetTunnel);
3248 GNUNET_MQ_hd_fixed_size (plaintext_keepalive,
3250 struct GNUNET_MessageHeader,
3251 t),
3252 GNUNET_MQ_hd_var_size (plaintext_data,
3255 t),
3256 GNUNET_MQ_hd_fixed_size (plaintext_data_ack,
3259 t),
3260 GNUNET_MQ_hd_fixed_size (plaintext_channel_open,
3263 t),
3264 GNUNET_MQ_hd_fixed_size (plaintext_channel_open_ack,
3267 t),
3268 GNUNET_MQ_hd_fixed_size (plaintext_channel_destroy,
3271 t),
3273 };
3274
3275 t->kx_retry_delay = INITIAL_KX_RETRY_DELAY;
3276 new_ephemeral (&t->ax);
3278 t->destination = destination;
3280 t->maintain_connections_task
3282 t);
3283 t->mq = GNUNET_MQ_queue_for_callbacks (NULL,
3284 NULL,
3285 NULL,
3286 NULL,
3287 handlers,
3289 t);
3291 t);
3292 return t;
3293}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
static void new_ephemeral(struct CadetTunnelAxolotl *ax)
Create a new Axolotl ephemeral (ratchet) key.
static int handle_decrypted(void *cls, const struct GNUNET_MessageHeader *msg)
Handles a message we decrypted, by injecting it into our message queue (which will do the dispatching...
static void decrypted_error_cb(void *cls, enum GNUNET_MQ_Error error)
Function called if we had an error processing an incoming decrypted message.
static void maintain_connections_cb(void *cls)
Function called to maintain the connections underlying our tunnel.
#define INITIAL_KX_RETRY_DELAY
How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have co...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition crypto_ecc.c:454
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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:482
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
Ask the cadet service to create a new channel.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
Confirm payload data end-to-end.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA
Payload data (inside an encrypted tunnel).
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE
Announce connection is still alive (direction sensitive).
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
Ask the cadet service to destroy a channel.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
Confirm the creation of a channel.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition mst.c:86
Struct containing all information regarding a tunnel to a peer.
Message for cadet data traffic.
Message to acknowledge end-to-end data.
Message to destroy a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
Message to acknowledge opening a channel of type GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
Message to create a Channel.
Message handler for a specific message type.
Header for all communications.

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

Referenced by GCP_get_tunnel().

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

◆ GCT_destroy_tunnel_now()

void GCT_destroy_tunnel_now ( struct CadetTunnel t)

Destroys the tunnel t now, without delay.

Used during shutdown.

Parameters
ttunnel to destroy

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

2413{
2417 t);
2418 GNUNET_assert (0 ==
2420 if (NULL != t->destroy_task)
2421 {
2422 GNUNET_SCHEDULER_cancel (t->destroy_task);
2423 t->destroy_task = NULL;
2424 }
2425 destroy_tunnel (t);
2426}
int shutting_down
Signal that shutdown is happening: prevent recovery measures.
unsigned int GCT_count_channels(struct CadetTunnel *t)
Returns the number of channels using a tunnel.
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
static int destroy_remaining_channels(void *cls, uint32_t key, void *value)
Destroy remaining channels during shutdown.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986

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

Referenced by destroy_tunnels_now().

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

◆ GCT_add_inbound_connection()

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

Add a connection to the tunnel.

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

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

3301{
3302 struct CadetTConnection *ct;
3303
3304 ct = GNUNET_new (struct CadetTConnection);
3306 ct->t = t;
3307 ct->cc = GCC_create_inbound (t->destination,
3308 path,
3309 ct,
3310 cid,
3312 ct);
3313 if (NULL == ct->cc)
3314 {
3316 "%s refused inbound %s (duplicate)\n",
3317 GCT_2s (t),
3318 GCC_2s (ct->cc));
3319 GNUNET_free (ct);
3320 return GNUNET_SYSERR;
3321 }
3322 /* FIXME: schedule job to kill connection (and path?) if it takes
3323 too long to get ready! (And track performance data on how long
3324 other connections took with the tunnel!)
3325 => Note: to be done within 'connection'-logic! */
3326 GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
3327 t->connection_busy_tail,
3328 ct);
3329 t->num_busy_connections++;
3331 "%s has new %s\n",
3332 GCT_2s (t),
3333 GCC_2s (ct->cc));
3334 return GNUNET_OK;
3335}
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
struct CadetConnection * GCC_create_inbound(struct CadetPeer *destination, struct CadetPeerPath *path, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
static void connection_ready_cb(void *cls, int is_ready)
A connection is is_ready for transmission.
#define LOG(level,...)
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
Entry in list of connections used by tunnel, with metadata.
struct CadetConnection * cc
Connection handle.
struct GNUNET_TIME_Absolute created
Creation time, to keep oldest connection alive.
struct CadetTunnel * t
Tunnel this connection belongs to.

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

Referenced by handle_connection_create().

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

◆ GCT_connection_lost()

void GCT_connection_lost ( struct CadetTConnection ct)

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

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

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

2249{
2250 struct CadetTunnel *t = ct->t;
2251
2252 if (GNUNET_YES == ct->is_ready)
2253 {
2254 GNUNET_CONTAINER_DLL_remove (t->connection_ready_head,
2255 t->connection_ready_tail,
2256 ct);
2257 t->num_ready_connections--;
2258 }
2259 else
2260 {
2261 GNUNET_CONTAINER_DLL_remove (t->connection_busy_head,
2262 t->connection_busy_tail,
2263 ct);
2264 t->num_busy_connections--;
2265 }
2266 GNUNET_free (ct);
2267}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int is_ready
Is the connection currently ready for transmission?

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

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

Here is the caller graph for this function:

◆ GCT_get_destination()

struct CadetPeer * GCT_get_destination ( struct CadetTunnel t)

Return the peer to which this tunnel goes.

Parameters
ta tunnel
Returns
the destination of the tunnel

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

649{
650 return t->destination;
651}

References t.

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

Here is the caller graph for this function:

◆ GCT_consider_path()

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

Consider using the path p for the tunnel t.

The tunnel destination is at offset off in path p.

Parameters
tour tunnel
pa path to our destination
offoffset of the destination on path path

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

2931{
2933 "Considering %s for %s (offset %u)\n",
2934 GCPP_2s (p),
2935 GCT_2s (t),
2936 off);
2937 (void) consider_path_cb (t,
2938 p,
2939 off);
2940}
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
static int consider_path_cb(void *cls, struct CadetPeerPath *path, unsigned int off)
Consider using the path p for the tunnel t.
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38

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

Referenced by GCP_path_entry_add(), and GCP_set_mq().

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

◆ GCT_add_channel()

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

Add a channel to a tunnel.

Parameters
tTunnel.
chChannel
Returns
unique number identifying ch within t

Add a channel to a tunnel.

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

Parameters
tTunnel.
chChannel
Returns
unique number identifying ch within t

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

2191{
2193
2194 ctn = get_next_free_ctn (t);
2195 if (NULL != t->destroy_task)
2196 {
2197 GNUNET_SCHEDULER_cancel (t->destroy_task);
2198 t->destroy_task = NULL;
2199 }
2202 ntohl (ctn.cn),
2203 ch,
2206 "Adding %s to %s with state %d\n",
2207 GCCH_2s (ch),
2208 GCT_2s (t),
2209 t->estate);
2210 switch (t->estate)
2211 {
2213 /* waiting for connection to start KX */
2214 break;
2215
2219 /* we're currently waiting for KX to complete */
2220 break;
2221
2223 /* waiting for OTHER peer to send us data,
2224 we might need to prompt more aggressively! */
2225 if (NULL == t->kx_task)
2226 t->kx_task
2227 = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2228 &retry_kx,
2229 t);
2230 break;
2231
2233 /* We are ready. Tell the new channel that we are up. */
2235 break;
2236 }
2237 return ctn;
2238}
static struct GNUNET_CADET_Channel * ch
Channel handle.
const char * GCCH_2s(const struct CadetChannel *ch)
Get the static string for identification of the channel.
void GCCH_tunnel_up(struct CadetChannel *ch)
Function called once and only once after a channel was bound to its tunnel via GCT_add_channel() is r...
static struct GNUNET_CADET_ChannelTunnelNumber get_next_free_ctn(struct CadetTunnel *t)
Compute the next free channel tunnel number for this tunnel.
static void retry_kx(void *cls)
Try to redo the KX or KX_AUTH handshake, if we can.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition scheduler.c:1260
Number identifying a CADET channel within a tunnel.

References CADET_TUNNEL_KEY_AX_AUTH_SENT, CADET_TUNNEL_KEY_AX_RECV, CADET_TUNNEL_KEY_AX_SENT, CADET_TUNNEL_KEY_AX_SENT_AND_RECV, CADET_TUNNEL_KEY_OK, CADET_TUNNEL_KEY_UNINITIALIZED, ch, GNUNET_CADET_ChannelTunnelNumber::cn, GCCH_2s(), GCCH_tunnel_up(), GCT_2s(), get_next_free_ctn(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, LOG, retry_kx(), and t.

Referenced by GCCH_channel_local_new().

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

◆ GCT_remove_channel()

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

Remove a channel from a tunnel.

Parameters
tTunnel.
chChannel
ctnunique number identifying ch within t

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

2364{
2366 "Removing %s from %s\n",
2367 GCCH_2s (ch),
2368 GCT_2s (t));
2371 ntohl (ctn.cn),
2372 ch));
2373 if ((0 ==
2374 GCT_count_channels (t)) &&
2375 (NULL == t->destroy_task))
2376 {
2377 t->destroy_task
2380 t);
2381 }
2382}
#define IDLE_DESTROY_DELAY
How long do we wait until tearing down an idle tunnel?
enum GNUNET_GenericReturnValue 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:1283
uint32_t cn
Which number does this channel have that uniquely identifies it within its tunnel,...

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

Referenced by channel_destroy().

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

◆ GCT_send_channel_destroy()

void GCT_send_channel_destroy ( struct CadetTunnel t,
struct GNUNET_CADET_ChannelTunnelNumber  ctn 
)

Send a DESTROY message via the tunnel.

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

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

3106{
3108
3110 "Sending DESTROY message for channel ID %u\n",
3111 ntohl (ctn.cn));
3112 msg.header.size = htons (sizeof(msg));
3114 msg.reserved = htonl (0);
3115 msg.ctn = ctn;
3116 GCT_send (t,
3117 &msg.header,
3118 NULL,
3119 NULL,
3120 &ctn);
3121}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct CadetTunnelQueueEntry * GCT_send(struct CadetTunnel *t, const struct GNUNET_MessageHeader *message, GCT_SendContinuation cont, void *cont_cls, struct GNUNET_CADET_ChannelTunnelNumber *ctn)
Sends an already built message on a tunnel, encrypting it and choosing the best connection if not pro...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_CADET_ChannelTunnelNumber ctn
ID of the channel.

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

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

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

◆ GCT_send()

struct CadetTunnelQueueEntry * GCT_send ( struct CadetTunnel t,
const struct GNUNET_MessageHeader message,
GCT_SendContinuation  cont,
void *  cont_cls,
struct GNUNET_CADET_ChannelTunnelNumber ctn 
)

Sends an already built message on a tunnel, encrypting it and choosing the best connection if not provided.

Parameters
messageMessage to send. Function modifies it.
tTunnel on which this message is transmitted.
contContinuation to call once message is really sent.
cont_clsClosure for cont.
Returns
Handle to cancel message.

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

3525{
3526 struct CadetTunnelQueueEntry *tq;
3527 uint16_t message_size;
3528 uint16_t payload_size;
3529 struct GNUNET_MQ_Envelope *env;
3531 struct CadetChannel *ch;
3532
3533 if (NULL != ctn)
3534 {
3535 ch = lookup_channel (t,
3536 *ctn);
3537 if ((NULL != ch) && GCCH_is_type_to_drop (ch, message))
3538 {
3539 GNUNET_break (0);
3540 return NULL;
3541 }
3542 }
3543
3544 if (CADET_TUNNEL_KEY_OK != t->estate)
3545 {
3546 GNUNET_break (0);
3547 return NULL;
3548 }
3549 message_size = ntohs (message->size);
3550 payload_size = message_size + sizeof (struct GNUNET_CRYPTO_AeadMac);
3552 "Encrypting %u bytes for %s\n",
3553 (unsigned int) message_size,
3554 GCT_2s (t));
3555 env = GNUNET_MQ_msg_extra (ax_msg,
3556 payload_size,
3558 t_ax_encrypt (&t->ax,
3559 &ax_msg[1],
3560 message,
3561 message_size);
3563 "# encrypted bytes",
3564 payload_size,
3565 GNUNET_NO);
3566 ax_msg->ax_header.Ns = htonl (t->ax.Ns++);
3567 ax_msg->ax_header.PNs = htonl (t->ax.PNs);
3568 /* FIXME: we should do this once, not once per message;
3569 this is a point multiplication, and DHRs does not
3570 change all the time. */
3572 &ax_msg->ax_header.DHRs);
3573 t_h_encrypt (&t->ax,
3574 ax_msg,
3575 payload_size,
3576 (unsigned char*) &ax_msg[1]);
3577
3578 tq = GNUNET_malloc (sizeof(*tq));
3579 tq->t = t;
3580 tq->env = env;
3581 tq->cid = &ax_msg->cid; /* will initialize 'ax_msg->cid' once we know the connection */
3582 tq->cont = cont;
3583 tq->cont_cls = cont_cls;
3585 t->tq_tail,
3586 tq);
3587 if (NULL != t->send_task)
3588 GNUNET_SCHEDULER_cancel (t->send_task);
3589 t->send_task
3591 t);
3592 return tq;
3593}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
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 struct CadetChannel * lookup_channel(struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn)
Lookup a channel by its ctn.
static void t_h_encrypt(struct CadetTunnelAxolotl *ax, struct GNUNET_CADET_TunnelEncryptedMessage *msg, size_t additional_data_size, const unsigned char *additional_data)
Encrypt header with the axolotl header key.
static void trigger_transmissions(void *cls)
Called when either we have a new connection, or a new message in the queue, or some existing connecti...
static void t_ax_encrypt(struct CadetTunnelAxolotl *ax, void *dst, const void *src, size_t size)
Encrypt data with the axolotl tunnel key.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
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:217
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
Axolotl encrypted data.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Struct containing all information regarding a channel to a remote client.
struct GNUNET_CADET_ChannelTunnelNumber ctn
Number identifying this channel in its tunnel.
Struct used to save messages in a non-ready tunnel to send once connected.
struct GNUNET_MQ_Envelope * env
Envelope of message to send follows.
GCT_SendContinuation cont
Continuation to call once sent (on the channel layer).
struct GNUNET_CADET_ConnectionTunnelIdentifier * cid
Where to put the connection identifier into the payload of the message in env once we have it?
struct CadetTunnel * t
Tunnel these messages belong in.
uint32_t PNs
Number of messages sent with the previous ratchet key.
struct GNUNET_CRYPTO_EcdhePublicKey DHRs
Current ratchet key.
uint32_t Ns
Number of messages sent with the current ratchet key.
Axolotl-encrypted tunnel message with application payload.
struct GNUNET_CADET_AxHeader ax_header
Axolotl-header that specifies which keys to use in which ratchet to decrypt the body that follows.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
type for session keys

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(), LOG, lookup_channel(), GNUNET_CADET_AxHeader::Ns, GNUNET_CADET_AxHeader::PNs, GNUNET_MessageHeader::size, stats, t, CadetTunnelQueueEntry::t, t_ax_encrypt(), t_h_encrypt(), 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 q)

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

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

Parameters
qHandle to the queue entry to cancel.

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

3598{
3599 struct CadetTunnel *t = tq->t;
3600
3602 t->tq_tail,
3603 tq);
3604 GNUNET_MQ_discard (tq->env);
3605 GNUNET_free (tq);
3606}
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition mq.c:285

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

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

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

◆ GCT_count_channels()

unsigned int GCT_count_channels ( struct CadetTunnel t)

Returns the number of channels using a tunnel.

Parameters
tTunnel in question.
Returns
Number of channels using the tunnel.

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

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

References GNUNET_CONTAINER_multihashmap32_size(), and t.

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

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

◆ GCT_count_any_connections()

unsigned int GCT_count_any_connections ( const struct CadetTunnel t)

Counts the number of connections created for a tunnel, including busy connections.

Parameters
tTunnel to be counted.
Returns
Number of connections created for the tunnel.

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

679{
680 return t->num_ready_connections + t->num_busy_connections;
681}

References t.

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

Here is the caller graph for this function:

◆ GCT_iterate_connections()

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

Iterate over all connections of a tunnel.

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

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

3620{
3621 struct CadetTConnection *n;
3622
3623 for (struct CadetTConnection *ct = t->connection_ready_head;
3624 NULL != ct;
3625 ct = n)
3626 {
3627 n = ct->next;
3628 iter (iter_cls,
3629 ct);
3630 }
3631 for (struct CadetTConnection *ct = t->connection_busy_head;
3632 NULL != ct;
3633 ct = n)
3634 {
3635 n = ct->next;
3636 iter (iter_cls,
3637 ct);
3638 }
3639}
struct CadetTConnection * next
Next in DLL.

References CadetTConnection::next, and t.

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

Here is the caller graph for this function:

◆ GCT_iterate_channels()

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

Iterate over all channels of a tunnel.

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

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

3692{
3693 struct ChanIterCls ctx;
3694
3695 ctx.iter = iter;
3696 ctx.iter_cls = iter_cls;
3699 &ctx);
3700}
static struct GNUNET_FS_Handle * ctx
static int iterate_channels_cb(void *cls, uint32_t key, void *value)
Helper function for GCT_iterate_channels.
Closure for iterate_channels_cb.
void * iter_cls
Closure for iter.
GCT_ChannelIterator iter
Function to call.

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

Here is the call graph for this function:

◆ GCT_get_estate()

enum CadetTunnelEState GCT_get_estate ( struct CadetTunnel t)

Get the encryption state of a tunnel.

Parameters
tTunnel.
Returns
Tunnel's encryption state.

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

711{
712 return t->estate;
713}

References t.

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

Here is the caller graph for this function:

◆ GCT_change_estate()

void GCT_change_estate ( struct CadetTunnel t,
enum CadetTunnelEState  state 
)

Change the tunnel encryption state.

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

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

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

1332{
1333 enum CadetTunnelEState old = t->estate;
1334
1335 t->estate = state;
1337 "%s estate changed from %s to %s\n",
1338 GCT_2s (t),
1339 estate2s (old),
1340 estate2s (state));
1341
1342 if ((CADET_TUNNEL_KEY_OK != old) &&
1343 (CADET_TUNNEL_KEY_OK == t->estate))
1344 {
1345 if (NULL != t->kx_task)
1346 {
1347 GNUNET_SCHEDULER_cancel (t->kx_task);
1348 t->kx_task = NULL;
1349 }
1350 /* notify all channels that have been waiting */
1353 t);
1354 if (NULL != t->send_task)
1355 GNUNET_SCHEDULER_cancel (t->send_task);
1357 t);
1358 }
1359}
static int state
The current state of the parser.
static int notify_tunnel_up_cb(void *cls, uint32_t key, void *value)
Our tunnel became ready for the first time, notify channels that have been waiting.
static const char * estate2s(enum CadetTunnelEState es)
Get string description for tunnel encryption state.
CadetTunnelEState
All the encryption states a tunnel can be in.

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

Referenced by cont_GCT_handle_kx(), cont_GCT_handle_kx_auth(), GCT_handle_encrypted(), handle_connection_create(), send_kx(), and send_kx_auth().

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

◆ GCT_handle_kx()

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

Handle KX message that lacks authentication (and which will thus only be considered authenticated after we respond with our own KX_AUTH and finally successfully decrypt the payload).

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

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 the payload).

Parameters
clsclosure from updating AX by KX
retresult from the update call

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

1817{
1818 struct CadetTunnel *t = ct->t;
1819
1821 "# KX received",
1822 1,
1823 GNUNET_NO);
1824 if (GNUNET_YES ==
1825 GCT_alice_or_betty (GCP_get_id (t->destination)))
1826 {
1827 /* Betty/Bob is not allowed to send KX! */
1828 GNUNET_break_op (0);
1829 return;
1830 }
1832 "Received KX message from %s with ephemeral %s from %s on connection %s\n",
1833 GCT_2s (t),
1834 GNUNET_e2s (&msg->ephemeral_key),
1835 GNUNET_i2s (GCP_get_id (t->destination)),
1836 GCC_2s (ct->cc));
1837#if 1
1838 if ((0 ==
1839 memcmp (&t->ax.DHRr,
1840 &msg->ratchet_key,
1841 sizeof(msg->ratchet_key))) &&
1842 (0 ==
1843 memcmp (&t->ax.last_ephemeral,
1844 &msg->ephemeral_key,
1845 sizeof(msg->ephemeral_key))))
1846
1847 {
1849 "# Duplicate KX received",
1850 1,
1851 GNUNET_NO);
1852 send_kx_auth (t,
1853 ct,
1854 &t->ax,
1855 GNUNET_NO);
1856 return;
1857 }
1858#endif
1859 /* We only keep ONE unverified KX around, so if there is an existing one,
1860 clean it up. */
1861 if (NULL != t->unverified_ax)
1862 {
1863 if ((0 ==
1864 memcmp (&t->unverified_ax->DHRr,
1865 &msg->ratchet_key,
1866 sizeof(msg->ratchet_key))) &&
1867 (0 ==
1868 memcmp (&t->unverified_ax->last_ephemeral,
1869 &msg->ephemeral_key,
1870 sizeof(msg->ephemeral_key))))
1871 {
1873 "# Duplicate unverified KX received",
1874 1,
1875 GNUNET_NO);
1876#if 1
1877 send_kx_auth (t,
1878 ct,
1879 t->unverified_ax,
1880 GNUNET_NO);
1881 return;
1882#endif
1883 }
1884 if ((t->as.ecdh_op) &&
1885 (0 ==
1886 memcmp (&t->as.ratchet_key,
1887 &msg->ratchet_key,
1888 sizeof(msg->ratchet_key))) &&
1889 (0 ==
1890 memcmp (&t->as.ephemeral_key,
1891 &msg->ephemeral_key,
1892 sizeof(msg->ephemeral_key))))
1893 {
1895 "Waiting for previous ECDH operation\n");
1896 return;
1897 }
1899 "Dropping old unverified KX state.\n");
1901 "# Unverified KX dropped for fresh KX",
1902 1,
1903 GNUNET_NO);
1904 GNUNET_break (NULL == t->unverified_ax->skipped_head);
1905 memset (t->unverified_ax,
1906 0,
1907 sizeof(struct CadetTunnelAxolotl));
1908 }
1909 else
1910 {
1912 "Creating fresh unverified KX for %s\n",
1913 GCT_2s (t));
1915 "# Fresh KX setup",
1916 1,
1917 GNUNET_NO);
1918 t->unverified_ax = GNUNET_new (struct CadetTunnelAxolotl);
1919 }
1920 /* Set as the 'current' RK/DHRr the one we are currently using,
1921 so that the duplicate-detection logic of
1922 #update_ax_by_kx can work. */
1923 t->unverified_ax->RK = t->ax.RK;
1924 t->unverified_ax->DHRr = t->ax.DHRr;
1925 t->unverified_ax->DHRs = t->ax.DHRs;
1926 t->unverified_ax->kx_0 = t->ax.kx_0;
1927 t->unverified_attempts = 0;
1928
1929 t->as.ax = *(t->unverified_ax);
1930 GNUNET_memcpy (&t->as.peer_id, GCP_get_id (t->destination),
1931 sizeof (t->as.peer_id));
1932 GNUNET_memcpy (&t->as.ephemeral_key, &msg->ephemeral_key,
1933 sizeof (t->as.ephemeral_key));
1934 GNUNET_memcpy (&t->as.ratchet_key, &msg->ratchet_key,
1935 sizeof (t->as.ratchet_key));
1936 memset (&t->as.auth, 0, sizeof (t->as.auth));
1937 t->as.flags = 0;
1938 t->as.cb_cls = t;
1939 t->as.cb = &cont_GCT_handle_kx;
1940
1941 if (t->as.ecdh_op)
1942 {
1944 "Cancelling previous ECDH operation\n");
1945
1946 GNUNET_PILS_cancel (t->as.ecdh_op);
1947 }
1948
1949 t->as.ecdh_op = GNUNET_PILS_ecdh (pils, &msg->ephemeral_key,
1950 &update_ax_by_kx, &t->as);
1951}
static void cont_GCT_handle_kx(void *cls, enum GNUNET_GenericReturnValue ret)
Continue to handle KX message.
static void send_kx_auth(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax, int force_reply)
Send a KX_AUTH message.
int GCT_alice_or_betty(const struct GNUNET_PeerIdentity *other)
Am I Alice or Betty (some call her Bob), or talking to myself?
static void update_ax_by_kx(void *cls, const struct GNUNET_HashCode *key_result)
Update our Axolotl key state based on the KX data we received.
struct GNUNET_PILS_Operation * GNUNET_PILS_ecdh(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, GNUNET_PILS_EcdhResultCallback cb, void *cb_cls)
Derive key material from a ECDH public key and our private key.
Definition pils_api.c:595
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
Definition pils_api.c:623
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
Axolotl data, according to https://github.com/trevp/axolotl/wiki .

References CadetTConnection::cc, cont_GCT_handle_kx(), GCC_2s(), GCP_get_id(), GCT_2s(), GCT_alice_or_betty(), GNUNET_break, GNUNET_break_op, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_PILS_cancel(), GNUNET_PILS_ecdh(), GNUNET_STATISTICS_update(), GNUNET_YES, LOG, msg, pils, send_kx_auth(), stats, t, CadetTConnection::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 2072 of file gnunet-service-cadet_tunnels.c.

2074{
2075 struct CadetTunnel *t = ct->t;
2076
2078 "# KX_AUTH received",
2079 1,
2080 GNUNET_NO);
2081 if ((CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) ||
2082 (CADET_TUNNEL_KEY_AX_RECV == t->estate))
2083 {
2084 /* Confusing, we got a KX_AUTH before we even send our own
2085 KX. This should not happen. We'll send our own KX ASAP anyway,
2086 so let's ignore this here. */
2087 GNUNET_break_op (0);
2088 return;
2089 }
2091 "Handling KX_AUTH message from %s with ephemeral %s\n",
2092 GCT_2s (t),
2093 GNUNET_e2s (&msg->kx.ephemeral_key));
2094 if ((t->as.ecdh_op) &&
2095 (0 ==
2096 memcmp (&t->as.ratchet_key,
2097 &msg->kx.ratchet_key,
2098 sizeof(msg->kx.ratchet_key))) &&
2099 (0 ==
2100 memcmp (&t->as.ephemeral_key,
2101 &msg->kx.ephemeral_key,
2102 sizeof(msg->kx.ephemeral_key))))
2103 {
2105 "Waiting for previous ECDH operation\n");
2106 return;
2107 }
2108 /* We do everything in a copy until we've checked the authentication
2109 so we don't clobber anything we care about by accident. */
2110 t->as.ax = t->ax;
2111 GNUNET_memcpy (&t->as.peer_id, GCP_get_id (t->destination),
2112 sizeof (t->as.peer_id));
2113 GNUNET_memcpy (&t->as.ephemeral_key, &msg->kx.ephemeral_key,
2114 sizeof (t->as.ephemeral_key));
2115 GNUNET_memcpy (&t->as.ratchet_key, &msg->kx.ratchet_key,
2116 sizeof (t->as.ratchet_key));
2117 t->as.auth = msg->auth;
2118 t->as.flags = msg->kx.flags;
2119 t->as.cb_cls = t;
2120 t->as.cb = &cont_GCT_handle_kx_auth;
2121
2122 if (t->as.ecdh_op)
2123 {
2125 "Cancelling previous ECDH operation\n");
2126
2127 GNUNET_PILS_cancel (t->as.ecdh_op);
2128 }
2129
2130 /* Update 'ax' by the new key material */
2131 t->as.ecdh_op = GNUNET_PILS_ecdh (pils, &msg->kx.ephemeral_key,
2132 &update_ax_by_kx, &t->as);
2133}
static void cont_GCT_handle_kx_auth(void *cls, enum GNUNET_GenericReturnValue ret)
Continue to handle KX_AUTH message.

References CADET_TUNNEL_KEY_AX_RECV, CADET_TUNNEL_KEY_UNINITIALIZED, cont_GCT_handle_kx_auth(), GCP_get_id(), GCT_2s(), GNUNET_break_op, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcpy, GNUNET_NO, GNUNET_PILS_cancel(), GNUNET_PILS_ecdh(), GNUNET_STATISTICS_update(), LOG, msg, pils, stats, t, CadetTConnection::t, and update_ax_by_kx().

Referenced by GCC_handle_kx_auth().

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 3345 of file gnunet-service-cadet_tunnels.c.

3347{
3348 struct CadetTunnel *t = ct->t;
3349 uint16_t size = ntohs (msg->header.size);
3350 char cbuf[size] GNUNET_ALIGN;
3351 ssize_t decrypted_size;
3352
3354 "%s received %u bytes of encrypted data in state %d\n",
3355 GCT_2s (t),
3356 (unsigned int) size,
3357 t->estate);
3358
3359 switch (t->estate)
3360 {
3363 /* We did not even SEND our KX, how can the other peer
3364 send us encrypted data? Must have been that we went
3365 down and the other peer still things we are up.
3366 Let's send it KX back. */
3368 "# received encrypted without any KX",
3369 1,
3370 GNUNET_NO);
3371 if (NULL != t->kx_task)
3372 {
3373 GNUNET_SCHEDULER_cancel (t->kx_task);
3374 t->kx_task = NULL;
3375 }
3376 send_kx (t,
3377 ct,
3378 &t->ax);
3379 return;
3380
3382 /* We send KX, and other peer send KX to us at the same time.
3383 Neither KX is AUTH'ed, so let's try KX_AUTH this time. */
3385 "# received encrypted without KX_AUTH",
3386 1,
3387 GNUNET_NO);
3388 if (NULL != t->kx_task)
3389 {
3390 GNUNET_SCHEDULER_cancel (t->kx_task);
3391 t->kx_task = NULL;
3392 }
3393 send_kx_auth (t,
3394 ct,
3395 &t->ax,
3396 GNUNET_YES);
3397 return;
3398
3400 /* We did not get the KX of the other peer, but that
3401 might have been lost. Send our KX again immediately. */
3403 "# received encrypted without KX",
3404 1,
3405 GNUNET_NO);
3406 if (NULL != t->kx_task)
3407 {
3408 GNUNET_SCHEDULER_cancel (t->kx_task);
3409 t->kx_task = NULL;
3410 }
3411 send_kx (t,
3412 ct,
3413 &t->ax);
3414 return;
3415
3417 /* Great, first payload, we might graduate to OK! */
3419 /* We are up and running, all good. */
3420 break;
3421 }
3422
3423 decrypted_size = -1;
3424 if (CADET_TUNNEL_KEY_OK == t->estate)
3425 {
3426 /* We have well-established key material available,
3427 try that. (This is the common case.) */
3428 decrypted_size = t_ax_decrypt_and_validate (&t->ax,
3429 cbuf,
3430 msg,
3431 size);
3432 }
3433
3434 if ((-1 == decrypted_size) &&
3435 (NULL != t->unverified_ax))
3436 {
3437 /* We have un-authenticated KX material available. We should try
3438 this as a back-up option, in case the sender crashed and
3439 switched keys. */
3440 decrypted_size = t_ax_decrypt_and_validate (t->unverified_ax,
3441 cbuf,
3442 msg,
3443 size);
3444 if (-1 != decrypted_size)
3445 {
3446 /* It worked! Treat this as authentication of the AX data! */
3447 cleanup_ax (&t->ax);
3448 t->ax = *t->unverified_ax;
3449 GNUNET_free (t->unverified_ax);
3450 t->unverified_ax = NULL;
3451 }
3452 if (CADET_TUNNEL_KEY_AX_AUTH_SENT == t->estate)
3453 {
3454 /* First time it worked, move tunnel into production! */
3457 if (NULL != t->send_task)
3458 GNUNET_SCHEDULER_cancel (t->send_task);
3460 t);
3461 }
3462 }
3463 if (NULL != t->unverified_ax)
3464 {
3465 /* We had unverified KX material that was useless; so increment
3466 counter and eventually move to ignore it. Note that we even do
3467 this increment if we successfully decrypted with the old KX
3468 material and thus didn't even both with the new one. This is
3469 the ideal case, as a malicious injection of bogus KX data
3470 basically only causes us to increment a counter a few times. */t->unverified_attempts++;
3472 "Failed to decrypt message with unverified KX data %u times\n",
3473 t->unverified_attempts);
3474 if (t->unverified_attempts > MAX_UNVERIFIED_ATTEMPTS)
3475 {
3476 cleanup_ax (t->unverified_ax);
3477 GNUNET_free (t->unverified_ax);
3478 t->unverified_ax = NULL;
3479 }
3480 }
3481
3482 if (-1 == decrypted_size)
3483 {
3484 /* Decryption failed for good, complain. */
3486 "%s failed to decrypt and validate encrypted data, retrying KX\n",
3487 GCT_2s (t));
3489 "# unable to decrypt",
3490 1,
3491 GNUNET_NO);
3492 if (NULL != t->kx_task)
3493 {
3494 GNUNET_SCHEDULER_cancel (t->kx_task);
3495 t->kx_task = NULL;
3496 }
3497 send_kx (t,
3498 ct,
3499 &t->ax);
3500 return;
3501 }
3503 "# decrypted bytes",
3504 decrypted_size,
3505 GNUNET_NO);
3506
3507 /* The MST will ultimately call #handle_decrypted() on each message. */
3508 t->current_ct = ct;
3511 cbuf,
3512 decrypted_size,
3513 GNUNET_YES,
3514 GNUNET_NO));
3515 t->current_ct = NULL;
3516}
static void cleanup_ax(struct CadetTunnelAxolotl *ax)
Cleanup state used by ax.
#define MAX_UNVERIFIED_ATTEMPTS
How often do we try to decrypt payload with unverified key material? Used to limit CPU increase upon ...
void GCT_change_estate(struct CadetTunnel *t, enum CadetTunnelEState state)
Change the tunnel encryption state.
static void send_kx(struct CadetTunnel *t, struct CadetTConnection *ct, struct CadetTunnelAxolotl *ax)
Send a KX message.
static ssize_t t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax, void *dst, const struct GNUNET_CADET_TunnelEncryptedMessage *src, size_t size)
Decrypt and verify data with the appropriate tunnel key and verify that the data has not been altered...
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
@ GNUNET_ERROR_TYPE_WARNING
enum GNUNET_GenericReturnValue 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:101
static unsigned int size
Size of the "table".
Definition peer.c:68

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, t, CadetTConnection::t, t_ax_decrypt_and_validate(), and trigger_transmissions().

Referenced by GCC_handle_encrypted().

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

◆ GCT_debug()

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

Log all possible info about the tunnel state.

Parameters
tTunnel to debug.
levelDebug level to use.

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

3737{
3738#if ! defined(GNUNET_CULL_LOGGING)
3739 struct CadetTConnection *iter_c;
3740 int do_log;
3741
3743 "cadet-tun",
3744 __FILE__, __FUNCTION__, __LINE__);
3745 if (0 == do_log)
3746 return;
3747
3748 LOG2 (level,
3749 "TTT TUNNEL TOWARDS %s in estate %s tq_len: %u #cons: %u\n",
3750 GCT_2s (t),
3751 estate2s (t->estate),
3752 t->tq_len,
3754 LOG2 (level,
3755 "TTT channels:\n");
3758 &level);
3759 LOG2 (level,
3760 "TTT connections:\n");
3761 for (iter_c = t->connection_ready_head; NULL != iter_c; iter_c = iter_c->next)
3762 GCC_debug (iter_c->cc,
3763 level);
3764 for (iter_c = t->connection_busy_head; NULL != iter_c; iter_c = iter_c->next)
3765 GCC_debug (iter_c->cc,
3766 level);
3767
3768 LOG2 (level,
3769 "TTT TUNNEL END\n");
3770#endif
3771}
void GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level)
Log connection info.
static int debug_channel(void *cls, uint32_t key, void *value)
Call GCCH_debug() on a channel.
unsigned int GCT_count_any_connections(const struct CadetTunnel *t)
Counts the number of connections created for a tunnel, including busy connections.
#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: