GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
gnunet-communicator-tcp.c File Reference

Transport plugin using TCP. More...

Include dependency graph for gnunet-communicator-tcp.c:

Go to the source code of this file.

Data Structures

struct  TcpHandshakeSignature
 Signature we use to verify that the ephemeral key was really chosen by the specified sender. More...
 
struct  TcpHandshakeAckSignature
 Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the specified sender. More...
 
struct  TCPConfirmation
 Encrypted continuation of TCP initial handshake. More...
 
struct  TCPConfirmationAck
 Ack for the encrypted continuation of TCP initial handshake. More...
 
struct  TCPBox
 TCP message box. More...
 
struct  TCPRekey
 TCP rekey message box. More...
 
struct  TcpRekeySignature
 Signature we use to verify that the ephemeral key was really chosen by the specified sender. More...
 
struct  TCPFinish
 TCP finish. More...
 
struct  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 LOG(kind, ...)   GNUNET_log_from (kind, "communicator-tcp", __VA_ARGS__)
 
#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.
 
#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).
 
#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).
 
#define BUF_SIZE   (2 * 64 * 1024 + sizeof(struct TCPBox))
 Size of our IO buffers for ciphertext data.
 
#define DEFAULT_REKEY_INTERVAL   GNUNET_TIME_UNIT_DAYS
 How often do we rekey based on time (at least)
 
#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 How long do we wait until we must have received the initial KX?
 
#define REKEY_MAX_BYTES   (1024LLU * 1024 * 400)
 How often do we rekey based on number of bytes transmitted? (additionally randomized).
 
#define INITIAL_KX_SIZE
 Size of the initial key exchange message sent first in both directions.
 
#define INITIAL_CORE_KX_SIZE
 Size of the initial core key exchange messages.
 
#define COMMUNICATOR_ADDRESS_PREFIX   "tcp"
 Address prefix used by the communicator.
 
#define COMMUNICATOR_CONFIG_SECTION   "communicator-tcp"
 Configuration section used by the communicator.
 

Functions

static void listen_cb (void *cls)
 We have been notified that our listen socket has something to read.
 
static void eddsa_priv_to_hpke_key (const struct GNUNET_CRYPTO_EddsaPrivateKey *edpk, struct GNUNET_CRYPTO_HpkePrivateKey *pk)
 
static void eddsa_pub_to_hpke_key (const struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_HpkePublicKey *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.
 
static void calculate_hmac (struct GNUNET_CRYPTO_AuthKey *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
 Compute mac over buf, and ratched the hmac_secret.
 
static void queue_finish (struct Queue *queue)
 Append a 'finish' message to the outgoing transmission.
 
static void queue_read (void *cls)
 Queue read task.
 
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.
 
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.
 
static void setup_cipher (const struct GNUNET_ShortHashCode *prk, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_CRYPTO_AuthKey *hmac_key)
 Setup cipher based on shared secret dh and decrypting peer pid.
 
static void rekey_monotime_store_cb (void *cls, int success)
 Callback called when peerstore store operation for rekey monotime value is finished.
 
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.
 
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.
 
static void setup_in_cipher (const struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral, struct Queue *queue)
 Setup cipher of queue for decryption.
 
static void do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
 Handle rekey message on queue.
 
static void handshake_ack_monotime_store_cb (void *cls, int success)
 Callback called when peerstore store operation for handshake ack monotime value is finished.
 
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.
 
static void send_challenge (struct GNUNET_CRYPTO_ChallengeNonceP challenge, struct Queue *queue)
 Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
 
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.
 
static void inject_rekey (struct Queue *queue)
 Inject a struct TCPRekey message into the queue's plaintext buffer.
 
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.
 
static void proto_queue_write (void *cls)
 We have been notified that our socket is ready to write.
 
static void queue_write (void *cls)
 We have been notified that our socket is ready to write.
 
static size_t try_handle_plaintext (struct Queue *queue)
 Test if we have received a full message in plaintext.
 
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
 Convert a struct sockaddr_in6 to astruct sockaddr *`.
 
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
 Convert a struct sockaddr_in4 to astruct sockaddr *`.
 
static struct PortOnlyIpv4Ipv6tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
 Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
 
static char * extract_address (const char *bindto)
 This Method extracts the address part of the BINDTO string.
 
static unsigned int extract_port (const char *addr_and_port)
 This Method extracts the port part of the BINDTO string.
 
static struct sockaddr * tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
 Convert TCP bind specification to a struct sockaddr *
 
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.
 
static void mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Signature of functions implementing the destruction of a message queue.
 
static void mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Implementation function that cancels the currently sent message.
 
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.
 
static void boot_queue (struct Queue *queue)
 Add the given queue to our internal data structure.
 
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.
 
static void start_initial_kx_out (struct Queue *queue)
 Initialize our key material for outgoing transmissions and inform the other peer about it.
 
static void handshake_monotime_store_cb (void *cls, int success)
 Callback called when peerstore store operation for handshake monotime is finished.
 
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.
 
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.
 
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.
 
static void proto_read_kx (void *cls)
 Read from the socket of the proto queue until we have enough data to upgrade to full queue.
 
static struct ProtoQueuecreate_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.
 
static int get_lt_delete_it (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over all ListenTasks to clean up.
 
static int get_queue_delete_it (void *cls, const struct GNUNET_HashCode *target, void *value)
 Iterator over all message queues to clean up.
 
static void do_shutdown (void *cls)
 Shutdown the UNIX communicator.
 
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.
 
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.
 
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.
 
static int init_socket (struct sockaddr *addr, socklen_t in_len)
 This method launch network interactions for each address we like to bind to.
 
static void nat_register ()
 This method reads from the DLL addrs_head to register them at the NAT service.
 
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.
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Setup communicator and launch network interactions.
 
int main (int argc, char *const *argv)
 The main function for the UNIX communicator.
 

Variables

static unsigned long long max_queue_length
 Maximum queue length before we stop reading towards the transport service.
 
static struct GNUNET_PILS_KeyRingkey_ring
 For PILS.
 
static struct GNUNET_PILS_Handlepils
 For PILS.
 
static struct GNUNET_STATISTICS_Handlestats
 For logging statistics.
 
static struct GNUNET_TRANSPORT_CommunicatorHandlech
 Our environment.
 
static struct GNUNET_CONTAINER_MultiHashMapqueue_map
 Queues (map from peer identity to struct Queue)
 
static struct GNUNET_CONTAINER_MultiHashMaplt_map
 ListenTasks (map from socket to struct ListenTask)
 
static unsigned long long rekey_max_bytes
 The rekey byte maximum.
 
static struct GNUNET_TIME_Relative rekey_interval
 The rekey interval.
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration.
 
static struct GNUNET_NT_InterfaceScanneris
 Network scanner to determine network types.
 
static struct GNUNET_NAT_Handlenat
 Connection to NAT service.
 
static struct ProtoQueueproto_head
 Protoqueues DLL head.
 
static struct ProtoQueueproto_tail
 Protoqueues DLL tail.
 
struct GNUNET_RESOLVER_RequestHandleresolve_request_handle
 Handle for DNS lookup of bindto address.
 
static struct Addressesaddrs_head
 Head of DLL with addresses we like to register at NAT service.
 
static struct Addressesaddrs_tail
 Head of DLL with addresses we like to register at NAT service.
 
static int addrs_lens
 Number of addresses in the DLL for register at NAT service.
 
static struct GNUNET_PEERSTORE_Handlepeerstore
 Database for peer's HELLOs.
 
static int shutdown_running = GNUNET_NO
 A flag indicating we are already doing a shutdown.
 
static int disable_v6
 IPv6 disabled.
 
static unsigned int bind_port
 The port the communicator should be assigned to.
 
static struct GNUNET_CONTAINER_MultiHashMappending_reversals
 Map of pending reversals.
 

Detailed Description

Transport plugin using TCP.

Author
Christian Grothoff

TODO:

  • support NAT connection reversal method (#5529)
  • support other TCP-specific NAT traversal methods (#5531)

Definition in file gnunet-communicator-tcp.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "communicator-tcp", __VA_ARGS__)

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

◆ NAT_TIMEOUT

How long until we give up on establishing an NAT connection? Must be > 4 RTT.

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

◆ ADDRESS_VALIDITY_PERIOD

#define ADDRESS_VALIDITY_PERIOD    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)

How long do we believe our addresses to remain up (before the other peer should revalidate).

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

126{
131
135 struct GNUNET_PeerIdentity sender;
136
141
145 struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral;
146
151 struct GNUNET_TIME_AbsoluteNBO monotonic_time;
152
156 struct GNUNET_CRYPTO_ChallengeNonceP challenge;
157};
158
164{
169
174
179
185
190};
191
195struct TCPConfirmation
196{
201
206
212
217
218};
219
224{
225
226
231
236
241
247
252
253};
254
258struct TCPBox
259{
267
277
278 /* followed by as may bytes of payload as indicated in @e header,
279 excluding the TCPBox itself! */
280};
281
282
287struct TCPRekey
288{
293
303
308
313
319};
320
326{
331
336
341
346
352};
353
359struct TCPFinish
360{
365
375};
376
382{
387
392};
393
395
399struct PendingReversal
400{
401 /*
402 * Timeout task.
403 */
405
410
414 struct sockaddr *in;
415};
416
420struct ListenTask
421{
426
431};
432
436struct Queue
437{
442
447
452
457
461 gcry_cipher_hd_t in_cipher;
462
466 gcry_cipher_hd_t out_cipher;
467
471 struct GNUNET_HashCode key;
472
477
483
488
493
497 struct sockaddr *address;
498
503 uint64_t rekey_left_bytes;
504
510
514 socklen_t address_len;
515
519 struct GNUNET_MQ_Handle *mq;
520
525
529 unsigned long long bytes_in_queue;
530
534 char cread_buf[BUF_SIZE];
535
539 char cwrite_buf[BUF_SIZE];
540
544 char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
545
549 char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
550
555 size_t cread_off;
556
561 size_t cwrite_off;
562
567 size_t pread_off;
568
573 size_t pwrite_off;
574
579
587 unsigned int backpressure;
588
593
598
603
607 int finishing;
608
615 int destroyed;
616
621 int rekeyed;
622
627
632
637
642
647
652
657
662
667
672
677
681 // TODO remove?
682 size_t unverified_size;
683
688};
689
690
695struct ProtoQueue
696{
700 struct ProtoQueue *next;
701
705 struct ProtoQueue *prev;
706
711
716
721
725 char write_buf[sizeof (struct TCPNATProbeMessage)];
726
730 size_t write_off;
731
736
740 struct sockaddr *address;
741
745 socklen_t address_len;
746
751
756 char ibuf[INITIAL_KX_SIZE];
757
761 size_t ibuf_off;
762};
763
767struct PortOnlyIpv4Ipv6
768{
772 struct sockaddr *addr_ipv4;
773
777 socklen_t addr_len_ipv4;
778
782 struct sockaddr *addr_ipv6;
783
787 socklen_t addr_len_ipv6;
788
789};
790
794struct Addresses
795{
799 struct Addresses *next;
800
804 struct Addresses *prev;
805
809 struct sockaddr *addr;
810
814 socklen_t addr_len;
815
816};
817
818
822static unsigned long long max_queue_length;
823
827static struct GNUNET_PILS_KeyRing *key_ring;
828
832static struct GNUNET_PILS_Handle *pils;
833
837static struct GNUNET_STATISTICS_Handle *stats;
838
843
848
853
857static unsigned long long rekey_max_bytes;
858
863
867static const struct GNUNET_CONFIGURATION_Handle *cfg;
868
872static struct GNUNET_NT_InterfaceScanner *is;
873
877static struct GNUNET_NAT_Handle *nat;
878
882static struct ProtoQueue *proto_head;
883
887static struct ProtoQueue *proto_tail;
888
893
897static struct Addresses *addrs_head;
898
902static struct Addresses *addrs_tail;
903
907static int addrs_lens;
908
913
917static int shutdown_running = GNUNET_NO;
918
922static int disable_v6;
923
927static unsigned int bind_port;
928
933
941static void
942listen_cb (void *cls);
943
944static void
947{
949 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
950 key.eddsa_key = *edpk;
952 pk);
953}
954
955
956static void
959{
961 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
962 key.eddsa_key = *edpk;
964}
965
966
974static void
975queue_destroy (struct Queue *queue)
976{
977 struct ListenTask *lt = NULL;
978 struct GNUNET_HashCode h_sock;
979 int sockfd;
980
981 if (NULL != queue->listen_sock)
982 {
983 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
984 GNUNET_CRYPTO_hash (&sockfd,
985 sizeof(int),
986 &h_sock);
987
989 }
990
992 "Disconnecting queue for peer `%s'\n",
993 GNUNET_i2s (&queue->target));
994 if (NULL != queue->rekey_monotime_sc)
995 {
996 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
997 queue->rekey_monotime_sc = NULL;
998 }
999 if (NULL != queue->handshake_monotime_sc)
1000 {
1001 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
1002 queue->handshake_monotime_sc = NULL;
1003 }
1004 if (NULL != queue->handshake_ack_monotime_sc)
1005 {
1006 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
1007 queue->handshake_ack_monotime_sc = NULL;
1008 }
1009 if (NULL != queue->rekey_monotime_get)
1010 {
1011 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1012 queue->rekey_monotime_get = NULL;
1013 }
1014 if (NULL != queue->handshake_monotime_get)
1015 {
1016 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
1017 queue->handshake_monotime_get = NULL;
1018 }
1019 if (NULL != queue->handshake_ack_monotime_get)
1020 {
1021 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1022 queue->handshake_ack_monotime_get = NULL;
1023 }
1024 if (NULL != queue->qh)
1025 {
1027 queue->qh = NULL;
1028 }
1030 GNUNET_YES ==
1033 "# queues active",
1035 GNUNET_NO);
1036 if (NULL != queue->read_task)
1037 {
1038 GNUNET_SCHEDULER_cancel (queue->read_task);
1039 queue->read_task = NULL;
1040 }
1041 if (NULL != queue->write_task)
1042 {
1043 GNUNET_SCHEDULER_cancel (queue->write_task);
1044 queue->write_task = NULL;
1045 }
1047 {
1049 "closing socket failed\n");
1050 }
1051 gcry_cipher_close (queue->in_cipher);
1052 gcry_cipher_close (queue->out_cipher);
1053 GNUNET_free (queue->address);
1054 if (0 != queue->backpressure)
1055 queue->destroyed = GNUNET_YES;
1056 else
1058
1059 if (NULL == lt)
1060 return;
1061
1062 if ((! shutdown_running) && (NULL == lt->listen_task))
1063 {
1065 "add read net listen\n");
1068 lt->listen_sock,
1069 &listen_cb,
1070 lt);
1071 }
1072 else
1073 GNUNET_free (lt);
1074}
1075
1076
1085static void
1086calculate_hmac (struct GNUNET_CRYPTO_AuthKey *hmac_secret,
1087 const void *buf,
1088 size_t buf_size,
1089 struct GNUNET_ShortHashCode *smac)
1090{
1091 struct GNUNET_HashCode mac;
1092
1093 GNUNET_CRYPTO_hmac (hmac_secret,
1094 buf,
1095 buf_size,
1096 &mac);
1097 /* truncate to `struct GNUNET_ShortHashCode` */
1098 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1099 /* ratchet hmac key */
1100 GNUNET_CRYPTO_hash (hmac_secret,
1101 sizeof(struct GNUNET_HashCode),
1102 (struct GNUNET_HashCode*) hmac_secret);
1103}
1104
1105
1112static void
1113queue_finish (struct Queue *queue)
1114{
1115 struct TCPFinish fin;
1116
1117 memset (&fin, 0, sizeof(fin));
1118 fin.header.size = htons (sizeof(fin));
1119 fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
1120 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1121 /* if there is any message left in pwrite_buf, we
1122 overwrite it (possibly dropping the last message
1123 from CORE hard here) */
1124 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1125 queue->pwrite_off = sizeof(fin);
1126 /* This flag will ensure that #queue_write() no longer
1127 notifies CORE about the possibility of sending
1128 more data, and that #queue_write() will call
1129 #queue_destroy() once the @c fin was fully written. */
1130 queue->finishing = GNUNET_YES;
1131}
1132
1133
1139static void
1140queue_read (void *cls);
1141
1142
1150static void
1151core_read_finished_cb (void *cls, int success)
1152{
1153 struct Queue *queue = cls;
1154 if (GNUNET_OK != success)
1156 "# messages lost in communicator API towards CORE",
1157 1,
1158 GNUNET_NO);
1159 if (NULL == queue)
1160 return;
1161
1163 "backpressure %u\n",
1164 queue->backpressure);
1165
1166 queue->backpressure--;
1167 /* handle deferred queue destruction */
1168 if ((queue->destroyed) && (0 == queue->backpressure))
1169 {
1171 return;
1172 }
1173 else if (GNUNET_YES != queue->destroyed)
1174 {
1175 queue->timeout =
1177 );
1178 /* possibly unchoke reading, now that CORE made progress */
1179 if (NULL == queue->read_task)
1180 queue->read_task =
1182 queue->timeout),
1183 queue->sock,
1184 &queue_read,
1185 queue);
1186 }
1187}
1188
1189
1199static void
1201 const void *plaintext,
1202 size_t plaintext_len)
1203{
1204 const struct GNUNET_MessageHeader *hdr = plaintext;
1205 int ret;
1206
1208 "pass message from %s to core\n",
1209 GNUNET_i2s (&queue->target));
1210
1211 if (ntohs (hdr->size) != plaintext_len)
1212 {
1213 /* NOTE: If we ever allow multiple CORE messages in one
1214 BOX, this will have to change! */
1215 GNUNET_break (0);
1216 return;
1217 }
1219 &queue->target,
1220 hdr,
1223 queue);
1225 "passed to core\n");
1226 if (GNUNET_OK == ret)
1227 queue->backpressure++;
1228 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1229 if (GNUNET_SYSERR == ret)
1231 "# bytes lost due to CORE not running",
1232 plaintext_len,
1233 GNUNET_NO);
1234}
1235
1236
1246static void
1247setup_cipher (const struct GNUNET_ShortHashCode *prk,
1248 const struct GNUNET_PeerIdentity *pid,
1249 gcry_cipher_hd_t *cipher,
1250 struct GNUNET_CRYPTO_AuthKey *hmac_key)
1251{
1252 char key[256 / 8];
1253 char ctr[128 / 8];
1254
1255 GNUNET_assert (0 == gcry_cipher_open (cipher,
1256 GCRY_CIPHER_AES256 /* low level: go for speed */
1257 ,
1258 GCRY_CIPHER_MODE_CTR,
1259 0 /* flags */));
1262 key,
1263 sizeof(key),
1264 prk,
1265 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-key"))
1266 );
1267 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1270 ctr,
1271 sizeof(ctr),
1272 prk,
1273 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-ctr"))
1274 );
1275 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1278 hmac_key,
1279 sizeof(struct GNUNET_HashCode),
1280 prk,
1281 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-hmac")));
1282}
1283
1284
1290static void
1291rekey_monotime_store_cb (void *cls, int success)
1292{
1293 struct Queue *queue = cls;
1294 if (GNUNET_OK != success)
1295 {
1297 "Failed to store rekey monotonic time in PEERSTORE!\n");
1298 }
1299 queue->rekey_monotime_sc = NULL;
1300 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1301}
1302
1303
1311static void
1312rekey_monotime_cb (void *cls,
1313 const struct GNUNET_PEERSTORE_Record *record,
1314 const char *emsg)
1315{
1316 struct Queue *queue = cls;
1317 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1318 struct GNUNET_TIME_Absolute mt;
1319 const struct GNUNET_PeerIdentity *pid;
1320 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1321
1322 (void) emsg;
1323
1324 rekey_monotonic_time = &queue->rekey_monotonic_time;
1325 pid = &queue->target;
1326 if (NULL == record)
1327 {
1328 queue->rekey_monotime_get = NULL;
1329 return;
1330 }
1331 if (sizeof(*mtbe) != record->value_size)
1332 {
1333 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1334 GNUNET_break (0);
1335 return;
1336 }
1337 mtbe = record->value;
1338 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1339 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1340 queue->rekey_monotonic_time).abs_value_us)
1341 {
1343 "Queue from %s dropped, rekey monotime in the past\n",
1344 GNUNET_i2s (&queue->target));
1345 GNUNET_break (0);
1346 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1347 queue->rekey_monotime_get = NULL;
1348 // FIXME: Why should we try to gracefully finish here??
1350 return;
1351 }
1352 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1353 "transport_tcp_communicator",
1354 pid,
1356 rekey_monotonic_time,
1357 sizeof(*
1358 rekey_monotonic_time),
1362 queue);
1363}
1364
1365
1372static void
1374 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
1375 struct Queue *queue)
1376{
1377 const struct GNUNET_PeerIdentity *my_identity;
1379 struct GNUNET_CRYPTO_HpkePrivateKey my_hpke_key;
1380 struct GNUNET_ShortHashCode k;
1381
1385
1386 eddsa_priv_to_hpke_key (my_private_key, &my_hpke_key);
1387
1389 c,
1390 &k);
1391 setup_cipher (&k, my_identity, &queue->in_cipher, &queue->in_hmac);
1392}
1393
1394
1401static void
1402setup_in_cipher (const struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral,
1403 struct Queue *queue)
1404{
1405 const struct GNUNET_PeerIdentity *my_identity;
1407 struct GNUNET_ShortHashCode k;
1408
1412
1414 setup_cipher (&k, my_identity, &queue->in_cipher, &queue->in_hmac);
1415}
1416
1417
1426static void
1427do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1428{
1429 const struct GNUNET_PeerIdentity *my_identity;
1430 struct TcpRekeySignature thp;
1431
1434
1435 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY);
1436 thp.purpose.size = htonl (sizeof(thp));
1438 "do_rekey size %u\n",
1439 thp.purpose.size);
1440 thp.sender = queue->target;
1442 "sender %s\n",
1443 GNUNET_p2s (&thp.sender.public_key));
1445 "sender %s\n",
1446 GNUNET_p2s (&queue->target.public_key));
1447 thp.receiver = *my_identity;
1449 "receiver %s\n",
1450 GNUNET_p2s (&thp.receiver.public_key));
1451 thp.ephemeral = rekey->ephemeral;
1453 "ephemeral %s\n",
1454 GNUNET_e2s ((struct GNUNET_CRYPTO_EcdhePublicKey*) &thp.ephemeral)
1455 );
1456 thp.monotonic_time = rekey->monotonic_time;
1458 "time %s\n",
1460 GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1461 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1462 if (GNUNET_OK !=
1465 &thp,
1466 &rekey->sender_sig,
1467 &queue->target.public_key))
1468 {
1469 GNUNET_break (0);
1470 // FIXME Why should we try to gracefully finish here?
1472 return;
1473 }
1474 queue->rekey_monotonic_time = rekey->monotonic_time;
1475 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1476 "transport_tcp_communicator",
1477 &queue->target,
1479 &
1481 queue);
1482 gcry_cipher_close (queue->in_cipher);
1483 queue->rekeyed = GNUNET_YES;
1484 setup_in_cipher (&rekey->ephemeral, queue);
1485}
1486
1487
1493static void
1494handshake_ack_monotime_store_cb (void *cls, int success)
1495{
1496 struct Queue *queue = cls;
1497
1498 if (GNUNET_OK != success)
1499 {
1501 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1502 }
1503 queue->handshake_ack_monotime_sc = NULL;
1504 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1505}
1506
1507
1515static void
1516handshake_ack_monotime_cb (void *cls,
1517 const struct GNUNET_PEERSTORE_Record *record,
1518 const char *emsg)
1519{
1520 struct Queue *queue = cls;
1521 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1522 struct GNUNET_TIME_Absolute mt;
1523 const struct GNUNET_PeerIdentity *pid;
1524 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1525
1526 (void) emsg;
1527
1528 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1529 pid = &queue->target;
1530 if (NULL == record)
1531 {
1532 queue->handshake_ack_monotime_get = NULL;
1533 return;
1534 }
1535 if (sizeof(*mtbe) != record->value_size)
1536 {
1537 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1538 GNUNET_break (0);
1539 return;
1540 }
1541 mtbe = record->value;
1542 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1543 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1544 queue->handshake_ack_monotonic_time).abs_value_us)
1545 {
1547 "Queue from %s dropped, handshake ack monotime in the past\n",
1548 GNUNET_i2s (&queue->target));
1549 GNUNET_break (0);
1550 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1551 queue->handshake_ack_monotime_get = NULL;
1552 // FIXME: Why should we try to gracefully finish here?
1554 return;
1555 }
1556 queue->handshake_ack_monotime_sc =
1558 "transport_tcp_communicator",
1559 pid,
1561 handshake_ack_monotonic_time,
1562 sizeof(*handshake_ack_monotonic_time),
1566 queue);
1567}
1568
1569
1576static void
1578 struct Queue *queue)
1579{
1580 const struct GNUNET_PeerIdentity *my_identity;
1582 struct TCPConfirmationAck tca;
1583 struct TcpHandshakeAckSignature thas;
1584
1588
1590 "sending challenge\n");
1591
1592 tca.header.type = ntohs (
1594 tca.header.size = ntohs (sizeof(tca));
1595 tca.challenge = challenge;
1596 tca.sender = *my_identity;
1597 tca.monotonic_time =
1599 thas.purpose.purpose = htonl (
1601 thas.purpose.size = htonl (sizeof(thas));
1602 thas.sender = *my_identity;
1603 thas.receiver = queue->target;
1604 thas.monotonic_time = tca.monotonic_time;
1605 thas.challenge = tca.challenge;
1607 &thas,
1608 &tca.sender_sig);
1609 GNUNET_assert (0 ==
1610 gcry_cipher_encrypt (queue->out_cipher,
1611 &queue->cwrite_buf[queue->cwrite_off],
1612 sizeof(tca),
1613 &tca,
1614 sizeof(tca)));
1615 queue->cwrite_off += sizeof(tca);
1617 "sending challenge done\n");
1618}
1619
1620
1627static void
1629{
1630 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1632 queue->rekey_left_bytes =
1634}
1635
1636
1643static void
1644inject_rekey (struct Queue *queue)
1645{
1646 const struct GNUNET_PeerIdentity *my_identity;
1648 struct TCPRekey rekey;
1649 struct TcpRekeySignature thp;
1650 struct GNUNET_ShortHashCode k;
1651
1655
1656 GNUNET_assert (0 == queue->pwrite_off);
1657 memset (&rekey, 0, sizeof(rekey));
1658 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1659 &k);
1661 rekey.header.size = ntohs (sizeof(rekey));
1662 rekey.monotonic_time =
1664 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY);
1665 thp.purpose.size = htonl (sizeof(thp));
1667 "inject_rekey size %u\n",
1668 thp.purpose.size);
1669 thp.sender = *my_identity;
1671 "sender %s\n",
1672 GNUNET_p2s (&thp.sender.public_key));
1673 thp.receiver = queue->target;
1675 "receiver %s\n",
1676 GNUNET_p2s (&thp.receiver.public_key));
1677 thp.ephemeral = rekey.ephemeral;
1679 "ephemeral %s\n",
1680 GNUNET_e2s ((struct GNUNET_CRYPTO_EcdhePublicKey*) &thp.ephemeral)
1681 );
1682 thp.monotonic_time = rekey.monotonic_time;
1684 "time %s\n",
1686 GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1688 &thp,
1689 &rekey.sender_sig);
1690 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1691 /* Encrypt rekey message with 'old' cipher */
1692 GNUNET_assert (0 ==
1693 gcry_cipher_encrypt (queue->out_cipher,
1694 &queue->cwrite_buf[queue->cwrite_off],
1695 sizeof(rekey),
1696 &rekey,
1697 sizeof(rekey)));
1698 queue->cwrite_off += sizeof(rekey);
1699 /* Setup new cipher for successive messages */
1700 gcry_cipher_close (queue->out_cipher);
1701 setup_out_cipher (queue, &k);
1702}
1703
1704
1705static int
1707 const struct GNUNET_HashCode *key,
1708 void *value)
1709{
1710 struct PendingReversal *pending_reversal = value;
1711 (void) cls;
1712
1713 if (NULL != pending_reversal->timeout_task)
1714 {
1715 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1716 pending_reversal->timeout_task = NULL;
1717 }
1720 key,
1721 pending_reversal));
1722 GNUNET_free (pending_reversal->in);
1723 GNUNET_free (pending_reversal);
1724 return GNUNET_OK;
1725}
1726
1727
1728static void
1729check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1730 struct GNUNET_PeerIdentity *sender)
1731{
1732 if (AF_INET == sa_family)
1733 {
1734 struct PendingReversal *pending_reversal;
1735 struct GNUNET_HashCode key;
1736 struct sockaddr_in *natted_address;
1737
1738 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1739 natted_address->sin_port = 0;
1740 GNUNET_CRYPTO_hash (natted_address,
1741 sizeof(struct sockaddr),
1742 &key);
1743
1745 &key);
1746 if (NULL != pending_reversal && (NULL == sender ||
1747 0 != memcmp (sender,
1748 &pending_reversal->target,
1749 sizeof(struct
1751 {
1753 "Removing invalid pending reversal for `%s'at `%s'\n",
1754 GNUNET_i2s (&pending_reversal->target),
1755 GNUNET_a2s (in, sizeof (struct sockaddr)));
1756 pending_reversals_delete_it (NULL, &key, pending_reversal);
1757 }
1758 GNUNET_free (natted_address);
1759 }
1760}
1761
1762
1768static void
1769free_proto_queue (struct ProtoQueue *pq)
1770{
1771 if (NULL != pq->listen_sock)
1772 {
1774 pq->listen_sock = NULL;
1775 }
1776 if (NULL != pq->read_task)
1777 {
1779 pq->read_task = NULL;
1780 }
1781 if (NULL != pq->write_task)
1782 {
1784 pq->write_task = NULL;
1785 }
1786 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1788 GNUNET_free (pq->address);
1790 GNUNET_free (pq);
1791}
1792
1793
1800static void
1801proto_queue_write (void *cls)
1802{
1803 struct ProtoQueue *pq = cls;
1804 ssize_t sent;
1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1806 pq->write_task = NULL;
1807 if (0 != pq->write_off)
1808 {
1809 sent = GNUNET_NETWORK_socket_send (pq->sock,
1810 pq->write_buf,
1811 pq->write_off);
1813 "Sent %lu bytes to TCP queue\n", sent);
1814 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1815 {
1817 free_proto_queue (pq);
1818 return;
1819 }
1820 if (sent > 0)
1821 {
1822 size_t usent = (size_t) sent;
1823 pq->write_off -= usent;
1824 memmove (pq->write_buf,
1825 &pq->write_buf[usent],
1826 pq->write_off);
1827 }
1828 }
1829 /* do we care to write more? */
1830 if ((0 < pq->write_off))
1831 pq->write_task =
1833 pq->sock,
1835 pq);
1836}
1837
1838
1845static void
1846queue_write (void *cls)
1847{
1848 struct Queue *queue = cls;
1849 ssize_t sent;
1850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1851 queue->write_task = NULL;
1852 if (0 != queue->cwrite_off)
1853 {
1854 sent = GNUNET_NETWORK_socket_send (queue->sock,
1855 queue->cwrite_buf,
1856 queue->cwrite_off);
1858 "Sent %lu bytes to TCP queue\n", sent);
1859 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1860 {
1863 return;
1864 }
1865 if (sent > 0)
1866 {
1867 size_t usent = (size_t) sent;
1868 queue->cwrite_off -= usent;
1869 memmove (queue->cwrite_buf,
1870 &queue->cwrite_buf[usent],
1871 queue->cwrite_off);
1872 queue->timeout =
1875 }
1876 }
1877 {
1878 /* can we encrypt more? (always encrypt full messages, needed
1879 such that #mq_cancel() can work!) */
1880 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1881 - (queue->cwrite_off
1882 + queue->pwrite_off
1883 + sizeof (struct TCPRekey)));
1884 if (we_do_not_need_to_rekey &&
1885 (queue->pwrite_off > 0) &&
1886 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1887 {
1889 "Encrypting %lu bytes\n", queue->pwrite_off);
1890 GNUNET_assert (0 ==
1891 gcry_cipher_encrypt (queue->out_cipher,
1892 &queue->cwrite_buf[queue->cwrite_off],
1893 queue->pwrite_off,
1894 queue->pwrite_buf,
1895 queue->pwrite_off));
1896 if (queue->rekey_left_bytes > queue->pwrite_off)
1897 queue->rekey_left_bytes -= queue->pwrite_off;
1898 else
1899 queue->rekey_left_bytes = 0;
1900 queue->cwrite_off += queue->pwrite_off;
1901 queue->pwrite_off = 0;
1902 }
1903 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1904 if (((0 == queue->rekey_left_bytes) ||
1906 queue->rekey_time).rel_value_us)) &&
1907 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1908 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1909 {
1911 }
1912 }
1913 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1914 (GNUNET_YES == queue->mq_awaits_continue))
1915 {
1916 queue->mq_awaits_continue = GNUNET_NO;
1918 }
1919 /* did we just finish writing 'finish'? */
1920 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1921 {
1923 "Finishing queue\n");
1925 return;
1926 }
1927 /* do we care to write more? */
1928 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1929 queue->write_task =
1931 queue->sock,
1932 &queue_write,
1933 queue);
1934}
1935
1936
1944static size_t
1946{
1947 const struct GNUNET_MessageHeader *hdr;
1948 const struct TCPConfirmationAck *tca;
1949 const struct TCPBox *box;
1950 const struct TCPRekey *rekey;
1951 const struct TCPFinish *fin;
1952 struct TCPRekey rekeyz;
1953 struct TCPFinish finz;
1954 struct GNUNET_ShortHashCode tmac;
1955 uint16_t type;
1956 size_t size = 0;
1957 struct TcpHandshakeAckSignature thas;
1958 const struct GNUNET_PeerIdentity *my_identity;
1959 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1960
1962 "try handle plaintext!\n");
1963
1964 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1965 if ((sizeof(*hdr) > queue->pread_off))
1966 {
1968 "Handling plaintext, not even a header!\n");
1969 return 0; /* not even a header */
1970 }
1971
1972 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1974 {
1976 "Already received data of size %lu bigger than KX size %lu!\n",
1977 queue->unverified_size,
1979 GNUNET_break_op (0);
1981 return 0;
1982 }
1983
1984 type = ntohs (hdr->type);
1985 switch (type)
1986 {
1988 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1990 "start processing ack\n");
1991 if (sizeof(*tca) > queue->pread_off)
1992 {
1994 "Handling plaintext size of tca greater than pread offset.\n")
1995 ;
1996 return 0;
1997 }
1998 if (ntohs (hdr->size) != sizeof(*tca))
1999 {
2001 "Handling plaintext size does not match message type.\n");
2002 GNUNET_break_op (0);
2004 return 0;
2005 }
2006
2009
2010 thas.purpose.purpose = htonl (
2012 thas.purpose.size = htonl (sizeof(thas));
2013 thas.sender = tca->sender;
2014 thas.receiver = *my_identity;
2015 thas.monotonic_time = tca->monotonic_time;
2016 thas.challenge = tca->challenge;
2017
2020 &thas,
2021 &tca->sender_sig,
2022 &tca->sender.public_key))
2023 {
2025 "Verification of signature failed!\n");
2026 GNUNET_break (0);
2028 return 0;
2029 }
2030 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
2031 {
2033 "Challenge in TCPConfirmationAck not correct!\n");
2034 GNUNET_break (0);
2036 return 0;
2037 }
2038
2039 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
2040 peerstore,
2041 "transport_tcp_communicator",
2042 &queue->target,
2045 queue);
2046
2048 "Handling plaintext, ack processed!\n");
2049
2051 {
2052 send_challenge (queue->challenge_received, queue);
2053 queue->write_task =
2055 queue->sock,
2056 &queue_write,
2057 queue);
2058 }
2059 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2060 {
2062 queue->address->sa_family, NULL);
2063 }
2064
2069 queue->initial_core_kx_done = GNUNET_YES;
2070
2071 {
2072 char *foreign_addr;
2073
2074 switch (queue->address->sa_family)
2075 {
2076 case AF_INET:
2077 GNUNET_asprintf (&foreign_addr,
2078 "%s-%s",
2080 GNUNET_a2s (queue->address, queue->address_len));
2081 break;
2082
2083 case AF_INET6:
2084 GNUNET_asprintf (&foreign_addr,
2085 "%s-%s",
2087 GNUNET_a2s (queue->address, queue->address_len));
2088 break;
2089
2090 default:
2091 GNUNET_assert (0);
2092 }
2094 &queue->target,
2095 foreign_addr,
2096 UINT16_MAX, /* no MTU */
2098 0, /* Priority */
2099 queue->nt,
2100 queue->cs,
2101 queue->mq);
2102
2103 GNUNET_free (foreign_addr);
2104 }
2105
2106 size = ntohs (hdr->size);
2107 break;
2109 /* Special case: header size excludes box itself! */
2110 box = (const struct TCPBox *) queue->pread_buf;
2111 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2112 return 0;
2113 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2114 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2115 {
2116 GNUNET_break_op (0);
2118 return 0;
2119 }
2120 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2121 size = ntohs (hdr->size) + sizeof(*box);
2123 "Handling plaintext, box processed!\n");
2125 "# bytes decrypted with BOX",
2126 size,
2127 GNUNET_NO);
2129 "# messages decrypted with BOX",
2130 1,
2131 GNUNET_NO);
2132 break;
2133
2135 rekey = (const struct TCPRekey *) queue->pread_buf;
2136 if (sizeof(*rekey) > queue->pread_off)
2137 return 0;
2138 if (ntohs (hdr->size) != sizeof(*rekey))
2139 {
2140 GNUNET_break_op (0);
2142 return 0;
2143 }
2144 rekeyz = *rekey;
2145 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2146 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2147 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2148 {
2149 GNUNET_break_op (0);
2151 return 0;
2152 }
2153 do_rekey (queue, rekey);
2154 size = ntohs (hdr->size);
2156 "Handling plaintext, rekey processed!\n");
2158 "# rekeying successful",
2159 1,
2160 GNUNET_NO);
2161 break;
2162
2164 fin = (const struct TCPFinish *) queue->pread_buf;
2165 if (sizeof(*fin) > queue->pread_off)
2166 return 0;
2167 if (ntohs (hdr->size) != sizeof(*fin))
2168 {
2169 GNUNET_break_op (0);
2171 return 0;
2172 }
2173 finz = *fin;
2174 memset (&finz.hmac, 0, sizeof(finz.hmac));
2175 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2176 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2177 {
2178 GNUNET_break_op (0);
2180 return 0;
2181 }
2182 /* handle FINISH by destroying queue */
2185 "Handling plaintext, finish processed!\n");
2186 break;
2187
2188 default:
2190 "Handling plaintext, nothing processed!\n");
2191 GNUNET_break_op (0);
2193 return 0;
2194 }
2195 GNUNET_assert (0 != size);
2196 if (-1 != queue->unverified_size)
2197 queue->unverified_size += size;
2198 return size;
2199}
2200
2201
2207static void
2208queue_read (void *cls)
2209{
2210 struct Queue *queue = cls;
2211 struct GNUNET_TIME_Relative left;
2212 ssize_t rcvd;
2213
2214 queue->read_task = NULL;
2215 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2216 &queue->cread_buf[queue->cread_off],
2217 BUF_SIZE - queue->cread_off);
2219 "Received %zd bytes from TCP queue\n", rcvd);
2220 if (-1 == rcvd)
2221 {
2222 if ((EAGAIN != errno) && (EINTR != errno))
2223 {
2226 return;
2227 }
2228 /* try again */
2229 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2230 if (0 != left.rel_value_us)
2231 {
2232 queue->read_task =
2234 return;
2235 }
2237 "Queue %p was idle for %s, disconnecting\n",
2238 queue,
2241 GNUNET_YES));
2243 return;
2244 }
2245 if (0 == rcvd)
2246 {
2247 /* Orderly shutdown of connection */
2249 "Socket for queue %p seems to have been closed\n", queue);
2251 return;
2252 }
2253 queue->timeout =
2255 queue->cread_off += rcvd;
2256 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2257 (queue->cread_off > 0))
2258 {
2259 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2260 queue->cread_off);
2261 size_t done;
2262 size_t total;
2263 size_t old_pread_off = queue->pread_off;
2264
2265 GNUNET_assert (0 ==
2266 gcry_cipher_decrypt (queue->in_cipher,
2267 &queue->pread_buf[queue->pread_off],
2268 max,
2269 queue->cread_buf,
2270 max));
2271 queue->pread_off += max;
2272 total = 0;
2273 while (0 != (done = try_handle_plaintext (queue)))
2274 {
2275 /* 'done' bytes of plaintext were used, shift buffer */
2276 GNUNET_assert (done <= queue->pread_off);
2277 /* NOTE: this memmove() could possibly sometimes be
2278 avoided if we pass 'total' into try_handle_plaintext()
2279 and use it at an offset into the buffer there! */
2280 memmove (queue->pread_buf,
2281 &queue->pread_buf[done],
2282 queue->pread_off - done);
2283 queue->pread_off -= done;
2284 total += done;
2285 /* The last plaintext was a rekey, abort for now */
2286 if (GNUNET_YES == queue->rekeyed)
2287 break;
2288 }
2289 /* when we encounter a rekey message, the decryption above uses the
2290 wrong key for everything after the rekey; in that case, we have
2291 to re-do the decryption at 'total' instead of at 'max'.
2292 However, we have to take into account that the plaintext buffer may have
2293 already contained data and not jumped too far ahead in the ciphertext.
2294 If there is no rekey and the last message is incomplete (max > total),
2295 it is safe to keep the decryption so we shift by 'max' */
2296 if (GNUNET_YES == queue->rekeyed)
2297 {
2298 max = total - old_pread_off;
2299 queue->rekeyed = GNUNET_NO;
2300 queue->pread_off = 0;
2301 }
2302 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2303 queue->cread_off -= max;
2304 }
2305 if (BUF_SIZE == queue->cread_off)
2306 return; /* buffer full, suspend reading */
2307 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2308 if (0 != left.rel_value_us)
2309 {
2310 if (max_queue_length > queue->backpressure)
2311 {
2312 /* continue reading */
2313 queue->read_task =
2315 }
2316 return;
2317 }
2319 "Queue %p was idle for %s, disconnecting\n",
2320 queue,
2323 GNUNET_YES));
2325}
2326
2327
2335static struct sockaddr *
2336tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len,
2337 struct sockaddr_in6 v6,
2338 unsigned int port)
2339{
2340 struct sockaddr *in;
2341
2342 v6.sin6_family = AF_INET6;
2343 v6.sin6_port = htons ((uint16_t) port);
2344#if HAVE_SOCKADDR_IN_SIN_LEN
2345 v6.sin6_len = sizeof(struct sockaddr_in6);
2346#endif
2347 v6.sin6_flowinfo = 0;
2348 v6.sin6_scope_id = 0;
2349 in = GNUNET_memdup (&v6, sizeof(v6));
2350 *sock_len = sizeof(struct sockaddr_in6);
2351
2352 return in;
2353}
2354
2355
2363static struct sockaddr *
2364tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len,
2365 struct sockaddr_in v4,
2366 unsigned int port)
2367{
2368 struct sockaddr *in;
2369
2370 v4.sin_family = AF_INET;
2371 v4.sin_port = htons ((uint16_t) port);
2372#if HAVE_SOCKADDR_IN_SIN_LEN
2373 v4.sin_len = sizeof(struct sockaddr_in);
2374#endif
2375 in = GNUNET_memdup (&v4, sizeof(v4));
2376 *sock_len = sizeof(struct sockaddr_in);
2377 return in;
2378}
2379
2380
2387static struct PortOnlyIpv4Ipv6 *
2388tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2389{
2390 struct PortOnlyIpv4Ipv6 *po;
2391 struct sockaddr_in *i4;
2392 struct sockaddr_in6 *i6;
2393 socklen_t sock_len_ipv4;
2394 socklen_t sock_len_ipv6;
2395
2396 /* interpreting value as just a PORT number */
2397 if (*port > UINT16_MAX)
2398 {
2400 "BINDTO specification `%s' invalid: value too large for port\n",
2401 bindto);
2402 return NULL;
2403 }
2404
2405 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2406
2407 if (GNUNET_YES == disable_v6)
2408 {
2409 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2410 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2411 *port);
2412 po->addr_len_ipv4 = sock_len_ipv4;
2413 }
2414 else
2415 {
2416
2417 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2418 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2419 *port);
2420 po->addr_len_ipv4 = sock_len_ipv4;
2421
2422 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2423 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2424 *port);
2425
2426 po->addr_len_ipv6 = sock_len_ipv6;
2427
2428 GNUNET_free (i6);
2429 }
2430
2431 GNUNET_free (i4);
2432
2433 return po;
2434}
2435
2436
2443static char *
2444extract_address (const char *bindto)
2445{
2446 char *addr;
2447 char *start;
2448 char *token;
2449 char *cp;
2450 char *rest = NULL;
2451
2453 "extract address with bindto %s\n",
2454 bindto);
2455
2456 if (NULL == bindto)
2458 "bindto is NULL\n");
2459
2460 cp = GNUNET_strdup (bindto);
2461
2463 "extract address 2\n");
2464
2465 start = cp;
2466 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2467 {
2468 start++; /* skip over '['*/
2469 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2470 addr = GNUNET_strdup (start);
2471 }
2472 else
2473 {
2474 token = strtok_r (cp, "]", &rest);
2475 if (strlen (bindto) == strlen (token))
2476 {
2477 token = strtok_r (cp, ":", &rest);
2478 addr = GNUNET_strdup (token);
2479 }
2480 else
2481 {
2482 token++;
2483 addr = GNUNET_strdup (token);
2484 }
2485 }
2486
2488 "tcp address: %s\n",
2489 addr);
2490 GNUNET_free (cp);
2491 return addr;
2492}
2493
2494
2501static unsigned int
2502extract_port (const char *addr_and_port)
2503{
2504 unsigned int port;
2505 char dummy[2];
2506 char *token;
2507 char *addr;
2508 char *colon;
2509 char *cp;
2510 char *rest = NULL;
2511
2512 if (NULL != addr_and_port)
2513 {
2514 cp = GNUNET_strdup (addr_and_port);
2515 token = strtok_r (cp, "]", &rest);
2516 if (strlen (addr_and_port) == strlen (token))
2517 {
2518 colon = strrchr (cp, ':');
2519 if (NULL == colon)
2520 {
2521 GNUNET_free (cp);
2522 return 0;
2523 }
2524 addr = colon;
2525 addr++;
2526 }
2527 else
2528 {
2529 token = strtok_r (NULL, "]", &rest);
2530 if (NULL == token)
2531 {
2532 GNUNET_free (cp);
2533 return 0;
2534 }
2535 else
2536 {
2537 addr = token;
2538 addr++;
2539 }
2540 }
2541
2542
2543 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2544 {
2545 /* interpreting value as just a PORT number */
2546 if (port > UINT16_MAX)
2547 {
2549 "Port `%u' invalid: value too large for port\n",
2550 port);
2551 GNUNET_free (cp);
2552 return 0;
2553 }
2554 }
2555 else
2556 {
2558 "BINDTO specification invalid: last ':' not followed by number\n");
2559 GNUNET_free (cp);
2560 return 0;
2561 }
2562 GNUNET_free (cp);
2563 }
2564 else
2565 {
2567 "return 0\n");
2568 /* interpret missing port as 0, aka pick any free one */
2569 port = 0;
2570 }
2571
2572 return port;
2573}
2574
2575
2583static struct sockaddr *
2584tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2585{
2586 struct sockaddr *in;
2587 unsigned int port;
2588 struct sockaddr_in v4;
2589 struct sockaddr_in6 v6;
2590 char *start;
2591
2592 memset (&v4, 0, sizeof(v4));
2593 start = extract_address (bindto);
2594 GNUNET_assert (NULL != start);
2596 "start %s\n",
2597 start);
2598
2600 "!bindto %s\n",
2601 bindto);
2602
2603
2604 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2605 {
2606 port = extract_port (bindto);
2607
2609 "port %u\n",
2610 port);
2611
2612 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2613 }
2614 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2615 {
2616 port = extract_port (bindto);
2617 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2618 }
2619 else
2620 {
2621 GNUNET_assert (0);
2622 }
2623
2625 return in;
2626}
2627
2628
2637static void
2638mq_send (struct GNUNET_MQ_Handle *mq,
2639 const struct GNUNET_MessageHeader *msg,
2640 void *impl_state)
2641{
2642 struct Queue *queue = impl_state;
2643 uint16_t msize = ntohs (msg->size);
2644 struct TCPBox box;
2646 "In MQ send. Queue finishing: %s; write task running: %s\n",
2647 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2648 (NULL == queue->write_task) ? "yes" : "no");
2649 GNUNET_assert (mq == queue->mq);
2650 queue->mq_awaits_continue = GNUNET_YES;
2651 if (GNUNET_YES == queue->finishing)
2652 return; /* this queue is dying, drop msg */
2653 GNUNET_assert (0 == queue->pwrite_off);
2654 box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
2655 box.header.size = htons (msize);
2656 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2657 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2658 queue->pwrite_off += sizeof(box);
2659 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2660 queue->pwrite_off += msize;
2662 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2663 GNUNET_assert (NULL != queue->sock);
2664 if (NULL == queue->write_task)
2665 queue->write_task =
2667 queue->sock,
2668 &queue_write,
2669 queue);
2670}
2671
2672
2681static void
2682mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2683{
2684 struct Queue *queue = impl_state;
2685
2686 if (mq == queue->mq)
2687 {
2688 queue->mq = NULL;
2690 }
2691}
2692
2693
2700static void
2701mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2702{
2703 struct Queue *queue = impl_state;
2704
2705 GNUNET_assert (0 != queue->pwrite_off);
2706 queue->pwrite_off = 0;
2707}
2708
2709
2719static void
2720mq_error (void *cls, enum GNUNET_MQ_Error error)
2721{
2722 struct Queue *queue = cls;
2723
2725 "MQ error in queue to %s: %d\n",
2726 GNUNET_i2s (&queue->target),
2727 (int) error);
2729}
2730
2731
2739static void
2740boot_queue (struct Queue *queue)
2741{
2742 queue->nt =
2743 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2745 queue_map,
2746 &queue->key,
2747 queue,
2750 "# queues active",
2752 GNUNET_NO);
2753 queue->timeout =
2756 &mq_destroy,
2757 &mq_cancel,
2758 queue,
2759 NULL,
2760 &mq_error,
2761 queue);
2762}
2763
2764
2775static void
2776transmit_kx (struct Queue *queue,
2777 const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
2778{
2779 const struct GNUNET_PeerIdentity *my_identity;
2781 struct TcpHandshakeSignature ths;
2782 struct TCPConfirmation tc;
2783
2787
2788 memcpy (queue->cwrite_buf, c, sizeof(*c));
2789 queue->cwrite_off = sizeof(*c);
2790 /* compute 'tc' and append in encrypted format to cwrite_buf */
2791 tc.sender = *my_identity;
2792 tc.monotonic_time =
2794 GNUNET_CRYPTO_random_block (&tc.challenge,
2795 sizeof(tc.challenge));
2796 ths.purpose.purpose = htonl (
2798 ths.purpose.size = htonl (sizeof(ths));
2799 ths.sender = *my_identity;
2800 ths.receiver = queue->target;
2801 ths.ephemeral = *c;
2802 ths.monotonic_time = tc.monotonic_time;
2803 ths.challenge = tc.challenge;
2805 &ths,
2806 &tc.sender_sig);
2807 GNUNET_assert (0 ==
2808 gcry_cipher_encrypt (queue->out_cipher,
2809 &queue->cwrite_buf[queue->cwrite_off],
2810 sizeof(tc),
2811 &tc,
2812 sizeof(tc)));
2813 queue->challenge = tc.challenge;
2814 queue->cwrite_off += sizeof(tc);
2815
2817 "handshake written\n");
2818}
2819
2820
2828static void
2830{
2832 struct GNUNET_ShortHashCode k;
2833
2835 &c, &k);
2836 setup_out_cipher (queue, &k);
2837 transmit_kx (queue, &c);
2838}
2839
2840
2846static void
2847handshake_monotime_store_cb (void *cls, int success)
2848{
2849 struct Queue *queue = cls;
2850 if (GNUNET_OK != success)
2851 {
2853 "Failed to store handshake monotonic time in PEERSTORE!\n");
2854 }
2855 queue->handshake_monotime_sc = NULL;
2856 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2857}
2858
2859
2867static void
2868handshake_monotime_cb (void *cls,
2869 const struct GNUNET_PEERSTORE_Record *record,
2870 const char *emsg)
2871{
2872 struct Queue *queue = cls;
2873 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2874 struct GNUNET_TIME_Absolute mt;
2875 const struct GNUNET_PeerIdentity *pid;
2876 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2877
2878 (void) emsg;
2879
2880 handshake_monotonic_time = &queue->handshake_monotonic_time;
2881 pid = &queue->target;
2883 "tcp handshake with us %s\n",
2885 if (NULL == record)
2886 {
2887 queue->handshake_monotime_get = NULL;
2888 return;
2889 }
2891 "tcp handshake from peer %s\n",
2892 GNUNET_i2s (pid));
2893 if (sizeof(*mtbe) != record->value_size)
2894 {
2895 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2896 GNUNET_break (0);
2897 return;
2898 }
2899 mtbe = record->value;
2900 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2901 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2902 queue->handshake_monotonic_time).abs_value_us)
2903 {
2905 "Queue from %s dropped, handshake monotime in the past\n",
2906 GNUNET_i2s (&queue->target));
2907 GNUNET_break (0);
2908 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2909 queue->handshake_ack_monotime_get = NULL;
2911 return;
2912 }
2913 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2914 "transport_tcp_communicator",
2915 pid,
2917 handshake_monotonic_time,
2918 sizeof(*
2919 handshake_monotonic_time),
2922 &
2924 queue);
2925}
2926
2927
2939static int
2941 struct TCPConfirmation *tc,
2942 char *ibuf)
2943{
2944 const struct GNUNET_PeerIdentity *my_identity;
2945 struct TcpHandshakeSignature ths;
2947
2950
2952 0 ==
2953 gcry_cipher_decrypt (queue->in_cipher,
2954 tc,
2955 sizeof(*tc),
2956 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2957 sizeof(*tc)));
2958 ths.purpose.purpose = htonl (
2960 ths.purpose.size = htonl (sizeof(ths));
2961 ths.sender = tc->sender;
2962 ths.receiver = *my_identity;
2963 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2964 ths.monotonic_time = tc->monotonic_time;
2965 ths.challenge = tc->challenge;
2968 &ths,
2969 &tc->sender_sig,
2970 &tc->sender.public_key);
2971 if (GNUNET_YES == ret)
2972 queue->handshake_monotime_get =
2974 "transport_tcp_communicator",
2975 &queue->target,
2978 queue);
2979 return ret;
2980}
2981
2982
2990static void
2991queue_read_kx (void *cls)
2992{
2993 struct Queue *queue = cls;
2994 ssize_t rcvd;
2995 struct GNUNET_TIME_Relative left;
2996 struct TCPConfirmation tc;
2997
2998 queue->read_task = NULL;
2999 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
3000 if (0 == left.rel_value_us)
3001 {
3003 return;
3004 }
3005 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
3006 &queue->cread_buf[queue->cread_off],
3007 BUF_SIZE - queue->cread_off);
3009 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
3010 PRIu64 ")\n",
3011 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
3012 if (-1 == rcvd)
3013 {
3014 if ((EAGAIN != errno) && (EINTR != errno))
3015 {
3018 return;
3019 }
3020 queue->read_task =
3022 return;
3023 }
3024 if (0 == rcvd)
3025 {
3026 /* Orderly shutdown of connection */
3028 "Socket for queue %p seems to have been closed\n", queue);
3030 return;
3031 }
3032 queue->cread_off += rcvd;
3033 if (queue->cread_off < INITIAL_KX_SIZE)
3034 {
3035 /* read more */
3037 "%lu/%lu bytes of KX read. Rescheduling...\n",
3038 queue->cread_off, INITIAL_KX_SIZE);
3039 queue->read_task =
3041 return;
3042 }
3043 /* we got all the data, let's find out who we are talking to! */
3045 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
3046 queue->cread_buf,
3047 queue);
3048 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
3049 {
3051 "Invalid TCP KX received from %s\n",
3052 GNUNET_a2s (queue->address, queue->address_len));
3054 return;
3055 }
3056 if (0 !=
3057 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
3058 {
3060 "Invalid sender in TCP KX received from %s\n",
3061 GNUNET_a2s (queue->address, queue->address_len));
3063 return;
3064 }
3065 send_challenge (tc.challenge, queue);
3066 queue->write_task =
3068 queue->sock,
3069 &queue_write,
3070 queue);
3071
3072 /* update queue timeout */
3073 queue->timeout =
3075 /* prepare to continue with regular read task immediately */
3076 memmove (queue->cread_buf,
3077 &queue->cread_buf[INITIAL_KX_SIZE],
3078 queue->cread_off - (INITIAL_KX_SIZE));
3080 "cread_off is %lu bytes before adjusting\n",
3081 queue->cread_off);
3082 queue->cread_off -= INITIAL_KX_SIZE;
3084 "cread_off set to %lu bytes\n",
3085 queue->cread_off);
3087}
3088
3089
3096static void
3097proto_read_kx (void *cls)
3098{
3099 struct ProtoQueue *pq = cls;
3100 ssize_t rcvd;
3101 struct GNUNET_TIME_Relative left;
3102 struct Queue *queue;
3103 struct TCPConfirmation tc;
3105
3106 pq->read_task = NULL;
3108 if (0 == left.rel_value_us)
3109 {
3110 free_proto_queue (pq);
3111 return;
3112 }
3113 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3114 &pq->ibuf[pq->ibuf_off],
3115 sizeof(pq->ibuf) - pq->ibuf_off);
3117 "Proto received %lu bytes for KX\n", rcvd);
3118 if (-1 == rcvd)
3119 {
3120 if ((EAGAIN != errno) && (EINTR != errno))
3121 {
3123 free_proto_queue (pq);
3124 return;
3125 }
3126 /* try again */
3127 pq->read_task =
3129 return;
3130 }
3131 if (0 == rcvd)
3132 {
3133 /* Orderly shutdown of connection */
3135 "Socket for proto queue %p seems to have been closed\n", pq);
3136 free_proto_queue (pq);
3137 return;
3138 }
3139 pq->ibuf_off += rcvd;
3140 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3141 {
3142 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3143
3145 &pm->clientIdentity);
3146
3147 queue = GNUNET_new (struct Queue);
3148 queue->target = pm->clientIdentity;
3149 eddsa_pub_to_hpke_key (&queue->target.public_key,
3150 &queue->target_hpke_key);
3153 }
3154 else if (pq->ibuf_off < sizeof(pq->ibuf))
3155 {
3156 /* read more */
3157 pq->read_task =
3159 return;
3160 }
3161 else
3162 {
3163 /* we got all the data, let's find out who we are talking to! */
3164 queue = GNUNET_new (struct Queue);
3166 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
3167 ibuf,
3168 queue);
3169 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3170 {
3172 "Invalid TCP KX received from %s\n",
3173 GNUNET_a2s (pq->address, pq->address_len));
3174 gcry_cipher_close (queue->in_cipher);
3176 free_proto_queue (pq);
3177 return;
3178 }
3179 queue->target = tc.sender;
3180 eddsa_pub_to_hpke_key (&queue->target.public_key,
3181 &queue->target_hpke_key);
3184 }
3185 queue->address = pq->address; /* steals reference */
3186 queue->address_len = pq->address_len;
3187 queue->listen_sock = pq->listen_sock;
3188 queue->sock = pq->sock;
3189
3191 "created queue with target %s\n",
3192 GNUNET_i2s (&queue->target));
3193
3195 "start kx proto\n");
3196
3198 boot_queue (queue);
3199 queue->read_task =
3201 queue->sock,
3202 read_task,
3203 queue);
3204 queue->write_task =
3206 queue->sock,
3207 &queue_write,
3208 queue);
3209 // TODO To early! Move it somewhere else.
3210 // send_challenge (tc.challenge, queue);
3211 queue->challenge_received = tc.challenge;
3212
3214 GNUNET_free (pq);
3215}
3216
3217
3218static struct ProtoQueue *
3220 struct sockaddr *in,
3221 socklen_t addrlen)
3222{
3223 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3224
3225 if (NULL == sock)
3226 {
3227 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3228 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3229 if (NULL == sock)
3230 {
3232 "socket(%d) failed: %s",
3233 in->sa_family,
3234 strerror (errno));
3235 GNUNET_free (in);
3236 GNUNET_free (pq);
3237 return NULL;
3238 }
3239 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3240 (errno != EINPROGRESS))
3241 {
3243 "connect to `%s' failed: %s",
3244 GNUNET_a2s (in, addrlen),
3245 strerror (errno));
3247 GNUNET_free (in);
3248 GNUNET_free (pq);
3249 return NULL;
3250 }
3251 }
3252 pq->address_len = addrlen;
3253 pq->address = in;
3255 pq->sock = sock;
3257 pq->sock,
3259 pq);
3261
3262 return pq;
3263}
3264
3265
3273static void
3274listen_cb (void *cls)
3275{
3276 struct sockaddr_storage in;
3277 socklen_t addrlen;
3278 struct GNUNET_NETWORK_Handle *sock;
3279 struct ListenTask *lt;
3280 struct sockaddr *in_addr;
3281
3283 "listen_cb\n");
3284
3285 lt = cls;
3286
3287 lt->listen_task = NULL;
3288 GNUNET_assert (NULL != lt->listen_sock);
3289 addrlen = sizeof(in);
3290 memset (&in, 0, sizeof(in));
3292 (struct sockaddr*) &in,
3293 &addrlen);
3294 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3295 return; /* system limit reached, wait until connection goes down */
3297 lt->listen_sock,
3298 &listen_cb,
3299 lt);
3300 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3301 return;
3302 if (NULL == sock)
3303 {
3305 return;
3306 }
3307 in_addr = GNUNET_memdup (&in, addrlen);
3308 create_proto_queue (sock, in_addr, addrlen);
3309}
3310
3311
3312static void
3313try_connection_reversal (void *cls,
3314 const struct sockaddr *addr,
3315 socklen_t addrlen)
3316{
3317 const struct GNUNET_PeerIdentity *my_identity;
3318 struct TCPNATProbeMessage pm;
3319 struct ProtoQueue *pq;
3320 struct sockaddr *in_addr;
3321 (void) cls;
3322
3325
3327 "addr->sa_family %d\n",
3328 addr->sa_family);
3330 "Try to connect back\n");
3331 in_addr = GNUNET_memdup (addr, addrlen);
3333 "in_addr->sa_family %d\n",
3334 in_addr->sa_family);
3335 pq = create_proto_queue (NULL, in_addr, addrlen);
3336 if (NULL != pq)
3337 {
3338 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3339 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3340 pm.clientIdentity = *my_identity;
3341 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3342 pq->write_off = sizeof(struct TCPNATProbeMessage);
3344 pq->sock,
3346 pq);
3347 }
3348 else
3349 {
3351 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3352 }
3353}
3354
3355
3356static void
3357pending_reversal_timeout (void *cls)
3358{
3359 struct sockaddr *in = cls;
3360 struct PendingReversal *pending_reversal;
3361 struct GNUNET_HashCode key;
3362
3364 sizeof(struct sockaddr),
3365 &key);
3367 &key);
3368
3369 GNUNET_assert (NULL != pending_reversal);
3370
3372 &key,
3373 pending_reversal))
3375 "No pending reversal found for address %s\n",
3376 GNUNET_a2s (in, sizeof (struct sockaddr)));
3377 GNUNET_free (pending_reversal->in);
3378 GNUNET_free (pending_reversal);
3379}
3380
3381
3400static int
3401mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3402{
3403 struct sockaddr *in;
3404 socklen_t in_len = 0;
3405 const char *path;
3406 struct sockaddr_in *v4;
3407 struct sockaddr_in6 *v6;
3408 unsigned int is_natd = GNUNET_NO;
3409 struct GNUNET_HashCode key;
3410 struct GNUNET_HashCode queue_map_key;
3411 struct GNUNET_HashContext *hsh;
3412 struct Queue *queue;
3413
3415 "Connecting to %s at %s\n",
3416 GNUNET_i2s (peer),
3417 address);
3418 if (0 != strncmp (address,
3420 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3421 {
3422 GNUNET_break_op (0);
3423 return GNUNET_SYSERR;
3424 }
3425 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3426 in = tcp_address_to_sockaddr (path, &in_len);
3427
3428 if (NULL == in)
3429 {
3431 "Failed to setup TCP socket address\n");
3432 return GNUNET_SYSERR;
3433 }
3434
3436 "in %s\n",
3437 GNUNET_a2s (in, in_len));
3438
3441 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3442 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3444
3445 if (NULL != queue)
3446 {
3448 "Queue for %s already exists or is in construction\n", address);
3449 GNUNET_free (in);
3450 return GNUNET_NO;
3451 }
3452 switch (in->sa_family)
3453 {
3454 case AF_INET:
3455 v4 = (struct sockaddr_in *) in;
3456 if (0 == v4->sin_port)
3457 {
3458 is_natd = GNUNET_YES;
3460 sizeof(struct sockaddr),
3461 &key);
3464 &key))
3465 {
3467 "There is already a request reversal for `%s'at `%s'\n",
3468 GNUNET_i2s (peer),
3469 address);
3470 GNUNET_free (in);
3471 return GNUNET_SYSERR;
3472 }
3473 }
3474 break;
3475
3476 case AF_INET6:
3477 if (GNUNET_YES == disable_v6)
3478 {
3480 "IPv6 disabled, skipping %s\n", address);
3481 GNUNET_free (in);
3482 return GNUNET_SYSERR;
3483 }
3484 v6 = (struct sockaddr_in6 *) in;
3485 if (0 == v6->sin6_port)
3486 {
3488 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3489 GNUNET_i2s (peer),
3490 address);
3491 GNUNET_free (in);
3492 return GNUNET_SYSERR;
3493 }
3494 break;
3495
3496 default:
3497 GNUNET_assert (0);
3498 }
3499
3500 if (GNUNET_YES == is_natd)
3501 {
3502 struct sockaddr_in local_sa;
3503 struct PendingReversal *pending_reversal;
3504
3505 memset (&local_sa, 0, sizeof(local_sa));
3506 local_sa.sin_family = AF_INET;
3507 local_sa.sin_port = htons (bind_port);
3508 /* We leave sin_address at 0, let the kernel figure it out,
3509 even if our bind() is more specific. (May want to reconsider
3510 later.) */
3511 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3512 {
3514 "request reversal for `%s' at `%s' failed\n",
3515 GNUNET_i2s (peer),
3516 address);
3517 GNUNET_free (in);
3518 return GNUNET_SYSERR;
3519 }
3520 pending_reversal = GNUNET_new (struct PendingReversal);
3521 pending_reversal->in = in;
3524 &key,
3525 pending_reversal,
3527 pending_reversal->target = *peer;
3529 &
3531 in);
3533 "Created NAT WAIT connection to `%s' at `%s'\n",
3534 GNUNET_i2s (peer),
3535 GNUNET_a2s (in, sizeof (struct sockaddr)));
3536 }
3537 else
3538 {
3539 struct GNUNET_NETWORK_Handle *sock;
3540
3541 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3542 IPPROTO_TCP);
3543 if (NULL == sock)
3544 {
3546 "socket(%d) failed: %s",
3547 in->sa_family,
3548 strerror (errno));
3549 GNUNET_free (in);
3550 return GNUNET_SYSERR;
3551 }
3552 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3553 (errno != EINPROGRESS))
3554 {
3556 "connect to `%s' failed: %s",
3557 address,
3558 strerror (errno));
3560 GNUNET_free (in);
3561 return GNUNET_SYSERR;
3562 }
3563
3564 queue = GNUNET_new (struct Queue);
3565 queue->target = *peer;
3566 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3567 queue->key = queue_map_key;
3568 queue->address = in;
3569 queue->address_len = in_len;
3570 queue->sock = sock;
3572 boot_queue (queue);
3574 "booted queue with target %s\n",
3575 GNUNET_i2s (&queue->target));
3576 // queue->mq_awaits_continue = GNUNET_YES;
3577 queue->read_task =
3579 queue->sock,
3581 queue);
3582
3583
3585 "start kx mq_init\n");
3586
3588 queue->write_task =
3590 queue->sock,
3591 &queue_write,
3592 queue);
3593 }
3594
3595 return GNUNET_OK;
3596}
3597
3598
3607static int
3608get_lt_delete_it (void *cls,
3609 const struct GNUNET_HashCode *key,
3610 void *value)
3611{
3612 struct ListenTask *lt = value;
3613
3614 (void) cls;
3615 (void) key;
3616 if (NULL != lt->listen_task)
3617 {
3619 lt->listen_task = NULL;
3620 }
3621 if (NULL != lt->listen_sock)
3622 {
3624 lt->listen_sock = NULL;
3625 }
3626 GNUNET_free (lt);
3627 return GNUNET_OK;
3628}
3629
3630
3639static int
3640get_queue_delete_it (void *cls,
3641 const struct GNUNET_HashCode *target,
3642 void *value)
3643{
3644 struct Queue *queue = value;
3645
3646 (void) cls;
3647 (void) target;
3649 return GNUNET_OK;
3650}
3651
3652
3658static void
3659do_shutdown (void *cls)
3660{
3662 "Shutdown %s!\n",
3663 shutdown_running ? "running" : "not running");
3664
3666 return;
3667 else
3669
3670 while (NULL != proto_head)
3672 if (NULL != nat)
3673 {
3675 nat = NULL;
3676 }
3684 if (NULL != ch)
3685 {
3688 ch = NULL;
3689 }
3690 if (NULL != stats)
3691 {
3693 stats = NULL;
3694 }
3695 if (NULL != is)
3696 {
3698 is = NULL;
3699 }
3700 if (NULL != pils)
3701 {
3703 pils = NULL;
3704 }
3705 if (NULL != key_ring)
3706 {
3708 key_ring = NULL;
3709 }
3710 if (NULL != peerstore)
3711 {
3713 peerstore = NULL;
3714 }
3715 if (NULL != resolve_request_handle)
3716 {
3719 }
3721 "Shutdown done!\n");
3722}
3723
3724
3736static void
3737enc_notify_cb (void *cls,
3738 const struct GNUNET_PeerIdentity *sender,
3739 const struct GNUNET_MessageHeader *msg)
3740{
3741 (void) cls;
3742 (void) sender;
3743 (void) msg;
3744 GNUNET_break_op (0);
3745}
3746
3747
3761static void
3762nat_address_cb (void *cls,
3763 void **app_ctx,
3764 int add_remove,
3766 const struct sockaddr *addr,
3767 socklen_t addrlen)
3768{
3769 char *my_addr;
3771
3773 "nat address cb %s %s\n",
3774 add_remove ? "add" : "remove",
3775 GNUNET_a2s (addr, addrlen));
3776
3777 if (GNUNET_YES == add_remove)
3778 {
3780
3781 GNUNET_asprintf (&my_addr,
3782 "%s-%s",
3784 GNUNET_a2s (addr, addrlen));
3785 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3786 ai =
3788 my_addr,
3789 nt,
3791 GNUNET_free (my_addr);
3792 *app_ctx = ai;
3793 }
3794 else
3795 {
3796 ai = *app_ctx;
3798 *app_ctx = NULL;
3799 }
3800}
3801
3802
3806static void
3807add_addr (struct sockaddr *in, socklen_t in_len)
3808{
3809
3810 struct Addresses *saddrs;
3811
3813 "add address %s\n",
3814 GNUNET_a2s (in, in_len));
3815
3816 saddrs = GNUNET_new (struct Addresses);
3817 saddrs->addr = in;
3818 saddrs->addr_len = in_len;
3820
3822 "after add address %s\n",
3823 GNUNET_a2s (in, in_len));
3824
3826 "add address %s\n",
3827 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3828
3829 addrs_lens++;
3830}
3831
3832
3840static int
3841init_socket (struct sockaddr *addr,
3842 socklen_t in_len)
3843{
3844 struct sockaddr_storage in_sto;
3845 socklen_t sto_len;
3846 struct GNUNET_NETWORK_Handle *listen_sock;
3847 struct ListenTask *lt;
3848 int sockfd;
3849 struct GNUNET_HashCode h_sock;
3850
3851 if (NULL == addr)
3852 {
3854 "Address is NULL.\n");
3855 return GNUNET_SYSERR;
3856 }
3857
3859 "address %s\n",
3860 GNUNET_a2s (addr, in_len));
3861
3862 listen_sock =
3863 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3864 if (NULL == listen_sock)
3865 {
3867 return GNUNET_SYSERR;
3868 }
3869
3870 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3871 {
3873 GNUNET_NETWORK_socket_close (listen_sock);
3874 listen_sock = NULL;
3875 return GNUNET_SYSERR;
3876 }
3877
3878 if (GNUNET_OK !=
3879 GNUNET_NETWORK_socket_listen (listen_sock,
3880 5))
3881 {
3883 "listen");
3884 GNUNET_NETWORK_socket_close (listen_sock);
3885 listen_sock = NULL;
3886 return GNUNET_SYSERR;
3887 }
3888
3889 /* We might have bound to port 0, allowing the OS to figure it out;
3890 thus, get the real IN-address from the socket */
3891 sto_len = sizeof(in_sto);
3892
3893 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3894 (struct sockaddr *) &in_sto,
3895 &sto_len))
3896 {
3897 memcpy (&in_sto, addr, in_len);
3898 sto_len = in_len;
3899 }
3900
3901 // addr = (struct sockaddr *) &in_sto;
3902 in_len = sto_len;
3904 "Bound to `%s'\n",
3905 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3906 if (NULL == stats)
3907 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3908
3909 if (NULL == is)
3911
3912 /* start listening */
3913
3914 lt = GNUNET_new (struct ListenTask);
3915 lt->listen_sock = listen_sock;
3916
3918 listen_sock,
3919 &listen_cb,
3920 lt);
3921
3923 "creating hash\n");
3924 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3925 GNUNET_CRYPTO_hash (&sockfd,
3926 sizeof(int),
3927 &h_sock);
3928
3930 "creating map\n");
3931 if (NULL == lt_map)
3933
3935 "creating map entry\n");
3938 &h_sock,
3939 lt,
3941
3943 "map entry created\n");
3944
3945 if (NULL == queue_map)
3947
3948 if (NULL == ch)
3953 &mq_init,
3954 NULL,
3956 NULL,
3957 NULL);
3958
3959 if (NULL == ch)
3960 {
3961 GNUNET_break (0);
3962 if (NULL != resolve_request_handle)
3965 return GNUNET_SYSERR;
3966 }
3967
3968 add_addr (addr, in_len);
3969 return GNUNET_OK;
3970
3971}
3972
3973
3977static void
3978nat_register ()
3979{
3980 struct sockaddr **saddrs;
3981 socklen_t *saddr_lens;
3982 int i;
3983 size_t len;
3984
3986 "starting nat register!\n");
3987 len = 0;
3988 i = 0;
3989 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3990 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3991 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3992 {
3994 "registering address %s\n",
3995 GNUNET_a2s (pos->addr, pos->addr_len));
3996
3997 saddr_lens[i] = pos->addr_len;
3998 len += saddr_lens[i];
3999 saddrs[i] = GNUNET_memdup (pos->addr, saddr_lens[i]);
4000 i++;
4001 }
4002
4004 "registering addresses %lu %lu %lu %lu\n",
4005 (addrs_lens) * sizeof(struct sockaddr *),
4006 (addrs_lens) * sizeof(socklen_t),
4007 len,
4011 IPPROTO_TCP,
4012 addrs_lens,
4013 (const struct sockaddr **) saddrs,
4014 saddr_lens,
4017 NULL /* closure */);
4018 for (i = addrs_lens - 1; i >= 0; i--)
4019 GNUNET_free (saddrs[i]);
4020 GNUNET_free (saddrs);
4021 GNUNET_free (saddr_lens);
4022
4023 if (NULL == nat)
4024 {
4025 GNUNET_break (0);
4026 if (NULL != resolve_request_handle)
4029 }
4030}
4031
4032
4040static void
4041init_socket_resolv (void *cls,
4042 const struct sockaddr *addr,
4043 socklen_t in_len)
4044{
4045 struct sockaddr_in *v4;
4046 struct sockaddr_in6 *v6;
4047 struct sockaddr *in;
4048
4049 (void) cls;
4050 if (NULL != addr)
4051 {
4052 if (AF_INET == addr->sa_family)
4053 {
4054 v4 = (struct sockaddr_in *) addr;
4055 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
4056 }
4057 else if (AF_INET6 == addr->sa_family)
4058 {
4059 v6 = (struct sockaddr_in6 *) addr;
4060 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
4061 }
4062 else
4063 {
4065 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
4066 addr->sa_family,
4067 AF_INET,
4068 AF_INET6);
4069 return;
4070 }
4071 init_socket (in, in_len);
4072 }
4073 else
4074 {
4076 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4077 if (NULL == addrs_head)
4078 {
4080 "Resolver finished resolving, but we do not listen to an address!.\n");
4081 return;
4082 }
4083 nat_register ();
4084 }
4085}
4086
4087
4096static void
4097run (void *cls,
4098 char *const *args,
4099 const char *cfgfile,
4100 const struct GNUNET_CONFIGURATION_Handle *c)
4101{
4102 char *bindto;
4103 struct sockaddr *in;
4104 socklen_t in_len;
4105 struct sockaddr_in v4;
4106 struct sockaddr_in6 v6;
4107 char *start;
4108 unsigned int port;
4109 char dummy[2];
4110 char *rest = NULL;
4111 struct PortOnlyIpv4Ipv6 *po;
4112 socklen_t addr_len_ipv4;
4113 socklen_t addr_len_ipv6;
4114
4115 (void) cls;
4116
4118 memset (&v4,0,sizeof(struct sockaddr_in));
4119 memset (&v6,0,sizeof(struct sockaddr_in6));
4120 cfg = c;
4121 if (GNUNET_OK !=
4124 "BINDTO",
4125 &bindto))
4126 {
4129 "BINDTO");
4130 return;
4131 }
4132 if (GNUNET_OK !=
4135 "MAX_QUEUE_LENGTH",
4137 {
4139 }
4140 if (GNUNET_OK !=
4143 "REKEY_INTERVAL",
4145 {
4147 }
4148 if (GNUNET_OK !=
4151 "REKEY_MAX_BYTES",
4153 {
4155 }
4157 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4158 (GNUNET_YES ==
4161 "DISABLE_V6")))
4162 {
4164 }
4166 GNUNET_assert (NULL != key_ring);
4167 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
4168 GNUNET_assert (NULL != pils);
4170 if (NULL == peerstore)
4171 {
4172 GNUNET_free (bindto);
4173 GNUNET_break (0);
4175 return;
4176 }
4177
4179
4180 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4181 {
4185 "address po %s\n",
4187 if (NULL != po->addr_ipv4)
4188 {
4190 }
4191 if (NULL != po->addr_ipv6)
4192 {
4195 }
4196 GNUNET_free (po);
4197 nat_register ();
4198 GNUNET_free (bindto);
4199 return;
4200 }
4201
4202 start = extract_address (bindto);
4203 // FIXME: check for NULL == start...
4204 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4205 {
4206 bind_port = extract_port (bindto);
4207
4209 init_socket (in, in_len);
4210 nat_register ();
4212 GNUNET_free (bindto);
4213 return;
4214 }
4215
4216 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4217 {
4218 bind_port = extract_port (bindto);
4220 init_socket (in, in_len);
4221 nat_register ();
4223 GNUNET_free (bindto);
4224 return;
4225 }
4226
4227 bind_port = extract_port (bindto);
4229 ":",
4230 &rest),
4231 AF_UNSPEC,
4234 &port);
4235
4236 GNUNET_free (bindto);
4238}
4239
4240
4248int
4249main (int argc, char *const *argv)
4250{
4251 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4253 };
4254 int ret;
4255
4257 "Starting tcp communicator\n");
4258
4259 ret = (GNUNET_OK ==
4261 argc,
4262 argv,
4263 "gnunet-communicator-tcp",
4264 _ ("GNUnet TCP communicator"),
4265 options,
4266 &run,
4267 NULL))
4268 ? 0
4269 : 1;
4270 return ret;
4271}
4272
4273
4274/* end of gnunet-communicator-tcp.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MessageHeader * msg
Definition 005.c:2
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
static int start
Set if we are to start default services (including ARM).
Definition gnunet-arm.c:38
static int ret
Final status code.
Definition gnunet-arm.c:93
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
static void queue_finish(struct Queue *queue)
Append a 'finish' message to the outgoing transmission.
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.
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
static unsigned int bind_port
The port the communicator should be assigned to.
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
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.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
static struct PortOnlyIpv4Ipv6 * tcp_address_to_sockaddr_port_only(const char *bindto, unsigned int *port)
Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
static void setup_in_cipher(const struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void eddsa_pub_to_hpke_key(const struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_HpkePublicKey *pk)
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
static void do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
Handle rekey message on queue.
static void calculate_hmac(struct GNUNET_CRYPTO_AuthKey *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
static struct ProtoQueue * create_proto_queue(struct GNUNET_NETWORK_Handle *sock, struct sockaddr *in, socklen_t addrlen)
static int init_socket(struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
static void try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
static void eddsa_priv_to_hpke_key(const struct GNUNET_CRYPTO_EddsaPrivateKey *edpk, struct GNUNET_CRYPTO_HpkePrivateKey *pk)
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
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...
static int disable_v6
IPv6 disabled.
static struct GNUNET_CONTAINER_MultiHashMap * pending_reversals
Map of pending reversals.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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 (!...
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer's HELLOs.
static int pending_reversals_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
static int get_lt_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all ListenTasks to clean up.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue's plaintext buffer.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
#define NAT_TIMEOUT
How long until we give up on establishing an NAT connection? Must be > 4 RTT.
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static struct GNUNET_CONTAINER_MultiHashMap * queue_map
Queues (map from peer identity to struct Queue)
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue.
static 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 ...
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static void check_and_remove_pending_reversal(struct sockaddr *in, sa_family_t sa_family, struct GNUNET_PeerIdentity *sender)
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.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
static void nat_register()
This method reads from the DLL addrs_head to register them at the NAT service.
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.
static int addrs_lens
Number of addresses in the DLL for register at NAT service.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static void pending_reversal_timeout(void *cls)
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
static void queue_read(void *cls)
Queue read task.
static struct GNUNET_PILS_KeyRing * key_ring
For PILS.
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
static int get_queue_delete_it(void *cls, const struct GNUNET_HashCode *target, void *value)
Iterator over all message queues to clean up.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
static void handshake_ack_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_A...
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 abou...
static void proto_queue_write(void *cls)
We have been notified that our socket is ready to write.
static void handshake_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake monotime is finished.
static void send_challenge(struct GNUNET_CRYPTO_ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
static void rekey_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for rekey monotime value is finished.
static char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
static int shutdown_running
A flag indicating we are already doing a shutdown.
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
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.
static void handshake_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE w...
static struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT service.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
static struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT service.
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.
#define DEFAULT_MAX_QUEUE_LENGTH
How many messages do we keep at most in the queue to the transport service before we start to drop (d...
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
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.
static struct GNUNET_PILS_Handle * pils
For PILS.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it.
static void setup_cipher(const struct GNUNET_ShortHashCode *prk, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_CRYPTO_AuthKey *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
static unsigned long long rekey_max_bytes
The rekey byte maximum.
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.
static struct GNUNET_SCHEDULER_Task * write_task
ID of write task.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
struct GNUNET_SCHEDULER_Task * read_task
static void queue(const char *label, uint32_t rd_count, struct GNUNET_GNSRECORD_Data *rd, const struct Zone *zone)
Add hostname to the list of requests to be made.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
The current private key.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:465
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
struct GNUNET_PILS_KeyRing * GNUNET_PILS_create_key_ring(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SCHEDULER_TaskCallback init_cb, void *cls)
Create a key ring handle to use the current peer identity key.
Definition pils_api.c:804
void GNUNET_PILS_destroy_key_ring(struct GNUNET_PILS_KeyRing *key_ring)
Destroy a key ring handle and free its memory.
Definition pils_api.c:864
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_PILS_key_ring_get_private_key(const struct GNUNET_PILS_KeyRing *key_ring)
Return the current private key of a given key ring handle.
Definition pils_api.c:887
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls, GNUNET_TRANSPORT_StartBurstNotify sb)
Connect to the transport service.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
@ GNUNET_TRANSPORT_CS_INBOUND
this is an inbound connection (communicator initiated)
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Decapsulate a key for a private EdDSA key.
uint64_t GNUNET_CRYPTO_random_u64(uint64_t max)
Generate a random unsigned 64-bit value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps(const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh decapsulation with own private key and the representative of the received public key...
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_encaps(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Encapsulate key material for a EdDSA public key.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
#define GNUNET_CRYPTO_hkdf_expand(result, out_len, prk,...)
HKDF-Expand using SHA256.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
#define GNUNET_CRYPTO_kdf_arg_string(d)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_BlindablePrivateKey *sk, struct GNUNET_CRYPTO_HpkePrivateKey *sk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
GNUNET_GenericReturnValue
Named constants for return values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_BlindablePublicKey *pk, struct GNUNET_CRYPTO_HpkePublicKey *pk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition mq.c:482
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition mq.c:437
int GNUNET_NAT_request_reversal(struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP respons...
Definition nat_api.c:675
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition nat_api.c:366
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition nat_api.c:703
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition network.c:392
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition network.c:508
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition network.c:1000
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition network.c:716
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition network.c:832
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition network.c:601
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition network.c:737
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition network.c:79
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition network.c:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition network.c:651
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition nt.c:428
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition nt.c:407
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition nt.c:309
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
void GNUNET_PEERSTORE_iteration_next(struct GNUNET_PEERSTORE_IterateContext *ic, uint64_t limit)
Continue an iteration.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender's monotonic time from handshake message.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender's monotonic time from handshake ack message.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender's monotonic time from rekey message.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:406
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE
TCP NAT probe message, send from NAT'd peer to other peer to establish bi-directional communication.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1517
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1588
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition strings.c:610
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition time.c:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:671
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define max(x, y)
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition scheduler.c:436
static void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition socks.c:330
DLL to store the addresses we like to register at NAT service.
struct Addresses * next
Kept in a DLL.
struct Addresses * prev
Kept in a DLL.
struct sockaddr * addr
Address we like to register at NAT service.
socklen_t addr_len
Length of address we like to register at NAT service.
Internal representation of the hash map.
type for (message) authentication keys
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Type of a nonce used for challenges.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using EdDSA.
HPKE DHKEM encapsulation (X25519) See RFC 9180.
A public key used for decryption.
A public key used for encryption.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Definition of a command line option.
A 512-bit hashcode.
Handle to a message queue.
Definition mq.c:87
Header for all communications.
Handle for active NAT registrations.
Definition nat_api.c:72
handle to a socket
Definition network.c:53
Handle to the interface scanner.
Definition nt.c:104
Handle to the PEERSTORE service.
Context for a iterate request.
Context for a store request.
A handle for the PILS service.
Definition pils_api.c:82
A simplified handle for using the peer identity key.
Definition pils_api.c:132
The identity of the host (wraps the signing key of the peer).
Handle to a request given to the resolver.
Entry in list of pending tasks.
Definition scheduler.c:141
Handle for the service.
A 256-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Internal representation of an address a communicator is currently providing for the transport service...
Opaque handle to the transport service for communicators.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
Struct to use as closure.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
Struct for pending nat reversals.
struct sockaddr * in
Address the reversal was send to.
struct GNUNET_SCHEDULER_Task * timeout_task
struct GNUNET_PeerIdentity target
To whom are we like to talk to.
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
socklen_t addr_len_ipv6
Length of ipv6 address.
socklen_t addr_len_ipv4
Length of ipv4 address.
Handle for an incoming connection where we do not yet have enough information to setup a full queue.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char write_buf[sizeof(struct TCPNATProbeMessage)]
buffer for writing struct TCPNATProbeMessage to network.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
size_t ibuf_off
Current offset for reading into ibuf.
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct sockaddr * address
Address of the other peer.
struct ProtoQueue * prev
Kept in a DLL.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
size_t write_off
Offset of the buffer?
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
struct ProtoQueue * next
Kept in a DLL.
Handle for a queue.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknowledgem...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
size_t unverified_size
Size of data received without KX challenge played back.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
int finishing
Did we enqueue a finish message and are closing down the queue?
int initial_core_kx_done
Has the initial (core) handshake already happened?
struct GNUNET_HashCode key
Key in hash map.
socklen_t address_len
Length of the address.
struct GNUNET_CRYPTO_AuthKey in_hmac
Shared secret for HMAC verification on incoming data.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
unsigned long long bytes_in_queue
Number of bytes we currently have in our write queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next?
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
struct GNUNET_CRYPTO_HpkePublicKey target_hpke_key
To whom are we talking to.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_CRYPTO_ChallengeNonceP challenge_received
Challenge value received.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next?
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_PeerIdentity target
To whom are we talking to.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next?
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct sockaddr * address
Address of the other peer.
struct GNUNET_CRYPTO_AuthKey out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
TCP message box.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Ack for the encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK.
struct GNUNET_PeerIdentity sender
Sender's identity.
Encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_PeerIdentity sender
Sender's identity.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Basically a WELCOME message, but with the purpose of giving the waiting peer a client handle to use.
struct GNUNET_PeerIdentity clientIdentity
Identity of the sender of the message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
TCP rekey message box.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral
New ephemeral key.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral
Ephemeral key used by the sender.
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...

◆ DEFAULT_MAX_QUEUE_LENGTH

#define DEFAULT_MAX_QUEUE_LENGTH   8

How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file).

Should be below the level of the communicator API, as otherwise we may read messages just to have them dropped by the communicator API.

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

◆ BUF_SIZE

#define BUF_SIZE   (2 * 64 * 1024 + sizeof(struct TCPBox))

Size of our IO buffers for ciphertext data.

Must be at least UINT_MAX + sizeof (struct TCPBox).

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

◆ DEFAULT_REKEY_INTERVAL

#define DEFAULT_REKEY_INTERVAL   GNUNET_TIME_UNIT_DAYS

How often do we rekey based on time (at least)

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

◆ PROTO_QUEUE_TIMEOUT

#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES

How long do we wait until we must have received the initial KX?

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

◆ REKEY_MAX_BYTES

#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 91 of file gnunet-communicator-tcp.c.

◆ INITIAL_KX_SIZE

#define INITIAL_KX_SIZE
Value:
(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
+ sizeof(struct TCPConfirmation))

Size of the initial key exchange message sent first in both directions.

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

◆ INITIAL_CORE_KX_SIZE

#define INITIAL_CORE_KX_SIZE
Value:
(sizeof(struct EphemeralKeyMessage) \
+ sizeof(struct PingMessage) \
+ sizeof(struct PongMessage))
Message transmitted with the signed ephemeral key of a peer.
We're sending an (encrypted) PING to the other peer to check if it can decrypt.
Response to a PING.

Size of the initial core key exchange messages.

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

◆ COMMUNICATOR_ADDRESS_PREFIX

#define COMMUNICATOR_ADDRESS_PREFIX   "tcp"

Address prefix used by the communicator.

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

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-tcp"

Configuration section used by the communicator.

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

Function Documentation

◆ listen_cb()

static void listen_cb ( void *  cls)
static

We have been notified that our listen socket has something to read.

Do the read and reschedule this function to be called again once more is available.

Parameters
clsNULL

Do the read and reschedule this function to be called again once more is available.

Parameters
clsListenTask with listening socket and task

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

3276{
3277 struct sockaddr_storage in;
3278 socklen_t addrlen;
3279 struct GNUNET_NETWORK_Handle *sock;
3280 struct ListenTask *lt;
3281 struct sockaddr *in_addr;
3282
3284 "listen_cb\n");
3285
3286 lt = cls;
3287
3288 lt->listen_task = NULL;
3289 GNUNET_assert (NULL != lt->listen_sock);
3290 addrlen = sizeof(in);
3291 memset (&in, 0, sizeof(in));
3293 (struct sockaddr*) &in,
3294 &addrlen);
3295 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3296 return; /* system limit reached, wait until connection goes down */
3298 lt->listen_sock,
3299 &listen_cb,
3300 lt);
3301 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3302 return;
3303 if (NULL == sock)
3304 {
3306 return;
3307 }
3308 in_addr = GNUNET_memdup (&in, addrlen);
3309 create_proto_queue (sock, in_addr, addrlen);
3310}

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 init_socket(), listen_cb(), and queue_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eddsa_priv_to_hpke_key()

static void eddsa_priv_to_hpke_key ( const struct GNUNET_CRYPTO_EddsaPrivateKey edpk,
struct GNUNET_CRYPTO_HpkePrivateKey pk 
)
static

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

948{
950 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
951 key.eddsa_key = *edpk;
953 pk);
954}

References GNUNET_CRYPTO_hpke_sk_to_x25519(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, key, and pk.

Referenced by setup_in_cipher_elligator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eddsa_pub_to_hpke_key()

static void eddsa_pub_to_hpke_key ( const struct GNUNET_CRYPTO_EddsaPublicKey edpk,
struct GNUNET_CRYPTO_HpkePublicKey pk 
)
static

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

960{
962 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
963 key.eddsa_key = *edpk;
965}

References GNUNET_CRYPTO_hpke_pk_to_x25519(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, key, and pk.

Referenced by mq_init(), and proto_read_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_destroy()

static void queue_destroy ( struct Queue queue)
static

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

Parameters
queuequeue to close down

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

977{
978 struct ListenTask *lt = NULL;
979 struct GNUNET_HashCode h_sock;
980 int sockfd;
981
982 if (NULL != queue->listen_sock)
983 {
984 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
985 GNUNET_CRYPTO_hash (&sockfd,
986 sizeof(int),
987 &h_sock);
988
990 }
991
993 "Disconnecting queue for peer `%s'\n",
994 GNUNET_i2s (&queue->target));
995 if (NULL != queue->rekey_monotime_sc)
996 {
997 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
998 queue->rekey_monotime_sc = NULL;
999 }
1000 if (NULL != queue->handshake_monotime_sc)
1001 {
1002 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
1003 queue->handshake_monotime_sc = NULL;
1004 }
1005 if (NULL != queue->handshake_ack_monotime_sc)
1006 {
1007 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
1008 queue->handshake_ack_monotime_sc = NULL;
1009 }
1010 if (NULL != queue->rekey_monotime_get)
1011 {
1012 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1013 queue->rekey_monotime_get = NULL;
1014 }
1015 if (NULL != queue->handshake_monotime_get)
1016 {
1017 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
1018 queue->handshake_monotime_get = NULL;
1019 }
1020 if (NULL != queue->handshake_ack_monotime_get)
1021 {
1022 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1023 queue->handshake_ack_monotime_get = NULL;
1024 }
1025 if (NULL != queue->qh)
1026 {
1028 queue->qh = NULL;
1029 }
1031 GNUNET_YES ==
1034 "# queues active",
1036 GNUNET_NO);
1037 if (NULL != queue->read_task)
1038 {
1039 GNUNET_SCHEDULER_cancel (queue->read_task);
1040 queue->read_task = NULL;
1041 }
1042 if (NULL != queue->write_task)
1043 {
1044 GNUNET_SCHEDULER_cancel (queue->write_task);
1045 queue->write_task = NULL;
1046 }
1048 {
1050 "closing socket failed\n");
1051 }
1052 gcry_cipher_close (queue->in_cipher);
1053 gcry_cipher_close (queue->out_cipher);
1054 GNUNET_free (queue->address);
1055 if (0 != queue->backpressure)
1056 queue->destroyed = GNUNET_YES;
1057 else
1059
1060 if (NULL == lt)
1061 return;
1062
1063 if ((! shutdown_running) && (NULL == lt->listen_task))
1064 {
1066 "add read net listen\n");
1069 lt->listen_sock,
1070 &listen_cb,
1071 lt);
1072 }
1073 else
1074 GNUNET_free (lt);
1075}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_hmac()

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

Compute mac over buf, and ratched the hmac_secret.

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

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

1091{
1092 struct GNUNET_HashCode mac;
1093
1094 GNUNET_CRYPTO_hmac (hmac_secret,
1095 buf,
1096 buf_size,
1097 &mac);
1098 /* truncate to `struct GNUNET_ShortHashCode` */
1099 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1100 /* ratchet hmac key */
1101 GNUNET_CRYPTO_hash (hmac_secret,
1102 sizeof(struct GNUNET_HashCode),
1103 (struct GNUNET_HashCode*) hmac_secret);
1104}

References GNUNET_CRYPTO_hash(), and GNUNET_CRYPTO_hmac().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_finish()

static void queue_finish ( struct Queue queue)
static

Append a 'finish' message to the outgoing transmission.

Once the finish has been transmitted, destroy the queue.

Parameters
queuequeue to shut down nicely

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

1115{
1116 struct TCPFinish fin;
1117
1118 memset (&fin, 0, sizeof(fin));
1119 fin.header.size = htons (sizeof(fin));
1120 fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
1121 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1122 /* if there is any message left in pwrite_buf, we
1123 overwrite it (possibly dropping the last message
1124 from CORE hard here) */
1125 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1126 queue->pwrite_off = sizeof(fin);
1127 /* This flag will ensure that #queue_write() no longer
1128 notifies CORE about the possibility of sending
1129 more data, and that #queue_write() will call
1130 #queue_destroy() once the @c fin was fully written. */
1131 queue->finishing = GNUNET_YES;
1132}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read()

static void queue_read ( void *  cls)
static

Queue read task.

If we hit the timeout, disconnect it

Parameters
clsthe struct Queue * to disconnect

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

2210{
2211 struct Queue *queue = cls;
2212 struct GNUNET_TIME_Relative left;
2213 ssize_t rcvd;
2214
2215 queue->read_task = NULL;
2216 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2217 &queue->cread_buf[queue->cread_off],
2218 BUF_SIZE - queue->cread_off);
2220 "Received %zd bytes from TCP queue\n", rcvd);
2221 if (-1 == rcvd)
2222 {
2223 if ((EAGAIN != errno) && (EINTR != errno))
2224 {
2227 return;
2228 }
2229 /* try again */
2230 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2231 if (0 != left.rel_value_us)
2232 {
2233 queue->read_task =
2235 return;
2236 }
2238 "Queue %p was idle for %s, disconnecting\n",
2239 queue,
2242 GNUNET_YES));
2244 return;
2245 }
2246 if (0 == rcvd)
2247 {
2248 /* Orderly shutdown of connection */
2250 "Socket for queue %p seems to have been closed\n", queue);
2252 return;
2253 }
2254 queue->timeout =
2256 queue->cread_off += rcvd;
2257 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2258 (queue->cread_off > 0))
2259 {
2260 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2261 queue->cread_off);
2262 size_t done;
2263 size_t total;
2264 size_t old_pread_off = queue->pread_off;
2265
2266 GNUNET_assert (0 ==
2267 gcry_cipher_decrypt (queue->in_cipher,
2268 &queue->pread_buf[queue->pread_off],
2269 max,
2270 queue->cread_buf,
2271 max));
2272 queue->pread_off += max;
2273 total = 0;
2274 while (0 != (done = try_handle_plaintext (queue)))
2275 {
2276 /* 'done' bytes of plaintext were used, shift buffer */
2277 GNUNET_assert (done <= queue->pread_off);
2278 /* NOTE: this memmove() could possibly sometimes be
2279 avoided if we pass 'total' into try_handle_plaintext()
2280 and use it at an offset into the buffer there! */
2281 memmove (queue->pread_buf,
2282 &queue->pread_buf[done],
2283 queue->pread_off - done);
2284 queue->pread_off -= done;
2285 total += done;
2286 /* The last plaintext was a rekey, abort for now */
2287 if (GNUNET_YES == queue->rekeyed)
2288 break;
2289 }
2290 /* when we encounter a rekey message, the decryption above uses the
2291 wrong key for everything after the rekey; in that case, we have
2292 to re-do the decryption at 'total' instead of at 'max'.
2293 However, we have to take into account that the plaintext buffer may have
2294 already contained data and not jumped too far ahead in the ciphertext.
2295 If there is no rekey and the last message is incomplete (max > total),
2296 it is safe to keep the decryption so we shift by 'max' */
2297 if (GNUNET_YES == queue->rekeyed)
2298 {
2299 max = total - old_pread_off;
2300 queue->rekeyed = GNUNET_NO;
2301 queue->pread_off = 0;
2302 }
2303 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2304 queue->cread_off -= max;
2305 }
2306 if (BUF_SIZE == queue->cread_off)
2307 return; /* buffer full, suspend reading */
2308 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2309 if (0 != left.rel_value_us)
2310 {
2311 if (max_queue_length > queue->backpressure)
2312 {
2313 /* continue reading */
2314 queue->read_task =
2316 }
2317 return;
2318 }
2320 "Queue %p was idle for %s, disconnecting\n",
2321 queue,
2324 GNUNET_YES));
2326}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_read_finished_cb()

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

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

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

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

1153{
1154 struct Queue *queue = cls;
1155 if (GNUNET_OK != success)
1157 "# messages lost in communicator API towards CORE",
1158 1,
1159 GNUNET_NO);
1160 if (NULL == queue)
1161 return;
1162
1164 "backpressure %u\n",
1165 queue->backpressure);
1166
1167 queue->backpressure--;
1168 /* handle deferred queue destruction */
1169 if ((queue->destroyed) && (0 == queue->backpressure))
1170 {
1172 return;
1173 }
1174 else if (GNUNET_YES != queue->destroyed)
1175 {
1176 queue->timeout =
1178 );
1179 /* possibly unchoke reading, now that CORE made progress */
1180 if (NULL == queue->read_task)
1181 queue->read_task =
1183 queue->timeout),
1184 queue->sock,
1185 &queue_read,
1186 queue);
1187 }
1188}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pass_plaintext_to_core()

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

We received plaintext_len bytes of plaintext on queue.

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

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

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

1204{
1205 const struct GNUNET_MessageHeader *hdr = plaintext;
1206 int ret;
1207
1209 "pass message from %s to core\n",
1210 GNUNET_i2s (&queue->target));
1211
1212 if (ntohs (hdr->size) != plaintext_len)
1213 {
1214 /* NOTE: If we ever allow multiple CORE messages in one
1215 BOX, this will have to change! */
1216 GNUNET_break (0);
1217 return;
1218 }
1220 &queue->target,
1221 hdr,
1224 queue);
1226 "passed to core\n");
1227 if (GNUNET_OK == ret)
1228 queue->backpressure++;
1229 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1230 if (GNUNET_SYSERR == ret)
1232 "# bytes lost due to CORE not running",
1233 plaintext_len,
1234 GNUNET_NO);
1235}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_cipher()

static void setup_cipher ( const struct GNUNET_ShortHashCode prk,
const struct GNUNET_PeerIdentity pid,
gcry_cipher_hd_t *  cipher,
struct GNUNET_CRYPTO_AuthKey hmac_key 
)
static

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

Parameters
dhshared secret
piddecrypting peer's identity
[out]ciphercipher to initialize
[out]hmac_keyHMAC key to initialize

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

1252{
1253 char key[256 / 8];
1254 char ctr[128 / 8];
1255
1256 GNUNET_assert (0 == gcry_cipher_open (cipher,
1257 GCRY_CIPHER_AES256 /* low level: go for speed */
1258 ,
1259 GCRY_CIPHER_MODE_CTR,
1260 0 /* flags */));
1263 key,
1264 sizeof(key),
1265 prk,
1266 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-key"))
1267 );
1268 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1271 ctr,
1272 sizeof(ctr),
1273 prk,
1274 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-ctr"))
1275 );
1276 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1279 hmac_key,
1280 sizeof(struct GNUNET_HashCode),
1281 prk,
1282 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-hmac")));
1283}

References GNUNET_assert, GNUNET_CRYPTO_hkdf_expand, GNUNET_CRYPTO_kdf_arg_string, GNUNET_YES, and key.

Referenced by setup_in_cipher(), setup_in_cipher_elligator(), and setup_out_cipher().

Here is the caller graph for this function:

◆ rekey_monotime_store_cb()

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

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

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

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

1293{
1294 struct Queue *queue = cls;
1295 if (GNUNET_OK != success)
1296 {
1298 "Failed to store rekey monotonic time in PEERSTORE!\n");
1299 }
1300 queue->rekey_monotime_sc = NULL;
1301 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1302}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_iteration_next(), and queue().

Referenced by rekey_monotime_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rekey_monotime_cb()

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

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where found.

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

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

1316{
1317 struct Queue *queue = cls;
1318 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1319 struct GNUNET_TIME_Absolute mt;
1320 const struct GNUNET_PeerIdentity *pid;
1321 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1322
1323 (void) emsg;
1324
1325 rekey_monotonic_time = &queue->rekey_monotonic_time;
1326 pid = &queue->target;
1327 if (NULL == record)
1328 {
1329 queue->rekey_monotime_get = NULL;
1330 return;
1331 }
1332 if (sizeof(*mtbe) != record->value_size)
1333 {
1334 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1335 GNUNET_break (0);
1336 return;
1337 }
1338 mtbe = record->value;
1339 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1340 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1341 queue->rekey_monotonic_time).abs_value_us)
1342 {
1344 "Queue from %s dropped, rekey monotime in the past\n",
1345 GNUNET_i2s (&queue->target));
1346 GNUNET_break (0);
1347 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1348 queue->rekey_monotime_get = NULL;
1349 // FIXME: Why should we try to gracefully finish here??
1351 return;
1352 }
1353 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1354 "transport_tcp_communicator",
1355 pid,
1357 rekey_monotonic_time,
1358 sizeof(*
1359 rekey_monotonic_time),
1363 queue);
1364}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_in_cipher_elligator()

static void setup_in_cipher_elligator ( const struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct Queue queue 
)
static

Setup cipher of queue for decryption from an elligator representative.

Parameters
ephemeralephemeral key we received from the other peer (elligator representative)
[in,out]queuequeue to initialize decryption cipher for

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

1377{
1378 const struct GNUNET_PeerIdentity *my_identity;
1380 struct GNUNET_CRYPTO_HpkePrivateKey my_hpke_key;
1381 struct GNUNET_ShortHashCode k;
1382
1386
1387 eddsa_priv_to_hpke_key (my_private_key, &my_hpke_key);
1388
1390 c,
1391 &k);
1392 setup_cipher (&k, my_identity, &queue->in_cipher, &queue->in_hmac);
1393}

References eddsa_priv_to_hpke_key(), GNUNET_assert, GNUNET_CRYPTO_hpke_elligator_kem_decaps(), GNUNET_PILS_get_identity(), GNUNET_PILS_key_ring_get_private_key(), key_ring, my_identity, my_private_key, pils, queue(), and setup_cipher().

Referenced by proto_read_kx(), and queue_read_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_in_cipher()

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

Setup cipher of queue for decryption.

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

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

References GNUNET_assert, GNUNET_CRYPTO_eddsa_kem_decaps(), GNUNET_PILS_get_identity(), GNUNET_PILS_key_ring_get_private_key(), key_ring, my_identity, my_private_key, pils, queue(), and setup_cipher().

Referenced by do_rekey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_rekey()

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

Handle rekey message on queue.

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

Parameters
queuethe queue rekey was received on
rekeythe rekey message

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

1429{
1430 const struct GNUNET_PeerIdentity *my_identity;
1431 struct TcpRekeySignature thp;
1432
1435
1436 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY);
1437 thp.purpose.size = htonl (sizeof(thp));
1439 "do_rekey size %u\n",
1440 thp.purpose.size);
1441 thp.sender = queue->target;
1443 "sender %s\n",
1444 GNUNET_p2s (&thp.sender.public_key));
1446 "sender %s\n",
1447 GNUNET_p2s (&queue->target.public_key));
1448 thp.receiver = *my_identity;
1450 "receiver %s\n",
1451 GNUNET_p2s (&thp.receiver.public_key));
1452 thp.ephemeral = rekey->ephemeral;
1454 "ephemeral %s\n",
1455 GNUNET_e2s ((struct GNUNET_CRYPTO_EcdhePublicKey*) &thp.ephemeral)
1456 );
1457 thp.monotonic_time = rekey->monotonic_time;
1459 "time %s\n",
1461 GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1462 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1463 if (GNUNET_OK !=
1466 &thp,
1467 &rekey->sender_sig,
1468 &queue->target.public_key))
1469 {
1470 GNUNET_break (0);
1471 // FIXME Why should we try to gracefully finish here?
1473 return;
1474 }
1475 queue->rekey_monotonic_time = rekey->monotonic_time;
1476 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1477 "transport_tcp_communicator",
1478 &queue->target,
1480 &
1482 queue);
1483 gcry_cipher_close (queue->in_cipher);
1484 queue->rekeyed = GNUNET_YES;
1485 setup_in_cipher (&rekey->ephemeral, queue);
1486}

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_PILS_get_identity(), 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, pils, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_SignaturePurpose::purpose, TcpRekeySignature::purpose, queue(), queue_finish(), TcpRekeySignature::receiver, rekey_monotime_cb(), TcpRekeySignature::sender, TCPRekey::sender_sig, setup_in_cipher(), and GNUNET_CRYPTO_SignaturePurpose::size.

Referenced by try_handle_plaintext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_store_cb()

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

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

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

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

1496{
1497 struct Queue *queue = cls;
1498
1499 if (GNUNET_OK != success)
1500 {
1502 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1503 }
1504 queue->handshake_ack_monotime_sc = NULL;
1505 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1506}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_iteration_next(), and queue().

Referenced by handshake_ack_monotime_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_ack_monotime_cb()

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

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK where found.

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

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

1520{
1521 struct Queue *queue = cls;
1522 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1523 struct GNUNET_TIME_Absolute mt;
1524 const struct GNUNET_PeerIdentity *pid;
1525 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1526
1527 (void) emsg;
1528
1529 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1530 pid = &queue->target;
1531 if (NULL == record)
1532 {
1533 queue->handshake_ack_monotime_get = NULL;
1534 return;
1535 }
1536 if (sizeof(*mtbe) != record->value_size)
1537 {
1538 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1539 GNUNET_break (0);
1540 return;
1541 }
1542 mtbe = record->value;
1543 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1544 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
1545 queue->handshake_ack_monotonic_time).abs_value_us)
1546 {
1548 "Queue from %s dropped, handshake ack monotime in the past\n",
1549 GNUNET_i2s (&queue->target));
1550 GNUNET_break (0);
1551 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1552 queue->handshake_ack_monotime_get = NULL;
1553 // FIXME: Why should we try to gracefully finish here?
1555 return;
1556 }
1557 queue->handshake_ack_monotime_sc =
1559 "transport_tcp_communicator",
1560 pid,
1562 handshake_ack_monotonic_time,
1563 sizeof(*handshake_ack_monotonic_time),
1567 queue);
1568}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_challenge()

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

Sending challenge with TcpConfirmationAck back to sender of ephemeral key.

Parameters
tcThe TCPConfirmation originally send.
queueThe queue context.

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

1580{
1581 const struct GNUNET_PeerIdentity *my_identity;
1583 struct TCPConfirmationAck tca;
1584 struct TcpHandshakeAckSignature thas;
1585
1589
1591 "sending challenge\n");
1592
1593 tca.header.type = ntohs (
1595 tca.header.size = ntohs (sizeof(tca));
1596 tca.challenge = challenge;
1597 tca.sender = *my_identity;
1598 tca.monotonic_time =
1600 thas.purpose.purpose = htonl (
1602 thas.purpose.size = htonl (sizeof(thas));
1603 thas.sender = *my_identity;
1604 thas.receiver = queue->target;
1605 thas.monotonic_time = tca.monotonic_time;
1606 thas.challenge = tca.challenge;
1608 &thas,
1609 &tca.sender_sig);
1610 GNUNET_assert (0 ==
1611 gcry_cipher_encrypt (queue->out_cipher,
1612 &queue->cwrite_buf[queue->cwrite_off],
1613 sizeof(tca),
1614 &tca,
1615 sizeof(tca)));
1616 queue->cwrite_off += sizeof(tca);
1618 "sending challenge done\n");
1619}

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_PILS_get_identity(), GNUNET_PILS_key_ring_get_private_key(), GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), TCPConfirmationAck::header, key_ring, TcpHandshakeAckSignature::monotonic_time, TCPConfirmationAck::monotonic_time, my_identity, my_private_key, pils, GNUNET_CRYPTO_SignaturePurpose::purpose, TcpHandshakeAckSignature::purpose, queue(), TcpHandshakeAckSignature::receiver, TcpHandshakeAckSignature::sender, TCPConfirmationAck::sender, TCPConfirmationAck::sender_sig, GNUNET_MessageHeader::size, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_MessageHeader::type.

Referenced by queue_read_kx(), and try_handle_plaintext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_out_cipher()

static void setup_out_cipher ( struct Queue queue,
struct GNUNET_ShortHashCode dh 
)
static

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

Parameters
queuequeue to setup outgoing (encryption) cipher for

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

1630{
1631 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1633 queue->rekey_left_bytes =
1635}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inject_rekey()

static void inject_rekey ( struct Queue queue)
static

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

Parameters
queuequeue to perform rekeying on

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

1646{
1647 const struct GNUNET_PeerIdentity *my_identity;
1649 struct TCPRekey rekey;
1650 struct TcpRekeySignature thp;
1651 struct GNUNET_ShortHashCode k;
1652
1656
1657 GNUNET_assert (0 == queue->pwrite_off);
1658 memset (&rekey, 0, sizeof(rekey));
1659 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1660 &k);
1661 rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1662 rekey.header.size = ntohs (sizeof(rekey));
1663 rekey.monotonic_time =
1665 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY);
1666 thp.purpose.size = htonl (sizeof(thp));
1668 "inject_rekey size %u\n",
1669 thp.purpose.size);
1670 thp.sender = *my_identity;
1672 "sender %s\n",
1673 GNUNET_p2s (&thp.sender.public_key));
1674 thp.receiver = queue->target;
1676 "receiver %s\n",
1677 GNUNET_p2s (&thp.receiver.public_key));
1678 thp.ephemeral = rekey.ephemeral;
1680 "ephemeral %s\n",
1681 GNUNET_e2s ((struct GNUNET_CRYPTO_EcdhePublicKey*) &thp.ephemeral)
1682 );
1683 thp.monotonic_time = rekey.monotonic_time;
1685 "time %s\n",
1687 GNUNET_TIME_absolute_ntoh (thp.monotonic_time)));
1689 &thp,
1690 &rekey.sender_sig);
1691 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1692 /* Encrypt rekey message with 'old' cipher */
1693 GNUNET_assert (0 ==
1694 gcry_cipher_encrypt (queue->out_cipher,
1695 &queue->cwrite_buf[queue->cwrite_off],
1696 sizeof(rekey),
1697 &rekey,
1698 sizeof(rekey)));
1699 queue->cwrite_off += sizeof(rekey);
1700 /* Setup new cipher for successive messages */
1701 gcry_cipher_close (queue->out_cipher);
1702 setup_out_cipher (queue, &k);
1703}

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_PILS_get_identity(), GNUNET_PILS_key_ring_get_private_key(), 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, key_ring, TCPRekey::monotonic_time, TcpRekeySignature::monotonic_time, my_identity, my_private_key, pils, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_SignaturePurpose::purpose, TcpRekeySignature::purpose, queue(), TcpRekeySignature::receiver, TcpRekeySignature::sender, TCPRekey::sender_sig, setup_out_cipher(), GNUNET_MessageHeader::size, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_MessageHeader::type.

Referenced by queue_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pending_reversals_delete_it()

static int pending_reversals_delete_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

1710{
1711 struct PendingReversal *pending_reversal = value;
1712 (void) cls;
1713
1714 if (NULL != pending_reversal->timeout_task)
1715 {
1716 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1717 pending_reversal->timeout_task = NULL;
1718 }
1721 key,
1722 pending_reversal));
1723 GNUNET_free (pending_reversal->in);
1724 GNUNET_free (pending_reversal);
1725 return GNUNET_OK;
1726}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_and_remove_pending_reversal()

static void check_and_remove_pending_reversal ( struct sockaddr *  in,
sa_family_t  sa_family,
struct GNUNET_PeerIdentity sender 
)
static

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

1732{
1733 if (AF_INET == sa_family)
1734 {
1735 struct PendingReversal *pending_reversal;
1736 struct GNUNET_HashCode key;
1737 struct sockaddr_in *natted_address;
1738
1739 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1740 natted_address->sin_port = 0;
1741 GNUNET_CRYPTO_hash (natted_address,
1742 sizeof(struct sockaddr),
1743 &key);
1744
1746 &key);
1747 if (NULL != pending_reversal && (NULL == sender ||
1748 0 != memcmp (sender,
1749 &pending_reversal->target,
1750 sizeof(struct
1752 {
1754 "Removing invalid pending reversal for `%s'at `%s'\n",
1755 GNUNET_i2s (&pending_reversal->target),
1756 GNUNET_a2s (in, sizeof (struct sockaddr)));
1757 pending_reversals_delete_it (NULL, &key, pending_reversal);
1758 }
1759 GNUNET_free (natted_address);
1760 }
1761}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_proto_queue()

static void free_proto_queue ( struct ProtoQueue pq)
static

Closes socket and frees memory associated with pq.

Parameters
pqproto queue to free

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

1771{
1772 if (NULL != pq->listen_sock)
1773 {
1775 pq->listen_sock = NULL;
1776 }
1777 if (NULL != pq->read_task)
1778 {
1780 pq->read_task = NULL;
1781 }
1782 if (NULL != pq->write_task)
1783 {
1785 pq->write_task = NULL;
1786 }
1787 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1789 GNUNET_free (pq->address);
1791 GNUNET_free (pq);
1792}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proto_queue_write()

static void proto_queue_write ( void *  cls)
static

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

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

Parameters
clsa struct ProtoQueue

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

1803{
1804 struct ProtoQueue *pq = cls;
1805 ssize_t sent;
1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1807 pq->write_task = NULL;
1808 if (0 != pq->write_off)
1809 {
1810 sent = GNUNET_NETWORK_socket_send (pq->sock,
1811 pq->write_buf,
1812 pq->write_off);
1814 "Sent %lu bytes to TCP queue\n", sent);
1815 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1816 {
1818 free_proto_queue (pq);
1819 return;
1820 }
1821 if (sent > 0)
1822 {
1823 size_t usent = (size_t) sent;
1824 pq->write_off -= usent;
1825 memmove (pq->write_buf,
1826 &pq->write_buf[usent],
1827 pq->write_off);
1828 }
1829 }
1830 /* do we care to write more? */
1831 if ((0 < pq->write_off))
1832 pq->write_task =
1834 pq->sock,
1836 pq);
1837}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_write()

static void queue_write ( void *  cls)
static

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

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

Parameters
clsa struct Queue

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

1848{
1849 struct Queue *queue = cls;
1850 ssize_t sent;
1851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1852 queue->write_task = NULL;
1853 if (0 != queue->cwrite_off)
1854 {
1855 sent = GNUNET_NETWORK_socket_send (queue->sock,
1856 queue->cwrite_buf,
1857 queue->cwrite_off);
1859 "Sent %lu bytes to TCP queue\n", sent);
1860 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1861 {
1864 return;
1865 }
1866 if (sent > 0)
1867 {
1868 size_t usent = (size_t) sent;
1869 queue->cwrite_off -= usent;
1870 memmove (queue->cwrite_buf,
1871 &queue->cwrite_buf[usent],
1872 queue->cwrite_off);
1873 queue->timeout =
1876 }
1877 }
1878 {
1879 /* can we encrypt more? (always encrypt full messages, needed
1880 such that #mq_cancel() can work!) */
1881 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1882 - (queue->cwrite_off
1883 + queue->pwrite_off
1884 + sizeof (struct TCPRekey)));
1885 if (we_do_not_need_to_rekey &&
1886 (queue->pwrite_off > 0) &&
1887 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1888 {
1890 "Encrypting %lu bytes\n", queue->pwrite_off);
1891 GNUNET_assert (0 ==
1892 gcry_cipher_encrypt (queue->out_cipher,
1893 &queue->cwrite_buf[queue->cwrite_off],
1894 queue->pwrite_off,
1895 queue->pwrite_buf,
1896 queue->pwrite_off));
1897 if (queue->rekey_left_bytes > queue->pwrite_off)
1898 queue->rekey_left_bytes -= queue->pwrite_off;
1899 else
1900 queue->rekey_left_bytes = 0;
1901 queue->cwrite_off += queue->pwrite_off;
1902 queue->pwrite_off = 0;
1903 }
1904 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1905 if (((0 == queue->rekey_left_bytes) ||
1907 queue->rekey_time).rel_value_us)) &&
1908 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1909 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1910 {
1912 }
1913 }
1914 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1915 (GNUNET_YES == queue->mq_awaits_continue))
1916 {
1917 queue->mq_awaits_continue = GNUNET_NO;
1919 }
1920 /* did we just finish writing 'finish'? */
1921 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1922 {
1924 "Finishing queue\n");
1926 return;
1927 }
1928 /* do we care to write more? */
1929 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1930 queue->write_task =
1932 queue->sock,
1933 &queue_write,
1934 queue);
1935}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_handle_plaintext()

static size_t try_handle_plaintext ( struct Queue queue)
static

Test if we have received a full message in plaintext.

If so, handle it.

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

Once we received this ack, we consider this a verified connection. FIXME: I am not sure this logic is sane here.

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

1947{
1948 const struct GNUNET_MessageHeader *hdr;
1949 const struct TCPConfirmationAck *tca;
1950 const struct TCPBox *box;
1951 const struct TCPRekey *rekey;
1952 const struct TCPFinish *fin;
1953 struct TCPRekey rekeyz;
1954 struct TCPFinish finz;
1955 struct GNUNET_ShortHashCode tmac;
1956 uint16_t type;
1957 size_t size = 0;
1958 struct TcpHandshakeAckSignature thas;
1959 const struct GNUNET_PeerIdentity *my_identity;
1960 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1961
1963 "try handle plaintext!\n");
1964
1965 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1966 if ((sizeof(*hdr) > queue->pread_off))
1967 {
1969 "Handling plaintext, not even a header!\n");
1970 return 0; /* not even a header */
1971 }
1972
1973 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1975 {
1977 "Already received data of size %lu bigger than KX size %lu!\n",
1978 queue->unverified_size,
1980 GNUNET_break_op (0);
1982 return 0;
1983 }
1984
1985 type = ntohs (hdr->type);
1986 switch (type)
1987 {
1989 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1991 "start processing ack\n");
1992 if (sizeof(*tca) > queue->pread_off)
1993 {
1995 "Handling plaintext size of tca greater than pread offset.\n")
1996 ;
1997 return 0;
1998 }
1999 if (ntohs (hdr->size) != sizeof(*tca))
2000 {
2002 "Handling plaintext size does not match message type.\n");
2003 GNUNET_break_op (0);
2005 return 0;
2006 }
2007
2010
2011 thas.purpose.purpose = htonl (
2013 thas.purpose.size = htonl (sizeof(thas));
2014 thas.sender = tca->sender;
2015 thas.receiver = *my_identity;
2016 thas.monotonic_time = tca->monotonic_time;
2017 thas.challenge = tca->challenge;
2018
2021 &thas,
2022 &tca->sender_sig,
2023 &tca->sender.public_key))
2024 {
2026 "Verification of signature failed!\n");
2027 GNUNET_break (0);
2029 return 0;
2030 }
2031 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
2032 {
2034 "Challenge in TCPConfirmationAck not correct!\n");
2035 GNUNET_break (0);
2037 return 0;
2038 }
2039
2040 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
2041 peerstore,
2042 "transport_tcp_communicator",
2043 &queue->target,
2046 queue);
2047
2049 "Handling plaintext, ack processed!\n");
2050
2052 {
2053 send_challenge (queue->challenge_received, queue);
2054 queue->write_task =
2056 queue->sock,
2057 &queue_write,
2058 queue);
2059 }
2060 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2061 {
2063 queue->address->sa_family, NULL);
2064 }
2065
2070 queue->initial_core_kx_done = GNUNET_YES;
2071
2072 {
2073 char *foreign_addr;
2074
2075 switch (queue->address->sa_family)
2076 {
2077 case AF_INET:
2078 GNUNET_asprintf (&foreign_addr,
2079 "%s-%s",
2081 GNUNET_a2s (queue->address, queue->address_len));
2082 break;
2083
2084 case AF_INET6:
2085 GNUNET_asprintf (&foreign_addr,
2086 "%s-%s",
2088 GNUNET_a2s (queue->address, queue->address_len));
2089 break;
2090
2091 default:
2092 GNUNET_assert (0);
2093 }
2095 &queue->target,
2096 foreign_addr,
2097 UINT16_MAX, /* no MTU */
2099 0, /* Priority */
2100 queue->nt,
2101 queue->cs,
2102 queue->mq);
2103
2104 GNUNET_free (foreign_addr);
2105 }
2106
2107 size = ntohs (hdr->size);
2108 break;
2110 /* Special case: header size excludes box itself! */
2111 box = (const struct TCPBox *) queue->pread_buf;
2112 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2113 return 0;
2114 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2115 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2116 {
2117 GNUNET_break_op (0);
2119 return 0;
2120 }
2121 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2122 size = ntohs (hdr->size) + sizeof(*box);
2124 "Handling plaintext, box processed!\n");
2126 "# bytes decrypted with BOX",
2127 size,
2128 GNUNET_NO);
2130 "# messages decrypted with BOX",
2131 1,
2132 GNUNET_NO);
2133 break;
2134
2136 rekey = (const struct TCPRekey *) queue->pread_buf;
2137 if (sizeof(*rekey) > queue->pread_off)
2138 return 0;
2139 if (ntohs (hdr->size) != sizeof(*rekey))
2140 {
2141 GNUNET_break_op (0);
2143 return 0;
2144 }
2145 rekeyz = *rekey;
2146 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2147 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2148 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2149 {
2150 GNUNET_break_op (0);
2152 return 0;
2153 }
2154 do_rekey (queue, rekey);
2155 size = ntohs (hdr->size);
2157 "Handling plaintext, rekey processed!\n");
2159 "# rekeying successful",
2160 1,
2161 GNUNET_NO);
2162 break;
2163
2165 fin = (const struct TCPFinish *) queue->pread_buf;
2166 if (sizeof(*fin) > queue->pread_off)
2167 return 0;
2168 if (ntohs (hdr->size) != sizeof(*fin))
2169 {
2170 GNUNET_break_op (0);
2172 return 0;
2173 }
2174 finz = *fin;
2175 memset (&finz.hmac, 0, sizeof(finz.hmac));
2176 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2177 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2178 {
2179 GNUNET_break_op (0);
2181 return 0;
2182 }
2183 /* handle FINISH by destroying queue */
2186 "Handling plaintext, finish processed!\n");
2187 break;
2188
2189 default:
2191 "Handling plaintext, nothing processed!\n");
2192 GNUNET_break_op (0);
2194 return 0;
2195 }
2196 GNUNET_assert (0 != size);
2197 if (-1 != queue->unverified_size)
2198 queue->unverified_size += size;
2199 return size;
2200}

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_PILS_get_identity(), 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, GNUNET_TRANSPORT_CommunicatorHandle::mq, my_identity, pass_plaintext_to_core(), peerstore, pils, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_SignaturePurpose::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_SignaturePurpose::size, size, stats, type, and GNUNET_MessageHeader::type.

Referenced by queue_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v6()

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

Convert a struct sockaddr_in6 to astruct sockaddr *`.

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

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

2340{
2341 struct sockaddr *in;
2342
2343 v6.sin6_family = AF_INET6;
2344 v6.sin6_port = htons ((uint16_t) port);
2345#if HAVE_SOCKADDR_IN_SIN_LEN
2346 v6.sin6_len = sizeof(struct sockaddr_in6);
2347#endif
2348 v6.sin6_flowinfo = 0;
2349 v6.sin6_scope_id = 0;
2350 in = GNUNET_memdup (&v6, sizeof(v6));
2351 *sock_len = sizeof(struct sockaddr_in6);
2352
2353 return in;
2354}

References GNUNET_memdup, and port.

Referenced by init_socket_resolv(), run(), tcp_address_to_sockaddr(), and tcp_address_to_sockaddr_port_only().

Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_numeric_v4()

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

Convert a struct sockaddr_in4 to astruct sockaddr *`.

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

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

2368{
2369 struct sockaddr *in;
2370
2371 v4.sin_family = AF_INET;
2372 v4.sin_port = htons ((uint16_t) port);
2373#if HAVE_SOCKADDR_IN_SIN_LEN
2374 v4.sin_len = sizeof(struct sockaddr_in);
2375#endif
2376 in = GNUNET_memdup (&v4, sizeof(v4));
2377 *sock_len = sizeof(struct sockaddr_in);
2378 return in;
2379}

References GNUNET_memdup, and port.

Referenced by init_socket_resolv(), run(), tcp_address_to_sockaddr(), and tcp_address_to_sockaddr_port_only().

Here is the caller graph for this function:

◆ tcp_address_to_sockaddr_port_only()

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

Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *

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

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

2390{
2391 struct PortOnlyIpv4Ipv6 *po;
2392 struct sockaddr_in *i4;
2393 struct sockaddr_in6 *i6;
2394 socklen_t sock_len_ipv4;
2395 socklen_t sock_len_ipv6;
2396
2397 /* interpreting value as just a PORT number */
2398 if (*port > UINT16_MAX)
2399 {
2401 "BINDTO specification `%s' invalid: value too large for port\n",
2402 bindto);
2403 return NULL;
2404 }
2405
2406 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2407
2408 if (GNUNET_YES == disable_v6)
2409 {
2410 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2411 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2412 *port);
2413 po->addr_len_ipv4 = sock_len_ipv4;
2414 }
2415 else
2416 {
2417
2418 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2419 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2420 *port);
2421 po->addr_len_ipv4 = sock_len_ipv4;
2422
2423 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2424 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2425 *port);
2426
2427 po->addr_len_ipv6 = sock_len_ipv6;
2428
2429 GNUNET_free (i6);
2430 }
2431
2432 GNUNET_free (i4);
2433
2434 return po;
2435}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_address()

static char * extract_address ( const char *  bindto)
static

This Method extracts the address part of the BINDTO string.

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

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

2446{
2447 char *addr;
2448 char *start;
2449 char *token;
2450 char *cp;
2451 char *rest = NULL;
2452
2454 "extract address with bindto %s\n",
2455 bindto);
2456
2457 if (NULL == bindto)
2459 "bindto is NULL\n");
2460
2461 cp = GNUNET_strdup (bindto);
2462
2464 "extract address 2\n");
2465
2466 start = cp;
2467 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2468 {
2469 start++; /* skip over '['*/
2470 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2471 addr = GNUNET_strdup (start);
2472 }
2473 else
2474 {
2475 token = strtok_r (cp, "]", &rest);
2476 if (strlen (bindto) == strlen (token))
2477 {
2478 token = strtok_r (cp, ":", &rest);
2479 addr = GNUNET_strdup (token);
2480 }
2481 else
2482 {
2483 token++;
2484 addr = GNUNET_strdup (token);
2485 }
2486 }
2487
2489 "tcp address: %s\n",
2490 addr);
2491 GNUNET_free (cp);
2492 return addr;
2493}

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

Here is the caller graph for this function:

◆ extract_port()

static unsigned int extract_port ( const char *  addr_and_port)
static

This Method extracts the port part of the BINDTO string.

Parameters
addr_and_portString we extract the port from.
Returns
The extracted port as unsigned int.

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

2504{
2505 unsigned int port;
2506 char dummy[2];
2507 char *token;
2508 char *addr;
2509 char *colon;
2510 char *cp;
2511 char *rest = NULL;
2512
2513 if (NULL != addr_and_port)
2514 {
2515 cp = GNUNET_strdup (addr_and_port);
2516 token = strtok_r (cp, "]", &rest);
2517 if (strlen (addr_and_port) == strlen (token))
2518 {
2519 colon = strrchr (cp, ':');
2520 if (NULL == colon)
2521 {
2522 GNUNET_free (cp);
2523 return 0;
2524 }
2525 addr = colon;
2526 addr++;
2527 }
2528 else
2529 {
2530 token = strtok_r (NULL, "]", &rest);
2531 if (NULL == token)
2532 {
2533 GNUNET_free (cp);
2534 return 0;
2535 }
2536 else
2537 {
2538 addr = token;
2539 addr++;
2540 }
2541 }
2542
2543
2544 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2545 {
2546 /* interpreting value as just a PORT number */
2547 if (port > UINT16_MAX)
2548 {
2550 "Port `%u' invalid: value too large for port\n",
2551 port);
2552 GNUNET_free (cp);
2553 return 0;
2554 }
2555 }
2556 else
2557 {
2559 "BINDTO specification invalid: last ':' not followed by number\n");
2560 GNUNET_free (cp);
2561 return 0;
2562 }
2563 GNUNET_free (cp);
2564 }
2565 else
2566 {
2568 "return 0\n");
2569 /* interpret missing port as 0, aka pick any free one */
2570 port = 0;
2571 }
2572
2573 return port;
2574}

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

Referenced by run(), and tcp_address_to_sockaddr().

Here is the caller graph for this function:

◆ tcp_address_to_sockaddr()

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

Convert TCP bind specification to a struct sockaddr *

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

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

2586{
2587 struct sockaddr *in;
2588 unsigned int port;
2589 struct sockaddr_in v4;
2590 struct sockaddr_in6 v6;
2591 char *start;
2592
2593 memset (&v4, 0, sizeof(v4));
2594 start = extract_address (bindto);
2595 GNUNET_assert (NULL != start);
2597 "start %s\n",
2598 start);
2599
2601 "!bindto %s\n",
2602 bindto);
2603
2604
2605 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2606 {
2607 port = extract_port (bindto);
2608
2610 "port %u\n",
2611 port);
2612
2613 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2614 }
2615 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2616 {
2617 port = extract_port (bindto);
2618 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2619 }
2620 else
2621 {
2622 GNUNET_assert (0);
2623 }
2624
2626 return in;
2627}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send()

static void mq_send ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Signature of functions implementing the sending functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct Queue

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

2642{
2643 struct Queue *queue = impl_state;
2644 uint16_t msize = ntohs (msg->size);
2645 struct TCPBox box;
2647 "In MQ send. Queue finishing: %s; write task running: %s\n",
2648 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2649 (NULL == queue->write_task) ? "yes" : "no");
2650 GNUNET_assert (mq == queue->mq);
2651 queue->mq_awaits_continue = GNUNET_YES;
2652 if (GNUNET_YES == queue->finishing)
2653 return; /* this queue is dying, drop msg */
2654 GNUNET_assert (0 == queue->pwrite_off);
2655 box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
2656 box.header.size = htons (msize);
2657 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2658 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2659 queue->pwrite_off += sizeof(box);
2660 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2661 queue->pwrite_off += msize;
2663 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2664 GNUNET_assert (NULL != queue->sock);
2665 if (NULL == queue->write_task)
2666 queue->write_task =
2668 queue->sock,
2669 &queue_write,
2670 queue);
2671}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy()

static void mq_destroy ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Signature of functions implementing the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct Queue

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

2684{
2685 struct Queue *queue = impl_state;
2686
2687 if (mq == queue->mq)
2688 {
2689 queue->mq = NULL;
2691 }
2692}

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

Referenced by boot_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_cancel()

static void mq_cancel ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Implementation function that cancels the currently sent message.

Parameters
mqmessage queue
impl_stateour struct Queue

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

2703{
2704 struct Queue *queue = impl_state;
2705
2706 GNUNET_assert (0 != queue->pwrite_off);
2707 queue->pwrite_off = 0;
2708}

References GNUNET_assert, and queue().

Referenced by boot_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error()

static void mq_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsour struct Queue
errorerror code

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

2722{
2723 struct Queue *queue = cls;
2724
2726 "MQ error in queue to %s: %d\n",
2727 GNUNET_i2s (&queue->target),
2728 (int) error);
2730}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, queue(), and queue_finish().

Referenced by boot_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boot_queue()

static void boot_queue ( struct Queue queue)
static

Add the given queue to our internal data structure.

Setup the MQ processing and inform transport that the queue is ready. Must be called after the KX for outgoing messages has been bootstrapped.

Parameters
queuequeue to boot

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

2742{
2743 queue->nt =
2744 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2746 queue_map,
2747 &queue->key,
2748 queue,
2751 "# queues active",
2753 GNUNET_NO);
2754 queue->timeout =
2757 &mq_destroy,
2758 &mq_cancel,
2759 queue,
2760 NULL,
2761 &mq_error,
2762 queue);
2763}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_kx()

static void transmit_kx ( struct Queue queue,
const struct GNUNET_CRYPTO_HpkeEncapsulation c 
)
static

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

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

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

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

2779{
2780 const struct GNUNET_PeerIdentity *my_identity;
2782 struct TcpHandshakeSignature ths;
2783 struct TCPConfirmation tc;
2784
2788
2789 memcpy (queue->cwrite_buf, c, sizeof(*c));
2790 queue->cwrite_off = sizeof(*c);
2791 /* compute 'tc' and append in encrypted format to cwrite_buf */
2792 tc.sender = *my_identity;
2793 tc.monotonic_time =
2795 GNUNET_CRYPTO_random_block (&tc.challenge,
2796 sizeof(tc.challenge));
2797 ths.purpose.purpose = htonl (
2799 ths.purpose.size = htonl (sizeof(ths));
2800 ths.sender = *my_identity;
2801 ths.receiver = queue->target;
2802 ths.ephemeral = *c;
2803 ths.monotonic_time = tc.monotonic_time;
2804 ths.challenge = tc.challenge;
2806 &ths,
2807 &tc.sender_sig);
2808 GNUNET_assert (0 ==
2809 gcry_cipher_encrypt (queue->out_cipher,
2810 &queue->cwrite_buf[queue->cwrite_off],
2811 sizeof(tc),
2812 &tc,
2813 sizeof(tc)));
2814 queue->challenge = tc.challenge;
2815 queue->cwrite_off += sizeof(tc);
2816
2818 "handshake written\n");
2819}

References cfg, TcpHandshakeSignature::challenge, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_random_block(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_PILS_get_identity(), GNUNET_PILS_key_ring_get_private_key(), GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), key_ring, TcpHandshakeSignature::monotonic_time, my_identity, my_private_key, pils, GNUNET_CRYPTO_SignaturePurpose::purpose, TcpHandshakeSignature::purpose, queue(), TcpHandshakeSignature::receiver, TcpHandshakeSignature::sender, GNUNET_CRYPTO_SignaturePurpose::size, and tc.

Referenced by start_initial_kx_out().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_initial_kx_out()

static void start_initial_kx_out ( struct Queue queue)
static

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

Must be called first before any data is sent.

Parameters
queuethe queue to setup

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

2831{
2833 struct GNUNET_ShortHashCode k;
2834
2836 &c, &k);
2837 setup_out_cipher (queue, &k);
2838 transmit_kx (queue, &c);
2839}

References GNUNET_CRYPTO_hpke_elligator_kem_encaps(), queue(), setup_out_cipher(), and transmit_kx().

Referenced by mq_init(), and proto_read_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_monotime_store_cb()

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

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

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

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

2849{
2850 struct Queue *queue = cls;
2851 if (GNUNET_OK != success)
2852 {
2854 "Failed to store handshake monotonic time in PEERSTORE!\n");
2855 }
2856 queue->handshake_monotime_sc = NULL;
2857 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2858}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_iteration_next(), and queue().

Referenced by handshake_monotime_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handshake_monotime_cb()

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

Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE where found.

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

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

2872{
2873 struct Queue *queue = cls;
2874 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2875 struct GNUNET_TIME_Absolute mt;
2876 const struct GNUNET_PeerIdentity *pid;
2877 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2878
2879 (void) emsg;
2880
2881 handshake_monotonic_time = &queue->handshake_monotonic_time;
2882 pid = &queue->target;
2884 "tcp handshake with us %s\n",
2886 if (NULL == record)
2887 {
2888 queue->handshake_monotime_get = NULL;
2889 return;
2890 }
2892 "tcp handshake from peer %s\n",
2893 GNUNET_i2s (pid));
2894 if (sizeof(*mtbe) != record->value_size)
2895 {
2896 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2897 GNUNET_break (0);
2898 return;
2899 }
2900 mtbe = record->value;
2901 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2902 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2903 queue->handshake_monotonic_time).abs_value_us)
2904 {
2906 "Queue from %s dropped, handshake monotime in the past\n",
2907 GNUNET_i2s (&queue->target));
2908 GNUNET_break (0);
2909 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2910 queue->handshake_ack_monotime_get = NULL;
2912 return;
2913 }
2914 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2915 "transport_tcp_communicator",
2916 pid,
2918 handshake_monotonic_time,
2919 sizeof(*
2920 handshake_monotonic_time),
2923 &
2925 queue);
2926}

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_PILS_get_identity(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_FOREVER_ABS, handshake_monotime_store_cb(), peerstore, pid, pils, queue(), queue_finish(), and record().

Referenced by decrypt_and_check_tc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_and_check_tc()

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

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

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

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

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

2944{
2945 const struct GNUNET_PeerIdentity *my_identity;
2946 struct TcpHandshakeSignature ths;
2948
2951
2953 0 ==
2954 gcry_cipher_decrypt (queue->in_cipher,
2955 tc,
2956 sizeof(*tc),
2957 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2958 sizeof(*tc)));
2959 ths.purpose.purpose = htonl (
2961 ths.purpose.size = htonl (sizeof(ths));
2962 ths.sender = tc->sender;
2963 ths.receiver = *my_identity;
2964 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2965 ths.monotonic_time = tc->monotonic_time;
2966 ths.challenge = tc->challenge;
2969 &ths,
2970 &tc->sender_sig,
2971 &tc->sender.public_key);
2972 if (GNUNET_YES == ret)
2973 queue->handshake_monotime_get =
2975 "transport_tcp_communicator",
2976 &queue->target,
2979 queue);
2980 return ret;
2981}

References TcpHandshakeSignature::challenge, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_verify, GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE, GNUNET_PILS_get_identity(), GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE, GNUNET_YES, handshake_monotime_cb(), TcpHandshakeSignature::monotonic_time, my_identity, peerstore, pils, GNUNET_CRYPTO_SignaturePurpose::purpose, TcpHandshakeSignature::purpose, queue(), TcpHandshakeSignature::receiver, ret, TcpHandshakeSignature::sender, GNUNET_CRYPTO_SignaturePurpose::size, and tc.

Referenced by proto_read_kx(), and queue_read_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_read_kx()

static void queue_read_kx ( void *  cls)
static

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

Parameters
clsa struct Queue

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

2993{
2994 struct Queue *queue = cls;
2995 ssize_t rcvd;
2996 struct GNUNET_TIME_Relative left;
2997 struct TCPConfirmation tc;
2998
2999 queue->read_task = NULL;
3000 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
3001 if (0 == left.rel_value_us)
3002 {
3004 return;
3005 }
3006 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
3007 &queue->cread_buf[queue->cread_off],
3008 BUF_SIZE - queue->cread_off);
3010 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
3011 PRIu64 ")\n",
3012 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
3013 if (-1 == rcvd)
3014 {
3015 if ((EAGAIN != errno) && (EINTR != errno))
3016 {
3019 return;
3020 }
3021 queue->read_task =
3023 return;
3024 }
3025 if (0 == rcvd)
3026 {
3027 /* Orderly shutdown of connection */
3029 "Socket for queue %p seems to have been closed\n", queue);
3031 return;
3032 }
3033 queue->cread_off += rcvd;
3034 if (queue->cread_off < INITIAL_KX_SIZE)
3035 {
3036 /* read more */
3038 "%lu/%lu bytes of KX read. Rescheduling...\n",
3039 queue->cread_off, INITIAL_KX_SIZE);
3040 queue->read_task =
3042 return;
3043 }
3044 /* we got all the data, let's find out who we are talking to! */
3046 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
3047 queue->cread_buf,
3048 queue);
3049 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
3050 {
3052 "Invalid TCP KX received from %s\n",
3053 GNUNET_a2s (queue->address, queue->address_len));
3055 return;
3056 }
3057 if (0 !=
3058 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
3059 {
3061 "Invalid sender in TCP KX received from %s\n",
3062 GNUNET_a2s (queue->address, queue->address_len));
3064 return;
3065 }
3066 send_challenge (tc.challenge, queue);
3067 queue->write_task =
3069 queue->sock,
3070 &queue_write,
3071 queue);
3072
3073 /* update queue timeout */
3074 queue->timeout =
3076 /* prepare to continue with regular read task immediately */
3077 memmove (queue->cread_buf,
3078 &queue->cread_buf[INITIAL_KX_SIZE],
3079 queue->cread_off - (INITIAL_KX_SIZE));
3081 "cread_off is %lu bytes before adjusting\n",
3082 queue->cread_off);
3083 queue->cread_off -= INITIAL_KX_SIZE;
3085 "cread_off set to %lu bytes\n",
3086 queue->cread_off);
3088}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proto_read_kx()

static void proto_read_kx ( void *  cls)
static

Read from the socket of the proto queue until we have enough data to upgrade to full queue.

Parameters
clsa struct ProtoQueue

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

3099{
3100 struct ProtoQueue *pq = cls;
3101 ssize_t rcvd;
3102 struct GNUNET_TIME_Relative left;
3103 struct Queue *queue;
3104 struct TCPConfirmation tc;
3106
3107 pq->read_task = NULL;
3109 if (0 == left.rel_value_us)
3110 {
3111 free_proto_queue (pq);
3112 return;
3113 }
3114 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3115 &pq->ibuf[pq->ibuf_off],
3116 sizeof(pq->ibuf) - pq->ibuf_off);
3118 "Proto received %lu bytes for KX\n", rcvd);
3119 if (-1 == rcvd)
3120 {
3121 if ((EAGAIN != errno) && (EINTR != errno))
3122 {
3124 free_proto_queue (pq);
3125 return;
3126 }
3127 /* try again */
3128 pq->read_task =
3130 return;
3131 }
3132 if (0 == rcvd)
3133 {
3134 /* Orderly shutdown of connection */
3136 "Socket for proto queue %p seems to have been closed\n", pq);
3137 free_proto_queue (pq);
3138 return;
3139 }
3140 pq->ibuf_off += rcvd;
3141 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3142 {
3143 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3144
3146 &pm->clientIdentity);
3147
3148 queue = GNUNET_new (struct Queue);
3149 queue->target = pm->clientIdentity;
3150 eddsa_pub_to_hpke_key (&queue->target.public_key,
3151 &queue->target_hpke_key);
3154 }
3155 else if (pq->ibuf_off < sizeof(pq->ibuf))
3156 {
3157 /* read more */
3158 pq->read_task =
3160 return;
3161 }
3162 else
3163 {
3164 /* we got all the data, let's find out who we are talking to! */
3165 queue = GNUNET_new (struct Queue);
3167 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
3168 ibuf,
3169 queue);
3170 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3171 {
3173 "Invalid TCP KX received from %s\n",
3174 GNUNET_a2s (pq->address, pq->address_len));
3175 gcry_cipher_close (queue->in_cipher);
3177 free_proto_queue (pq);
3178 return;
3179 }
3180 queue->target = tc.sender;
3181 eddsa_pub_to_hpke_key (&queue->target.public_key,
3182 &queue->target_hpke_key);
3185 }
3186 queue->address = pq->address; /* steals reference */
3187 queue->address_len = pq->address_len;
3188 queue->listen_sock = pq->listen_sock;
3189 queue->sock = pq->sock;
3190
3192 "created queue with target %s\n",
3193 GNUNET_i2s (&queue->target));
3194
3196 "start kx proto\n");
3197
3199 boot_queue (queue);
3200 queue->read_task =
3202 queue->sock,
3203 read_task,
3204 queue);
3205 queue->write_task =
3207 queue->sock,
3208 &queue_write,
3209 queue);
3210 // TODO To early! Move it somewhere else.
3211 // send_challenge (tc.challenge, queue);
3212 queue->challenge_received = tc.challenge;
3213
3215 GNUNET_free (pq);
3216}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_proto_queue()

static struct ProtoQueue * create_proto_queue ( struct GNUNET_NETWORK_Handle sock,
struct sockaddr *  in,
socklen_t  addrlen 
)
static

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

3223{
3224 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3225
3226 if (NULL == sock)
3227 {
3228 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3229 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3230 if (NULL == sock)
3231 {
3233 "socket(%d) failed: %s",
3234 in->sa_family,
3235 strerror (errno));
3236 GNUNET_free (in);
3237 GNUNET_free (pq);
3238 return NULL;
3239 }
3240 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3241 (errno != EINPROGRESS))
3242 {
3244 "connect to `%s' failed: %s",
3245 GNUNET_a2s (in, addrlen),
3246 strerror (errno));
3248 GNUNET_free (in);
3249 GNUNET_free (pq);
3250 return NULL;
3251 }
3252 }
3253 pq->address_len = addrlen;
3254 pq->address = in;
3256 pq->sock = sock;
3258 pq->sock,
3260 pq);
3262
3263 return pq;
3264}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_connection_reversal()

static void try_connection_reversal ( void *  cls,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

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

3317{
3318 const struct GNUNET_PeerIdentity *my_identity;
3319 struct TCPNATProbeMessage pm;
3320 struct ProtoQueue *pq;
3321 struct sockaddr *in_addr;
3322 (void) cls;
3323
3326
3328 "addr->sa_family %d\n",
3329 addr->sa_family);
3331 "Try to connect back\n");
3332 in_addr = GNUNET_memdup (addr, addrlen);
3334 "in_addr->sa_family %d\n",
3335 in_addr->sa_family);
3336 pq = create_proto_queue (NULL, in_addr, addrlen);
3337 if (NULL != pq)
3338 {
3339 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3340 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3341 pm.clientIdentity = *my_identity;
3342 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3343 pq->write_off = sizeof(struct TCPNATProbeMessage);
3345 pq->sock,
3347 pq);
3348 }
3349 else
3350 {
3352 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3353 }
3354}

References create_proto_queue(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memdup, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, GNUNET_PILS_get_identity(), GNUNET_SCHEDULER_add_write_net(), my_identity, pils, pm, PROTO_QUEUE_TIMEOUT, proto_queue_write(), ProtoQueue::sock, ProtoQueue::write_buf, ProtoQueue::write_off, and ProtoQueue::write_task.

Referenced by nat_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pending_reversal_timeout()

static void pending_reversal_timeout ( void *  cls)
static

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

3359{
3360 struct sockaddr *in = cls;
3361 struct PendingReversal *pending_reversal;
3362 struct GNUNET_HashCode key;
3363
3365 sizeof(struct sockaddr),
3366 &key);
3368 &key);
3369
3370 GNUNET_assert (NULL != pending_reversal);
3371
3373 &key,
3374 pending_reversal))
3376 "No pending reversal found for address %s\n",
3377 GNUNET_a2s (in, sizeof (struct sockaddr)));
3378 GNUNET_free (pending_reversal->in);
3379 GNUNET_free (pending_reversal);
3380}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_init()

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

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

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

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

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

3403{
3404 struct sockaddr *in;
3405 socklen_t in_len = 0;
3406 const char *path;
3407 struct sockaddr_in *v4;
3408 struct sockaddr_in6 *v6;
3409 unsigned int is_natd = GNUNET_NO;
3410 struct GNUNET_HashCode key;
3411 struct GNUNET_HashCode queue_map_key;
3412 struct GNUNET_HashContext *hsh;
3413 struct Queue *queue;
3414
3416 "Connecting to %s at %s\n",
3417 GNUNET_i2s (peer),
3418 address);
3419 if (0 != strncmp (address,
3421 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3422 {
3423 GNUNET_break_op (0);
3424 return GNUNET_SYSERR;
3425 }
3426 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3427 in = tcp_address_to_sockaddr (path, &in_len);
3428
3429 if (NULL == in)
3430 {
3432 "Failed to setup TCP socket address\n");
3433 return GNUNET_SYSERR;
3434 }
3435
3437 "in %s\n",
3438 GNUNET_a2s (in, in_len));
3439
3442 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3443 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3445
3446 if (NULL != queue)
3447 {
3449 "Queue for %s already exists or is in construction\n", address);
3450 GNUNET_free (in);
3451 return GNUNET_NO;
3452 }
3453 switch (in->sa_family)
3454 {
3455 case AF_INET:
3456 v4 = (struct sockaddr_in *) in;
3457 if (0 == v4->sin_port)
3458 {
3459 is_natd = GNUNET_YES;
3461 sizeof(struct sockaddr),
3462 &key);
3465 &key))
3466 {
3468 "There is already a request reversal for `%s'at `%s'\n",
3469 GNUNET_i2s (peer),
3470 address);
3471 GNUNET_free (in);
3472 return GNUNET_SYSERR;
3473 }
3474 }
3475 break;
3476
3477 case AF_INET6:
3478 if (GNUNET_YES == disable_v6)
3479 {
3481 "IPv6 disabled, skipping %s\n", address);
3482 GNUNET_free (in);
3483 return GNUNET_SYSERR;
3484 }
3485 v6 = (struct sockaddr_in6 *) in;
3486 if (0 == v6->sin6_port)
3487 {
3489 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3490 GNUNET_i2s (peer),
3491 address);
3492 GNUNET_free (in);
3493 return GNUNET_SYSERR;
3494 }
3495 break;
3496
3497 default:
3498 GNUNET_assert (0);
3499 }
3500
3501 if (GNUNET_YES == is_natd)
3502 {
3503 struct sockaddr_in local_sa;
3504 struct PendingReversal *pending_reversal;
3505
3506 memset (&local_sa, 0, sizeof(local_sa));
3507 local_sa.sin_family = AF_INET;
3508 local_sa.sin_port = htons (bind_port);
3509 /* We leave sin_address at 0, let the kernel figure it out,
3510 even if our bind() is more specific. (May want to reconsider
3511 later.) */
3512 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3513 {
3515 "request reversal for `%s' at `%s' failed\n",
3516 GNUNET_i2s (peer),
3517 address);
3518 GNUNET_free (in);
3519 return GNUNET_SYSERR;
3520 }
3521 pending_reversal = GNUNET_new (struct PendingReversal);
3522 pending_reversal->in = in;
3525 &key,
3526 pending_reversal,
3528 pending_reversal->target = *peer;
3530 &
3532 in);
3534 "Created NAT WAIT connection to `%s' at `%s'\n",
3535 GNUNET_i2s (peer),
3536 GNUNET_a2s (in, sizeof (struct sockaddr)));
3537 }
3538 else
3539 {
3540 struct GNUNET_NETWORK_Handle *sock;
3541
3542 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3543 IPPROTO_TCP);
3544 if (NULL == sock)
3545 {
3547 "socket(%d) failed: %s",
3548 in->sa_family,
3549 strerror (errno));
3550 GNUNET_free (in);
3551 return GNUNET_SYSERR;
3552 }
3553 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3554 (errno != EINPROGRESS))
3555 {
3557 "connect to `%s' failed: %s",
3558 address,
3559 strerror (errno));
3561 GNUNET_free (in);
3562 return GNUNET_SYSERR;
3563 }
3564
3565 queue = GNUNET_new (struct Queue);
3566 queue->target = *peer;
3567 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3568 queue->key = queue_map_key;
3569 queue->address = in;
3570 queue->address_len = in_len;
3571 queue->sock = sock;
3573 boot_queue (queue);
3575 "booted queue with target %s\n",
3576 GNUNET_i2s (&queue->target));
3577 // queue->mq_awaits_continue = GNUNET_YES;
3578 queue->read_task =
3580 queue->sock,
3582 queue);
3583
3584
3586 "start kx mq_init\n");
3587
3589 queue->write_task =
3591 queue->sock,
3592 &queue_write,
3593 queue);
3594 }
3595
3596 return GNUNET_OK;
3597}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_lt_delete_it()

static int get_lt_delete_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over all ListenTasks to clean up.

Parameters
clsNULL
keyunused
valuethe ListenTask to cancel.
Returns
GNUNET_OK to continue to iterate

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

3612{
3613 struct ListenTask *lt = value;
3614
3615 (void) cls;
3616 (void) key;
3617 if (NULL != lt->listen_task)
3618 {
3620 lt->listen_task = NULL;
3621 }
3622 if (NULL != lt->listen_sock)
3623 {
3625 lt->listen_sock = NULL;
3626 }
3627 GNUNET_free (lt);
3628 return GNUNET_OK;
3629}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_queue_delete_it()

static int get_queue_delete_it ( void *  cls,
const struct GNUNET_HashCode target,
void *  value 
)
static

Iterator over all message queues to clean up.

Parameters
clsNULL
targetunused
valuethe queue to destroy
Returns
GNUNET_OK to continue to iterate

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

3644{
3645 struct Queue *queue = value;
3646
3647 (void) cls;
3648 (void) target;
3650 return GNUNET_OK;
3651}

References GNUNET_OK, queue(), queue_destroy(), Queue::target, and value.

Referenced by do_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown the UNIX communicator.

Parameters
clsNULL (always)

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

3661{
3663 "Shutdown %s!\n",
3664 shutdown_running ? "running" : "not running");
3665
3667 return;
3668 else
3670
3671 while (NULL != proto_head)
3673 if (NULL != nat)
3674 {
3676 nat = NULL;
3677 }
3685 if (NULL != ch)
3686 {
3689 ch = NULL;
3690 }
3691 if (NULL != stats)
3692 {
3694 stats = NULL;
3695 }
3696 if (NULL != is)
3697 {
3699 is = NULL;
3700 }
3701 if (NULL != pils)
3702 {
3704 pils = NULL;
3705 }
3706 if (NULL != key_ring)
3707 {
3709 key_ring = NULL;
3710 }
3711 if (NULL != peerstore)
3712 {
3714 peerstore = NULL;
3715 }
3716 if (NULL != resolve_request_handle)
3717 {
3720 }
3722 "Shutdown done!\n");
3723}

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_log, GNUNET_NAT_unregister(), GNUNET_NT_scanner_done(), GNUNET_PEERSTORE_disconnect(), GNUNET_PILS_destroy_key_ring(), GNUNET_PILS_disconnect(), GNUNET_RESOLVER_request_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_communicator_address_remove_all(), GNUNET_TRANSPORT_communicator_disconnect(), GNUNET_YES, is, key_ring, lt_map, nat, peerstore, pending_reversals, pending_reversals_delete_it(), pils, proto_head, queue_map, resolve_request_handle, shutdown_running, and stats.

Here is the call graph for this function:

◆ enc_notify_cb()

static void enc_notify_cb ( void *  cls,
const struct GNUNET_PeerIdentity sender,
const struct GNUNET_MessageHeader msg 
)
static

Function called when the transport service has received an acknowledgement for this communicator (!) via a different return path.

Not applicable for TCP.

Parameters
clsclosure
senderwhich peer sent the notification
msgpayload

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

3741{
3742 (void) cls;
3743 (void) sender;
3744 (void) msg;
3745 GNUNET_break_op (0);
3746}

References GNUNET_break_op, and msg.

Referenced by init_socket().

Here is the caller graph for this function:

◆ nat_address_cb()

static void nat_address_cb ( void *  cls,
void **  app_ctx,
int  add_remove,
enum GNUNET_NAT_AddressClass  ac,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.

Parameters
clsclosure
[in,out]app_ctxlocation where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to add a new public IP address, GNUNET_NO to remove a previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual length of the addr

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

3769{
3770 char *my_addr;
3772
3774 "nat address cb %s %s\n",
3775 add_remove ? "add" : "remove",
3776 GNUNET_a2s (addr, addrlen));
3777
3778 if (GNUNET_YES == add_remove)
3779 {
3781
3782 GNUNET_asprintf (&my_addr,
3783 "%s-%s",
3785 GNUNET_a2s (addr, addrlen));
3786 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3787 ai =
3789 my_addr,
3790 nt,
3792 GNUNET_free (my_addr);
3793 *app_ctx = ai;
3794 }
3795 else
3796 {
3797 ai = *app_ctx;
3799 *app_ctx = NULL;
3800 }
3801}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_addr()

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

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

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

3809{
3810
3811 struct Addresses *saddrs;
3812
3814 "add address %s\n",
3815 GNUNET_a2s (in, in_len));
3816
3817 saddrs = GNUNET_new (struct Addresses);
3818 saddrs->addr = in;
3819 saddrs->addr_len = in_len;
3821
3823 "after add address %s\n",
3824 GNUNET_a2s (in, in_len));
3825
3827 "add address %s\n",
3828 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3829
3830 addrs_lens++;
3831}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_socket()

static int init_socket ( struct sockaddr *  addr,
socklen_t  in_len 
)
static

This method launch network interactions for each address we like to bind to.

Parameters
addrThe address we will listen to.
in_lenThe length of the address we will listen to.
Returns
GNUNET_SYSERR in case of error. GNUNET_OK in case we are successfully listen to the address.

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

3844{
3845 struct sockaddr_storage in_sto;
3846 socklen_t sto_len;
3847 struct GNUNET_NETWORK_Handle *listen_sock;
3848 struct ListenTask *lt;
3849 int sockfd;
3850 struct GNUNET_HashCode h_sock;
3851
3852 if (NULL == addr)
3853 {
3855 "Address is NULL.\n");
3856 return GNUNET_SYSERR;
3857 }
3858
3860 "address %s\n",
3861 GNUNET_a2s (addr, in_len));
3862
3863 listen_sock =
3864 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3865 if (NULL == listen_sock)
3866 {
3868 return GNUNET_SYSERR;
3869 }
3870
3871 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3872 {
3874 GNUNET_NETWORK_socket_close (listen_sock);
3875 listen_sock = NULL;
3876 return GNUNET_SYSERR;
3877 }
3878
3879 if (GNUNET_OK !=
3880 GNUNET_NETWORK_socket_listen (listen_sock,
3881 5))
3882 {
3884 "listen");
3885 GNUNET_NETWORK_socket_close (listen_sock);
3886 listen_sock = NULL;
3887 return GNUNET_SYSERR;
3888 }
3889
3890 /* We might have bound to port 0, allowing the OS to figure it out;
3891 thus, get the real IN-address from the socket */
3892 sto_len = sizeof(in_sto);
3893
3894 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3895 (struct sockaddr *) &in_sto,
3896 &sto_len))
3897 {
3898 memcpy (&in_sto, addr, in_len);
3899 sto_len = in_len;
3900 }
3901
3902 // addr = (struct sockaddr *) &in_sto;
3903 in_len = sto_len;
3905 "Bound to `%s'\n",
3906 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3907 if (NULL == stats)
3908 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3909
3910 if (NULL == is)
3912
3913 /* start listening */
3914
3915 lt = GNUNET_new (struct ListenTask);
3916 lt->listen_sock = listen_sock;
3917
3919 listen_sock,
3920 &listen_cb,
3921 lt);
3922
3924 "creating hash\n");
3925 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3926 GNUNET_CRYPTO_hash (&sockfd,
3927 sizeof(int),
3928 &h_sock);
3929
3931 "creating map\n");
3932 if (NULL == lt_map)
3934
3936 "creating map entry\n");
3939 &h_sock,
3940 lt,
3942
3944 "map entry created\n");
3945
3946 if (NULL == queue_map)
3948
3949 if (NULL == ch)
3954 &mq_init,
3955 NULL,
3957 NULL,
3958 NULL);
3959
3960 if (NULL == ch)
3961 {
3962 GNUNET_break (0);
3963 if (NULL != resolve_request_handle)
3966 return GNUNET_SYSERR;
3967 }
3968
3969 add_addr (addr, in_len);
3970 return GNUNET_OK;
3971
3972}

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 init_socket_resolv(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nat_register()

static void nat_register ( )
static

This method reads from the DLL addrs_head to register them at the NAT service.

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

3980{
3981 struct sockaddr **saddrs;
3982 socklen_t *saddr_lens;
3983 int i;
3984 size_t len;
3985
3987 "starting nat register!\n");
3988 len = 0;
3989 i = 0;
3990 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3991 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3992 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3993 {
3995 "registering address %s\n",
3996 GNUNET_a2s (pos->addr, pos->addr_len));
3997
3998 saddr_lens[i] = pos->addr_len;
3999 len += saddr_lens[i];
4000 saddrs[i] = GNUNET_memdup (pos->addr, saddr_lens[i]);
4001 i++;
4002 }
4003
4005 "registering addresses %lu %lu %lu %lu\n",
4006 (addrs_lens) * sizeof(struct sockaddr *),
4007 (addrs_lens) * sizeof(socklen_t),
4008 len,
4012 IPPROTO_TCP,
4013 addrs_lens,
4014 (const struct sockaddr **) saddrs,
4015 saddr_lens,
4018 NULL /* closure */);
4019 for (i = addrs_lens - 1; i >= 0; i--)
4020 GNUNET_free (saddrs[i]);
4021 GNUNET_free (saddrs);
4022 GNUNET_free (saddr_lens);
4023
4024 if (NULL == nat)
4025 {
4026 GNUNET_break (0);
4027 if (NULL != resolve_request_handle)
4030 }
4031}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_socket_resolv()

static void init_socket_resolv ( void *  cls,
const struct sockaddr *  addr,
socklen_t  in_len 
)
static

This method is the callback called by the resolver API, and wraps method init_socket.

Parameters
clsThe port we will bind to.
addrThe address we will bind to.
in_lenThe length of the address we will bind to.

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

4045{
4046 struct sockaddr_in *v4;
4047 struct sockaddr_in6 *v6;
4048 struct sockaddr *in;
4049
4050 (void) cls;
4051 if (NULL != addr)
4052 {
4053 if (AF_INET == addr->sa_family)
4054 {
4055 v4 = (struct sockaddr_in *) addr;
4056 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
4057 }
4058 else if (AF_INET6 == addr->sa_family)
4059 {
4060 v6 = (struct sockaddr_in6 *) addr;
4061 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
4062 }
4063 else
4064 {
4066 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
4067 addr->sa_family,
4068 AF_INET,
4069 AF_INET6);
4070 return;
4071 }
4072 init_socket (in, in_len);
4073 }
4074 else
4075 {
4077 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4078 if (NULL == addrs_head)
4079 {
4081 "Resolver finished resolving, but we do not listen to an address!.\n");
4082 return;
4083 }
4084 nat_register ();
4085 }
4086}

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Setup communicator and launch network interactions.

Parameters
clsNULL (always)
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

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

4102{
4103 char *bindto;
4104 struct sockaddr *in;
4105 socklen_t in_len;
4106 struct sockaddr_in v4;
4107 struct sockaddr_in6 v6;
4108 char *start;
4109 unsigned int port;
4110 char dummy[2];
4111 char *rest = NULL;
4112 struct PortOnlyIpv4Ipv6 *po;
4113 socklen_t addr_len_ipv4;
4114 socklen_t addr_len_ipv6;
4115
4116 (void) cls;
4117
4119 memset (&v4,0,sizeof(struct sockaddr_in));
4120 memset (&v6,0,sizeof(struct sockaddr_in6));
4121 cfg = c;
4122 if (GNUNET_OK !=
4125 "BINDTO",
4126 &bindto))
4127 {
4130 "BINDTO");
4131 return;
4132 }
4133 if (GNUNET_OK !=
4136 "MAX_QUEUE_LENGTH",
4138 {
4140 }
4141 if (GNUNET_OK !=
4144 "REKEY_INTERVAL",
4146 {
4148 }
4149 if (GNUNET_OK !=
4152 "REKEY_MAX_BYTES",
4154 {
4156 }
4158 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4159 (GNUNET_YES ==
4162 "DISABLE_V6")))
4163 {
4165 }
4167 GNUNET_assert (NULL != key_ring);
4168 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
4169 GNUNET_assert (NULL != pils);
4171 if (NULL == peerstore)
4172 {
4173 GNUNET_free (bindto);
4174 GNUNET_break (0);
4176 return;
4177 }
4178
4180
4181 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4182 {
4186 "address po %s\n",
4188 if (NULL != po->addr_ipv4)
4189 {
4191 }
4192 if (NULL != po->addr_ipv6)
4193 {
4196 }
4197 GNUNET_free (po);
4198 nat_register ();
4199 GNUNET_free (bindto);
4200 return;
4201 }
4202
4203 start = extract_address (bindto);
4204 // FIXME: check for NULL == start...
4205 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4206 {
4207 bind_port = extract_port (bindto);
4208
4210 init_socket (in, in_len);
4211 nat_register ();
4213 GNUNET_free (bindto);
4214 return;
4215 }
4216
4217 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4218 {
4219 bind_port = extract_port (bindto);
4221 init_socket (in, in_len);
4222 nat_register ();
4224 GNUNET_free (bindto);
4225 return;
4226 }
4227
4228 bind_port = extract_port (bindto);
4230 ":",
4231 &rest),
4232 AF_UNSPEC,
4235 &port);
4236
4237 GNUNET_free (bindto);
4239}

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_assert, 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_PILS_connect(), GNUNET_PILS_create_key_ring(), GNUNET_RESOLVER_ip_get(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, init_socket(), init_socket_resolv(), key_ring, max_queue_length, nat_register(), peerstore, pending_reversals, pils, 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for the UNIX communicator.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

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

4251{
4252 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4254 };
4255 int ret;
4256
4258 "Starting tcp communicator\n");
4259
4260 ret = (GNUNET_OK ==
4262 argc,
4263 argv,
4264 "gnunet-communicator-tcp",
4265 _ ("GNUnet TCP communicator"),
4266 options,
4267 &run,
4268 NULL))
4269 ? 0
4270 : 1;
4271 return ret;
4272}

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

Here is the call graph for this function:

Variable Documentation

◆ max_queue_length

unsigned long long max_queue_length
static

Maximum queue length before we stop reading towards the transport service.

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

Referenced by queue_read(), queue_read(), and run().

◆ key_ring

◆ pils

◆ stats

◆ ch

◆ queue_map

struct GNUNET_CONTAINER_MultiHashMap* queue_map
static

Queues (map from peer identity to struct Queue)

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

Referenced by boot_queue(), do_shutdown(), init_socket(), mq_init(), and queue_destroy().

◆ lt_map

struct GNUNET_CONTAINER_MultiHashMap* lt_map
static

ListenTasks (map from socket to struct ListenTask)

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

Referenced by do_shutdown(), init_socket(), and queue_destroy().

◆ rekey_max_bytes

unsigned long long rekey_max_bytes
static

The rekey byte maximum.

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

Referenced by run(), setup_out_cipher(), and setup_out_cipher().

◆ rekey_interval

struct GNUNET_TIME_Relative rekey_interval
static

The rekey interval.

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

Referenced by run(), run(), setup_out_cipher(), and setup_out_cipher().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

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

Referenced by init_socket(), inject_rekey(), nat_register(), run(), send_challenge(), and transmit_kx().

◆ is

struct GNUNET_NT_InterfaceScanner* is
static

Network scanner to determine network types.

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

Referenced by boot_queue(), do_shutdown(), init_socket(), and nat_address_cb().

◆ nat

struct GNUNET_NAT_Handle* nat
static

Connection to NAT service.

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

Referenced by do_shutdown(), mq_init(), and nat_register().

◆ proto_head

struct ProtoQueue* proto_head
static

◆ proto_tail

struct ProtoQueue* proto_tail
static

◆ resolve_request_handle

struct GNUNET_RESOLVER_RequestHandle* resolve_request_handle

Handle for DNS lookup of bindto address.

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

Referenced by do_shutdown(), do_shutdown(), init_socket(), init_socket(), nat_register(), and run().

◆ addrs_head

struct Addresses* addrs_head
static

Head of DLL with addresses we like to register at NAT service.

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

Referenced by add_addr(), init_socket_resolv(), and nat_register().

◆ addrs_tail

struct Addresses* addrs_tail
static

Head of DLL with addresses we like to register at NAT service.

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

Referenced by add_addr().

◆ addrs_lens

int addrs_lens
static

Number of addresses in the DLL for register at NAT service.

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

Referenced by add_addr(), add_addr(), and nat_register().

◆ peerstore

◆ shutdown_running

int shutdown_running = GNUNET_NO
static

A flag indicating we are already doing a shutdown.

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

Referenced by do_shutdown(), and queue_destroy().

◆ disable_v6

int disable_v6
static

IPv6 disabled.

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

Referenced by mq_init(), run(), and tcp_address_to_sockaddr_port_only().

◆ bind_port

unsigned int bind_port
static

The port the communicator should be assigned to.

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

Referenced by init_socket_resolv(), mq_init(), mq_init(), run(), and run().

◆ pending_reversals