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 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 setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
 Setup cipher of queue for decryption. More...
 
static void do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
 Handle rekey message on queue. More...
 
static 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 void send_challenge (struct ChallengeNonceP challenge, struct Queue *queue)
 Sending challenge with TcpConfirmationAck back to sender of ephemeral key. 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 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 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)
 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 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 init_socket(), mq_init(), nat_address_cb(), and try_handle_plaintext().

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

2783 {
2784  struct sockaddr_storage in;
2785  socklen_t addrlen;
2786  struct GNUNET_NETWORK_Handle *sock;
2787  struct ProtoQueue *pq;
2788  struct ListenTask *lt;
2789 
2791  "listen_cb\n");
2792 
2793  lt = cls;
2794 
2795  lt->listen_task = NULL;
2796  GNUNET_assert (NULL != lt->listen_sock);
2797  addrlen = sizeof(in);
2798  memset (&in, 0, sizeof(in));
2800  (struct sockaddr*) &in,
2801  &addrlen);
2802  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2803  return; /* system limit reached, wait until connection goes down */
2805  lt->listen_sock,
2806  &listen_cb,
2807  lt);
2808  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2809  return;
2810  if (NULL == sock)
2811  {
2813  return;
2814  }
2815  pq = GNUNET_new (struct ProtoQueue);
2816  pq->address_len = addrlen;
2817  pq->address = GNUNET_memdup (&in, addrlen);
2819  pq->sock = sock;
2821  pq->sock,
2822  &proto_read_kx,
2823  pq);
2825 }
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:181
#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 876 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_get_fd(), 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().

877 {
878  struct ListenTask *lt = NULL;
879  struct GNUNET_HashCode h_sock;
880  int sockfd;
881 
882  sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
883  GNUNET_CRYPTO_hash (&sockfd,
884  sizeof(int),
885  &h_sock);
886 
888 
890  "Disconnecting queue for peer `%s'\n",
891  GNUNET_i2s (&queue->target));
892  if (NULL != queue->rekey_monotime_sc)
893  {
895  queue->rekey_monotime_sc = NULL;
896  }
897  if (NULL != queue->handshake_monotime_sc)
898  {
900  queue->handshake_monotime_sc = NULL;
901  }
902  if (NULL != queue->handshake_ack_monotime_sc)
903  {
905  queue->handshake_ack_monotime_sc = NULL;
906  }
907  if (NULL != queue->rekey_monotime_get)
908  {
910  queue->rekey_monotime_get = NULL;
911  }
912  if (NULL != queue->handshake_monotime_get)
913  {
915  queue->handshake_monotime_get = NULL;
916  }
917  if (NULL != queue->handshake_ack_monotime_get)
918  {
920  queue->handshake_ack_monotime_get = NULL;
921  }
922  if (NULL != queue->qh)
923  {
925  queue->qh = NULL;
926  }
927  GNUNET_assert (
928  GNUNET_YES ==
931  "# queues active",
933  GNUNET_NO);
934  if (NULL != queue->read_task)
935  {
937  queue->read_task = NULL;
938  }
939  if (NULL != queue->write_task)
940  {
942  queue->write_task = NULL;
943  }
945  {
947  "closing socket failed\n");
948  }
949  gcry_cipher_close (queue->in_cipher);
950  gcry_cipher_close (queue->out_cipher);
951  GNUNET_free (queue->address);
952  if (0 != queue->backpressure)
953  queue->destroyed = GNUNET_YES;
954  else
955  GNUNET_free (queue);
956 
957  if (NULL == lt)
958  return;
959 
960  if ((! shutdown_running) && (NULL == lt->listen_task))
961  {
963  "add read net listen\n");
966  lt->listen_sock,
967  &listen_cb,
968  lt);
969  }
970  else
971  GNUNET_free (lt);
972 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1077
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:41
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 984 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().

988 {
989  struct GNUNET_HashCode mac;
990 
991  GNUNET_CRYPTO_hmac_raw (hmac_secret,
992  sizeof(struct GNUNET_HashCode),
993  buf,
994  buf_size,
995  &mac);
996  /* truncate to `struct GNUNET_ShortHashCode` */
997  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
998  /* ratchet hmac key */
999  GNUNET_CRYPTO_hash (hmac_secret,
1000  sizeof(struct GNUNET_HashCode),
1001  hmac_secret);
1002 }
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:274
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:41
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 1012 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().

1013 {
1014  struct TCPFinish fin;
1015 
1016  memset (&fin, 0, sizeof(fin));
1017  fin.header.size = htons (sizeof(fin));
1018  fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
1019  calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1020  /* if there is any message left in pwrite_buf, we
1021  overwrite it (possibly dropping the last message
1022  from CORE hard here) */
1023  memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1024  queue->pwrite_off = sizeof(fin);
1025  /* This flag will ensure that #queue_write() no longer
1026  notifies CORE about the possibility of sending
1027  more data, and that #queue_write() will call
1028  #queue_destroy() once the @c fin was fully written. */
1029  queue->finishing = GNUNET_YES;
1030 }
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 1041 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().

1042 {
1043  queue->timeout =
1045 }
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:181
#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 1891 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, 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().

1892 {
1893  struct Queue *queue = cls;
1894  struct GNUNET_TIME_Relative left;
1895  ssize_t rcvd;
1896 
1897  queue->read_task = NULL;
1898  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1899  &queue->cread_buf[queue->cread_off],
1900  BUF_SIZE - queue->cread_off);
1902  "Received %lu bytes from TCP queue\n", rcvd);
1903  if (-1 == rcvd)
1904  {
1905  if ((EAGAIN != errno) && (EINTR != errno))
1906  {
1908  queue_finish (queue);
1909  return;
1910  }
1911  /* try again */
1913  queue->read_task =
1914  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1915  return;
1916  }
1917  if (0 != rcvd)
1918  reschedule_queue_timeout (queue);
1919  queue->cread_off += rcvd;
1920  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1921  (queue->cread_off > 0))
1922  {
1923  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1924  queue->cread_off);
1925  size_t done;
1926  size_t total;
1927  size_t old_pread_off = queue->pread_off;
1928 
1929  GNUNET_assert (0 ==
1930  gcry_cipher_decrypt (queue->in_cipher,
1931  &queue->pread_buf[queue->pread_off],
1932  max,
1933  queue->cread_buf,
1934  max));
1935  queue->pread_off += max;
1936  total = 0;
1937  while (0 != (done = try_handle_plaintext (queue)))
1938  {
1939  /* 'done' bytes of plaintext were used, shift buffer */
1940  GNUNET_assert (done <= queue->pread_off);
1941  /* NOTE: this memmove() could possibly sometimes be
1942  avoided if we pass 'total' into try_handle_plaintext()
1943  and use it at an offset into the buffer there! */
1944  memmove (queue->pread_buf,
1945  &queue->pread_buf[done],
1946  queue->pread_off - done);
1947  queue->pread_off -= done;
1948  total += done;
1949  /* The last plaintext was a rekey, abort for now */
1950  if (GNUNET_YES == queue->rekeyed)
1951  break;
1952  }
1953  /* when we encounter a rekey message, the decryption above uses the
1954  wrong key for everything after the rekey; in that case, we have
1955  to re-do the decryption at 'total' instead of at 'max'.
1956  However, we have to take into account that the plaintext buffer may have
1957  already contained data and not jumped too far ahead in the ciphertext.
1958  If there is no rekey and the last message is incomplete (max > total),
1959  it is safe to keep the decryption so we shift by 'max' */
1960  if (GNUNET_YES == queue->rekeyed)
1961  {
1962  max = total - old_pread_off;
1963  queue->rekeyed = GNUNET_NO;
1964  queue->pread_off = 0;
1965  }
1966  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1967  queue->cread_off -= max;
1968  }
1969  if (BUF_SIZE == queue->cread_off)
1970  return; /* buffer full, suspend reading */
1972  if (0 != left.rel_value_us)
1973  {
1974  if (max_queue_length > queue->backpressure)
1975  {
1976  /* continue reading */
1978  queue->read_task =
1979  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1980  }
1981  return;
1982  }
1984  "Queue %p was idle for %s, disconnecting\n",
1985  queue,
1988  GNUNET_YES));
1989  queue_finish (queue);
1990 }
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:783
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.
#define max(x, y)
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:232
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 1065 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().

1066 {
1067  struct Queue *queue = cls;
1068  if (GNUNET_OK != success)
1070  "# messages lost in communicator API towards CORE",
1071  1,
1072  GNUNET_NO);
1073  if (NULL == queue)
1074  return;
1075 
1077  "backpressure %u\n",
1078  queue->backpressure);
1079 
1080  queue->backpressure--;
1081  /* handle deferred queue destruction */
1082  if ((queue->destroyed) && (0 == queue->backpressure))
1083  {
1084  GNUNET_free (queue);
1085  return;
1086  }
1087  else if (GNUNET_YES != queue->destroyed)
1088  {
1089  reschedule_queue_timeout (queue);
1090  /* possibly unchoke reading, now that CORE made progress */
1091  if (NULL == queue->read_task)
1092  queue->read_task =
1094  queue->timeout),
1095  queue->sock,
1096  &queue_read,
1097  queue);
1098  }
1099 }
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:232
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 1112 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().

1115 {
1116  const struct GNUNET_MessageHeader *hdr = plaintext;
1117  int ret;
1118 
1119  if (ntohs (hdr->size) != plaintext_len)
1120  {
1121  /* NOTE: If we ever allow multiple CORE messages in one
1122  BOX, this will have to change! */
1123  GNUNET_break (0);
1124  return;
1125  }
1127  &queue->target,
1128  hdr,
1131  queue);
1132  if (GNUNET_OK == ret)
1133  queue->backpressure++;
1134  GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1135  if (GNUNET_SYSERR == ret)
1137  "# bytes lost due to CORE not running",
1138  plaintext_len,
1139  GNUNET_NO);
1140 }
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 1153 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().

1157 {
1158  char key[256 / 8];
1159  char ctr[128 / 8];
1160 
1161  gcry_cipher_open (cipher,
1162  GCRY_CIPHER_AES256 /* low level: go for speed */,
1163  GCRY_CIPHER_MODE_CTR,
1164  0 /* flags */);
1166  sizeof(key),
1167  "TCP-key",
1168  strlen ("TCP-key"),
1169  dh,
1170  sizeof(*dh),
1171  pid,
1172  sizeof(*pid),
1173  NULL,
1174  0));
1175  gcry_cipher_setkey (*cipher, key, sizeof(key));
1177  sizeof(ctr),
1178  "TCP-ctr",
1179  strlen ("TCP-ctr"),
1180  dh,
1181  sizeof(*dh),
1182  pid,
1183  sizeof(*pid),
1184  NULL,
1185  0));
1186  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1188  GNUNET_CRYPTO_kdf (hmac_key,
1189  sizeof(struct GNUNET_HashCode),
1190  "TCP-hmac",
1191  strlen ("TCP-hmac"),
1192  dh,
1193  sizeof(*dh),
1194  pid,
1195  sizeof(*pid),
1196  NULL,
1197  0));
1198 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue 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
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
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 1207 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().

1208 {
1209  struct Queue *queue = cls;
1210  if (GNUNET_OK != success)
1211  {
1213  "Failed to store rekey monotonic time in PEERSTORE!\n");
1214  }
1215  queue->rekey_monotime_sc = NULL;
1216 }
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(*
1269  rekey_monotonic_time),
1273  queue);
1274 }
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:474
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:

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

1286 {
1287  struct GNUNET_HashCode dh;
1288 
1289  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
1290  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
1291 }
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
static struct GNUNET_PeerIdentity my_identity
Our public key.
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.
enum GNUNET_GenericReturnValue 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:718
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_rekey()

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

Handle rekey message on queue.

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

Parameters
queuethe queue rekey was received on
rekeythe rekey message

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

1304 {
1305  struct TcpRekeySignature thp;
1306 
1308  thp.purpose.size = htonl (sizeof(thp));
1310  "do_rekey size %u\n",
1311  thp.purpose.size);
1312  thp.sender = queue->target;
1314  "sender %s\n",
1315  GNUNET_p2s (&thp.sender.public_key));
1317  "sender %s\n",
1318  GNUNET_p2s (&queue->target.public_key));
1319  thp.receiver = my_identity;
1321  "receiver %s\n",
1322  GNUNET_p2s (&thp.receiver.public_key));
1323  thp.ephemeral = rekey->ephemeral;
1325  "ephemeral %s\n",
1326  GNUNET_e2s (&thp.ephemeral));
1327  thp.monotonic_time = rekey->monotonic_time;
1329  "time %s\n",
1331  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1332  GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1333  if (GNUNET_OK !=
1335  &thp,
1336  &rekey->sender_sig,
1337  &queue->target.public_key))
1338  {
1339  GNUNET_break (0);
1340  queue_finish (queue);
1341  return;
1342  }
1343  queue->rekey_monotonic_time = rekey->monotonic_time;
1345  "transport_tcp_communicator",
1346  &queue->target,
1349  queue);
1350  gcry_cipher_close (queue->in_cipher);
1351  queue->rekeyed = GNUNET_YES;
1352  setup_in_cipher (&rekey->ephemeral, queue);
1353 }
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:474
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 1362 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().

1363 {
1364  struct Queue *queue = cls;
1365 
1366  if (GNUNET_OK != success)
1367  {
1369  "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1370  }
1371  queue->handshake_ack_monotime_sc = NULL;
1372 }
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 1383 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().

1386 {
1387  struct Queue *queue = cls;
1388  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1389  struct GNUNET_TIME_Absolute mt;
1390  const struct GNUNET_PeerIdentity *pid;
1391  struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1392 
1393  (void) emsg;
1394 
1395  handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1396  pid = &queue->target;
1397  if (NULL == record)
1398  {
1399  queue->handshake_ack_monotime_get = NULL;
1400  return;
1401  }
1402  if (sizeof(*mtbe) != record->value_size)
1403  {
1404  GNUNET_break (0);
1405  return;
1406  }
1407  mtbe = record->value;
1408  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1409  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1411  {
1413  "Queue from %s dropped, handshake ack monotime in the past\n",
1414  GNUNET_i2s (&queue->target));
1415  GNUNET_break (0);
1416  queue_finish (queue);
1417  return;
1418  }
1419  queue->handshake_ack_monotime_sc =
1421  "transport_tcp_communicator",
1422  pid,
1424  handshake_ack_monotonic_time,
1425  sizeof(*handshake_ack_monotonic_time),
1428  &
1430  queue);
1431 }
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:474
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:

◆ send_challenge()

static void send_challenge ( struct ChallengeNonceP  challenge,
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 1441 of file gnunet-communicator-tcp.c.

References TCPConfirmationAck::challenge, TcpHandshakeSignature::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 queue_read_kx(), and try_handle_plaintext().

1442 {
1443  struct TCPConfirmationAck tca;
1444  struct TcpHandshakeAckSignature thas;
1445 
1447  "transport",
1448  "sending challenge\n");
1449 
1450  tca.header.type = ntohs (
1452  tca.header.size = ntohs (sizeof(tca));
1453  tca.challenge = challenge;
1454  tca.sender = my_identity;
1455  tca.monotonic_time =
1457  thas.purpose.purpose = htonl (
1459  thas.purpose.size = htonl (sizeof(thas));
1460  thas.sender = my_identity;
1461  thas.receiver = queue->target;
1462  thas.monotonic_time = tca.monotonic_time;
1463  thas.challenge = tca.challenge;
1465  &thas,
1466  &tca.sender_sig);
1467  GNUNET_assert (0 ==
1468  gcry_cipher_encrypt (queue->out_cipher,
1469  &queue->cwrite_buf[queue->cwrite_off],
1470  sizeof(tca),
1471  &tca,
1472  sizeof(tca)));
1473  queue->cwrite_off += sizeof(tca);
1475  "transport",
1476  "sending challenge done\n");
1477 }
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.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
#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 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:590
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:464
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:

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

1488 {
1489  struct GNUNET_HashCode dh;
1490 
1491  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
1492  /* we don't need the private key anymore, drop it! */
1493  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
1494  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1496  queue->rekey_left_bytes =
1498 }
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:181
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.
enum GNUNET_GenericReturnValue 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:758
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.
#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 1508 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().

1509 {
1510  struct TCPRekey rekey;
1511  struct TcpRekeySignature thp;
1512 
1513  GNUNET_assert (0 == queue->pwrite_off);
1514  memset (&rekey, 0, sizeof(rekey));
1516  rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1517  rekey.header.size = ntohs (sizeof(rekey));
1518  GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
1519  rekey.monotonic_time =
1521  thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1522  thp.purpose.size = htonl (sizeof(thp));
1524  "inject_rekey size %u\n",
1525  thp.purpose.size);
1526  thp.sender = my_identity;
1528  "sender %s\n",
1529  GNUNET_p2s (&thp.sender.public_key));
1530  thp.receiver = queue->target;
1532  "receiver %s\n",
1533  GNUNET_p2s (&thp.receiver.public_key));
1534  thp.ephemeral = rekey.ephemeral;
1536  "ephemeral %s\n",
1537  GNUNET_e2s (&thp.ephemeral));
1538  thp.monotonic_time = rekey.monotonic_time;
1540  "time %s\n",
1542  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1544  &thp,
1545  &rekey.sender_sig);
1546  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1547  /* Encrypt rekey message with 'old' cipher */
1548  GNUNET_assert (0 ==
1549  gcry_cipher_encrypt (queue->out_cipher,
1550  &queue->cwrite_buf[queue->cwrite_off],
1551  sizeof(rekey),
1552  &rekey,
1553  sizeof(rekey)));
1554  queue->cwrite_off += sizeof(rekey);
1555  /* Setup new cipher for successive messages */
1556  gcry_cipher_close (queue->out_cipher);
1557  setup_out_cipher (queue);
1558 }
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:474
#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:435
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:213
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:590
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:464
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 1568 of file gnunet-communicator-tcp.c.

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

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

1569 {
1570  struct Queue *queue = cls;
1571  ssize_t sent;
1572  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1573  queue->write_task = NULL;
1574  if (0 != queue->cwrite_off)
1575  {
1576  sent = GNUNET_NETWORK_socket_send (queue->sock,
1577  queue->cwrite_buf,
1578  queue->cwrite_off);
1580  "Sent %lu bytes to TCP queue\n", sent);
1581  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1582  {
1584  queue_destroy (queue);
1585  return;
1586  }
1587  if (sent > 0)
1588  {
1589  size_t usent = (size_t) sent;
1590  queue->cwrite_off -= usent;
1591  memmove (queue->cwrite_buf,
1592  &queue->cwrite_buf[usent],
1593  queue->cwrite_off);
1594  reschedule_queue_timeout (queue);
1595  }
1596  }
1597  /* can we encrypt more? (always encrypt full messages, needed
1598  such that #mq_cancel() can work!) */
1599  if ((0 < queue->rekey_left_bytes) &&
1600  (queue->pwrite_off > 0) &&
1601  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1602  {
1604  "Encrypting %lu bytes\n", queue->pwrite_off);
1605  GNUNET_assert (0 ==
1606  gcry_cipher_encrypt (queue->out_cipher,
1607  &queue->cwrite_buf[queue->cwrite_off],
1608  queue->pwrite_off,
1609  queue->pwrite_buf,
1610  queue->pwrite_off));
1611  if (queue->rekey_left_bytes > queue->pwrite_off)
1612  queue->rekey_left_bytes -= queue->pwrite_off;
1613  else
1614  queue->rekey_left_bytes = 0;
1615  queue->cwrite_off += queue->pwrite_off;
1616  queue->pwrite_off = 0;
1617  }
1618  // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1619  if (((0 == queue->pwrite_off) &&
1620  ((0 == queue->rekey_left_bytes) ||
1621  (0 ==
1623  queue->rekey_time).rel_value_us))))
1624  {
1625  inject_rekey (queue);
1626  }
1627  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1628  (GNUNET_YES == queue->mq_awaits_continue))
1629  {
1630  queue->mq_awaits_continue = GNUNET_NO;
1632  }
1633  /* did we just finish writing 'finish'? */
1634  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1635  {
1637  "Finishing queue\n");
1638  queue_destroy (queue);
1639  return;
1640  }
1641  /* do we care to write more? */
1642  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1643  queue->write_task =
1645  queue->sock,
1646  &queue_write,
1647  queue);
1648 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
uint64_t rel_value_us
The actual value.
int finishing
Did we enqueue a finish message and are closing down the queue?
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:812
#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:232
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:

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

References Queue::address, Queue::address_len, calculate_hmac(), Queue::challenge, Queue::challenge_received, COMMUNICATOR_ADDRESS_PREFIX, Queue::cs, do_rekey(), GNUNET_a2s(), GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, 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_SCHEDULER_add_write_net(), GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_CS_INBOUND, GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, handshake_ack_monotime_cb(), Queue::handshake_ack_monotime_get, TCPBox::hmac, TCPFinish::hmac, Queue::in_hmac, INITIAL_CORE_KX_SIZE, Queue::mq, my_identity, Queue::nt, pass_plaintext_to_core(), Queue::pread_buf, Queue::pread_off, Queue::qh, queue_destroy(), queue_finish(), queue_write(), send_challenge(), size, GNUNET_MessageHeader::size, Queue::sock, Queue::target, type, GNUNET_MessageHeader::type, unverified_size, and Queue::write_task.

Referenced by queue_read().

1660 {
1661  const struct GNUNET_MessageHeader *hdr =
1662  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1663  const struct TCPConfirmationAck *tca = (const struct
1664  TCPConfirmationAck *) queue->pread_buf;
1665  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1666  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1667  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1668  struct TCPRekey rekeyz;
1669  struct TCPFinish finz;
1670  struct GNUNET_ShortHashCode tmac;
1671  uint16_t type;
1672  size_t size = 0; /* make compiler happy */
1673  struct TcpHandshakeAckSignature thas;
1674  const struct ChallengeNonceP challenge = queue->challenge;
1675 
1677  "try handle plaintext!\n");
1678 
1679  if ((sizeof(*hdr) > queue->pread_off))
1680  {
1682  "Handling plaintext, not even a header!\n");
1683  return 0; /* not even a header */
1684  }
1685 
1687  {
1689  "Already received data of size %lu bigger than KX size %lu!\n",
1692  GNUNET_break_op (0);
1693  queue_finish (queue);
1694  return 0;
1695  }
1696 
1697  type = ntohs (hdr->type);
1698  switch (type)
1699  {
1702  "start processing ack\n");
1703  if (sizeof(*tca) > queue->pread_off)
1704  {
1706  "Handling plaintext size of tca greater than pread offset.\n");
1707  return 0;
1708  }
1709  if (ntohs (hdr->size) != sizeof(*tca))
1710  {
1712  "Handling plaintext size does not match message type.\n");
1713  GNUNET_break_op (0);
1714  queue_finish (queue);
1715  return 0;
1716  }
1717 
1718  thas.purpose.purpose = htonl (
1720  thas.purpose.size = htonl (sizeof(thas));
1721  thas.sender = tca->sender;
1722  thas.receiver = my_identity;
1723  thas.monotonic_time = tca->monotonic_time;
1724  thas.challenge = tca->challenge;
1725 
1728  &thas,
1729  &tca->sender_sig,
1730  &tca->sender.public_key))
1731  {
1733  "Verification of signature failed!\n");
1734  GNUNET_break (0);
1735  queue_finish (queue);
1736  return 0;
1737  }
1738  if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1739  {
1741  "Challenge in TCPConfirmationAck not correct!\n");
1742  GNUNET_break (0);
1743  queue_finish (queue);
1744  return 0;
1745  }
1746 
1748  "transport_tcp_communicator",
1749  &queue->target,
1751  &
1753  queue);
1754 
1756  "Handling plaintext, ack processed!\n");
1757 
1758  if (GNUNET_TRANSPORT_CS_INBOUND == queue->cs)
1759  {
1760  send_challenge (queue->challenge_received, queue);
1761  queue->write_task =
1763  queue->sock,
1764  &queue_write,
1765  queue);
1766  }
1767 
1768  unverified_size = -1;
1769 
1770  char *foreign_addr;
1771 
1772  switch (queue->address->sa_family)
1773  {
1774  case AF_INET:
1775  GNUNET_asprintf (&foreign_addr,
1776  "%s-%s",
1778  GNUNET_a2s (queue->address, queue->address_len));
1779  break;
1780 
1781  case AF_INET6:
1782  GNUNET_asprintf (&foreign_addr,
1783  "%s-%s",
1785  GNUNET_a2s (queue->address, queue->address_len));
1786  break;
1787 
1788  default:
1789  GNUNET_assert (0);
1790  }
1791 
1793  &queue->target,
1794  foreign_addr,
1795  UINT32_MAX, /* no MTU */
1797  0, /* Priority */
1798  queue->nt,
1799  queue->cs,
1800  queue->mq);
1801 
1802  GNUNET_free (foreign_addr);
1803 
1804  size = ntohs (hdr->size);
1805  break;
1807  /* Special case: header size excludes box itself! */
1808  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1809  return 0;
1810  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1811  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1812  {
1813  GNUNET_break_op (0);
1814  queue_finish (queue);
1815  return 0;
1816  }
1817  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1818  size = ntohs (hdr->size) + sizeof(*box);
1820  "Handling plaintext, box processed!\n");
1821  break;
1822 
1824  if (sizeof(*rekey) > queue->pread_off)
1825  return 0;
1826  if (ntohs (hdr->size) != sizeof(*rekey))
1827  {
1828  GNUNET_break_op (0);
1829  queue_finish (queue);
1830  return 0;
1831  }
1832  rekeyz = *rekey;
1833  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1834  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1835  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1836  {
1837  GNUNET_break_op (0);
1838  queue_finish (queue);
1839  return 0;
1840  }
1841  do_rekey (queue, rekey);
1842  size = ntohs (hdr->size);
1844  "Handling plaintext, rekey processed!\n");
1845  break;
1846 
1848  if (sizeof(*fin) > queue->pread_off)
1849  return 0;
1850  if (ntohs (hdr->size) != sizeof(*fin))
1851  {
1852  GNUNET_break_op (0);
1853  queue_finish (queue);
1854  return 0;
1855  }
1856  finz = *fin;
1857  memset (&finz.hmac, 0, sizeof(finz.hmac));
1858  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1859  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1860  {
1861  GNUNET_break_op (0);
1862  queue_finish (queue);
1863  return 0;
1864  }
1865  /* handle FINISH by destroying queue */
1866  queue_destroy (queue);
1868  "Handling plaintext, finish processed!\n");
1869  break;
1870 
1871  default:
1873  "Handling plaintext, nothing processed!\n");
1874  GNUNET_break_op (0);
1875  queue_finish (queue);
1876  return 0;
1877  }
1878  GNUNET_assert (0 != size);
1879  if (-1 != unverified_size)
1880  unverified_size += size;
1881  return size;
1882 }
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.
socklen_t address_len
Length of the address.
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.
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
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.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
#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 COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
this is an inbound connection (communicator initiated)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
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.
struct ChallengeNonceP challenge_received
Challenge value received.
#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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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.
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...
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.
struct sockaddr * address
Address of the other peer.
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
TCP rekey message box.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
#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.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
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.
static void send_challenge(struct ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
#define GNUNET_free(ptr)
Wrapper around free.
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:

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

2003 {
2004  struct sockaddr *in;
2005 
2006  v6.sin6_family = AF_INET6;
2007  v6.sin6_port = htons ((uint16_t) port);
2008 #if HAVE_SOCKADDR_IN_SIN_LEN
2009  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
2010 #endif
2011  v6.sin6_flowinfo = 0;
2012  v6.sin6_scope_id = 0;
2013  in = GNUNET_memdup (&v6, sizeof(v6));
2014  *sock_len = sizeof(struct sockaddr_in6);
2015 
2016  return in;
2017 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
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 2028 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().

2030 {
2031  struct sockaddr *in;
2032 
2033  v4.sin_family = AF_INET;
2034  v4.sin_port = htons ((uint16_t) port);
2035 #if HAVE_SOCKADDR_IN_SIN_LEN
2036  v4.sin_len = sizeof(struct sockaddr_in);
2037 #endif
2038  in = GNUNET_memdup (&v4, sizeof(v4));
2039  *sock_len = sizeof(struct sockaddr_in);
2040  return in;
2041 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
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 2051 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().

2052 {
2053  struct PortOnlyIpv4Ipv6 *po;
2054  struct sockaddr_in *i4;
2055  struct sockaddr_in6 *i6;
2056  socklen_t sock_len_ipv4;
2057  socklen_t sock_len_ipv6;
2058 
2059  /* interpreting value as just a PORT number */
2060  if (*port > UINT16_MAX)
2061  {
2063  "BINDTO specification `%s' invalid: value too large for port\n",
2064  bindto);
2065  return NULL;
2066  }
2067 
2068  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2069 
2070  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2071  (GNUNET_YES ==
2074  "DISABLE_V6")))
2075  {
2076  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2077  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2078  *port);
2079  po->addr_len_ipv4 = sock_len_ipv4;
2080  }
2081  else
2082  {
2083 
2084  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2085  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2086  *port);
2087  po->addr_len_ipv4 = sock_len_ipv4;
2088 
2089  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2090  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2091  *port);
2092 
2093  po->addr_len_ipv6 = sock_len_ipv6;
2094 
2095  GNUNET_free (i6);
2096  }
2097 
2098  GNUNET_free (i4);
2099 
2100  return po;
2101 }
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:83
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue 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".
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 *`.
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 2111 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().

2112 {
2113 
2114  char *start;
2115  char *token;
2116  char *cp;
2117  char *rest = NULL;
2118 
2120  "extract address with bindto %s\n",
2121  bindto);
2122 
2123  if (NULL == bindto)
2125  "bindto is NULL\n");
2126 
2127  cp = GNUNET_strdup (bindto);
2128 
2130  "extract address 2\n");
2131 
2132  start = cp;
2133  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2134  {
2135  start++; /* skip over '['*/
2136  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2137  }
2138  else
2139  {
2140  token = strtok_r (cp, "]", &rest);
2141  if (strlen (bindto) == strlen (token))
2142  {
2143  token = strtok_r (cp, ":", &rest);
2144  }
2145  else
2146  {
2147  token++;
2148  return token;
2149  }
2150  }
2151 
2153  "extract address 3\n");
2155  "extract address with start %s\n",
2156  start);
2157 
2158  return start;
2159 }
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 2169 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().

2170 {
2171  unsigned int port;
2172  char dummy[2];
2173  char *token;
2174  char *addr;
2175  char *colon;
2176  char *cp;
2177  char *rest = NULL;
2178 
2179  if (NULL != addr_and_port)
2180  {
2181  cp = GNUNET_strdup (addr_and_port);
2182  token = strtok_r (cp, "]", &rest);
2183  if (strlen (addr_and_port) == strlen (token))
2184  {
2185  colon = strrchr (cp, ':');
2186  if (NULL == colon)
2187  {
2188  return 0;
2189  }
2190  addr = colon;
2191  addr++;
2192  }
2193  else
2194  {
2195  token = strtok_r (NULL, "]", &rest);
2196  if (NULL == token)
2197  {
2198  return 0;
2199  }
2200  else
2201  {
2202  addr = token;
2203  addr++;
2204  }
2205  }
2206 
2207 
2208  if (1 == sscanf (addr, "%u%1s", &port, dummy))
2209  {
2210  /* interpreting value as just a PORT number */
2211  if (port > UINT16_MAX)
2212  {
2214  "Port `%u' invalid: value too large for port\n",
2215  port);
2216  // GNUNET_free (cp);
2217  return 0;
2218  }
2219  }
2220  else
2221  {
2223  "BINDTO specification invalid: last ':' not followed by number\n");
2224  // GNUNET_free (cp);
2225  return 0;
2226  }
2227  }
2228  else
2229  {
2231  "return 0\n");
2232  /* interpret missing port as 0, aka pick any free one */
2233  port = 0;
2234  }
2235 
2236 
2237  return port;
2238 }
#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:83
#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 2249 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().

2250 {
2251  struct sockaddr *in;
2252  unsigned int port;
2253  struct sockaddr_in v4;
2254  struct sockaddr_in6 v6;
2255  const char *start;
2256 
2257  // cp = GNUNET_strdup (bindto);
2258  start = extract_address (bindto);
2259 
2261  "start %s\n",
2262  start);
2263 
2265  "!bindto %s\n",
2266  bindto);
2267 
2268 
2269  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2270  {
2271  // colon = strrchr (cp, ':');
2272  port = extract_port (bindto);
2273 
2275  "port %u\n",
2276  port);
2277 
2278  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2279  }
2280  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2281  {
2282  // colon = strrchr (cp, ':');
2283  port = extract_port (bindto);
2284  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2285  }
2286  else
2287  {
2288  GNUNET_assert (0);
2289  }
2290 
2291  // GNUNET_free (start);
2292 
2293  return in;
2294 }
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:83
#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:

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

2309 {
2310  struct Queue *queue = impl_state;
2311  uint16_t msize = ntohs (msg->size);
2312  struct TCPBox box;
2314  "In MQ send. Queue finishing: %s; write task running: %s\n",
2315  (GNUNET_YES == queue->finishing) ? "yes" : "no",
2316  (NULL == queue->write_task) ? "yes" : "no");
2317  GNUNET_assert (mq == queue->mq);
2318  queue->mq_awaits_continue = GNUNET_YES;
2319  if (GNUNET_YES == queue->finishing)
2320  return; /* this queue is dying, drop msg */
2321  GNUNET_assert (0 == queue->pwrite_off);
2322  box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
2323  box.header.size = htons (msize);
2324  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2325  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2326  queue->pwrite_off += sizeof(box);
2327  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2328  queue->pwrite_off += msize;
2330  "%lu bytes of plaintext to send\n", queue->pwrite_off);
2331  GNUNET_assert (NULL != queue->sock);
2332  if (NULL == queue->write_task)
2333  queue->write_task =
2335  queue->sock,
2336  &queue_write,
2337  queue);
2338 }
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 2350 of file gnunet-communicator-tcp.c.

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

Referenced by boot_queue().

2351 {
2352  struct Queue *queue = impl_state;
2353 
2354  if (mq == queue->mq)
2355  {
2356  queue->mq = NULL;
2357  queue_finish (queue);
2358  }
2359 }
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 2369 of file gnunet-communicator-tcp.c.

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

Referenced by boot_queue().

2370 {
2371  struct Queue *queue = impl_state;
2372 
2373  GNUNET_assert (0 != queue->pwrite_off);
2374  queue->pwrite_off = 0;
2375 }
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 2388 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().

2389 {
2390  struct Queue *queue = cls;
2391 
2393  "MQ error in queue to %s: %d\n",
2394  GNUNET_i2s (&queue->target),
2395  (int) error);
2396  queue_finish (queue);
2397 }
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)
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 2408 of file gnunet-communicator-tcp.c.

References Queue::address, Queue::address_len, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_MQ_queue_for_callbacks(), GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_STATISTICS_set(), GNUNET_TIME_relative_to_absolute(), Queue::mq, mq_cancel(), mq_destroy(), mq_error(), mq_send(), Queue::nt, Queue::target, and Queue::timeout.

Referenced by mq_init(), and proto_read_kx().

2409 {
2410  queue->nt =
2413  queue_map,
2414  &queue->target,
2415  queue,
2418  "# queues active",
2420  GNUNET_NO);
2421  queue->timeout =
2424  &mq_destroy,
2425  &mq_cancel,
2426  queue,
2427  NULL,
2428  &mq_error,
2429  queue);
2430  /* { */
2431  /* char *foreign_addr; */
2432 
2433  /* switch (queue->address->sa_family) */
2434  /* { */
2435  /* case AF_INET: */
2436  /* GNUNET_asprintf (&foreign_addr, */
2437  /* "%s-%s", */
2438  /* COMMUNICATOR_ADDRESS_PREFIX, */
2439  /* GNUNET_a2s (queue->address, queue->address_len)); */
2440  /* break; */
2441 
2442  /* case AF_INET6: */
2443  /* GNUNET_asprintf (&foreign_addr, */
2444  /* "%s-%s", */
2445  /* COMMUNICATOR_ADDRESS_PREFIX, */
2446  /* GNUNET_a2s (queue->address, queue->address_len)); */
2447  /* break; */
2448 
2449  /* default: */
2450  /* GNUNET_assert (0); */
2451  /* } */
2452  /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */
2453  /* &queue->target, */
2454  /* foreign_addr, */
2455  /* 0 /\* no MTU *\/, */
2456  /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */
2457  /* 0, /\* Priority *\/ */
2458  /* queue->nt, */
2459  /* queue->cs, */
2460  /* queue->mq); */
2461  /* GNUNET_free (foreign_addr); */
2462  /* } */
2463 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:181
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
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct sockaddr * address
Address of the other peer.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
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.
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 2477 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().

2479 {
2480  struct TcpHandshakeSignature ths;
2481  struct TCPConfirmation tc;
2482 
2483  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2484  queue->cwrite_off = sizeof(*epub);
2485  /* compute 'tc' and append in encrypted format to cwrite_buf */
2486  tc.sender = my_identity;
2487  tc.monotonic_time =
2490  &tc.challenge,
2491  sizeof(tc.challenge));
2492  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2493  ths.purpose.size = htonl (sizeof(ths));
2494  ths.sender = my_identity;
2495  ths.receiver = queue->target;
2496  ths.ephemeral = *epub;
2497  ths.monotonic_time = tc.monotonic_time;
2498  ths.challenge = tc.challenge;
2500  &ths,
2501  &tc.sender_sig);
2502  GNUNET_assert (0 ==
2503  gcry_cipher_encrypt (queue->out_cipher,
2504  &queue->cwrite_buf[queue->cwrite_off],
2505  sizeof(tc),
2506  &tc,
2507  sizeof(tc)));
2508  queue->challenge = tc.challenge;
2509  queue->cwrite_off += sizeof(tc);
2510 
2512  "transport",
2513  "handshake written\n");
2514 }
#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:590
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:464
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 2525 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().

2526 {
2527  struct GNUNET_CRYPTO_EcdhePublicKey epub;
2528 
2531  setup_out_cipher (queue);
2532  transmit_kx (queue, &epub);
2533 }
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:435
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:213
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 2542 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().

2543 {
2544  struct Queue *queue = cls;
2545  if (GNUNET_OK != success)
2546  {
2548  "Failed to store handshake monotonic time in PEERSTORE!\n");
2549  }
2550  queue->handshake_monotime_sc = NULL;
2551 }
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 2562 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().

2565 {
2566  struct Queue *queue = cls;
2567  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2568  struct GNUNET_TIME_Absolute mt;
2569  const struct GNUNET_PeerIdentity *pid;
2570  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2571 
2572  (void) emsg;
2573 
2574  handshake_monotonic_time = &queue->handshake_monotonic_time;
2575  pid = &queue->target;
2576  if (NULL == record)
2577  {
2578  queue->handshake_monotime_get = NULL;
2579  return;
2580  }
2581  if (sizeof(*mtbe) != record->value_size)
2582  {
2583  GNUNET_break (0);
2584  return;
2585  }
2586  mtbe = record->value;
2587  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2588  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2590  {
2592  "Queue from %s dropped, handshake monotime in the past\n",
2593  GNUNET_i2s (&queue->target));
2594  GNUNET_break (0);
2595  queue_finish (queue);
2596  return;
2597  }
2599  "transport_tcp_communicator",
2600  pid,
2602  handshake_monotonic_time,
2603  sizeof(
2604  handshake_monotonic_time),
2607  &
2609  queue);
2610 }
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:474
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 2625 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().

2628 {
2629  struct TcpHandshakeSignature ths;
2630 
2631  GNUNET_assert (
2632  0 ==
2633  gcry_cipher_decrypt (queue->in_cipher,
2634  tc,
2635  sizeof(*tc),
2636  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2637  sizeof(*tc)));
2638  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2639  ths.purpose.size = htonl (sizeof(ths));
2640  ths.sender = tc->sender;
2641  ths.receiver = my_identity;
2642  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2643  ths.monotonic_time = tc->monotonic_time;
2644  ths.challenge = tc->challenge;
2647  &ths,
2648  &tc->sender_sig,
2649  &tc->sender.public_key);
2651  "transport_tcp_communicator",
2652  &queue->target,
2654  &
2656  queue);
2657 }
#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 2666 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().

2667 {
2668  if (NULL != pq->listen_sock)
2669  {
2671  pq->listen_sock = NULL;
2672  }
2674  GNUNET_free (pq->address);
2676  GNUNET_free (pq);
2677 }
#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:

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

References Queue::address, ProtoQueue::address, Queue::address_len, ProtoQueue::address_len, boot_queue(), TCPConfirmation::challenge, Queue::challenge_received, Queue::cs, 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, 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().

2688 {
2689  struct ProtoQueue *pq = cls;
2690  ssize_t rcvd;
2691  struct GNUNET_TIME_Relative left;
2692  struct Queue *queue;
2693  struct TCPConfirmation tc;
2694 
2695  pq->read_task = NULL;
2697  if (0 == left.rel_value_us)
2698  {
2699  free_proto_queue (pq);
2700  return;
2701  }
2702  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2703  &pq->ibuf[pq->ibuf_off],
2704  sizeof(pq->ibuf) - pq->ibuf_off);
2706  "Received %lu bytes for KX\n", rcvd);
2707  if (-1 == rcvd)
2708  {
2709  if ((EAGAIN != errno) && (EINTR != errno))
2710  {
2712  free_proto_queue (pq);
2713  return;
2714  }
2715  /* try again */
2716  pq->read_task =
2718  return;
2719  }
2720  pq->ibuf_off += rcvd;
2721  if (pq->ibuf_off > sizeof(pq->ibuf))
2722  {
2723  /* read more */
2724  pq->read_task =
2726  return;
2727  }
2728  /* we got all the data, let's find out who we are talking to! */
2729  queue = GNUNET_new (struct Queue);
2730  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2731  queue);
2732  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2733  {
2735  "Invalid TCP KX received from %s\n",
2736  GNUNET_a2s (queue->address, queue->address_len));
2737  gcry_cipher_close (queue->in_cipher);
2738  GNUNET_free (queue);
2739  free_proto_queue (pq);
2740  return;
2741  }
2742  queue->address = pq->address; /* steals reference */
2743  queue->address_len = pq->address_len;
2744  queue->target = tc.sender;
2745  queue->listen_sock = pq->listen_sock;
2746  queue->sock = pq->sock;
2747 
2748 
2750  "start kx proto\n");
2751 
2752  start_initial_kx_out (queue);
2754  boot_queue (queue);
2755  queue->read_task =
2757  queue->sock,
2758  &queue_read,
2759  queue);
2760  queue->write_task =
2762  queue->sock,
2763  &queue_write,
2764  queue);
2765  // TODO To early! Move it somewhere else.
2766  // send_challenge (tc.challenge, queue);
2767  queue->challenge_received = tc.challenge;
2768 
2770  GNUNET_free (pq);
2771 }
#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.
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:783
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 ChallengeNonceP challenge_received
Challenge value received.
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.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
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 boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
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:232
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 2836 of file gnunet-communicator-tcp.c.

References Queue::address, Queue::address_len, BUF_SIZE, TCPConfirmation::challenge, 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_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, INITIAL_KX_SIZE, queue(), queue_destroy(), queue_read(), queue_write(), Queue::read_task, GNUNET_TIME_Relative::rel_value_us, reschedule_queue_timeout(), send_challenge(), TCPConfirmation::sender, setup_in_cipher(), Queue::sock, Queue::target, Queue::timeout, and Queue::write_task.

Referenced by mq_init().

2837 {
2838  struct Queue *queue = cls;
2839  ssize_t rcvd;
2840  struct GNUNET_TIME_Relative left;
2841  struct TCPConfirmation tc;
2842 
2843  queue->read_task = NULL;
2845  if (0 == left.rel_value_us)
2846  {
2847  queue_destroy (queue);
2848  return;
2849  }
2850  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2851  &queue->cread_buf[queue->cread_off],
2852  BUF_SIZE - queue->cread_off);
2854  "Received %lu bytes for KX\n",
2855  rcvd);
2856  if (-1 == rcvd)
2857  {
2858  if ((EAGAIN != errno) && (EINTR != errno))
2859  {
2861  queue_destroy (queue);
2862  return;
2863  }
2864  queue->read_task =
2865  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2866  return;
2867  }
2868  queue->cread_off += rcvd;
2869  if (queue->cread_off < INITIAL_KX_SIZE)
2870  {
2871  /* read more */
2872  queue->read_task =
2873  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2874  return;
2875  }
2876  /* we got all the data, let's find out who we are talking to! */
2878  queue->cread_buf,
2879  queue);
2880  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2881  {
2883  "Invalid TCP KX received from %s\n",
2884  GNUNET_a2s (queue->address, queue->address_len));
2885  queue_destroy (queue);
2886  return;
2887  }
2888  if (0 !=
2889  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2890  {
2892  "Invalid sender in TCP KX received from %s\n",
2893  GNUNET_a2s (queue->address, queue->address_len));
2894  queue_destroy (queue);
2895  return;
2896  }
2897  send_challenge (tc.challenge, queue);
2898  queue->write_task =
2900  queue->sock,
2901  &queue_write,
2902  queue);
2903 
2904  /* update queue timeout */
2905  reschedule_queue_timeout (queue);
2906  /* prepare to continue with regular read task immediately */
2907  memmove (queue->cread_buf,
2908  &queue->cread_buf[INITIAL_KX_SIZE],
2909  queue->cread_off - (INITIAL_KX_SIZE));
2911  "cread_off is %lu bytes before adjusting\n",
2912  queue->cread_off);
2913  queue->cread_off -= INITIAL_KX_SIZE;
2915  "cread_off set to %lu bytes\n",
2916  queue->cread_off);
2917  if (0 <= queue->cread_off)
2918  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2919 }
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:783
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.
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
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
#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.
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.
The identity of the host (wraps the signing key of the peer).
struct sockaddr * address
Address of the other peer.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
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.
static void send_challenge(struct ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
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:

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

References Queue::address, Queue::address_len, boot_queue(), COMMUNICATOR_ADDRESS_PREFIX, Queue::cs, 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().

2942 {
2943  struct Queue *queue;
2944  const char *path;
2945  struct sockaddr *in;
2946  socklen_t in_len = 0;
2947  struct GNUNET_NETWORK_Handle *sock;
2948 
2950  "Connecting to %s\n", address);
2951  if (0 != strncmp (address,
2953  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2954  {
2955  GNUNET_break_op (0);
2956  return GNUNET_SYSERR;
2957  }
2958  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2959  in = tcp_address_to_sockaddr (path, &in_len);
2960 
2961  if (NULL == in)
2962  {
2964  "Failed to setup TCP socket address\n");
2965  return GNUNET_SYSERR;
2966  }
2967 
2969  "in %s\n",
2970  GNUNET_a2s (in, in_len));
2971 
2972  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2973  if (NULL == sock)
2974  {
2976  "socket(%d) failed: %s",
2977  in->sa_family,
2978  strerror (errno));
2979  GNUNET_free (in);
2980  return GNUNET_SYSERR;
2981  }
2982  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2983  (errno != EINPROGRESS))
2984  {
2986  "connect to `%s' failed: %s",
2987  address,
2988  strerror (errno));
2990  GNUNET_free (in);
2991  return GNUNET_SYSERR;
2992  }
2993 
2994  queue = GNUNET_new (struct Queue);
2995  queue->target = *peer;
2996  queue->address = in;
2997  queue->address_len = in_len;
2998  queue->sock = sock;
3000  boot_queue (queue);
3001  // queue->mq_awaits_continue = GNUNET_YES;
3002  queue->read_task =
3004  queue->sock,
3005  &queue_read_kx,
3006  queue);
3007 
3008 
3010  "start kx mq_init\n");
3011 
3012  start_initial_kx_out (queue);
3013  queue->write_task =
3015  queue->sock,
3016  &queue_write,
3017  queue);
3018  return GNUNET_OK;
3019 }
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...
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)
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
#define GNUNET_log(kind,...)
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
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:909
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 3031 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().

3034 {
3035  struct ListenTask *lt = value;
3036 
3037  (void) cls;
3038  (void) key;
3039  if (NULL != lt->listen_task)
3040  {
3042  lt->listen_task = NULL;
3043  }
3044  if (NULL != lt->listen_sock)
3045  {
3047  lt->listen_sock = NULL;
3048  }
3049  return GNUNET_OK;
3050 }
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 3062 of file gnunet-communicator-tcp.c.

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

Referenced by do_shutdown().

3065 {
3066  struct Queue *queue = value;
3067 
3068  (void) cls;
3069  (void) target;
3070  queue_destroy (queue);
3071  return GNUNET_OK;
3072 }
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 3081 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().

3082 {
3084  "Shutdown %s!\n",
3085  shutdown_running ? "running" : "not running");
3086 
3088  return;
3089  else
3091 
3092  while (NULL != proto_head)
3094  if (NULL != nat)
3095  {
3097  nat = NULL;
3098  }
3103  if (NULL != ch)
3104  {
3106  ch = NULL;
3107  }
3108  if (NULL != stats)
3109  {
3111  stats = NULL;
3112  }
3113  if (NULL != my_private_key)
3114  {
3116  my_private_key = NULL;
3117  }
3118  if (NULL != is)
3119  {
3121  is = NULL;
3122  }
3123  if (NULL != peerstore)
3124  {
3126  peerstore = NULL;
3127  }
3128  if (NULL != resolve_request_handle)
3129  {
3131  resolve_request_handle = NULL;
3132  }
3134  "Shutdown done!\n");
3135 }
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 3150 of file gnunet-communicator-tcp.c.

References GNUNET_break_op.

Referenced by init_socket().

3153 {
3154  (void) cls;
3155  (void) sender;
3156  (void) msg;
3157  GNUNET_break_op (0);
3158 }
#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 3175 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().

3181 {
3182  char *my_addr;
3184 
3186  "nat address cb %s %s\n",
3187  add_remove ? "add" : "remove",
3188  GNUNET_a2s (addr, addrlen));
3189 
3190  if (GNUNET_YES == add_remove)
3191  {
3192  enum GNUNET_NetworkType nt;
3193 
3194  GNUNET_asprintf (&my_addr,
3195  "%s-%s",
3197  GNUNET_a2s (addr, addrlen));
3198  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3199  ai =
3201  my_addr,
3202  nt,
3204  GNUNET_free (my_addr);
3205  *app_ctx = ai;
3206  }
3207  else
3208  {
3209  ai = *app_ctx;
3211  *app_ctx = NULL;
3212  }
3213 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer...
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#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 3220 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().

3221