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 2779 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().

2780 {
2781  struct sockaddr_storage in;
2782  socklen_t addrlen;
2783  struct GNUNET_NETWORK_Handle *sock;
2784  struct ProtoQueue *pq;
2785  struct ListenTask *lt;
2786 
2788  "listen_cb\n");
2789 
2790  lt = cls;
2791 
2792  lt->listen_task = NULL;
2793  GNUNET_assert (NULL != lt->listen_sock);
2794  addrlen = sizeof(in);
2795  memset (&in, 0, sizeof(in));
2797  (struct sockaddr*) &in,
2798  &addrlen);
2799  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2800  return; /* system limit reached, wait until connection goes down */
2802  lt->listen_sock,
2803  &listen_cb,
2804  lt);
2805  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2806  return;
2807  if (NULL == sock)
2808  {
2810  return;
2811  }
2812  pq = GNUNET_new (struct ProtoQueue);
2813  pq->address_len = addrlen;
2814  pq->address = GNUNET_memdup (&in, addrlen);
2816  pq->sock = sock;
2818  pq->sock,
2819  &proto_read_kx,
2820  pq);
2822 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue...
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
Handle for an incoming connection where we do not yet have enough information to setup a full queue...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:430
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct sockaddr * address
Address of the other peer.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:52
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
static struct ProtoQueue * proto_head
Protoqueues DLL head.
Struct to use as closure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_destroy()

static void queue_destroy ( struct Queue queue)
static

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

Parameters
queuequeue to close down

Definition at line 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_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 
882  sizeof(queue->listen_sock),
883  &h_sock);
884 
886 
888  "Disconnecting queue for peer `%s'\n",
889  GNUNET_i2s (&queue->target));
890  if (NULL != queue->rekey_monotime_sc)
891  {
893  queue->rekey_monotime_sc = NULL;
894  }
895  if (NULL != queue->handshake_monotime_sc)
896  {
898  queue->handshake_monotime_sc = NULL;
899  }
900  if (NULL != queue->handshake_ack_monotime_sc)
901  {
903  queue->handshake_ack_monotime_sc = NULL;
904  }
905  if (NULL != queue->rekey_monotime_get)
906  {
908  queue->rekey_monotime_get = NULL;
909  }
910  if (NULL != queue->handshake_monotime_get)
911  {
913  queue->handshake_monotime_get = NULL;
914  }
915  if (NULL != queue->handshake_ack_monotime_get)
916  {
918  queue->handshake_ack_monotime_get = NULL;
919  }
920  if (NULL != queue->qh)
921  {
923  queue->qh = NULL;
924  }
925  GNUNET_assert (
926  GNUNET_YES ==
929  "# queues active",
931  GNUNET_NO);
932  if (NULL != queue->read_task)
933  {
935  queue->read_task = NULL;
936  }
937  if (NULL != queue->write_task)
938  {
940  queue->write_task = NULL;
941  }
943  {
945  "closing socket failed\n");
946  }
947  gcry_cipher_close (queue->in_cipher);
948  gcry_cipher_close (queue->out_cipher);
949  GNUNET_free (queue->address);
950  if (0 != queue->backpressure)
951  queue->destroyed = GNUNET_YES;
952  else
953  GNUNET_free (queue);
954 
955  if (NULL == lt)
956  return;
957 
958  if ((! shutdown_running) && (NULL == lt->listen_task))
959  {
961  "add read net listen\n");
964  lt->listen_sock,
965  &listen_cb,
966  lt);
967  }
968  else
969  GNUNET_free (lt);
970 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c: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 982 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().

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

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

1040 {
1041  queue->timeout =
1043 }
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer...
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read()

static void queue_read ( void *  cls)
static

Queue read task.

If we hit the timeout, disconnect it

Parameters
clsthe struct Queue * to disconnect

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

1889 {
1890  struct Queue *queue = cls;
1891  struct GNUNET_TIME_Relative left;
1892  ssize_t rcvd;
1893 
1894  queue->read_task = NULL;
1895  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1896  &queue->cread_buf[queue->cread_off],
1897  BUF_SIZE - queue->cread_off);
1899  "Received %lu bytes from TCP queue\n", rcvd);
1900  if (-1 == rcvd)
1901  {
1902  if ((EAGAIN != errno) && (EINTR != errno))
1903  {
1905  queue_finish (queue);
1906  return;
1907  }
1908  /* try again */
1910  queue->read_task =
1911  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1912  return;
1913  }
1914  if (0 != rcvd)
1915  reschedule_queue_timeout (queue);
1916  queue->cread_off += rcvd;
1917  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1918  (queue->cread_off > 0))
1919  {
1920  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1921  queue->cread_off);
1922  size_t done;
1923  size_t total;
1924  size_t old_pread_off = queue->pread_off;
1925 
1926  GNUNET_assert (0 ==
1927  gcry_cipher_decrypt (queue->in_cipher,
1928  &queue->pread_buf[queue->pread_off],
1929  max,
1930  queue->cread_buf,
1931  max));
1932  queue->pread_off += max;
1933  total = 0;
1934  while (0 != (done = try_handle_plaintext (queue)))
1935  {
1936  /* 'done' bytes of plaintext were used, shift buffer */
1937  GNUNET_assert (done <= queue->pread_off);
1938  /* NOTE: this memmove() could possibly sometimes be
1939  avoided if we pass 'total' into try_handle_plaintext()
1940  and use it at an offset into the buffer there! */
1941  memmove (queue->pread_buf,
1942  &queue->pread_buf[done],
1943  queue->pread_off - done);
1944  queue->pread_off -= done;
1945  total += done;
1946  /* The last plaintext was a rekey, abort for now */
1947  if (GNUNET_YES == queue->rekeyed)
1948  break;
1949  }
1950  /* when we encounter a rekey message, the decryption above uses the
1951  wrong key for everything after the rekey; in that case, we have
1952  to re-do the decryption at 'total' instead of at 'max'.
1953  However, we have to take into account that the plaintext buffer may have
1954  already contained data and not jumpt too far ahead in the ciphertext.
1955  If there is no rekey and the last message is incomplete (max > total),
1956  it is safe to keep the decryption so we shift by 'max' */
1957  if (GNUNET_YES == queue->rekeyed)
1958  {
1959  max = total - old_pread_off;
1960  queue->rekeyed = GNUNET_NO;
1961  queue->pread_off = 0;
1962  }
1963  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1964  queue->cread_off -= max;
1965  }
1966  if (BUF_SIZE == queue->cread_off)
1967  return; /* buffer full, suspend reading */
1969  if (0 != left.rel_value_us)
1970  {
1971  if (max_queue_length > queue->backpressure)
1972  {
1973  /* continue reading */
1975  queue->read_task =
1976  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1977  }
1978  return;
1979  }
1981  "Queue %p was idle for %s, disconnecting\n",
1982  queue,
1985  GNUNET_YES));
1986  queue_finish (queue);
1987 }
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:331
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_read_finished_cb()

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

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

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

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

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

◆ pass_plaintext_to_core()

static void pass_plaintext_to_core ( struct Queue queue,
const void *  plaintext,
size_t  plaintext_len 
)
static

We received plaintext_len bytes of plaintext on queue.

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

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

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

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

1155 {
1156  char key[256 / 8];
1157  char ctr[128 / 8];
1158 
1159  gcry_cipher_open (cipher,
1160  GCRY_CIPHER_AES256 /* low level: go for speed */,
1161  GCRY_CIPHER_MODE_CTR,
1162  0 /* flags */);
1164  sizeof(key),
1165  "TCP-key",
1166  strlen ("TCP-key"),
1167  dh,
1168  sizeof(*dh),
1169  pid,
1170  sizeof(*pid),
1171  NULL,
1172  0));
1173  gcry_cipher_setkey (*cipher, key, sizeof(key));
1175  sizeof(ctr),
1176  "TCP-ctr",
1177  strlen ("TCP-ctr"),
1178  dh,
1179  sizeof(*dh),
1180  pid,
1181  sizeof(*pid),
1182  NULL,
1183  0));
1184  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1186  GNUNET_CRYPTO_kdf (hmac_key,
1187  sizeof(struct GNUNET_HashCode),
1188  "TCP-hmac",
1189  strlen ("TCP-hmac"),
1190  dh,
1191  sizeof(*dh),
1192  pid,
1193  sizeof(*pid),
1194  NULL,
1195  0));
1196 }
#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 1205 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().

1206 {
1207  struct Queue *queue = cls;
1208  if (GNUNET_OK != success)
1209  {
1211  "Failed to store rekey monotonic time in PEERSTORE!\n");
1212  }
1213  queue->rekey_monotime_sc = NULL;
1214 }
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 1225 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().

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

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

1283 {
1284  struct GNUNET_HashCode dh;
1285 
1286  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
1287  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
1288 }
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:827
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 1300 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().

1301 {
1302  struct TcpRekeySignature thp;
1303 
1305  thp.purpose.size = htonl (sizeof(thp));
1307  "do_rekey size %u\n",
1308  thp.purpose.size);
1309  thp.sender = queue->target;
1311  "sender %s\n",
1312  GNUNET_p2s (&thp.sender.public_key));
1314  "sender %s\n",
1315  GNUNET_p2s (&queue->target.public_key));
1316  thp.receiver = my_identity;
1318  "receiver %s\n",
1319  GNUNET_p2s (&thp.receiver.public_key));
1320  thp.ephemeral = rekey->ephemeral;
1322  "ephemeral %s\n",
1323  GNUNET_e2s (&thp.ephemeral));
1324  thp.monotonic_time = rekey->monotonic_time;
1326  "time %s\n",
1328  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1329  GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1330  if (GNUNET_OK !=
1332  &thp,
1333  &rekey->sender_sig,
1334  &queue->target.public_key))
1335  {
1336  GNUNET_break (0);
1337  queue_finish (queue);
1338  return;
1339  }
1340  queue->rekey_monotonic_time = rekey->monotonic_time;
1342  "transport_tcp_communicator",
1343  &queue->target,
1346  queue);
1347  gcry_cipher_close (queue->in_cipher);
1348  queue->rekeyed = GNUNET_YES;
1349  setup_in_cipher (&rekey->ephemeral, queue);
1350 }
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
static struct GNUNET_PeerIdentity my_identity
Our public key.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender&#39;s monotonic time from rekey message.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
New ephemeral key.
static void rekey_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where...
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
#define GNUNET_log(kind,...)
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_store_cb()

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

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

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

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

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

1383 {
1384  struct Queue *queue = cls;
1385  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1386  struct GNUNET_TIME_Absolute mt;
1387  const struct GNUNET_PeerIdentity *pid;
1388  struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1389 
1390  (void) emsg;
1391 
1392  handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1393  pid = &queue->target;
1394  if (NULL == record)
1395  {
1396  queue->handshake_ack_monotime_get = NULL;
1397  return;
1398  }
1399  if (sizeof(*mtbe) != record->value_size)
1400  {
1401  GNUNET_break (0);
1402  return;
1403  }
1404  mtbe = record->value;
1405  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1406  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1408  {
1410  "Queue from %s dropped, handshake ack monotime in the past\n",
1411  GNUNET_i2s (&queue->target));
1412  GNUNET_break (0);
1413  queue_finish (queue);
1414  return;
1415  }
1417  "transport_tcp_communicator",
1418  pid,
1420  handshake_ack_monotonic_time,
1421  sizeof(
1422  handshake_ack_monotonic_time),
1425  &
1427  queue);
1428 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
Delete any previous values for the given key before storing the given value.
size_t value_size
Size of value BLOB.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
void * value
Record value BLOB.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished...
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

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

1439 {
1440  struct TCPConfirmationAck tca;
1441  struct TcpHandshakeAckSignature thas;
1442 
1444  "transport",
1445  "sending challenge\n");
1446 
1447  tca.header.type = ntohs (
1449  tca.header.size = ntohs (sizeof(tca));
1450  tca.challenge = challenge;
1451  tca.sender = my_identity;
1452  tca.monotonic_time =
1454  thas.purpose.purpose = htonl (
1456  thas.purpose.size = htonl (sizeof(thas));
1457  thas.sender = my_identity;
1458  thas.receiver = queue->target;
1459  thas.monotonic_time = tca.monotonic_time;
1460  thas.challenge = tca.challenge;
1462  &thas,
1463  &tca.sender_sig);
1464  GNUNET_assert (0 ==
1465  gcry_cipher_encrypt (queue->out_cipher,
1466  &queue->cwrite_buf[queue->cwrite_off],
1467  sizeof(tca),
1468  &tca,
1469  sizeof(tca)));
1470  queue->cwrite_off += sizeof(tca);
1472  "transport",
1473  "sending challenge done\n");
1474 }
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:837
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
Ack for the encrypted continuation of TCP initial handshake.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Here is the call graph for this function:
Here is the caller graph for this function:

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

1485 {
1486  struct GNUNET_HashCode dh;
1487 
1488  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
1489  /* we don't need the private key anymore, drop it! */
1490  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
1491  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1493  queue->rekey_left_bytes =
1495 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
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:867
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 1505 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().

1506 {
1507  struct TCPRekey rekey;
1508  struct TcpRekeySignature thp;
1509 
1510  GNUNET_assert (0 == queue->pwrite_off);
1511  memset (&rekey, 0, sizeof(rekey));
1513  rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1514  rekey.header.size = ntohs (sizeof(rekey));
1515  GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
1516  rekey.monotonic_time =
1518  thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1519  thp.purpose.size = htonl (sizeof(thp));
1521  "inject_rekey size %u\n",
1522  thp.purpose.size);
1523  thp.sender = my_identity;
1525  "sender %s\n",
1526  GNUNET_p2s (&thp.sender.public_key));
1527  thp.receiver = queue->target;
1529  "receiver %s\n",
1530  GNUNET_p2s (&thp.receiver.public_key));
1531  thp.ephemeral = rekey.ephemeral;
1533  "ephemeral %s\n",
1534  GNUNET_e2s (&thp.ephemeral));
1535  thp.monotonic_time = rekey.monotonic_time;
1537  "time %s\n",
1539  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1541  &thp,
1542  &rekey.sender_sig);
1543  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1544  /* Encrypt rekey message with 'old' cipher */
1545  GNUNET_assert (0 ==
1546  gcry_cipher_encrypt (queue->out_cipher,
1547  &queue->cwrite_buf[queue->cwrite_off],
1548  sizeof(rekey),
1549  &rekey,
1550  sizeof(rekey)));
1551  queue->cwrite_off += sizeof(rekey);
1552  /* Setup new cipher for successive messages */
1553  gcry_cipher_close (queue->out_cipher);
1554  setup_out_cipher (queue);
1555 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:419
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:197
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:837
static void setup_out_cipher(struct Queue *queue)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
TCP rekey message box.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_write()

static void queue_write ( void *  cls)
static

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

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

Parameters
clsa struct Queue

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

1566 {
1567  struct Queue *queue = cls;
1568  ssize_t sent;
1569  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1570  queue->write_task = NULL;
1571  if (0 != queue->cwrite_off)
1572  {
1573  sent = GNUNET_NETWORK_socket_send (queue->sock,
1574  queue->cwrite_buf,
1575  queue->cwrite_off);
1577  "Sent %lu bytes to TCP queue\n", sent);
1578  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1579  {
1581  queue_destroy (queue);
1582  return;
1583  }
1584  if (sent > 0)
1585  {
1586  size_t usent = (size_t) sent;
1587  queue->cwrite_off -= usent;
1588  memmove (queue->cwrite_buf,
1589  &queue->cwrite_buf[usent],
1590  queue->cwrite_off);
1591  reschedule_queue_timeout (queue);
1592  }
1593  }
1594  /* can we encrypt more? (always encrypt full messages, needed
1595  such that #mq_cancel() can work!) */
1596  if ((0 < queue->rekey_left_bytes) &&
1597  (queue->pwrite_off > 0) &&
1598  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1599  {
1601  "Encrypting %lu bytes\n", queue->pwrite_off);
1602  GNUNET_assert (0 ==
1603  gcry_cipher_encrypt (queue->out_cipher,
1604  &queue->cwrite_buf[queue->cwrite_off],
1605  queue->pwrite_off,
1606  queue->pwrite_buf,
1607  queue->pwrite_off));
1608  if (queue->rekey_left_bytes > queue->pwrite_off)
1609  queue->rekey_left_bytes -= queue->pwrite_off;
1610  else
1611  queue->rekey_left_bytes = 0;
1612  queue->cwrite_off += queue->pwrite_off;
1613  queue->pwrite_off = 0;
1614  }
1615  // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1616  if (((0 == queue->pwrite_off) &&
1617  ((0 == queue->rekey_left_bytes) ||
1618  (0 ==
1620  queue->rekey_time).rel_value_us))))
1621  {
1622  inject_rekey (queue);
1623  }
1624  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1625  (GNUNET_YES == queue->mq_awaits_continue))
1626  {
1627  queue->mq_awaits_continue = GNUNET_NO;
1629  }
1630  /* did we just finish writing 'finish'? */
1631  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1632  {
1634  "Finishing queue\n");
1635  queue_destroy (queue);
1636  return;
1637  }
1638  /* do we care to write more? */
1639  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1640  queue->write_task =
1642  queue->sock,
1643  &queue_write,
1644  queue);
1645 }
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:331
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:499
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

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

1657 {
1658  const struct GNUNET_MessageHeader *hdr =
1659  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1660  const struct TCPConfirmationAck *tca = (const struct
1661  TCPConfirmationAck *) queue->pread_buf;
1662  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1663  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1664  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1665  struct TCPRekey rekeyz;
1666  struct TCPFinish finz;
1667  struct GNUNET_ShortHashCode tmac;
1668  uint16_t type;
1669  size_t size = 0; /* make compiler happy */
1670  struct TcpHandshakeAckSignature thas;
1671  const struct ChallengeNonceP challenge = queue->challenge;
1672 
1674  "try handle plaintext!\n");
1675 
1676  if ((sizeof(*hdr) > queue->pread_off))
1677  {
1679  "Handling plaintext, not even a header!\n");
1680  return 0; /* not even a header */
1681  }
1682 
1684  {
1686  "Already received data of size %lu bigger than KX size %lu!\n",
1689  GNUNET_break_op (0);
1690  queue_finish (queue);
1691  return 0;
1692  }
1693 
1694  type = ntohs (hdr->type);
1695  switch (type)
1696  {
1699  "start processing ack\n");
1700  if (sizeof(*tca) > queue->pread_off)
1701  {
1703  "Handling plaintext size of tca greater than pread offset.\n");
1704  return 0;
1705  }
1706  if (ntohs (hdr->size) != sizeof(*tca))
1707  {
1709  "Handling plaintext size does not match message type.\n");
1710  GNUNET_break_op (0);
1711  queue_finish (queue);
1712  return 0;
1713  }
1714 
1715  thas.purpose.purpose = htonl (
1717  thas.purpose.size = htonl (sizeof(thas));
1718  thas.sender = tca->sender;
1719  thas.receiver = my_identity;
1720  thas.monotonic_time = tca->monotonic_time;
1721  thas.challenge = tca->challenge;
1722 
1725  &thas,
1726  &tca->sender_sig,
1727  &tca->sender.public_key))
1728  {
1730  "Verification of signature failed!\n");
1731  GNUNET_break (0);
1732  queue_finish (queue);
1733  return 0;
1734  }
1735  if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1736  {
1738  "Challenge in TCPConfirmationAck not correct!\n");
1739  GNUNET_break (0);
1740  queue_finish (queue);
1741  return 0;
1742  }
1743 
1745  "transport_tcp_communicator",
1746  &queue->target,
1748  &
1750  queue);
1751 
1753  "Handling plaintext, ack processed!\n");
1754 
1755  if (GNUNET_TRANSPORT_CS_INBOUND == queue->cs)
1756  {
1757  send_challenge (queue->challenge_received, queue);
1758  queue->write_task =
1760  queue->sock,
1761  &queue_write,
1762  queue);
1763  }
1764 
1765  unverified_size = -1;
1766 
1767  char *foreign_addr;
1768 
1769  switch (queue->address->sa_family)
1770  {
1771  case AF_INET:
1772  GNUNET_asprintf (&foreign_addr,
1773  "%s-%s",
1775  GNUNET_a2s (queue->address, queue->address_len));
1776  break;
1777 
1778  case AF_INET6:
1779  GNUNET_asprintf (&foreign_addr,
1780  "%s-%s",
1782  GNUNET_a2s (queue->address, queue->address_len));
1783  break;
1784 
1785  default:
1786  GNUNET_assert (0);
1787  }
1788 
1790  &queue->target,
1791  foreign_addr,
1792  UINT32_MAX, /* no MTU */
1794  0, /* Priority */
1795  queue->nt,
1796  queue->cs,
1797  queue->mq);
1798 
1799  GNUNET_free (foreign_addr);
1800 
1801  size = ntohs (hdr->size);
1802  break;
1804  /* Special case: header size excludes box itself! */
1805  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1806  return 0;
1807  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1808  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1809  {
1810  GNUNET_break_op (0);
1811  queue_finish (queue);
1812  return 0;
1813  }
1814  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1815  size = ntohs (hdr->size) + sizeof(*box);
1817  "Handling plaintext, box processed!\n");
1818  break;
1819 
1821  if (sizeof(*rekey) > queue->pread_off)
1822  return 0;
1823  if (ntohs (hdr->size) != sizeof(*rekey))
1824  {
1825  GNUNET_break_op (0);
1826  queue_finish (queue);
1827  return 0;
1828  }
1829  rekeyz = *rekey;
1830  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1831  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1832  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1833  {
1834  GNUNET_break_op (0);
1835  queue_finish (queue);
1836  return 0;
1837  }
1838  do_rekey (queue, rekey);
1839  size = ntohs (hdr->size);
1841  "Handling plaintext, rekey processed!\n");
1842  break;
1843 
1845  if (sizeof(*fin) > queue->pread_off)
1846  return 0;
1847  if (ntohs (hdr->size) != sizeof(*fin))
1848  {
1849  GNUNET_break_op (0);
1850  queue_finish (queue);
1851  return 0;
1852  }
1853  finz = *fin;
1854  memset (&finz.hmac, 0, sizeof(finz.hmac));
1855  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1856  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1857  {
1858  GNUNET_break_op (0);
1859  queue_finish (queue);
1860  return 0;
1861  }
1862  /* handle FINISH by destroying queue */
1863  queue_destroy (queue);
1865  "Handling plaintext, finish processed!\n");
1866  break;
1867 
1868  default:
1870  "Handling plaintext, nothing processed!\n");
1871  GNUNET_break_op (0);
1872  queue_finish (queue);
1873  return 0;
1874  }
1875  GNUNET_assert (0 != size);
1876  if (-1 != unverified_size)
1877  unverified_size += size;
1878  return size;
1879 }
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 1998 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().

2000 {
2001  struct sockaddr *in;
2002 
2003  v6.sin6_family = AF_INET6;
2004  v6.sin6_port = htons ((uint16_t) port);
2005 #if HAVE_SOCKADDR_IN_SIN_LEN
2006  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
2007 #endif
2008  v6.sin6_flowinfo = 0;
2009  v6.sin6_scope_id = 0;
2010  in = GNUNET_memdup (&v6, sizeof(v6));
2011  *sock_len = sizeof(struct sockaddr_in6);
2012 
2013  return in;
2014 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v4()

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

Convert a struct sockaddr_in4 to astruct sockaddr *`.

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

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

2027 {
2028  struct sockaddr *in;
2029 
2030  v4.sin_family = AF_INET;
2031  v4.sin_port = htons ((uint16_t) port);
2032 #if HAVE_SOCKADDR_IN_SIN_LEN
2033  v4.sin_len = sizeof(struct sockaddr_in);
2034 #endif
2035  in = GNUNET_memdup (&v4, sizeof(v4));
2036  *sock_len = sizeof(struct sockaddr_in);
2037  return in;
2038 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_port_only()

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

Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *

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

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

2049 {
2050  struct PortOnlyIpv4Ipv6 *po;
2051  struct sockaddr_in *i4;
2052  struct sockaddr_in6 *i6;
2053  socklen_t sock_len_ipv4;
2054  socklen_t sock_len_ipv6;
2055 
2056  /* interpreting value as just a PORT number */
2057  if (*port > UINT16_MAX)
2058  {
2060  "BINDTO specification `%s' invalid: value too large for port\n",
2061  bindto);
2062  return NULL;
2063  }
2064 
2065  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2066 
2067  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2068  (GNUNET_YES ==
2071  "DISABLE_V6")))
2072  {
2073  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2074  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2075  *port);
2076  po->addr_len_ipv4 = sock_len_ipv4;
2077  }
2078  else
2079  {
2080 
2081  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2082  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2083  *port);
2084  po->addr_len_ipv4 = sock_len_ipv4;
2085 
2086  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2087  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2088  *port);
2089 
2090  po->addr_len_ipv6 = sock_len_ipv6;
2091 
2092  GNUNET_free (i6);
2093  }
2094 
2095  GNUNET_free (i4);
2096 
2097  return po;
2098 }
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
socklen_t addr_len_ipv4
Length of ipv4 address.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
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 2108 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().

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

2167 {
2168  unsigned int port;
2169  char dummy[2];
2170  char *token;
2171  char *addr;
2172  char *colon;
2173  char *cp;
2174  char *rest = NULL;
2175 
2176  if (NULL != addr_and_port)
2177  {
2178  cp = GNUNET_strdup (addr_and_port);
2179  token = strtok_r (cp, "]", &rest);
2180  if (strlen (addr_and_port) == strlen (token))
2181  {
2182  colon = strrchr (cp, ':');
2183  if (NULL == colon)
2184  {
2185  return 0;
2186  }
2187  addr = colon;
2188  addr++;
2189  }
2190  else
2191  {
2192  token = strtok_r (NULL, "]", &rest);
2193  if (NULL == token)
2194  {
2195  return 0;
2196  }
2197  else
2198  {
2199  addr = token;
2200  addr++;
2201  }
2202  }
2203 
2204 
2205  if (1 == sscanf (addr, "%u%1s", &port, dummy))
2206  {
2207  /* interpreting value as just a PORT number */
2208  if (port > UINT16_MAX)
2209  {
2211  "Port `%u' invalid: value too large for port\n",
2212  port);
2213  // GNUNET_free (cp);
2214  return 0;
2215  }
2216  }
2217  else
2218  {
2220  "BINDTO specification invalid: last ':' not followed by number\n");
2221  // GNUNET_free (cp);
2222  return 0;
2223  }
2224  }
2225  else
2226  {
2228  "return 0\n");
2229  /* interpret missing port as 0, aka pick any free one */
2230  port = 0;
2231  }
2232 
2233 
2234  return port;
2235 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr()

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

Convert TCP bind specification to a struct sockaddr *

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

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

2247 {
2248  struct sockaddr *in;
2249  unsigned int port;
2250  struct sockaddr_in v4;
2251  struct sockaddr_in6 v6;
2252  const char *start;
2253 
2254  // cp = GNUNET_strdup (bindto);
2255  start = extract_address (bindto);
2256 
2258  "start %s\n",
2259  start);
2260 
2262  "!bindto %s\n",
2263  bindto);
2264 
2265 
2266  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2267  {
2268  // colon = strrchr (cp, ':');
2269  port = extract_port (bindto);
2270 
2272  "port %u\n",
2273  port);
2274 
2275  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2276  }
2277  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2278  {
2279  // colon = strrchr (cp, ':');
2280  port = extract_port (bindto);
2281  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2282  }
2283  else
2284  {
2285  GNUNET_assert (0);
2286  }
2287 
2288  // GNUNET_free (start);
2289 
2290  return in;
2291 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
Here is the call graph for this function:
Here is the caller graph for this function:

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

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

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

Referenced by boot_queue().

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

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

Referenced by boot_queue().

2367 {
2368  struct Queue *queue = impl_state;
2369 
2370  GNUNET_assert (0 != queue->pwrite_off);
2371  queue->pwrite_off = 0;
2372 }
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 2385 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().

2386 {
2387  struct Queue *queue = cls;
2388 
2390  "MQ error in queue to %s: %d\n",
2391  GNUNET_i2s (&queue->target),
2392  (int) error);
2393  queue_finish (queue);
2394 }
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 2405 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().

2406 {
2407  queue->nt =
2410  queue_map,
2411  &queue->target,
2412  queue,
2415  "# queues active",
2417  GNUNET_NO);
2418  queue->timeout =
2421  &mq_destroy,
2422  &mq_cancel,
2423  queue,
2424  NULL,
2425  &mq_error,
2426  queue);
2427  /* { */
2428  /* char *foreign_addr; */
2429 
2430  /* switch (queue->address->sa_family) */
2431  /* { */
2432  /* case AF_INET: */
2433  /* GNUNET_asprintf (&foreign_addr, */
2434  /* "%s-%s", */
2435  /* COMMUNICATOR_ADDRESS_PREFIX, */
2436  /* GNUNET_a2s (queue->address, queue->address_len)); */
2437  /* break; */
2438 
2439  /* case AF_INET6: */
2440  /* GNUNET_asprintf (&foreign_addr, */
2441  /* "%s-%s", */
2442  /* COMMUNICATOR_ADDRESS_PREFIX, */
2443  /* GNUNET_a2s (queue->address, queue->address_len)); */
2444  /* break; */
2445 
2446  /* default: */
2447  /* GNUNET_assert (0); */
2448  /* } */
2449  /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */
2450  /* &queue->target, */
2451  /* foreign_addr, */
2452  /* 0 /\* no MTU *\/, */
2453  /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */
2454  /* 0, /\* Priority *\/ */
2455  /* queue->nt, */
2456  /* queue->cs, */
2457  /* queue->mq); */
2458  /* GNUNET_free (foreign_addr); */
2459  /* } */
2460 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WANT.
Definition: nt.c:314
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
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 2474 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().

2476 {
2477  struct TcpHandshakeSignature ths;
2478  struct TCPConfirmation tc;
2479 
2480  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2481  queue->cwrite_off = sizeof(*epub);
2482  /* compute 'tc' and append in encrypted format to cwrite_buf */
2483  tc.sender = my_identity;
2484  tc.monotonic_time =
2487  &tc.challenge,
2488  sizeof(tc.challenge));
2489  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2490  ths.purpose.size = htonl (sizeof(ths));
2491  ths.sender = my_identity;
2492  ths.receiver = queue->target;
2493  ths.ephemeral = *epub;
2494  ths.monotonic_time = tc.monotonic_time;
2495  ths.challenge = tc.challenge;
2497  &ths,
2498  &tc.sender_sig);
2499  GNUNET_assert (0 ==
2500  gcry_cipher_encrypt (queue->out_cipher,
2501  &queue->cwrite_buf[queue->cwrite_off],
2502  sizeof(tc),
2503  &tc,
2504  sizeof(tc)));
2505  queue->challenge = tc.challenge;
2506  queue->cwrite_off += sizeof(tc);
2507 
2509  "transport",
2510  "handshake written\n");
2511 }
#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:837
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
Encrypted continuation of TCP initial handshake.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_initial_kx_out()

static void start_initial_kx_out ( struct Queue queue)
static

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

Must be called first before any data is sent.

Parameters
queuethe queue to setup

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

2523 {
2524  struct GNUNET_CRYPTO_EcdhePublicKey epub;
2525 
2528  setup_out_cipher (queue);
2529  transmit_kx (queue, &epub);
2530 }
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:419
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:197
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 2539 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().

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

2562 {
2563  struct Queue *queue = cls;
2564  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2565  struct GNUNET_TIME_Absolute mt;
2566  const struct GNUNET_PeerIdentity *pid;
2567  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2568 
2569  (void) emsg;
2570 
2571  handshake_monotonic_time = &queue->handshake_monotonic_time;
2572  pid = &queue->target;
2573  if (NULL == record)
2574  {
2575  queue->handshake_monotime_get = NULL;
2576  return;
2577  }
2578  if (sizeof(*mtbe) != record->value_size)
2579  {
2580  GNUNET_break (0);
2581  return;
2582  }
2583  mtbe = record->value;
2584  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2585  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2587  {
2589  "Queue from %s dropped, handshake monotime in the past\n",
2590  GNUNET_i2s (&queue->target));
2591  GNUNET_break (0);
2592  queue_finish (queue);
2593  return;
2594  }
2596  "transport_tcp_communicator",
2597  pid,
2599  handshake_monotonic_time,
2600  sizeof(
2601  handshake_monotonic_time),
2604  &
2606  queue);
2607 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
Delete any previous values for the given key before storing the given value.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
size_t value_size
Size of value BLOB.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender&#39;s monotonic time from handshake message.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
void * value
Record value BLOB.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
static void handshake_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake monotime is finished.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_and_check_tc()

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

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

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

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

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

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

2664 {
2665  if (NULL != pq->listen_sock)
2666  {
2668  pq->listen_sock = NULL;
2669  }
2671  GNUNET_free (pq->address);
2673  GNUNET_free (pq);
2674 }
#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 2684 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().

2685 {
2686  struct ProtoQueue *pq = cls;
2687  ssize_t rcvd;
2688  struct GNUNET_TIME_Relative left;
2689  struct Queue *queue;
2690  struct TCPConfirmation tc;
2691 
2692  pq->read_task = NULL;
2694  if (0 == left.rel_value_us)
2695  {
2696  free_proto_queue (pq);
2697  return;
2698  }
2699  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2700  &pq->ibuf[pq->ibuf_off],
2701  sizeof(pq->ibuf) - pq->ibuf_off);
2703  "Received %lu bytes for KX\n", rcvd);
2704  if (-1 == rcvd)
2705  {
2706  if ((EAGAIN != errno) && (EINTR != errno))
2707  {
2709  free_proto_queue (pq);
2710  return;
2711  }
2712  /* try again */
2713  pq->read_task =
2715  return;
2716  }
2717  pq->ibuf_off += rcvd;
2718  if (pq->ibuf_off > sizeof(pq->ibuf))
2719  {
2720  /* read more */
2721  pq->read_task =
2723  return;
2724  }
2725  /* we got all the data, let's find out who we are talking to! */
2726  queue = GNUNET_new (struct Queue);
2727  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2728  queue);
2729  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2730  {
2732  "Invalid TCP KX received from %s\n",
2733  GNUNET_a2s (queue->address, queue->address_len));
2734  gcry_cipher_close (queue->in_cipher);
2735  GNUNET_free (queue);
2736  free_proto_queue (pq);
2737  return;
2738  }
2739  queue->address = pq->address; /* steals reference */
2740  queue->address_len = pq->address_len;
2741  queue->target = tc.sender;
2742  queue->listen_sock = pq->listen_sock;
2743  queue->sock = pq->sock;
2744 
2745 
2747  "start kx proto\n");
2748 
2749  start_initial_kx_out (queue);
2751  boot_queue (queue);
2752  queue->read_task =
2754  queue->sock,
2755  &queue_read,
2756  queue);
2757  queue->write_task =
2759  queue->sock,
2760  &queue_write,
2761  queue);
2762  // TODO To early! Move it somewhere else.
2763  // send_challenge (tc.challenge, queue);
2764  queue->challenge_received = tc.challenge;
2765 
2767  GNUNET_free (pq);
2768 }
#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:331
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read_kx()

static void queue_read_kx ( void *  cls)
static

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

Parameters
clsa struct Queue

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

2834 {
2835  struct Queue *queue = cls;
2836  ssize_t rcvd;
2837  struct GNUNET_TIME_Relative left;
2838  struct TCPConfirmation tc;
2839 
2840  queue->read_task = NULL;
2842  if (0 == left.rel_value_us)
2843  {
2844  queue_destroy (queue);
2845  return;
2846  }
2847  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2848  &queue->cread_buf[queue->cread_off],
2849  BUF_SIZE - queue->cread_off);
2851  "Received %lu bytes for KX\n",
2852  rcvd);
2853  if (-1 == rcvd)
2854  {
2855  if ((EAGAIN != errno) && (EINTR != errno))
2856  {
2858  queue_destroy (queue);
2859  return;
2860  }
2861  queue->read_task =
2862  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2863  return;
2864  }
2865  queue->cread_off += rcvd;
2866  if (queue->cread_off < INITIAL_KX_SIZE)
2867  {
2868  /* read more */
2869  queue->read_task =
2870  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2871  return;
2872  }
2873  /* we got all the data, let's find out who we are talking to! */
2875  queue->cread_buf,
2876  queue);
2877  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2878  {
2880  "Invalid TCP KX received from %s\n",
2881  GNUNET_a2s (queue->address, queue->address_len));
2882  queue_destroy (queue);
2883  return;
2884  }
2885  if (0 !=
2886  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2887  {
2889  "Invalid sender in TCP KX received from %s\n",
2890  GNUNET_a2s (queue->address, queue->address_len));
2891  queue_destroy (queue);
2892  return;
2893  }
2894  send_challenge (tc.challenge, queue);
2895  queue->write_task =
2897  queue->sock,
2898  &queue_write,
2899  queue);
2900 
2901  /* update queue timeout */
2902  reschedule_queue_timeout (queue);
2903  /* prepare to continue with regular read task immediately */
2904  memmove (queue->cread_buf,
2905  &queue->cread_buf[INITIAL_KX_SIZE],
2906  queue->cread_off - (INITIAL_KX_SIZE));
2908  "cread_off is %lu bytes before adjusting\n",
2909  queue->cread_off);
2910  queue->cread_off -= INITIAL_KX_SIZE;
2912  "cread_off set to %lu bytes\n",
2913  queue->cread_off);
2914  if (0 <= queue->cread_off)
2915  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2916 }
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:331
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
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 2938 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().

2939 {
2940  struct Queue *queue;
2941  const char *path;
2942  struct sockaddr *in;
2943  socklen_t in_len = 0;
2944  struct GNUNET_NETWORK_Handle *sock;
2945 
2947  "Connecting to %s\n", address);
2948  if (0 != strncmp (address,
2950  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2951  {
2952  GNUNET_break_op (0);
2953  return GNUNET_SYSERR;
2954  }
2955  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2956  in = tcp_address_to_sockaddr (path, &in_len);
2957 
2958  if (NULL == in)
2959  {
2961  "Failed to setup TCP socket address\n");
2962  return GNUNET_SYSERR;
2963  }
2964 
2966  "in %s\n",
2967  GNUNET_a2s (in, in_len));
2968 
2969  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2970  if (NULL == sock)
2971  {
2973  "socket(%d) failed: %s",
2974  in->sa_family,
2975  strerror (errno));
2976  GNUNET_free (in);
2977  return GNUNET_SYSERR;
2978  }
2979  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2980  (errno != EINPROGRESS))
2981  {
2983  "connect to `%s' failed: %s",
2984  address,
2985  strerror (errno));
2987  GNUNET_free (in);
2988  return GNUNET_SYSERR;
2989  }
2990 
2991  queue = GNUNET_new (struct Queue);
2992  queue->target = *peer;
2993  queue->address = in;
2994  queue->address_len = in_len;
2995  queue->sock = sock;
2997  boot_queue (queue);
2998  // queue->mq_awaits_continue = GNUNET_YES;
2999  queue->read_task =
3001  queue->sock,
3002  &queue_read_kx,
3003  queue);
3004 
3005 
3007  "start kx mq_init\n");
3008 
3009  start_initial_kx_out (queue);
3010  queue->write_task =
3012  queue->sock,
3013  &queue_write,
3014  queue);
3015  return GNUNET_OK;
3016 }
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 3028 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().

3031 {
3032  struct ListenTask *lt = value;
3033 
3034  (void) cls;
3035  (void) key;
3036  if (NULL != lt->listen_task)
3037  {
3039  lt->listen_task = NULL;
3040  }
3041  if (NULL != lt->listen_sock)
3042  {
3044  lt->listen_sock = NULL;
3045  }
3046  return GNUNET_OK;
3047 }
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 3059 of file gnunet-communicator-tcp.c.

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

Referenced by do_shutdown().

3062 {
3063  struct Queue *queue = value;
3064 
3065  (void) cls;
3066  (void) target;
3067  queue_destroy (queue);
3068  return GNUNET_OK;
3069 }
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 3078 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().

3079 {
3081  "Shutdown %s!\n",
3082  shutdown_running ? "running" : "not running");
3083 
3085  return;
3086  else
3088 
3089  while (NULL != proto_head)
3091  if (NULL != nat)
3092  {
3094  nat = NULL;
3095  }
3100  if (NULL != ch)
3101  {
3103  ch = NULL;
3104  }
3105  if (NULL != stats)
3106  {
3108  stats = NULL;
3109  }
3110  if (NULL != my_private_key)
3111  {
3113  my_private_key = NULL;
3114  }
3115  if (NULL != is)
3116  {
3118  is = NULL;
3119  }
3120  if (NULL != peerstore)
3121  {
3123  peerstore = NULL;
3124  }
3125  if (NULL != resolve_request_handle)
3126  {
3128  resolve_request_handle = NULL;
3129  }
3131  "Shutdown done!\n");
3132 }
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 3147 of file gnunet-communicator-tcp.c.

References GNUNET_break_op.

Referenced by init_socket().

3150 {
3151  (void) cls;
3152  (void) sender;
3153  (void) msg;
3154  GNUNET_break_op (0);
3155 }
#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 3172 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().

3178 {
3179  char *my_addr;
3181 
3183  "nat address cb %s %s\n",
3184  add_remove ? "add" : "remove",
3185  GNUNET_a2s (addr, addrlen));
3186 
3187  if (GNUNET_YES == add_remove)
3188  {
3189  enum GNUNET_NetworkType nt;
3190 
3191  GNUNET_asprintf (&my_addr,
3192  "%s-%s",
3194  GNUNET_a2s (addr, addrlen));
3195  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3196  ai =
3198  my_addr,
3199  nt,
3201  GNUNET_free (my_addr);
3202  *app_ctx = ai;
3203  }
3204  else
3205  {
3206  ai = *app_ctx;
3208  *app_ctx = NULL;
3209  }
3210 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WANT.
Definition: nt.c:314
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer...
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer...
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
#define GNUNET_log(kind,...)
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
Internal representation of an address a communicator is currently providing for the transport service...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_addr()

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

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

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

3218 {
3219 
3220  struct Addresses *saddrs;
3221