29#include "gnunet_signatures.h"
39#define LOG(level, ...) GNUNET_log_from (level, "cadet-con", __VA_ARGS__)
46#define INITIAL_CONNECTION_CREATE_RETRY_DELAY \
47 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
210 "Trying to update connection state for %s having old state %d to new %d and mqm_ready old %d to mqm_ready new %d\n",
223 cc->
state = new_state;
227 "Updating connection state for %s having old_ready %d and new_rady %d\n",
232 if (old_ready != new_ready)
252 if (NULL != cc->
task)
263 for (
unsigned int i = 0; i < cc->
off; i++)
269 ->connection_of_tunnel,
314 destroy_msg->
cid = cc->
cid;
403 "Sending KEEPALIVE on behalf of %s via %s\n",
483 "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
489 if (NULL != cc->
task)
514 "Received KX message with ephermal %s on CC %s in state %d\n",
523 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
542 "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
551 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
574 "Faking connection ACK for %s due to ENCRYPTED payload\n",
594 .purpose.size = htonl (
sizeof(cp)),
595 .monotonic_time =
msg->monotime};
626 create_msg->
cid = cc->
cid;
641 for (
unsigned int i = 0; i <= cc->
off; i++)
644 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
669 "Sending CONNECTION_CREATE_ACK message for %s\n",
700 "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
706 if (NULL != cc->
task)
717 "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
744 if (NULL != cc->
task)
754 "Core MQ for %s became available in state %d\n",
786 "Scheduling keepalive for %s in %s\n",
826 cc->
state = init_state;
843 "Creating %s using path %s (offset: %u)\n",
848 for (
unsigned int i = 0; i < off; i++)
903 "Got two connections on %s, dropping my existing %s\n",
913 "Got two connections on %s, keeping my existing %s\n",
967 "Scheduling message for transmission on %s\n",
973 if (NULL != cc->
task)
1018 static char buf[128];
1021 return "Connection(NULL)";
1027 "Connection %s (%s)",
1040#define LOG2(level, ...) \
1041 GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)
1053#if ! defined(GNUNET_CULL_LOGGING)
1065 LOG2 (level,
"Connection (NULL)\n");
1069 "%s to %s via path %s in state %d is %s\n",
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
P2P messages used by CADET.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
Peer private key.
static struct GNUNET_PeerIdentity my_full_id
Peer identity.
static int result
Global testing status.
struct GNUNET_CONTAINER_MultiShortmap * connections
Map from struct GNUNET_CADET_ConnectionTunnelIdentifier hash codes to struct CadetConnection objects.
struct GNUNET_TIME_Relative keepalive_period
How frequently do we send KEEPALIVE messages on idle connections?
GNUnet CADET service with encryption.
static struct CadetConnection * connection_create(struct CadetPeer *destination, struct CadetPeerPath *path, unsigned int off, struct CadetTConnection *ct, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, enum CadetConnectionState init_state, GCC_ReadyCallback ready_cb, void *ready_cb_cls)
Create a connection to destination via path and notify cb whenever we are ready for more data.
static void set_monotime_sig(struct GNUNET_CADET_ConnectionCreateMessage *msg)
Set the signature for a monotime value on a GNUNET_CADET_ConnectionCreateMessage.
static void manage_first_hop_mq(void *cls, int available)
There has been a change in the message queue existence for our peer at the first hop.
void GCC_handle_encrypted(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
Handle encrypted message.
struct CadetPeerPath * GCC_get_path(struct CadetConnection *cc, unsigned int *off)
Obtain the path used by this connection.
#define INITIAL_CONNECTION_CREATE_RETRY_DELAY
How long do we wait initially before retransmitting the KX? TODO: replace by 2 RTT if/once we have co...
void GCC_handle_connection_create_ack(struct CadetConnection *cc)
A GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for this connection,...
CadetConnectionState
All the states a connection can be in.
@ CADET_CONNECTION_NEW
Uninitialized status, we have not yet even gotten the message queue.
@ CADET_CONNECTION_READY
Connection confirmed, ready to carry traffic.
@ CADET_CONNECTION_SENDING_CREATE
Connection create message in queue, awaiting transmission by CORE.
@ CADET_CONNECTION_CREATE_RECEIVED
We are an inbound connection, and received a CREATE.
@ CADET_CONNECTION_SENT
Connection create message sent, waiting for ACK.
void GCC_handle_kx(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
Handle KX message.
void GCC_destroy_without_core(struct CadetConnection *cc)
Destroy a connection, called when the CORE layer is already done (i.e.
static void update_state(struct CadetConnection *cc, enum CadetConnectionState new_state, int new_mqm_ready)
Update the connection state.
void GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, struct GNUNET_TIME_Relative latency)
We observed some the given latency on the connection identified by cti.
void GCC_handle_kx_auth(struct CadetConnection *cc, const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
Handle KX_AUTH message.
static void keepalive_done(void *cls, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Keepalive was transmitted.
static void GCC_destroy(struct CadetConnection *cc)
Destroy a connection, part of the internal implementation.
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 send_keepalive(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE through the tunnel to prevent it from timing out.
static void send_create_ack(void *cls)
Send a CREATE_ACK message towards the origin.
void GCC_handle_duplicate_create(struct CadetConnection *cc)
We got a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a connection that we already have.
void GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
We observed an ACK for a message that was originally sent via the connection identified by cid.
struct CadetTConnection * GCC_get_ct(struct CadetConnection *cc)
Return the tunnel associated with this connection.
static void send_create(void *cls)
Send a GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the first hop.
void GCC_destroy_without_tunnel(struct CadetConnection *cc)
Destroy a connection, called if the tunnel association with the connection was already broken,...
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.
void GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
Transmit message msg via connection cc.
void GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level)
Log connection info.
const struct CadetConnectionMetrics * GCC_get_metrics(struct CadetConnection *cc)
Obtain performance metrics from cc.
void GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
We sent a message for which we expect to receive an ACK via the connection identified by cti.
struct CadetConnection * GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
Lookup a connection by its identifier.
const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id(struct CadetConnection *cc)
Obtain unique ID for the connection.
A connection is a live end-to-end messaging mechanism where the peers are identified by a path and kn...
void(* GCC_ReadyCallback)(void *cls, int is_ready)
Function called to notify tunnel about change in our readiness.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
struct CadetConnection * GCPP_get_connection(struct CadetPeerPath *path, struct CadetPeer *destination, unsigned int off)
Return connection to destination using path, or return NULL if no such connection exists.
void GCPP_del_connection(struct CadetPeerPath *path, unsigned int off, struct CadetConnection *cc)
Notify path that it is no longer used for connection cc which ended at the path's offset off.
void GCPP_add_connection(struct CadetPeerPath *path, unsigned int off, struct CadetConnection *cc)
Notify path that it is used for connection cc which ends at the path's offset off.
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
unsigned int GCPP_find_peer(struct CadetPeerPath *path, struct CadetPeer *cp)
Find peer's offset on path.
void GCP_add_connection(struct CadetPeer *cp, struct CadetConnection *cc)
Add a connection to this cp.
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
struct CadetTunnel * GCP_get_tunnel(struct CadetPeer *cp, int create)
Get the tunnel towards a peer.
void GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *last_env)
Stops message queue change notifications.
void GCP_send(struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *env)
Send the message in env to cp.
void GCP_remove_connection(struct CadetPeer *cp, struct CadetConnection *cc)
Remove a connection that went via this cp.
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct GCP_MessageQueueManager * GCP_request_mq(struct CadetPeer *cp, GCP_MessageQueueNotificationCallback cb, void *cb_cls)
Start message queue change notifications.
void GCT_handle_kx(struct CadetTConnection *ct, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
Handle KX message that lacks authentication (and which will thus only be considered authenticated aft...
void GCT_send_cancel(struct CadetTunnelQueueEntry *tq)
Cancel a previously sent message while it's in the queue.
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.
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...
void GCT_connection_lost(struct CadetTConnection *ct)
We lost a connection, remove it from our list and clean up the connection object itself.
enum CadetTunnelEState GCT_get_estate(struct CadetTunnel *t)
Get the encryption state of a tunnel.
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.
Information we track per tunnel.
@ CADET_TUNNEL_KEY_UNINITIALIZED
Uninitialized status, we need to send KX.
@ CADET_TUNNEL_KEY_OK
Handshake completed: session key available.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static struct GNUNET_SCHEDULER_Task * t
Main task.
CADET service; establish channels to distant peers.
API to create, modify and access statistics.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from 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...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
GNUNET_ErrorType
Types of errors.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#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_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
Send origin an ACK that the connection is complete.
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
Request the destruction of a connection.
#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE
Announce connection is still alive (direction sensitive).
#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
Request the creation of a connection.
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR
Signature by a peer that like to create a connection.
Purpose for the signature of a monotime.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose is GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR.
Performance metrics for a connection.
struct GNUNET_TIME_Relative aged_latency
Our current best estimate of the latency, based on a weighted average of at least latency_datapoints ...
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)
Low-level connection to a destination.
struct CadetTConnection * ct
Which tunnel is using this connection?
struct GNUNET_MQ_Envelope * env
Pending message, NULL if we are ready to transmit.
struct CadetConnectionMetrics metrics
Performance metrics for this connection.
GCC_ReadyCallback ready_cb
Function to call once we are ready to transmit.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct GNUNET_SCHEDULER_Task * task
Task for connection maintenance.
struct GNUNET_TIME_Absolute create_at
Earliest time for re-trying CREATE.
unsigned int latency_datapoints
How many latency observations did we make for this connection?
struct GNUNET_TIME_Relative retry_delay
How long do we wait before we try again with a CREATE message?
struct GNUNET_TIME_Absolute create_ack_at
Earliest time for re-trying CREATE_ACK.
void * ready_cb_cls
Closure for ready_cb.
enum CadetConnectionState state
State of the connection.
struct CadetPeerPath * path
Path we are using to our destination.
unsigned int off
Offset of our destination in path.
int mqm_ready
Are we ready to transmit via mq_man right now?
struct GCP_MessageQueueManager * mq_man
Handle for calling GCP_request_mq_cancel() once we are finished.
struct CadetPeer * destination
To which peer does this connection go?
struct CadetTunnelQueueEntry * keepalive_qe
Queue entry for keepalive messages.
Information regarding a possible path to reach a peer.
Struct containing all information regarding a given peer.
Entry in list of connections used by tunnel, with metadata.
struct CadetConnection * cc
Connection handle.
struct CadetTunnel * t
Tunnel this connection belongs to.
Struct used to save messages in a non-ready tunnel to send once connected.
Struct containing all information regarding a tunnel to a peer.
Data structure used to track whom we have to notify about changes to our message queue.
Message for ack'ing a connection.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
Message for cadet connection creation.
int has_monotime
This flag indicates the peer sending the connection create message likes to trigger a KX handshake.
uint32_t options
Connection options in network byte order.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
struct GNUNET_TIME_AbsoluteNBO monotime
This monotonic time is set, if a peer likes to trigger a KX, but is not the peer that should start th...
Message to destroy a connection.
struct GNUNET_CADET_ConnectionTunnelIdentifier cid
ID of the connection.
Hash uniquely identifying a connection below a tunnel.
struct GNUNET_ShortHashCode connection_of_tunnel
Axolotl-encrypted tunnel message with application payload.
Message for a Key eXchange for a tunnel, with authentication.
Message for a Key eXchange for a tunnel.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.