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

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

◆ queue_destroy()

static void queue_destroy ( struct Queue queue)
static

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

Parameters
queuequeue to close down

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

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

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

877 {
878  struct ListenTask *lt = NULL;
879  struct GNUNET_HashCode h_sock;
880  int sockfd;
881 
882  sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
883  GNUNET_CRYPTO_hash (&sockfd,
884  sizeof(int),
885  &h_sock);
886 
888 
890  "Disconnecting queue for peer `%s'\n",
891  GNUNET_i2s (&queue->target));
892  if (NULL != queue->rekey_monotime_sc)
893  {
895  queue->rekey_monotime_sc = NULL;
896  }
897  if (NULL != queue->handshake_monotime_sc)
898  {
900  queue->handshake_monotime_sc = NULL;
901  }
902  if (NULL != queue->handshake_ack_monotime_sc)
903  {
905  queue->handshake_ack_monotime_sc = NULL;
906  }
907  if (NULL != queue->rekey_monotime_get)
908  {
910  queue->rekey_monotime_get = NULL;
911  }
912  if (NULL != queue->handshake_monotime_get)
913  {
915  queue->handshake_monotime_get = NULL;
916  }
917  if (NULL != queue->handshake_ack_monotime_get)
918  {
920  queue->handshake_ack_monotime_get = NULL;
921  }
922  if (NULL != queue->qh)
923  {
925  queue->qh = NULL;
926  }
927  GNUNET_assert (
928  GNUNET_YES ==
931  "# queues active",
933  GNUNET_NO);
934  if (NULL != queue->read_task)
935  {
937  queue->read_task = NULL;
938  }
939  if (NULL != queue->write_task)
940  {
942  queue->write_task = NULL;
943  }
945  {
947  "closing socket failed\n");
948  }
949  gcry_cipher_close (queue->in_cipher);
950  gcry_cipher_close (queue->out_cipher);
951  GNUNET_free (queue->address);
952  if (0 != queue->backpressure)
953  queue->destroyed = GNUNET_YES;
954  else
955  GNUNET_free (queue);
956 
957  if (NULL == lt)
958  return;
959 
960  if ((! shutdown_running) && (NULL == lt->listen_task))
961  {
963  "add read net listen\n");
966  lt->listen_sock,
967  &listen_cb,
968  lt);
969  }
970  else
971  GNUNET_free (lt);
972 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1077
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
A 512-bit hashcode.
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
int shutdown_running
A flag indicating we are already doing a shutdown.
struct sockaddr * address
Address of the other peer.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define GNUNET_log(kind,...)
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
Struct to use as closure.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_hmac()

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

Compute mac over buf, and ratched the hmac_secret.

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

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

References GNUNET_CRYPTO_hash(), and GNUNET_CRYPTO_hmac_raw().

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

988 {
989  struct GNUNET_HashCode mac;
990 
991  GNUNET_CRYPTO_hmac_raw (hmac_secret,
992  sizeof(struct GNUNET_HashCode),
993  buf,
994  buf_size,
995  &mac);
996  /* truncate to `struct GNUNET_ShortHashCode` */
997  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
998  /* ratchet hmac key */
999  GNUNET_CRYPTO_hash (hmac_secret,
1000  sizeof(struct GNUNET_HashCode),
1001  hmac_secret);
1002 }
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn' this be the standard hmac function and the abov...
Definition: crypto_hash.c:274
A 256-bit hashcode.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
static char buf[2048]
A 512-bit hashcode.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_finish()

static void queue_finish ( struct Queue queue)
static

Append a 'finish' message to the outgoing transmission.

Once the finish has been transmitted, destroy the queue.

Parameters
queuequeue to shut down nicely

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

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

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

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

◆ reschedule_queue_timeout()

static void reschedule_queue_timeout ( struct Queue queue)
static

Increment queue timeout due to activity.

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

Parameters
queuequeue for which the timeout should be rescheduled

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

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

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

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

◆ queue_read()

static void queue_read ( void *  cls)
static

Queue read task.

If we hit the timeout, disconnect it

Parameters
clsthe struct Queue * to disconnect

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

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

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

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

◆ core_read_finished_cb()

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

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

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

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

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

Referenced by pass_plaintext_to_core().

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

◆ pass_plaintext_to_core()

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

We received plaintext_len bytes of plaintext on queue.

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

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

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

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

Referenced by try_handle_plaintext().

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

◆ setup_cipher()

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

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

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

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

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

Referenced by setup_in_cipher(), and setup_out_cipher().

1157 {
1158  char key[256 / 8];
1159  char ctr[128 / 8];
1160 
1161  GNUNET_assert (0 == gcry_cipher_open (cipher,
1162  GCRY_CIPHER_AES256 /* low level: go for speed */,
1163  GCRY_CIPHER_MODE_CTR,
1164  0 /* flags */));
1166  sizeof(key),
1167  "TCP-key",
1168  strlen ("TCP-key"),
1169  dh,
1170  sizeof(*dh),
1171  pid,
1172  sizeof(*pid),
1173  NULL,
1174  0));
1175  GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1177  sizeof(ctr),
1178  "TCP-ctr",
1179  strlen ("TCP-ctr"),
1180  dh,
1181  sizeof(*dh),
1182  pid,
1183  sizeof(*pid),
1184  NULL,
1185  0));
1186  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1188  GNUNET_CRYPTO_kdf (hmac_key,
1189  sizeof(struct GNUNET_HashCode),
1190  "TCP-hmac",
1191  strlen ("TCP-hmac"),
1192  dh,
1193  sizeof(*dh),
1194  pid,
1195  sizeof(*pid),
1196  NULL,
1197  0));
1198 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rekey_monotime_store_cb()

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

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

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

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

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

Referenced by rekey_monotime_cb().

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

◆ rekey_monotime_cb()

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

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where found.

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

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

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

Referenced by do_rekey().

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

◆ setup_in_cipher()

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

Setup cipher of queue for decryption.

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

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

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

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

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

◆ do_rekey()

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

Handle rekey message on queue.

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

Parameters
queuethe queue rekey was received on
rekeythe rekey message

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

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

Referenced by try_handle_plaintext().

1304 {
1305  struct TcpRekeySignature thp;
1306 
1308  thp.purpose.size = htonl (sizeof(thp));
1310  "do_rekey size %u\n",
1311  thp.purpose.size);
1312  thp.sender = queue->target;
1314  "sender %s\n",
1315  GNUNET_p2s (&thp.sender.public_key));
1317  "sender %s\n",
1318  GNUNET_p2s (&queue->target.public_key));
1319  thp.receiver = my_identity;
1321  "receiver %s\n",
1322  GNUNET_p2s (&thp.receiver.public_key));
1323  thp.ephemeral = rekey->ephemeral;
1325  "ephemeral %s\n",
1326  GNUNET_e2s (&thp.ephemeral));
1327  thp.monotonic_time = rekey->monotonic_time;
1329  "time %s\n",
1331  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1332  GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1333  if (GNUNET_OK !=
1335  &thp,
1336  &rekey->sender_sig,
1337  &queue->target.public_key))
1338  {
1339  GNUNET_break (0);
1340  queue_finish (queue);
1341  return;
1342  }
1343  queue->rekey_monotonic_time = rekey->monotonic_time;
1345  "transport_tcp_communicator",
1346  &queue->target,
1349  queue);
1350  gcry_cipher_close (queue->in_cipher);
1351  queue->rekeyed = GNUNET_YES;
1352  setup_in_cipher (&rekey->ephemeral, queue);
1353 }
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:542
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:604
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_store_cb()

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

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

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

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

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

Referenced by handshake_ack_monotime_cb().

1363 {
1364  struct Queue *queue = cls;
1365 
1366  if (GNUNET_OK != success)
1367  {
1369  "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1370  }
1371  queue->handshake_ack_monotime_sc = NULL;
1372 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
Handle for a queue.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_cb()

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

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK where found.

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

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

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

Referenced by try_handle_plaintext().

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

◆ send_challenge()

static void send_challenge ( struct ChallengeNonceP  challenge,
struct Queue queue 
)
static

Sending challenge with TcpConfirmationAck back to sender of ephemeral key.

Parameters
tcThe TCPConfirmation originally send.
queueThe queue context.

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

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

Referenced by queue_read_kx(), and try_handle_plaintext().

1442 {
1443  struct TCPConfirmationAck tca;
1444  struct TcpHandshakeAckSignature thas;
1445 
1447  "transport",
1448  "sending challenge\n");
1449 
1450  tca.header.type = ntohs (
1452  tca.header.size = ntohs (sizeof(tca));
1453  tca.challenge = challenge;
1454  tca.sender = my_identity;
1455  tca.monotonic_time =
1457  thas.purpose.purpose = htonl (
1459  thas.purpose.size = htonl (sizeof(thas));
1460  thas.sender = my_identity;
1461  thas.receiver = queue->target;
1462  thas.monotonic_time = tca.monotonic_time;
1463  thas.challenge = tca.challenge;
1465  &thas,
1466  &tca.sender_sig);
1467  GNUNET_assert (0 ==
1468  gcry_cipher_encrypt (queue->out_cipher,
1469  &queue->cwrite_buf[queue->cwrite_off],
1470  sizeof(tca),
1471  &tca,
1472  sizeof(tca)));
1473  queue->cwrite_off += sizeof(tca);
1475  "transport",
1476  "sending challenge done\n");
1477 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:658
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
Ack for the encrypted continuation of TCP initial handshake.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_out_cipher()

static void setup_out_cipher ( struct Queue queue)
static

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

Parameters
queuequeue to setup outgoing (encryption) cipher for

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

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

Referenced by inject_rekey(), and start_initial_kx_out().

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

◆ inject_rekey()

static void inject_rekey ( struct Queue queue)
static

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

Parameters
queuequeue to perform rekeying on

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

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

Referenced by queue_write().

1509 {
1510  struct TCPRekey rekey;
1511  struct TcpRekeySignature thp;
1512 
1513  GNUNET_assert (0 == queue->pwrite_off);
1514  memset (&rekey, 0, sizeof(rekey));
1516  rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1517  rekey.header.size = ntohs (sizeof(rekey));
1518  GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
1519  rekey.monotonic_time =
1521  thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1522  thp.purpose.size = htonl (sizeof(thp));
1524  "inject_rekey size %u\n",
1525  thp.purpose.size);
1526  thp.sender = my_identity;
1528  "sender %s\n",
1529  GNUNET_p2s (&thp.sender.public_key));
1530  thp.receiver = queue->target;
1532  "receiver %s\n",
1533  GNUNET_p2s (&thp.receiver.public_key));
1534  thp.ephemeral = rekey.ephemeral;
1536  "ephemeral %s\n",
1537  GNUNET_e2s (&thp.ephemeral));
1538  thp.monotonic_time = rekey.monotonic_time;
1540  "time %s\n",
1542  GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1544  &thp,
1545  &rekey.sender_sig);
1546  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1547  /* Encrypt rekey message with 'old' cipher */
1548  GNUNET_assert (0 ==
1549  gcry_cipher_encrypt (queue->out_cipher,
1550  &queue->cwrite_buf[queue->cwrite_off],
1551  sizeof(rekey),
1552  &rekey,
1553  sizeof(rekey)));
1554  queue->cwrite_off += sizeof(rekey);
1555  /* Setup new cipher for successive messages */
1556  gcry_cipher_close (queue->out_cipher);
1557  setup_out_cipher (queue);
1558 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:542
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:435
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:213
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:658
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:604
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_write()

static void queue_write ( void *  cls)
static

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

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

Parameters
clsa struct Queue

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

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

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

1569 {
1570  struct Queue *queue = cls;
1571  ssize_t sent;
1572  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1573  queue->write_task = NULL;
1574  if (0 != queue->cwrite_off)
1575  {
1576  sent = GNUNET_NETWORK_socket_send (queue->sock,
1577  queue->cwrite_buf,
1578  queue->cwrite_off);
1580  "Sent %lu bytes to TCP queue\n", sent);
1581  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1582  {
1584  queue_destroy (queue);
1585  return;
1586  }
1587  if (sent > 0)
1588  {
1589  size_t usent = (size_t) sent;
1590  queue->cwrite_off -= usent;
1591  memmove (queue->cwrite_buf,
1592  &queue->cwrite_buf[usent],
1593  queue->cwrite_off);
1594  reschedule_queue_timeout (queue);
1595  }
1596  }
1597  /* can we encrypt more? (always encrypt full messages, needed
1598  such that #mq_cancel() can work!) */
1599  if ((0 < queue->rekey_left_bytes) &&
1600  (queue->pwrite_off > 0) &&
1601  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1602  {
1604  "Encrypting %lu bytes\n", queue->pwrite_off);
1605  GNUNET_assert (0 ==
1606  gcry_cipher_encrypt (queue->out_cipher,
1607  &queue->cwrite_buf[queue->cwrite_off],
1608  queue->pwrite_off,
1609  queue->pwrite_buf,
1610  queue->pwrite_off));
1611  if (queue->rekey_left_bytes > queue->pwrite_off)
1612  queue->rekey_left_bytes -= queue->pwrite_off;
1613  else
1614  queue->rekey_left_bytes = 0;
1615  queue->cwrite_off += queue->pwrite_off;
1616  queue->pwrite_off = 0;
1617  }
1618  // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1619  if (((0 == queue->pwrite_off) &&
1620  ((0 == queue->rekey_left_bytes) ||
1621  (0 ==
1623  queue->rekey_time).rel_value_us))))
1624  {
1625  inject_rekey (queue);
1626  }
1627  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1628  (GNUNET_YES == queue->mq_awaits_continue))
1629  {
1630  queue->mq_awaits_continue = GNUNET_NO;
1632  }
1633  /* did we just finish writing 'finish'? */
1634  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1635  {
1637  "Finishing queue\n");
1638  queue_destroy (queue);
1639  return;
1640  }
1641  /* do we care to write more? */
1642  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1643  queue->write_task =
1645  queue->sock,
1646  &queue_write,
1647  queue);
1648 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
uint64_t rel_value_us
The actual value.
int finishing
Did we enqueue a finish message and are closing down the queue?
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:812
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue&#39;s plaintext buffer.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
Handle for a queue.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:499
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_handle_plaintext()

static size_t try_handle_plaintext ( struct Queue queue)
static

Test if we have received a full message in plaintext.

If so, handle it.

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

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

References Queue::address, Queue::address_len, calculate_hmac(), Queue::challenge, Queue::challenge_received, COMMUNICATOR_ADDRESS_PREFIX, Queue::cs, do_rekey(), GNUNET_a2s(), GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_memcmp, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, GNUNET_PEERSTORE_iterate(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, GNUNET_SCHEDULER_add_write_net(), GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_CS_INBOUND, GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, handshake_ack_monotime_cb(), Queue::handshake_ack_monotime_get, TCPBox::hmac, TCPFinish::hmac, Queue::in_hmac, INITIAL_CORE_KX_SIZE, Queue::mq, my_identity, Queue::nt, pass_plaintext_to_core(), Queue::pread_buf, Queue::pread_off, Queue::qh, queue_destroy(), queue_finish(), queue_write(), send_challenge(), size, GNUNET_MessageHeader::size, Queue::sock, Queue::target, type, GNUNET_MessageHeader::type, unverified_size, and Queue::write_task.

Referenced by queue_read().

1660 {
1661  const struct GNUNET_MessageHeader *hdr =
1662  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1663  const struct TCPConfirmationAck *tca = (const struct
1664  TCPConfirmationAck *) queue->pread_buf;
1665  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1666  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1667  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1668  struct TCPRekey rekeyz;
1669  struct TCPFinish finz;
1670  struct GNUNET_ShortHashCode tmac;
1671  uint16_t type;
1672  size_t size = 0; /* make compiler happy */
1673  struct TcpHandshakeAckSignature thas;
1674  const struct ChallengeNonceP challenge = queue->challenge;
1675 
1677  "try handle plaintext!\n");
1678 
1679  if ((sizeof(*hdr) > queue->pread_off))
1680  {
1682  "Handling plaintext, not even a header!\n");
1683  return 0; /* not even a header */
1684  }
1685 
1687  {
1689  "Already received data of size %lu bigger than KX size %lu!\n",
1692  GNUNET_break_op (0);
1693  queue_finish (queue);
1694  return 0;
1695  }
1696 
1697  type = ntohs (hdr->type);
1698  switch (type)
1699  {
1702  "start processing ack\n");
1703  if (sizeof(*tca) > queue->pread_off)
1704  {
1706  "Handling plaintext size of tca greater than pread offset.\n");
1707  return 0;
1708  }
1709  if (ntohs (hdr->size) != sizeof(*tca))
1710  {
1712  "Handling plaintext size does not match message type.\n");
1713  GNUNET_break_op (0);
1714  queue_finish (queue);
1715  return 0;
1716  }
1717 
1718  thas.purpose.purpose = htonl (
1720  thas.purpose.size = htonl (sizeof(thas));
1721  thas.sender = tca->sender;
1722  thas.receiver = my_identity;
1723  thas.monotonic_time = tca->monotonic_time;
1724  thas.challenge = tca->challenge;
1725 
1728  &thas,
1729  &tca->sender_sig,
1730  &tca->sender.public_key))
1731  {
1733  "Verification of signature failed!\n");
1734  GNUNET_break (0);
1735  queue_finish (queue);
1736  return 0;
1737  }
1738  if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1739  {
1741  "Challenge in TCPConfirmationAck not correct!\n");
1742  GNUNET_break (0);
1743  queue_finish (queue);
1744  return 0;
1745  }
1746 
1748  "transport_tcp_communicator",
1749  &queue->target,
1751  &
1753  queue);
1754 
1756  "Handling plaintext, ack processed!\n");
1757 
1758  if (GNUNET_TRANSPORT_CS_INBOUND == queue->cs)
1759  {
1760  send_challenge (queue->challenge_received, queue);
1761  queue->write_task =
1763  queue->sock,
1764  &queue_write,
1765  queue);
1766  }
1767 
1768  unverified_size = -1;
1769 
1770  char *foreign_addr;
1771 
1772  switch (queue->address->sa_family)
1773  {
1774  case AF_INET:
1775  GNUNET_asprintf (&foreign_addr,
1776  "%s-%s",
1778  GNUNET_a2s (queue->address, queue->address_len));
1779  break;
1780 
1781  case AF_INET6:
1782  GNUNET_asprintf (&foreign_addr,
1783  "%s-%s",
1785  GNUNET_a2s (queue->address, queue->address_len));
1786  break;
1787 
1788  default:
1789  GNUNET_assert (0);
1790  }
1791 
1793  &queue->target,
1794  foreign_addr,
1795  UINT32_MAX, /* no MTU */
1797  0, /* Priority */
1798  queue->nt,
1799  queue->cs,
1800  queue->mq);
1801 
1802  GNUNET_free (foreign_addr);
1803 
1804  size = ntohs (hdr->size);
1805  break;
1807  /* Special case: header size excludes box itself! */
1808  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1809  return 0;
1810  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1811  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1812  {
1813  GNUNET_break_op (0);
1814  queue_finish (queue);
1815  return 0;
1816  }
1817  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1818  size = ntohs (hdr->size) + sizeof(*box);
1820  "Handling plaintext, box processed!\n");
1821  break;
1822 
1824  if (sizeof(*rekey) > queue->pread_off)
1825  return 0;
1826  if (ntohs (hdr->size) != sizeof(*rekey))
1827  {
1828  GNUNET_break_op (0);
1829  queue_finish (queue);
1830  return 0;
1831  }
1832  rekeyz = *rekey;
1833  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1834  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1835  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1836  {
1837  GNUNET_break_op (0);
1838  queue_finish (queue);
1839  return 0;
1840  }
1841  do_rekey (queue, rekey);
1842  size = ntohs (hdr->size);
1844  "Handling plaintext, rekey processed!\n");
1845  break;
1846 
1848  if (sizeof(*fin) > queue->pread_off)
1849  return 0;
1850  if (ntohs (hdr->size) != sizeof(*fin))
1851  {
1852  GNUNET_break_op (0);
1853  queue_finish (queue);
1854  return 0;
1855  }
1856  finz = *fin;
1857  memset (&finz.hmac, 0, sizeof(finz.hmac));
1858  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1859  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1860  {
1861  GNUNET_break_op (0);
1862  queue_finish (queue);
1863  return 0;
1864  }
1865  /* handle FINISH by destroying queue */
1866  queue_destroy (queue);
1868  "Handling plaintext, finish processed!\n");
1869  break;
1870 
1871  default:
1873  "Handling plaintext, nothing processed!\n");
1874  GNUNET_break_op (0);
1875  queue_finish (queue);
1876  return 0;
1877  }
1878  GNUNET_assert (0 != size);
1879  if (-1 != unverified_size)
1880  unverified_size += size;
1881  return size;
1882 }
struct GNUNET_PeerIdentity target
To whom are we talking to.
size_t unverified_size
Size of data received without KX challenge played back.
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
socklen_t address_len
Length of the address.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
static void pass_plaintext_to_core(struct Queue *queue, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext on queue.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer&#39;s HELLOs.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
A 256-bit hashcode.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
this is an inbound connection (communicator initiated)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct ChallengeNonceP challenge_received
Challenge value received.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
static void do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
Handle rekey message on queue.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next...
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
Type of a nonce used for challenges.
TCP message box.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Ack for the encrypted continuation of TCP initial handshake.
struct sockaddr * address
Address of the other peer.
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
TCP rekey message box.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
#define GNUNET_log(kind,...)
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
static void handshake_ack_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_A...
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
static void send_challenge(struct ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
#define GNUNET_free(ptr)
Wrapper around free.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v6()

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

Convert a struct sockaddr_in6 to astruct sockaddr *`.

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

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

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

◆ tcp_address_to_sockaddr_numeric_v4()

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

Convert a struct sockaddr_in4 to astruct sockaddr *`.

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

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

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

◆ tcp_address_to_sockaddr_port_only()

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

Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *

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

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

2055 {
2056  struct PortOnlyIpv4Ipv6 *po;
2057  struct sockaddr_in *i4;
2058  struct sockaddr_in6 *i6;
2059  socklen_t sock_len_ipv4;
2060  socklen_t sock_len_ipv6;
2061 
2062  /* interpreting value as just a PORT number */
2063  if (*port > UINT16_MAX)
2064  {
2066  "BINDTO specification `%s' invalid: value too large for port\n",
2067  bindto);
2068  return NULL;
2069  }
2070 
2071  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2072 
2073  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2074  (GNUNET_YES ==
2077  "DISABLE_V6")))
2078  {
2079  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2080  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2081  *port);
2082  po->addr_len_ipv4 = sock_len_ipv4;
2083  }
2084  else
2085  {
2086 
2087  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2088  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2089  *port);
2090  po->addr_len_ipv4 = sock_len_ipv4;
2091 
2092  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2093  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2094  *port);
2095 
2096  po->addr_len_ipv6 = sock_len_ipv6;
2097 
2098  GNUNET_free (i6);
2099  }
2100 
2101  GNUNET_free (i4);
2102 
2103  return po;
2104 }
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
socklen_t addr_len_ipv4
Length of ipv4 address.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
socklen_t addr_len_ipv6
Length of ipv6 address.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_address()

static char* extract_address ( const char *  bindto)
static

This Method extracts the address part of the BINDTO string.

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

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

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

Referenced by run(), and tcp_address_to_sockaddr().

2115 {
2116 
2117  char *start;
2118  char *token;
2119  char *cp;
2120  char *rest = NULL;
2121  char *res;
2122 
2124  "extract address with bindto %s\n",
2125  bindto);
2126 
2127  if (NULL == bindto)
2129  "bindto is NULL\n");
2130 
2131  cp = GNUNET_strdup (bindto);
2132 
2134  "extract address 2\n");
2135 
2136  start = cp;
2137  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2138  {
2139  start++; /* skip over '['*/
2140  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2141  }
2142  else
2143  {
2144  token = strtok_r (cp, "]", &rest);
2145  if (strlen (bindto) == strlen (token))
2146  {
2147  token = strtok_r (cp, ":", &rest);
2148  }
2149  else
2150  {
2151  token++;
2152  res = GNUNET_strdup (token);
2153  GNUNET_free (cp);
2154  return res;
2155  }
2156  }
2157 
2159  "extract address 3\n");
2161  "extract address with start %s\n",
2162  start);
2163 
2164  return GNUNET_strdup (start);
2165 }
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_.
static int res
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
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 2175 of file gnunet-communicator-tcp.c.

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

Referenced by run(), and tcp_address_to_sockaddr().

2176 {
2177  unsigned int port;
2178  char dummy[2];
2179  char *token;
2180  char *addr;
2181  char *colon;
2182  char *cp;
2183  char *rest = NULL;
2184 
2185  if (NULL != addr_and_port)
2186  {
2187  cp = GNUNET_strdup (addr_and_port);
2188  token = strtok_r (cp, "]", &rest);
2189  if (strlen (addr_and_port) == strlen (token))
2190  {
2191  colon = strrchr (cp, ':');
2192  if (NULL == colon)
2193  {
2194  GNUNET_free (cp);
2195  return 0;
2196  }
2197  addr = colon;
2198  addr++;
2199  }
2200  else
2201  {
2202  token = strtok_r (NULL, "]", &rest);
2203  if (NULL == token)
2204  {
2205  GNUNET_free (cp);
2206  return 0;
2207  }
2208  else
2209  {
2210  addr = token;
2211  addr++;
2212  }
2213  }
2214 
2215 
2216  if (1 == sscanf (addr, "%u%1s", &port, dummy))
2217  {
2218  /* interpreting value as just a PORT number */
2219  if (port > UINT16_MAX)
2220  {
2222  "Port `%u' invalid: value too large for port\n",
2223  port);
2224  GNUNET_free (cp);
2225  return 0;
2226  }
2227  }
2228  else
2229  {
2231  "BINDTO specification invalid: last ':' not followed by number\n");
2232  GNUNET_free (cp);
2233  return 0;
2234  }
2235  }
2236  else
2237  {
2239  "return 0\n");
2240  /* interpret missing port as 0, aka pick any free one */
2241  port = 0;
2242  }
2243 
2244 
2245  return port;
2246 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
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 2257 of file gnunet-communicator-tcp.c.

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

Referenced by mq_init().

2258 {
2259  struct sockaddr *in;
2260  unsigned int port;
2261  struct sockaddr_in v4;
2262  struct sockaddr_in6 v6;
2263  char *start;
2264 
2265  // cp = GNUNET_strdup (bindto);
2266  start = extract_address (bindto);
2267 
2269  "start %s\n",
2270  start);
2271 
2273  "!bindto %s\n",
2274  bindto);
2275 
2276 
2277  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2278  {
2279  // colon = strrchr (cp, ':');
2280  port = extract_port (bindto);
2281 
2283  "port %u\n",
2284  port);
2285 
2286  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2287  }
2288  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2289  {
2290  // colon = strrchr (cp, ':');
2291  port = extract_port (bindto);
2292  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2293  }
2294  else
2295  {
2296  GNUNET_assert (0);
2297  }
2298 
2299  GNUNET_free (start);
2300  return in;
2301 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
#define GNUNET_log(kind,...)
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
#define GNUNET_free(ptr)
Wrapper around free.
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 2313 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().

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

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

Referenced by boot_queue().

2358 {
2359  struct Queue *queue = impl_state;
2360 
2361  if (mq == queue->mq)
2362  {
2363  queue->mq = NULL;
2364  queue_finish (queue);
2365  }
2366 }
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 2376 of file gnunet-communicator-tcp.c.

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

Referenced by boot_queue().

2377 {
2378  struct Queue *queue = impl_state;
2379 
2380  GNUNET_assert (0 != queue->pwrite_off);
2381  queue->pwrite_off = 0;
2382 }
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 2395 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().

2396 {
2397  struct Queue *queue = cls;
2398 
2400  "MQ error in queue to %s: %d\n",
2401  GNUNET_i2s (&queue->target),
2402  (int) error);
2403  queue_finish (queue);
2404 }
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 2415 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().

2416 {
2417  queue->nt =
2420  queue_map,
2421  &queue->target,
2422  queue,
2425  "# queues active",
2427  GNUNET_NO);
2428  queue->timeout =
2431  &mq_destroy,
2432  &mq_cancel,
2433  queue,
2434  NULL,
2435  &mq_error,
2436  queue);
2437 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:314
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:181
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:565
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct sockaddr * address
Address of the other peer.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
enum GNUNET_NetworkType nt
Which network type does this queue use?
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_kx()

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

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

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

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

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

2453 {
2454  struct TcpHandshakeSignature ths;
2455  struct TCPConfirmation tc;
2456 
2457  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2458  queue->cwrite_off = sizeof(*epub);
2459  /* compute 'tc' and append in encrypted format to cwrite_buf */
2460  tc.sender = my_identity;
2461  tc.monotonic_time =
2464  &tc.challenge,
2465  sizeof(tc.challenge));
2466  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2467  ths.purpose.size = htonl (sizeof(ths));
2468  ths.sender = my_identity;
2469  ths.receiver = queue->target;
2470  ths.ephemeral = *epub;
2471  ths.monotonic_time = tc.monotonic_time;
2472  ths.challenge = tc.challenge;
2474  &ths,
2475  &tc.sender_sig);
2476  GNUNET_assert (0 ==
2477  gcry_cipher_encrypt (queue->out_cipher,
2478  &queue->cwrite_buf[queue->cwrite_off],
2479  sizeof(tc),
2480  &tc,
2481  sizeof(tc)));
2482  queue->challenge = tc.challenge;
2483  queue->cwrite_off += sizeof(tc);
2484 
2486  "transport",
2487  "handshake written\n");
2488 }
#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:658
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
Encrypted continuation of TCP initial handshake.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_initial_kx_out()

static void start_initial_kx_out ( struct Queue queue)
static

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

Must be called first before any data is sent.

Parameters
queuethe queue to setup

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

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

◆ handshake_monotime_store_cb()

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

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

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

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

2517 {
2518  struct Queue *queue = cls;
2519  if (GNUNET_OK != success)
2520  {
2522  "Failed to store handshake monotonic time in PEERSTORE!\n");
2523  }
2524  queue->handshake_monotime_sc = NULL;
2525 }
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 2536 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().

2539 {
2540  struct Queue *queue = cls;
2541  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2542  struct GNUNET_TIME_Absolute mt;
2543  const struct GNUNET_PeerIdentity *pid;
2544  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2545 
2546  (void) emsg;
2547 
2548  handshake_monotonic_time = &queue->handshake_monotonic_time;
2549  pid = &queue->target;
2550  if (NULL == record)
2551  {
2552  queue->handshake_monotime_get = NULL;
2553  return;
2554  }
2555  if (sizeof(*mtbe) != record->value_size)
2556  {
2557  GNUNET_break (0);
2558  return;
2559  }
2560  mtbe = record->value;
2561  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2562  if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2564  {
2566  "Queue from %s dropped, handshake monotime in the past\n",
2567  GNUNET_i2s (&queue->target));
2568  GNUNET_break (0);
2569  queue_finish (queue);
2570  return;
2571  }
2573  "transport_tcp_communicator",
2574  pid,
2576  handshake_monotonic_time,
2577  sizeof(*
2578  handshake_monotonic_time),
2581  &
2583  queue);
2584 }
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:542
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 2599 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, TcpHandshakeSignature::sender, TCPConfirmation::sender, TCPConfirmation::sender_sig, GNUNET_CRYPTO_EccSignaturePurpose::size, and Queue::target.

Referenced by proto_read_kx(), and queue_read_kx().

2602 {
2603  struct TcpHandshakeSignature ths;
2604 
2605  GNUNET_assert (
2606  0 ==
2607  gcry_cipher_decrypt (queue->in_cipher,
2608  tc,
2609  sizeof(*tc),
2610  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2611  sizeof(*tc)));
2612  ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
2613  ths.purpose.size = htonl (sizeof(ths));
2614  ths.sender = tc->sender;
2615  ths.receiver = my_identity;
2616  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2617  ths.monotonic_time = tc->monotonic_time;
2618  ths.challenge = tc->challenge;
2619  queue->handshake_monotime_get =
2621  "transport_tcp_communicator",
2622  &queue->target,
2625  queue);
2628  &ths,
2629  &tc->sender_sig,
2630  &tc->sender.public_key);
2631 }
#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 2640 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().

2641 {
2642  if (NULL != pq->listen_sock)
2643  {
2645  pq->listen_sock = NULL;
2646  }
2648  GNUNET_free (pq->address);
2650  GNUNET_free (pq);
2651 }
#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 2661 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_from_nocheck(), 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().

2662 {
2663  struct ProtoQueue *pq = cls;
2664  ssize_t rcvd;
2665  struct GNUNET_TIME_Relative left;
2666  struct Queue *queue;
2667  struct TCPConfirmation tc;
2668 
2669  pq->read_task = NULL;
2671  if (0 == left.rel_value_us)
2672  {
2673  free_proto_queue (pq);
2674  return;
2675  }
2676  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2677  &pq->ibuf[pq->ibuf_off],
2678  sizeof(pq->ibuf) - pq->ibuf_off);
2680  "Received %lu bytes for KX\n", rcvd);
2682  "transport",
2683  "Received %lu bytes for KX\n", rcvd);
2684  if (-1 == rcvd)
2685  {
2686  if ((EAGAIN != errno) && (EINTR != errno))
2687  {
2689  free_proto_queue (pq);
2690  return;
2691  }
2692  /* try again */
2693  pq->read_task =
2695  return;
2696  }
2697  pq->ibuf_off += rcvd;
2698  if (pq->ibuf_off > sizeof(pq->ibuf))
2699  {
2700  /* read more */
2701  pq->read_task =
2703  return;
2704  }
2705  /* we got all the data, let's find out who we are talking to! */
2706  queue = GNUNET_new (struct Queue);
2707  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2708  queue);
2709  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2710  {
2712  "Invalid TCP KX received from %s\n",
2713  GNUNET_a2s (queue->address, queue->address_len));
2714  gcry_cipher_close (queue->in_cipher);
2715  GNUNET_free (queue);
2716  free_proto_queue (pq);
2717  return;
2718  }
2719  queue->address = pq->address; /* steals reference */
2720  queue->address_len = pq->address_len;
2721  queue->target = tc.sender;
2722  queue->listen_sock = pq->listen_sock;
2723  queue->sock = pq->sock;
2724 
2725 
2727  "start kx proto\n");
2728 
2729  start_initial_kx_out (queue);
2731  boot_queue (queue);
2732  queue->read_task =
2734  queue->sock,
2735  &queue_read,
2736  queue);
2737  queue->write_task =
2739  queue->sock,
2740  &queue_write,
2741  queue);
2742  // TODO To early! Move it somewhere else.
2743  // send_challenge (tc.challenge, queue);
2744  queue->challenge_received = tc.challenge;
2745 
2747  GNUNET_free (pq);
2748 }
#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...
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.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
socklen_t address_len
Length of the address.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
struct sockaddr * address
Address of the other peer.
size_t ibuf_off
Current offset for reading into ibuf.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#define GNUNET_log(kind,...)
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read_kx()

static void queue_read_kx ( void *  cls)
static

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

Parameters
clsa struct Queue

Definition at line 2813 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_from_nocheck(), 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().

2814 {
2815  struct Queue *queue = cls;
2816  ssize_t rcvd;
2817  struct GNUNET_TIME_Relative left;
2818  struct TCPConfirmation tc;
2819 
2820  queue->read_task = NULL;
2822  if (0 == left.rel_value_us)
2823  {
2824  queue_destroy (queue);
2825  return;
2826  }
2827  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2828  &queue->cread_buf[queue->cread_off],
2829  BUF_SIZE - queue->cread_off);
2831  "Received %lu bytes for KX\n",
2832  rcvd);
2834  "transport",
2835  "Received %lu bytes for KX\n",
2836  rcvd);
2837  if (-1 == rcvd)
2838  {
2839  if ((EAGAIN != errno) && (EINTR != errno))
2840  {
2842  queue_destroy (queue);
2843  return;
2844  }
2845  queue->read_task =
2846  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2847  return;
2848  }
2849  queue->cread_off += rcvd;
2850  if (queue->cread_off < INITIAL_KX_SIZE)
2851  {
2852  /* read more */
2853  queue->read_task =
2854  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2855  return;
2856  }
2857  /* we got all the data, let's find out who we are talking to! */
2859  queue->cread_buf,
2860  queue);
2861  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2862  {
2864  "Invalid TCP KX received from %s\n",
2865  GNUNET_a2s (queue->address, queue->address_len));
2866  queue_destroy (queue);
2867  return;
2868  }
2869  if (0 !=
2870  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2871  {
2873  "Invalid sender in TCP KX received from %s\n",
2874  GNUNET_a2s (queue->address, queue->address_len));
2875  queue_destroy (queue);
2876  return;
2877  }
2878  send_challenge (tc.challenge, queue);
2879  queue->write_task =
2881  queue->sock,
2882  &queue_write,
2883  queue);
2884 
2885  /* update queue timeout */
2886  reschedule_queue_timeout (queue);
2887  /* prepare to continue with regular read task immediately */
2888  memmove (queue->cread_buf,
2889  &queue->cread_buf[INITIAL_KX_SIZE],
2890  queue->cread_off - (INITIAL_KX_SIZE));
2892  "cread_off is %lu bytes before adjusting\n",
2893  queue->cread_off);
2894  queue->cread_off -= INITIAL_KX_SIZE;
2896  "cread_off set to %lu bytes\n",
2897  queue->cread_off);
2898  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2899 }
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.
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.
The identity of the host (wraps the signing key of the peer).
struct sockaddr * address
Address of the other peer.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
static void send_challenge(struct ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
Time for relative time used by GNUnet, in microseconds.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_init()

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

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

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

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

Definition at line 2921 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_log_from_nocheck(), 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().

2922 {
2923  struct Queue *queue;
2924  const char *path;
2925  struct sockaddr *in;
2926  socklen_t in_len = 0;
2927  struct GNUNET_NETWORK_Handle *sock;
2928 
2930  "Connecting to %s\n", address);
2932  "transport",
2933  "Connecting to %s\n", address);
2934  if (0 != strncmp (address,
2936  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2937  {
2938  GNUNET_break_op (0);
2939  return GNUNET_SYSERR;
2940  }
2941  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2942  in = tcp_address_to_sockaddr (path, &in_len);
2943 
2944  if (NULL == in)
2945  {
2947  "Failed to setup TCP socket address\n");
2948  return GNUNET_SYSERR;
2949  }
2950 
2952  "in %s\n",
2953  GNUNET_a2s (in, in_len));
2954 
2955  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2956  if (NULL == sock)
2957  {
2959  "socket(%d) failed: %s",
2960  in->sa_family,
2961  strerror (errno));
2962  GNUNET_free (in);
2963  return GNUNET_SYSERR;
2964  }
2965  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2966  (errno != EINPROGRESS))
2967  {
2969  "connect to `%s' failed: %s",
2970  address,
2971  strerror (errno));
2973  GNUNET_free (in);
2974  return GNUNET_SYSERR;
2975  }
2976 
2977  queue = GNUNET_new (struct Queue);
2978  queue->target = *peer;
2979  queue->address = in;
2980  queue->address_len = in_len;
2981  queue->sock = sock;
2983  boot_queue (queue);
2984  // queue->mq_awaits_continue = GNUNET_YES;
2985  queue->read_task =
2987  queue->sock,
2988  &queue_read_kx,
2989  queue);
2990 
2991 
2993  "start kx mq_init\n");
2994 
2995  start_initial_kx_out (queue);
2996  queue->write_task =
2998  queue->sock,
2999  &queue_write,
3000  queue);
3001  return GNUNET_OK;
3002 }
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...
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.
#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 3014 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().

3017 {
3018  struct ListenTask *lt = value;
3019 
3020  (void) cls;
3021  (void) key;
3022  if (NULL != lt->listen_task)
3023  {
3025  lt->listen_task = NULL;
3026  }
3027  if (NULL != lt->listen_sock)
3028  {
3030  lt->listen_sock = NULL;
3031  }
3032  return GNUNET_OK;
3033 }
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 3045 of file gnunet-communicator-tcp.c.

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

Referenced by do_shutdown().

3048 {
3049  struct Queue *queue = value;
3050 
3051  (void) cls;
3052  (void) target;
3053  queue_destroy (queue);
3054  return GNUNET_OK;
3055 }
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 3064 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().

3065 {
3067  "Shutdown %s!\n",
3068  shutdown_running ? "running" : "not running");
3069 
3071  return;
3072  else
3074 
3075  while (NULL != proto_head)
3077  if (NULL != nat)
3078  {
3080  nat = NULL;
3081  }
3086  if (NULL != ch)
3087  {
3089  ch = NULL;
3090  }
3091  if (NULL != stats)
3092  {
3094  stats = NULL;
3095  }
3096  if (NULL != my_private_key)
3097  {
3099  my_private_key = NULL;
3100  }
3101  if (NULL != is)
3102  {
3104  is = NULL;
3105  }
3106  if (NULL != peerstore)
3107  {
3109  peerstore = NULL;
3110  }
3111  if (NULL != resolve_request_handle)
3112  {
3114  resolve_request_handle = NULL;
3115  }
3117  "Shutdown done!\n");
3118 }
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 3133 of file gnunet-communicator-tcp.c.

References GNUNET_break_op.

Referenced by init_socket().

3136 {
3137  (void) cls;
3138  (void) sender;
3139  (void) msg;
3140  GNUNET_break_op (0);
3141 }
#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 3158 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().

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