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

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 (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 void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Setup communicator and launch network interactions. More...
 
int main (int argc, char *const *argv)
 The main function for the UNIX communicator. More...
 

Variables

static struct GNUNET_SCHEDULER_Tasklisten_task
 ID of listen task. More...
 
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_NETWORK_Handlelisten_sock
 Listen socket. 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...
 

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 49 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 60 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 66 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 71 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 76 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 82 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 88 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 96 of file gnunet-communicator-tcp.c.

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

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-tcp"

Configuration section used by the communicator.

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

Referenced by run(), and tcp_address_to_sockaddr().

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

Definition at line 1769 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, PROTO_QUEUE_TIMEOUT, proto_read_kx(), ProtoQueue::read_task, ProtoQueue::sock, and ProtoQueue::timeout.

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

1770 {
1771  struct sockaddr_storage in;
1772  socklen_t addrlen;
1773  struct GNUNET_NETWORK_Handle *sock;
1774  struct ProtoQueue *pq;
1775 
1776  listen_task = NULL;
1777  GNUNET_assert (NULL != listen_sock);
1778  addrlen = sizeof(in);
1779  memset (&in, 0, sizeof(in));
1781  (struct sockaddr*) &in,
1782  &addrlen);
1783  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
1784  return; /* system limit reached, wait until connection goes down */
1786  listen_sock,
1787  &listen_cb,
1788  NULL);
1789  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
1790  return;
1791  if (NULL == sock)
1792  {
1794  return;
1795  }
1796  pq = GNUNET_new (struct ProtoQueue);
1797  pq->address_len = addrlen;
1798  pq->address = GNUNET_memdup (&in, addrlen);
1800  pq->sock = sock;
1802  pq->sock,
1803  &proto_read_kx,
1804  pq);
1806 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
#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
static struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
#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.
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.
static struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
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:1486
static struct ProtoQueue * proto_head
Protoqueues DLL head.
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 579 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_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(), 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().

580 {
581  struct GNUNET_MQ_Handle *mq;
582 
584  "Disconnecting queue for peer `%s'\n",
585  GNUNET_i2s (&queue->target));
586  if (NULL != (mq = queue->mq))
587  {
588  queue->mq = NULL;
589  GNUNET_MQ_destroy (mq);
590  }
591  if (NULL != queue->qh)
592  {
594  queue->qh = NULL;
595  }
596  GNUNET_assert (
597  GNUNET_YES ==
600  "# queues active",
602  GNUNET_NO);
603  if (NULL != queue->read_task)
604  {
606  queue->read_task = NULL;
607  }
608  if (NULL != queue->write_task)
609  {
611  queue->write_task = NULL;
612  }
614  gcry_cipher_close (queue->in_cipher);
615  gcry_cipher_close (queue->out_cipher);
616  GNUNET_free (queue->address);
617  if (0 != queue->backpressure)
618  queue->destroyed = GNUNET_YES;
619  else
620  GNUNET_free (queue);
621  if (NULL == listen_task)
623  listen_sock,
624  &listen_cb,
625  NULL);
626 }
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.
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...
static struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
#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_NO
Definition: gnunet_common.h:86
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.
static struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
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:824
#define GNUNET_YES
Definition: gnunet_common.h:85
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:1486
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
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
#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:966
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 638 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().

642 {
643  struct GNUNET_HashCode mac;
644 
645  GNUNET_CRYPTO_hmac_raw (hmac_secret,
646  sizeof(struct GNUNET_HashCode),
647  buf,
648  buf_size,
649  &mac);
650  /* truncate to `struct GNUNET_ShortHashCode` */
651  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
652  /* ratchet hmac key */
653  GNUNET_CRYPTO_hash (hmac_secret,
654  sizeof(struct GNUNET_HashCode),
655  hmac_secret);
656 }
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:403
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 666 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().

667 {
668  struct TCPFinish fin;
669 
670  memset (&fin, 0, sizeof(fin));
671  fin.header.size = htons (sizeof(fin));
672  fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
673  calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
674  /* if there is any message left in pwrite_buf, we
675  overwrite it (possibly dropping the last message
676  from CORE hard here) */
677  memcpy (queue->pwrite_buf, &fin, sizeof(fin));
678  queue->pwrite_off = sizeof(fin);
679  /* This flag will ensure that #queue_write() no longer
680  notifies CORE about the possibility of sending
681  more data, and that #queue_write() will call
682  #queue_destroy() once the @c fin was fully written. */
683  queue->finishing = GNUNET_YES;
684 }
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...
#define GNUNET_YES
Definition: gnunet_common.h:85
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 695 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().

696 {
697  queue->timeout =
699 }
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 998 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().

999 {
1000  struct Queue *queue = cls;
1001  struct GNUNET_TIME_Relative left;
1002  ssize_t rcvd;
1003 
1004  queue->read_task = NULL;
1005  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1006  &queue->cread_buf[queue->cread_off],
1007  BUF_SIZE - queue->cread_off);
1009  "Received %lu bytes from TCP queue\n", rcvd);
1010  if (-1 == rcvd)
1011  {
1012  if ((EAGAIN != errno) && (EINTR != errno))
1013  {
1015  queue_finish (queue);
1016  return;
1017  }
1018  /* try again */
1020  queue->read_task =
1021  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1022  return;
1023  }
1024  if (0 != rcvd)
1025  reschedule_queue_timeout (queue);
1026  queue->cread_off += rcvd;
1027  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1028  (queue->cread_off > 0))
1029  {
1030  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1031  queue->cread_off);
1032  size_t done;
1033  size_t total;
1034  size_t old_pread_off = queue->pread_off;
1035 
1036  GNUNET_assert (0 ==
1037  gcry_cipher_decrypt (queue->in_cipher,
1038  &queue->pread_buf[queue->pread_off],
1039  max,
1040  queue->cread_buf,
1041  max));
1042  queue->pread_off += max;
1043  total = 0;
1044  while (0 != (done = try_handle_plaintext (queue)))
1045  {
1046  /* 'done' bytes of plaintext were used, shift buffer */
1047  GNUNET_assert (done <= queue->pread_off);
1048  /* NOTE: this memmove() could possibly sometimes be
1049  avoided if we pass 'total' into try_handle_plaintext()
1050  and use it at an offset into the buffer there! */
1051  memmove (queue->pread_buf,
1052  &queue->pread_buf[done],
1053  queue->pread_off - done);
1054  queue->pread_off -= done;
1055  total += done;
1056  /* The last plaintext was a rekey, abort for now */
1057  if (GNUNET_YES == queue->rekeyed)
1058  break;
1059  }
1060  /* when we encounter a rekey message, the decryption above uses the
1061  wrong key for everything after the rekey; in that case, we have
1062  to re-do the decryption at 'total' instead of at 'max'.
1063  However, we have to take into account that the plaintext buffer may have
1064  already contained data and not jumpt too far ahead in the ciphertext.
1065  If there is no rekey and the last message is incomplete (max > total),
1066  it is safe to keep the decryption so we shift by 'max' */
1067  if (GNUNET_YES == queue->rekeyed)
1068  {
1069  max = total - old_pread_off;
1070  queue->rekeyed = GNUNET_NO;
1071  queue->pread_off = 0;
1072  }
1073  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1074  queue->cread_off -= max;
1075  }
1076  if (BUF_SIZE == queue->cread_off)
1077  return; /* buffer full, suspend reading */
1079  if (0 != left.rel_value_us)
1080  {
1081  if (max_queue_length > queue->backpressure)
1082  {
1083  /* continue reading */
1085  queue->read_task =
1086  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1087  }
1088  return;
1089  }
1091  "Queue %p was idle for %s, disconnecting\n",
1092  queue,
1095  GNUNET_YES));
1096  queue_finish (queue);
1097 }
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.
#define GNUNET_NO
Definition: gnunet_common.h:86
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:88
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:687
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.
#define GNUNET_YES
Definition: gnunet_common.h:85
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:1486
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 719 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().

720 {
721  struct Queue *queue = cls;
722  if (GNUNET_OK != success)
724  "# messages lost in communicator API towards CORE",
725  1,
726  GNUNET_NO);
727  queue->backpressure--;
728  /* handle deferred queue destruction */
729  if ((queue->destroyed) && (0 == queue->backpressure))
730  {
731  GNUNET_free (queue);
732  return;
733  }
734  reschedule_queue_timeout (queue);
735  /* possibly unchoke reading, now that CORE made progress */
736  if (NULL == queue->read_task)
737  queue->read_task =
739  queue->timeout),
740  queue->sock,
741  &queue_read,
742  queue);
743 }
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...
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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:1486
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 756 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().

759 {
760  const struct GNUNET_MessageHeader *hdr = plaintext;
761  int ret;
762 
763  if (ntohs (hdr->size) != plaintext_len)
764  {
765  /* NOTE: If we ever allow multiple CORE messages in one
766  BOX, this will have to change! */
767  GNUNET_break (0);
768  return;
769  }
771  &queue->target,
772  hdr,
775  queue);
776  if (GNUNET_OK == ret)
777  queue->backpressure++;
778  GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
779  if (GNUNET_SYSERR == ret)
781  "# bytes lost due to CORE not running",
782  plaintext_len,
783  GNUNET_NO);
784 }
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
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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...
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 797 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().

801 {
802  char key[256 / 8];
803  char ctr[128 / 8];
804 
805  gcry_cipher_open (cipher,
806  GCRY_CIPHER_AES256 /* low level: go for speed */,
807  GCRY_CIPHER_MODE_CTR,
808  0 /* flags */);
810  sizeof(key),
811  "TCP-key",
812  strlen ("TCP-key"),
813  dh,
814  sizeof(*dh),
815  pid,
816  sizeof(*pid),
817  NULL,
818  0));
819  gcry_cipher_setkey (*cipher, key, sizeof(key));
821  sizeof(ctr),
822  "TCP-ctr",
823  strlen ("TCP-ctr"),
824  dh,
825  sizeof(*dh),
826  pid,
827  sizeof(*pid),
828  NULL,
829  0));
830  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
832  GNUNET_CRYPTO_kdf (hmac_key,
833  sizeof(struct GNUNET_HashCode),
834  "TCP-hmac",
835  strlen ("TCP-hmac"),
836  dh,
837  sizeof(*dh),
838  pid,
839  sizeof(*pid),
840  NULL,
841  0));
842 }
#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.
#define GNUNET_YES
Definition: gnunet_common.h:85
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 852 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().

854 {
855  struct GNUNET_HashCode dh;
856 
857  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
858  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
859 }
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:1040
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 871 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().

872 {
873  struct TcpHandshakeSignature thp;
875  thp.purpose.size = htonl (sizeof(thp));
876  thp.sender = queue->target;
877  thp.receiver = my_identity;
878  thp.ephemeral = rekey->ephemeral;
879  thp.monotonic_time = rekey->monotonic_time;
880  /* FIXME: check monotonic time is monotonic... */
881  if (GNUNET_OK !=
883  &thp.purpose,
884  &rekey->sender_sig,
885  &queue->target.public_key))
886  {
887  GNUNET_break (0);
888  queue_finish (queue);
889  return;
890  }
891  gcry_cipher_close (queue->in_cipher);
892  queue->rekeyed = GNUNET_YES;
893  setup_in_cipher (&rekey->ephemeral, queue);
894 }
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_OK
Named constants for return values.
Definition: gnunet_common.h:83
#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...
int GNUNET_CRYPTO_eddsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:844
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.
#define GNUNET_YES
Definition: gnunet_common.h:85
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 905 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().

906 {
907  const struct GNUNET_MessageHeader *hdr =
908  (const struct GNUNET_MessageHeader *) queue->pread_buf;
909  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
910  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
911  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
912  struct TCPRekey rekeyz;
913  struct TCPFinish finz;
914  struct GNUNET_ShortHashCode tmac;
915  uint16_t type;
916  size_t size = 0; /* make compiler happy */
917 
918  if (sizeof(*hdr) > queue->pread_off)
919  return 0; /* not even a header */
920  type = ntohs (hdr->type);
921  switch (type)
922  {
924  /* Special case: header size excludes box itself! */
925  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
926  return 0;
927  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
928  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
929  {
930  GNUNET_break_op (0);
931  queue_finish (queue);
932  return 0;
933  }
934  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
935  size = ntohs (hdr->size) + sizeof(*box);
936  break;
937 
939  if (sizeof(*rekey) > queue->pread_off)
940  return 0;
941  if (ntohs (hdr->size) != sizeof(*rekey))
942  {
943  GNUNET_break_op (0);
944  queue_finish (queue);
945  return 0;
946  }
947  rekeyz = *rekey;
948  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
949  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
950  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
951  {
952  GNUNET_break_op (0);
953  queue_finish (queue);
954  return 0;
955  }
956  do_rekey (queue, rekey);
957  size = ntohs (hdr->size);
958  break;
959 
961  if (sizeof(*fin) > queue->pread_off)
962  return 0;
963  if (ntohs (hdr->size) != sizeof(*fin))
964  {
965  GNUNET_break_op (0);
966  queue_finish (queue);
967  return 0;
968  }
969  finz = *fin;
970  memset (&finz.hmac, 0, sizeof(finz.hmac));
971  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
972  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
973  {
974  GNUNET_break_op (0);
975  queue_finish (queue);
976  return 0;
977  }
978  /* handle FINISH by destroying queue */
979  queue_destroy (queue);
980  break;
981 
982  default:
983  GNUNET_break_op (0);
984  queue_finish (queue);
985  return 0;
986  }
987  GNUNET_assert (0 != size);
988  return size;
989 }
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()

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

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

Referenced by mq_init(), and run().

1109 {
1110  struct sockaddr *in;
1111  unsigned int port;
1112  char dummy[2];
1113  char *colon;
1114  char *cp;
1115 
1116  if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1117  {
1118  /* interpreting value as just a PORT number */
1119  if (port > UINT16_MAX)
1120  {
1122  "BINDTO specification `%s' invalid: value too large for port\n",
1123  bindto);
1124  return NULL;
1125  }
1126  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1127  (GNUNET_YES ==
1130  "DISABLE_V6")))
1131  {
1132  struct sockaddr_in *i4;
1133 
1134  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1135  i4->sin_family = AF_INET;
1136  i4->sin_port = htons ((uint16_t) port);
1137 #if HAVE_SOCKADDR_IN_SIN_LEN
1138  i4->sin_len = sizeof(sizeof(struct sockaddr_in));
1139 #endif
1140  *sock_len = sizeof(struct sockaddr_in);
1141  in = (struct sockaddr *) i4;
1142  }
1143  else
1144  {
1145  struct sockaddr_in6 *i6;
1146 
1147  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1148  i6->sin6_family = AF_INET6;
1149  i6->sin6_port = htons ((uint16_t) port);
1150 #if HAVE_SOCKADDR_IN_SIN_LEN
1151  i6->sin6_len = sizeof(sizeof(struct sockaddr_in6));
1152 #endif
1153  *sock_len = sizeof(struct sockaddr_in6);
1154  in = (struct sockaddr *) i6;
1155  }
1156  return in;
1157  }
1158  cp = GNUNET_strdup (bindto);
1159  colon = strrchr (cp, ':');
1160  if (NULL != colon)
1161  {
1162  /* interpet value after colon as port */
1163  *colon = '\0';
1164  colon++;
1165  if (1 == sscanf (colon, "%u%1s", &port, dummy))
1166  {
1167  /* interpreting value as just a PORT number */
1168  if (port > UINT16_MAX)
1169  {
1171  "BINDTO specification `%s' invalid: value too large for port\n",
1172  bindto);
1173  GNUNET_free (cp);
1174  return NULL;
1175  }
1176  }
1177  else
1178  {
1179  GNUNET_log (
1181  "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1182  bindto);
1183  GNUNET_free (cp);
1184  return NULL;
1185  }
1186  }
1187  else
1188  {
1189  /* interpret missing port as 0, aka pick any free one */
1190  port = 0;
1191  }
1192  {
1193  /* try IPv4 */
1194  struct sockaddr_in v4;
1195 
1196  if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
1197  {
1198  v4.sin_family = AF_INET;
1199  v4.sin_port = htons ((uint16_t) port);
1200 #if HAVE_SOCKADDR_IN_SIN_LEN
1201  v4.sin_len = sizeof(struct sockaddr_in);
1202 #endif
1203  in = GNUNET_memdup (&v4, sizeof(v4));
1204  *sock_len = sizeof(v4);
1205  GNUNET_free (cp);
1206  return in;
1207  }
1208  }
1209  {
1210  /* try IPv6 */
1211  struct sockaddr_in6 v6;
1212  const char *start;
1213 
1214  start = cp;
1215  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1216  {
1217  start++; /* skip over '[' */
1218  cp[strlen (cp) - 1] = '\0'; /* eat ']' */
1219  }
1220  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
1221  {
1222  v6.sin6_family = AF_INET6;
1223  v6.sin6_port = htons ((uint16_t) port);
1224 #if HAVE_SOCKADDR_IN_SIN_LEN
1225  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
1226 #endif
1227  in = GNUNET_memdup (&v6, sizeof(v6));
1228  *sock_len = sizeof(v6);
1229  GNUNET_free (cp);
1230  return in;
1231  }
1232  }
1233  /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1234  GNUNET_free (cp);
1235  return NULL;
1236 }
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:85
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 1246 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().

1247 {
1248  struct GNUNET_HashCode dh;
1249 
1250  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
1251  /* we don't need the private key anymore, drop it! */
1252  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
1253  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1255  queue->rekey_left_bytes =
1257 }
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:1101
#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 1267 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_create2(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_sign(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, GNUNET_OK, GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TCPRekey::header, TCPRekey::hmac, TcpHandshakeSignature::monotonic_time, TCPRekey::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().

1268 {
1269  struct TCPRekey rekey;
1270  struct TcpHandshakeSignature thp;
1271 
1272  GNUNET_assert (0 == queue->pwrite_off);
1273  memset (&rekey, 0, sizeof(rekey));
1276  rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1277  rekey.header.size = ntohs (sizeof(rekey));
1278  GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
1279  rekey.monotonic_time =
1281  thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1282  thp.purpose.size = htonl (sizeof(thp));
1283  thp.sender = my_identity;
1284  thp.receiver = queue->target;
1285  thp.ephemeral = rekey.ephemeral;
1286  thp.monotonic_time = rekey.monotonic_time;
1288  &thp.purpose,
1289  &rekey.sender_sig));
1290  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1291  /* Encrypt rekey message with 'old' cipher */
1292  GNUNET_assert (0 ==
1293  gcry_cipher_encrypt (queue->out_cipher,
1294  &queue->cwrite_buf[queue->cwrite_off],
1295  sizeof(rekey),
1296  &rekey,
1297  sizeof(rekey)));
1298  queue->cwrite_off += sizeof(rekey);
1299  /* Setup new cipher for successive messages */
1300  gcry_cipher_close (queue->out_cipher);
1301  setup_out_cipher (queue);
1302 }
int GNUNET_CRYPTO_ecdhe_key_create2(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:521
struct GNUNET_PeerIdentity target
To whom are we talking to.
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.
int GNUNET_CRYPTO_eddsa_sign(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:745
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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.
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:206
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 1312 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().

1313 {
1314  struct Queue *queue = cls;
1315  ssize_t sent;
1316  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1317  queue->write_task = NULL;
1318  if (0 != queue->cwrite_off)
1319  {
1320  sent = GNUNET_NETWORK_socket_send (queue->sock,
1321  queue->cwrite_buf,
1322  queue->cwrite_off);
1324  "Sent %lu bytes to TCP queue\n", sent);
1325  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1326  {
1328  queue_destroy (queue);
1329  return;
1330  }
1331  if (sent > 0)
1332  {
1333  size_t usent = (size_t) sent;
1334  queue->cwrite_off -= usent;
1335  memmove (queue->cwrite_buf,
1336  &queue->cwrite_buf[usent],
1337  queue->cwrite_off);
1338  reschedule_queue_timeout (queue);
1339  }
1340  }
1341  /* can we encrypt more? (always encrypt full messages, needed
1342  such that #mq_cancel() can work!) */
1343  if ((0 < queue->rekey_left_bytes) &&
1344  (queue->pwrite_off > 0) &&
1345  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1346  {
1348  "Encrypting %lu bytes\n", queue->pwrite_off);
1349  GNUNET_assert (0 ==
1350  gcry_cipher_encrypt (queue->out_cipher,
1351  &queue->cwrite_buf[queue->cwrite_off],
1352  queue->pwrite_off,
1353  queue->pwrite_buf,
1354  queue->pwrite_off));
1355  if (queue->rekey_left_bytes > queue->pwrite_off)
1356  queue->rekey_left_bytes -= queue->pwrite_off;
1357  else
1358  queue->rekey_left_bytes = 0;
1359  queue->cwrite_off += queue->pwrite_off;
1360  queue->pwrite_off = 0;
1361  }
1362  if ((0 == queue->pwrite_off) &&
1363  ((0 == queue->rekey_left_bytes) ||
1364  (0 ==
1366  {
1367  inject_rekey (queue);
1368  }
1369  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1370  (GNUNET_YES == queue->mq_awaits_continue))
1371  {
1372  queue->mq_awaits_continue = GNUNET_NO;
1374  }
1375  /* did we just finish writing 'finish'? */
1376  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1377  {
1379  "Finishing queue\n");
1380  queue_destroy (queue);
1381  return;
1382  }
1383  /* do we care to write more? */
1384  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1385  queue->write_task =
1387  queue->sock,
1388  &queue_write,
1389  queue);
1390 }
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:1557
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
#define GNUNET_NO
Definition: gnunet_common.h:86
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
#define GNUNET_YES
Definition: gnunet_common.h:85
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:486
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 1402 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().

1405 {
1406  struct Queue *queue = impl_state;
1407  uint16_t msize = ntohs (msg->size);
1408  struct TCPBox box;
1410  "In MQ send. Queue finishing: %s; write task running: %s\n",
1411  (GNUNET_YES == queue->finishing) ? "yes" : "no",
1412  (NULL == queue->write_task) ? "yes" : "no");
1413  GNUNET_assert (mq == queue->mq);
1414  queue->mq_awaits_continue = GNUNET_YES;
1415  if (GNUNET_YES == queue->finishing)
1416  return; /* this queue is dying, drop msg */
1417  GNUNET_assert (0 == queue->pwrite_off);
1418  box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
1419  box.header.size = htons (msize);
1420  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
1421  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
1422  queue->pwrite_off += sizeof(box);
1423  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
1424  queue->pwrite_off += msize;
1426  "%lu bytes of plaintext to send\n", queue->pwrite_off);
1427  GNUNET_assert (NULL != queue->sock);
1428  if (NULL == queue->write_task)
1429  queue->write_task =
1431  queue->sock,
1432  &queue_write,
1433  queue);
1434 }
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:1557
#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,...)
#define GNUNET_YES
Definition: gnunet_common.h:85
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 1446 of file gnunet-communicator-tcp.c.

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

Referenced by boot_queue().

1447 {
1448  struct Queue *queue = impl_state;
1449 
1450  if (mq == queue->mq)
1451  {
1452  queue->mq = NULL;
1453  queue_finish (queue);
1454  }
1455 }
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 1465 of file gnunet-communicator-tcp.c.

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

Referenced by boot_queue().

1466 {
1467  struct Queue *queue = impl_state;
1468 
1469  GNUNET_assert (0 != queue->pwrite_off);
1470  queue->pwrite_off = 0;
1471 }
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 1484 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().

1485 {
1486  struct Queue *queue = cls;
1487 
1489  "MQ error in queue to %s: %d\n",
1490  GNUNET_i2s (&queue->target),
1491  (int) error);
1492  queue_finish (queue);
1493 }
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 1504 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(), 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().

1505 {
1506  queue->nt =
1509  queue_map,
1510  &queue->target,
1511  queue,
1514  "# queues active",
1516  GNUNET_NO);
1517  queue->timeout =
1520  &mq_destroy,
1521  &mq_cancel,
1522  queue,
1523  NULL,
1524  &mq_error,
1525  queue);
1526  {
1527  char *foreign_addr;
1528 
1529  switch (queue->address->sa_family)
1530  {
1531  case AF_INET:
1532  GNUNET_asprintf (&foreign_addr,
1533  "%s-%s",
1535  GNUNET_a2s (queue->address, queue->address_len));
1536  break;
1537 
1538  case AF_INET6:
1539  GNUNET_asprintf (&foreign_addr,
1540  "%s-%s",
1542  GNUNET_a2s (queue->address, queue->address_len));
1543  break;
1544 
1545  default:
1546  GNUNET_assert (0);
1547  }
1549  &queue->target,
1550  foreign_addr,
1551  0 /* no MTU */,
1552  queue->nt,
1553  cs,
1554  queue->mq);
1555  GNUNET_free (foreign_addr);
1556  }
1557 }
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.
#define GNUNET_NO
Definition: gnunet_common.h:86
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:552
#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. ...
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.
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...
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, 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...
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 1571 of file gnunet-communicator-tcp.c.

References Queue::cwrite_buf, Queue::cwrite_off, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign(), GNUNET_OK, 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().

1573 {
1574  struct TcpHandshakeSignature ths;
1575  struct TCPConfirmation tc;
1576 
1577  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
1578  queue->cwrite_off = sizeof(*epub);
1579  /* compute 'tc' and append in encrypted format to cwrite_buf */
1580  tc.sender = my_identity;
1581  tc.monotonic_time =
1583  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1584  ths.purpose.size = htonl (sizeof(ths));
1585  ths.sender = my_identity;
1586  ths.receiver = queue->target;
1587  ths.ephemeral = *epub;
1588  ths.monotonic_time = tc.monotonic_time;
1590  &ths.purpose,
1591  &tc.sender_sig));
1592  GNUNET_assert (0 ==
1593  gcry_cipher_encrypt (queue->out_cipher,
1594  &queue->cwrite_buf[queue->cwrite_off],
1595  sizeof(tc),
1596  &tc,
1597  sizeof(tc)));
1598  queue->cwrite_off += sizeof(tc);
1599 }
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake,.
struct GNUNET_PeerIdentity target
To whom are we talking to.
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:418
int GNUNET_CRYPTO_eddsa_sign(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:745
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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 1610 of file gnunet-communicator-tcp.c.

References Queue::ephemeral, GNUNET_assert, GNUNET_CRYPTO_ecdhe_key_create2(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_OK, setup_out_cipher(), and transmit_kx().

Referenced by mq_init(), and proto_read_kx().

1611 {
1612  struct GNUNET_CRYPTO_EcdhePublicKey epub;
1613 
1617  setup_out_cipher (queue);
1618  transmit_kx (queue, &epub);
1619 }
int GNUNET_CRYPTO_ecdhe_key_create2(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:521
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
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:206
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 1634 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().

1637 {
1638  struct TcpHandshakeSignature ths;
1639 
1640  GNUNET_assert (
1641  0 ==
1642  gcry_cipher_decrypt (queue->in_cipher,
1643  tc,
1644  sizeof(*tc),
1645  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
1646  sizeof(*tc)));
1647  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1648  ths.purpose.size = htonl (sizeof(ths));
1649  ths.sender = tc->sender;
1650  ths.receiver = my_identity;
1651  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
1652  ths.monotonic_time = tc->monotonic_time;
1653  /* FIXME: check monotonic time against previous mono times
1654  from this sender! */
1657  &ths.purpose,
1658  &tc->sender_sig,
1659  &tc->sender.public_key);
1660 }
#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.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
int GNUNET_CRYPTO_eddsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:844
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 call graph for this function:
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 1669 of file gnunet-communicator-tcp.c.

References ProtoQueue::address, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NETWORK_socket_close(), and ProtoQueue::sock.

Referenced by do_shutdown(), and proto_read_kx().

1670 {
1672  GNUNET_free (pq->address);
1674  GNUNET_free (pq);
1675 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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.
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.
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 1685 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(), 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().

1686 {
1687  struct ProtoQueue *pq = cls;
1688  ssize_t rcvd;
1689  struct GNUNET_TIME_Relative left;
1690  struct Queue *queue;
1691  struct TCPConfirmation tc;
1692 
1693  pq->read_task = NULL;
1695  if (0 == left.rel_value_us)
1696  {
1697  free_proto_queue (pq);
1698  return;
1699  }
1700  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
1701  &pq->ibuf[pq->ibuf_off],
1702  sizeof(pq->ibuf) - pq->ibuf_off);
1704  "Received %lu bytes for KX\n", rcvd);
1705  if (-1 == rcvd)
1706  {
1707  if ((EAGAIN != errno) && (EINTR != errno))
1708  {
1710  free_proto_queue (pq);
1711  return;
1712  }
1713  /* try again */
1714  pq->read_task =
1716  return;
1717  }
1718  pq->ibuf_off += rcvd;
1719  if (pq->ibuf_off > sizeof(pq->ibuf))
1720  {
1721  /* read more */
1722  pq->read_task =
1724  return;
1725  }
1726  /* we got all the data, let's find out who we are talking to! */
1727  queue = GNUNET_new (struct Queue);
1728  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
1729  queue);
1730  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
1731  {
1733  "Invalid TCP KX received from %s\n",
1734  GNUNET_a2s (queue->address, queue->address_len));
1735  gcry_cipher_close (queue->in_cipher);
1736  GNUNET_free (queue);
1737  free_proto_queue (pq);
1738  return;
1739  }
1740  queue->address = pq->address; /* steals reference */
1741  queue->address_len = pq->address_len;
1742  queue->target = tc.sender;
1743  queue->sock = pq->sock;
1744  start_initial_kx_out (queue);
1746  queue->read_task =
1748  queue->sock,
1749  &queue_read,
1750  queue);
1751  queue->write_task =
1753  queue->sock,
1754  &queue_write,
1755  queue);
1757  GNUNET_free (pq);
1758 }
#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:418
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:1557
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#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_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
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:1486
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 1817 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().

1818 {
1819  struct Queue *queue = cls;
1820  ssize_t rcvd;
1821  struct GNUNET_TIME_Relative left;
1822  struct TCPConfirmation tc;
1823 
1824  queue->read_task = NULL;
1826  if (0 == left.rel_value_us)
1827  {
1828  queue_destroy (queue);
1829  return;
1830  }
1831  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1832  &queue->cread_buf[queue->cread_off],
1833  BUF_SIZE - queue->cread_off);
1834  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %lu bytes for KX\n", rcvd);
1835  if (-1 == rcvd)
1836  {
1837  if ((EAGAIN != errno) && (EINTR != errno))
1838  {
1840  queue_destroy (queue);
1841  return;
1842  }
1843  queue->read_task =
1844  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
1845  return;
1846  }
1847  queue->cread_off += rcvd;
1848  if (queue->cread_off < INITIAL_KX_SIZE)
1849  {
1850  /* read more */
1851  queue->read_task =
1852  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
1853  return;
1854  }
1855  /* we got all the data, let's find out who we are talking to! */
1857  queue->cread_buf,
1858  queue);
1859  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
1860  {
1862  "Invalid TCP KX received from %s\n",
1863  GNUNET_a2s (queue->address, queue->address_len));
1864  queue_destroy (queue);
1865  return;
1866  }
1867  if (0 !=
1868  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
1869  {
1871  "Invalid sender in TCP KX received from %s\n",
1872  GNUNET_a2s (queue->address, queue->address_len));
1873  queue_destroy (queue);
1874  return;
1875  }
1876 
1877  /* update queue timeout */
1878  reschedule_queue_timeout (queue);
1879  /* prepare to continue with regular read task immediately */
1880  memmove (queue->cread_buf,
1881  &queue->cread_buf[INITIAL_KX_SIZE],
1882  queue->cread_off - (INITIAL_KX_SIZE));
1883  queue->cread_off -= INITIAL_KX_SIZE;
1884  if (0 < queue->cread_off)
1885  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
1886 }
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:418
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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:1280
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:1486
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 1908 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_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 run().

1909 {
1910  struct Queue *queue;
1911  const char *path;
1912  struct sockaddr *in;
1913  socklen_t in_len;
1914  struct GNUNET_NETWORK_Handle *sock;
1915 
1917  "Connecting to %s\n", address);
1918  if (0 != strncmp (address,
1920  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
1921  {
1922  GNUNET_break_op (0);
1923  return GNUNET_SYSERR;
1924  }
1925  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
1926  in = tcp_address_to_sockaddr (path, &in_len);
1927 
1928  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
1929  if (NULL == sock)
1930  {
1932  "socket(%d) failed: %s",
1933  in->sa_family,
1934  strerror (errno));
1935  GNUNET_free (in);
1936  return GNUNET_SYSERR;
1937  }
1938  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
1939  (errno != EINPROGRESS))
1940  {
1942  "connect to `%s' failed: %s",
1943  address,
1944  strerror (errno));
1946  GNUNET_free (in);
1947  return GNUNET_SYSERR;
1948  }
1949 
1950  queue = GNUNET_new (struct Queue);
1951  queue->target = *peer;
1952  queue->address = in;
1953  queue->address_len = in_len;
1954  queue->sock = sock;
1956  //queue->mq_awaits_continue = GNUNET_YES;
1957  queue->read_task =
1959  queue->sock,
1960  &queue_read_kx,
1961  queue);
1962  start_initial_kx_out (queue);
1963  queue->write_task =
1965  queue->sock,
1966  &queue_write,
1967  queue);
1968  return GNUNET_OK;
1969 }
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:1557
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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:1486
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 1981 of file gnunet-communicator-tcp.c.

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

Referenced by do_shutdown().

1984 {
1985  struct Queue *queue = value;
1986 
1987  (void) cls;
1988  (void) target;
1989  queue_destroy (queue);
1990  return GNUNET_OK;
1991 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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 2000 of file gnunet-communicator-tcp.c.

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

Referenced by run().

2001 {
2002  while (NULL != proto_head)
2004  if (NULL != nat)
2005  {
2007  nat = NULL;
2008  }
2009  if (NULL != listen_task)
2010  {
2012  listen_task = NULL;
2013  }
2014  if (NULL != listen_sock)
2015  {
2017  listen_sock = NULL;
2018  }
2021  if (NULL != ch)
2022  {
2024  ch = NULL;
2025  }
2026  if (NULL != stats)
2027  {
2029  stats = NULL;
2030  }
2031  if (NULL != my_private_key)
2032  {
2034  my_private_key = NULL;
2035  }
2036  if (NULL != is)
2037  {
2039  is = NULL;
2040  }
2041 }
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
static struct GNUNET_CONTAINER_MultiPeerMap * 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.
static struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
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.
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:966
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 2056 of file gnunet-communicator-tcp.c.

References GNUNET_break_op.

Referenced by run().

2059 {
2060  (void) cls;
2061  (void) sender;
2062  (void) msg;
2063  GNUNET_break_op (0);
2064 }
#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 2081 of file gnunet-communicator-tcp.c.

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

Referenced by run().

2087 {
2088  char *my_addr;
2090 
2091  if (GNUNET_YES == add_remove)
2092  {
2093  enum GNUNET_NetworkType nt;
2094 
2095  GNUNET_asprintf (&my_addr,
2096  "%s-%s",
2098  GNUNET_a2s (addr, addrlen));
2099  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2100  ai =
2102  my_addr,
2103  nt,
2105  GNUNET_free (my_addr);
2106  *app_ctx = ai;
2107  }
2108  else
2109  {
2110  ai = *app_ctx;
2112  *app_ctx = NULL;
2113  }
2114 }
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_YES
Definition: gnunet_common.h:85
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:

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

References _, COMMUNICATOR_ADDRESS_PREFIX, COMMUNICATOR_CONFIG_SECTION, DEFAULT_MAX_QUEUE_LENGTH, DEFAULT_REKEY_INTERVAL, do_shutdown(), enc_notify_cb(), GNUNET_a2s(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_time(), 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_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror, GNUNET_log_strerror_file, GNUNET_NAT_register(), GNUNET_NETWORK_get_fd(), GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_listen(), GNUNET_NO, GNUNET_NT_scanner_init(), GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CC_RELIABLE, GNUNET_TRANSPORT_communicator_connect(), listen_cb(), max_queue_length, mq_init(), my_identity, nat_address_cb(), GNUNET_PeerIdentity::public_key, rekey_interval, and tcp_address_to_sockaddr().

Referenced by main().

2130 {
2131  char *bindto;
2132  struct sockaddr *in;
2133  socklen_t in_len;
2134  struct sockaddr_storage in_sto;
2135  socklen_t sto_len;
2136 
2137  (void) cls;
2138  cfg = c;
2139  if (GNUNET_OK !=
2142  "BINDTO",
2143  &bindto))
2144  {
2147  "BINDTO");
2148  return;
2149  }
2150  if (GNUNET_OK !=
2153  "MAX_QUEUE_LENGTH",
2154  &max_queue_length))
2156  if (GNUNET_OK !=
2159  "REKEY_INTERVAL",
2160  &rekey_interval))
2162 
2163  in = tcp_address_to_sockaddr (bindto, &in_len);
2164  if (NULL == in)
2165  {
2167  "Failed to setup TCP socket address with path `%s'\n",
2168  bindto);
2169  GNUNET_free (bindto);
2170  return;
2171  }
2172  listen_sock =
2173  GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2174  if (NULL == listen_sock)
2175  {
2177  GNUNET_free (in);
2178  GNUNET_free (bindto);
2179  return;
2180  }
2181  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len))
2182  {
2185  listen_sock = NULL;
2186  GNUNET_free (in);
2187  GNUNET_free (bindto);
2188  return;
2189  }
2190  if (GNUNET_OK !=
2192  5))
2193  {
2195  "listen");
2197  listen_sock = NULL;
2198  GNUNET_free (in);
2199  GNUNET_free (bindto);
2200  }
2201  /* We might have bound to port 0, allowing the OS to figure it out;
2202  thus, get the real IN-address from the socket */
2203  sto_len = sizeof(in_sto);
2204  if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
2205  (struct sockaddr *) &in_sto,
2206  &sto_len))
2207  {
2208  memcpy (&in_sto, in, in_len);
2209  sto_len = in_len;
2210  }
2211  GNUNET_free (in);
2212  GNUNET_free (bindto);
2213  in = (struct sockaddr *) &in_sto;
2214  in_len = sto_len;
2216  "Bound to `%s'\n",
2217  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
2218  stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
2222  if (NULL == my_private_key)
2223  {
2224  GNUNET_log (
2226  _ (
2227  "Transport service is lacking key configuration settings. Exiting.\n"));
2229  return;
2230  }
2232  /* start listening */
2234  listen_sock,
2235  &listen_cb,
2236  NULL);
2242  &mq_init,
2243  NULL,
2244  &enc_notify_cb,
2245  NULL);
2246  if (NULL == ch)
2247  {
2248  GNUNET_break (0);
2250  return;
2251  }
2254  IPPROTO_TCP,
2255  1 /* one address */,
2256  (const struct sockaddr **) &in,
2257  &in_len,
2258  &nat_address_cb,
2259  NULL /* FIXME: support reversal: #5529 */,
2260  NULL /* closure */);
2261 }
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
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 struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static struct GNUNET_PeerIdentity my_identity
Our public key.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
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
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
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:526
#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:180
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.
#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)
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#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 struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static int mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
Function called by the transport service to initialize a message queue given address information abou...
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition: nat_api.c:378
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:412
#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...
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:189
static struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#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 ...
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:1486
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
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
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

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

The main function for the UNIX communicator.

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

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

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

2273 {
2274  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2276  };
2277  int ret;
2278 
2279  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2280  return 2;
2281 
2282  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
2283  argv,
2284  "gnunet-communicator-tcp",
2285  _ ("GNUnet TCP communicator"),
2286  options,
2287  &run,
2288  NULL))
2289  ? 0
2290  : 1;
2291  GNUNET_free ((void *) argv);
2292  return ret;
2293 }
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:1438
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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:180
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
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

Variable Documentation

◆ listen_task

struct GNUNET_SCHEDULER_Task* listen_task
static

ID of listen task.

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

◆ max_queue_length

unsigned long long max_queue_length
static

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

Definition at line 497 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 502 of file gnunet-communicator-tcp.c.

◆ ch

Our environment.

Definition at line 507 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 512 of file gnunet-communicator-tcp.c.

◆ listen_sock

struct GNUNET_NETWORK_Handle* listen_sock
static

Listen socket.

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

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

Our public key.

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

Referenced by decrypt_and_check_tc(), do_rekey(), inject_rekey(), run(), setup_in_cipher(), and transmit_kx().

◆ rekey_interval

struct GNUNET_TIME_Relative rekey_interval
static

The rekey interval.

Definition at line 527 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 532 of file gnunet-communicator-tcp.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 537 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 547 of file gnunet-communicator-tcp.c.

◆ proto_head

struct ProtoQueue* proto_head
static

Protoqueues DLL head.

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

◆ proto_tail

struct ProtoQueue* proto_tail
static

Protoqueues DLL tail.

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