Very first draft of a gnunet libp2p communicator. More...
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_util_lib.h"
#include "gnunet_pils_service.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"
#include <libp2p/basic/scheduler.hpp>
#include <libp2p/common/literals.hpp>
#include <libp2p/injector/host_injector.hpp>
#include <libp2p/layer/websocket/ws_adaptor.hpp>
#include <libp2p/log/configurator.hpp>
#include <libp2p/log/logger.hpp>
#include <libp2p/protocol/echo.hpp>
Go to the source code of this file.
Data Structures | |
struct | Queue |
Handle for a queue. More... | |
struct | Addresses |
DLL to store the addresses we like to register at NAT service. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "communicator-tcp", __VA_ARGS__) |
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 | 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 | 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 enum GNUNET_GenericReturnValue | load_ikm () |
FIXME: We could alternatively ask PILS for de/encaps, but at a high cost wrt async RPC calls... 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... | |
void | pid_change_cb (void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash) |
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 struct GNUNET_PILS_Handle * | pils |
For PILS. 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 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 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 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... | |
Very first draft of a gnunet libp2p communicator.
This is not in any way in a working or compiling state
Definition in file gnunet-communicator-libp2p.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "communicator-tcp", __VA_ARGS__) |
Definition at line 53 of file gnunet-communicator-libp2p.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 2481 of file gnunet-communicator-libp2p.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 194 of file gnunet-communicator-libp2p.c.
References GNUNET_CRYPTO_hpke_sk_to_x25519(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, key, and pk.
Referenced by pid_change_cb().
|
static |
Definition at line 205 of file gnunet-communicator-libp2p.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 223 of file gnunet-communicator-libp2p.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 334 of file gnunet-communicator-libp2p.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 362 of file gnunet-communicator-libp2p.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 1426 of file gnunet-communicator-libp2p.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 400 of file gnunet-communicator-libp2p.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 449 of file gnunet-communicator-libp2p.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 496 of file gnunet-communicator-libp2p.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 546 of file gnunet-communicator-libp2p.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 567 of file gnunet-communicator-libp2p.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 628 of file gnunet-communicator-libp2p.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 646 of file gnunet-communicator-libp2p.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 665 of file gnunet-communicator-libp2p.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 728 of file gnunet-communicator-libp2p.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 750 of file gnunet-communicator-libp2p.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 811 of file gnunet-communicator-libp2p.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 856 of file gnunet-communicator-libp2p.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 872 of file gnunet-communicator-libp2p.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 928 of file gnunet-communicator-libp2p.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 951 of file gnunet-communicator-libp2p.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 991 of file gnunet-communicator-libp2p.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 1023 of file gnunet-communicator-libp2p.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().
|
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 1068 of file gnunet-communicator-libp2p.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 1167 of file gnunet-communicator-libp2p.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 1554 of file gnunet-communicator-libp2p.c.
References GNUNET_memdup, and port.
Referenced by 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 1582 of file gnunet-communicator-libp2p.c.
References GNUNET_memdup, and port.
Referenced by 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 1606 of file gnunet-communicator-libp2p.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 1662 of file gnunet-communicator-libp2p.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_strdup, and start.
Referenced by 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 1720 of file gnunet-communicator-libp2p.c.
References dummy, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_strdup, and port.
Referenced by 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 1802 of file gnunet-communicator-libp2p.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 1856 of file gnunet-communicator-libp2p.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 1900 of file gnunet-communicator-libp2p.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 1919 of file gnunet-communicator-libp2p.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 1938 of file gnunet-communicator-libp2p.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 1958 of file gnunet-communicator-libp2p.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 1994 of file gnunet-communicator-libp2p.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 2042 of file gnunet-communicator-libp2p.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 2060 of file gnunet-communicator-libp2p.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 2081 of file gnunet-communicator-libp2p.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 2153 of file gnunet-communicator-libp2p.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 2200 of file gnunet-communicator-libp2p.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 2306 of file gnunet-communicator-libp2p.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 2426 of file gnunet-communicator-libp2p.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().
|
static |
Definition at line 2520 of file gnunet-communicator-libp2p.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 2564 of file gnunet-communicator-libp2p.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 2771 of file gnunet-communicator-libp2p.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 2803 of file gnunet-communicator-libp2p.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 2822 of file gnunet-communicator-libp2p.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_PILS_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(), pils, 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 2900 of file gnunet-communicator-libp2p.c.
References GNUNET_break_op, and msg.
Referenced by init_socket().
|
static |
This method adds addresses to the DLL, that are later register at the NAT service.
Definition at line 2915 of file gnunet-communicator-libp2p.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 |
FIXME: We could alternatively ask PILS for de/encaps, but at a high cost wrt async RPC calls...
Get the initial secret key for generating the peer id. This is supposed to be generated at random once in the lifetime of a peer, so all generated peer ids use the same initial secret key to optain the same peer id per set of addresses.
First check whether there's already a initial secret key. If so: return it. If no initial secret key exists yet, generate at random and store it where it will be found.
initial | secret key the memory the initial secret key can be written to. |
Definition at line 2955 of file gnunet-communicator-libp2p.c.
References cfg, filename, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_test_read(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_NONE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, ikm, LOG, ret, and size.
Referenced by run().
|
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 3077 of file gnunet-communicator-libp2p.c.
References add_addr(), cfg, ch, COMMUNICATOR_ADDRESS_PREFIX, COMMUNICATOR_CONFIG_SECTION, enc_notify_cb(), GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, 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(), queue_map, resolve_request_handle, and stats.
Referenced by run().
void pid_change_cb | ( | void * | cls, |
const struct GNUNET_HELLO_Parser * | parser, | ||
const struct GNUNET_HashCode * | addr_hash | ||
) |
Definition at line 3211 of file gnunet-communicator-libp2p.c.
References eddsa_priv_to_hpke_key(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_new, GNUNET_PILS_derive_pid(), ikm, LOG, my_identity, my_private_key, my_x25519_private_key, and GNUNET_PeerIdentity::public_key.
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 3241 of file gnunet-communicator-libp2p.c.
References bind_port, cfg, COMMUNICATOR_CONFIG_SECTION, DEFAULT_REKEY_INTERVAL, do_shutdown(), dummy, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_time(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_PILS_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), init_socket(), load_ikm(), peerstore, pid_change_cb(), pils, rekey_interval, 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 3394 of file gnunet-communicator-libp2p.c.
References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GETOPT_OPTION_END, GNUNET_log, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, ret, and run().
|
static |
For PILS.
Definition at line 121 of file gnunet-communicator-libp2p.c.
Referenced by do_shutdown(), and run().
|
static |
For logging statistics.
Definition at line 126 of file gnunet-communicator-libp2p.c.
Referenced by boot_queue(), core_read_finished_cb(), do_shutdown(), init_socket(), pass_plaintext_to_core(), queue_destroy(), and try_handle_plaintext().
|
static |
Our environment.
Definition at line 131 of file gnunet-communicator-libp2p.c.
Referenced by do_shutdown(), init_socket(), pass_plaintext_to_core(), and try_handle_plaintext().
|
static |
Queues (map from peer identity to struct Queue
)
Definition at line 136 of file gnunet-communicator-libp2p.c.
Referenced by boot_queue(), do_shutdown(), init_socket(), mq_init(), and queue_destroy().
|
static |
ListenTasks (map from socket to struct ListenTask
)
Definition at line 141 of file gnunet-communicator-libp2p.c.
Referenced by do_shutdown(), init_socket(), and queue_destroy().
|
static |
Our public key.
Definition at line 146 of file gnunet-communicator-libp2p.c.
Referenced by decrypt_and_check_tc(), do_rekey(), handshake_monotime_cb(), inject_rekey(), pid_change_cb(), send_challenge(), setup_in_cipher(), setup_in_cipher_elligator(), transmit_kx(), and try_handle_plaintext().
|
static |
Our private key.
Definition at line 151 of file gnunet-communicator-libp2p.c.
Referenced by do_shutdown(), inject_rekey(), pid_change_cb(), send_challenge(), setup_in_cipher(), and transmit_kx().
|
static |
Our private key.
Definition at line 156 of file gnunet-communicator-libp2p.c.
Referenced by pid_change_cb(), and setup_in_cipher_elligator().
|
static |
Our configuration.
Definition at line 161 of file gnunet-communicator-libp2p.c.
Referenced by init_socket(), inject_rekey(), load_ikm(), run(), send_challenge(), and transmit_kx().
|
static |
Head of DLL with addresses we like to register at NAT service.
Definition at line 166 of file gnunet-communicator-libp2p.c.
Referenced by add_addr().
|
static |
Head of DLL with addresses we like to register at NAT service.
Definition at line 171 of file gnunet-communicator-libp2p.c.
Referenced by add_addr().
|
static |
Database for peer's HELLOs.
Definition at line 176 of file gnunet-communicator-libp2p.c.
Referenced by decrypt_and_check_tc(), do_rekey(), do_shutdown(), handshake_ack_monotime_cb(), handshake_monotime_cb(), rekey_monotime_cb(), run(), and try_handle_plaintext().
|
static |
A flag indicating we are already doing a shutdown.
Definition at line 181 of file gnunet-communicator-libp2p.c.
Referenced by do_shutdown(), and queue_destroy().