GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-communicator-udp.c File Reference

Transport plugin using UDP. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_constants.h"
#include "gnunet_nt_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_transport_communication_service.h"
Include dependency graph for gnunet-communicator-udp.c:

Go to the source code of this file.

Data Structures

struct  UdpHandshakeSignature
 Signature we use to verify that the ephemeral key was really chosen by the specified sender. More...
 
struct  InitialKX
 "Plaintext" header at beginning of KX message. More...
 
struct  UDPConfirmation
 Encrypted continuation of UDP initial handshake, followed by message header with payload. More...
 
struct  UDPAck
 UDP key acknowledgement. More...
 
struct  UdpBroadcastSignature
 Signature we use to verify that the broadcast was really made by the peer that claims to have made it. More...
 
struct  UDPBroadcast
 Broadcast by peer in LAN announcing its presence. More...
 
struct  UDPBox
 UDP message box. More...
 
struct  KeyCacheEntry
 Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct UDPBox. More...
 
struct  SharedSecret
 Shared secret we generated for a particular sender or receiver. More...
 
struct  SenderAddress
 Information we track per sender address we have recently been in contact with (we decrypt messages from the sender). More...
 
struct  ReceiverAddress
 Information we track per receiving address we have recently been in contact with (encryption to receiver). More...
 
struct  BroadcastInterface
 Interface we broadcast our presence on. More...
 
struct  SearchContext
 Context information to be used while searching for operation contexts. More...
 

Macros

#define REKEY_TIME_INTERVAL   GNUNET_TIME_UNIT_DAYS
 How often do we rekey based on time (at least) More...
 
#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 How long do we wait until we must have received the initial KX? More...
 
#define BROADCAST_FREQUENCY   GNUNET_TIME_UNIT_MINUTES
 How often do we broadcast our presence on the LAN? More...
 
#define INTERFACE_SCAN_FREQUENCY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 How often do we scan for changes to our network interfaces? More...
 
#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_UNIT_HOURS
 How long do we believe our addresses to remain up (before the other peer should revalidate). More...
 
#define AES_KEY_SIZE   (256 / 8)
 AES key size. More...
 
#define AES_IV_SIZE   (96 / 8)
 AES (GCM) IV size. More...
 
#define GCM_TAG_SIZE   (128 / 8)
 Size of the GCM tag. More...
 
#define KCN_THRESHOLD   92
 If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET. More...
 
#define KCN_TARGET   128
 How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD so we do not generate just one ACK at the time. More...
 
#define MAX_SQN_DELTA   160
 What is the maximum delta between KCN sequence numbers that we allow. More...
 
#define MAX_SECRETS   128
 How many shared master secrets do we keep around at most per sender? Should be large enough so that we generally have a chance of sending an ACK before the sender already rotated out the master secret. More...
 
#define REKEY_MAX_BYTES   (1024LLU * 1024 * 1024 * 4LLU)
 How often do we rekey based on number of bytes transmitted? (additionally randomized). More...
 
#define COMMUNICATOR_ADDRESS_PREFIX   "udp"
 Address prefix used by the communicator. More...
 
#define COMMUNICATOR_CONFIG_SECTION   "communicator-udp"
 Configuration section used by the communicator. More...
 

Functions

static void bi_destroy (struct BroadcastInterface *bi)
 An interface went away, stop broadcasting on it. More...
 
static void receiver_destroy (struct ReceiverAddress *receiver)
 Destroys a receiving state due to timeout or shutdown. More...
 
static void kce_destroy (struct KeyCacheEntry *kce)
 Free memory used by key cache entry. More...
 
static void get_kid (const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
 Compute kid. More...
 
static void kce_generate (struct SharedSecret *ss, uint32_t seq)
 Setup key cache entry for sequence number seq and shared secret ss. More...
 
static void secret_destroy (struct SharedSecret *ss)
 Destroy ss and associated key cache entries. More...
 
static void sender_destroy (struct SenderAddress *sender)
 Functions with this signature are called whenever we need to close a sender's state due to timeout. More...
 
static void get_iv_key (const struct GNUNET_HashCode *msec, uint32_t serial, char key[(256/8)], char iv[(96/8)])
 Compute key and iv. More...
 
static void reschedule_sender_timeout (struct SenderAddress *sender)
 Increment sender timeout due to activity. More...
 
static void reschedule_receiver_timeout (struct ReceiverAddress *receiver)
 Increment receiver timeout due to activity. More...
 
static void check_timeouts (void *cls)
 Task run to check #receiver_heap and #sender_heap for timeouts. More...
 
static void calculate_cmac (struct SharedSecret *ss)
 Calcualte cmac from master in ss. More...
 
static void pass_plaintext_to_core (struct SenderAddress *sender, const void *plaintext, size_t plaintext_len)
 We received plaintext_len bytes of plaintext from a sender. More...
 
static void setup_cipher (const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
 Setup cipher based on shared secret msec and serial number serial. More...
 
static int try_decrypt (const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
 Try to decrypt buf using shared secret ss and key/iv derived using serial. More...
 
static struct SharedSecretsetup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
 Setup shared secret for decryption. More...
 
static struct SharedSecretsetup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver)
 Setup shared secret for encryption. More...
 
static void setup_receiver_mq (struct ReceiverAddress *receiver)
 Setup the MQ for the receiver. More...
 
static int handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 We received an ACK for pid. More...
 
static void try_handle_plaintext (struct SenderAddress *sender, const void *buf, size_t buf_size)
 Test if we have received a valid message in plaintext. More...
 
static void consider_ss_ack (struct SharedSecret *ss)
 We established a shared secret with a sender. More...
 
static void decrypt_box (const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
 We received a box with matching kce. More...
 
static int find_sender_by_address (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find existing struct SenderAddress by matching addresses. More...
 
static struct SenderAddresssetup_sender (const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
 Create sender address for target. More...
 
static int verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, const struct UDPConfirmation *uc)
 Check signature from uc against ephemeral. More...
 
static char * sockaddr_to_udpaddr_string (const struct sockaddr *address, socklen_t address_len)
 Converts address to the address string format used by this communicator in HELLOs. More...
 
static void sock_read (void *cls)
 Socket read task. More...
 
static struct sockaddr * udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
 Convert UDP bind specification to a struct sockaddr * More...
 
static void do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
 Pad dgram by pad_size using out_cipher. More...
 
static void mq_send_kx (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Signature of functions implementing the sending functionality of a message queue. More...
 
static void mq_send_d (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Signature of functions implementing the sending functionality of a message queue. More...
 
static void mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Signature of functions implementing the destruction of a message queue. More...
 
static void mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Signature of functions implementing the destruction of a message queue. More...
 
static void mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Implementation function that cancels the currently sent message. More...
 
static void mq_error (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static int mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
 Function called by the transport service to initialize a message queue given address information about another peer. More...
 
static int get_receiver_delete_it (void *cls, const struct GNUNET_PeerIdentity *target, void *value)
 Iterator over all receivers to clean up. More...
 
static int get_sender_delete_it (void *cls, const struct GNUNET_PeerIdentity *target, void *value)
 Iterator over all senders to clean up. More...
 
static void do_shutdown (void *cls)
 Shutdown the UNIX communicator. More...
 
static void enc_notify_cb (void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
 Function called when the transport service has received a backchannel message for this communicator (!) via a different return path. More...
 
static void nat_address_cb (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes. More...
 
static void ifc_broadcast (void *cls)
 Broadcast our presence on one of our interfaces. More...
 
static int iface_proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
 Callback function invoked for each interface found. More...
 
static void do_broadcast (void *cls)
 Scan interfaces to broadcast our presence on the LAN. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Setup communicator and launch network interactions. More...
 
int main (int argc, char *const *argv)
 The main function for the UNIX communicator. More...
 

Variables

static struct GNUNET_CONTAINER_MultiShortmapkey_cache
 Cache of pre-generated key IDs. More...
 
static struct GNUNET_SCHEDULER_Taskread_task
 ID of read task. More...
 
static struct GNUNET_SCHEDULER_Tasktimeout_task
 ID of timeout task. More...
 
static struct GNUNET_SCHEDULER_Taskbroadcast_task
 ID of master broadcast task. More...
 
static struct GNUNET_STATISTICS_Handlestats
 For logging statistics. More...
 
static struct GNUNET_TRANSPORT_CommunicatorHandlech
 Our environment. More...
 
static struct GNUNET_CONTAINER_MultiPeerMapreceivers
 Receivers (map from peer identity to struct ReceiverAddress) More...
 
static struct GNUNET_CONTAINER_MultiPeerMapsenders
 Senders (map from peer identity to struct SenderAddress) More...
 
static struct GNUNET_CONTAINER_Heapsenders_heap
 Expiration heap for senders (contains struct SenderAddress) More...
 
static struct GNUNET_CONTAINER_Heapreceivers_heap
 Expiration heap for receivers (contains struct ReceiverAddress) More...
 
static struct BroadcastInterfacebi_head
 Broadcast interface tasks. More...
 
static struct BroadcastInterfacebi_tail
 Broadcast interface tasks. More...
 
static struct GNUNET_NETWORK_Handleudp_sock
 Our socket. More...
 
static int have_v6_socket
 GNUNET_YES if udp_sock supports IPv6. More...
 
static struct GNUNET_PeerIdentity my_identity
 Our public key. More...
 
static struct GNUNET_CRYPTO_EddsaPrivateKeymy_private_key
 Our private key. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_TRANSPORT_ApplicationHandleah
 Our handle to report addresses for validation to TRANSPORT. More...
 
static struct GNUNET_NT_InterfaceScanneris
 Network scanner to determine network types. More...
 
static struct GNUNET_NAT_Handlenat
 Connection to NAT service. More...
 
static uint16_t my_port
 Port number to which we are actually bound. More...
 

Detailed Description

Transport plugin using UDP.

Author
Christian Grothoff

TODO:

Definition in file gnunet-communicator-udp.c.

Macro Definition Documentation

◆ REKEY_TIME_INTERVAL

#define REKEY_TIME_INTERVAL   GNUNET_TIME_UNIT_DAYS

How often do we rekey based on time (at least)

Definition at line 54 of file gnunet-communicator-udp.c.

◆ PROTO_QUEUE_TIMEOUT

#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES

How long do we wait until we must have received the initial KX?

Definition at line 59 of file gnunet-communicator-udp.c.

◆ BROADCAST_FREQUENCY

#define BROADCAST_FREQUENCY   GNUNET_TIME_UNIT_MINUTES

How often do we broadcast our presence on the LAN?

Definition at line 64 of file gnunet-communicator-udp.c.

Referenced by ifc_broadcast().

◆ INTERFACE_SCAN_FREQUENCY

#define INTERFACE_SCAN_FREQUENCY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)

How often do we scan for changes to our network interfaces?

Definition at line 69 of file gnunet-communicator-udp.c.

Referenced by do_broadcast(), and ifc_broadcast().

◆ ADDRESS_VALIDITY_PERIOD

#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_UNIT_HOURS

How long do we believe our addresses to remain up (before the other peer should revalidate).

Definition at line 76 of file gnunet-communicator-udp.c.

Referenced by pass_plaintext_to_core().

◆ AES_KEY_SIZE

#define AES_KEY_SIZE   (256 / 8)

AES key size.

Definition at line 81 of file gnunet-communicator-udp.c.

Referenced by setup_cipher().

◆ AES_IV_SIZE

#define AES_IV_SIZE   (96 / 8)

AES (GCM) IV size.

Definition at line 86 of file gnunet-communicator-udp.c.

Referenced by get_iv_key(), and setup_cipher().

◆ GCM_TAG_SIZE

#define GCM_TAG_SIZE   (128 / 8)

Size of the GCM tag.

Definition at line 91 of file gnunet-communicator-udp.c.

◆ KCN_THRESHOLD

#define KCN_THRESHOLD   92

If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET.

Should be large enough that we don't generate ACKs all the time and still have enough time for the ACK to arrive before the sender runs out. So really this should ideally be based on the RTT.

Definition at line 102 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack().

◆ KCN_TARGET

#define KCN_TARGET   128

How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD so we do not generate just one ACK at the time.

Definition at line 110 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack().

◆ MAX_SQN_DELTA

#define MAX_SQN_DELTA   160

What is the maximum delta between KCN sequence numbers that we allow.

Used to expire 'ancient' KCNs that likely were dropped by the network. Must be larger than KCN_TARGET (otherwise we generate new KCNs all the time), but not too large (otherwise packet loss may cause sender to fall back to KX needlessly when sender runs out of ACK'ed KCNs due to losses).

Definition at line 121 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack().

◆ MAX_SECRETS

#define MAX_SECRETS   128

How many shared master secrets do we keep around at most per sender? Should be large enough so that we generally have a chance of sending an ACK before the sender already rotated out the master secret.

Generally values around KCN_TARGET make sense. Might make sense to adapt to RTT if we had a good measurement...

Definition at line 132 of file gnunet-communicator-udp.c.

Referenced by sock_read().

◆ REKEY_MAX_BYTES

#define REKEY_MAX_BYTES   (1024LLU * 1024 * 1024 * 4LLU)

How often do we rekey based on number of bytes transmitted? (additionally randomized).

Definition at line 138 of file gnunet-communicator-udp.c.

◆ COMMUNICATOR_ADDRESS_PREFIX

#define COMMUNICATOR_ADDRESS_PREFIX   "udp"

Address prefix used by the communicator.

Definition at line 144 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack(), mq_init(), nat_address_cb(), run(), and sockaddr_to_udpaddr_string().

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-udp"

Configuration section used by the communicator.

Definition at line 149 of file gnunet-communicator-udp.c.

Referenced by run(), and udp_address_to_sockaddr().

Function Documentation

◆ bi_destroy()

static void bi_destroy ( struct BroadcastInterface bi)
static

An interface went away, stop broadcasting on it.

Parameters
bientity to close down

Definition at line 769 of file gnunet-communicator-udp.c.

References BroadcastInterface::ba, BroadcastInterface::broadcast_task, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror, GNUNET_NETWORK_socket_setsockopt(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), BroadcastInterface::mcreq, and BroadcastInterface::sa.

Referenced by do_broadcast(), and do_shutdown().

770 {
771  if (AF_INET6 == bi->sa->sa_family)
772  {
773  /* Leave the multicast group */
775  IPPROTO_IPV6,
776  IPV6_LEAVE_GROUP,
777  &bi->mcreq,
778  sizeof(bi->mcreq)))
779  {
781  }
782  }
785  GNUNET_free (bi->sa);
786  GNUNET_free (bi->ba);
787  GNUNET_free (bi);
788 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:883
static struct BroadcastInterface * bi_tail
Broadcast interface tasks.
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
struct sockaddr * ba
Broadcast address to use on the interface.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
struct sockaddr * sa
Sender's address of the interface.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
struct ipv6_mreq mcreq
If this is an IPv6 interface, this is the request we use to join/leave the group. ...
struct GNUNET_SCHEDULER_Task * broadcast_task
Task for this broadcast interface.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiver_destroy()

static void receiver_destroy ( struct ReceiverAddress receiver)
static

Destroys a receiving state due to timeout or shutdown.

Parameters
receiverentity to close down

Definition at line 797 of file gnunet-communicator-udp.c.

References ReceiverAddress::address, ReceiverAddress::d_mq, ReceiverAddress::d_qh, ReceiverAddress::foreign_addr, GNUNET_assert, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_TRANSPORT_communicator_mq_del(), GNUNET_YES, ReceiverAddress::hn, ReceiverAddress::kx_mq, ReceiverAddress::kx_qh, mq, and ReceiverAddress::target.

Referenced by check_timeouts(), get_receiver_delete_it(), mq_destroy_d(), mq_destroy_kx(), mq_error(), mq_send_d(), and mq_send_kx().

798 {
799  struct GNUNET_MQ_Handle *mq;
800 
802  "Disconnecting receiver for peer `%s'\n",
803  GNUNET_i2s (&receiver->target));
804  if (NULL != (mq = receiver->kx_mq))
805  {
806  receiver->kx_mq = NULL;
807  GNUNET_MQ_destroy (mq);
808  }
809  if (NULL != receiver->kx_qh)
810  {
812  receiver->kx_qh = NULL;
813  }
814  if (NULL != (mq = receiver->d_mq))
815  {
816  receiver->d_mq = NULL;
817  GNUNET_MQ_destroy (mq);
818  }
819  if (NULL != receiver->d_qh)
820  {
822  receiver->d_qh = NULL;
823  }
826  &receiver->target,
827  receiver));
828  GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn));
830  "# receivers active",
832  GNUNET_NO);
833  GNUNET_free (receiver->address);
834  GNUNET_free (receiver->foreign_addr);
835  GNUNET_free (receiver);
836 }
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Handle to a message queue.
Definition: mq.c:85
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:833
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_PeerIdentity target
To whom are we talking to.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
struct GNUNET_TRANSPORT_QueueHandle * kx_qh
handle for KX queue with the ch.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kce_destroy()

static void kce_destroy ( struct KeyCacheEntry kce)
static

Free memory used by key cache entry.

Parameters
kcethe key cache entry

Definition at line 845 of file gnunet-communicator-udp.c.

References SharedSecret::active_kce_count, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_free, GNUNET_YES, SharedSecret::kce_head, SharedSecret::kce_tail, KeyCacheEntry::kid, and KeyCacheEntry::ss.

Referenced by consider_ss_ack(), decrypt_box(), and secret_destroy().

846 {
847  struct SharedSecret *ss = kce->ss;
848 
849  ss->active_kce_count--;
852  &kce->kid,
853  kce));
854  GNUNET_free (kce);
855 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
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.
struct SharedSecret * ss
Corresponding shared secret.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
Shared secret we generated for a particular sender or receiver.
unsigned int active_kce_count
Number of active KCN entries.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_kid()

static void get_kid ( const struct GNUNET_HashCode msec,
uint32_t  serial,
struct GNUNET_ShortHashCode kid 
)
static

Compute kid.

Parameters
msecmaster secret for HMAC calculation
serialnumber for the smac calculation
kid[out]where to write the key ID

Definition at line 866 of file gnunet-communicator-udp.c.

References GNUNET_CRYPTO_hkdf().

Referenced by kce_generate(), and mq_send_d().

869 {
870  uint32_t sid = htonl (serial);
871 
872  GNUNET_CRYPTO_hkdf (kid,
873  sizeof(*kid),
874  GCRY_MD_SHA512,
875  GCRY_MD_SHA256,
876  &sid,
877  sizeof(sid),
878  msec,
879  sizeof(*msec),
880  "UDP-KID",
881  strlen ("UDP-KID"),
882  NULL,
883  0);
884 }
int GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:320
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kce_generate()

static void kce_generate ( struct SharedSecret ss,
uint32_t  seq 
)
static

Setup key cache entry for sequence number seq and shared secret ss.

Parameters
ssshared secret
seqsequence number for the key cache entry

Definition at line 894 of file gnunet-communicator-udp.c.

References SharedSecret::active_kce_count, get_kid(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_size(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_set(), SharedSecret::kce_head, SharedSecret::kce_tail, KeyCacheEntry::kid, SharedSecret::master, KeyCacheEntry::sequence_number, and KeyCacheEntry::ss.

Referenced by consider_ss_ack().

895 {
896  struct KeyCacheEntry *kce;
897 
898  GNUNET_assert (0 < seq);
899  kce = GNUNET_new (struct KeyCacheEntry);
900  kce->ss = ss;
901  kce->sequence_number = seq;
902  get_kid (&ss->master, seq, &kce->kid);
904  ss->active_kce_count++;
906  key_cache,
907  &kce->kid,
908  kce,
911  "# KIDs active",
913  GNUNET_NO);
914 }
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
struct SharedSecret * ss
Corresponding shared secret.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
struct GNUNET_HashCode master
Master shared secret.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
int 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_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
unsigned int active_kce_count
Number of active KCN entries.
Allow multiple values with the same key.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ secret_destroy()

static void secret_destroy ( struct SharedSecret ss)
static

Destroy ss and associated key cache entries.

Parameters
ssshared secret to destroy

Definition at line 923 of file gnunet-communicator-udp.c.

References ReceiverAddress::acks_available, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multishortmap_size(), GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), kce_destroy(), SharedSecret::kce_head, SenderAddress::num_secrets, ReceiverAddress::num_secrets, SharedSecret::receiver, UdpHandshakeSignature::receiver, SharedSecret::sender, UdpHandshakeSignature::sender, SharedSecret::sequence_allowed, SharedSecret::sequence_used, SenderAddress::ss_head, ReceiverAddress::ss_head, SenderAddress::ss_tail, and ReceiverAddress::ss_tail.

Referenced by sock_read().

924 {
925  struct SenderAddress *sender;
926  struct ReceiverAddress *receiver;
927  struct KeyCacheEntry *kce;
928 
929  if (NULL != (sender = ss->sender))
930  {
931  GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
932  sender->num_secrets--;
933  }
934  if (NULL != (receiver = ss->receiver))
935  {
936  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
937  receiver->num_secrets--;
938  receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
939  }
940  while (NULL != (kce = ss->kce_head))
941  kce_destroy (kce);
942  GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
944  "# KIDs active",
946  GNUNET_NO);
947  GNUNET_free (ss);
948 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
unsigned int num_secrets
Length of the DLL at ss_head.
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
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 SharedSecret * ss_head
Shared secrets we used with target, first used is head.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
uint32_t sequence_used
Up to which sequence number did we use this master already? (for encrypting only) ...
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Information we track per receiving address we have recently been in contact with (encryption to recei...
unsigned int num_secrets
Length of the DLL at ss_head.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define GNUNET_free(ptr)
Wrapper around free.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sender_destroy()

static void sender_destroy ( struct SenderAddress sender)
static

Functions with this signature are called whenever we need to close a sender's state due to timeout.

Parameters
senderentity to close down

Definition at line 958 of file gnunet-communicator-udp.c.

References SenderAddress::address, GNUNET_assert, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_YES, SenderAddress::hn, and SenderAddress::target.

Referenced by check_timeouts(), and get_sender_delete_it().

959 {
960  GNUNET_assert (
961  GNUNET_YES ==
963  GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn));
965  "# senders active",
967  GNUNET_NO);
968  GNUNET_free (sender->address);
969  GNUNET_free (sender);
970 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct sockaddr * address
Address of the other peer.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_iv_key()

static void get_iv_key ( const struct GNUNET_HashCode msec,
uint32_t  serial,
char  key[(256/8)],
char  iv[(96/8)] 
)
static

Compute key and iv.

Parameters
msecmaster secret for calculation
serialnumber for the smac calculation
key[out]where to write the decrption key
iv[out]where to write the IV

Definition at line 982 of file gnunet-communicator-udp.c.

References AES_IV_SIZE, GNUNET_CRYPTO_hkdf(), key, and res.

Referenced by setup_cipher().

986 {
987  uint32_t sid = htonl (serial);
988  char res[AES_KEY_SIZE + AES_IV_SIZE];
989 
990  GNUNET_CRYPTO_hkdf (res,
991  sizeof(res),
992  GCRY_MD_SHA512,
993  GCRY_MD_SHA256,
994  &sid,
995  sizeof(sid),
996  msec,
997  sizeof(*msec),
998  "UDP-IV-KEY",
999  strlen ("UDP-IV-KEY"),
1000  NULL,
1001  0);
1002  memcpy (key, res, AES_KEY_SIZE);
1003  memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
1004 }
int GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:320
#define AES_IV_SIZE
AES (GCM) IV size.
static int res
struct GNUNET_HashCode key
The key used in the DHT.
#define AES_KEY_SIZE
AES key size.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_sender_timeout()

static void reschedule_sender_timeout ( struct SenderAddress sender)
static

Increment sender timeout due to activity.

Parameters
senderaddress for which the timeout should be rescheduled

Definition at line 1013 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_update_cost(), GNUNET_TIME_relative_to_absolute(), SenderAddress::hn, and SenderAddress::timeout.

Referenced by setup_sender().

1014 {
1015  sender->timeout =
1018 }
void GNUNET_CONTAINER_heap_update_cost(struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost)
Updates the cost of any node in the tree.
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:246
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
uint64_t abs_value_us
The actual value.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_receiver_timeout()

static void reschedule_receiver_timeout ( struct ReceiverAddress receiver)
static

Increment receiver timeout due to activity.

Parameters
receiveraddress for which the timeout should be rescheduled

Definition at line 1027 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_update_cost(), GNUNET_TIME_relative_to_absolute(), ReceiverAddress::hn, and ReceiverAddress::timeout.

Referenced by mq_send_d(), and mq_send_kx().

1028 {
1029  receiver->timeout =
1032  receiver->timeout.abs_value_us);
1033 }
void GNUNET_CONTAINER_heap_update_cost(struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost)
Updates the cost of any node in the tree.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
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:246
uint64_t abs_value_us
The actual value.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_timeouts()

static void check_timeouts ( void *  cls)
static

Task run to check #receiver_heap and #sender_heap for timeouts.

Parameters
clsunused, NULL

Definition at line 1042 of file gnunet-communicator-udp.c.

References GNUNET_CONTAINER_heap_peek(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_TIME_UNIT_FOREVER_REL, UdpHandshakeSignature::receiver, receiver_destroy(), GNUNET_TIME_Relative::rel_value_us, UdpHandshakeSignature::sender, sender_destroy(), SenderAddress::timeout, and ReceiverAddress::timeout.

Referenced by mq_init(), and setup_sender().

1043 {
1044  struct GNUNET_TIME_Relative st;
1045  struct GNUNET_TIME_Relative rt;
1046  struct GNUNET_TIME_Relative delay;
1047  struct ReceiverAddress *receiver;
1048  struct SenderAddress *sender;
1049 
1050  (void) cls;
1051  timeout_task = NULL;
1053  while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
1054  {
1056  if (0 != rt.rel_value_us)
1057  break;
1059  "Receiver timed out\n");
1060  receiver_destroy (receiver);
1061  }
1063  while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1064  {
1066  if (0 != st.rel_value_us)
1067  break;
1068  sender_destroy (sender);
1069  }
1071  if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1073 }
uint64_t rel_value_us
The actual value.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
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
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Information we track per receiving address we have recently been in contact with (encryption to recei...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
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:331
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
static void sender_destroy(struct SenderAddress *sender)
Functions with this signature are called whenever we need to close a sender&#39;s state due to timeout...
Time for relative time used by GNUnet, in microseconds.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_cmac()

static void calculate_cmac ( struct SharedSecret ss)
static

Calcualte cmac from master in ss.

Parameters
ss[in,out]data structure to complete

Definition at line 1082 of file gnunet-communicator-udp.c.

References SharedSecret::cmac, GNUNET_CRYPTO_hkdf(), and SharedSecret::master.

Referenced by setup_shared_secret_enc(), and sock_read().

1083 {
1084  GNUNET_CRYPTO_hkdf (&ss->cmac,
1085  sizeof(ss->cmac),
1086  GCRY_MD_SHA512,
1087  GCRY_MD_SHA256,
1088  "CMAC",
1089  strlen ("CMAC"),
1090  &ss->master,
1091  sizeof(ss->master),
1092  "UDP-CMAC",
1093  strlen ("UDP-CMAC"),
1094  NULL,
1095  0);
1096 }
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
int GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:320
struct GNUNET_HashCode master
Master shared secret.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pass_plaintext_to_core()

static void pass_plaintext_to_core ( struct SenderAddress sender,
const void *  plaintext,
size_t  plaintext_len 
)
static

We received plaintext_len bytes of plaintext from a sender.

Pass it on to CORE.

Parameters
queuethe queue that received the plaintext
plaintextthe plaintext that was received
plaintext_lennumber of bytes of plaintext received

Definition at line 1108 of file gnunet-communicator-udp.c.

References ADDRESS_VALIDITY_PERIOD, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TRANSPORT_communicator_receive(), GNUNET_MessageHeader::size, and SenderAddress::target.

Referenced by try_handle_plaintext().

1111 {
1112  const struct GNUNET_MessageHeader *hdr = plaintext;
1113  const char *pos = plaintext;
1114 
1115  while (ntohs (hdr->size) < plaintext_len)
1116  {
1118  "# bytes given to core",
1119  ntohs (hdr->size),
1120  GNUNET_NO);
1122  "Giving %u bytes to TNG\n", ntohs (hdr->size));
1125  &sender->target,
1126  hdr,
1128  NULL /* no flow control possible */
1129  ,
1130  NULL));
1131  /* move on to next message, if any */
1132  plaintext_len -= ntohs (hdr->size);
1133  if (plaintext_len < sizeof(*hdr))
1134  break;
1135  pos += ntohs (hdr->size);
1136  hdr = (const struct GNUNET_MessageHeader *) pos;
1137  // TODO for now..., we do not actually sen >1msg or have a way of telling
1138  // if we are done
1139  break;
1140  }
1142  "# bytes padding discarded",
1143  plaintext_len,
1144  GNUNET_NO);
1145 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_PeerIdentity target
To whom are we talking to.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Header for all communications.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_cipher()

static void setup_cipher ( const struct GNUNET_HashCode msec,
uint32_t  serial,
gcry_cipher_hd_t *  cipher 
)
static

Setup cipher based on shared secret msec and serial number serial.

Parameters
msecmaster shared secret
serialserial number of cipher to set up
cipher[out]cipher to initialize

Definition at line 1157 of file gnunet-communicator-udp.c.

References AES_IV_SIZE, AES_KEY_SIZE, get_iv_key(), GNUNET_assert, and key.

Referenced by mq_send_d(), mq_send_kx(), and try_decrypt().

1160 {
1161  char key[AES_KEY_SIZE];
1162  char iv[AES_IV_SIZE];
1163  int rc;
1164 
1165  GNUNET_assert (0 ==
1166  gcry_cipher_open (cipher,
1167  GCRY_CIPHER_AES256 /* low level: go for speed */,
1168  GCRY_CIPHER_MODE_GCM,
1169  0 /* flags */));
1170  get_iv_key (msec, serial, key, iv);
1171  rc = gcry_cipher_setkey (*cipher, key, sizeof(key));
1172  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1173  rc = gcry_cipher_setiv (*cipher, iv, sizeof(iv));
1174  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1175 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define AES_IV_SIZE
AES (GCM) IV size.
struct GNUNET_HashCode key
The key used in the DHT.
#define AES_KEY_SIZE
AES key size.
static void get_iv_key(const struct GNUNET_HashCode *msec, uint32_t serial, char key[(256/8)], char iv[(96/8)])
Compute key and iv.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_decrypt()

static int try_decrypt ( const struct SharedSecret ss,
const char  tag[(128/8)],
uint32_t  serial,
const char *  in_buf,
size_t  in_buf_size,
char *  out_buf 
)
static

Try to decrypt buf using shared secret ss and key/iv derived using serial.

Parameters
ssshared secret
tagGCM authentication tag
serialserial number to use
in_bufinput buffer to decrypt
in_buf_sizenumber of bytes in in_buf and available in out_buf
out_bufwhere to write the result
Returns
GNUNET_OK on success

Definition at line 1191 of file gnunet-communicator-udp.c.

References GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, SharedSecret::master, and setup_cipher().

Referenced by decrypt_box(), and sock_read().

1197 {
1198  gcry_cipher_hd_t cipher;
1199 
1200  setup_cipher (&ss->master, serial, &cipher);
1201  GNUNET_assert (
1202  0 ==
1203  gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1204  if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
1205  {
1206  gcry_cipher_close (cipher);
1208  "# AEAD authentication failures",
1209  1,
1210  GNUNET_NO);
1211  return GNUNET_SYSERR;
1212  }
1213  gcry_cipher_close (cipher);
1214  return GNUNET_OK;
1215 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GCM_TAG_SIZE
Size of the GCM tag.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
struct GNUNET_HashCode master
Master shared secret.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_shared_secret_dec()

static struct SharedSecret* setup_shared_secret_dec ( const struct GNUNET_CRYPTO_EcdhePublicKey ephemeral)
static

Setup shared secret for decryption.

Parameters
ephemeralephemeral key we received from the other peer
Returns
new shared secret

Definition at line 1225 of file gnunet-communicator-udp.c.

References GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_new, and SharedSecret::master.

Referenced by sock_read().

1226 {
1227  struct SharedSecret *ss;
1228 
1229  ss = GNUNET_new (struct SharedSecret);
1230  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master);
1231  return ss;
1232 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int 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:1024
struct GNUNET_HashCode master
Master shared secret.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
Shared secret we generated for a particular sender or receiver.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_shared_secret_enc()

static struct SharedSecret* setup_shared_secret_enc ( const struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral,
struct ReceiverAddress receiver 
)
static

Setup shared secret for encryption.

Parameters
ephemeralephemeral key we are sending to the other peer
receiver[in,out]queue to initialize encryption key for
Returns
new shared secret

Definition at line 1243 of file gnunet-communicator-udp.c.

References calculate_cmac(), GNUNET_CONTAINER_DLL_insert, GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), SharedSecret::master, ReceiverAddress::num_secrets, GNUNET_PeerIdentity::public_key, SharedSecret::receiver, UdpHandshakeSignature::receiver, setup_receiver_mq(), ReceiverAddress::ss_head, ReceiverAddress::ss_tail, and ReceiverAddress::target.

Referenced by mq_send_kx().

1245 {
1246  struct SharedSecret *ss;
1247 
1248  ss = GNUNET_new (struct SharedSecret);
1249  GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
1250  &receiver->target.public_key,
1251  &ss->master);
1252  calculate_cmac (ss);
1253  ss->receiver = receiver;
1254  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1255  receiver->num_secrets++;
1256  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1257  return ss;
1258 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int num_secrets
Length of the DLL at ss_head.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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_HashCode master
Master shared secret.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
int 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:1084
Shared secret we generated for a particular sender or receiver.
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void calculate_cmac(struct SharedSecret *ss)
Calcualte cmac from master in ss.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_receiver_mq()

static void setup_receiver_mq ( struct ReceiverAddress receiver)
static

Setup the MQ for the receiver.

If a queue exists, the existing one is destroyed. Then the MTU is recalculated and a fresh queue is initialized.

Parameters
receiverreceiver to setup MQ for

Definition at line 2166 of file gnunet-communicator-udp.c.

References ReceiverAddress::address, ReceiverAddress::d_mq, ReceiverAddress::d_mtu, ReceiverAddress::d_qh, ReceiverAddress::foreign_addr, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_queue_for_callbacks(), GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_CS_OUTBOUND, GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, ReceiverAddress::kx_mq, ReceiverAddress::kx_mtu, ReceiverAddress::kx_qh, mq_cancel(), mq_destroy_d(), mq_destroy_kx(), mq_error(), mq_send_d(), mq_send_kx(), ReceiverAddress::nt, and ReceiverAddress::target.

Referenced by mq_init(), and setup_shared_secret_enc().

2167 {
2168  size_t base_mtu;
2169 
2170  /*if (NULL != receiver->kx_qh)
2171  {
2172  GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh);
2173  receiver->kx_qh = NULL;
2174  }
2175  if (NULL != receiver->d_qh)
2176  {
2177  GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh);
2178  receiver->d_qh = NULL;
2179  }*/
2180  // GNUNET_assert (NULL == receiver->mq);
2181  switch (receiver->address->sa_family)
2182  {
2183  case AF_INET:
2184  base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
2185  - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
2186  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2187  break;
2188 
2189  case AF_INET6:
2190  base_mtu = 1280 /* Minimum MTU required by IPv6 */
2191  - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
2192  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2193  break;
2194 
2195  default:
2196  GNUNET_assert (0);
2197  break;
2198  }
2199  /* MTU based on full KX messages */
2200  receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
2201  - sizeof(struct UDPConfirmation); /* 104 */
2202  /* MTU based on BOXed messages */
2203  receiver->d_mtu = base_mtu - sizeof(struct UDPBox);
2204 
2206  "Setting up MQs and QHs\n");
2207  /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
2208  1404 (IPv4 + Box) bytes, depending on circumstances... */
2209  if (NULL == receiver->kx_mq)
2211  &mq_destroy_kx,
2212  &mq_cancel,
2213  receiver,
2214  NULL,
2215  &mq_error,
2216  receiver);
2217  if (NULL == receiver->d_mq)
2219  &mq_destroy_d,
2220  &mq_cancel,
2221  receiver,
2222  NULL,
2223  &mq_error,
2224  receiver);
2225 
2226  receiver->kx_qh =
2228  &receiver->target,
2229  receiver->foreign_addr,
2230  receiver->kx_mtu,
2232  0, /* Priority */
2233  receiver->nt,
2235  receiver->kx_mq);
2236  receiver->d_qh =
2238  &receiver->target,
2239  receiver->foreign_addr,
2240  receiver->d_mtu,
2241  0, /* Initialize with 0 acks */
2242  1, /* Priority */
2243  receiver->nt,
2245  receiver->d_mq);
2246 
2247 }
static void mq_send_d(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
UDP packet header.
Standard IPv4 header.
Encrypted continuation of UDP initial handshake, followed by message header with payload.
"Plaintext" header at beginning of KX message.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
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:561
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
size_t kx_mtu
MTU we allowed transport for this receiver&#39;s KX queue.
UDP message box.
static void mq_destroy_kx(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
size_t d_mtu
MTU we allowed transport for this receiver&#39;s default queue.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
Standard IPv6 header.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
this is an outbound connection (transport initiated)
#define GNUNET_log(kind,...)
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static void mq_send_kx(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
struct GNUNET_TRANSPORT_QueueHandle * kx_qh
handle for KX queue with the ch.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_ack()

static int handle_ack ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

We received an ACK for pid.

Check if it is for the receiver in value and if so, handle it and return GNUNET_NO. Otherwise, return GNUNET_YES.

Parameters
clsa const struct UDPAck
pidpeer the ACK is from
valuea struct ReceiverAddress
Returns
GNUNET_YES to continue to iterate

Definition at line 1283 of file gnunet-communicator-udp.c.

References ReceiverAddress::acks_available, UDPAck::cmac, ReceiverAddress::d_qh, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_TRANSPORT_communicator_mq_update(), GNUNET_YES, SharedSecret::next, UDPAck::sequence_max, ReceiverAddress::ss_head, ReceiverAddress::ss_tail, and value.

Referenced by enc_notify_cb(), and try_handle_plaintext().

1284 {
1285  const struct UDPAck *ack = cls;
1286  struct ReceiverAddress *receiver = value;
1288  "in handle ack\n");
1289 
1290  (void) pid;
1291  for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1292  {
1293  if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1294  {
1295  uint32_t allowed;
1297  "Found matching mac\n");
1298 
1299  allowed = ntohl (ack->sequence_max);
1300 
1301  if (allowed > ss->sequence_allowed)
1302  {
1304  "%u > %u (%u)\n", allowed, ss->sequence_allowed,
1305  receiver->acks_available);
1306 
1307  receiver->acks_available += (allowed - ss->sequence_allowed);
1309  "Tell transport we have more acks!\n");
1311  receiver->d_qh,
1312  (allowed - ss->sequence_allowed),
1313  1);
1314  ss->sequence_allowed = allowed;
1315  /* move ss to head to avoid discarding it anytime soon! */
1316  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1317  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1318  }
1319  return GNUNET_NO;
1320  }
1321  }
1322  return GNUNET_YES;
1323 }
#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.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
static char * value
Value of the record to add/remove.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
A 512-bit hashcode.
struct SharedSecret * next
Kept in a DLL.
Information we track per receiving address we have recently been in contact with (encryption to recei...
struct GNUNET_HashCode cmac
CMAC of the base key being acknowledged.
Shared secret we generated for a particular sender or receiver.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
uint32_t sequence_max
Sequence acknowledgement limit.
#define GNUNET_log(kind,...)
UDP key acknowledgement.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
void GNUNET_TRANSPORT_communicator_mq_update(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_TRANSPORT_QueueHandle *u_qh, uint64_t q_len, uint32_t priority)
Notify transport service that an MQ was updated.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_handle_plaintext()

static void try_handle_plaintext ( struct SenderAddress sender,
const void *  buf,
size_t  buf_size 
)
static

Test if we have received a valid message in plaintext.

If so, handle it.

Parameters
senderpeer to process inbound plaintext for
bufbuffer we received
buf_sizenumber of bytes in buf

Definition at line 1335 of file gnunet-communicator-udp.c.

References GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK, GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD, handle_ack(), pass_plaintext_to_core(), GNUNET_MessageHeader::size, SenderAddress::target, type, and GNUNET_MessageHeader::type.

Referenced by decrypt_box(), and sock_read().

1338 {
1339  const struct GNUNET_MessageHeader *hdr =
1340  (const struct GNUNET_MessageHeader *) buf;
1341  const struct UDPAck *ack = (const struct UDPAck *) buf;
1342  uint16_t type;
1343 
1344  if (sizeof(*hdr) > buf_size)
1345  return; /* not even a header */
1346  if (ntohs (hdr->size) > buf_size)
1347  return; /* not even a header */
1348  type = ntohs (hdr->type);
1349  switch (type)
1350  {
1352  /* lookup master secret by 'cmac', then update sequence_max */
1354  &sender->target,
1355  &handle_ack,
1356  (void *) ack);
1357  /* There could be more messages after the ACK, handle those as well */
1358  buf += ntohs (hdr->size);
1359  buf_size -= ntohs (hdr->size);
1360  pass_plaintext_to_core (sender, buf, buf_size);
1361  break;
1362 
1364  /* skip padding */
1365  break;
1366 
1367  default:
1368  pass_plaintext_to_core (sender, buf, buf_size);
1369  }
1370 }
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD
UDP communicator padding.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
static int handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
We received an ACK for pid.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_PeerIdentity target
To whom are we talking to.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static void pass_plaintext_to_core(struct SenderAddress *sender, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext from a sender.
static char buf[2048]
UDP key acknowledgement.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ consider_ss_ack()

static void consider_ss_ack ( struct SharedSecret ss)
static

We established a shared secret with a sender.

We should try to send the sender an struct UDPAck at the next opportunity to allow the sender to use ss longer (assuming we did not yet already recently).

Parameters
ssshared secret to generate ACKs for

Definition at line 1382 of file gnunet-communicator-udp.c.

References SharedSecret::active_kce_count, UDPAck::cmac, SharedSecret::cmac, COMMUNICATOR_ADDRESS_PREFIX, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s_full(), GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK, GNUNET_TRANSPORT_communicator_notify(), UDPAck::header, kce_destroy(), kce_generate(), SharedSecret::kce_head, SharedSecret::kce_tail, KCN_TARGET, KCN_THRESHOLD, MAX_SQN_DELTA, SharedSecret::sender, SharedSecret::sequence_allowed, UDPAck::sequence_max, KeyCacheEntry::sequence_number, GNUNET_MessageHeader::size, SenderAddress::target, and GNUNET_MessageHeader::type.

Referenced by decrypt_box(), and sock_read().

1383 {
1384  GNUNET_assert (NULL != ss->sender);
1385  /* drop ancient KeyCacheEntries */
1386  while ((NULL != ss->kce_head) &&
1387  (MAX_SQN_DELTA <
1389  kce_destroy (ss->kce_tail);
1390  if (ss->active_kce_count < KCN_THRESHOLD)
1391  {
1392  struct UDPAck ack;
1393 
1394  while (ss->active_kce_count < KCN_TARGET)
1395  kce_generate (ss, ++ss->sequence_allowed);
1396  ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
1397  ack.header.size = htons (sizeof(ack));
1398  ack.sequence_max = htonl (ss->sequence_allowed);
1399  ack.cmac = ss->cmac;
1401  "Notifying transport of UDPAck %s\n",
1402  GNUNET_i2s_full (&ss->sender->target));
1404  &ss->sender->target,
1406  &ack.header);
1407  }
1408 }
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
#define KCN_TARGET
How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD s...
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
unsigned int active_kce_count
Number of active KCN entries.
#define KCN_THRESHOLD
If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET...
void GNUNET_TRANSPORT_communicator_notify(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *pid, const char *comm, const struct GNUNET_MessageHeader *header)
The communicator asks the transport service to route a message via a different path to another commun...
#define GNUNET_log(kind,...)
UDP key acknowledgement.
#define MAX_SQN_DELTA
What is the maximum delta between KCN sequence numbers that we allow.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static void kce_generate(struct SharedSecret *ss, uint32_t seq)
Setup key cache entry for sequence number seq and shared secret ss.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_box()

static void decrypt_box ( const struct UDPBox box,
size_t  box_len,
struct KeyCacheEntry kce 
)
static

We received a box with matching kce.

Decrypt and process it.

Parameters
boxthe data we received
box_lennumber of bytes in box
kcekey index to decrypt box

Definition at line 1419 of file gnunet-communicator-udp.c.

References consider_ss_ack(), UDPBox::gcm_tag, GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), kce_destroy(), SharedSecret::sender, KeyCacheEntry::sequence_number, KeyCacheEntry::ss, try_decrypt(), and try_handle_plaintext().

Referenced by sock_read().

1422 {
1423  struct SharedSecret *ss = kce->ss;
1424  char out_buf[box_len - sizeof(*box)];
1425 
1426  GNUNET_assert (NULL != ss->sender);
1427  if (GNUNET_OK != try_decrypt (ss,
1428  box->gcm_tag,
1429  kce->sequence_number,
1430  (const char *) &box[1],
1431  sizeof(out_buf),
1432  out_buf))
1433  {
1435  "# Decryption failures with valid KCE",
1436  1,
1437  GNUNET_NO);
1438  kce_destroy (kce);
1439  return;
1440  }
1441  kce_destroy (kce);
1443  "# bytes decrypted with BOX",
1444  sizeof(out_buf),
1445  GNUNET_NO);
1446  try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
1447  consider_ss_ack (ss);
1448 }
static void consider_ss_ack(struct SharedSecret *ss)
We established a shared secret with a sender.
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct SharedSecret * ss
Corresponding shared secret.
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
static void try_handle_plaintext(struct SenderAddress *sender, const void *buf, size_t buf_size)
Test if we have received a valid message in plaintext.
Shared secret we generated for a particular sender or receiver.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static int try_decrypt(const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
Try to decrypt buf using shared secret ss and key/iv derived using serial.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_sender_by_address()

static int find_sender_by_address ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Find existing struct SenderAddress by matching addresses.

Parameters
clsa struct SearchContext
keyignored, must match already
valuea struct SenderAddress
Returns
GNUNET_YES if not found (continue to search), GNUNET_NO if found

Definition at line 1482 of file gnunet-communicator-udp.c.

References SenderAddress::address, SearchContext::address, SenderAddress::address_len, SearchContext::address_len, GNUNET_NO, GNUNET_YES, sc, SearchContext::sender, UdpHandshakeSignature::sender, and value.

Referenced by setup_sender().

1485 {
1486  struct SearchContext *sc = cls;
1487  struct SenderAddress *sender = value;
1488 
1489  if ((sender->address_len == sc->address_len) &&
1490  (0 == memcmp (sender->address, sc->address, sender->address_len)))
1491  {
1492  sc->sender = sender;
1493  return GNUNET_NO; /* stop iterating! */
1494  }
1495  return GNUNET_YES;
1496 }
socklen_t address_len
Number of bytes in address.
socklen_t address_len
Length of the address.
static char * value
Value of the record to add/remove.
struct sockaddr * address
Address of the other peer.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:225
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
struct SenderAddress * sender
Return value to set if we found a match.
const struct sockaddr * address
Address we are looking for.
Here is the caller graph for this function:

◆ setup_sender()

static struct SenderAddress* setup_sender ( const struct GNUNET_PeerIdentity target,
const struct sockaddr *  address,
socklen_t  address_len 
)
static

Create sender address for target.

Note that we might already have one, so a fresh one is only allocated if one does not yet exist for address.

Parameters
targetpeer to generate address for
addresstarget address
address_lennumber of bytes in address
Returns
data structure to keep track of key material for decrypting data from target

Definition at line 1511 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, address, SenderAddress::address, SearchContext::address, SenderAddress::address_len, SearchContext::address_len, check_timeouts(), find_sender_by_address(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_memdup, GNUNET_new, GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_set(), GNUNET_TIME_relative_to_absolute(), SenderAddress::hn, SenderAddress::nt, reschedule_sender_timeout(), SearchContext::sender, UdpHandshakeSignature::sender, SenderAddress::target, and SenderAddress::timeout.

Referenced by sock_read().

1514 {
1515  struct SenderAddress *sender;
1516  struct SearchContext sc = { .address = address,
1517  .address_len = address_len,
1518  .sender = NULL };
1519 
1521  target,
1523  &sc);
1524  if (NULL != sc.sender)
1525  {
1527  return sc.sender;
1528  }
1529  sender = GNUNET_new (struct SenderAddress);
1530  sender->target = *target;
1532  sender->address_len = address_len;
1534  senders,
1535  &sender->target,
1536  sender,
1539  "# senders active",
1541  GNUNET_NO);
1542  sender->timeout =
1545  sender,
1546  sender->timeout.abs_value_us);
1548  if (NULL == timeout_task)
1550  return sender;
1551 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
socklen_t address_len
Number of bytes in address.
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:246
socklen_t address_len
Length of the address.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
uint64_t abs_value_us
The actual value.
static void reschedule_sender_timeout(struct SenderAddress *sender)
Increment sender timeout due to activity.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
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
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
struct sockaddr * address
Address of the other peer.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:225
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static int find_sender_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find existing struct SenderAddress by matching addresses.
struct SenderAddress * sender
Return value to set if we found a match.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
static char * address
GNS address for this phone.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
enum GNUNET_NetworkType nt
Which network type does this queue use?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_confirmation()

static int verify_confirmation ( const struct GNUNET_CRYPTO_EcdhePublicKey ephemeral,
const struct UDPConfirmation uc 
)
static

Check signature from uc against ephemeral.

Parameters
ephermalkey that is signed
ucsignature of claimant
Returns
GNUNET_OK if signature is valid

Definition at line 1562 of file gnunet-communicator-udp.c.

References UdpHandshakeSignature::ephemeral, GNUNET_CRYPTO_eddsa_verify, GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, UDPConfirmation::monotonic_time, UdpHandshakeSignature::monotonic_time, my_identity, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpHandshakeSignature::purpose, UdpHandshakeSignature::receiver, UDPConfirmation::sender, UdpHandshakeSignature::sender, UDPConfirmation::sender_sig, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by sock_read().

1564 {
1565  struct UdpHandshakeSignature uhs;
1566 
1568  uhs.purpose.size = htonl (sizeof(uhs));
1569  uhs.sender = uc->sender;
1570  uhs.receiver = my_identity;
1571  uhs.ephemeral = *ephemeral;
1572  uhs.monotonic_time = uc->monotonic_time;
1575  &uhs,
1576  &uc->sender_sig,
1577  &uc->sender.public_key);
1578 }
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
Signature used by UDP communicator handshake.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the caller graph for this function:

◆ sockaddr_to_udpaddr_string()

static char* sockaddr_to_udpaddr_string ( const struct sockaddr *  address,
socklen_t  address_len 
)
static

Converts address to the address string format used by this communicator in HELLOs.

Parameters
addressthe address to convert, must be AF_INET or AF_INET6.
address_lennumber of bytes in address
Returns
string representation of address

Definition at line 1590 of file gnunet-communicator-udp.c.

References COMMUNICATOR_ADDRESS_PREFIX, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_assert, and ret.

Referenced by mq_init(), and sock_read().

1592 {
1593  char *ret;
1594 
1595  switch (address->sa_family)
1596  {
1597  case AF_INET:
1598  GNUNET_asprintf (&ret,
1599  "%s-%s",
1601  GNUNET_a2s (address, address_len));
1602  break;
1603 
1604  case AF_INET6:
1605  GNUNET_asprintf (&ret,
1606  "%s-%s",
1608  GNUNET_a2s (address, address_len));
1609  break;
1610 
1611  default:
1612  GNUNET_assert (0);
1613  }
1614  return ret;
1615 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static char * address
GNS address for this phone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sock_read()

static void sock_read ( void *  cls)
static

Socket read task.

Parameters
clsNULL

Definition at line 1624 of file gnunet-communicator-udp.c.

References buf, calculate_cmac(), consider_ss_ack(), decrypt_box(), InitialKX::ephemeral, InitialKX::gcm_tag, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_eddsa_verify, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_application_validate(), UdpBroadcastSignature::h_address, UDPBox::kid, MAX_SECRETS, nt, SenderAddress::num_secrets, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpBroadcastSignature::purpose, secret_destroy(), UDPConfirmation::sender, UdpBroadcastSignature::sender, SharedSecret::sender, UdpHandshakeSignature::sender, setup_sender(), setup_shared_secret_dec(), GNUNET_CRYPTO_EccSignaturePurpose::size, sockaddr_to_udpaddr_string(), SenderAddress::ss_head, SenderAddress::ss_tail, try_decrypt(), try_handle_plaintext(), uc, and verify_confirmation().

Referenced by run().

1625 {
1626  struct sockaddr_storage sa;
1627  socklen_t salen = sizeof(sa);
1628  char buf[UINT16_MAX];
1629  ssize_t rcvd;
1630 
1631  (void) cls;
1633  udp_sock,
1634  &sock_read,
1635  NULL);
1637  buf,
1638  sizeof(buf),
1639  (struct sockaddr *) &sa,
1640  &salen);
1641  if (-1 == rcvd)
1642  {
1644  return;
1645  }
1647  "Read %lu bytes\n", rcvd);
1648  /* first, see if it is a UDPBox */
1649  if (rcvd > sizeof(struct UDPBox))
1650  {
1651  const struct UDPBox *box;
1652  struct KeyCacheEntry *kce;
1653 
1654  box = (const struct UDPBox *) buf;
1656  if (NULL != kce)
1657  {
1658  decrypt_box (box, (size_t) rcvd, kce);
1659  return;
1660  }
1661  }
1662 
1663  /* next, check if it is a broadcast */
1664  if (sizeof(struct UDPBroadcast) == rcvd)
1665  {
1666  const struct UDPBroadcast *ub;
1667  struct UdpBroadcastSignature uhs;
1668 
1669  ub = (const struct UDPBroadcast *) buf;
1670  uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
1671  uhs.purpose.size = htonl (sizeof(uhs));
1672  uhs.sender = ub->sender;
1673  GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
1674  if (GNUNET_OK ==
1676  &uhs,
1677  &ub->sender_sig,
1678  &ub->sender.public_key))
1679  {
1680  char *addr_s;
1681  enum GNUNET_NetworkType nt;
1682 
1683  addr_s =
1684  sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
1685  GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
1686  /* use our own mechanism to determine network type */
1687  nt =
1688  GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
1689  GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
1690  GNUNET_free (addr_s);
1691  return;
1692  }
1693  /* continue with KX, mostly for statistics... */
1694  }
1695 
1696 
1697  /* finally, test if it is a KX */
1698  if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
1699  {
1701  "# messages dropped (no kid, too small for KX)",
1702  1,
1703  GNUNET_NO);
1704  return;
1705  }
1707  "Got KX\n");
1708  {
1709  const struct InitialKX *kx;
1710  struct SharedSecret *ss;
1711  char pbuf[rcvd - sizeof(struct InitialKX)];
1712  const struct UDPConfirmation *uc;
1713  struct SenderAddress *sender;
1714 
1715  kx = (const struct InitialKX *) buf;
1716  ss = setup_shared_secret_dec (&kx->ephemeral);
1717  if (GNUNET_OK != try_decrypt (ss,
1718  kx->gcm_tag,
1719  0,
1720  &buf[sizeof(*kx)],
1721  sizeof(pbuf),
1722  pbuf))
1723  {
1725  "Unable to decrypt tag, dropping...\n");
1726  GNUNET_free (ss);
1728  stats,
1729  "# messages dropped (no kid, AEAD decryption failed)",
1730  1,
1731  GNUNET_NO);
1732  return;
1733  }
1734  uc = (const struct UDPConfirmation *) pbuf;
1735  if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc))
1736  {
1737  GNUNET_break_op (0);
1738  GNUNET_free (ss);
1740  "# messages dropped (sender signature invalid)",
1741  1,
1742  GNUNET_NO);
1743  return;
1744  }
1745  calculate_cmac (ss);
1746  sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
1747  ss->sender = sender;
1748  GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
1749  sender->num_secrets++;
1750  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1752  "# messages decrypted without BOX",
1753  1,
1754  GNUNET_NO);
1755  try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
1756  consider_ss_ack (ss);
1757  if (sender->num_secrets > MAX_SECRETS)
1758  secret_destroy (sender->ss_tail);
1759  }
1760 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
static void consider_ss_ack(struct SharedSecret *ss)
We established a shared secret with a sender.
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
Our handle to report addresses for validation to TRANSPORT.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Broadcast by peer in LAN announcing its presence.
static struct SenderAddress * setup_sender(const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
Create sender address for target.
char gcm_tag[(128/8)]
HMAC for the following encrypted message, using GCM.
static struct SharedSecret * setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
Setup shared secret for decryption.
void GNUNET_TRANSPORT_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key for KX.
static void secret_destroy(struct SharedSecret *ss)
Destroy ss and associated key cache entries.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
static struct GNUNET_FS_UnindexContext * uc
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
Encrypted continuation of UDP initial handshake, followed by message header with payload.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static char * sockaddr_to_udpaddr_string(const struct sockaddr *address, socklen_t address_len)
Converts address to the address string format used by this communicator in HELLOs.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
"Plaintext" header at beginning of KX message.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
static int verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, const struct UDPConfirmation *uc)
Check signature from uc against ephemeral.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
Signature used by UDP broadcasts.
#define MAX_SECRETS
How many shared master secrets do we keep around at most per sender? Should be large enough so that w...
static char buf[2048]
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
UDP message box.
static void sock_read(void *cls)
Socket read task.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static void try_handle_plaintext(struct SenderAddress *sender, const void *buf, size_t buf_size)
Test if we have received a valid message in plaintext.
Shared secret we generated for a particular sender or receiver.
unsigned int num_secrets
Length of the DLL at ss_head.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static void decrypt_box(const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
We received a box with matching kce.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
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.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
Signature we use to verify that the broadcast was really made by the peer that claims to have made it...
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
static void calculate_cmac(struct SharedSecret *ss)
Calcualte cmac from master in ss.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition: network.c:754
#define GNUNET_free(ptr)
Wrapper around free.
static int try_decrypt(const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
Try to decrypt buf using shared secret ss and key/iv derived using serial.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_address_to_sockaddr()

static struct sockaddr* udp_address_to_sockaddr ( const char *  bindto,
socklen_t *  sock_len 
)
static

Convert UDP bind specification to a struct sockaddr *

Parameters
bindtobind specification to convert
[out]sock_lenset to the length of the address
Returns
converted bindto specification

Definition at line 1771 of file gnunet-communicator-udp.c.

References COMMUNICATOR_CONFIG_SECTION, dummy, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memdup, GNUNET_NETWORK_test_pf(), GNUNET_NO, GNUNET_strdup, GNUNET_YES, port, and start.

Referenced by mq_init(), and run().

1772 {
1773  struct sockaddr *in;
1774  unsigned int port;
1775  char dummy[2];
1776  char *colon;
1777  char *cp;
1778 
1779  if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1780  {
1781  /* interpreting value as just a PORT number */
1782  if (port > UINT16_MAX)
1783  {
1785  "BINDTO specification `%s' invalid: value too large for port\n",
1786  bindto);
1787  return NULL;
1788  }
1789  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1790  (GNUNET_YES ==
1793  "DISABLE_V6")))
1794  {
1795  struct sockaddr_in *i4;
1796 
1797  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1798  i4->sin_family = AF_INET;
1799  i4->sin_port = htons ((uint16_t) port);
1800  *sock_len = sizeof(struct sockaddr_in);
1801  in = (struct sockaddr *) i4;
1802  }
1803  else
1804  {
1805  struct sockaddr_in6 *i6;
1806 
1807  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1808  i6->sin6_family = AF_INET6;
1809  i6->sin6_port = htons ((uint16_t) port);
1810  *sock_len = sizeof(struct sockaddr_in6);
1811  in = (struct sockaddr *) i6;
1812  }
1813  return in;
1814  }
1815  cp = GNUNET_strdup (bindto);
1816  colon = strrchr (cp, ':');
1817  if (NULL != colon)
1818  {
1819  /* interpet value after colon as port */
1820  *colon = '\0';
1821  colon++;
1822  if (1 == sscanf (colon, "%u%1s", &port, dummy))
1823  {
1824  /* interpreting value as just a PORT number */
1825  if (port > UINT16_MAX)
1826  {
1828  "BINDTO specification `%s' invalid: value too large for port\n",
1829  bindto);
1830  GNUNET_free (cp);
1831  return NULL;
1832  }
1833  }
1834  else
1835  {
1836  GNUNET_log (
1838  "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1839  bindto);
1840  GNUNET_free (cp);
1841  return NULL;
1842  }
1843  }
1844  else
1845  {
1846  /* interpret missing port as 0, aka pick any free one */
1847  port = 0;
1848  }
1849  {
1850  /* try IPv4 */
1851  struct sockaddr_in v4;
1852  if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
1853  {
1854  v4.sin_family = AF_INET;
1855  v4.sin_port = htons ((uint16_t) port);
1856 #if HAVE_SOCKADDR_IN_SIN_LEN
1857  v4.sin_len = sizeof(struct sockaddr_in);
1858 #endif
1859  in = GNUNET_memdup (&v4, sizeof(struct sockaddr_in));
1860  *sock_len = sizeof(struct sockaddr_in);
1861  GNUNET_free (cp);
1862  return in;
1863  }
1864  }
1865  {
1866  /* try IPv6 */
1867  struct sockaddr_in6 v6;
1868  const char *start;
1869 
1870  start = cp;
1871  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1872  {
1873  start++; /* skip over '[' */
1874  cp[strlen (cp) - 1] = '\0'; /* eat ']' */
1875  }
1876  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
1877  {
1878  v6.sin6_family = AF_INET6;
1879  v6.sin6_port = htons ((uint16_t) port);
1880 #if HAVE_SOCKADDR_IN_SIN_LEN
1881  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
1882 #endif
1883  in = GNUNET_memdup (&v6, sizeof(v6));
1884  *sock_len = sizeof(v6);
1885  GNUNET_free (cp);
1886  return in;
1887  }
1888  }
1889  /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1890  GNUNET_free (cp);
1891  return NULL;
1892 }
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_pad()

static void do_pad ( gcry_cipher_hd_t  out_cipher,
char *  dgram,
size_t  pad_size 
)
static

Pad dgram by pad_size using out_cipher.

Parameters
out_ciphercipher to use
dgramdatagram to pad
pad_sizenumber of bytes of padding to append

Definition at line 1903 of file gnunet-communicator-udp.c.

References GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD, and GNUNET_MessageHeader::size.

Referenced by mq_send_d(), and mq_send_kx().

1904 {
1905  char pad[pad_size];
1906 
1908  if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
1909  {
1910  struct GNUNET_MessageHeader hdr =
1911  { .size = htons (sizeof(pad)),
1912  .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
1913 
1914  memcpy (pad, &hdr, sizeof(hdr));
1915  }
1916  GNUNET_assert (
1917  0 ==
1918  gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
1919 }
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD
UDP communicator padding.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
Header for all communications.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send_kx()

static void mq_send_kx ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Signature of functions implementing the sending functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct ReceiverAddress

Definition at line 1931 of file gnunet-communicator-udp.c.

References ReceiverAddress::address, ReceiverAddress::address_len, do_pad(), UdpHandshakeSignature::ephemeral, InitialKX::ephemeral, InitialKX::gcm_tag, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_MQ_impl_send_continue(), GNUNET_NETWORK_socket_sendto(), GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), ReceiverAddress::kx_mq, ReceiverAddress::kx_mtu, SharedSecret::master, UDPConfirmation::monotonic_time, UdpHandshakeSignature::monotonic_time, my_identity, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpHandshakeSignature::purpose, UdpHandshakeSignature::receiver, receiver_destroy(), reschedule_receiver_timeout(), UDPConfirmation::sender, UdpHandshakeSignature::sender, UDPConfirmation::sender_sig, setup_cipher(), setup_shared_secret_enc(), GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, ReceiverAddress::target, and uc.

Referenced by setup_receiver_mq().

1934 {
1935  struct ReceiverAddress *receiver = impl_state;
1936  uint16_t msize = ntohs (msg->size);
1937  struct UdpHandshakeSignature uhs;
1938  struct UDPConfirmation uc;
1939  struct InitialKX kx;
1940  struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
1941  char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)];
1942  size_t dpos;
1943  gcry_cipher_hd_t out_cipher;
1944  struct SharedSecret *ss;
1945 
1946 
1947  GNUNET_assert (mq == receiver->kx_mq);
1948  if (msize > receiver->kx_mtu)
1949  {
1950  GNUNET_break (0);
1951  receiver_destroy (receiver);
1952  return;
1953  }
1954  reschedule_receiver_timeout (receiver);
1955 
1956  /* setup key material */
1958 
1959  ss = setup_shared_secret_enc (&epriv, receiver);
1960  setup_cipher (&ss->master, 0, &out_cipher);
1961  /* compute 'uc' */
1962  uc.sender = my_identity;
1963  uc.monotonic_time =
1965  uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
1966  uhs.purpose.size = htonl (sizeof(uhs));
1967  uhs.sender = my_identity;
1968  uhs.receiver = receiver->target;
1969  GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral);
1970  uhs.monotonic_time = uc.monotonic_time;
1972  &uhs,
1973  &uc.sender_sig);
1974  /* Leave space for kx */
1975  dpos = sizeof(kx);
1976  /* Append encrypted uc to dgram */
1977  GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
1978  &dgram[dpos],
1979  sizeof(uc),
1980  &uc,
1981  sizeof(uc)));
1982  dpos += sizeof(uc);
1983  /* Append encrypted payload to dgram */
1984  GNUNET_assert (
1985  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
1986  dpos += msize;
1987  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
1988  /* Datagram starts with kx */
1989  kx.ephemeral = uhs.ephemeral;
1990  GNUNET_assert (
1991  0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
1992  gcry_cipher_close (out_cipher);
1993  memcpy (dgram, &kx, sizeof(kx));
1995  dgram,
1996  sizeof(dgram),
1997  receiver->address,
1998  receiver->address_len))
2001  "Sending KX to %s\n", GNUNET_a2s (receiver->address,
2002  receiver->address_len));
2004 }
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
static struct GNUNET_FS_UnindexContext * uc
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Encrypted continuation of UDP initial handshake, followed by message header with payload.
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
Signature used by UDP communicator handshake.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
"Plaintext" header at beginning of KX message.
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
struct GNUNET_HashCode master
Master shared secret.
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
size_t kx_mtu
MTU we allowed transport for this receiver&#39;s KX queue.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:850
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
Information we track per receiving address we have recently been in contact with (encryption to recei...
Private ECC key encoded for transmission.
Shared secret we generated for a particular sender or receiver.
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:215
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static void do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
Pad dgram by pad_size using out_cipher.
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.
Definition: time.c:807
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
socklen_t address_len
Length of the address.
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
static struct SharedSecret * setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver)
Setup shared secret for encryption.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:495
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send_d()

static void mq_send_d ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Signature of functions implementing the sending functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct ReceiverAddress

Definition at line 2016 of file gnunet-communicator-udp.c.

References ReceiverAddress::acks_available, ReceiverAddress::d_mq, ReceiverAddress::d_mtu, do_pad(), UDPBox::gcm_tag, get_kid(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_MQ_impl_send_continue(), GNUNET_NETWORK_socket_sendto(), UDPBox::kid, SharedSecret::prev, receiver_destroy(), reschedule_receiver_timeout(), setup_cipher(), GNUNET_MessageHeader::size, and ReceiverAddress::ss_tail.

Referenced by setup_receiver_mq().

2019 {
2020  struct ReceiverAddress *receiver = impl_state;
2021  uint16_t msize = ntohs (msg->size);
2022 
2023  GNUNET_assert (mq == receiver->d_mq);
2024  if ((msize > receiver->d_mtu) ||
2025  (0 == receiver->acks_available))
2026  {
2027  GNUNET_break (0);
2028  receiver_destroy (receiver);
2029  return;
2030  }
2031  reschedule_receiver_timeout (receiver);
2032 
2033  /* begin "BOX" encryption method, scan for ACKs from tail! */
2034  for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
2035  {
2036  if (ss->sequence_used >= ss->sequence_allowed)
2037  {
2038  continue;
2039  }
2040  char dgram[sizeof(struct UDPBox) + receiver->d_mtu];
2041  struct UDPBox *box;
2042  gcry_cipher_hd_t out_cipher;
2043  size_t dpos;
2044 
2045  box = (struct UDPBox *) dgram;
2046  ss->sequence_used++;
2047  get_kid (&ss->master, ss->sequence_used, &box->kid);
2048  setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
2049  /* Append encrypted payload to dgram */
2050  dpos = sizeof(struct UDPBox);
2051  GNUNET_assert (
2052  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2053  dpos += msize;
2054  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2055  GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
2056  box->gcm_tag,
2057  sizeof(box->gcm_tag)));
2058  gcry_cipher_close (out_cipher);
2060  dgram,
2061  sizeof(dgram),
2062  receiver->address,
2063  receiver->address_len))
2066  receiver->acks_available--;
2067  if (0 == receiver->acks_available)
2068  {
2069  /* We have no more ACKs */
2071  "No more acks\n");
2072  }
2073  return;
2074  }
2075 }
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:850
UDP message box.
Information we track per receiving address we have recently been in contact with (encryption to recei...
size_t d_mtu
MTU we allowed transport for this receiver&#39;s default queue.
Shared secret we generated for a particular sender or receiver.
static void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static void do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
Pad dgram by pad_size using out_cipher.
struct SharedSecret * prev
Kept in a DLL.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
socklen_t address_len
Length of the address.
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:495
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy_d()

static void mq_destroy_d ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Signature of functions implementing the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct ReceiverAddress

Definition at line 2087 of file gnunet-communicator-udp.c.

References ReceiverAddress::d_mq, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and receiver_destroy().

Referenced by setup_receiver_mq().

2088 {
2089  struct ReceiverAddress *receiver = impl_state;
2091  "Default MQ destroyed\n");
2092  if (mq == receiver->d_mq)
2093  {
2094  receiver->d_mq = NULL;
2095  receiver_destroy (receiver);
2096  }
2097 }
Information we track per receiving address we have recently been in contact with (encryption to recei...
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy_kx()

static void mq_destroy_kx ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Signature of functions implementing the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct ReceiverAddress

Definition at line 2109 of file gnunet-communicator-udp.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, ReceiverAddress::kx_mq, and receiver_destroy().

Referenced by setup_receiver_mq().

2110 {
2111  struct ReceiverAddress *receiver = impl_state;
2113  "KX MQ destroyed\n");
2114  if (mq == receiver->kx_mq)
2115  {
2116  receiver->kx_mq = NULL;
2117  receiver_destroy (receiver);
2118  }
2119 }
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
Information we track per receiving address we have recently been in contact with (encryption to recei...
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_cancel()

static void mq_cancel ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Implementation function that cancels the currently sent message.

Parameters
mqmessage queue
impl_stateour struct RecvierAddress

Definition at line 2129 of file gnunet-communicator-udp.c.

References GNUNET_assert.

Referenced by setup_receiver_mq().

2130 {
2131  /* Cancellation is impossible with UDP; bail */
2132  GNUNET_assert (0);
2133 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ mq_error()

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

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsour struct ReceiverAddress
errorerror code

Definition at line 2146 of file gnunet-communicator-udp.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, receiver_destroy(), and ReceiverAddress::target.

Referenced by setup_receiver_mq().

2147 {
2148  struct ReceiverAddress *receiver = cls;
2149 
2151  "MQ error in queue to %s: %d\n",
2152  GNUNET_i2s (&receiver->target),
2153  (int) error);
2154  receiver_destroy (receiver);
2155 }
Information we track per receiving address we have recently been in contact with (encryption to recei...
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
struct GNUNET_PeerIdentity target
To whom are we talking to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_init()

static int mq_init ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const char *  address 
)
static

Function called by the transport service to initialize a message queue given address information about another peer.

If and when the communication channel is established, the communicator must call GNUNET_TRANSPORT_communicator_mq_add() to notify the service that the channel is now up. It is the responsibility of the communicator to manage sane retries and timeouts for any peer/address combination provided by the transport service. Timeouts and retries do not need to be signalled to the transport service.

Parameters
clsclosure
peeridentity of the other peer
addresswhere to send the message, human-readable communicator-specific format, 0-terminated, UTF-8
Returns
GNUNET_OK on success, GNUNET_SYSERR if the provided address is invalid

Definition at line 2269 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, ReceiverAddress::address, ReceiverAddress::address_len, check_timeouts(), COMMUNICATOR_ADDRESS_PREFIX, ReceiverAddress::foreign_addr, GNUNET_break_op, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s_full(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TIME_relative_to_absolute(), ReceiverAddress::hn, ReceiverAddress::nt, peer, UdpHandshakeSignature::receiver, setup_receiver_mq(), sockaddr_to_udpaddr_string(), ReceiverAddress::target, ReceiverAddress::timeout, and udp_address_to_sockaddr().

Referenced by run().

2270 {
2271  struct ReceiverAddress *receiver;
2272  const char *path;
2273  struct sockaddr *in;
2274  socklen_t in_len;
2275 
2276  if (0 != strncmp (address,
2278  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2279  {
2280  GNUNET_break_op (0);
2281  return GNUNET_SYSERR;
2282  }
2283  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2284  in = udp_address_to_sockaddr (path, &in_len);
2285 
2286  receiver = GNUNET_new (struct ReceiverAddress);
2287  receiver->address = in;
2288  receiver->address_len = in_len;
2289  receiver->target = *peer;
2290  receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
2292  receivers,
2293  &receiver->target,
2294  receiver,
2297  "Added %s to receivers\n",
2298  GNUNET_i2s_full (&receiver->target));
2299  receiver->timeout =
2302  receiver,
2303  receiver->timeout.abs_value_us);
2305  "# receivers active",
2307  GNUNET_NO);
2308  receiver->foreign_addr =
2309  sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
2310  setup_receiver_mq (receiver);
2311  if (NULL == timeout_task)
2313  return GNUNET_OK;
2314 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
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:246
struct sockaddr * address
Address of the other peer.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static char * sockaddr_to_udpaddr_string(const struct sockaddr *address, socklen_t address_len)
Converts address to the address string format used by this communicator in HELLOs.
uint64_t abs_value_us
The actual value.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
enum GNUNET_NetworkType nt
Which network type does this queue use?
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
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void setup_receiver_mq(struct ReceiverAddress *receiver)
Setup the MQ for the receiver.
Information we track per receiving address we have recently been in contact with (encryption to recei...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
socklen_t address_len
Length of the address.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
static char * address
GNS address for this phone.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_receiver_delete_it()

static int get_receiver_delete_it ( void *  cls,
const struct GNUNET_PeerIdentity target,
void *  value 
)
static

Iterator over all receivers to clean up.

Parameters
clsNULL
targetunused
valuethe queue to destroy
Returns
GNUNET_OK to continue to iterate

Definition at line 2326 of file gnunet-communicator-udp.c.

References GNUNET_OK, receiver_destroy(), and value.

Referenced by do_shutdown().

2329 {
2330  struct ReceiverAddress *receiver = value;
2331 
2332  (void) cls;
2333  (void) target;
2334  receiver_destroy (receiver);
2335  return GNUNET_OK;
2336 }
static char * value
Value of the record to add/remove.
Information we track per receiving address we have recently been in contact with (encryption to recei...
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_sender_delete_it()

static int get_sender_delete_it ( void *  cls,
const struct GNUNET_PeerIdentity target,
void *  value 
)
static

Iterator over all senders to clean up.

Parameters
clsNULL
targetunused
valuethe queue to destroy
Returns
GNUNET_OK to continue to iterate

Definition at line 2348 of file gnunet-communicator-udp.c.

References GNUNET_OK, UdpHandshakeSignature::sender, sender_destroy(), and value.

Referenced by do_shutdown().

2351 {
2352  struct SenderAddress *sender = value;
2353 
2354  (void) cls;
2355  (void) target;
2356  sender_destroy (sender);
2357  return GNUNET_OK;
2358 }
static char * value
Value of the record to add/remove.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
static void sender_destroy(struct SenderAddress *sender)
Functions with this signature are called whenever we need to close a sender&#39;s state due to timeout...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown the UNIX communicator.

Parameters
clsNULL (always)

Definition at line 2367 of file gnunet-communicator-udp.c.

References bi_destroy(), get_receiver_delete_it(), get_sender_delete_it(), GNUNET_break, GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_free, GNUNET_NAT_unregister(), GNUNET_NETWORK_socket_close(), GNUNET_NO, GNUNET_NT_scanner_done(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_application_done(), and GNUNET_TRANSPORT_communicator_disconnect().

Referenced by run().

2368 {
2369  if (NULL != nat)
2370  {
2372  nat = NULL;
2373  }
2374  while (NULL != bi_head)
2375  bi_destroy (bi_head);
2376  if (NULL != broadcast_task)
2377  {
2379  broadcast_task = NULL;
2380  }
2381  if (NULL != read_task)
2382  {
2384  read_task = NULL;
2385  }
2386  if (NULL != udp_sock)
2387  {
2389  udp_sock = NULL;
2390  }
2393  NULL);
2400  if (NULL != ch)
2401  {
2403  ch = NULL;
2404  }
2405  if (NULL != ah)
2406  {
2408  ah = NULL;
2409  }
2410  if (NULL != stats)
2411  {
2413  stats = NULL;
2414  }
2415  if (NULL != my_private_key)
2416  {
2418  my_private_key = NULL;
2419  }
2420  if (NULL != is)
2421  {
2423  is = NULL;
2424  }
2425 }
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
Our handle to report addresses for validation to TRANSPORT.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
static void bi_destroy(struct BroadcastInterface *bi)
An interface went away, stop broadcasting on it.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
static struct GNUNET_SCHEDULER_Task * broadcast_task
ID of master broadcast task.
static int get_sender_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all senders to clean up.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:433
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:692
static int get_receiver_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all receivers to clean up.
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enc_notify_cb()

static void enc_notify_cb ( void *  cls,
const struct GNUNET_PeerIdentity sender,
const struct GNUNET_MessageHeader msg 
)
static

Function called when the transport service has received a backchannel message for this communicator (!) via a different return path.

Should be an acknowledgement.

Parameters
clsclosure, NULL
senderwhich peer sent the notification
msgpayload

Definition at line 2438 of file gnunet-communicator-udp.c.

References GNUNET_break_op, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s_full(), GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK, handle_ack(), GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by run().

2441 {
2442  const struct UDPAck *ack;
2443 
2444  (void) cls;
2446  "Storing UDPAck received from backchannel from %s\n",
2447  GNUNET_i2s_full (sender));
2448  if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
2449  (ntohs (msg->size) != sizeof(struct UDPAck)))
2450  {
2451  GNUNET_break_op (0);
2452  return;
2453  }
2454  ack = (const struct UDPAck *) msg;
2456  sender,
2457  &handle_ack,
2458  (void *) ack);
2459 }
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static int handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
We received an ACK for pid.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_log(kind,...)
UDP key acknowledgement.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nat_address_cb()

static void nat_address_cb ( void *  cls,
void **  app_ctx,
int  add_remove,
enum GNUNET_NAT_AddressClass  ac,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.

Parameters
clsclosure
app_ctx[in,out]location where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to add a new public IP address, GNUNET_NO to remove a previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual length of the addr

Definition at line 2476 of file gnunet-communicator-udp.c.

References ai, COMMUNICATOR_ADDRESS_PREFIX, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_free, GNUNET_NT_scanner_get_type(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_address_add(), GNUNET_TRANSPORT_communicator_address_remove(), GNUNET_YES, and nt.

Referenced by run().

2482 {
2483  char *my_addr;
2485 
2486  if (GNUNET_YES == add_remove)
2487  {
2488  enum GNUNET_NetworkType nt;
2489 
2490  GNUNET_asprintf (&my_addr,
2491  "%s-%s",
2493  GNUNET_a2s (addr, addrlen));
2494  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2495  ai =
2497  my_addr,
2498  nt,
2500  GNUNET_free (my_addr);
2501  *app_ctx = ai;
2502  }
2503  else
2504  {
2505  ai = *app_ctx;
2507  *app_ctx = NULL;
2508  }
2509 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer...
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer...
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
Internal representation of an address a communicator is currently providing for the transport service...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ifc_broadcast()

static void ifc_broadcast ( void *  cls)
static

Broadcast our presence on one of our interfaces.

Parameters
clsa struct BroadcastInterface

Definition at line 2518 of file gnunet-communicator-udp.c.

References BroadcastInterface::ba, BroadcastInterface::bcm, BROADCAST_FREQUENCY, BroadcastInterface::broadcast_task, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NETWORK_socket_sendto(), GNUNET_NETWORK_socket_setsockopt(), GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), INTERFACE_SCAN_FREQUENCY, BroadcastInterface::mcreq, my_port, BroadcastInterface::sa, and BroadcastInterface::salen.

Referenced by iface_proc().

2519 {
2520  struct BroadcastInterface *bi = cls;
2521  struct GNUNET_TIME_Relative delay;
2522 
2524  delay.rel_value_us =
2526  bi->broadcast_task =
2528 
2529  switch (bi->sa->sa_family)
2530  {
2531  case AF_INET: {
2532  static int yes = 1;
2533  static int no = 0;
2534  ssize_t sent;
2535 
2537  SOL_SOCKET,
2538  SO_BROADCAST,
2539  &yes,
2540  sizeof(int)))
2543  &bi->bcm,
2544  sizeof(bi->bcm),
2545  bi->ba,
2546  bi->salen);
2547  if (-1 == sent)
2550  SOL_SOCKET,
2551  SO_BROADCAST,
2552  &no,
2553  sizeof(int)))
2555  break;
2556  }
2557 
2558  case AF_INET6: {
2559  ssize_t sent;
2560  struct sockaddr_in6 dst;
2561 
2562  dst.sin6_family = AF_INET6;
2563  dst.sin6_port = htons (my_port);
2564  dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
2565  dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
2566 
2568  &bi->bcm,
2569  sizeof(bi->bcm),
2570  (const struct sockaddr *) &dst,
2571  sizeof(dst));
2572  if (-1 == sent)
2574  break;
2575  }
2576 
2577  default:
2578  GNUNET_break (0);
2579  break;
2580  }
2581 }
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:883
#define BROADCAST_FREQUENCY
How often do we broadcast our presence on the LAN?
static uint16_t my_port
Port number to which we are actually bound.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct sockaddr * ba
Broadcast address to use on the interface.
static void ifc_broadcast(void *cls)
Broadcast our presence on one of our interfaces.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:850
struct sockaddr * sa
Sender&#39;s address of the interface.
socklen_t salen
Number of bytes in sa.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct UDPBroadcast bcm
Message we broadcast on this interface.
struct ipv6_mreq mcreq
If this is an IPv6 interface, this is the request we use to join/leave the group. ...
#define INTERFACE_SCAN_FREQUENCY
How often do we scan for changes to our network interfaces?
struct GNUNET_SCHEDULER_Task * broadcast_task
Task for this broadcast interface.
Interface we broadcast our presence on.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iface_proc()

static int iface_proc ( void *  cls,
const char *  name,
int  isDefault,
const struct sockaddr *  addr,
const struct sockaddr *  broadcast_addr,
const struct sockaddr *  netmask,
socklen_t  addrlen 
)
static

Callback function invoked for each interface found.

Activates/deactivates broadcast interfaces.

Parameters
clsNULL
namename of the interface (can be NULL for unknown)
isDefaultis this presumably the default interface
addraddress of this interface (can be NULL for unknown or unassigned)
broadcast_addrthe broadcast address (can be NULL for unknown or unassigned)
netmaskthe network mask (can be NULL for unknown or unassigned)
addrlenlength of the address
Returns
GNUNET_OK to continue iteration, GNUNET_SYSERR to abort

Definition at line 2599 of file gnunet-communicator-udp.c.

References BroadcastInterface::ba, BroadcastInterface::bcm, BroadcastInterface::broadcast_task, BroadcastInterface::found, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_memdup, GNUNET_NETWORK_socket_setsockopt(), GNUNET_new, GNUNET_NT_LOOPBACK, GNUNET_NT_scanner_get_type(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, GNUNET_YES, UdpBroadcastSignature::h_address, have_v6_socket, ifc_broadcast(), BroadcastInterface::mcreq, my_identity, BroadcastInterface::next, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpBroadcastSignature::purpose, BroadcastInterface::sa, BroadcastInterface::salen, UDPBroadcast::sender, UdpBroadcastSignature::sender, UDPBroadcast::sender_sig, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by do_broadcast().

2606 {
2607  struct BroadcastInterface *bi;
2608  enum GNUNET_NetworkType network;
2609  struct UdpBroadcastSignature ubs;
2610 
2611  (void) cls;
2612  (void) netmask;
2613  if (NULL == addr)
2614  return GNUNET_YES; /* need to know our address! */
2615  network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2616  if (GNUNET_NT_LOOPBACK == network)
2617  {
2618  /* Broadcasting on loopback does not make sense */
2619  return GNUNET_YES;
2620  }
2621  for (bi = bi_head; NULL != bi; bi = bi->next)
2622  {
2623  if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
2624  {
2625  bi->found = GNUNET_YES;
2626  return GNUNET_OK;
2627  }
2628  }
2629 
2630  if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
2631  return GNUNET_OK; /* broadcast_addr is required for IPv6! */
2632  if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket))
2633  return GNUNET_OK; /* not using IPv6 */
2634 
2635  bi = GNUNET_new (struct BroadcastInterface);
2636  bi->sa = GNUNET_memdup (addr, addrlen);
2637  if (NULL != broadcast_addr)
2638  bi->ba = GNUNET_memdup (broadcast_addr, addrlen);
2639  bi->salen = addrlen;
2640  bi->found = GNUNET_YES;
2641  bi->bcm.sender = my_identity;
2642  ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
2643  ubs.purpose.size = htonl (sizeof(ubs));
2644  ubs.sender = my_identity;
2645  GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
2647  &ubs,
2648  &bi->bcm.sender_sig);
2649  if (NULL != broadcast_addr)
2650  {
2653  }
2654  if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
2655  {
2656  /* Create IPv6 multicast request */
2657  const struct sockaddr_in6 *s6 =
2658  (const struct sockaddr_in6 *) broadcast_addr;
2659 
2660  GNUNET_assert (
2661  1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
2662 
2663  /* http://tools.ietf.org/html/rfc2553#section-5.2:
2664  *
2665  * IPV6_JOIN_GROUP
2666  *
2667  * Join a multicast group on a specified local interface. If the
2668  * interface index is specified as 0, the kernel chooses the local
2669  * interface. For example, some kernels look up the multicast
2670  * group in the normal IPv6 routing table and using the resulting
2671  * interface; we do this for each interface, so no need to use
2672  * zero (anymore...).
2673  */bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
2674 
2675  /* Join the multicast group */
2677  IPPROTO_IPV6,
2678  IPV6_JOIN_GROUP,
2679  &bi->mcreq,
2680  sizeof(bi->mcreq)))
2681  {
2683  }
2684  }
2685  return GNUNET_OK;
2686 }
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:883
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
static struct BroadcastInterface * bi_tail
Broadcast interface tasks.
int found
Was this interface found in the last iface_proc() scan?
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
struct GNUNET_PeerIdentity sender
Sender&#39;s peer identity.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int have_v6_socket
GNUNET_YES if udp_sock supports IPv6.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
struct sockaddr * ba
Broadcast address to use on the interface.
static void ifc_broadcast(void *cls)
Broadcast our presence on one of our interfaces.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
Signature used by UDP broadcasts.
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
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
struct sockaddr * sa
Sender&#39;s address of the interface.
socklen_t salen
Number of bytes in sa.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
Loopback (same host).
Definition: gnunet_nt_lib.h:45
struct UDPBroadcast bcm
Message we broadcast on this interface.
struct ipv6_mreq mcreq
If this is an IPv6 interface, this is the request we use to join/leave the group. ...
Signature we use to verify that the broadcast was really made by the peer that claims to have made it...
struct GNUNET_SCHEDULER_Task * broadcast_task
Task for this broadcast interface.
Interface we broadcast our presence on.
struct BroadcastInterface * next
Kept in a DLL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_broadcast()

static void do_broadcast ( void *  cls)
static

Scan interfaces to broadcast our presence on the LAN.

Parameters
clsNULL, unused

Definition at line 2695 of file gnunet-communicator-udp.c.

References bi_destroy(), BroadcastInterface::found, GNUNET_NO, GNUNET_OS_network_interfaces_list(), GNUNET_SCHEDULER_add_delayed(), iface_proc(), INTERFACE_SCAN_FREQUENCY, and BroadcastInterface::next.

Referenced by run().

2696 {
2697  struct BroadcastInterface *bin;
2698 
2699  (void) cls;
2700  for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
2701  bi->found = GNUNET_NO;
2703  for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
2704  {
2705  bin = bi->next;
2706  if (GNUNET_NO == bi->found)
2707  bi_destroy (bi);
2708  }
2710  &do_broadcast,
2711  NULL);
2712 }
int found
Was this interface found in the last iface_proc() scan?
static void do_broadcast(void *cls)
Scan interfaces to broadcast our presence on the LAN.
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:396
static int iface_proc(void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
Callback function invoked for each interface found.
static void bi_destroy(struct BroadcastInterface *bi)
An interface went away, stop broadcasting on it.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
static struct GNUNET_SCHEDULER_Task * broadcast_task
ID of master broadcast task.
#define INTERFACE_SCAN_FREQUENCY
How often do we scan for changes to our network interfaces?
Interface we broadcast our presence on.
struct BroadcastInterface * next
Kept in a DLL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Setup communicator and launch network interactions.

Parameters
clsNULL (always)
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 2724 of file gnunet-communicator-udp.c.

References _, COMMUNICATOR_ADDRESS_PREFIX, COMMUNICATOR_CONFIG_SECTION, do_broadcast(), do_shutdown(), enc_notify_cb(), GNUNET_a2s(), GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror, GNUNET_log_strerror_file, GNUNET_NAT_register(), GNUNET_NETWORK_get_fd(), GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NT_scanner_init(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_CC_UNRELIABLE, GNUNET_TRANSPORT_communicator_connect(), GNUNET_YES, have_v6_socket, mq_init(), my_identity, my_port, nat_address_cb(), GNUNET_PeerIdentity::public_key, sock_read(), and udp_address_to_sockaddr().

Referenced by main().

2728 {
2729  char *bindto;
2730  struct sockaddr *in;
2731  socklen_t in_len;
2732  struct sockaddr_storage in_sto;
2733  socklen_t sto_len;
2734 
2735  (void) cls;
2736  cfg = c;
2737  if (GNUNET_OK !=
2740  "BINDTO",
2741  &bindto))
2742  {
2745  "BINDTO");
2746  return;
2747  }
2748 
2749  in = udp_address_to_sockaddr (bindto, &in_len);
2750  if (NULL == in)
2751  {
2753  "Failed to setup UDP socket address with path `%s'\n",
2754  bindto);
2755  GNUNET_free (bindto);
2756  return;
2757  }
2758  udp_sock =
2759  GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP);
2760  if (NULL == udp_sock)
2761  {
2763  GNUNET_free (in);
2764  GNUNET_free (bindto);
2765  return;
2766  }
2767  if (AF_INET6 == in->sa_family)
2769  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len))
2770  {
2773  udp_sock = NULL;
2774  GNUNET_free (in);
2775  GNUNET_free (bindto);
2776  return;
2777  }
2778 
2779  /* We might have bound to port 0, allowing the OS to figure it out;
2780  thus, get the real IN-address from the socket */
2781  sto_len = sizeof(in_sto);
2782  if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock),
2783  (struct sockaddr *) &in_sto,
2784  &sto_len))
2785  {
2786  memcpy (&in_sto, in, in_len);
2787  sto_len = in_len;
2788  }
2789  GNUNET_free (in);
2790  GNUNET_free (bindto);
2791  in = (struct sockaddr *) &in_sto;
2792  in_len = sto_len;
2794  "Bound to `%s'\n",
2795  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
2796  switch (in->sa_family)
2797  {
2798  case AF_INET:
2799  my_port = ntohs (((struct sockaddr_in *) in)->sin_port);
2800  break;
2801 
2802  case AF_INET6:
2803  my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port);
2804  break;
2805 
2806  default:
2807  GNUNET_break (0);
2808  my_port = 0;
2809  }
2810  stats = GNUNET_STATISTICS_create ("C-UDP", cfg);
2814  receivers_heap =
2820  if (NULL == my_private_key)
2821  {
2822  GNUNET_log (
2824  _ (
2825  "Transport service is lacking key configuration settings. Exiting.\n"));
2827  return;
2828  }
2830  /* start reading */
2832  udp_sock,
2833  &sock_read,
2834  NULL);
2839  &mq_init,
2840  NULL,
2841  &enc_notify_cb,
2842  NULL);
2843  if (NULL == ch)
2844  {
2845  GNUNET_break (0);
2847  return;
2848  }
2850  if (NULL == ah)
2851  {
2852  GNUNET_break (0);
2854  return;
2855  }
2856  /* start broadcasting */
2857  if (GNUNET_YES !=
2860  "DISABLE_BROADCAST"))
2861  {
2863  }
2866  IPPROTO_UDP,
2867  1 /* one address */,
2868  (const struct sockaddr **) &in,
2869  &in_len,
2870  &nat_address_cb,
2871  NULL /* FIXME: support reversal: #5529 */,
2872  NULL /* closure */);
2873 }
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1080
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static void do_broadcast(void *cls)
Scan interfaces to broadcast our presence on the LAN.
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
Our handle to report addresses for validation to TRANSPORT.
static uint16_t my_port
Port number to which we are actually bound.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static struct GNUNET_PeerIdentity my_identity
Our public key.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
int GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:485
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static int have_v6_socket
GNUNET_YES if udp_sock supports IPv6.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received a backchannel message for this communicator (...
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
static struct GNUNET_SCHEDULER_Task * broadcast_task
ID of master broadcast task.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
Heap with the minimum cost at the root.
static void sock_read(void *cls)
Socket read task.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static int mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
Function called by the transport service to initialize a message queue given address information abou...
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition: nat_api.c:378
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:412
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:193
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
static void nat_address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer&#39;s key from the file specified in the configuration...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for the UNIX communicator.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 2884 of file gnunet-communicator-udp.c.

References _, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, and run().

2885 {
2886  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2888  };
2889  int ret;
2890 
2891  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2892  return 2;
2893 
2894  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
2895  argv,
2896  "gnunet-communicator-udp",
2897  _ ("GNUnet UDP communicator"),
2898  options,
2899  &run,
2900  NULL))
2901  ? 0
2902  : 1;
2903  GNUNET_free_nz ((void *) argv);
2904  return ret;
2905 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1457
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
#define GNUNET_free_nz(ptr)
Wrapper around free.
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:367
Here is the call graph for this function:

Variable Documentation

◆ key_cache

struct GNUNET_CONTAINER_MultiShortmap* key_cache
static

Cache of pre-generated key IDs.

Definition at line 660 of file gnunet-communicator-udp.c.

◆ read_task

struct GNUNET_SCHEDULER_Task* read_task
static

ID of read task.

Definition at line 665 of file gnunet-communicator-udp.c.

◆ timeout_task

struct GNUNET_SCHEDULER_Task* timeout_task
static

ID of timeout task.

Definition at line 670 of file gnunet-communicator-udp.c.

◆ broadcast_task

struct GNUNET_SCHEDULER_Task* broadcast_task
static

ID of master broadcast task.

Definition at line 675 of file gnunet-communicator-udp.c.

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

For logging statistics.

Definition at line 680 of file gnunet-communicator-udp.c.

◆ ch

Our environment.

Definition at line 685 of file gnunet-communicator-udp.c.

◆ receivers

struct GNUNET_CONTAINER_MultiPeerMap* receivers
static

Receivers (map from peer identity to struct ReceiverAddress)

Definition at line 690 of file gnunet-communicator-udp.c.

◆ senders

struct GNUNET_CONTAINER_MultiPeerMap* senders
static

Senders (map from peer identity to struct SenderAddress)

Definition at line 695 of file gnunet-communicator-udp.c.

◆ senders_heap

struct GNUNET_CONTAINER_Heap* senders_heap
static

Expiration heap for senders (contains struct SenderAddress)

Definition at line 700 of file gnunet-communicator-udp.c.

◆ receivers_heap

struct GNUNET_CONTAINER_Heap* receivers_heap
static

Expiration heap for receivers (contains struct ReceiverAddress)

Definition at line 705 of file gnunet-communicator-udp.c.

◆ bi_head

struct BroadcastInterface* bi_head
static

Broadcast interface tasks.

Kept in a DLL.

Definition at line 710 of file gnunet-communicator-udp.c.

◆ bi_tail

struct BroadcastInterface* bi_tail
static

Broadcast interface tasks.

Kept in a DLL.

Definition at line 715 of file gnunet-communicator-udp.c.

◆ udp_sock

struct GNUNET_NETWORK_Handle* udp_sock
static

Our socket.

Definition at line 720 of file gnunet-communicator-udp.c.

◆ have_v6_socket

int have_v6_socket
static

GNUNET_YES if udp_sock supports IPv6.

Definition at line 725 of file gnunet-communicator-udp.c.

Referenced by iface_proc(), and run().

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

Our public key.

Definition at line 730 of file gnunet-communicator-udp.c.

Referenced by iface_proc(), mq_send_kx(), run(), and verify_confirmation().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey* my_private_key
static

Our private key.

Definition at line 735 of file gnunet-communicator-udp.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 740 of file gnunet-communicator-udp.c.

◆ ah

Our handle to report addresses for validation to TRANSPORT.

Definition at line 745 of file gnunet-communicator-udp.c.

◆ is

struct GNUNET_NT_InterfaceScanner* is
static

Network scanner to determine network types.

Definition at line 750 of file gnunet-communicator-udp.c.

◆ nat

struct GNUNET_NAT_Handle* nat
static

Connection to NAT service.

Definition at line 755 of file gnunet-communicator-udp.c.

◆ my_port

uint16_t my_port
static

Port number to which we are actually bound.

Definition at line 760 of file gnunet-communicator-udp.c.

Referenced by ifc_broadcast(), and run().