Transport plugin using TCP. More...
#include "platform.h"
#include "gnunet_common.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_nat_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_communication_service.h"
#include "gnunet_resolver_service.h"
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 | TCPNATProbeMessage |
Basically a WELCOME message, but with the purpose of giving the waiting peer a client handle to use. More... | |
struct | PendingReversal |
Struct for pending nat reversals. 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 | NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
How long until we give up on establishing an NAT connection? Must be > 4 RTT. More... | |
#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 * 400) |
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 | eddsa_priv_to_hpke_key (struct GNUNET_CRYPTO_EddsaPrivateKey *edpk, struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
static void | eddsa_pub_to_hpke_key (struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_EcdhePublicKey *pk) |
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 | 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_ShortHashCode *prk, 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_elligator (const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct Queue *queue) |
Setup cipher of queue for decryption from an elligator representative. More... | |
static void | setup_in_cipher (const struct GNUNET_CRYPTO_HpkeEncapsulation *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 GNUNET_CRYPTO_ChallengeNonceP challenge, struct Queue *queue) |
Sending challenge with TcpConfirmationAck back to sender of ephemeral key. More... | |
static void | setup_out_cipher (struct Queue *queue, struct GNUNET_ShortHashCode *dh) |
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 int | pending_reversals_delete_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
static void | check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family, struct GNUNET_PeerIdentity *sender) |
static void | free_proto_queue (struct ProtoQueue *pq) |
Closes socket and frees memory associated with pq. More... | |
static void | proto_queue_write (void *cls) |
We have been notified that our socket is ready to write. 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 a struct 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 a struct sockaddr *`. More... | |
static struct PortOnlyIpv4Ipv6 * | tcp_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_HpkeEncapsulation *c) |
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 | 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 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 struct ProtoQueue * | create_proto_queue (struct GNUNET_NETWORK_Handle *sock, struct sockaddr *in, socklen_t addrlen) |
static void | try_connection_reversal (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
static void | pending_reversal_timeout (void *cls) |
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_HashCode *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_Handle * | stats |
For logging statistics. More... | |
static struct GNUNET_TRANSPORT_CommunicatorHandle * | ch |
Our environment. More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | queue_map |
Queues (map from peer identity to struct Queue ) More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | lt_map |
ListenTasks (map from socket to struct ListenTask ) More... | |
static struct GNUNET_PeerIdentity | my_identity |
Our public key. More... | |
static unsigned long long | rekey_max_bytes |
The rekey byte maximum. More... | |
static struct GNUNET_TIME_Relative | rekey_interval |
The rekey interval. More... | |
static struct GNUNET_CRYPTO_EddsaPrivateKey * | my_private_key |
Our private key. More... | |
static struct GNUNET_CRYPTO_EcdhePrivateKey | my_x25519_private_key |
Our private key. More... | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Our configuration. More... | |
static struct GNUNET_NT_InterfaceScanner * | is |
Network scanner to determine network types. More... | |
static struct GNUNET_NAT_Handle * | nat |
Connection to NAT service. More... | |
static struct ProtoQueue * | proto_head |
Protoqueues DLL head. More... | |
static struct ProtoQueue * | proto_tail |
Protoqueues DLL tail. More... | |
struct GNUNET_RESOLVER_RequestHandle * | resolve_request_handle |
Handle for DNS lookup of bindto address. More... | |
static struct Addresses * | addrs_head |
Head of DLL with addresses we like to register at NAT service. More... | |
static struct Addresses * | addrs_tail |
Head of DLL with addresses we like to register at NAT service. More... | |
static int | addrs_lens |
Number of addresses in the DLL for register at NAT service. More... | |
static struct GNUNET_PEERSTORE_Handle * | peerstore |
Database for peer's HELLOs. More... | |
static int | shutdown_running = GNUNET_NO |
A flag indicating we are already doing a shutdown. More... | |
static int | disable_v6 |
IPv6 disabled. More... | |
static unsigned int | bind_port |
The port the communicator should be assigned to. More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | pending_reversals |
Map of pending reversals. More... | |
Transport plugin using TCP.
TODO:
Definition in file gnunet-communicator-tcp.c.
#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
How long until we give up on establishing an NAT connection? Must be > 4 RTT.
Definition at line 48 of file gnunet-communicator-tcp.c.
#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 54 of file gnunet-communicator-tcp.c.
#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 65 of file gnunet-communicator-tcp.c.
#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 71 of file gnunet-communicator-tcp.c.
#define DEFAULT_REKEY_INTERVAL GNUNET_TIME_UNIT_DAYS |
How often do we rekey based on time (at least)
Definition at line 76 of file gnunet-communicator-tcp.c.
#define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES |
How long do we wait until we must have received the initial KX?
Definition at line 81 of file gnunet-communicator-tcp.c.
#define REKEY_MAX_BYTES (1024LLU * 1024 * 400) |
How often do we rekey based on number of bytes transmitted? (additionally randomized).
Currently 400 MB
Definition at line 87 of file gnunet-communicator-tcp.c.
#define INITIAL_KX_SIZE |
Size of the initial key exchange message sent first in both directions.
Definition at line 93 of file gnunet-communicator-tcp.c.
#define INITIAL_CORE_KX_SIZE |
Size of the initial core key exchange messages.
Definition at line 100 of file gnunet-communicator-tcp.c.
#define COMMUNICATOR_ADDRESS_PREFIX "tcp" |
Address prefix used by the communicator.
Definition at line 108 of file gnunet-communicator-tcp.c.
#define COMMUNICATOR_CONFIG_SECTION "communicator-tcp" |
Configuration section used by the communicator.
Definition at line 113 of file gnunet-communicator-tcp.c.
|
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.
cls | NULL |
Do the read and reschedule this function to be called again once more is available.
cls | ListenTask with listening socket and task |
Definition at line 3234 of file gnunet-communicator-tcp.c.
References create_proto_queue(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_memdup, GNUNET_NETWORK_socket_accept(), GNUNET_SCHEDULER_add_read_net(), GNUNET_TIME_UNIT_FOREVER_REL, listen_cb(), ListenTask::listen_sock, and ListenTask::listen_task.
Referenced by GNUNET_SET_listen(), GNUNET_SETI_listen(), GNUNET_SETU_listen(), init_socket(), listen_cb(), and queue_destroy().
|
static |
Definition at line 947 of file gnunet-communicator-tcp.c.
References GNUNET_CRYPTO_hpke_sk_to_x25519(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, key, and pk.
Referenced by init_socket().
|
static |
Definition at line 958 of file gnunet-communicator-tcp.c.
References GNUNET_CRYPTO_hpke_pk_to_x25519(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, key, and pk.
Referenced by mq_init(), and proto_read_kx().
|
static |
Functions with this signature are called whenever we need to close a queue due to a disconnect or failure to establish a connection.
queue | queue to close down |
Definition at line 976 of file gnunet-communicator-tcp.c.
References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_multihashmap_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_iteration_stop(), 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, listen_cb(), ListenTask::listen_sock, ListenTask::listen_task, lt_map, queue(), queue_map, shutdown_running, and stats.
Referenced by get_queue_delete_it(), queue_read(), queue_read_kx(), queue_write(), and try_handle_plaintext().
|
static |
Compute mac over buf, and ratched the hmac_secret.
[in,out] | hmac_secret | secret for HMAC calculation |
buf | buffer to MAC | |
buf_size | number of bytes in buf | |
[out] | smac | where to write the HMAC |
Definition at line 1087 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().
|
static |
Append a 'finish' message to the outgoing transmission.
Once the finish has been transmitted, destroy the queue.
queue | queue to shut down nicely |
Definition at line 1115 of file gnunet-communicator-tcp.c.
References calculate_hmac(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH, GNUNET_YES, TCPFinish::header, TCPFinish::hmac, queue(), GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.
Referenced by do_rekey(), handshake_ack_monotime_cb(), handshake_monotime_cb(), mq_destroy(), mq_error(), rekey_monotime_cb(), and try_handle_plaintext().
|
static |
Queue read task.
If we hit the timeout, disconnect it
cls | the struct Queue * to disconnect |
Definition at line 2179 of file gnunet-communicator-tcp.c.
References BUF_SIZE, GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_log_strerror, GNUNET_MIN, GNUNET_NETWORK_socket_recv(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, max, max_queue_length, queue(), queue_destroy(), queue_read(), GNUNET_TIME_Relative::rel_value_us, and try_handle_plaintext().
Referenced by core_read_finished_cb(), proto_read_kx(), queue_read(), and queue_read_kx().
|
static |
Core tells us it is done processing a message that transport received on a queue with status success.
Definition at line 1153 of file gnunet-communicator-tcp.c.
References GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 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_TIME_relative_to_absolute(), GNUNET_YES, queue(), queue_read(), and stats.
Referenced by pass_plaintext_to_core().
|
static |
We received plaintext_len bytes of plaintext on queue.
Pass it on to CORE. If transmission is actually happening, increase backpressure counter.
queue | the queue that received the plaintext |
plaintext | the plaintext that was received |
plaintext_len | number of bytes of plaintext received |
Definition at line 1202 of file gnunet-communicator-tcp.c.
References ADDRESS_VALIDITY_PERIOD, ch, core_read_finished_cb(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TRANSPORT_communicator_receive(), queue(), ret, GNUNET_MessageHeader::size, and stats.
Referenced by try_handle_plaintext().
|
static |
Setup cipher based on shared secret dh and decrypting peer pid.
dh | shared secret | |
pid | decrypting peer's identity | |
[out] | cipher | cipher to initialize |
[out] | hmac_key | HMAC key to initialize |
Definition at line 1249 of file gnunet-communicator-tcp.c.
References GNUNET_assert, GNUNET_CRYPTO_hkdf_expand(), GNUNET_YES, and key.
Referenced by setup_in_cipher(), setup_in_cipher_elligator(), and setup_out_cipher().
|
static |
Callback called when peerstore store operation for rekey monotime value is finished.
cls | Queue context the store operation was executed. |
success | Store operation was successful (GNUNET_OK) or not. |
Definition at line 1299 of file gnunet-communicator-tcp.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_iteration_next(), and queue().
Referenced by rekey_monotime_cb().
|
static |
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where found.
cls | Queue context the store operation was executed. |
record | The record found or NULL if there is no record left. |
emsg | Message from peerstore. |
Definition at line 1320 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_iteration_next(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, peerstore, pid, queue(), queue_finish(), record(), and rekey_monotime_store_cb().
Referenced by do_rekey().
|
static |
Setup cipher of queue for decryption from an elligator representative.
ephemeral | ephemeral key we received from the other peer (elligator representative) | |
[in,out] | queue | queue to initialize decryption cipher for |
Definition at line 1381 of file gnunet-communicator-tcp.c.
References GNUNET_CRYPTO_hpke_elligator_kem_decaps(), my_identity, my_x25519_private_key, queue(), and setup_cipher().
Referenced by proto_read_kx(), and queue_read_kx().
|
static |
Setup cipher of queue for decryption.
ephemeral | ephemeral key we received from the other peer | |
[in,out] | queue | queue to initialize decryption cipher for |
Definition at line 1399 of file gnunet-communicator-tcp.c.
References GNUNET_CRYPTO_eddsa_kem_decaps(), my_identity, my_private_key, queue(), and setup_cipher().
Referenced by do_rekey().
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.
queue | the queue rekey was received on |
rekey | the rekey message |
Definition at line 1418 of file gnunet-communicator-tcp.c.
References TCPRekey::ephemeral, TcpRekeySignature::ephemeral, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_eddsa_verify, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_p2s(), GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY, GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, TCPRekey::monotonic_time, TcpRekeySignature::monotonic_time, my_identity, peerstore, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpRekeySignature::purpose, queue(), queue_finish(), TcpRekeySignature::receiver, rekey_monotime_cb(), TcpRekeySignature::sender, TCPRekey::sender_sig, setup_in_cipher(), and GNUNET_CRYPTO_EccSignaturePurpose::size.
Referenced by try_handle_plaintext().
|
static |
Callback called when peerstore store operation for handshake ack monotime value is finished.
cls | Queue context the store operation was executed. |
success | Store operation was successful (GNUNET_OK) or not. |
Definition at line 1481 of file gnunet-communicator-tcp.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_iteration_next(), and queue().
Referenced by handshake_ack_monotime_cb().
|
static |
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK where found.
cls | Queue context the store operation was executed. |
record | The record found or NULL if there is no record left. |
emsg | Message from peerstore. |
Definition at line 1503 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_iteration_next(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, handshake_ack_monotime_store_cb(), peerstore, pid, queue(), queue_finish(), and record().
Referenced by try_handle_plaintext().
|
static |
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
tc | The TCPConfirmation originally send. |
queue | The queue context. |
Definition at line 1564 of file gnunet-communicator-tcp.c.
References cfg, TcpHandshakeAckSignature::challenge, TCPConfirmationAck::challenge, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK, GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TCPConfirmationAck::header, TcpHandshakeAckSignature::monotonic_time, TCPConfirmationAck::monotonic_time, my_identity, my_private_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeAckSignature::purpose, queue(), TcpHandshakeAckSignature::receiver, TcpHandshakeAckSignature::sender, TCPConfirmationAck::sender, TCPConfirmationAck::sender_sig, GNUNET_MessageHeader::size, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_MessageHeader::type.
Referenced by queue_read_kx(), and try_handle_plaintext().
|
static |
Setup cipher for outgoing data stream based on target and our ephemeral private key.
queue | queue to setup outgoing (encryption) cipher for |
Definition at line 1609 of file gnunet-communicator-tcp.c.
References GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_TIME_relative_to_absolute(), queue(), rekey_interval, rekey_max_bytes, and setup_cipher().
Referenced by inject_rekey(), and start_initial_kx_out().
|
static |
Inject a struct TCPRekey
message into the queue's plaintext buffer.
queue | queue to perform rekeying on |
Definition at line 1625 of file gnunet-communicator-tcp.c.
References calculate_hmac(), cfg, TCPRekey::ephemeral, TcpRekeySignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_kem_encaps(), GNUNET_CRYPTO_eddsa_sign, GNUNET_e2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY, GNUNET_p2s(), GNUNET_SIGNATURE_PURPOSE_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, my_private_key, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpRekeySignature::purpose, queue(), TcpRekeySignature::receiver, TcpRekeySignature::sender, TCPRekey::sender_sig, setup_out_cipher(), GNUNET_MessageHeader::size, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_MessageHeader::type.
Referenced by mq_send_d(), and queue_write().
|
static |
Definition at line 1681 of file gnunet-communicator-tcp.c.
References GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, PendingReversal::in, key, pending_reversals, PendingReversal::timeout_task, and value.
Referenced by check_and_remove_pending_reversal(), and do_shutdown().
|
static |
Definition at line 1704 of file gnunet-communicator-tcp.c.
References GNUNET_a2s(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_memdup, key, pending_reversals, pending_reversals_delete_it(), and PendingReversal::target.
Referenced by free_proto_queue(), proto_read_kx(), and try_handle_plaintext().
|
static |
Closes socket and frees memory associated with pq.
pq | proto queue to free |
Definition at line 1744 of file gnunet-communicator-tcp.c.
References ProtoQueue::address, check_and_remove_pending_reversal(), GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), ProtoQueue::listen_sock, proto_head, proto_tail, ProtoQueue::read_task, ProtoQueue::sock, and ProtoQueue::write_task.
Referenced by do_shutdown(), proto_queue_write(), and proto_read_kx().
|
static |
We have been notified that our socket is ready to write.
Then reschedule this function to be called again once more is available.
cls | a struct ProtoQueue |
Definition at line 1776 of file gnunet-communicator-tcp.c.
References free_proto_queue(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_send(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, proto_queue_write(), ProtoQueue::sock, ProtoQueue::write_buf, ProtoQueue::write_off, and ProtoQueue::write_task.
Referenced by proto_queue_write(), and try_connection_reversal().
|
static |
We have been notified that our socket is ready to write.
Then reschedule this function to be called again once more is available.
cls | a struct Queue |
Definition at line 1821 of file gnunet-communicator-tcp.c.
References BUF_SIZE, GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 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_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, inject_rekey(), queue(), queue_destroy(), queue_write(), and GNUNET_TIME_Relative::rel_value_us.
Referenced by mq_init(), mq_send(), proto_read_kx(), queue_read_kx(), queue_write(), and try_handle_plaintext().
|
static |
Test if we have received a full message in plaintext.
If so, handle it.
queue | queue to process inbound plaintext for |
Once we received this ack, we consider this a verified connection. FIXME: I am not sure this logic is sane here.
Definition at line 1920 of file gnunet-communicator-tcp.c.
References calculate_hmac(), ch, TcpHandshakeAckSignature::challenge, TCPConfirmationAck::challenge, check_and_remove_pending_reversal(), COMMUNICATOR_ADDRESS_PREFIX, 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_NO, GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, GNUNET_SCHEDULER_add_write_net(), GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_CS_INBOUND, GNUNET_TRANSPORT_CS_OUTBOUND, GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, GNUNET_YES, handshake_ack_monotime_cb(), TCPBox::hmac, TCPRekey::hmac, TCPFinish::hmac, INITIAL_CORE_KX_SIZE, TcpHandshakeAckSignature::monotonic_time, TCPConfirmationAck::monotonic_time, my_identity, pass_plaintext_to_core(), peerstore, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeAckSignature::purpose, queue(), queue_destroy(), queue_finish(), queue_write(), TcpHandshakeAckSignature::receiver, send_challenge(), TcpHandshakeAckSignature::sender, TCPConfirmationAck::sender, TCPConfirmationAck::sender_sig, GNUNET_MessageHeader::size, GNUNET_CRYPTO_EccSignaturePurpose::size, size, stats, type, and GNUNET_MessageHeader::type.
Referenced by queue_read().
|
static |
Convert a struct sockaddr_in6 to a
struct sockaddr *`.
[out] | sock_len | set to the length of the address. |
v6 | The sockaddr_in6 to be converted. |
Definition at line 2307 of file gnunet-communicator-tcp.c.
References GNUNET_memdup, and port.
Referenced by init_socket_resolv(), run(), tcp_address_to_sockaddr(), and tcp_address_to_sockaddr_port_only().
|
static |
Convert a struct sockaddr_in4 to a
struct sockaddr *`.
[out] | sock_len | set to the length of the address. |
v4 | The sockaddr_in4 to be converted. |
Definition at line 2335 of file gnunet-communicator-tcp.c.
References GNUNET_memdup, and port.
Referenced by init_socket_resolv(), run(), tcp_address_to_sockaddr(), and tcp_address_to_sockaddr_port_only().
|
static |
Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
bindto | bind specification to convert. |
Definition at line 2359 of file gnunet-communicator-tcp.c.
References PortOnlyIpv4Ipv6::addr_ipv4, PortOnlyIpv4Ipv6::addr_ipv6, PortOnlyIpv4Ipv6::addr_len_ipv4, PortOnlyIpv4Ipv6::addr_len_ipv6, disable_v6, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_new, GNUNET_YES, port, tcp_address_to_sockaddr_numeric_v4(), and tcp_address_to_sockaddr_numeric_v6().
Referenced by run().
|
static |
This Method extracts the address part of the BINDTO string.
bindto | String we extract the address part from. |
Definition at line 2415 of file gnunet-communicator-tcp.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_strdup, and start.
Referenced by run(), and tcp_address_to_sockaddr().
|
static |
This Method extracts the port part of the BINDTO string.
addr_and_port | String we extract the port from. |
Definition at line 2473 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().
|
static |
Convert TCP bind specification to a struct sockaddr *
bindto | bind specification to convert | |
[out] | sock_len | set to the length of the address |
Definition at line 2555 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().
|
static |
Signature of functions implementing the sending functionality of a message queue.
mq | the message queue |
msg | the message to send |
impl_state | our struct Queue |
Definition at line 2609 of file gnunet-communicator-tcp.c.
References calculate_hmac(), 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, mq, msg, queue(), queue_write(), GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.
Referenced by boot_queue().
|
static |
Signature of functions implementing the destruction of a message queue.
Implementations must not free mq, but should take care of impl_state.
mq | the message queue to destroy |
impl_state | our struct Queue |
Definition at line 2653 of file gnunet-communicator-tcp.c.
References mq, queue(), and queue_finish().
Referenced by boot_queue().
|
static |
Implementation function that cancels the currently sent message.
mq | message queue |
impl_state | our struct Queue |
Definition at line 2672 of file gnunet-communicator-tcp.c.
References GNUNET_assert, and queue().
Referenced by boot_queue().
|
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.
cls | our struct Queue |
error | error code |
Definition at line 2691 of file gnunet-communicator-tcp.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, queue(), and queue_finish().
Referenced by boot_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.
queue | queue to boot |
Definition at line 2711 of file gnunet-communicator-tcp.c.
References GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_MQ_queue_for_callbacks(), GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_STATISTICS_set(), GNUNET_TIME_relative_to_absolute(), is, mq_cancel(), mq_destroy(), mq_error(), mq_send(), queue(), queue_map, and stats.
Referenced by mq_init(), and proto_read_kx().
|
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().
queue | queue to do KX for |
epub | our public key for the KX |
Definition at line 2747 of file gnunet-communicator-tcp.c.
References cfg, TcpHandshakeSignature::challenge, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TcpHandshakeSignature::monotonic_time, my_identity, my_private_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, queue(), TcpHandshakeSignature::receiver, TcpHandshakeSignature::sender, GNUNET_CRYPTO_EccSignaturePurpose::size, and tc.
Referenced by start_initial_kx_out().
|
static |
Initialize our key material for outgoing transmissions and inform the other peer about it.
Must be called first before any data is sent.
queue | the queue to setup |
Definition at line 2795 of file gnunet-communicator-tcp.c.
References GNUNET_CRYPTO_hpke_elligator_kem_encaps(), queue(), setup_out_cipher(), and transmit_kx().
Referenced by mq_init(), and proto_read_kx().
|
static |
Callback called when peerstore store operation for handshake monotime is finished.
cls | Queue context the store operation was executed. |
success | Store operation was successful (GNUNET_OK) or not. |
Definition at line 2813 of file gnunet-communicator-tcp.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_iteration_next(), and queue().
Referenced by handshake_monotime_cb().
|
static |
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE where found.
cls | Queue context the store operation was executed. |
record | The record found or NULL if there is no record left. |
emsg | Message from peerstore. |
Definition at line 2834 of file gnunet-communicator-tcp.c.
References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_PEERSTORE_iteration_next(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, handshake_monotime_store_cb(), my_identity, peerstore, pid, queue(), queue_finish(), and record().
Referenced by decrypt_and_check_tc().
|
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.
queue | queue to decrypt initial bytes from other peer for | |
[out] | tc | where to store the result |
ibuf | incoming data, of size INITIAL_KX_SIZE |
Definition at line 2906 of file gnunet-communicator-tcp.c.
References TcpHandshakeSignature::challenge, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_verify, GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE, GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE, GNUNET_YES, handshake_monotime_cb(), TcpHandshakeSignature::monotonic_time, my_identity, peerstore, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TcpHandshakeSignature::purpose, queue(), TcpHandshakeSignature::receiver, ret, TcpHandshakeSignature::sender, GNUNET_CRYPTO_EccSignaturePurpose::size, and tc.
Referenced by proto_read_kx(), and queue_read_kx().
|
static |
Read from the socket of the queue until we have enough data to initialize the decryption logic and can switch to regular reading.
cls | a struct Queue |
Definition at line 2953 of file gnunet-communicator-tcp.c.
References BUF_SIZE, decrypt_and_check_tc(), GNUNET_a2s(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recv(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, INITIAL_KX_SIZE, queue(), queue_destroy(), queue_read(), queue_read_kx(), queue_write(), GNUNET_TIME_Relative::rel_value_us, send_challenge(), setup_in_cipher_elligator(), and tc.
Referenced by mq_init(), proto_read_kx(), and queue_read_kx().
|
static |
Read from the socket of the proto queue until we have enough data to upgrade to full queue.
cls | a struct ProtoQueue |
Definition at line 3059 of file gnunet-communicator-tcp.c.
References ProtoQueue::address, ProtoQueue::address_len, boot_queue(), check_and_remove_pending_reversal(), decrypt_and_check_tc(), eddsa_pub_to_hpke_key(), 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_i2s(), GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recv(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CS_INBOUND, GNUNET_TRANSPORT_CS_OUTBOUND, ProtoQueue::ibuf, ProtoQueue::ibuf_off, ProtoQueue::listen_sock, pm, proto_head, proto_read_kx(), proto_tail, queue(), queue_read(), queue_read_kx(), queue_write(), read_task, ProtoQueue::read_task, GNUNET_TIME_Relative::rel_value_us, setup_in_cipher_elligator(), ProtoQueue::sock, start_initial_kx_out(), tc, and ProtoQueue::timeout.
Referenced by create_proto_queue(), and proto_read_kx().
|
static |
Definition at line 3179 of file gnunet-communicator-tcp.c.
References ProtoQueue::address, ProtoQueue::address_len, GNUNET_a2s(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_TIME_relative_to_absolute(), proto_head, PROTO_QUEUE_TIMEOUT, proto_read_kx(), proto_tail, ProtoQueue::read_task, ProtoQueue::sock, and ProtoQueue::timeout.
Referenced by listen_cb(), and try_connection_reversal().
|
static |
Definition at line 3273 of file gnunet-communicator-tcp.c.
References create_proto_queue(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memdup, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, GNUNET_SCHEDULER_add_write_net(), my_identity, pm, PROTO_QUEUE_TIMEOUT, proto_queue_write(), ProtoQueue::sock, ProtoQueue::write_buf, ProtoQueue::write_off, and ProtoQueue::write_task.
Referenced by nat_register().
|
static |
Definition at line 3313 of file gnunet-communicator-tcp.c.
References GNUNET_a2s(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NO, PendingReversal::in, key, and pending_reversals.
Referenced by mq_init().
|
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.
cls | closure |
peer | identity of the other peer |
address | where to send the message, human-readable communicator-specific format, 0-terminated, UTF-8 |
Definition at line 3357 of file gnunet-communicator-tcp.c.
References address, bind_port, boot_queue(), COMMUNICATOR_ADDRESS_PREFIX, disable_v6, eddsa_pub_to_hpke_key(), GNUNET_a2s(), GNUNET_assert, GNUNET_break_op, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_context_finish(), GNUNET_CRYPTO_hash_context_read(), GNUNET_CRYPTO_hash_context_start(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NAT_request_reversal(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CS_OUTBOUND, GNUNET_YES, PendingReversal::in, key, nat, NAT_TIMEOUT, pending_reversal_timeout(), pending_reversals, queue(), queue_map, queue_read_kx(), queue_write(), start_initial_kx_out(), PendingReversal::target, tcp_address_to_sockaddr(), and PendingReversal::timeout_task.
Referenced by init_socket().
|
static |
Iterator over all ListenTasks to clean up.
cls | NULL |
key | unused |
value | the ListenTask to cancel. |
Definition at line 3564 of file gnunet-communicator-tcp.c.
References GNUNET_break, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), key, ListenTask::listen_sock, ListenTask::listen_task, and value.
Referenced by do_shutdown().
|
static |
Iterator over all message queues to clean up.
cls | NULL |
target | unused |
value | the queue to destroy |
Definition at line 3596 of file gnunet-communicator-tcp.c.
References GNUNET_OK, queue(), queue_destroy(), Queue::target, and value.
Referenced by do_shutdown().
|
static |
Shutdown the UNIX communicator.
cls | NULL (always) |
Definition at line 3615 of file gnunet-communicator-tcp.c.
References ch, free_proto_queue(), get_lt_delete_it(), get_queue_delete_it(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NAT_unregister(), 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, is, lt_map, my_private_key, nat, peerstore, pending_reversals, pending_reversals_delete_it(), proto_head, queue_map, resolve_request_handle, shutdown_running, and stats.
Referenced by run().
|
static |
Function called when the transport service has received an acknowledgement for this communicator (!) via a different return path.
Not applicable for TCP.
cls | closure |
sender | which peer sent the notification |
msg | payload |
Definition at line 3688 of file gnunet-communicator-tcp.c.
References GNUNET_break_op, and msg.
Referenced by init_socket().
|
static |
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.
cls | closure | |
[in,out] | app_ctx | location where the app can store stuff on add and retrieve it on remove |
add_remove | GNUNET_YES to add a new public IP address, GNUNET_NO to remove a previous (now invalid) one | |
ac | address class the address belongs to | |
addr | either the previous or the new public IP address | |
addrlen | actual length of the addr |
Definition at line 3713 of file gnunet-communicator-tcp.c.
References ai, ch, 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, is, and nt.
Referenced by nat_register().
|
static |
This method adds addresses to the DLL, that are later register at the NAT service.
Definition at line 3758 of file gnunet-communicator-tcp.c.
References Addresses::addr, Addresses::addr_len, addrs_head, addrs_lens, addrs_tail, GNUNET_a2s(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and GNUNET_new.
Referenced by init_socket().
|
static |
This method launch network interactions for each address we like to bind to.
addr | The address we will listen to. |
in_len | The length of the address we will listen to. |
Definition at line 3792 of file gnunet-communicator-tcp.c.
References _, add_addr(), cfg, ch, COMMUNICATOR_ADDRESS_PREFIX, COMMUNICATOR_CONFIG_SECTION, eddsa_priv_to_hpke_key(), enc_notify_cb(), GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_get_fd(), GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_listen(), GNUNET_new, GNUNET_NO, GNUNET_NT_scanner_init(), GNUNET_OK, GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CC_RELIABLE, GNUNET_TRANSPORT_communicator_connect(), is, listen_cb(), ListenTask::listen_sock, ListenTask::listen_task, lt_map, mq_init(), my_identity, my_private_key, my_x25519_private_key, GNUNET_PeerIdentity::public_key, queue_map, resolve_request_handle, and stats.
Referenced by init_socket_resolv(), and run().
|
static |
This method reads from the DLL addrs_head to register them at the NAT service.
Definition at line 3945 of file gnunet-communicator-tcp.c.
References Addresses::addr, Addresses::addr_len, addrs_head, addrs_lens, cfg, COMMUNICATOR_CONFIG_SECTION, GNUNET_a2s(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memdup, GNUNET_NAT_register(), GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_shutdown(), nat, nat_address_cb(), Addresses::next, resolve_request_handle, and try_connection_reversal().
Referenced by init_socket_resolv(), and run().
|
static |
This method is the callback called by the resolver API, and wraps method init_socket.
cls | The port we will bind to. |
addr | The address we will bind to. |
in_len | The length of the address we will bind to. |
Definition at line 4008 of file gnunet-communicator-tcp.c.
References addrs_head, bind_port, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, init_socket(), nat_register(), tcp_address_to_sockaddr_numeric_v4(), and tcp_address_to_sockaddr_numeric_v6().
Referenced by run().
|
static |
Setup communicator and launch network interactions.
cls | NULL (always) |
args | remaining command-line arguments |
cfgfile | name of the configuration file used (for saving, can be NULL!) |
c | configuration |
Definition at line 4064 of file gnunet-communicator-tcp.c.
References PortOnlyIpv4Ipv6::addr_ipv4, PortOnlyIpv4Ipv6::addr_ipv6, PortOnlyIpv4Ipv6::addr_len_ipv4, PortOnlyIpv4Ipv6::addr_len_ipv6, bind_port, cfg, COMMUNICATOR_CONFIG_SECTION, DEFAULT_MAX_QUEUE_LENGTH, DEFAULT_REKEY_INTERVAL, disable_v6, do_shutdown(), dummy, extract_address(), extract_port(), GNUNET_a2s(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_NETWORK_test_pf(), GNUNET_NO, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_RESOLVER_ip_get(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, init_socket(), init_socket_resolv(), max_queue_length, nat_register(), peerstore, pending_reversals, port, rekey_interval, REKEY_MAX_BYTES, rekey_max_bytes, resolve_request_handle, start, tcp_address_to_sockaddr_numeric_v4(), tcp_address_to_sockaddr_numeric_v6(), and tcp_address_to_sockaddr_port_only().
Referenced by main().
int main | ( | int | argc, |
char *const * | argv | ||
) |
The main function for the UNIX communicator.
argc | number of arguments from the command line |
argv | command line arguments |
Definition at line 4212 of file gnunet-communicator-tcp.c.