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

Transport plugin using TCP. 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_ats_transport_service.h"
#include "transport.h"
#include "gnunet_transport_communication_service.h"
#include "gnunet_resolver_service.h"
Include dependency graph for gnunet-communicator-tcp.c:

Go to the source code of this file.

Data Structures

struct  TcpHandshakeSignature
 Signature we use to verify that the ephemeral key was really chosen by the specified sender. More...
 
struct  TCPConfirmation
 Encrypted continuation of TCP initial handshake. More...
 
struct  TCPBox
 TCP message box. More...
 
struct  TCPRekey
 TCP rekey message box. More...
 
struct  TCPFinish
 TCP finish. More...
 
struct  ListenTask
 Struct to use as closure. More...
 
struct  Queue
 Handle for a queue. More...
 
struct  ProtoQueue
 Handle for an incoming connection where we do not yet have enough information to setup a full queue. More...
 
struct  PortOnlyIpv4Ipv6
 In case of port only configuration we like to bind to ipv4 and ipv6 addresses. More...
 
struct  Addresses
 DLL to store the addresses we like to register at NAT service. More...
 

Macros

#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
 How long do we believe our addresses to remain up (before the other peer should revalidate). More...
 
#define DEFAULT_MAX_QUEUE_LENGTH   8
 How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file). More...
 
#define BUF_SIZE   (2 * 64 * 1024 + sizeof(struct TCPBox))
 Size of our IO buffers for ciphertext data. More...
 
#define DEFAULT_REKEY_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 REKEY_MAX_BYTES   (1024LLU * 1024 * 1024 * 4LLU)
 How often do we rekey based on number of bytes transmitted? (additionally randomized). More...
 
#define INITIAL_KX_SIZE
 Size of the initial key exchange message sent first in both directions. More...
 
#define COMMUNICATOR_ADDRESS_PREFIX   "tcp"
 Address prefix used by the communicator. More...
 
#define COMMUNICATOR_CONFIG_SECTION   "communicator-tcp"
 Configuration section used by the communicator. More...
 

Functions

static void listen_cb (void *cls)
 We have been notified that our listen socket has something to read. More...
 
static void queue_destroy (struct Queue *queue)
 Functions with this signature are called whenever we need to close a queue due to a disconnect or failure to establish a connection. More...
 
static void calculate_hmac (struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
 Compute mac over buf, and ratched the hmac_secret. More...
 
static void queue_finish (struct Queue *queue)
 Append a 'finish' message to the outgoing transmission. More...
 
static void reschedule_queue_timeout (struct Queue *queue)
 Increment queue timeout due to activity. More...
 
static void queue_read (void *cls)
 Queue read task. More...
 
static void core_read_finished_cb (void *cls, int success)
 Core tells us it is done processing a message that transport received on a queue with status success. More...
 
static void pass_plaintext_to_core (struct Queue *queue, const void *plaintext, size_t plaintext_len)
 We received plaintext_len bytes of plaintext on queue. More...
 
static void setup_cipher (const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
 Setup cipher based on shared secret dh and decrypting peer pid. More...
 
static void setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
 Setup cipher of queue for decryption. More...
 
static void do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
 Handle rekey message on queue. More...
 
static size_t try_handle_plaintext (struct Queue *queue)
 Test if we have received a full message in plaintext. More...
 
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
 Convert a struct sockaddr_in6 to astruct sockaddr *`. More...
 
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
 Convert a struct sockaddr_in4 to astruct sockaddr *`. More...
 
static struct PortOnlyIpv4Ipv6tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
 Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 * More...
 
static char * extract_address (const char *bindto)
 This Method extracts the address part of the BINDTO string. More...
 
static unsigned int extract_port (const char *addr_and_port)
 This Method extracts the port part of the BINDTO string. More...
 
static struct sockaddr * tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
 Convert TCP bind specification to a struct sockaddr * More...
 
static void setup_out_cipher (struct Queue *queue)
 Setup cipher for outgoing data stream based on target and our ephemeral private key. More...
 
static void inject_rekey (struct Queue *queue)
 Inject a struct TCPRekey message into the queue's plaintext buffer. More...
 
static void queue_write (void *cls)
 We have been notified that our socket is ready to write. More...
 
static void mq_send (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 (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 void boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
 Add the given queue to our internal data structure. More...
 
static void transmit_kx (struct Queue *queue, const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
 Generate and transmit our ephemeral key and the signature for the initial KX with the other peer. More...
 
static void start_initial_kx_out (struct Queue *queue)
 Initialize our key material for outgoing transmissions and inform the other peer about it. More...
 
static int decrypt_and_check_tc (struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
 We have received the first bytes from the other side on a queue. More...
 
static void free_proto_queue (struct ProtoQueue *pq)
 Closes socket and frees memory associated with pq. More...
 
static void proto_read_kx (void *cls)
 Read from the socket of the proto queue until we have enough data to upgrade to full queue. More...
 
static void queue_read_kx (void *cls)
 Read from the socket of the queue until we have enough data to initialize the decryption logic and can switch to regular reading. 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_queue_delete_it (void *cls, const struct GNUNET_PeerIdentity *target, void *value)
 Iterator over all message queues 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 an acknowledgement 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 int init_socket (const struct sockaddr *addr, socklen_t in_len)
 This method launch network interactions for each address we like to bind to. More...
 
static void nat_register ()
 This method reads from the DLL addrs_head to register them at the NAT service. More...
 
static void add_addr (struct sockaddr *in, socklen_t in_len)
 This method adds addresses to the DLL, that are later register at the NAT service. More...
 
static void init_socket_resolv (void *cls, const struct sockaddr *addr, socklen_t in_len)
 This method is the callback called by the resolver API, and wraps method init_socket. 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 unsigned long long max_queue_length
 Maximum queue length before we stop reading towards the transport service. More...
 
static struct GNUNET_STATISTICS_Handlestats
 For logging statistics. More...
 
static struct GNUNET_TRANSPORT_CommunicatorHandlech
 Our environment. More...
 
static struct GNUNET_CONTAINER_MultiPeerMapqueue_map
 Queues (map from peer identity to struct Queue) More...
 
static struct GNUNET_PeerIdentity my_identity
 Our public key. More...
 
static struct GNUNET_TIME_Relative rekey_interval
 The rekey interval. More...
 
static struct GNUNET_CRYPTO_EddsaPrivateKeymy_private_key
 Our private key. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_NT_InterfaceScanneris
 Network scanner to determine network types. More...
 
static struct GNUNET_NAT_Handlenat
 Connection to NAT service. More...
 
static struct ProtoQueueproto_head
 Protoqueues DLL head. More...
 
static struct ProtoQueueproto_tail
 Protoqueues DLL tail. More...
 
struct GNUNET_RESOLVER_RequestHandleresolve_request_handle
 Handle for DNS lookup of bindto address. More...
 
struct Addressesaddrs_head
 Head of DLL with addresses we like to register at NAT servcie. More...
 
struct Addressesaddrs_tail
 Head of DLL with addresses we like to register at NAT servcie. More...
 
int addrs_lens
 Number of addresses in the DLL for register at NAT service. More...
 

Detailed Description

Transport plugin using TCP.

Author
Christian Grothoff

TODO:

Definition in file gnunet-communicator-tcp.c.

Macro Definition Documentation

◆ ADDRESS_VALIDITY_PERIOD

#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)

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

Definition at line 51 of file gnunet-communicator-tcp.c.

Referenced by pass_plaintext_to_core().

◆ DEFAULT_MAX_QUEUE_LENGTH

#define DEFAULT_MAX_QUEUE_LENGTH   8

How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file).

Should be below the level of the communicator API, as otherwise we may read messages just to have them dropped by the communicator API.

Definition at line 62 of file gnunet-communicator-tcp.c.

Referenced by run().

◆ BUF_SIZE

#define BUF_SIZE   (2 * 64 * 1024 + sizeof(struct TCPBox))

Size of our IO buffers for ciphertext data.

Must be at least UINT_MAX + sizeof (struct TCPBox).

Definition at line 68 of file gnunet-communicator-tcp.c.

Referenced by queue_read(), queue_read_kx(), and queue_write().

◆ DEFAULT_REKEY_INTERVAL

#define DEFAULT_REKEY_INTERVAL   GNUNET_TIME_UNIT_DAYS

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

Definition at line 73 of file gnunet-communicator-tcp.c.

Referenced by run().

◆ 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 78 of file gnunet-communicator-tcp.c.

Referenced by listen_cb().

◆ 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 84 of file gnunet-communicator-tcp.c.

Referenced by setup_out_cipher().

◆ INITIAL_KX_SIZE

#define INITIAL_KX_SIZE
Value:
+ sizeof(struct TCPConfirmation))
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...

Size of the initial key exchange message sent first in both directions.

Definition at line 90 of file gnunet-communicator-tcp.c.

Referenced by queue_read_kx().

◆ COMMUNICATOR_ADDRESS_PREFIX

#define COMMUNICATOR_ADDRESS_PREFIX   "tcp"

Address prefix used by the communicator.

Definition at line 98 of file gnunet-communicator-tcp.c.

Referenced by boot_queue(), init_socket(), mq_init(), and nat_address_cb().

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-tcp"

Configuration section used by the communicator.

Definition at line 103 of file gnunet-communicator-tcp.c.

Referenced by init_socket(), nat_register(), run(), and tcp_address_to_sockaddr_port_only().

Function Documentation

◆ listen_cb()

static void listen_cb ( void *  cls)
static

We have been notified that our listen socket has something to read.

Do the read and reschedule this function to be called again once more is available.

Parameters
clsNULL

Do the read and reschedule this function to be called again once more is available.

Parameters
clsListenTask with listening socket and task

Definition at line 2021 of file gnunet-communicator-tcp.c.

References ProtoQueue::address, ProtoQueue::address_len, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_memdup, GNUNET_NETWORK_socket_accept(), GNUNET_new, GNUNET_SCHEDULER_add_read_net(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, ListenTask::listen_sock, ListenTask::listen_task, PROTO_QUEUE_TIMEOUT, proto_read_kx(), ProtoQueue::read_task, ProtoQueue::sock, and ProtoQueue::timeout.

Referenced by GNUNET_SET_listen(), init_socket(), and queue_destroy().

2022 {
2023  struct sockaddr_storage in;
2024  socklen_t addrlen;
2025  struct GNUNET_NETWORK_Handle *sock;
2026  struct ProtoQueue *pq;
2027  struct ListenTask *lt;
2028 
2029  lt = cls;
2030 
2031  lt->listen_task = NULL;
2032  GNUNET_assert (NULL != lt->listen_sock);
2033  addrlen = sizeof(in);
2034  memset (&in, 0, sizeof(in));
2036  (struct sockaddr*) &in,
2037  &addrlen);
2038  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2039  return; /* system limit reached, wait until connection goes down */
2041  lt->listen_sock,
2042  &listen_cb,
2043  lt);
2044  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2045  return;
2046  if (NULL == sock)
2047  {
2049  return;
2050  }
2051  pq = GNUNET_new (struct ProtoQueue);
2052  pq->address_len = addrlen;
2053  pq->address = GNUNET_memdup (&in, addrlen);
2055  pq->sock = sock;
2057  pq->sock,
2058  &proto_read_kx,
2059  pq);
2061 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue...
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
#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_SCHEDULER_Task * listen_task
ID of listen task.
Handle for an incoming connection where we do not yet have enough information to setup a full queue...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:430
#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...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct sockaddr * address
Address of the other peer.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
handle to a socket
Definition: network.c:52
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 ProtoQueue * proto_head
Protoqueues DLL head.
Struct to use as closure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_destroy()

static void queue_destroy ( struct Queue queue)
static

Functions with this signature are called whenever we need to close a queue due to a disconnect or failure to establish a connection.

Parameters
queuequeue to close down

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

References Queue::address, Queue::backpressure, Queue::destroyed, GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_destroy(), GNUNET_NETWORK_socket_close(), GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_mq_del(), GNUNET_YES, Queue::in_cipher, listen_cb(), ListenTask::listen_sock, Queue::listen_sock, ListenTask::listen_task, Queue::listen_task, mq, Queue::mq, Queue::out_cipher, Queue::qh, Queue::read_task, Queue::sock, Queue::target, and Queue::write_task.

Referenced by get_queue_delete_it(), queue_read_kx(), queue_write(), and try_handle_plaintext().

681 {
682  struct GNUNET_MQ_Handle *mq;
683  struct ListenTask *lt;
684  lt = GNUNET_new (struct ListenTask);
685  lt->listen_sock = queue->listen_sock;
686  lt->listen_task = queue->listen_task;
687 
689  "Disconnecting queue for peer `%s'\n",
690  GNUNET_i2s (&queue->target));
691  if (NULL != (mq = queue->mq))
692  {
693  queue->mq = NULL;
694  GNUNET_MQ_destroy (mq);
695  }
696  if (NULL != queue->qh)
697  {
699  queue->qh = NULL;
700  }
701  GNUNET_assert (
702  GNUNET_YES ==
705  "# queues active",
707  GNUNET_NO);
708  if (NULL != queue->read_task)
709  {
711  queue->read_task = NULL;
712  }
713  if (NULL != queue->write_task)
714  {
716  queue->write_task = NULL;
717  }
719  gcry_cipher_close (queue->in_cipher);
720  gcry_cipher_close (queue->out_cipher);
721  GNUNET_free (queue->address);
722  if (0 != queue->backpressure)
723  queue->destroyed = GNUNET_YES;
724  else
725  GNUNET_free (queue);
726 
727  if (NULL == lt->listen_task)
730  lt->listen_sock,
731  &listen_cb,
732  lt);
733 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
#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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
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.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
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 sockaddr * address
Address of the other peer.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:833
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
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
Struct to use as closure.
#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:

◆ calculate_hmac()

static void calculate_hmac ( struct GNUNET_HashCode hmac_secret,
const void *  buf,
size_t  buf_size,
struct GNUNET_ShortHashCode smac 
)
static

Compute mac over buf, and ratched the hmac_secret.

Parameters
[in,out]hmac_secretsecret for HMAC calculation
bufbuffer to MAC
buf_sizenumber of bytes in buf
smac[out]where to write the HMAC

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

References GNUNET_CRYPTO_hash(), and GNUNET_CRYPTO_hmac_raw().

Referenced by inject_rekey(), mq_send(), queue_finish(), and try_handle_plaintext().

749 {
750  struct GNUNET_HashCode mac;
751 
752  GNUNET_CRYPTO_hmac_raw (hmac_secret,
753  sizeof(struct GNUNET_HashCode),
754  buf,
755  buf_size,
756  &mac);
757  /* truncate to `struct GNUNET_ShortHashCode` */
758  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
759  /* ratchet hmac key */
760  GNUNET_CRYPTO_hash (hmac_secret,
761  sizeof(struct GNUNET_HashCode),
762  hmac_secret);
763 }
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn' this be the standard hmac function and the abov...
Definition: crypto_hash.c:420
A 256-bit hashcode.
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
static char buf[2048]
A 512-bit hashcode.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_finish()

static void queue_finish ( struct Queue queue)
static

Append a 'finish' message to the outgoing transmission.

Once the finish has been transmitted, destroy the queue.

Parameters
queuequeue to shut down nicely

Definition at line 773 of file gnunet-communicator-tcp.c.

References calculate_hmac(), Queue::finishing, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH, GNUNET_YES, TCPFinish::header, TCPFinish::hmac, Queue::out_hmac, Queue::pwrite_buf, Queue::pwrite_off, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by do_rekey(), mq_destroy(), mq_error(), queue_read(), and try_handle_plaintext().

774 {
775  struct TCPFinish fin;
776 
777  memset (&fin, 0, sizeof(fin));
778  fin.header.size = htons (sizeof(fin));
779  fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
780  calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
781  /* if there is any message left in pwrite_buf, we
782  overwrite it (possibly dropping the last message
783  from CORE hard here) */
784  memcpy (queue->pwrite_buf, &fin, sizeof(fin));
785  queue->pwrite_off = sizeof(fin);
786  /* This flag will ensure that #queue_write() no longer
787  notifies CORE about the possibility of sending
788  more data, and that #queue_write() will call
789  #queue_destroy() once the @c fin was fully written. */
790  queue->finishing = GNUNET_YES;
791 }
int finishing
Did we enqueue a finish message and are closing down the queue?
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_queue_timeout()

static void reschedule_queue_timeout ( struct Queue queue)
static

Increment queue timeout due to activity.

We do not immediately notify the monitor here as that might generate excessive signalling.

Parameters
queuequeue for which the timeout should be rescheduled

Definition at line 802 of file gnunet-communicator-tcp.c.

References GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_TIME_relative_to_absolute(), queue_read(), and Queue::timeout.

Referenced by core_read_finished_cb(), queue_read(), queue_read_kx(), and queue_write().

803 {
804  queue->timeout =
806 }
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
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer...
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read()

static void queue_read ( void *  cls)
static

Queue read task.

If we hit the timeout, disconnect it

Parameters
clsthe struct Queue * to disconnect

Definition at line 1105 of file gnunet-communicator-tcp.c.

References Queue::backpressure, BUF_SIZE, Queue::cread_buf, Queue::cread_off, done(), GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_log_strerror, GNUNET_MIN, GNUNET_NETWORK_socket_recv(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, Queue::in_cipher, max_queue_length, Queue::pread_buf, Queue::pread_off, queue(), queue_finish(), Queue::read_task, Queue::rekeyed, GNUNET_TIME_Relative::rel_value_us, reschedule_queue_timeout(), Queue::sock, Queue::timeout, and try_handle_plaintext().

Referenced by core_read_finished_cb(), proto_read_kx(), queue_read_kx(), and reschedule_queue_timeout().

1106 {
1107  struct Queue *queue = cls;
1108  struct GNUNET_TIME_Relative left;
1109  ssize_t rcvd;
1110 
1111  queue->read_task = NULL;
1112  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1113  &queue->cread_buf[queue->cread_off],
1114  BUF_SIZE - queue->cread_off);
1116  "Received %lu bytes from TCP queue\n", rcvd);
1117  if (-1 == rcvd)
1118  {
1119  if ((EAGAIN != errno) && (EINTR != errno))
1120  {
1122  queue_finish (queue);
1123  return;
1124  }
1125  /* try again */
1127  queue->read_task =
1128  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1129  return;
1130  }
1131  if (0 != rcvd)
1132  reschedule_queue_timeout (queue);
1133  queue->cread_off += rcvd;
1134  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1135  (queue->cread_off > 0))
1136  {
1137  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1138  queue->cread_off);
1139  size_t done;
1140  size_t total;
1141  size_t old_pread_off = queue->pread_off;
1142 
1143  GNUNET_assert (0 ==
1144  gcry_cipher_decrypt (queue->in_cipher,
1145  &queue->pread_buf[queue->pread_off],
1146  max,
1147  queue->cread_buf,
1148  max));
1149  queue->pread_off += max;
1150  total = 0;
1151  while (0 != (done = try_handle_plaintext (queue)))
1152  {
1153  /* 'done' bytes of plaintext were used, shift buffer */
1154  GNUNET_assert (done <= queue->pread_off);
1155  /* NOTE: this memmove() could possibly sometimes be
1156  avoided if we pass 'total' into try_handle_plaintext()
1157  and use it at an offset into the buffer there! */
1158  memmove (queue->pread_buf,
1159  &queue->pread_buf[done],
1160  queue->pread_off - done);
1161  queue->pread_off -= done;
1162  total += done;
1163  /* The last plaintext was a rekey, abort for now */
1164  if (GNUNET_YES == queue->rekeyed)
1165  break;
1166  }
1167  /* when we encounter a rekey message, the decryption above uses the
1168  wrong key for everything after the rekey; in that case, we have
1169  to re-do the decryption at 'total' instead of at 'max'.
1170  However, we have to take into account that the plaintext buffer may have
1171  already contained data and not jumpt too far ahead in the ciphertext.
1172  If there is no rekey and the last message is incomplete (max > total),
1173  it is safe to keep the decryption so we shift by 'max' */
1174  if (GNUNET_YES == queue->rekeyed)
1175  {
1176  max = total - old_pread_off;
1177  queue->rekeyed = GNUNET_NO;
1178  queue->pread_off = 0;
1179  }
1180  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1181  queue->cread_off -= max;
1182  }
1183  if (BUF_SIZE == queue->cread_off)
1184  return; /* buffer full, suspend reading */
1186  if (0 != left.rel_value_us)
1187  {
1188  if (max_queue_length > queue->backpressure)
1189  {
1190  /* continue reading */
1192  queue->read_task =
1193  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1194  }
1195  return;
1196  }
1198  "Queue %p was idle for %s, disconnecting\n",
1199  queue,
1202  GNUNET_YES));
1203  queue_finish (queue);
1204 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
static void done()
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next...
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static void queue_read(void *cls)
Queue read task.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
#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...
Handle for a queue.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:701
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next...
#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...
#define GNUNET_log(kind,...)
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
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
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
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
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
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:

◆ core_read_finished_cb()

static void core_read_finished_cb ( void *  cls,
int  success 
)
static

Core tells us it is done processing a message that transport received on a queue with status success.

Parameters
clsa struct Queue * where the message originally came from
successGNUNET_OK on success

Definition at line 826 of file gnunet-communicator-tcp.c.

References Queue::backpressure, Queue::destroyed, GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get_remaining(), queue(), queue_read(), Queue::read_task, reschedule_queue_timeout(), Queue::sock, and Queue::timeout.

Referenced by pass_plaintext_to_core().

827 {
828  struct Queue *queue = cls;
829  if (GNUNET_OK != success)
831  "# messages lost in communicator API towards CORE",
832  1,
833  GNUNET_NO);
834  queue->backpressure--;
835  /* handle deferred queue destruction */
836  if ((queue->destroyed) && (0 == queue->backpressure))
837  {
838  GNUNET_free (queue);
839  return;
840  }
841  reschedule_queue_timeout (queue);
842  /* possibly unchoke reading, now that CORE made progress */
843  if (NULL == queue->read_task)
844  queue->read_task =
846  queue->timeout),
847  queue->sock,
848  &queue_read,
849  queue);
850 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
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 queue_read(void *cls)
Queue read task.
Handle for a queue.
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
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
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
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
#define GNUNET_free(ptr)
Wrapper around free.
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 Queue queue,
const void *  plaintext,
size_t  plaintext_len 
)
static

We received plaintext_len bytes of plaintext on queue.

Pass it on to CORE. If transmission is actually happening, increase backpressure counter.

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

Definition at line 863 of file gnunet-communicator-tcp.c.

References ADDRESS_VALIDITY_PERIOD, Queue::backpressure, core_read_finished_cb(), GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TRANSPORT_communicator_receive(), ret, GNUNET_MessageHeader::size, and Queue::target.

Referenced by try_handle_plaintext().

866 {
867  const struct GNUNET_MessageHeader *hdr = plaintext;
868  int ret;
869 
870  if (ntohs (hdr->size) != plaintext_len)
871  {
872  /* NOTE: If we ever allow multiple CORE messages in one
873  BOX, this will have to change! */
874  GNUNET_break (0);
875  return;
876  }
878  &queue->target,
879  hdr,
882  queue);
883  if (GNUNET_OK == ret)
884  queue->backpressure++;
885  GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
886  if (GNUNET_SYSERR == ret)
888  "# bytes lost due to CORE not running",
889  plaintext_len,
890  GNUNET_NO);
891 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
static void core_read_finished_cb(void *cls, int success)
Core tells us it is done processing a message that transport received on a queue with status success...
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
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 dh,
const struct GNUNET_PeerIdentity pid,
gcry_cipher_hd_t *  cipher,
struct GNUNET_HashCode hmac_key 
)
static

Setup cipher based on shared secret dh and decrypting peer pid.

Parameters
dhshared secret
piddecrypting peer's identity
cipher[out]cipher to initialize
hmac_key[out]HMAC key to initialize

Definition at line 904 of file gnunet-communicator-tcp.c.

References GNUNET_assert, GNUNET_CRYPTO_kdf(), GNUNET_YES, and key.

Referenced by setup_in_cipher(), and setup_out_cipher().

908 {
909  char key[256 / 8];
910  char ctr[128 / 8];
911 
912  gcry_cipher_open (cipher,
913  GCRY_CIPHER_AES256 /* low level: go for speed */,
914  GCRY_CIPHER_MODE_CTR,
915  0 /* flags */);
917  sizeof(key),
918  "TCP-key",
919  strlen ("TCP-key"),
920  dh,
921  sizeof(*dh),
922  pid,
923  sizeof(*pid),
924  NULL,
925  0));
926  gcry_cipher_setkey (*cipher, key, sizeof(key));
928  sizeof(ctr),
929  "TCP-ctr",
930  strlen ("TCP-ctr"),
931  dh,
932  sizeof(*dh),
933  pid,
934  sizeof(*pid),
935  NULL,
936  0));
937  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
939  GNUNET_CRYPTO_kdf (hmac_key,
940  sizeof(struct GNUNET_HashCode),
941  "TCP-hmac",
942  strlen ("TCP-hmac"),
943  dh,
944  sizeof(*dh),
945  pid,
946  sizeof(*pid),
947  NULL,
948  0));
949 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_in_cipher()

static void setup_in_cipher ( const struct GNUNET_CRYPTO_EcdhePublicKey ephemeral,
struct Queue queue 
)
static

Setup cipher of queue for decryption.

Parameters
ephemeralephemeral key we received from the other peer
queue[in,out]queue to initialize decryption cipher for

Definition at line 959 of file gnunet-communicator-tcp.c.

References GNUNET_CRYPTO_eddsa_ecdh(), Queue::in_cipher, Queue::in_hmac, my_identity, and setup_cipher().

Referenced by do_rekey(), proto_read_kx(), and queue_read_kx().

961 {
962  struct GNUNET_HashCode dh;
963 
964  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
965  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
966 }
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
static struct GNUNET_PeerIdentity my_identity
Our public key.
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
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
static void setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
A 512-bit hashcode.
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_rekey()

static void do_rekey ( struct Queue queue,
const struct TCPRekey rekey 
)
static

Handle rekey message on queue.

The message was already HMAC'ed, but we should additionally still check the signature. Then we need to stop the old cipher and start afresh.

Parameters
queuethe queue rekey was received on
rekeythe rekey message

Definition at line 978 of file gnunet-communicator-tcp.c.

References TcpHandshakeSignature::ephemeral, TCPRekey::ephemeral, GNUNET_break, GNUNET_CRYPTO_eddsa_verify, GNUNET_OK, GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, GNUNET_YES, Queue::in_cipher, TcpHandshakeSignature::monotonic_time, TCPRekey::monotonic_time, my_identity, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, queue_finish(), TcpHandshakeSignature::receiver, Queue::rekeyed, TcpHandshakeSignature::sender, TCPRekey::sender_sig, setup_in_cipher(), GNUNET_CRYPTO_EccSignaturePurpose::size, and Queue::target.

Referenced by try_handle_plaintext().

979 {
980  struct TcpHandshakeSignature thp;
982  thp.purpose.size = htonl (sizeof(thp));
983  thp.sender = queue->target;
984  thp.receiver = my_identity;
985  thp.ephemeral = rekey->ephemeral;
986  thp.monotonic_time = rekey->monotonic_time;
987  /* FIXME: check monotonic time is monotonic... */
988  if (GNUNET_OK !=
990  &thp,
991  &rekey->sender_sig,
992  &queue->target.public_key))
993  {
994  GNUNET_break (0);
995  queue_finish (queue);
996  return;
997  }
998  gcry_cipher_close (queue->in_cipher);
999  queue->rekeyed = GNUNET_YES;
1000  setup_in_cipher (&rekey->ephemeral, queue);
1001 }
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static struct GNUNET_PeerIdentity my_identity
Our public key.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
New ephemeral key.
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_handle_plaintext()

static size_t try_handle_plaintext ( struct Queue queue)
static

Test if we have received a full message in plaintext.

If so, handle it.

Parameters
queuequeue to process inbound plaintext for
Returns
number of bytes of plaintext handled, 0 for none

Definition at line 1012 of file gnunet-communicator-tcp.c.

References calculate_hmac(), do_rekey(), GNUNET_assert, GNUNET_break_op, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, TCPFinish::hmac, TCPRekey::hmac, Queue::in_hmac, pass_plaintext_to_core(), Queue::pread_buf, Queue::pread_off, queue_destroy(), queue_finish(), size, GNUNET_MessageHeader::size, type, and GNUNET_MessageHeader::type.

Referenced by queue_read().

1013 {
1014  const struct GNUNET_MessageHeader *hdr =
1015  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1016  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1017  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1018  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1019  struct TCPRekey rekeyz;
1020  struct TCPFinish finz;
1021  struct GNUNET_ShortHashCode tmac;
1022  uint16_t type;
1023  size_t size = 0; /* make compiler happy */
1024 
1025  if (sizeof(*hdr) > queue->pread_off)
1026  return 0; /* not even a header */
1027  type = ntohs (hdr->type);
1028  switch (type)
1029  {
1031  /* Special case: header size excludes box itself! */
1032  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1033  return 0;
1034  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1035  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1036  {
1037  GNUNET_break_op (0);
1038  queue_finish (queue);
1039  return 0;
1040  }
1041  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1042  size = ntohs (hdr->size) + sizeof(*box);
1043  break;
1044 
1046  if (sizeof(*rekey) > queue->pread_off)
1047  return 0;
1048  if (ntohs (hdr->size) != sizeof(*rekey))
1049  {
1050  GNUNET_break_op (0);
1051  queue_finish (queue);
1052  return 0;
1053  }
1054  rekeyz = *rekey;
1055  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1056  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1057  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1058  {
1059  GNUNET_break_op (0);
1060  queue_finish (queue);
1061  return 0;
1062  }
1063  do_rekey (queue, rekey);
1064  size = ntohs (hdr->size);
1065  break;
1066 
1068  if (sizeof(*fin) > queue->pread_off)
1069  return 0;
1070  if (ntohs (hdr->size) != sizeof(*fin))
1071  {
1072  GNUNET_break_op (0);
1073  queue_finish (queue);
1074  return 0;
1075  }
1076  finz = *fin;
1077  memset (&finz.hmac, 0, sizeof(finz.hmac));
1078  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1079  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1080  {
1081  GNUNET_break_op (0);
1082  queue_finish (queue);
1083  return 0;
1084  }
1085  /* handle FINISH by destroying queue */
1086  queue_destroy (queue);
1087  break;
1088 
1089  default:
1090  GNUNET_break_op (0);
1091  queue_finish (queue);
1092  return 0;
1093  }
1094  GNUNET_assert (0 != size);
1095  return size;
1096 }
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void pass_plaintext_to_core(struct Queue *queue, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext on queue.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
A 256-bit hashcode.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
static void do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
Handle rekey message on queue.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next...
static unsigned int size
Size of the "table".
Definition: peer.c:67
TCP message box.
TCP rekey message box.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v6()

static struct sockaddr* tcp_address_to_sockaddr_numeric_v6 ( socklen_t *  sock_len,
struct sockaddr_in6  v6,
unsigned int  port 
)
static

Convert a struct sockaddr_in6 to astruct sockaddr *`.

Parameters
[out]sock_lenset to the length of the address.
v6The sockaddr_in6 to be converted.
Returns
The struct sockaddr *.

Definition at line 1214 of file gnunet-communicator-tcp.c.

References GNUNET_a2s(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, and GNUNET_memdup.

Referenced by init_socket_resolv(), run(), tcp_address_to_sockaddr(), and tcp_address_to_sockaddr_port_only().

1216 {
1217  struct sockaddr *in;
1218 
1220  "1 address %s\n",
1221  GNUNET_a2s (in, *sock_len));
1222 
1223  v6.sin6_family = AF_INET6;
1224  v6.sin6_port = htons ((uint16_t) port);
1225 #if HAVE_SOCKADDR_IN_SIN_LEN
1226  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
1227 #endif
1228  in = GNUNET_memdup (&v6, sizeof(v6));
1229  *sock_len = sizeof(struct sockaddr_in6);
1231  "address %s\n",
1232  GNUNET_a2s (in, *sock_len));
1233 
1234  return in;
1235 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
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 uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v4()

static struct sockaddr* tcp_address_to_sockaddr_numeric_v4 ( socklen_t *  sock_len,
struct sockaddr_in  v4,
unsigned int  port 
)
static

Convert a struct sockaddr_in4 to astruct sockaddr *`.

Parameters
[out]sock_lenset to the length of the address.
v4The sockaddr_in4 to be converted.
Returns
The struct sockaddr *.

Definition at line 1245 of file gnunet-communicator-tcp.c.

References GNUNET_memdup.

Referenced by init_socket_resolv(), run(), tcp_address_to_sockaddr(), and tcp_address_to_sockaddr_port_only().

1247 {
1248  struct sockaddr *in;
1249 
1250  v4.sin_family = AF_INET;
1251  v4.sin_port = htons ((uint16_t) port);
1252 #if HAVE_SOCKADDR_IN_SIN_LEN
1253  v4.sin_len = sizeof(struct sockaddr_in);
1254 #endif
1255  in = GNUNET_memdup (&v4, sizeof(v4));
1256  *sock_len = sizeof(struct sockaddr_in);
1257  return in;
1258 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_port_only()

static struct PortOnlyIpv4Ipv6* tcp_address_to_sockaddr_port_only ( const char *  bindto,
unsigned int *  port 
)
static

Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *

Parameters
bindtobind specification to convert.
Returns
The converted bindto specification.

Definition at line 1267 of file gnunet-communicator-tcp.c.

References PortOnlyIpv4Ipv6::addr_ipv4, PortOnlyIpv4Ipv6::addr_ipv6, PortOnlyIpv4Ipv6::addr_len_ipv4, PortOnlyIpv4Ipv6::addr_len_ipv6, COMMUNICATOR_CONFIG_SECTION, GNUNET_a2s(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_malloc, GNUNET_NETWORK_test_pf(), GNUNET_new, GNUNET_NO, GNUNET_YES, tcp_address_to_sockaddr_numeric_v4(), and tcp_address_to_sockaddr_numeric_v6().

Referenced by run().

1268 {
1269  struct PortOnlyIpv4Ipv6 *po;
1270  struct sockaddr_in *i4;
1271  struct sockaddr_in6 *i6;
1272  socklen_t sock_len_ipv4;
1273  socklen_t sock_len_ipv6;
1274 
1275  /* interpreting value as just a PORT number */
1276  if (*port > UINT16_MAX)
1277  {
1279  "BINDTO specification `%s' invalid: value too large for port\n",
1280  bindto);
1281  return NULL;
1282  }
1283 
1284  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
1285 
1286  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1287  (GNUNET_YES ==
1290  "DISABLE_V6")))
1291  {
1292  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1293  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1294  *port);
1295  po->addr_len_ipv4 = &sock_len_ipv4;
1296  }
1297  else
1298  {
1299 
1300  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1301  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1302  *port);
1303  po->addr_len_ipv4 = &sock_len_ipv4;
1304 
1306  "3.5 address %s\n",
1307  GNUNET_a2s (po->addr_ipv4, sock_len_ipv4));
1308 
1309  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1310  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
1311  *port);
1313  "3 address %s\n",
1314  GNUNET_a2s (po->addr_ipv6, sock_len_ipv6));
1315 
1316  po->addr_len_ipv6 = &sock_len_ipv6;
1317  }
1318  return po;
1319 }
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
socklen_t * addr_len_ipv6
Length of ipv6 address.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
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)...
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
socklen_t * addr_len_ipv4
Length of ipv4 address.
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_address()

static char* extract_address ( const char *  bindto)
static

This Method extracts the address part of the BINDTO string.

Parameters
bindtoString we extract the address part from.
Returns
The extracted address string.

Definition at line 1328 of file gnunet-communicator-tcp.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_strdup, and start.

Referenced by run(), and tcp_address_to_sockaddr().

1329 {
1330 
1331  char *start;
1332  char *token;
1333  char *cp;
1334  char *rest = NULL;
1335 
1336  if (NULL == bindto)
1338  "bindto is NULL\n");
1339 
1340  cp = GNUNET_strdup (bindto);
1341  start = cp;
1342  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1343  {
1344  start++; /* skip over '['*/
1345  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
1346  }
1347  else {
1348  token = strtok_r (cp, "]", &rest);
1349  if (strlen (bindto) == strlen (token))
1350  {
1351  token = strtok_r (cp, ":", &rest);
1352  }
1353  else
1354  {
1355  token++;
1356  return token;
1357  }
1358  }
1359 
1360  // GNUNET_free(cp);
1361 
1362  return start;
1363 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ extract_port()

static unsigned int extract_port ( const char *  addr_and_port)
static

This Method extracts the port part of the BINDTO string.

Parameters
addr_and_portString we extract the port from.
Returns
The extracted port as unsigned int.

Definition at line 1372 of file gnunet-communicator-tcp.c.

References dummy, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_strdup, and port.

Referenced by run(), and tcp_address_to_sockaddr().

1373 {
1374  unsigned int port;
1375  char dummy[2];
1376  char *token;
1377  char *addr;
1378  char *colon;
1379  char *cp;
1380  char *rest = NULL;
1381 
1382  if (NULL != addr_and_port)
1383  {
1384  cp = GNUNET_strdup (addr_and_port);
1385  token = strtok_r (cp, "]", &rest);
1386  if (strlen (addr_and_port) == strlen (token))
1387  {
1388  colon = strrchr (cp, ':');
1389  if (NULL == colon)
1390  {
1391  return 0;
1392  }
1393  addr = colon;
1394  addr++;
1395  }
1396  else
1397  {
1398  token = strtok_r (NULL, "]", &rest);
1399  if (NULL == token)
1400  {
1401  return 0;
1402  }
1403  else
1404  {
1405  addr = token;
1406  addr++;
1407  }
1408  }
1409 
1410 
1411  if (1 == sscanf (addr, "%u%1s", &port, dummy))
1412  {
1413  /* interpreting value as just a PORT number */
1414  if (port > UINT16_MAX)
1415  {
1417  "Port `%u' invalid: value too large for port\n",
1418  port);
1419  // GNUNET_free (cp);
1420  return 0;
1421  }
1422  }
1423  else
1424  {
1426  "BINDTO specification invalid: last ':' not followed by number\n");
1427  // GNUNET_free (cp);
1428  return 0;
1429  }
1430  }
1431  else
1432  {
1434  "return 0\n");
1435  /* interpret missing port as 0, aka pick any free one */
1436  port = 0;
1437  }
1438 
1439 
1440  return port;
1441 }
#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,...)
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr()

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

Convert TCP 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 1451 of file gnunet-communicator-tcp.c.

References extract_address(), extract_port(), port, start, tcp_address_to_sockaddr_numeric_v4(), and tcp_address_to_sockaddr_numeric_v6().

Referenced by mq_init().

1452 {
1453  struct sockaddr *in;
1454  unsigned int port;
1455  struct sockaddr_in v4;
1456  struct sockaddr_in6 v6;
1457  const char *start;
1458 
1459  // cp = GNUNET_strdup (bindto);
1460  start = extract_address (bindto);
1461 
1462  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
1463  {
1464  // colon = strrchr (cp, ':');
1465  port = extract_port (bindto);
1466  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
1467  }
1468  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
1469  {
1470  // colon = strrchr (cp, ':');
1471  port = extract_port (bindto);
1472  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
1473  }
1474 
1475  return in;
1476 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_out_cipher()

static void setup_out_cipher ( struct Queue queue)
static

Setup cipher for outgoing data stream based on target and our ephemeral private key.

Parameters
queuequeue to setup outgoing (encryption) cipher for

Definition at line 1486 of file gnunet-communicator-tcp.c.

References Queue::ephemeral, GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_TIME_relative_to_absolute(), Queue::out_cipher, Queue::out_hmac, GNUNET_PeerIdentity::public_key, rekey_interval, Queue::rekey_left_bytes, REKEY_MAX_BYTES, Queue::rekey_time, setup_cipher(), and Queue::target.

Referenced by inject_rekey(), and start_initial_kx_out().

1487 {
1488  struct GNUNET_HashCode dh;
1489 
1490  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
1491  /* we don't need the private key anymore, drop it! */
1492  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
1493  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1495  queue->rekey_left_bytes =
1497 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
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 rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
static void setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
A 512-bit hashcode.
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
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inject_rekey()

static void inject_rekey ( struct Queue queue)
static

Inject a struct TCPRekey message into the queue's plaintext buffer.

Parameters
queuequeue to perform rekeying on

Definition at line 1507 of file gnunet-communicator-tcp.c.

References calculate_hmac(), Queue::cwrite_buf, Queue::cwrite_off, Queue::ephemeral, TCPRekey::ephemeral, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_sign, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TCPRekey::header, TCPRekey::hmac, TCPRekey::monotonic_time, TcpHandshakeSignature::monotonic_time, my_identity, Queue::out_cipher, Queue::out_hmac, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, Queue::pwrite_off, TcpHandshakeSignature::receiver, TcpHandshakeSignature::sender, TCPRekey::sender_sig, setup_out_cipher(), GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, Queue::target, and GNUNET_MessageHeader::type.

Referenced by queue_write().

1508 {
1509  struct TCPRekey rekey;
1510  struct TcpHandshakeSignature thp;
1511 
1512  GNUNET_assert (0 == queue->pwrite_off);
1513  memset (&rekey, 0, sizeof(rekey));
1515  rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1516  rekey.header.size = ntohs (sizeof(rekey));
1517  GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
1518  rekey.monotonic_time =
1520  thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1521  thp.purpose.size = htonl (sizeof(thp));
1522  thp.sender = my_identity;
1523  thp.receiver = queue->target;
1524  thp.ephemeral = rekey.ephemeral;
1525  thp.monotonic_time = rekey.monotonic_time;
1527  &thp,
1528  &rekey.sender_sig);
1529  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1530  /* Encrypt rekey message with 'old' cipher */
1531  GNUNET_assert (0 ==
1532  gcry_cipher_encrypt (queue->out_cipher,
1533  &queue->cwrite_buf[queue->cwrite_off],
1534  sizeof(rekey),
1535  &rekey,
1536  sizeof(rekey)));
1537  queue->cwrite_off += sizeof(rekey);
1538  /* Setup new cipher for successive messages */
1539  gcry_cipher_close (queue->out_cipher);
1540  setup_out_cipher (queue);
1541 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
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
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 setup_out_cipher(struct Queue *queue)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
TCP rekey message box.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_write()

static void queue_write ( void *  cls)
static

We have been notified that our socket is ready to write.

Then reschedule this function to be called again once more is available.

Parameters
clsa struct Queue

Definition at line 1551 of file gnunet-communicator-tcp.c.

References BUF_SIZE, Queue::cwrite_buf, Queue::cwrite_off, Queue::finishing, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_MQ_impl_send_continue(), GNUNET_NETWORK_socket_send(), GNUNET_NO, GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, inject_rekey(), Queue::mq, Queue::mq_awaits_continue, Queue::out_cipher, Queue::pwrite_buf, Queue::pwrite_off, queue(), queue_destroy(), Queue::rekey_left_bytes, Queue::rekey_time, GNUNET_TIME_Relative::rel_value_us, reschedule_queue_timeout(), Queue::sock, and Queue::write_task.

Referenced by mq_init(), mq_send(), and proto_read_kx().

1552 {
1553  struct Queue *queue = cls;
1554  ssize_t sent;
1555  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1556  queue->write_task = NULL;
1557  if (0 != queue->cwrite_off)
1558  {
1559  sent = GNUNET_NETWORK_socket_send (queue->sock,
1560  queue->cwrite_buf,
1561  queue->cwrite_off);
1563  "Sent %lu bytes to TCP queue\n", sent);
1564  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1565  {
1567  queue_destroy (queue);
1568  return;
1569  }
1570  if (sent > 0)
1571  {
1572  size_t usent = (size_t) sent;
1573  queue->cwrite_off -= usent;
1574  memmove (queue->cwrite_buf,
1575  &queue->cwrite_buf[usent],
1576  queue->cwrite_off);
1577  reschedule_queue_timeout (queue);
1578  }
1579  }
1580  /* can we encrypt more? (always encrypt full messages, needed
1581  such that #mq_cancel() can work!) */
1582  if ((0 < queue->rekey_left_bytes) &&
1583  (queue->pwrite_off > 0) &&
1584  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1585  {
1587  "Encrypting %lu bytes\n", queue->pwrite_off);
1588  GNUNET_assert (0 ==
1589  gcry_cipher_encrypt (queue->out_cipher,
1590  &queue->cwrite_buf[queue->cwrite_off],
1591  queue->pwrite_off,
1592  queue->pwrite_buf,
1593  queue->pwrite_off));
1594  if (queue->rekey_left_bytes > queue->pwrite_off)
1595  queue->rekey_left_bytes -= queue->pwrite_off;
1596  else
1597  queue->rekey_left_bytes = 0;
1598  queue->cwrite_off += queue->pwrite_off;
1599  queue->pwrite_off = 0;
1600  }
1601  if ((0 == queue->pwrite_off) &&
1602  ((0 == queue->rekey_left_bytes) ||
1603  (0 ==
1605  {
1606  inject_rekey (queue);
1607  }
1608  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1609  (GNUNET_YES == queue->mq_awaits_continue))
1610  {
1611  queue->mq_awaits_continue = GNUNET_NO;
1613  }
1614  /* did we just finish writing 'finish'? */
1615  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1616  {
1618  "Finishing queue\n");
1619  queue_destroy (queue);
1620  return;
1621  }
1622  /* do we care to write more? */
1623  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1624  queue->write_task =
1626  queue->sock,
1627  &queue_write,
1628  queue);
1629 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
uint64_t rel_value_us
The actual value.
int finishing
Did we enqueue a finish message and are closing down the queue?
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:816
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, 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:1588
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue&#39;s plaintext buffer.
#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 void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
Handle for a queue.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#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
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
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send()

static void mq_send ( 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 Queue

Definition at line 1641 of file gnunet-communicator-tcp.c.

References calculate_hmac(), Queue::finishing, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX, GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, TCPBox::header, TCPBox::hmac, Queue::mq, Queue::mq_awaits_continue, Queue::out_hmac, Queue::pwrite_buf, Queue::pwrite_off, queue(), queue_write(), GNUNET_MessageHeader::size, Queue::sock, GNUNET_MessageHeader::type, and Queue::write_task.

Referenced by boot_queue().

1644 {
1645  struct Queue *queue = impl_state;
1646  uint16_t msize = ntohs (msg->size);
1647  struct TCPBox box;
1649  "In MQ send. Queue finishing: %s; write task running: %s\n",
1650  (GNUNET_YES == queue->finishing) ? "yes" : "no",
1651  (NULL == queue->write_task) ? "yes" : "no");
1652  GNUNET_assert (mq == queue->mq);
1653  queue->mq_awaits_continue = GNUNET_YES;
1654  if (GNUNET_YES == queue->finishing)
1655  return; /* this queue is dying, drop msg */
1656  GNUNET_assert (0 == queue->pwrite_off);
1657  box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
1658  box.header.size = htons (msize);
1659  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
1660  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
1661  queue->pwrite_off += sizeof(box);
1662  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
1663  queue->pwrite_off += msize;
1665  "%lu bytes of plaintext to send\n", queue->pwrite_off);
1666  GNUNET_assert (NULL != queue->sock);
1667  if (NULL == queue->write_task)
1668  queue->write_task =
1670  queue->sock,
1671  &queue_write,
1672  queue);
1673 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
int finishing
Did we enqueue a finish message and are closing down the queue?
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, 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:1588
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
Handle for a queue.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
TCP message box.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy()

static void mq_destroy ( 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 Queue

Definition at line 1685 of file gnunet-communicator-tcp.c.

References Queue::mq, queue(), and queue_finish().

Referenced by boot_queue().

1686 {
1687  struct Queue *queue = impl_state;
1688 
1689  if (mq == queue->mq)
1690  {
1691  queue->mq = NULL;
1692  queue_finish (queue);
1693  }
1694 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
Handle for a queue.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
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 Queue

Definition at line 1704 of file gnunet-communicator-tcp.c.

References GNUNET_assert, Queue::pwrite_off, and queue().

Referenced by boot_queue().

1705 {
1706  struct Queue *queue = impl_state;
1707 
1708  GNUNET_assert (0 != queue->pwrite_off);
1709  queue->pwrite_off = 0;
1710 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Handle for a queue.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
Here is the call graph for this function:
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 Queue
errorerror code

Definition at line 1723 of file gnunet-communicator-tcp.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, queue(), queue_finish(), and Queue::target.

Referenced by boot_queue().

1724 {
1725  struct Queue *queue = cls;
1726 
1728  "MQ error in queue to %s: %d\n",
1729  GNUNET_i2s (&queue->target),
1730  (int) error);
1731  queue_finish (queue);
1732 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
struct GNUNET_PeerIdentity target
To whom are we talking to.
Handle for a queue.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
#define GNUNET_log(kind,...)
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:

◆ boot_queue()

static void boot_queue ( struct Queue queue,
enum GNUNET_TRANSPORT_ConnectionStatus  cs 
)
static

Add the given queue to our internal data structure.

Setup the MQ processing and inform transport that the queue is ready. Must be called after the KX for outgoing messages has been bootstrapped.

Parameters
queuequeue to boot

Definition at line 1743 of file gnunet-communicator-tcp.c.

References Queue::address, Queue::address_len, COMMUNICATOR_ADDRESS_PREFIX, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_free, GNUNET_MQ_queue_for_callbacks(), GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_STATISTICS_set(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, Queue::mq, mq_cancel(), mq_destroy(), mq_error(), mq_send(), Queue::nt, Queue::qh, Queue::target, and Queue::timeout.

Referenced by mq_init(), and proto_read_kx().

1744 {
1745  queue->nt =
1748  queue_map,
1749  &queue->target,
1750  queue,
1753  "# queues active",
1755  GNUNET_NO);
1756  queue->timeout =
1759  &mq_destroy,
1760  &mq_cancel,
1761  queue,
1762  NULL,
1763  &mq_error,
1764  queue);
1765  {
1766  char *foreign_addr;
1767 
1768  switch (queue->address->sa_family)
1769  {
1770  case AF_INET:
1771  GNUNET_asprintf (&foreign_addr,
1772  "%s-%s",
1774  GNUNET_a2s (queue->address, queue->address_len));
1775  break;
1776 
1777  case AF_INET6:
1778  GNUNET_asprintf (&foreign_addr,
1779  "%s-%s",
1781  GNUNET_a2s (queue->address, queue->address_len));
1782  break;
1783 
1784  default:
1785  GNUNET_assert (0);
1786  }
1788  &queue->target,
1789  foreign_addr,
1790  0 /* no MTU */,
1792  0, /* Priority */
1793  queue->nt,
1794  cs,
1795  queue->mq);
1796  GNUNET_free (foreign_addr);
1797  }
1798 }
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_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the 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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
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
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
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)...
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 mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void mq_send(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 * 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...
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 sockaddr * address
Address of the other peer.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
enum GNUNET_TRANSPORT_ConnectionStatus cs
Connection status for this queue.
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...
enum GNUNET_NetworkType nt
Which network type does this queue use?
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_kx()

static void transmit_kx ( struct Queue queue,
const struct GNUNET_CRYPTO_EcdhePublicKey epub 
)
static

Generate and transmit our ephemeral key and the signature for the initial KX with the other peer.

Must be called first, before any other bytes are ever written to the output buffer. Note that our cipher must already be initialized when calling this function. Helper function for start_initial_kx_out().

Parameters
queuequeue to do KX for
epubour public key for the KX

Definition at line 1812 of file gnunet-communicator-tcp.c.

References Queue::cwrite_buf, Queue::cwrite_off, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TcpHandshakeSignature::monotonic_time, TCPConfirmation::monotonic_time, my_identity, Queue::out_cipher, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, TcpHandshakeSignature::receiver, TCPConfirmation::sender, TcpHandshakeSignature::sender, TCPConfirmation::sender_sig, GNUNET_CRYPTO_EccSignaturePurpose::size, Queue::target, and tc.

Referenced by start_initial_kx_out().

1814 {
1815  struct TcpHandshakeSignature ths;
1816  struct TCPConfirmation tc;
1817 
1818  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
1819  queue->cwrite_off = sizeof(*epub);
1820  /* compute 'tc' and append in encrypted format to cwrite_buf */
1821  tc.sender = my_identity;
1822  tc.monotonic_time =
1824  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1825  ths.purpose.size = htonl (sizeof(ths));
1826  ths.sender = my_identity;
1827  ths.receiver = queue->target;
1828  ths.ephemeral = *epub;
1829  ths.monotonic_time = tc.monotonic_time;
1831  &ths,
1832  &tc.sender_sig);
1833  GNUNET_assert (0 ==
1834  gcry_cipher_encrypt (queue->out_cipher,
1835  &queue->cwrite_buf[queue->cwrite_off],
1836  sizeof(tc),
1837  &tc,
1838  sizeof(tc)));
1839  queue->cwrite_off += sizeof(tc);
1840 }
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake,.
struct GNUNET_PeerIdentity target
To whom are we talking to.
#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.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
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
Encrypted continuation of TCP initial handshake.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_initial_kx_out()

static void start_initial_kx_out ( struct Queue queue)
static

Initialize our key material for outgoing transmissions and inform the other peer about it.

Must be called first before any data is sent.

Parameters
queuethe queue to setup

Definition at line 1851 of file gnunet-communicator-tcp.c.

References Queue::ephemeral, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), setup_out_cipher(), and transmit_kx().

Referenced by mq_init(), and proto_read_kx().

1852 {
1853  struct GNUNET_CRYPTO_EcdhePublicKey epub;
1854 
1857  setup_out_cipher (queue);
1858  transmit_kx (queue, &epub);
1859 }
static void transmit_kx(struct Queue *queue, const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
Generate and transmit our ephemeral key and the signature for the initial KX with the other peer...
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
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 void setup_out_cipher(struct Queue *queue)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_and_check_tc()

static int decrypt_and_check_tc ( struct Queue queue,
struct TCPConfirmation tc,
char *  ibuf 
)
static

We have received the first bytes from the other side on a queue.

Decrypt the tc contained in ibuf and check the signature. Note that setup_in_cipher() must have already been called.

Parameters
queuequeue to decrypt initial bytes from other peer for
tc[out]where to store the result
ibufincoming data, of size INITIAL_KX_SIZE
Returns
GNUNET_OK if the signature was OK, GNUNET_SYSERR if not

Definition at line 1874 of file gnunet-communicator-tcp.c.

References TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_verify, GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, Queue::in_cipher, TCPConfirmation::monotonic_time, TcpHandshakeSignature::monotonic_time, my_identity, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, TcpHandshakeSignature::receiver, TcpHandshakeSignature::sender, TCPConfirmation::sender, TCPConfirmation::sender_sig, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by proto_read_kx(), and queue_read_kx().

1877 {
1878  struct TcpHandshakeSignature ths;
1879 
1880  GNUNET_assert (
1881  0 ==
1882  gcry_cipher_decrypt (queue->in_cipher,
1883  tc,
1884  sizeof(*tc),
1885  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
1886  sizeof(*tc)));
1887  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1888  ths.purpose.size = htonl (sizeof(ths));
1889  ths.sender = tc->sender;
1890  ths.receiver = my_identity;
1891  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
1892  ths.monotonic_time = tc->monotonic_time;
1893  /* FIXME: check monotonic time against previous mono times
1894  from this sender! */
1897  &ths,
1898  &tc->sender_sig,
1899  &tc->sender.public_key);
1900 }
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake,.
static struct GNUNET_PeerIdentity my_identity
Our public key.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the caller graph for this function:

◆ free_proto_queue()

static void free_proto_queue ( struct ProtoQueue pq)
static

Closes socket and frees memory associated with pq.

Parameters
pqproto queue to free

Definition at line 1909 of file gnunet-communicator-tcp.c.

References ProtoQueue::address, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), ProtoQueue::listen_sock, ProtoQueue::listen_task, and ProtoQueue::sock.

Referenced by do_shutdown(), and proto_read_kx().

1910 {
1911  if (NULL != pq->listen_task)
1912  {
1914  pq->listen_task = NULL;
1915  }
1916  if (NULL != pq->listen_sock)
1917  {
1919  pq->listen_sock = NULL;
1920  }
1922  GNUNET_free (pq->address);
1924  GNUNET_free (pq);
1925 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct sockaddr * address
Address of the other peer.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
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:

◆ proto_read_kx()

static void proto_read_kx ( void *  cls)
static

Read from the socket of the proto queue until we have enough data to upgrade to full queue.

Parameters
clsa struct ProtoQueue

Definition at line 1935 of file gnunet-communicator-tcp.c.

References Queue::address, ProtoQueue::address, Queue::address_len, ProtoQueue::address_len, boot_queue(), decrypt_and_check_tc(), free_proto_queue(), GNUNET_a2s(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recv(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CS_INBOUND, ProtoQueue::ibuf, ProtoQueue::ibuf_off, Queue::in_cipher, Queue::listen_sock, ProtoQueue::listen_sock, Queue::listen_task, ProtoQueue::listen_task, queue(), queue_read(), queue_write(), Queue::read_task, ProtoQueue::read_task, GNUNET_TIME_Relative::rel_value_us, TCPConfirmation::sender, setup_in_cipher(), Queue::sock, ProtoQueue::sock, start_initial_kx_out(), Queue::target, ProtoQueue::timeout, and Queue::write_task.

Referenced by listen_cb().

1936 {
1937  struct ProtoQueue *pq = cls;
1938  ssize_t rcvd;
1939  struct GNUNET_TIME_Relative left;
1940  struct Queue *queue;
1941  struct TCPConfirmation tc;
1942 
1943  pq->read_task = NULL;
1945  if (0 == left.rel_value_us)
1946  {
1947  free_proto_queue (pq);
1948  return;
1949  }
1950  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
1951  &pq->ibuf[pq->ibuf_off],
1952  sizeof(pq->ibuf) - pq->ibuf_off);
1954  "Received %lu bytes for KX\n", rcvd);
1955  if (-1 == rcvd)
1956  {
1957  if ((EAGAIN != errno) && (EINTR != errno))
1958  {
1960  free_proto_queue (pq);
1961  return;
1962  }
1963  /* try again */
1964  pq->read_task =
1966  return;
1967  }
1968  pq->ibuf_off += rcvd;
1969  if (pq->ibuf_off > sizeof(pq->ibuf))
1970  {
1971  /* read more */
1972  pq->read_task =
1974  return;
1975  }
1976  /* we got all the data, let's find out who we are talking to! */
1977  queue = GNUNET_new (struct Queue);
1978  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
1979  queue);
1980  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
1981  {
1983  "Invalid TCP KX received from %s\n",
1984  GNUNET_a2s (queue->address, queue->address_len));
1985  gcry_cipher_close (queue->in_cipher);
1986  GNUNET_free (queue);
1987  free_proto_queue (pq);
1988  return;
1989  }
1990  queue->address = pq->address; /* steals reference */
1991  queue->address_len = pq->address_len;
1992  queue->target = tc.sender;
1993  queue->listen_task = pq->listen_task;
1994  queue->listen_sock = pq->listen_sock;
1995  queue->sock = pq->sock;
1996  start_initial_kx_out (queue);
1998  queue->read_task =
2000  queue->sock,
2001  &queue_read,
2002  queue);
2003  queue->write_task =
2005  queue->sock,
2006  &queue_write,
2007  queue);
2009  GNUNET_free (pq);
2010 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
Add the given queue to our internal data structure.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue...
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, 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:1588
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void queue_read(void *cls)
Queue read task.
Handle for an incoming connection where we do not yet have enough information to setup a full queue...
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#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...
Handle for a queue.
this is an inbound connection (communicator initiated)
#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)...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct sockaddr * address
Address of the other peer.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it...
#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...
socklen_t address_len
Length of the address.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
struct sockaddr * address
Address of the other peer.
size_t ibuf_off
Current offset for reading into ibuf.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#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
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
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
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read_kx()

static void queue_read_kx ( void *  cls)
static

Read from the socket of the queue until we have enough data to initialize the decryption logic and can switch to regular reading.

Parameters
clsa struct Queue

Definition at line 2072 of file gnunet-communicator-tcp.c.

References Queue::address, Queue::address_len, BUF_SIZE, Queue::cread_buf, Queue::cread_off, decrypt_and_check_tc(), GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recv(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_net(), GNUNET_TIME_absolute_get_remaining(), INITIAL_KX_SIZE, queue(), queue_destroy(), queue_read(), Queue::read_task, GNUNET_TIME_Relative::rel_value_us, reschedule_queue_timeout(), TCPConfirmation::sender, setup_in_cipher(), Queue::sock, Queue::target, and Queue::timeout.

Referenced by mq_init().

2073 {
2074  struct Queue *queue = cls;
2075  ssize_t rcvd;
2076  struct GNUNET_TIME_Relative left;
2077  struct TCPConfirmation tc;
2078 
2079  queue->read_task = NULL;
2081  if (0 == left.rel_value_us)
2082  {
2083  queue_destroy (queue);
2084  return;
2085  }
2086  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2087  &queue->cread_buf[queue->cread_off],
2088  BUF_SIZE - queue->cread_off);
2089  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %lu bytes for KX\n", rcvd);
2090  if (-1 == rcvd)
2091  {
2092  if ((EAGAIN != errno) && (EINTR != errno))
2093  {
2095  queue_destroy (queue);
2096  return;
2097  }
2098  queue->read_task =
2099  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2100  return;
2101  }
2102  queue->cread_off += rcvd;
2103  if (queue->cread_off < INITIAL_KX_SIZE)
2104  {
2105  /* read more */
2106  queue->read_task =
2107  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2108  return;
2109  }
2110  /* we got all the data, let's find out who we are talking to! */
2112  queue->cread_buf,
2113  queue);
2114  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2115  {
2117  "Invalid TCP KX received from %s\n",
2118  GNUNET_a2s (queue->address, queue->address_len));
2119  queue_destroy (queue);
2120  return;
2121  }
2122  if (0 !=
2123  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2124  {
2126  "Invalid sender in TCP KX received from %s\n",
2127  GNUNET_a2s (queue->address, queue->address_len));
2128  queue_destroy (queue);
2129  return;
2130  }
2131 
2132  /* update queue timeout */
2133  reschedule_queue_timeout (queue);
2134  /* prepare to continue with regular read task immediately */
2135  memmove (queue->cread_buf,
2136  &queue->cread_buf[INITIAL_KX_SIZE],
2137  queue->cread_off - (INITIAL_KX_SIZE));
2138  queue->cread_off -= INITIAL_KX_SIZE;
2139  if (0 < queue->cread_off)
2140  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2141 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next...
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static void queue_read(void *cls)
Queue read task.
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
#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 void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
Handle for a queue.
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 reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
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)...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
The identity of the host (wraps the signing key of the peer).
struct sockaddr * address
Address of the other peer.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#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
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
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
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:

◆ 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 2162 of file gnunet-communicator-tcp.c.

References Queue::address, Queue::address_len, boot_queue(), COMMUNICATOR_ADDRESS_PREFIX, GNUNET_break_op, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CS_OUTBOUND, peer, queue(), queue_read_kx(), queue_write(), Queue::read_task, Queue::sock, start_initial_kx_out(), Queue::target, tcp_address_to_sockaddr(), and Queue::write_task.

Referenced by GNUNET_TRANSPORT_communicator_connect(), and init_socket().

2163 {
2164  struct Queue *queue;
2165  const char *path;
2166  struct sockaddr *in;
2167  socklen_t in_len;
2168  struct GNUNET_NETWORK_Handle *sock;
2169 
2171  "Connecting to %s\n", address);
2172  if (0 != strncmp (address,
2174  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2175  {
2176  GNUNET_break_op (0);
2177  return GNUNET_SYSERR;
2178  }
2179  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2180  in = tcp_address_to_sockaddr (path, &in_len);
2181 
2182  if (NULL == in)
2183  {
2185  "Failed to setup TCP socket address\n");
2186  return GNUNET_SYSERR;
2187  }
2188 
2189  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2190  if (NULL == sock)
2191  {
2193  "socket(%d) failed: %s",
2194  in->sa_family,
2195  strerror (errno));
2196  GNUNET_free (in);
2197  return GNUNET_SYSERR;
2198  }
2199  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2200  (errno != EINPROGRESS))
2201  {
2203  "connect to `%s' failed: %s",
2204  address,
2205  strerror (errno));
2207  GNUNET_free (in);
2208  return GNUNET_SYSERR;
2209  }
2210 
2211  queue = GNUNET_new (struct Queue);
2212  queue->target = *peer;
2213  queue->address = in;
2214  queue->address_len = in_len;
2215  queue->sock = sock;
2217  // queue->mq_awaits_continue = GNUNET_YES;
2218  queue->read_task =
2220  queue->sock,
2221  &queue_read_kx,
2222  queue);
2223  start_initial_kx_out (queue);
2224  queue->write_task =
2226  queue->sock,
2227  &queue_write,
2228  queue);
2229  return GNUNET_OK;
2230 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
static void boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
Add the given queue to our internal data structure.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, 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:1588
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:658
Handle for a queue.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it...
#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 sockaddr * address
Address of the other peer.
this is an outbound connection (transport initiated)
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:52
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 char * address
GNS address for this phone.
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_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_queue_delete_it()

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

Iterator over all message queues to clean up.

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

Definition at line 2241 of file gnunet-communicator-tcp.c.

References GNUNET_OK, queue(), queue_destroy(), and value.

Referenced by do_shutdown().

2244 {
2245  struct Queue *queue = value;
2246 
2247  (void) cls;
2248  (void) target;
2249  queue_destroy (queue);
2250  return GNUNET_OK;
2251 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static char * value
Value of the record to add/remove.
Handle for a queue.
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 2260 of file gnunet-communicator-tcp.c.

References free_proto_queue(), get_queue_delete_it(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, GNUNET_NAT_unregister(), GNUNET_NO, GNUNET_NT_scanner_done(), GNUNET_STATISTICS_destroy(), and GNUNET_TRANSPORT_communicator_disconnect().

Referenced by init_socket().

2261 {
2262  while (NULL != proto_head)
2264  if (NULL != nat)
2265  {
2267  nat = NULL;
2268  }
2271  if (NULL != ch)
2272  {
2274  ch = NULL;
2275  }
2276  if (NULL != stats)
2277  {
2279  stats = NULL;
2280  }
2281  if (NULL != my_private_key)
2282  {
2284  my_private_key = NULL;
2285  }
2286  if (NULL != is)
2287  {
2289  is = NULL;
2290  }
2291 }
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
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_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 * queue_map
Queues (map from peer identity to struct Queue)
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
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_queue_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all message queues to clean up.
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 void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
#define GNUNET_free(ptr)
Wrapper around free.
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 an acknowledgement for this communicator (!) via a different return path.

Not applicable for TCP.

Parameters
clsclosure
senderwhich peer sent the notification
msgpayload

Definition at line 2306 of file gnunet-communicator-tcp.c.

References GNUNET_break_op.

Referenced by init_socket().

2309 {
2310  (void) cls;
2311  (void) sender;
2312  (void) msg;
2313  GNUNET_break_op (0);
2314 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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 2331 of file gnunet-communicator-tcp.c.

References ai, COMMUNICATOR_ADDRESS_PREFIX, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, 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 nat_register().

2337 {
2338  char *my_addr;
2340 
2342  "1 nat_address %s\n",
2343  GNUNET_a2s (addr, addrlen));
2344 
2345  if (GNUNET_YES == add_remove)
2346  {
2347  enum GNUNET_NetworkType nt;
2348 
2349  GNUNET_asprintf (&my_addr,
2350  "%s-%s",
2352  GNUNET_a2s (addr, addrlen));
2353  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2354  ai =
2356  my_addr,
2357  nt,
2359  GNUNET_free (my_addr);
2360  *app_ctx = ai;
2361  }
2362  else
2363  {
2364  ai = *app_ctx;
2366  *app_ctx = NULL;
2367  }
2368 }
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.
#define GNUNET_log(kind,...)
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:

◆ init_socket()

static int init_socket ( const struct sockaddr *  addr,
socklen_t  in_len 
)
static

This method launch network interactions for each address we like to bind to.

Parameters
addrThe address we will listen to.
in_lenThe length of the address we will listen to.
Returns
GNUNET_SYSERR in case of error. GNUNET_OK in case we are successfully listen to the address.

Definition at line 2378 of file gnunet-communicator-tcp.c.

References _, COMMUNICATOR_ADDRESS_PREFIX, COMMUNICATOR_CONFIG_SECTION, do_shutdown(), enc_notify_cb(), GNUNET_a2s(), GNUNET_break, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_get_fd(), GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_listen(), GNUNET_new, GNUNET_NO, GNUNET_NT_scanner_init(), GNUNET_OK, GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CC_RELIABLE, GNUNET_TRANSPORT_communicator_connect(), listen_cb(), ListenTask::listen_sock, ListenTask::listen_task, mq_init(), my_identity, and GNUNET_PeerIdentity::public_key.

Referenced by init_socket_resolv(), and run().

2380 {
2381  struct sockaddr_storage in_sto;
2382  socklen_t sto_len;
2383  struct GNUNET_NETWORK_Handle *listen_sock;
2384  struct ListenTask *lt;
2385 
2386  if (NULL == addr)
2387  {
2389  "Address is NULL.\n");
2390  return GNUNET_SYSERR;
2391  }
2392 
2394  "4 address %s\n",
2395  GNUNET_a2s (addr, in_len));
2396 
2398  "address %s\n",
2399  GNUNET_a2s (addr, in_len));
2400 
2401  listen_sock =
2402  GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
2403  if (NULL == listen_sock)
2404  {
2406  return GNUNET_SYSERR;
2407  }
2408 
2409  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
2410  {
2412  GNUNET_NETWORK_socket_close (listen_sock);
2413  listen_sock = NULL;
2414  return GNUNET_SYSERR;
2415  }
2416 
2417  if (GNUNET_OK !=
2418  GNUNET_NETWORK_socket_listen (listen_sock,
2419  5))
2420  {
2422  "listen");
2423  GNUNET_NETWORK_socket_close (listen_sock);
2424  listen_sock = NULL;
2425  return GNUNET_SYSERR;
2426  }
2427 
2428  /* We might have bound to port 0, allowing the OS to figure it out;
2429  thus, get the real IN-address from the socket */
2430  sto_len = sizeof(in_sto);
2431 
2432  if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
2433  (struct sockaddr *) &in_sto,
2434  &sto_len))
2435  {
2436  memcpy (&in_sto, addr, in_len);
2437  sto_len = in_len;
2438  }
2439 
2440  addr = (struct sockaddr *) &in_sto;
2441  in_len = sto_len;
2443  "Bound to `%s'\n",
2444  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
2445  stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
2447 
2448  if (NULL == is)
2450 
2451  if (NULL == my_private_key)
2453  if (NULL == my_private_key)
2454  {
2455  GNUNET_log (
2457  _ (
2458  "Transport service is lacking key configuration settings. Exiting.\n"));
2461  return GNUNET_SYSERR;
2462  }
2464  /* start listening */
2465 
2466  lt = GNUNET_new (struct ListenTask);
2467  lt->listen_sock = listen_sock;
2468 
2470  listen_sock,
2471  &listen_cb,
2472  lt);
2473 
2474  if (NULL == queue_map)
2476 
2477  if (NULL == ch )
2482  &mq_init,
2483  NULL,
2484  &enc_notify_cb,
2485  NULL);
2486 
2487  if (NULL == ch)
2488  {
2489  GNUNET_break (0);
2492  return GNUNET_SYSERR;
2493  }
2494 
2495  return GNUNET_OK;
2496 
2497 }
int GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:708
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
Transmission is reliabile (with ACKs), i.e.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1080
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
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.
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
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).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#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
#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 void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received an acknowledgement for this communicator (!) ...
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
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 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...
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:412
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_STATISTICS_Handle * stats
For logging statistics.
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:52
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 void do_shutdown(void *cls)
Shutdown the UNIX communicator.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
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
Struct to use as closure.
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:

◆ nat_register()

static void nat_register ( )
static

This method reads from the DLL addrs_head to register them at the NAT service.

Definition at line 2503 of file gnunet-communicator-tcp.c.

References Addresses::addr, Addresses::addr_len, addrs_lens, COMMUNICATOR_CONFIG_SECTION, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_malloc, GNUNET_NAT_register(), GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_shutdown(), nat_address_cb(), and Addresses::next.

Referenced by init_socket_resolv(), and run().

2504 {
2505 
2506  struct sockaddr **saddrs;
2507  socklen_t *saddr_lens;
2508  int i;
2509  struct Addresses *pos;
2510 
2512  "nat here\n");
2513 
2514  i = 0;
2515  saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *));
2516 
2518  "2 nat here\n");
2519 
2520  saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t));
2521 
2523  "3 nat here\n");
2524 
2525  for (pos = addrs_head; NULL != pos; pos = pos->next)
2526  {
2527 
2529  "5 nat here\n");
2530 
2531  saddr_lens[i] = addrs_head->addr_len;
2532  saddrs[i] = GNUNET_malloc (saddr_lens[i]);
2533  saddrs[i] = addrs_head->addr;
2534 
2535  i++;
2536 
2538  "6 nat here\n");
2539 
2540  }
2541 
2544  IPPROTO_TCP,
2545  addrs_lens,
2546  (const struct sockaddr **) saddrs,
2547  saddr_lens,
2548  &nat_address_cb,
2549  NULL /* FIXME: support reversal: #5529 */,
2550  NULL /* closure */);
2551 
2552  if (NULL == nat)
2553  {
2554  GNUNET_break (0);
2557  }
2558 }
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
DLL to store the addresses we like to register at NAT service.
int addrs_lens
Number of addresses in the DLL for register at NAT service.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT servcie.
struct Addresses * next
Kept in a DLL.
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 sockaddr * addr
Address we like to register at NAT service.
#define GNUNET_log(kind,...)
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 ...
socklen_t addr_len
Length of address we like to register at NAT service.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_addr()

static void add_addr ( struct sockaddr *  in,
socklen_t  in_len 
)
static

This method adds addresses to the DLL, that are later register at the NAT service.

Definition at line 2564 of file gnunet-communicator-tcp.c.

References Addresses::addr, Addresses::addr_len, addrs_lens, GNUNET_CONTAINER_DLL_insert, and GNUNET_new.

Referenced by init_socket_resolv(), and run().

2565 {
2566 
2567  struct Addresses *saddrs;
2568 
2569  saddrs = GNUNET_new (struct Addresses);
2570  saddrs->addr = in;
2571  saddrs->addr_len = in_len;
2573  addrs_lens++;
2574 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
DLL to store the addresses we like to register at NAT service.
int addrs_lens
Number of addresses in the DLL for register at NAT service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT servcie.
struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT servcie.
struct sockaddr * addr
Address we like to register at NAT service.
socklen_t addr_len
Length of address we like to register at NAT service.
Here is the caller graph for this function:

◆ init_socket_resolv()

static void init_socket_resolv ( void *  cls,
const struct sockaddr *  addr,
socklen_t  in_len 
)
static

This method is the callback called by the resolver API, and wraps method init_socket.

Parameters
clsThe port we will bind to.
addrThe address we will bind to.
in_lenThe length of the address we will bind to.

Definition at line 2584 of file gnunet-communicator-tcp.c.

References add_addr(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, init_socket(), nat_register(), port, tcp_address_to_sockaddr_numeric_v4(), and tcp_address_to_sockaddr_numeric_v6().

Referenced by run().

2587 {
2588  struct sockaddr_in *v4;
2589  struct sockaddr_in6 *v6;
2590  struct sockaddr *in;
2591  unsigned int *port;
2592 
2593  port = cls;
2594  if (NULL != addr)
2595  {
2596  if (AF_INET == addr->sa_family)
2597  {
2598  v4 = (struct sockaddr_in *) addr;
2599  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, *port);// _global);
2600  add_addr (in, in_len);
2601  }
2602  else if (AF_INET6 == addr->sa_family)
2603  {
2604  v6 = (struct sockaddr_in6 *) addr;
2605  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, *port);// _global);
2606  add_addr (in, in_len);
2607  }
2608  else
2609  {
2611  "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
2612  addr->sa_family,
2613  AF_INET,
2614  AF_INET6);
2615  return;
2616  }
2617  init_socket (in,
2618  in_len);
2619  }
2620  else
2621  {
2623  "Address is NULL. This might be an error or the resolver finished resolving.\n");
2624  nat_register ();
2625  }
2626 }
static int init_socket(const struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static void nat_register()
This method reads from the DLL addrs_head to register them at the NAT service.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
static void add_addr(struct sockaddr *in, socklen_t in_len)
This method adds addresses to the DLL, that are later register at the NAT service.
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 2637 of file gnunet-communicator-tcp.c.

References add_addr(), PortOnlyIpv4Ipv6::addr_ipv4, PortOnlyIpv4Ipv6::addr_ipv6, PortOnlyIpv4Ipv6::addr_len_ipv4, PortOnlyIpv4Ipv6::addr_len_ipv6, COMMUNICATOR_CONFIG_SECTION, DEFAULT_MAX_QUEUE_LENGTH, DEFAULT_REKEY_INTERVAL, dummy, extract_address(), extract_port(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_RESOLVER_ip_get(), GNUNET_TIME_UNIT_MINUTES, init_socket(), init_socket_resolv(), max_queue_length, nat_register(), port, rekey_interval, start, tcp_address_to_sockaddr_numeric_v4(), tcp_address_to_sockaddr_numeric_v6(), and tcp_address_to_sockaddr_port_only().

Referenced by main().

2641 {
2642  char *bindto;
2643  struct sockaddr *in;
2644  socklen_t in_len;
2645  struct sockaddr_in v4;
2646  struct sockaddr_in6 v6;
2647  char *start;
2648  unsigned int port;
2649  char dummy[2];
2650  char *rest = NULL;
2651  struct PortOnlyIpv4Ipv6 *po;
2652 
2653  (void) cls;
2654  cfg = c;
2655  if (GNUNET_OK !=
2658  "BINDTO",
2659  &bindto))
2660  {
2663  "BINDTO");
2664  return;
2665  }
2666  if (GNUNET_OK !=
2669  "MAX_QUEUE_LENGTH",
2670  &max_queue_length))
2672  if (GNUNET_OK !=
2675  "REKEY_INTERVAL",
2676  &rekey_interval))
2678 
2679 
2680  // cp = GNUNET_strdup (bindto);
2681  start = extract_address (bindto);
2682 
2683  if (1 == sscanf (bindto, "%u%1s", &port, dummy))
2684  {
2685  po = tcp_address_to_sockaddr_port_only (bindto, &port);
2686 
2687  if (NULL != &po->addr_ipv4)
2688  {
2689  init_socket (po->addr_ipv4, *po->addr_len_ipv4);
2690  add_addr (po->addr_ipv4, *po->addr_len_ipv4);
2691  }
2692 
2693  if (NULL != &po->addr_ipv6)
2694  {
2695  init_socket (po->addr_ipv6, *po->addr_len_ipv6);
2696  add_addr (po->addr_ipv6, *po->addr_len_ipv6);
2697  }
2698 
2699  nat_register ();
2700  }
2701  else if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2702  {
2703  port = extract_port (bindto);
2704 
2705  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, port);
2706  init_socket (in, in_len);
2707  add_addr (in, in_len);
2708  nat_register ();
2709  }
2710  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2711  {
2712  port = extract_port (bindto);
2713  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, port);
2714  init_socket (in, in_len);
2715  add_addr (in, in_len);
2716  nat_register ();
2717  }
2718  else
2719  {
2720  port = extract_port (bindto);
2721 
2722  resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":",
2723  &rest),
2724  AF_UNSPEC,
2727  &port);
2728  }
2729  GNUNET_free (bindto);
2730 }
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static void init_socket_resolv(void *cls, const struct sockaddr *addr, socklen_t in_len)
This method is the callback called by the resolver API, and wraps method init_socket.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
static int init_socket(const struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
socklen_t * addr_len_ipv6
Length of ipv6 address.
static struct PortOnlyIpv4Ipv6 * tcp_address_to_sockaddr_port_only(const char *bindto, unsigned int *port)
Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:939
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
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 char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
#define DEFAULT_MAX_QUEUE_LENGTH
How many messages do we keep at most in the queue to the transport service before we start to drop (d...
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static void nat_register()
This method reads from the DLL addrs_head to register them at the NAT service.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
static void add_addr(struct sockaddr *in, socklen_t in_len)
This method adds addresses to the DLL, that are later register at the NAT service.
socklen_t * addr_len_ipv4
Length of ipv4 address.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_free(ptr)
Wrapper around free.
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 2741 of file gnunet-communicator-tcp.c.

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

2742 {
2743  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2745  };
2746  int ret;
2747 
2748  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2749  return 2;
2750 
2751  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
2752  argv,
2753  "gnunet-communicator-tcp",
2754  _ ("GNUnet TCP communicator"),
2755  options,
2756  &run,
2757  NULL))
2758  ? 0
2759  : 1;
2760  GNUNET_free_nz ((void *) argv);
2761  return ret;
2762 }
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

◆ max_queue_length

unsigned long long max_queue_length
static

Maximum queue length before we stop reading towards the transport service.

Definition at line 584 of file gnunet-communicator-tcp.c.

Referenced by queue_read(), and run().

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

For logging statistics.

Definition at line 589 of file gnunet-communicator-tcp.c.

◆ ch

Our environment.

Definition at line 594 of file gnunet-communicator-tcp.c.

◆ queue_map

struct GNUNET_CONTAINER_MultiPeerMap* queue_map
static

Queues (map from peer identity to struct Queue)

Definition at line 599 of file gnunet-communicator-tcp.c.

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

◆ rekey_interval

struct GNUNET_TIME_Relative rekey_interval
static

The rekey interval.

Definition at line 609 of file gnunet-communicator-tcp.c.

Referenced by run(), and setup_out_cipher().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey* my_private_key
static

Our private key.

Definition at line 614 of file gnunet-communicator-tcp.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 619 of file gnunet-communicator-tcp.c.

◆ is

struct GNUNET_NT_InterfaceScanner* is
static

◆ nat

struct GNUNET_NAT_Handle* nat
static

Connection to NAT service.

Definition at line 629 of file gnunet-communicator-tcp.c.

◆ proto_head

struct ProtoQueue* proto_head
static

Protoqueues DLL head.

Definition at line 634 of file gnunet-communicator-tcp.c.

◆ proto_tail

struct ProtoQueue* proto_tail
static

Protoqueues DLL tail.

Definition at line 639 of file gnunet-communicator-tcp.c.

◆ resolve_request_handle

struct GNUNET_RESOLVER_RequestHandle* resolve_request_handle

Handle for DNS lookup of bindto address.

Definition at line 644 of file gnunet-communicator-tcp.c.

◆ addrs_head

struct Addresses* addrs_head

Head of DLL with addresses we like to register at NAT servcie.

Definition at line 649 of file gnunet-communicator-tcp.c.

◆ addrs_tail

struct Addresses* addrs_tail

Head of DLL with addresses we like to register at NAT servcie.

Definition at line 654 of file gnunet-communicator-tcp.c.

◆ addrs_lens

int addrs_lens

Number of addresses in the DLL for register at NAT service.

Definition at line 659 of file gnunet-communicator-tcp.c.

Referenced by add_addr(), and nat_register().