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_core_service.h"
#include "gnunet_peerstore_service.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 "gnunet_resolver_service.h"
Include dependency graph for gnunet-communicator-tcp.c:

Go to the source code of this file.

Data Structures

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

Macros

#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
 How long do we believe our addresses to remain up (before the other peer should revalidate). More...
 
#define DEFAULT_MAX_QUEUE_LENGTH   8
 How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file). More...
 
#define BUF_SIZE   (2 * 64 * 1024 + sizeof(struct TCPBox))
 Size of our IO buffers for ciphertext data. More...
 
#define DEFAULT_REKEY_INTERVAL   GNUNET_TIME_UNIT_DAYS
 How often do we rekey based on time (at least) More...
 
#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 How long do we wait until we must have received the initial KX? More...
 
#define REKEY_MAX_BYTES   (1024LLU * 1024 * 1024 * 4LLU)
 How often do we rekey based on number of bytes transmitted? (additionally randomized). More...
 
#define INITIAL_KX_SIZE
 Size of the initial key exchange message sent first in both directions. More...
 
#define INITIAL_CORE_KX_SIZE
 Size of the initial core key exchange messages. 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 rekey_monotime_store_cb (void *cls, int success)
 Callback called when peerstore store operation for rekey monotime value is finished. More...
 
static void rekey_monotime_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
 Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where found. More...
 
static void do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
 Handle rekey message on queue. More...
 
static void handshake_ack_monotime_store_cb (void *cls, int success)
 Callback called when peerstore store operation for handshake ack monotime value is finished. More...
 
static void handshake_ack_monotime_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
 Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK where found. More...
 
static size_t try_handle_plaintext (struct Queue *queue)
 Test if we have received a full message in plaintext. More...
 
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
 Convert a struct sockaddr_in6 to astruct sockaddr *`. More...
 
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
 Convert a struct sockaddr_in4 to astruct sockaddr *`. More...
 
static struct PortOnlyIpv4Ipv6tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
 Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 * More...
 
static char * extract_address (const char *bindto)
 This Method extracts the address part of the BINDTO string. More...
 
static unsigned int extract_port (const char *addr_and_port)
 This Method extracts the port part of the BINDTO string. More...
 
static struct sockaddr * tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
 Convert TCP bind specification to a struct sockaddr * More...
 
static void setup_out_cipher (struct Queue *queue)
 Setup cipher for outgoing data stream based on target and our ephemeral private key. More...
 
static void inject_rekey (struct Queue *queue)
 Inject a struct TCPRekey message into the queue's plaintext buffer. More...
 
static void queue_write (void *cls)
 We have been notified that our socket is ready to write. More...
 
static void mq_send (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Signature of functions implementing the sending functionality of a message queue. More...
 
static void mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Signature of functions implementing the destruction of a message queue. More...
 
static void mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Implementation function that cancels the currently sent message. More...
 
static void mq_error (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static void boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
 Add the given queue to our internal data structure. More...
 
static void transmit_kx (struct Queue *queue, const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
 Generate and transmit our ephemeral key and the signature for the initial KX with the other peer. More...
 
static void start_initial_kx_out (struct Queue *queue)
 Initialize our key material for outgoing transmissions and inform the other peer about it. More...
 
static void handshake_monotime_store_cb (void *cls, int success)
 Callback called when peerstore store operation for handshake monotime is finished. More...
 
static void handshake_monotime_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
 Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE where found. 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 send_challenge (struct TCPConfirmation tc, struct Queue *queue)
 Sending challenge with TcpConfirmationAck back to sender of ephemeral key. 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_lt_delete_it (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over all ListenTasks to clean up. 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 add_addr (struct sockaddr *in, socklen_t in_len)
 This method adds addresses to the DLL, that are later register at the NAT service. More...
 
static int init_socket (struct sockaddr *addr, socklen_t in_len)
 This method launch network interactions for each address we like to bind to. More...
 
static void nat_register ()
 This method reads from the DLL addrs_head to register them at the NAT service. More...
 
static void init_socket_resolv (void *cls, const struct sockaddr *addr, socklen_t in_len)
 This method is the callback called by the resolver API, and wraps method init_socket. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Setup communicator and launch network interactions. More...
 
int main (int argc, char *const *argv)
 The main function for the UNIX communicator. More...
 

Variables

static unsigned long long max_queue_length
 Maximum queue length before we stop reading towards the transport service. More...
 
static struct GNUNET_STATISTICS_Handlestats
 For logging statistics. More...
 
static struct GNUNET_TRANSPORT_CommunicatorHandlech
 Our environment. More...
 
static struct GNUNET_CONTAINER_MultiPeerMapqueue_map
 Queues (map from peer identity to struct Queue) More...
 
static struct GNUNET_CONTAINER_MultiHashMaplt_map
 ListenTasks (map from socket to struct ListenTask) More...
 
static struct GNUNET_PeerIdentity my_identity
 Our public key. More...
 
static struct GNUNET_TIME_Relative rekey_interval
 The rekey interval. More...
 
static struct GNUNET_CRYPTO_EddsaPrivateKeymy_private_key
 Our private key. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_NT_InterfaceScanneris
 Network scanner to determine network types. More...
 
static struct GNUNET_NAT_Handlenat
 Connection to NAT service. More...
 
static struct ProtoQueueproto_head
 Protoqueues DLL head. More...
 
static struct ProtoQueueproto_tail
 Protoqueues DLL tail. More...
 
struct GNUNET_RESOLVER_RequestHandleresolve_request_handle
 Handle for DNS lookup of bindto address. More...
 
struct Addressesaddrs_head
 Head of DLL with addresses we like to register at NAT servcie. More...
 
struct Addressesaddrs_tail
 Head of DLL with addresses we like to register at NAT servcie. More...
 
struct ListenTasklts_head
 Head of DLL with ListenTasks. More...
 
struct ListenTasklts_tail
 Head of DLL with ListenTask. More...
 
int addrs_lens
 Number of addresses in the DLL for register at NAT service. More...
 
size_t unverified_size
 Size of data received without KX challenge played back. More...
 
static struct GNUNET_PEERSTORE_Handlepeerstore
 Database for peer's HELLOs. More...
 
int shutdown_running = GNUNET_NO
 A flag indicating we are already doing a shutdown. More...
 
unsigned int bind_port
 The port the communicator should be assigned to. 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 47 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 58 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 64 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 69 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 74 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 80 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 86 of file gnunet-communicator-tcp.c.

Referenced by queue_read_kx().

◆ INITIAL_CORE_KX_SIZE

#define INITIAL_CORE_KX_SIZE
Value:
(sizeof(struct EphemeralKeyMessage) \
+ sizeof(struct PingMessage) \
+ sizeof(struct PongMessage))
Response to a PING.
We're sending an (encrypted) PING to the other peer to check if it can decrypt.
Message transmitted with the signed ephemeral key of a peer.

Size of the initial core key exchange messages.

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

Referenced by try_handle_plaintext().

◆ COMMUNICATOR_ADDRESS_PREFIX

#define COMMUNICATOR_ADDRESS_PREFIX   "tcp"

Address prefix used by the communicator.

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

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

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-tcp"

Configuration section used by the communicator.

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

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

Function Documentation

◆ listen_cb()

static void listen_cb ( void *  cls)
static

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

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

Parameters
clsNULL

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

Parameters
clsListenTask with listening socket and task

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

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

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

2695 {
2696  struct sockaddr_storage in;
2697  socklen_t addrlen;
2698  struct GNUNET_NETWORK_Handle *sock;
2699  struct ProtoQueue *pq;
2700  struct ListenTask *lt;
2701 
2703  "listen_cb\n");
2704 
2705  lt = cls;
2706 
2707  lt->listen_task = NULL;
2708  GNUNET_assert (NULL != lt->listen_sock);
2709  addrlen = sizeof(in);
2710  memset (&in, 0, sizeof(in));
2712  (struct sockaddr*) &in,
2713  &addrlen);
2714  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2715  return; /* system limit reached, wait until connection goes down */
2717  lt->listen_sock,
2718  &listen_cb,
2719  lt);
2720  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2721  return;
2722  if (NULL == sock)
2723  {
2725  return;
2726  }
2727  pq = GNUNET_new (struct ProtoQueue);
2728  pq->address_len = addrlen;
2729  pq->address = GNUNET_memdup (&in, addrlen);
2731  pq->sock = sock;
2733  pq->sock,
2734  &proto_read_kx,
2735  pq);
2737 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue...
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
Handle for an incoming connection where we do not yet have enough information to setup a full queue...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:430
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct sockaddr * address
Address of the other peer.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:52
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
static struct ProtoQueue * proto_head
Protoqueues DLL head.
Struct to use as closure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_destroy()

static void queue_destroy ( struct Queue queue)
static

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

Parameters
queuequeue to close down

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

References Queue::address, Queue::backpressure, Queue::destroyed, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NETWORK_socket_close(), GNUNET_NO, GNUNET_PEERSTORE_iterate_cancel(), GNUNET_PEERSTORE_store_cancel(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_mq_del(), GNUNET_YES, Queue::handshake_ack_monotime_get, Queue::handshake_ack_monotime_sc, Queue::handshake_monotime_get, Queue::handshake_monotime_sc, Queue::in_cipher, listen_cb(), ListenTask::listen_sock, Queue::listen_sock, ListenTask::listen_task, Queue::out_cipher, Queue::qh, Queue::read_task, Queue::rekey_monotime_get, Queue::rekey_monotime_sc, shutdown_running, Queue::sock, Queue::target, and Queue::write_task.

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

867 {
868  struct ListenTask *lt = NULL;
869  struct GNUNET_HashCode h_sock;
870 
872  sizeof(queue->listen_sock),
873  &h_sock);
874 
876 
878  "Disconnecting queue for peer `%s'\n",
879  GNUNET_i2s (&queue->target));
880  if (NULL != queue->rekey_monotime_sc)
881  {
883  queue->rekey_monotime_sc = NULL;
884  }
885  if (NULL != queue->handshake_monotime_sc)
886  {
888  queue->handshake_monotime_sc = NULL;
889  }
890  if (NULL != queue->handshake_ack_monotime_sc)
891  {
893  queue->handshake_ack_monotime_sc = NULL;
894  }
895  if (NULL != queue->rekey_monotime_get)
896  {
898  queue->rekey_monotime_get = NULL;
899  }
900  if (NULL != queue->handshake_monotime_get)
901  {
903  queue->handshake_monotime_get = NULL;
904  }
905  if (NULL != queue->handshake_ack_monotime_get)
906  {
908  queue->handshake_ack_monotime_get = NULL;
909  }
910  if (NULL != queue->qh)
911  {
913  queue->qh = NULL;
914  }
915  GNUNET_assert (
916  GNUNET_YES ==
919  "# queues active",
921  GNUNET_NO);
922  if (NULL != queue->read_task)
923  {
925  queue->read_task = NULL;
926  }
927  if (NULL != queue->write_task)
928  {
930  queue->write_task = NULL;
931  }
933  {
935  "closing socket failed\n");
936  }
937  gcry_cipher_close (queue->in_cipher);
938  gcry_cipher_close (queue->out_cipher);
939  GNUNET_free (queue->address);
940  if (0 != queue->backpressure)
941  queue->destroyed = GNUNET_YES;
942  else
943  GNUNET_free (queue);
944 
945  if ((! shutdown_running) && (NULL == lt->listen_task))
946  {
948  "add read net listen\n");
951  lt->listen_sock,
952  &listen_cb,
953  lt);
954  }
955  else
956  GNUNET_free (lt);
957 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
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)
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
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
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
#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.
A 512-bit hashcode.
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
int shutdown_running
A flag indicating we are already doing a shutdown.
struct sockaddr * address
Address of the other peer.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define GNUNET_log(kind,...)
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
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
Struct to use as closure.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_hmac()

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

Compute mac over buf, and ratched the hmac_secret.

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

Definition at line 969 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().

973 {
974  struct GNUNET_HashCode mac;
975 
976  GNUNET_CRYPTO_hmac_raw (hmac_secret,
977  sizeof(struct GNUNET_HashCode),
978  buf,
979  buf_size,
980  &mac);
981  /* truncate to `struct GNUNET_ShortHashCode` */
982  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
983  /* ratchet hmac key */
984  GNUNET_CRYPTO_hash (hmac_secret,
985  sizeof(struct GNUNET_HashCode),
986  hmac_secret);
987 }
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn' this be the standard hmac function and the abov...
Definition: crypto_hash.c:420
A 256-bit hashcode.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
static char buf[2048]
A 512-bit hashcode.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_finish()

static void queue_finish ( struct Queue queue)
static

Append a 'finish' message to the outgoing transmission.

Once the finish has been transmitted, destroy the queue.

Parameters
queuequeue to shut down nicely

Definition at line 997 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(), handshake_ack_monotime_cb(), handshake_monotime_cb(), mq_destroy(), mq_error(), queue_read(), rekey_monotime_cb(), and try_handle_plaintext().

998 {
999  struct TCPFinish fin;
1000 
1001  memset (&fin, 0, sizeof(fin));
1002  fin.header.size = htons (sizeof(fin));
1003  fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
1004  calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1005  /* if there is any message left in pwrite_buf, we
1006  overwrite it (possibly dropping the last message
1007  from CORE hard here) */
1008  memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1009  queue->pwrite_off = sizeof(fin);
1010  /* This flag will ensure that #queue_write() no longer
1011  notifies CORE about the possibility of sending
1012  more data, and that #queue_write() will call
1013  #queue_destroy() once the @c fin was fully written. */
1014  queue->finishing = GNUNET_YES;
1015 }
int finishing
Did we enqueue a finish message and are closing down the queue?
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_queue_timeout()

static void reschedule_queue_timeout ( struct Queue queue)
static

Increment queue timeout due to activity.

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

Parameters
queuequeue for which the timeout should be rescheduled

Definition at line 1026 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().

1027 {
1028  queue->timeout =
1030 }
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 1605 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().

1606 {
1607  struct Queue *queue = cls;
1608  struct GNUNET_TIME_Relative left;
1609  ssize_t rcvd;
1610 
1611  queue->read_task = NULL;
1612  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1613  &queue->cread_buf[queue->cread_off],
1614  BUF_SIZE - queue->cread_off);
1616  "Received %lu bytes from TCP queue\n", rcvd);
1617  if (-1 == rcvd)
1618  {
1619  if ((EAGAIN != errno) && (EINTR != errno))
1620  {
1622  queue_finish (queue);
1623  return;
1624  }
1625  /* try again */
1627  queue->read_task =
1628  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1629  return;
1630  }
1631  if (0 != rcvd)
1632  reschedule_queue_timeout (queue);
1633  queue->cread_off += rcvd;
1634  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1635  (queue->cread_off > 0))
1636  {
1637  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1638  queue->cread_off);
1639  size_t done;
1640  size_t total;
1641  size_t old_pread_off = queue->pread_off;
1642 
1643  GNUNET_assert (0 ==
1644  gcry_cipher_decrypt (queue->in_cipher,
1645  &queue->pread_buf[queue->pread_off],
1646  max,
1647  queue->cread_buf,
1648  max));
1649  queue->pread_off += max;
1650  total = 0;
1651  while (0 != (done = try_handle_plaintext (queue)))
1652  {
1653  /* 'done' bytes of plaintext were used, shift buffer */
1654  GNUNET_assert (done <= queue->pread_off);
1655  /* NOTE: this memmove() could possibly sometimes be
1656  avoided if we pass 'total' into try_handle_plaintext()
1657  and use it at an offset into the buffer there! */
1658  memmove (queue->pread_buf,
1659  &queue->pread_buf[done],
1660  queue->pread_off - done);
1661  queue->pread_off -= done;
1662  total += done;
1663  /* The last plaintext was a rekey, abort for now */
1664  if (GNUNET_YES == queue->rekeyed)
1665  break;
1666  }
1667  /* when we encounter a rekey message, the decryption above uses the
1668  wrong key for everything after the rekey; in that case, we have
1669  to re-do the decryption at 'total' instead of at 'max'.
1670  However, we have to take into account that the plaintext buffer may have
1671  already contained data and not jumpt too far ahead in the ciphertext.
1672  If there is no rekey and the last message is incomplete (max > total),
1673  it is safe to keep the decryption so we shift by 'max' */
1674  if (GNUNET_YES == queue->rekeyed)
1675  {
1676  max = total - old_pread_off;
1677  queue->rekeyed = GNUNET_NO;
1678  queue->pread_off = 0;
1679  }
1680  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1681  queue->cread_off -= max;
1682  }
1683  if (BUF_SIZE == queue->cread_off)
1684  return; /* buffer full, suspend reading */
1686  if (0 != left.rel_value_us)
1687  {
1688  if (max_queue_length > queue->backpressure)
1689  {
1690  /* continue reading */
1692  queue->read_task =
1693  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1694  }
1695  return;
1696  }
1698  "Queue %p was idle for %s, disconnecting\n",
1699  queue,
1702  GNUNET_YES));
1703  queue_finish (queue);
1704 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
static void done()
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next...
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static void queue_read(void *cls)
Queue read task.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Handle for a queue.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:702
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next...
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
#define GNUNET_log(kind,...)
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_read_finished_cb()

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

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

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

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

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

Referenced by pass_plaintext_to_core().

1051 {
1052  struct Queue *queue = cls;
1053  if (GNUNET_OK != success)
1055  "# messages lost in communicator API towards CORE",
1056  1,
1057  GNUNET_NO);
1058  if (NULL == queue)
1059  return;
1060 
1062  "backpressure %u\n",
1063  queue->backpressure);
1064 
1065  queue->backpressure--;
1066  /* handle deferred queue destruction */
1067  if ((queue->destroyed) && (0 == queue->backpressure))
1068  {
1069  GNUNET_free (queue);
1070  return;
1071  }
1072  else if (GNUNET_YES != queue->destroyed)
1073  {
1074  reschedule_queue_timeout (queue);
1075  /* possibly unchoke reading, now that CORE made progress */
1076  if (NULL == queue->read_task)
1077  queue->read_task =
1079  queue->timeout),
1080  queue->sock,
1081  &queue_read,
1082  queue);
1083  }
1084 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void queue_read(void *cls)
Queue read task.
Handle for a queue.
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
#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 1097 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().

1100 {
1101  const struct GNUNET_MessageHeader *hdr = plaintext;
1102  int ret;
1103 
1104  if (ntohs (hdr->size) != plaintext_len)
1105  {
1106  /* NOTE: If we ever allow multiple CORE messages in one
1107  BOX, this will have to change! */
1108  GNUNET_break (0);
1109  return;
1110  }
1112  &queue->target,
1113  hdr,
1116  queue);
1117  if (GNUNET_OK == ret)
1118  queue->backpressure++;
1119  GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1120  if (GNUNET_SYSERR == ret)
1122  "# bytes lost due to CORE not running",
1123  plaintext_len,
1124  GNUNET_NO);
1125 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
static void core_read_finished_cb(void *cls, int success)
Core tells us it is done processing a message that transport received on a queue with status success...
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
Header for all communications.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_cipher()

static void setup_cipher ( const struct GNUNET_HashCode dh,
const struct GNUNET_PeerIdentity pid,
gcry_cipher_hd_t *  cipher,
struct GNUNET_HashCode hmac_key 
)
static

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

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

Definition at line 1138 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().

1142 {
1143  char key[256 / 8];
1144  char ctr[128 / 8];
1145 
1146  gcry_cipher_open (cipher,
1147  GCRY_CIPHER_AES256 /* low level: go for speed */,
1148  GCRY_CIPHER_MODE_CTR,
1149  0 /* flags */);
1151  sizeof(key),
1152  "TCP-key",
1153  strlen ("TCP-key"),
1154  dh,
1155  sizeof(*dh),
1156  pid,
1157  sizeof(*pid),
1158  NULL,
1159  0));
1160  gcry_cipher_setkey (*cipher, key, sizeof(key));
1162  sizeof(ctr),
1163  "TCP-ctr",
1164  strlen ("TCP-ctr"),
1165  dh,
1166  sizeof(*dh),
1167  pid,
1168  sizeof(*pid),
1169  NULL,
1170  0));
1171  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1173  GNUNET_CRYPTO_kdf (hmac_key,
1174  sizeof(struct GNUNET_HashCode),
1175  "TCP-hmac",
1176  strlen ("TCP-hmac"),
1177  dh,
1178  sizeof(*dh),
1179  pid,
1180  sizeof(*pid),
1181  NULL,
1182  0));
1183 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90
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 1193 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().

1195 {
1196  struct GNUNET_HashCode dh;
1197 
1198  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
1199  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
1200 }
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
static struct GNUNET_PeerIdentity my_identity
Our public key.
int GNUNET_CRYPTO_eddsa_ecdh(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private EdDSA key.
Definition: crypto_ecc.c:1024
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
static void setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
A 512-bit hashcode.
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rekey_monotime_store_cb()

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

Callback called when peerstore store operation for rekey monotime value is finished.

Parameters
clsQueue context the store operation was executed.
successStore operation was successful (GNUNET_OK) or not.

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

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, queue(), and Queue::rekey_monotime_sc.

Referenced by rekey_monotime_cb().

1209 {
1210  struct Queue *queue = cls;
1211  if (GNUNET_OK != success)
1212  {
1214  "Failed to store rekey monotonic time in PEERSTORE!\n");
1215  }
1216  queue->rekey_monotime_sc = NULL;
1217 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rekey_monotime_cb()

static void rekey_monotime_cb ( void *  cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  emsg 
)
static

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where found.

Parameters
clsQueue context the store operation was executed.
recordThe record found or NULL if there is no record left.
emsgMessage from peerstore.

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

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, pid, queue(), queue_finish(), Queue::rekey_monotime_get, Queue::rekey_monotime_sc, rekey_monotime_store_cb(), Queue::rekey_monotonic_time, Queue::target, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by do_rekey().

1230 {
1231  struct Queue *queue = cls;
1232  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1233  struct GNUNET_TIME_Absolute mt;
1234  const struct GNUNET_PeerIdentity *pid;
1235  struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1236 
1237  (void) emsg;
1238 
1239  rekey_monotonic_time = &queue->rekey_monotonic_time;
1240  pid = &queue->target;
1241  if (NULL == record)
1242  {
1243  queue->rekey_monotime_get = NULL;
1244  return;
1245  }
1246  if (sizeof(*mtbe) != record->value_size)
1247  {
1248  GNUNET_break (0);
1249  return;
1250  }
1251  mtbe = record->value;
1252  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1253  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1255  {
1257  "Queue from %s dropped, rekey monotime in the past\n",
1258  GNUNET_i2s (&queue->target));
1259  GNUNET_break (0);
1260  queue_finish (queue);
1261  return;
1262  }
1264  "transport_tcp_communicator",
1265  pid,
1267  rekey_monotonic_time,
1268  sizeof(rekey_monotonic_time),
1272  queue);
1273 }
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.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
Delete any previous values for the given key before storing the given value.
size_t value_size
Size of value BLOB.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender&#39;s monotonic time from rekey message.
static void rekey_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for rekey monotime value is finished.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
void * value
Record value BLOB.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
The identity of the host (wraps the signing key of the peer).
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

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

References TcpRekeySignature::ephemeral, TCPRekey::ephemeral, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_eddsa_verify, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_p2s(), GNUNET_PEERSTORE_iterate(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY, GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, Queue::in_cipher, TcpRekeySignature::monotonic_time, TCPRekey::monotonic_time, my_identity, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpRekeySignature::purpose, TcpHandshakeSignature::purpose, queue_finish(), TcpRekeySignature::receiver, rekey_monotime_cb(), Queue::rekey_monotime_get, Queue::rekey_monotonic_time, Queue::rekeyed, TcpRekeySignature::sender, TCPRekey::sender_sig, setup_in_cipher(), GNUNET_CRYPTO_EccSignaturePurpose::size, and Queue::target.

Referenced by try_handle_plaintext().

1285 {
1286  struct TcpRekeySignature thp;
1287 
1289  thp.purpose.size = htonl (sizeof(thp));
1291  "do_rekey size %u\n",
1292  thp.purpose.size);
1293  thp.sender = queue->target;
1295  "sender %s\n",
1296  GNUNET_p2s (&thp.sender.public_key));
1298  "sender %s\n",
1299  GNUNET_p2s (&queue->target.public_key));
1300  thp.receiver = my_identity;
1302  "receiver %s\n",
1303  GNUNET_p2s (&thp.receiver.public_key));
1304  thp.ephemeral = rekey->ephemeral;
1306  "ephemeral %s\n",
1307  GNUNET_e2s (&thp.ephemeral));
1308  thp.monotonic_time = rekey->monotonic_time;
1310  "time %s\n",
1312  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1313  GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1314  if (GNUNET_OK !=
1316  &thp,
1317  &rekey->sender_sig,
1318  &queue->target.public_key))
1319  {
1320  GNUNET_break (0);
1321  queue_finish (queue);
1322  return;
1323  }
1324  queue->rekey_monotonic_time = rekey->monotonic_time;
1326  "transport_tcp_communicator",
1327  &queue->target,
1330  queue);
1331  gcry_cipher_close (queue->in_cipher);
1332  queue->rekeyed = GNUNET_YES;
1333  setup_in_cipher (&rekey->ephemeral, queue);
1334 }
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.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
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...
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender&#39;s monotonic time from rekey message.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
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.
static void rekey_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where...
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
#define GNUNET_log(kind,...)
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_store_cb()

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

Callback called when peerstore store operation for handshake ack monotime value is finished.

Parameters
clsQueue context the store operation was executed.
successStore operation was successful (GNUNET_OK) or not.

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

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, Queue::handshake_ack_monotime_sc, and queue().

Referenced by handshake_ack_monotime_cb().

1343 {
1344  struct Queue *queue = cls;
1345 
1346  if (GNUNET_OK != success)
1347  {
1349  "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1350  }
1351  queue->handshake_ack_monotime_sc = NULL;
1352 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_cb()

static void handshake_ack_monotime_cb ( void *  cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  emsg 
)
static

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK where found.

Parameters
clsQueue context the store operation was executed.
recordThe record found or NULL if there is no record left.
emsgMessage from peerstore.

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

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, Queue::handshake_ack_monotime_get, Queue::handshake_ack_monotime_sc, handshake_ack_monotime_store_cb(), Queue::handshake_ack_monotonic_time, pid, queue(), queue_finish(), Queue::target, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by try_handle_plaintext().

1365 {
1366  struct Queue *queue = cls;
1367  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1368  struct GNUNET_TIME_Absolute mt;
1369  const struct GNUNET_PeerIdentity *pid;
1370  struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1371 
1372  (void) emsg;
1373 
1374  handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1375  pid = &queue->target;
1376  if (NULL == record)
1377  {
1378  queue->handshake_ack_monotime_get = NULL;
1379  return;
1380  }
1381  if (sizeof(*mtbe) != record->value_size)
1382  {
1383  GNUNET_break (0);
1384  return;
1385  }
1386  mtbe = record->value;
1387  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1388  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1390  {
1392  "Queue from %s dropped, handshake ack monotime in the past\n",
1393  GNUNET_i2s (&queue->target));
1394  GNUNET_break (0);
1395  queue_finish (queue);
1396  return;
1397  }
1399  "transport_tcp_communicator",
1400  pid,
1402  handshake_ack_monotonic_time,
1403  sizeof(
1404  handshake_ack_monotonic_time),
1407  &
1409  queue);
1410 }
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.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
Delete any previous values for the given key before storing the given value.
size_t value_size
Size of value BLOB.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
void * value
Record value BLOB.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished...
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
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:

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

References calculate_hmac(), Queue::challenge, do_rekey(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcmp, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, GNUNET_PEERSTORE_iterate(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_SYSERR, handshake_ack_monotime_cb(), Queue::handshake_ack_monotime_get, TCPFinish::hmac, TCPBox::hmac, Queue::in_hmac, INITIAL_CORE_KX_SIZE, my_identity, pass_plaintext_to_core(), Queue::pread_buf, Queue::pread_off, queue_destroy(), queue_finish(), size, GNUNET_MessageHeader::size, Queue::target, type, GNUNET_MessageHeader::type, and unverified_size.

Referenced by queue_read().

1421 {
1422  const struct GNUNET_MessageHeader *hdr =
1423  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1424  const struct TCPConfirmationAck *tca = (const struct
1425  TCPConfirmationAck *) queue->pread_buf;
1426  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1427  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1428  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1429  struct TCPRekey rekeyz;
1430  struct TCPFinish finz;
1431  struct GNUNET_ShortHashCode tmac;
1432  uint16_t type;
1433  size_t size = 0; /* make compiler happy */
1434  struct TcpHandshakeAckSignature thas;
1435  const struct ChallengeNonceP challenge = queue->challenge;
1436 
1437  if ((sizeof(*hdr) > queue->pread_off))
1438  {
1440  "Handling plaintext, not even a header!\n");
1441  return 0; /* not even a header */
1442  }
1443 
1445  {
1447  "Already received data of size %lu bigger than KX size %lu!\n",
1450  GNUNET_break_op (0);
1451  queue_finish (queue);
1452  return 0;
1453  }
1454 
1455  type = ntohs (hdr->type);
1456  switch (type)
1457  {
1460  "start processing ack\n");
1461  if (sizeof(*tca) > queue->pread_off)
1462  {
1464  "Handling plaintext size of tca greater than pread offset.\n");
1465  return 0;
1466  }
1467  if (ntohs (hdr->size) != sizeof(*tca))
1468  {
1470  "Handling plaintext size does not match message type.\n");
1471  GNUNET_break_op (0);
1472  queue_finish (queue);
1473  return 0;
1474  }
1475 
1476  thas.purpose.purpose = htonl (
1478  thas.purpose.size = htonl (sizeof(thas));
1479  thas.sender = tca->sender;
1480  thas.receiver = my_identity;
1481  thas.monotonic_time = tca->monotonic_time;
1482  thas.challenge = tca->challenge;
1483 
1486  &thas,
1487  &tca->sender_sig,
1488  &tca->sender.public_key))
1489  {
1491  "Verification of signature failed!\n");
1492  GNUNET_break (0);
1493  queue_finish (queue);
1494  return 0;
1495  }
1496  if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1497  {
1499  "Challenge in TCPConfirmationAck not correct!\n");
1500  GNUNET_break (0);
1501  queue_finish (queue);
1502  return 0;
1503  }
1504 
1506  "transport_tcp_communicator",
1507  &queue->target,
1509  &
1511  queue);
1512 
1514  "Handling plaintext, ack processed!");
1515 
1516  unverified_size = -1;
1517 
1518  size = ntohs (hdr->size);
1519  break;
1521  /* Special case: header size excludes box itself! */
1522  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1523  return 0;
1524  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1525  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1526  {
1527  GNUNET_break_op (0);
1528  queue_finish (queue);
1529  return 0;
1530  }
1531  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1532  size = ntohs (hdr->size) + sizeof(*box);
1534  "Handling plaintext, box processed!\n");
1535  break;
1536 
1538  if (sizeof(*rekey) > queue->pread_off)
1539  return 0;
1540  if (ntohs (hdr->size) != sizeof(*rekey))
1541  {
1542  GNUNET_break_op (0);
1543  queue_finish (queue);
1544  return 0;
1545  }
1546  rekeyz = *rekey;
1547  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1548  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1549  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1550  {
1551  GNUNET_break_op (0);
1552  queue_finish (queue);
1553  return 0;
1554  }
1555  do_rekey (queue, rekey);
1556  size = ntohs (hdr->size);
1558  "Handling plaintext, rekey processed!\n");
1559  break;
1560 
1562  if (sizeof(*fin) > queue->pread_off)
1563  return 0;
1564  if (ntohs (hdr->size) != sizeof(*fin))
1565  {
1566  GNUNET_break_op (0);
1567  queue_finish (queue);
1568  return 0;
1569  }
1570  finz = *fin;
1571  memset (&finz.hmac, 0, sizeof(finz.hmac));
1572  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1573  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1574  {
1575  GNUNET_break_op (0);
1576  queue_finish (queue);
1577  return 0;
1578  }
1579  /* handle FINISH by destroying queue */
1580  queue_destroy (queue);
1582  "Handling plaintext, finish processed!\n");
1583  break;
1584 
1585  default:
1587  "Handling plaintext, nothing processed!\n");
1588  GNUNET_break_op (0);
1589  queue_finish (queue);
1590  return 0;
1591  }
1592  GNUNET_assert (0 != size);
1593  if (-1 != unverified_size)
1594  unverified_size += size;
1595  return size;
1596 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
size_t unverified_size
Size of data received without KX challenge played back.
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
#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...
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
A 256-bit hashcode.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
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.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
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.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
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
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
Type of a nonce used for challenges.
TCP message box.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Ack for the encrypted continuation of TCP initial handshake.
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
TCP rekey message box.
#define GNUNET_log(kind,...)
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
static void handshake_ack_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_A...
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v6()

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

Convert a struct sockaddr_in6 to astruct sockaddr *`.

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

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

References GNUNET_memdup.

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

1716 {
1717  struct sockaddr *in;
1718 
1719  v6.sin6_family = AF_INET6;
1720  v6.sin6_port = htons ((uint16_t) port);
1721 #if HAVE_SOCKADDR_IN_SIN_LEN
1722  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
1723 #endif
1724  v6.sin6_flowinfo = 0;
1725  v6.sin6_scope_id = 0;
1726  in = GNUNET_memdup (&v6, sizeof(v6));
1727  *sock_len = sizeof(struct sockaddr_in6);
1728 
1729  return in;
1730 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v4()

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

Convert a struct sockaddr_in4 to astruct sockaddr *`.

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

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

References GNUNET_memdup.

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

1742 {
1743  struct sockaddr *in;
1744 
1745  v4.sin_family = AF_INET;
1746  v4.sin_port = htons ((uint16_t) port);
1747 #if HAVE_SOCKADDR_IN_SIN_LEN
1748  v4.sin_len = sizeof(struct sockaddr_in);
1749 #endif
1750  in = GNUNET_memdup (&v4, sizeof(v4));
1751  *sock_len = sizeof(struct sockaddr_in);
1752  return in;
1753 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_port_only()

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

Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *

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

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

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

Referenced by run().

1763 {
1764  struct PortOnlyIpv4Ipv6 *po;
1765  struct sockaddr_in *i4;
1766  struct sockaddr_in6 *i6;
1767  socklen_t sock_len_ipv4;
1768  socklen_t sock_len_ipv6;
1769 
1770  /* interpreting value as just a PORT number */
1771  if (*port > UINT16_MAX)
1772  {
1774  "BINDTO specification `%s' invalid: value too large for port\n",
1775  bindto);
1776  return NULL;
1777  }
1778 
1779  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
1780 
1781  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1782  (GNUNET_YES ==
1785  "DISABLE_V6")))
1786  {
1787  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1788  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1789  *port);
1790  po->addr_len_ipv4 = sock_len_ipv4;
1791  }
1792  else
1793  {
1794 
1795  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1796  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1797  *port);
1798  po->addr_len_ipv4 = sock_len_ipv4;
1799 
1800  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1801  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
1802  *port);
1803 
1804  po->addr_len_ipv6 = sock_len_ipv6;
1805 
1806  GNUNET_free (i6);
1807  }
1808 
1809  GNUNET_free (i4);
1810 
1811  return po;
1812 }
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
socklen_t addr_len_ipv4
Length of ipv4 address.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
socklen_t addr_len_ipv6
Length of ipv6 address.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
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:

◆ extract_address()

static char* extract_address ( const char *  bindto)
static

This Method extracts the address part of the BINDTO string.

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

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

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_strdup, and start.

Referenced by run(), and tcp_address_to_sockaddr().

1822 {
1823 
1824  char *start;
1825  char *token;
1826  char *cp;
1827  char *rest = NULL;
1828 
1830  "extract address with bindto %s\n",
1831  bindto);
1832 
1833  if (NULL == bindto)
1835  "bindto is NULL\n");
1836 
1837  cp = GNUNET_strdup (bindto);
1838 
1840  "extract address 2\n");
1841 
1842  start = cp;
1843  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1844  {
1845  start++; /* skip over '['*/
1846  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
1847  }
1848  else {
1849  token = strtok_r (cp, "]", &rest);
1850  if (strlen (bindto) == strlen (token))
1851  {
1852  token = strtok_r (cp, ":", &rest);
1853  }
1854  else
1855  {
1856  token++;
1857  return token;
1858  }
1859  }
1860 
1862  "extract address 3\n");
1864  "extract address with start %s\n",
1865  start);
1866 
1867  return start;
1868 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ extract_port()

static unsigned int extract_port ( const char *  addr_and_port)
static

This Method extracts the port part of the BINDTO string.

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

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

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

Referenced by run(), and tcp_address_to_sockaddr().

1878 {
1879  unsigned int port;
1880  char dummy[2];
1881  char *token;
1882  char *addr;
1883  char *colon;
1884  char *cp;
1885  char *rest = NULL;
1886 
1887  if (NULL != addr_and_port)
1888  {
1889  cp = GNUNET_strdup (addr_and_port);
1890  token = strtok_r (cp, "]", &rest);
1891  if (strlen (addr_and_port) == strlen (token))
1892  {
1893  colon = strrchr (cp, ':');
1894  if (NULL == colon)
1895  {
1896  return 0;
1897  }
1898  addr = colon;
1899  addr++;
1900  }
1901  else
1902  {
1903  token = strtok_r (NULL, "]", &rest);
1904  if (NULL == token)
1905  {
1906  return 0;
1907  }
1908  else
1909  {
1910  addr = token;
1911  addr++;
1912  }
1913  }
1914 
1915 
1916  if (1 == sscanf (addr, "%u%1s", &port, dummy))
1917  {
1918  /* interpreting value as just a PORT number */
1919  if (port > UINT16_MAX)
1920  {
1922  "Port `%u' invalid: value too large for port\n",
1923  port);
1924  // GNUNET_free (cp);
1925  return 0;
1926  }
1927  }
1928  else
1929  {
1931  "BINDTO specification invalid: last ':' not followed by number\n");
1932  // GNUNET_free (cp);
1933  return 0;
1934  }
1935  }
1936  else
1937  {
1939  "return 0\n");
1940  /* interpret missing port as 0, aka pick any free one */
1941  port = 0;
1942  }
1943 
1944 
1945  return port;
1946 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr()

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

Convert TCP bind specification to a struct sockaddr *

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

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

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

Referenced by mq_init().

1957 {
1958  struct sockaddr *in;
1959  unsigned int port;
1960  struct sockaddr_in v4;
1961  struct sockaddr_in6 v6;
1962  const char *start;
1963 
1964  // cp = GNUNET_strdup (bindto);
1965  start = extract_address (bindto);
1966 
1968  "start %s\n",
1969  start);
1970 
1972  "!bindto %s\n",
1973  bindto);
1974 
1975 
1976 
1977  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
1978  {
1979  // colon = strrchr (cp, ':');
1980  port = extract_port (bindto);
1981 
1983  "port %u\n",
1984  port);
1985 
1986  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
1987  }
1988  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
1989  {
1990  // colon = strrchr (cp, ':');
1991  port = extract_port (bindto);
1992  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
1993  }
1994  else{
1995  GNUNET_assert (0);
1996  }
1997 
1998  // GNUNET_free (start);
1999 
2000  return in;
2001 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_out_cipher()

static void setup_out_cipher ( struct Queue queue)
static

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

Parameters
queuequeue to setup outgoing (encryption) cipher for

Definition at line 2011 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().

2012 {
2013  struct GNUNET_HashCode dh;
2014 
2015  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
2016  /* we don't need the private key anymore, drop it! */
2017  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
2018  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
2020  queue->rekey_left_bytes =
2022 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
static void setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
A 512-bit hashcode.
int GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
Definition: crypto_ecc.c:1084
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inject_rekey()

static void inject_rekey ( struct Queue queue)
static

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

Parameters
queuequeue to perform rekeying on

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

References calculate_hmac(), Queue::cwrite_buf, Queue::cwrite_off, Queue::ephemeral, TCPRekey::ephemeral, TcpRekeySignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_sign, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, GNUNET_p2s(), GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_ntoh(), TCPRekey::header, TCPRekey::hmac, TCPRekey::monotonic_time, TcpRekeySignature::monotonic_time, my_identity, Queue::out_cipher, Queue::out_hmac, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpRekeySignature::purpose, Queue::pwrite_off, TcpRekeySignature::receiver, TcpRekeySignature::sender, TCPRekey::sender_sig, setup_out_cipher(), GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, Queue::target, and GNUNET_MessageHeader::type.

Referenced by queue_write().

2033 {
2034  struct TCPRekey rekey;
2035  struct TcpRekeySignature thp;
2036 
2037  GNUNET_assert (0 == queue->pwrite_off);
2038  memset (&rekey, 0, sizeof(rekey));
2040  rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
2041  rekey.header.size = ntohs (sizeof(rekey));
2042  GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
2043  rekey.monotonic_time =
2045  thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
2046  thp.purpose.size = htonl (sizeof(thp));
2048  "inject_rekey size %u\n",
2049  thp.purpose.size);
2050  thp.sender = my_identity;
2052  "sender %s\n",
2053  GNUNET_p2s (&thp.sender.public_key));
2054  thp.receiver = queue->target;
2056  "receiver %s\n",
2057  GNUNET_p2s (&thp.receiver.public_key));
2058  thp.ephemeral = rekey.ephemeral;
2060  "ephemeral %s\n",
2061  GNUNET_e2s (&thp.ephemeral));
2062  thp.monotonic_time = rekey.monotonic_time;
2064  "time %s\n",
2066  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
2068  &thp,
2069  &rekey.sender_sig);
2070  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
2071  /* Encrypt rekey message with 'old' cipher */
2072  GNUNET_assert (0 ==
2073  gcry_cipher_encrypt (queue->out_cipher,
2074  &queue->cwrite_buf[queue->cwrite_off],
2075  sizeof(rekey),
2076  &rekey,
2077  sizeof(rekey)));
2078  queue->cwrite_off += sizeof(rekey);
2079  /* Setup new cipher for successive messages */
2080  gcry_cipher_close (queue->out_cipher);
2081  setup_out_cipher (queue);
2082 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:215
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:807
static void setup_out_cipher(struct Queue *queue)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
TCP rekey message box.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
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.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
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 2092 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, unverified_size, and Queue::write_task.

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

2093 {
2094  struct Queue *queue = cls;
2095  ssize_t sent;
2096  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
2097  queue->write_task = NULL;
2098  if (0 != queue->cwrite_off)
2099  {
2100  sent = GNUNET_NETWORK_socket_send (queue->sock,
2101  queue->cwrite_buf,
2102  queue->cwrite_off);
2104  "Sent %lu bytes to TCP queue\n", sent);
2105  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
2106  {
2108  queue_destroy (queue);
2109  return;
2110  }
2111  if (sent > 0)
2112  {
2113  size_t usent = (size_t) sent;
2114  queue->cwrite_off -= usent;
2115  memmove (queue->cwrite_buf,
2116  &queue->cwrite_buf[usent],
2117  queue->cwrite_off);
2118  reschedule_queue_timeout (queue);
2119  }
2120  }
2121  /* can we encrypt more? (always encrypt full messages, needed
2122  such that #mq_cancel() can work!) */
2123  if ((0 < queue->rekey_left_bytes) &&
2124  (queue->pwrite_off > 0) &&
2125  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
2126  {
2128  "Encrypting %lu bytes\n", queue->pwrite_off);
2129  GNUNET_assert (0 ==
2130  gcry_cipher_encrypt (queue->out_cipher,
2131  &queue->cwrite_buf[queue->cwrite_off],
2132  queue->pwrite_off,
2133  queue->pwrite_buf,
2134  queue->pwrite_off));
2135  if (queue->rekey_left_bytes > queue->pwrite_off)
2136  queue->rekey_left_bytes -= queue->pwrite_off;
2137  else
2138  queue->rekey_left_bytes = 0;
2139  queue->cwrite_off += queue->pwrite_off;
2140  queue->pwrite_off = 0;
2141  }
2142  if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
2143  ((0 == queue->rekey_left_bytes) ||
2144  (0 ==
2146  queue->rekey_time).rel_value_us))))
2147  {
2148  inject_rekey (queue);
2149  }
2150  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
2151  (GNUNET_YES == queue->mq_awaits_continue))
2152  {
2153  queue->mq_awaits_continue = GNUNET_NO;
2155  }
2156  /* did we just finish writing 'finish'? */
2157  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
2158  {
2160  "Finishing queue\n");
2161  queue_destroy (queue);
2162  return;
2163  }
2164  /* do we care to write more? */
2165  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
2166  queue->write_task =
2168  queue->sock,
2169  &queue_write,
2170  queue);
2171 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
size_t unverified_size
Size of data received without KX challenge played back.
uint64_t rel_value_us
The actual value.
int finishing
Did we enqueue a finish message and are closing down the queue?
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:816
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue&#39;s plaintext buffer.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
Handle for a queue.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:499
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 2183 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().

2186 {
2187  struct Queue *queue = impl_state;
2188  uint16_t msize = ntohs (msg->size);
2189  struct TCPBox box;
2191  "In MQ send. Queue finishing: %s; write task running: %s\n",
2192  (GNUNET_YES == queue->finishing) ? "yes" : "no",
2193  (NULL == queue->write_task) ? "yes" : "no");
2194  GNUNET_assert (mq == queue->mq);
2195  queue->mq_awaits_continue = GNUNET_YES;
2196  if (GNUNET_YES == queue->finishing)
2197  return; /* this queue is dying, drop msg */
2198  GNUNET_assert (0 == queue->pwrite_off);
2199  box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
2200  box.header.size = htons (msize);
2201  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2202  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2203  queue->pwrite_off += sizeof(box);
2204  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2205  queue->pwrite_off += msize;
2207  "%lu bytes of plaintext to send\n", queue->pwrite_off);
2208  GNUNET_assert (NULL != queue->sock);
2209  if (NULL == queue->write_task)
2210  queue->write_task =
2212  queue->sock,
2213  &queue_write,
2214  queue);
2215 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
int finishing
Did we enqueue a finish message and are closing down the queue?
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
Handle for a queue.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
TCP message box.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy()

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

Signature of functions implementing the destruction of a message queue.

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

Parameters
mqthe message queue to destroy
impl_stateour struct Queue

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

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

Referenced by boot_queue().

2228 {
2229  struct Queue *queue = impl_state;
2230 
2231  if (mq == queue->mq)
2232  {
2233  queue->mq = NULL;
2234  queue_finish (queue);
2235  }
2236 }
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 2246 of file gnunet-communicator-tcp.c.

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

Referenced by boot_queue().

2247 {
2248  struct Queue *queue = impl_state;
2249 
2250  GNUNET_assert (0 != queue->pwrite_off);
2251  queue->pwrite_off = 0;
2252 }
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 2265 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().

2266 {
2267  struct Queue *queue = cls;
2268 
2270  "MQ error in queue to %s: %d\n",
2271  GNUNET_i2s (&queue->target),
2272  (int) error);
2273  queue_finish (queue);
2274 }
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 2285 of file gnunet-communicator-tcp.c.

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

Referenced by mq_init(), and proto_read_kx().

2286 {
2287  queue->nt =
2290  queue_map,
2291  &queue->target,
2292  queue,
2295  "# queues active",
2297  GNUNET_NO);
2298  queue->timeout =
2301  &mq_destroy,
2302  &mq_cancel,
2303  queue,
2304  NULL,
2305  &mq_error,
2306  queue);
2307  {
2308  char *foreign_addr;
2309 
2310  switch (queue->address->sa_family)
2311  {
2312  case AF_INET:
2313  GNUNET_asprintf (&foreign_addr,
2314  "%s-%s",
2316  GNUNET_a2s (queue->address, queue->address_len));
2317  break;
2318 
2319  case AF_INET6:
2320  GNUNET_asprintf (&foreign_addr,
2321  "%s-%s",
2323  GNUNET_a2s (queue->address, queue->address_len));
2324  break;
2325 
2326  default:
2327  GNUNET_assert (0);
2328  }
2330  &queue->target,
2331  foreign_addr,
2332  0 /* no MTU */,
2334  0, /* Priority */
2335  queue->nt,
2336  cs,
2337  queue->mq);
2338  GNUNET_free (foreign_addr);
2339  }
2340 }
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 WANT.
Definition: nt.c:314
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
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:565
#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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct sockaddr * address
Address of the other peer.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
enum GNUNET_TRANSPORT_ConnectionStatus cs
Connection status for this queue.
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
enum GNUNET_NetworkType nt
Which network type does this queue use?
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_kx()

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

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

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

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

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

References Queue::challenge, TcpHandshakeSignature::challenge, TCPConfirmation::challenge, Queue::cwrite_buf, Queue::cwrite_off, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log_from_nocheck(), 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().

2356 {
2357  struct TcpHandshakeSignature ths;
2358  struct TCPConfirmation tc;
2359 
2360  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2361  queue->cwrite_off = sizeof(*epub);
2362  /* compute 'tc' and append in encrypted format to cwrite_buf */
2363  tc.sender = my_identity;
2364  tc.monotonic_time =
2367  &tc.challenge,
2368  sizeof(tc.challenge));
2369  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2370  ths.purpose.size = htonl (sizeof(ths));
2371  ths.sender = my_identity;
2372  ths.receiver = queue->target;
2373  ths.ephemeral = *epub;
2374  ths.monotonic_time = tc.monotonic_time;
2375  ths.challenge = tc.challenge;
2377  &ths,
2378  &tc.sender_sig);
2379  GNUNET_assert (0 ==
2380  gcry_cipher_encrypt (queue->out_cipher,
2381  &queue->cwrite_buf[queue->cwrite_off],
2382  sizeof(tc),
2383  &tc,
2384  sizeof(tc)));
2385  queue->challenge = tc.challenge;
2386  queue->cwrite_off += sizeof(tc);
2387 
2389  "transport",
2390  "handshake written\n");
2391 }
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake,.
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
Randomness for IVs etc.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
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
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
Encrypted continuation of TCP initial handshake.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
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 2402 of file gnunet-communicator-tcp.c.

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

Referenced by mq_init(), and proto_read_kx().

2403 {
2404  struct GNUNET_CRYPTO_EcdhePublicKey epub;
2405 
2408  setup_out_cipher (queue);
2409  transmit_kx (queue, &epub);
2410 }
static void transmit_kx(struct Queue *queue, const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
Generate and transmit our ephemeral key and the signature for the initial KX with the other peer...
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:215
static void setup_out_cipher(struct Queue *queue)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_monotime_store_cb()

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

Callback called when peerstore store operation for handshake monotime is finished.

Parameters
clsQueue context the store operation was executed.
successStore operation was successful (GNUNET_OK) or not.

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

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, Queue::handshake_monotime_sc, and queue().

Referenced by handshake_monotime_cb().

2419 {
2420  struct Queue *queue = cls;
2421  if (GNUNET_OK != success)
2422  {
2424  "Failed to store handshake monotonic time in PEERSTORE!\n");
2425  }
2426  queue->handshake_monotime_sc = NULL;
2427 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
Handle for a queue.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_monotime_cb()

static void handshake_monotime_cb ( void *  cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  emsg 
)
static

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE where found.

Parameters
clsQueue context the store operation was executed.
recordThe record found or NULL if there is no record left.
emsgMessage from peerstore.

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

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, Queue::handshake_monotime_get, Queue::handshake_monotime_sc, handshake_monotime_store_cb(), Queue::handshake_monotonic_time, pid, queue(), queue_finish(), Queue::target, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by decrypt_and_check_tc().

2440 {
2441  struct Queue *queue = cls;
2442  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2443  struct GNUNET_TIME_Absolute mt;
2444  const struct GNUNET_PeerIdentity *pid;
2445  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2446 
2447  (void) emsg;
2448 
2449  handshake_monotonic_time = &queue->handshake_monotonic_time;
2450  pid = &queue->target;
2451  if (NULL == record)
2452  {
2453  queue->handshake_monotime_get = NULL;
2454  return;
2455  }
2456  if (sizeof(*mtbe) != record->value_size)
2457  {
2458  GNUNET_break (0);
2459  return;
2460  }
2461  mtbe = record->value;
2462  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2463  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2465  {
2467  "Queue from %s dropped, handshake monotime in the past\n",
2468  GNUNET_i2s (&queue->target));
2469  GNUNET_break (0);
2470  queue_finish (queue);
2471  return;
2472  }
2474  "transport_tcp_communicator",
2475  pid,
2477  handshake_monotonic_time,
2478  sizeof(
2479  handshake_monotonic_time),
2482  &
2484  queue);
2485 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
Delete any previous values for the given key before storing the given value.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
size_t value_size
Size of value BLOB.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender&#39;s monotonic time from handshake message.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
void * value
Record value BLOB.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
static void handshake_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake monotime is finished.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

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

References TcpHandshakeSignature::challenge, TCPConfirmation::challenge, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_verify, GNUNET_PEERSTORE_iterate(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE, GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, handshake_monotime_cb(), Queue::handshake_monotime_get, Queue::in_cipher, TCPConfirmation::monotonic_time, TcpHandshakeSignature::monotonic_time, my_identity, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, TcpHandshakeSignature::receiver, TCPConfirmation::sender, TcpHandshakeSignature::sender, TCPConfirmation::sender_sig, GNUNET_CRYPTO_EccSignaturePurpose::size, and Queue::target.

Referenced by proto_read_kx(), and queue_read_kx().

2502 {
2503  struct TcpHandshakeSignature ths;
2504 
2505  GNUNET_assert (
2506  0 ==
2507  gcry_cipher_decrypt (queue->in_cipher,
2508  tc,
2509  sizeof(*tc),
2510  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2511  sizeof(*tc)));
2512  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2513  ths.purpose.size = htonl (sizeof(ths));
2514  ths.sender = tc->sender;
2515  ths.receiver = my_identity;
2516  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2517  ths.monotonic_time = tc->monotonic_time;
2518  ths.challenge = tc->challenge;
2521  &ths,
2522  &tc->sender_sig,
2523  &tc->sender.public_key);
2525  "transport_tcp_communicator",
2526  &queue->target,
2528  &
2530  queue);
2531 }
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake,.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static void handshake_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE w...
static struct GNUNET_PeerIdentity my_identity
Our public key.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender&#39;s monotonic time from handshake message.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
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 2540 of file gnunet-communicator-tcp.c.

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

Referenced by do_shutdown(), and proto_read_kx().

2541 {
2542  if (NULL != pq->listen_sock)
2543  {
2545  pq->listen_sock = NULL;
2546  }
2548  GNUNET_free (pq->address);
2550  GNUNET_free (pq);
2551 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct sockaddr * address
Address of the other peer.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_challenge()

static void send_challenge ( struct TCPConfirmation  tc,
struct Queue queue 
)
static

Sending challenge with TcpConfirmationAck back to sender of ephemeral key.

Parameters
tcThe TCPConfirmation originally send.
queueThe queue context.

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

References TCPConfirmationAck::challenge, TCPConfirmation::challenge, TcpHandshakeAckSignature::challenge, Queue::cwrite_buf, Queue::cwrite_off, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log_from_nocheck(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK, GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TCPConfirmationAck::header, TcpHandshakeAckSignature::monotonic_time, TCPConfirmationAck::monotonic_time, my_identity, Queue::out_cipher, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeAckSignature::purpose, TcpHandshakeAckSignature::receiver, TCPConfirmationAck::sender, TcpHandshakeAckSignature::sender, TCPConfirmationAck::sender_sig, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, Queue::target, and GNUNET_MessageHeader::type.

Referenced by proto_read_kx(), and queue_read_kx().

2561 {
2562  struct TCPConfirmationAck tca;
2563  struct TcpHandshakeAckSignature thas;
2564 
2566  "transport",
2567  "sending challenge\n");
2568 
2569  tca.header.type = ntohs (
2571  tca.header.size = ntohs (sizeof(tca));
2572  tca.challenge = tc.challenge;
2573  tca.sender = my_identity;
2574  tca.monotonic_time =
2576  thas.purpose.purpose = htonl (
2578  thas.purpose.size = htonl (sizeof(thas));
2579  thas.sender = my_identity;
2580  thas.receiver = queue->target;
2581  thas.monotonic_time = tca.monotonic_time;
2582  thas.challenge = tca.challenge;
2584  &thas,
2585  &tca.sender_sig);
2586  GNUNET_assert (0 ==
2587  gcry_cipher_encrypt (queue->out_cipher,
2588  &queue->cwrite_buf[queue->cwrite_off],
2589  sizeof(tca),
2590  &tca,
2591  sizeof(tca)));
2592  queue->cwrite_off += sizeof(tca);
2593 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
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 ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
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
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
Ack for the 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:

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

References Queue::address, ProtoQueue::address, Queue::address_len, ProtoQueue::address_len, boot_queue(), decrypt_and_check_tc(), free_proto_queue(), GNUNET_a2s(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recv(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CS_INBOUND, ProtoQueue::ibuf, ProtoQueue::ibuf_off, Queue::in_cipher, Queue::listen_sock, ProtoQueue::listen_sock, queue(), queue_read(), queue_write(), Queue::read_task, ProtoQueue::read_task, GNUNET_TIME_Relative::rel_value_us, send_challenge(), 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().

2603 {
2604  struct ProtoQueue *pq = cls;
2605  ssize_t rcvd;
2606  struct GNUNET_TIME_Relative left;
2607  struct Queue *queue;
2608  struct TCPConfirmation tc;
2609 
2610  pq->read_task = NULL;
2612  if (0 == left.rel_value_us)
2613  {
2614  free_proto_queue (pq);
2615  return;
2616  }
2617  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2618  &pq->ibuf[pq->ibuf_off],
2619  sizeof(pq->ibuf) - pq->ibuf_off);
2621  "Received %lu bytes for KX\n", rcvd);
2622  if (-1 == rcvd)
2623  {
2624  if ((EAGAIN != errno) && (EINTR != errno))
2625  {
2627  free_proto_queue (pq);
2628  return;
2629  }
2630  /* try again */
2631  pq->read_task =
2633  return;
2634  }
2635  pq->ibuf_off += rcvd;
2636  if (pq->ibuf_off > sizeof(pq->ibuf))
2637  {
2638  /* read more */
2639  pq->read_task =
2641  return;
2642  }
2643  /* we got all the data, let's find out who we are talking to! */
2644  queue = GNUNET_new (struct Queue);
2645  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2646  queue);
2647  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2648  {
2650  "Invalid TCP KX received from %s\n",
2651  GNUNET_a2s (queue->address, queue->address_len));
2652  gcry_cipher_close (queue->in_cipher);
2653  GNUNET_free (queue);
2654  free_proto_queue (pq);
2655  return;
2656  }
2657  queue->address = pq->address; /* steals reference */
2658  queue->address_len = pq->address_len;
2659  queue->target = tc.sender;
2660  queue->listen_sock = pq->listen_sock;
2661  queue->sock = pq->sock;
2662 
2663 
2665  "start kx proto\n");
2666 
2667  start_initial_kx_out (queue);
2669  queue->read_task =
2671  queue->sock,
2672  &queue_read,
2673  queue);
2674  queue->write_task =
2676  queue->sock,
2677  &queue_write,
2678  queue);
2679  send_challenge (tc, queue);
2680 
2682  GNUNET_free (pq);
2683 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
Add the given queue to our internal data structure.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue...
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void queue_read(void *cls)
Queue read task.
Handle for an incoming connection where we do not yet have enough information to setup a full queue...
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Handle for a queue.
this is an inbound connection (communicator initiated)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct sockaddr * address
Address of the other peer.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it...
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
socklen_t address_len
Length of the address.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
struct sockaddr * address
Address of the other peer.
size_t ibuf_off
Current offset for reading into ibuf.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#define GNUNET_log(kind,...)
static void send_challenge(struct TCPConfirmation tc, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
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 2748 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(), send_challenge(), TCPConfirmation::sender, setup_in_cipher(), Queue::sock, Queue::target, and Queue::timeout.

Referenced by mq_init().

2749 {
2750  struct Queue *queue = cls;
2751  ssize_t rcvd;
2752  struct GNUNET_TIME_Relative left;
2753  struct TCPConfirmation tc;
2754 
2755  queue->read_task = NULL;
2757  if (0 == left.rel_value_us)
2758  {
2759  queue_destroy (queue);
2760  return;
2761  }
2762  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2763  &queue->cread_buf[queue->cread_off],
2764  BUF_SIZE - queue->cread_off);
2765  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %lu bytes for KX\n", rcvd);
2766  if (-1 == rcvd)
2767  {
2768  if ((EAGAIN != errno) && (EINTR != errno))
2769  {
2771  queue_destroy (queue);
2772  return;
2773  }
2774  queue->read_task =
2775  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2776  return;
2777  }
2778  queue->cread_off += rcvd;
2779  if (queue->cread_off < INITIAL_KX_SIZE)
2780  {
2781  /* read more */
2782  queue->read_task =
2783  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2784  return;
2785  }
2786  /* we got all the data, let's find out who we are talking to! */
2788  queue->cread_buf,
2789  queue);
2790  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2791  {
2793  "Invalid TCP KX received from %s\n",
2794  GNUNET_a2s (queue->address, queue->address_len));
2795  queue_destroy (queue);
2796  return;
2797  }
2798  if (0 !=
2799  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2800  {
2802  "Invalid sender in TCP KX received from %s\n",
2803  GNUNET_a2s (queue->address, queue->address_len));
2804  queue_destroy (queue);
2805  return;
2806  }
2807  send_challenge (tc, queue);
2808  /* update queue timeout */
2809  reschedule_queue_timeout (queue);
2810  /* prepare to continue with regular read task immediately */
2811  memmove (queue->cread_buf,
2812  &queue->cread_buf[INITIAL_KX_SIZE],
2813  queue->cread_off - (INITIAL_KX_SIZE));
2814  queue->cread_off -= INITIAL_KX_SIZE;
2815  if (0 < queue->cread_off)
2816  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2817 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next...
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static void queue_read(void *cls)
Queue read task.
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
Handle for a queue.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
The identity of the host (wraps the signing key of the peer).
struct sockaddr * address
Address of the other peer.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#define GNUNET_log(kind,...)
static void send_challenge(struct TCPConfirmation tc, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_init()

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

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

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

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

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

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

Referenced by GNUNET_TRANSPORT_communicator_connect(), and init_socket().

2839 {
2840  struct Queue *queue;
2841  const char *path;
2842  struct sockaddr *in;
2843  socklen_t in_len = 0;
2844  struct GNUNET_NETWORK_Handle *sock;
2845 
2847  "Connecting to %s\n", address);
2848  if (0 != strncmp (address,
2850  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2851  {
2852  GNUNET_break_op (0);
2853  return GNUNET_SYSERR;
2854  }
2855  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2856  in = tcp_address_to_sockaddr (path, &in_len);
2857 
2858  if (NULL == in)
2859  {
2861  "Failed to setup TCP socket address\n");
2862  return GNUNET_SYSERR;
2863  }
2864 
2866  "in %s\n",
2867  GNUNET_a2s (in, in_len));
2868 
2869  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2870  if (NULL == sock)
2871  {
2873  "socket(%d) failed: %s",
2874  in->sa_family,
2875  strerror (errno));
2876  GNUNET_free (in);
2877  return GNUNET_SYSERR;
2878  }
2879  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2880  (errno != EINPROGRESS))
2881  {
2883  "connect to `%s' failed: %s",
2884  address,
2885  strerror (errno));
2887  GNUNET_free (in);
2888  return GNUNET_SYSERR;
2889  }
2890 
2891  queue = GNUNET_new (struct Queue);
2892  queue->target = *peer;
2893  queue->address = in;
2894  queue->address_len = in_len;
2895  queue->sock = sock;
2897  // queue->mq_awaits_continue = GNUNET_YES;
2898  queue->read_task =
2900  queue->sock,
2901  &queue_read_kx,
2902  queue);
2903 
2904 
2906  "start kx mq_init\n");
2907 
2908  start_initial_kx_out (queue);
2909  queue->write_task =
2911  queue->sock,
2912  &queue_write,
2913  queue);
2914  return GNUNET_OK;
2915 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
static void boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
Add the given queue to our internal data structure.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:658
Handle for a queue.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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_SCHEDULER_Task * write_task
ID of write task for this connection.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it...
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
struct sockaddr * address
Address of the other peer.
this is an outbound connection (transport initiated)
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:52
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
static char * address
GNS address for this phone.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_lt_delete_it()

static int get_lt_delete_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over all ListenTasks to clean up.

Parameters
clsNULL
keyunused
valuethe ListenTask to cancel.
Returns
GNUNET_OK to continue to iterate

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

References GNUNET_break, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), ListenTask::listen_sock, ListenTask::listen_task, and value.

Referenced by do_shutdown().

2929 {
2930  struct ListenTask *lt = value;
2931 
2932  (void) cls;
2933  (void) key;
2934  if (NULL != lt->listen_task)
2935  {
2937  lt->listen_task = NULL;
2938  }
2939  if (NULL != lt->listen_sock)
2940  {
2942  lt->listen_sock = NULL;
2943  }
2944  return GNUNET_OK;
2945 }
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * value
Value of the record to add/remove.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
Struct to use as closure.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

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

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

Referenced by do_shutdown().

2959 {
2960  struct Queue *queue = value;
2961 
2962  (void) cls;
2963  (void) target;
2964  queue_destroy (queue);
2965  return GNUNET_OK;
2966 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static char * value
Value of the record to add/remove.
Handle for a queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown the UNIX communicator.

Parameters
clsNULL (always)

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

References free_proto_queue(), get_lt_delete_it(), get_queue_delete_it(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NAT_unregister(), GNUNET_NO, GNUNET_NT_scanner_done(), GNUNET_PEERSTORE_disconnect(), GNUNET_RESOLVER_request_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_communicator_address_remove_all(), GNUNET_TRANSPORT_communicator_disconnect(), GNUNET_YES, and shutdown_running.

Referenced by run().

2975 {
2977  "Shutdown %s!\n",
2978  shutdown_running ? "running" : "not running");
2979 
2981  return;
2982  else
2984 
2985  while (NULL != proto_head)
2987  if (NULL != nat)
2988  {
2990  nat = NULL;
2991  }
2996  if (NULL != ch)
2997  {
2999  ch = NULL;
3000  }
3001  if (NULL != stats)
3002  {
3004  stats = NULL;
3005  }
3006  if (NULL != my_private_key)
3007  {
3009  my_private_key = NULL;
3010  }
3011  if (NULL != is)
3012  {
3014  is = NULL;
3015  }
3016  if (NULL != peerstore)
3017  {
3019  peerstore = NULL;
3020  }
3021  if (NULL != resolve_request_handle)
3022  {
3024  resolve_request_handle = NULL;
3025  }
3027  "Shutdown done!\n");
3028 }
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer...
static int get_lt_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all ListenTasks to clean up.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
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)
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
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_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
int shutdown_running
A flag indicating we are already doing a shutdown.
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.
#define GNUNET_log(kind,...)
static struct ProtoQueue * proto_head
Protoqueues DLL head.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enc_notify_cb()

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

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

Not applicable for TCP.

Parameters
clsclosure
senderwhich peer sent the notification
msgpayload

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

References GNUNET_break_op.

Referenced by init_socket().

3046 {
3047  (void) cls;
3048  (void) sender;
3049  (void) msg;
3050  GNUNET_break_op (0);
3051 }
#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 3068 of file gnunet-communicator-tcp.c.

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

Referenced by nat_register().

3074 {
3075  char *my_addr;
3077 
3079  "nat address cb %s %s\n",
3080  add_remove ? "add" : "remove",
3081  GNUNET_a2s (addr, addrlen));
3082 
3083  if (GNUNET_YES == add_remove)
3084  {
3085  enum GNUNET_NetworkType nt;
3086 
3087  GNUNET_asprintf (&my_addr,
3088  "%s-%s",
3090  GNUNET_a2s (addr, addrlen));
3091  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3092  ai =
3094  my_addr,
3095  nt,
3097  GNUNET_free (my_addr);
3098  *app_ctx = ai;
3099  }
3100  else
3101  {
3102  ai = *app_ctx;
3104  *app_ctx = NULL;
3105  }
3106 }
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 WANT.
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
#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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer...
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
#define GNUNET_log(kind,...)
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
Internal representation of an address a communicator is currently providing for the transport service...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_addr()

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

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

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

References Addresses::addr, Addresses::addr_len, addrs_lens, GNUNET_a2s(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and GNUNET_new.

Referenced by init_socket().

3113 {
3114 
3115  struct Addresses *saddrs;
3116 
3118  "add address %s\n",
3119  GNUNET_a2s (in, in_len));
3120 
3121  saddrs = GNUNET_new (struct Addresses);
3122  saddrs->addr = in;
3123  saddrs->addr_len = in_len;
3125 
3127  "after add address %s\n",
3128  GNUNET_a2s (in, in_len));
3129 
3131  "add address %s\n",
3132  GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3133 
3134  addrs_lens++;
3135 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
DLL to store the addresses we like to register at NAT service.
int addrs_lens
Number of addresses in the DLL for register at NAT service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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 Addresses * addrs_head
Head of DLL with addresses we like to register at NAT servcie.
struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT servcie.
struct sockaddr * addr
Address we like to register at NAT service.
#define GNUNET_log(kind,...)
socklen_t addr_len
Length of address we like to register at NAT service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_socket()

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

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

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

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

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

Referenced by init_socket_resolv(), and run().

3147 {
3148  struct sockaddr_storage in_sto;
3149  socklen_t sto_len;
3150  struct GNUNET_NETWORK_Handle *listen_sock;
3151  struct ListenTask *lt;
3152  struct GNUNET_HashCode h_sock;
3153 
3154  if (NULL == addr)
3155  {
3157  "Address is NULL.\n");
3158  return GNUNET_SYSERR;
3159  }
3160 
3162  "address %s\n",
3163  GNUNET_a2s (addr, in_len));
3164 
3165  listen_sock =
3166  GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3167  if (NULL == listen_sock)
3168  {
3170  return GNUNET_SYSERR;
3171  }
3172 
3173  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3174  {
3176  GNUNET_NETWORK_socket_close (listen_sock);
3177  listen_sock = NULL;
3178  return GNUNET_SYSERR;
3179  }
3180 
3181  if (GNUNET_OK !=
3182  GNUNET_NETWORK_socket_listen (listen_sock,
3183  5))
3184  {