GNUnet 0.27.0
 
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_HashCode *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_HashCode *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_HashCode *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_raw (hmac_secret,
1094 sizeof(struct GNUNET_HashCode),
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 hmac_secret);
1104}
1105
1106
1113static void
1114queue_finish (struct Queue *queue)
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}
1133
1134
1140static void
1141queue_read (void *cls);
1142
1143
1151static void
1152core_read_finished_cb (void *cls, int success)
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}
1189
1190
1200static void
1202 const void *plaintext,
1203 size_t plaintext_len)
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}
1236
1237
1247static void
1248setup_cipher (const struct GNUNET_ShortHashCode *prk,
1249 const struct GNUNET_PeerIdentity *pid,
1250 gcry_cipher_hd_t *cipher,
1251 struct GNUNET_HashCode *hmac_key)
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}
1284
1285
1291static void
1292rekey_monotime_store_cb (void *cls, int success)
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}
1303
1304
1312static void
1313rekey_monotime_cb (void *cls,
1314 const struct GNUNET_PEERSTORE_Record *record,
1315 const char *emsg)
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}
1365
1366
1373static void
1375 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
1376 struct Queue *queue)
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}
1394
1395
1402static void
1403setup_in_cipher (const struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral,
1404 struct Queue *queue)
1405{
1406 const struct GNUNET_PeerIdentity *my_identity;
1408 struct GNUNET_ShortHashCode k;
1409
1413
1415 setup_cipher (&k, my_identity, &queue->in_cipher, &queue->in_hmac);
1416}
1417
1418
1427static void
1428do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
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}
1487
1488
1494static void
1495handshake_ack_monotime_store_cb (void *cls, int success)
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}
1507
1508
1516static void
1517handshake_ack_monotime_cb (void *cls,
1518 const struct GNUNET_PEERSTORE_Record *record,
1519 const char *emsg)
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}
1569
1570
1577static void
1579 struct Queue *queue)
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}
1620
1621
1628static void
1630{
1631 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1633 queue->rekey_left_bytes =
1635}
1636
1637
1644static void
1645inject_rekey (struct Queue *queue)
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);
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}
1704
1705
1706static int
1708 const struct GNUNET_HashCode *key,
1709 void *value)
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}
1727
1728
1729static void
1730check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1731 struct GNUNET_PeerIdentity *sender)
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}
1762
1763
1769static void
1770free_proto_queue (struct ProtoQueue *pq)
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}
1793
1794
1801static void
1802proto_queue_write (void *cls)
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}
1838
1839
1846static void
1847queue_write (void *cls)
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}
1936
1937
1945static size_t
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}
2201
2202
2208static void
2209queue_read (void *cls)
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}
2327
2328
2336static struct sockaddr *
2337tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len,
2338 struct sockaddr_in6 v6,
2339 unsigned int port)
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}
2355
2356
2364static struct sockaddr *
2365tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len,
2366 struct sockaddr_in v4,
2367 unsigned int port)
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}
2380
2381
2388static struct PortOnlyIpv4Ipv6 *
2389tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
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}
2436
2437
2444static char *
2445extract_address (const char *bindto)
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}
2494
2495
2502static unsigned int
2503extract_port (const char *addr_and_port)
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}
2575
2576
2584static struct sockaddr *
2585tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
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}
2628
2629
2638static void
2639mq_send (struct GNUNET_MQ_Handle *mq,
2640 const struct GNUNET_MessageHeader *msg,
2641 void *impl_state)
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}
2672
2673
2682static void
2683mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2684{
2685 struct Queue *queue = impl_state;
2686
2687 if (mq == queue->mq)
2688 {
2689 queue->mq = NULL;
2691 }
2692}
2693
2694
2701static void
2702mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2703{
2704 struct Queue *queue = impl_state;
2705
2706 GNUNET_assert (0 != queue->pwrite_off);
2707 queue->pwrite_off = 0;
2708}
2709
2710
2720static void
2721mq_error (void *cls, enum GNUNET_MQ_Error error)
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}
2731
2732
2740static void
2741boot_queue (struct Queue *queue)
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}
2764
2765
2776static void
2777transmit_kx (struct Queue *queue,
2778 const struct GNUNET_CRYPTO_HpkeEncapsulation *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 =
2796 &tc.challenge,
2797 sizeof(tc.challenge));
2798 ths.purpose.purpose = htonl (
2800 ths.purpose.size = htonl (sizeof(ths));
2801 ths.sender = *my_identity;
2802 ths.receiver = queue->target;
2803 ths.ephemeral = *c;
2804 ths.monotonic_time = tc.monotonic_time;
2805 ths.challenge = tc.challenge;
2807 &ths,
2808 &tc.sender_sig);
2809 GNUNET_assert (0 ==
2810 gcry_cipher_encrypt (queue->out_cipher,
2811 &queue->cwrite_buf[queue->cwrite_off],
2812 sizeof(tc),
2813 &tc,
2814 sizeof(tc)));
2815 queue->challenge = tc.challenge;
2816 queue->cwrite_off += sizeof(tc);
2817
2819 "handshake written\n");
2820}
2821
2822
2830static void
2832{
2834 struct GNUNET_ShortHashCode k;
2835
2837 &c, &k);
2838 setup_out_cipher (queue, &k);
2839 transmit_kx (queue, &c);
2840}
2841
2842
2848static void
2849handshake_monotime_store_cb (void *cls, int success)
2850{
2851 struct Queue *queue = cls;
2852 if (GNUNET_OK != success)
2853 {
2855 "Failed to store handshake monotonic time in PEERSTORE!\n");
2856 }
2857 queue->handshake_monotime_sc = NULL;
2858 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2859}
2860
2861
2869static void
2870handshake_monotime_cb (void *cls,
2871 const struct GNUNET_PEERSTORE_Record *record,
2872 const char *emsg)
2873{
2874 struct Queue *queue = cls;
2875 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2876 struct GNUNET_TIME_Absolute mt;
2877 const struct GNUNET_PeerIdentity *pid;
2878 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2879
2880 (void) emsg;
2881
2882 handshake_monotonic_time = &queue->handshake_monotonic_time;
2883 pid = &queue->target;
2885 "tcp handshake with us %s\n",
2887 if (NULL == record)
2888 {
2889 queue->handshake_monotime_get = NULL;
2890 return;
2891 }
2893 "tcp handshake from peer %s\n",
2894 GNUNET_i2s (pid));
2895 if (sizeof(*mtbe) != record->value_size)
2896 {
2897 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2898 GNUNET_break (0);
2899 return;
2900 }
2901 mtbe = record->value;
2902 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2903 if (mt.abs_value_us > GNUNET_TIME_absolute_ntoh (
2904 queue->handshake_monotonic_time).abs_value_us)
2905 {
2907 "Queue from %s dropped, handshake monotime in the past\n",
2908 GNUNET_i2s (&queue->target));
2909 GNUNET_break (0);
2910 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2911 queue->handshake_ack_monotime_get = NULL;
2913 return;
2914 }
2915 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2916 "transport_tcp_communicator",
2917 pid,
2919 handshake_monotonic_time,
2920 sizeof(*
2921 handshake_monotonic_time),
2924 &
2926 queue);
2927}
2928
2929
2941static int
2943 struct TCPConfirmation *tc,
2944 char *ibuf)
2945{
2946 const struct GNUNET_PeerIdentity *my_identity;
2947 struct TcpHandshakeSignature ths;
2949
2952
2954 0 ==
2955 gcry_cipher_decrypt (queue->in_cipher,
2956 tc,
2957 sizeof(*tc),
2958 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2959 sizeof(*tc)));
2960 ths.purpose.purpose = htonl (
2962 ths.purpose.size = htonl (sizeof(ths));
2963 ths.sender = tc->sender;
2964 ths.receiver = *my_identity;
2965 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2966 ths.monotonic_time = tc->monotonic_time;
2967 ths.challenge = tc->challenge;
2970 &ths,
2971 &tc->sender_sig,
2972 &tc->sender.public_key);
2973 if (GNUNET_YES == ret)
2974 queue->handshake_monotime_get =
2976 "transport_tcp_communicator",
2977 &queue->target,
2980 queue);
2981 return ret;
2982}
2983
2984
2992static void
2993queue_read_kx (void *cls)
2994{
2995 struct Queue *queue = cls;
2996 ssize_t rcvd;
2997 struct GNUNET_TIME_Relative left;
2998 struct TCPConfirmation tc;
2999
3000 queue->read_task = NULL;
3001 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
3002 if (0 == left.rel_value_us)
3003 {
3005 return;
3006 }
3007 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
3008 &queue->cread_buf[queue->cread_off],
3009 BUF_SIZE - queue->cread_off);
3011 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
3012 PRIu64 ")\n",
3013 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
3014 if (-1 == rcvd)
3015 {
3016 if ((EAGAIN != errno) && (EINTR != errno))
3017 {
3020 return;
3021 }
3022 queue->read_task =
3024 return;
3025 }
3026 if (0 == rcvd)
3027 {
3028 /* Orderly shutdown of connection */
3030 "Socket for queue %p seems to have been closed\n", queue);
3032 return;
3033 }
3034 queue->cread_off += rcvd;
3035 if (queue->cread_off < INITIAL_KX_SIZE)
3036 {
3037 /* read more */
3039 "%lu/%lu bytes of KX read. Rescheduling...\n",
3040 queue->cread_off, INITIAL_KX_SIZE);
3041 queue->read_task =
3043 return;
3044 }
3045 /* we got all the data, let's find out who we are talking to! */
3047 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
3048 queue->cread_buf,
3049 queue);
3050 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
3051 {
3053 "Invalid TCP KX received from %s\n",
3054 GNUNET_a2s (queue->address, queue->address_len));
3056 return;
3057 }
3058 if (0 !=
3059 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
3060 {
3062 "Invalid sender in TCP KX received from %s\n",
3063 GNUNET_a2s (queue->address, queue->address_len));
3065 return;
3066 }
3067 send_challenge (tc.challenge, queue);
3068 queue->write_task =
3070 queue->sock,
3071 &queue_write,
3072 queue);
3073
3074 /* update queue timeout */
3075 queue->timeout =
3077 /* prepare to continue with regular read task immediately */
3078 memmove (queue->cread_buf,
3079 &queue->cread_buf[INITIAL_KX_SIZE],
3080 queue->cread_off - (INITIAL_KX_SIZE));
3082 "cread_off is %lu bytes before adjusting\n",
3083 queue->cread_off);
3084 queue->cread_off -= INITIAL_KX_SIZE;
3086 "cread_off set to %lu bytes\n",
3087 queue->cread_off);
3089}
3090
3091
3098static void
3099proto_read_kx (void *cls)
3100{
3101 struct ProtoQueue *pq = cls;
3102 ssize_t rcvd;
3103 struct GNUNET_TIME_Relative left;
3104 struct Queue *queue;
3105 struct TCPConfirmation tc;
3107
3108 pq->read_task = NULL;
3110 if (0 == left.rel_value_us)
3111 {
3112 free_proto_queue (pq);
3113 return;
3114 }
3115 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3116 &pq->ibuf[pq->ibuf_off],
3117 sizeof(pq->ibuf) - pq->ibuf_off);
3119 "Proto received %lu bytes for KX\n", rcvd);
3120 if (-1 == rcvd)
3121 {
3122 if ((EAGAIN != errno) && (EINTR != errno))
3123 {
3125 free_proto_queue (pq);
3126 return;
3127 }
3128 /* try again */
3129 pq->read_task =
3131 return;
3132 }
3133 if (0 == rcvd)
3134 {
3135 /* Orderly shutdown of connection */
3137 "Socket for proto queue %p seems to have been closed\n", pq);
3138 free_proto_queue (pq);
3139 return;
3140 }
3141 pq->ibuf_off += rcvd;
3142 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3143 {
3144 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3145
3147 &pm->clientIdentity);
3148
3149 queue = GNUNET_new (struct Queue);
3150 queue->target = pm->clientIdentity;
3151 eddsa_pub_to_hpke_key (&queue->target.public_key,
3152 &queue->target_hpke_key);
3155 }
3156 else if (pq->ibuf_off > sizeof(pq->ibuf))
3157 {
3158 /* read more */
3159 pq->read_task =
3161 return;
3162 }
3163 else
3164 {
3165 /* we got all the data, let's find out who we are talking to! */
3166 queue = GNUNET_new (struct Queue);
3168 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
3169 ibuf,
3170 queue);
3171 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3172 {
3174 "Invalid TCP KX received from %s\n",
3175 GNUNET_a2s (pq->address, pq->address_len));
3176 gcry_cipher_close (queue->in_cipher);
3178 free_proto_queue (pq);
3179 return;
3180 }
3181 queue->target = tc.sender;
3182 eddsa_pub_to_hpke_key (&queue->target.public_key,
3183 &queue->target_hpke_key);
3186 }
3187 queue->address = pq->address; /* steals reference */
3188 queue->address_len = pq->address_len;
3189 queue->listen_sock = pq->listen_sock;
3190 queue->sock = pq->sock;
3191
3193 "created queue with target %s\n",
3194 GNUNET_i2s (&queue->target));
3195
3197 "start kx proto\n");
3198
3200 boot_queue (queue);
3201 queue->read_task =
3203 queue->sock,
3204 read_task,
3205 queue);
3206 queue->write_task =
3208 queue->sock,
3209 &queue_write,
3210 queue);
3211 // TODO To early! Move it somewhere else.
3212 // send_challenge (tc.challenge, queue);
3213 queue->challenge_received = tc.challenge;
3214
3216 GNUNET_free (pq);
3217}
3218
3219
3220static struct ProtoQueue *
3222 struct sockaddr *in,
3223 socklen_t addrlen)
3224{
3225 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3226
3227 if (NULL == sock)
3228 {
3229 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3230 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3231 if (NULL == sock)
3232 {
3234 "socket(%d) failed: %s",
3235 in->sa_family,
3236 strerror (errno));
3237 GNUNET_free (in);
3238 GNUNET_free (pq);
3239 return NULL;
3240 }
3241 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3242 (errno != EINPROGRESS))
3243 {
3245 "connect to `%s' failed: %s",
3246 GNUNET_a2s (in, addrlen),
3247 strerror (errno));
3249 GNUNET_free (in);
3250 GNUNET_free (pq);
3251 return NULL;
3252 }
3253 }
3254 pq->address_len = addrlen;
3255 pq->address = in;
3257 pq->sock = sock;
3259 pq->sock,
3261 pq);
3263
3264 return pq;
3265}
3266
3267
3275static void
3276listen_cb (void *cls)
3277{
3278 struct sockaddr_storage in;
3279 socklen_t addrlen;
3280 struct GNUNET_NETWORK_Handle *sock;
3281 struct ListenTask *lt;
3282 struct sockaddr *in_addr;
3283
3285 "listen_cb\n");
3286
3287 lt = cls;
3288
3289 lt->listen_task = NULL;
3290 GNUNET_assert (NULL != lt->listen_sock);
3291 addrlen = sizeof(in);
3292 memset (&in, 0, sizeof(in));
3294 (struct sockaddr*) &in,
3295 &addrlen);
3296 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3297 return; /* system limit reached, wait until connection goes down */
3299 lt->listen_sock,
3300 &listen_cb,
3301 lt);
3302 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3303 return;
3304 if (NULL == sock)
3305 {
3307 return;
3308 }
3309 in_addr = GNUNET_memdup (&in, addrlen);
3310 create_proto_queue (sock, in_addr, addrlen);
3311}
3312
3313
3314static void
3315try_connection_reversal (void *cls,
3316 const struct sockaddr *addr,
3317 socklen_t addrlen)
3318{
3319 const struct GNUNET_PeerIdentity *my_identity;
3320 struct TCPNATProbeMessage pm;
3321 struct ProtoQueue *pq;
3322 struct sockaddr *in_addr;
3323 (void) cls;
3324
3327
3329 "addr->sa_family %d\n",
3330 addr->sa_family);
3332 "Try to connect back\n");
3333 in_addr = GNUNET_memdup (addr, addrlen);
3335 "in_addr->sa_family %d\n",
3336 in_addr->sa_family);
3337 pq = create_proto_queue (NULL, in_addr, addrlen);
3338 if (NULL != pq)
3339 {
3340 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3341 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3342 pm.clientIdentity = *my_identity;
3343 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3344 pq->write_off = sizeof(struct TCPNATProbeMessage);
3346 pq->sock,
3348 pq);
3349 }
3350 else
3351 {
3353 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3354 }
3355}
3356
3357
3358static void
3359pending_reversal_timeout (void *cls)
3360{
3361 struct sockaddr *in = cls;
3362 struct PendingReversal *pending_reversal;
3363 struct GNUNET_HashCode key;
3364
3366 sizeof(struct sockaddr),
3367 &key);
3369 &key);
3370
3371 GNUNET_assert (NULL != pending_reversal);
3372
3374 &key,
3375 pending_reversal))
3377 "No pending reversal found for address %s\n",
3378 GNUNET_a2s (in, sizeof (struct sockaddr)));
3379 GNUNET_free (pending_reversal->in);
3380 GNUNET_free (pending_reversal);
3381}
3382
3383
3402static int
3403mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3404{
3405 struct sockaddr *in;
3406 socklen_t in_len = 0;
3407 const char *path;
3408 struct sockaddr_in *v4;
3409 struct sockaddr_in6 *v6;
3410 unsigned int is_natd = GNUNET_NO;
3411 struct GNUNET_HashCode key;
3412 struct GNUNET_HashCode queue_map_key;
3413 struct GNUNET_HashContext *hsh;
3414 struct Queue *queue;
3415
3417 "Connecting to %s at %s\n",
3418 GNUNET_i2s (peer),
3419 address);
3420 if (0 != strncmp (address,
3422 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3423 {
3424 GNUNET_break_op (0);
3425 return GNUNET_SYSERR;
3426 }
3427 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3428 in = tcp_address_to_sockaddr (path, &in_len);
3429
3430 if (NULL == in)
3431 {
3433 "Failed to setup TCP socket address\n");
3434 return GNUNET_SYSERR;
3435 }
3436
3438 "in %s\n",
3439 GNUNET_a2s (in, in_len));
3440
3443 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3444 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3446
3447 if (NULL != queue)
3448 {
3450 "Queue for %s already exists or is in construction\n", address);
3451 GNUNET_free (in);
3452 return GNUNET_NO;
3453 }
3454 switch (in->sa_family)
3455 {
3456 case AF_INET:
3457 v4 = (struct sockaddr_in *) in;
3458 if (0 == v4->sin_port)
3459 {
3460 is_natd = GNUNET_YES;
3462 sizeof(struct sockaddr),
3463 &key);
3466 &key))
3467 {
3469 "There is already a request reversal for `%s'at `%s'\n",
3470 GNUNET_i2s (peer),
3471 address);
3472 GNUNET_free (in);
3473 return GNUNET_SYSERR;
3474 }
3475 }
3476 break;
3477
3478 case AF_INET6:
3479 if (GNUNET_YES == disable_v6)
3480 {
3482 "IPv6 disabled, skipping %s\n", address);
3483 GNUNET_free (in);
3484 return GNUNET_SYSERR;
3485 }
3486 v6 = (struct sockaddr_in6 *) in;
3487 if (0 == v6->sin6_port)
3488 {
3490 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3491 GNUNET_i2s (peer),
3492 address);
3493 GNUNET_free (in);
3494 return GNUNET_SYSERR;
3495 }
3496 break;
3497
3498 default:
3499 GNUNET_assert (0);
3500 }
3501
3502 if (GNUNET_YES == is_natd)
3503 {
3504 struct sockaddr_in local_sa;
3505 struct PendingReversal *pending_reversal;
3506
3507 memset (&local_sa, 0, sizeof(local_sa));
3508 local_sa.sin_family = AF_INET;
3509 local_sa.sin_port = htons (bind_port);
3510 /* We leave sin_address at 0, let the kernel figure it out,
3511 even if our bind() is more specific. (May want to reconsider
3512 later.) */
3513 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3514 {
3516 "request reversal for `%s' at `%s' failed\n",
3517 GNUNET_i2s (peer),
3518 address);
3519 GNUNET_free (in);
3520 return GNUNET_SYSERR;
3521 }
3522 pending_reversal = GNUNET_new (struct PendingReversal);
3523 pending_reversal->in = in;
3526 &key,
3527 pending_reversal,
3529 pending_reversal->target = *peer;
3531 &
3533 in);
3535 "Created NAT WAIT connection to `%s' at `%s'\n",
3536 GNUNET_i2s (peer),
3537 GNUNET_a2s (in, sizeof (struct sockaddr)));
3538 }
3539 else
3540 {
3541 struct GNUNET_NETWORK_Handle *sock;
3542
3543 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3544 IPPROTO_TCP);
3545 if (NULL == sock)
3546 {
3548 "socket(%d) failed: %s",
3549 in->sa_family,
3550 strerror (errno));
3551 GNUNET_free (in);
3552 return GNUNET_SYSERR;
3553 }
3554 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3555 (errno != EINPROGRESS))
3556 {
3558 "connect to `%s' failed: %s",
3559 address,
3560 strerror (errno));
3562 GNUNET_free (in);
3563 return GNUNET_SYSERR;
3564 }
3565
3566 queue = GNUNET_new (struct Queue);
3567 queue->target = *peer;
3568 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3569 queue->key = queue_map_key;
3570 queue->address = in;
3571 queue->address_len = in_len;
3572 queue->sock = sock;
3574 boot_queue (queue);
3576 "booted queue with target %s\n",
3577 GNUNET_i2s (&queue->target));
3578 // queue->mq_awaits_continue = GNUNET_YES;
3579 queue->read_task =
3581 queue->sock,
3583 queue);
3584
3585
3587 "start kx mq_init\n");
3588
3590 queue->write_task =
3592 queue->sock,
3593 &queue_write,
3594 queue);
3595 }
3596
3597 return GNUNET_OK;
3598}
3599
3600
3609static int
3610get_lt_delete_it (void *cls,
3611 const struct GNUNET_HashCode *key,
3612 void *value)
3613{
3614 struct ListenTask *lt = value;
3615
3616 (void) cls;
3617 (void) key;
3618 if (NULL != lt->listen_task)
3619 {
3621 lt->listen_task = NULL;
3622 }
3623 if (NULL != lt->listen_sock)
3624 {
3626 lt->listen_sock = NULL;
3627 }
3628 GNUNET_free (lt);
3629 return GNUNET_OK;
3630}
3631
3632
3641static int
3642get_queue_delete_it (void *cls,
3643 const struct GNUNET_HashCode *target,
3644 void *value)
3645{
3646 struct Queue *queue = value;
3647
3648 (void) cls;
3649 (void) target;
3651 return GNUNET_OK;
3652}
3653
3654
3660static void
3661do_shutdown (void *cls)
3662{
3664 "Shutdown %s!\n",
3665 shutdown_running ? "running" : "not running");
3666
3668 return;
3669 else
3671
3672 while (NULL != proto_head)
3674 if (NULL != nat)
3675 {
3677 nat = NULL;
3678 }
3686 if (NULL != ch)
3687 {
3690 ch = NULL;
3691 }
3692 if (NULL != stats)
3693 {
3695 stats = NULL;
3696 }
3697 if (NULL != is)
3698 {
3700 is = NULL;
3701 }
3702 if (NULL != pils)
3703 {
3705 pils = NULL;
3706 }
3707 if (NULL != key_ring)
3708 {
3710 key_ring = NULL;
3711 }
3712 if (NULL != peerstore)
3713 {
3715 peerstore = NULL;
3716 }
3717 if (NULL != resolve_request_handle)
3718 {
3721 }
3723 "Shutdown done!\n");
3724}
3725
3726
3738static void
3739enc_notify_cb (void *cls,
3740 const struct GNUNET_PeerIdentity *sender,
3741 const struct GNUNET_MessageHeader *msg)
3742{
3743 (void) cls;
3744 (void) sender;
3745 (void) msg;
3746 GNUNET_break_op (0);
3747}
3748
3749
3763static void
3764nat_address_cb (void *cls,
3765 void **app_ctx,
3766 int add_remove,
3768 const struct sockaddr *addr,
3769 socklen_t addrlen)
3770{
3771 char *my_addr;
3773
3775 "nat address cb %s %s\n",
3776 add_remove ? "add" : "remove",
3777 GNUNET_a2s (addr, addrlen));
3778
3779 if (GNUNET_YES == add_remove)
3780 {
3782
3783 GNUNET_asprintf (&my_addr,
3784 "%s-%s",
3786 GNUNET_a2s (addr, addrlen));
3787 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3788 ai =
3790 my_addr,
3791 nt,
3793 GNUNET_free (my_addr);
3794 *app_ctx = ai;
3795 }
3796 else
3797 {
3798 ai = *app_ctx;
3800 *app_ctx = NULL;
3801 }
3802}
3803
3804
3808static void
3809add_addr (struct sockaddr *in, socklen_t in_len)
3810{
3811
3812 struct Addresses *saddrs;
3813
3815 "add address %s\n",
3816 GNUNET_a2s (in, in_len));
3817
3818 saddrs = GNUNET_new (struct Addresses);
3819 saddrs->addr = in;
3820 saddrs->addr_len = in_len;
3822
3824 "after add address %s\n",
3825 GNUNET_a2s (in, in_len));
3826
3828 "add address %s\n",
3829 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3830
3831 addrs_lens++;
3832}
3833
3834
3842static int
3843init_socket (struct sockaddr *addr,
3844 socklen_t in_len)
3845{
3846 struct sockaddr_storage in_sto;
3847 socklen_t sto_len;
3848 struct GNUNET_NETWORK_Handle *listen_sock;
3849 struct ListenTask *lt;
3850 int sockfd;
3851 struct GNUNET_HashCode h_sock;
3852
3853 if (NULL == addr)
3854 {
3856 "Address is NULL.\n");
3857 return GNUNET_SYSERR;
3858 }
3859
3861 "address %s\n",
3862 GNUNET_a2s (addr, in_len));
3863
3864 listen_sock =
3865 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3866 if (NULL == listen_sock)
3867 {
3869 return GNUNET_SYSERR;
3870 }
3871
3872 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3873 {
3875 GNUNET_NETWORK_socket_close (listen_sock);
3876 listen_sock = NULL;
3877 return GNUNET_SYSERR;
3878 }
3879
3880 if (GNUNET_OK !=
3881 GNUNET_NETWORK_socket_listen (listen_sock,
3882 5))
3883 {
3885 "listen");
3886 GNUNET_NETWORK_socket_close (listen_sock);
3887 listen_sock = NULL;
3888 return GNUNET_SYSERR;
3889 }
3890
3891 /* We might have bound to port 0, allowing the OS to figure it out;
3892 thus, get the real IN-address from the socket */
3893 sto_len = sizeof(in_sto);
3894
3895 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3896 (struct sockaddr *) &in_sto,
3897 &sto_len))
3898 {
3899 memcpy (&in_sto, addr, in_len);
3900 sto_len = in_len;
3901 }
3902
3903 // addr = (struct sockaddr *) &in_sto;
3904 in_len = sto_len;
3906 "Bound to `%s'\n",
3907 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3908 if (NULL == stats)
3909 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3910
3911 if (NULL == is)
3913
3914 /* start listening */
3915
3916 lt = GNUNET_new (struct ListenTask);
3917 lt->listen_sock = listen_sock;
3918
3920 listen_sock,
3921 &listen_cb,
3922 lt);
3923
3925 "creating hash\n");
3926 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3927 GNUNET_CRYPTO_hash (&sockfd,
3928 sizeof(int),
3929 &h_sock);
3930
3932 "creating map\n");
3933 if (NULL == lt_map)
3935
3937 "creating map entry\n");
3940 &h_sock,
3941 lt,
3943
3945 "map entry created\n");
3946
3947 if (NULL == queue_map)
3949
3950 if (NULL == ch)
3955 &mq_init,
3956 NULL,
3958 NULL,
3959 NULL);
3960
3961 if (NULL == ch)
3962 {
3963 GNUNET_break (0);
3964 if (NULL != resolve_request_handle)
3967 return GNUNET_SYSERR;
3968 }
3969
3970 add_addr (addr, in_len);
3971 return GNUNET_OK;
3972
3973}
3974
3975
3979static void
3980nat_register ()
3981{
3982 struct sockaddr **saddrs;
3983 socklen_t *saddr_lens;
3984 int i;
3985 size_t len;
3986
3988 "starting nat register!\n");
3989 len = 0;
3990 i = 0;
3991 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3992 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3993 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3994 {
3996 "registering address %s\n",
3997 GNUNET_a2s (pos->addr, pos->addr_len));
3998
3999 saddr_lens[i] = pos->addr_len;
4000 len += saddr_lens[i];
4001 saddrs[i] = GNUNET_memdup (pos->addr, saddr_lens[i]);
4002 i++;
4003 }
4004
4006 "registering addresses %lu %lu %lu %lu\n",
4007 (addrs_lens) * sizeof(struct sockaddr *),
4008 (addrs_lens) * sizeof(socklen_t),
4009 len,
4013 IPPROTO_TCP,
4014 addrs_lens,
4015 (const struct sockaddr **) saddrs,
4016 saddr_lens,
4019 NULL /* closure */);
4020 for (i = addrs_lens - 1; i >= 0; i--)
4021 GNUNET_free (saddrs[i]);
4022 GNUNET_free (saddrs);
4023 GNUNET_free (saddr_lens);
4024
4025 if (NULL == nat)
4026 {
4027 GNUNET_break (0);
4028 if (NULL != resolve_request_handle)
4031 }
4032}
4033
4034
4042static void
4043init_socket_resolv (void *cls,
4044 const struct sockaddr *addr,
4045 socklen_t in_len)
4046{
4047 struct sockaddr_in *v4;
4048 struct sockaddr_in6 *v6;
4049 struct sockaddr *in;
4050
4051 (void) cls;
4052 if (NULL != addr)
4053 {
4054 if (AF_INET == addr->sa_family)
4055 {
4056 v4 = (struct sockaddr_in *) addr;
4057 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
4058 }
4059 else if (AF_INET6 == addr->sa_family)
4060 {
4061 v6 = (struct sockaddr_in6 *) addr;
4062 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
4063 }
4064 else
4065 {
4067 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
4068 addr->sa_family,
4069 AF_INET,
4070 AF_INET6);
4071 return;
4072 }
4073 init_socket (in, in_len);
4074 }
4075 else
4076 {
4078 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4079 if (NULL == addrs_head)
4080 {
4082 "Resolver finished resolving, but we do not listen to an address!.\n");
4083 return;
4084 }
4085 nat_register ();
4086 }
4087}
4088
4089
4098static void
4099run (void *cls,
4100 char *const *args,
4101 const char *cfgfile,
4102 const struct GNUNET_CONFIGURATION_Handle *c)
4103{
4104 char *bindto;
4105 struct sockaddr *in;
4106 socklen_t in_len;
4107 struct sockaddr_in v4;
4108 struct sockaddr_in6 v6;
4109 char *start;
4110 unsigned int port;
4111 char dummy[2];
4112 char *rest = NULL;
4113 struct PortOnlyIpv4Ipv6 *po;
4114 socklen_t addr_len_ipv4;
4115 socklen_t addr_len_ipv6;
4116
4117 (void) cls;
4118
4120 memset (&v4,0,sizeof(struct sockaddr_in));
4121 memset (&v6,0,sizeof(struct sockaddr_in6));
4122 cfg = c;
4123 if (GNUNET_OK !=
4126 "BINDTO",
4127 &bindto))
4128 {
4131 "BINDTO");
4132 return;
4133 }
4134 if (GNUNET_OK !=
4137 "MAX_QUEUE_LENGTH",
4139 {
4141 }
4142 if (GNUNET_OK !=
4145 "REKEY_INTERVAL",
4147 {
4149 }
4150 if (GNUNET_OK !=
4153 "REKEY_MAX_BYTES",
4155 {
4157 }
4159 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4160 (GNUNET_YES ==
4163 "DISABLE_V6")))
4164 {
4166 }
4168 GNUNET_assert (NULL != key_ring);
4169 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
4170 GNUNET_assert (NULL != pils);
4172 if (NULL == peerstore)
4173 {
4174 GNUNET_free (bindto);
4175 GNUNET_break (0);
4177 return;
4178 }
4179
4181
4182 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4183 {
4187 "address po %s\n",
4189 if (NULL != po->addr_ipv4)
4190 {
4192 }
4193 if (NULL != po->addr_ipv6)
4194 {
4197 }
4198 GNUNET_free (po);
4199 nat_register ();
4200 GNUNET_free (bindto);
4201 return;
4202 }
4203
4204 start = extract_address (bindto);
4205 // FIXME: check for NULL == start...
4206 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4207 {
4208 bind_port = extract_port (bindto);
4209
4211 init_socket (in, in_len);
4212 nat_register ();
4214 GNUNET_free (bindto);
4215 return;
4216 }
4217
4218 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4219 {
4220 bind_port = extract_port (bindto);
4222 init_socket (in, in_len);
4223 nat_register ();
4225 GNUNET_free (bindto);
4226 return;
4227 }
4228
4229 bind_port = extract_port (bindto);
4231 ":",
4232 &rest),
4233 AF_UNSPEC,
4236 &port);
4237
4238 GNUNET_free (bindto);
4240}
4241
4242
4250int
4251main (int argc, char *const *argv)
4252{
4253 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4255 };
4256 int ret;
4257
4259 "Starting tcp communicator\n");
4260
4261 ret = (GNUNET_OK ==
4263 argc,
4264 argv,
4265 "gnunet-communicator-tcp",
4266 _ ("GNUnet TCP communicator"),
4267 options,
4268 &run,
4269 NULL))
4270 ? 0
4271 : 1;
4272 return ret;
4273}
4274
4275
4276/* 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 calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
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 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.
static void setup_cipher(const struct GNUNET_ShortHashCode *prk, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
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 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(enum GNUNET_CRYPTO_Quality mode, 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...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
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...
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.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#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:41
#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.
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn't this be the standard hmac function and the abo...
@ 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:407
#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:604
#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:665
#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
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.
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.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
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_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_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
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_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 3277 of file gnunet-communicator-tcp.c.

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

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_HashCode hmac_secret,
const void *  buf,
size_t  buf_size,
struct GNUNET_ShortHashCode smac 
)
static

Compute mac over buf, and ratched the hmac_secret.

Parameters
[in,out]hmac_secretsecret for HMAC calculation
bufbuffer to MAC
buf_sizenumber of bytes in buf
[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_raw (hmac_secret,
1095 sizeof(struct GNUNET_HashCode),
1096 buf,
1097 buf_size,
1098 &mac);
1099 /* truncate to `struct GNUNET_ShortHashCode` */
1100 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1101 /* ratchet hmac key */
1102 GNUNET_CRYPTO_hash (hmac_secret,
1103 sizeof(struct GNUNET_HashCode),
1104 hmac_secret);
1105}

References GNUNET_CRYPTO_hash(), and GNUNET_CRYPTO_hmac_raw().

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

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

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

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

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

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

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

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

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_HashCode 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 1249 of file gnunet-communicator-tcp.c.

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

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

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

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

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

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

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

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 1404 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 1429 of file gnunet-communicator-tcp.c.

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

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

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

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

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

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

1581{
1582 const struct GNUNET_PeerIdentity *my_identity;
1584 struct TCPConfirmationAck tca;
1585 struct TcpHandshakeAckSignature thas;
1586
1590
1592 "sending challenge\n");
1593
1594 tca.header.type = ntohs (
1596 tca.header.size = ntohs (sizeof(tca));
1597 tca.challenge = challenge;
1598 tca.sender = *my_identity;
1599 tca.monotonic_time =
1601 thas.purpose.purpose = htonl (
1603 thas.purpose.size = htonl (sizeof(thas));
1604 thas.sender = *my_identity;
1605 thas.receiver = queue->target;
1606 thas.monotonic_time = tca.monotonic_time;
1607 thas.challenge = tca.challenge;
1609 &thas,
1610 &tca.sender_sig);
1611 GNUNET_assert (0 ==
1612 gcry_cipher_encrypt (queue->out_cipher,
1613 &queue->cwrite_buf[queue->cwrite_off],
1614 sizeof(tca),
1615 &tca,
1616 sizeof(tca)));
1617 queue->cwrite_off += sizeof(tca);
1619 "sending challenge done\n");
1620}

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

1631{
1632 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1634 queue->rekey_left_bytes =
1636}

References GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_TIME_relative_to_absolute(), queue(), rekey_interval, rekey_max_bytes, and setup_cipher().

Referenced by inject_rekey(), and start_initial_kx_out().

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

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

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

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

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

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

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

1772{
1773 if (NULL != pq->listen_sock)
1774 {
1776 pq->listen_sock = NULL;
1777 }
1778 if (NULL != pq->read_task)
1779 {
1781 pq->read_task = NULL;
1782 }
1783 if (NULL != pq->write_task)
1784 {
1786 pq->write_task = NULL;
1787 }
1788 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1790 GNUNET_free (pq->address);
1792 GNUNET_free (pq);
1793}

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

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

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

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

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

1948{
1949 const struct GNUNET_MessageHeader *hdr;
1950 const struct TCPConfirmationAck *tca;
1951 const struct TCPBox *box;
1952 const struct TCPRekey *rekey;
1953 const struct TCPFinish *fin;
1954 struct TCPRekey rekeyz;
1955 struct TCPFinish finz;
1956 struct GNUNET_ShortHashCode tmac;
1957 uint16_t type;
1958 size_t size = 0;
1959 struct TcpHandshakeAckSignature thas;
1960 const struct GNUNET_PeerIdentity *my_identity;
1961 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1962
1964 "try handle plaintext!\n");
1965
1966 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1967 if ((sizeof(*hdr) > queue->pread_off))
1968 {
1970 "Handling plaintext, not even a header!\n");
1971 return 0; /* not even a header */
1972 }
1973
1974 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1976 {
1978 "Already received data of size %lu bigger than KX size %lu!\n",
1979 queue->unverified_size,
1981 GNUNET_break_op (0);
1983 return 0;
1984 }
1985
1986 type = ntohs (hdr->type);
1987 switch (type)
1988 {
1990 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1992 "start processing ack\n");
1993 if (sizeof(*tca) > queue->pread_off)
1994 {
1996 "Handling plaintext size of tca greater than pread offset.\n")
1997 ;
1998 return 0;
1999 }
2000 if (ntohs (hdr->size) != sizeof(*tca))
2001 {
2003 "Handling plaintext size does not match message type.\n");
2004 GNUNET_break_op (0);
2006 return 0;
2007 }
2008
2011
2012 thas.purpose.purpose = htonl (
2014 thas.purpose.size = htonl (sizeof(thas));
2015 thas.sender = tca->sender;
2016 thas.receiver = *my_identity;
2017 thas.monotonic_time = tca->monotonic_time;
2018 thas.challenge = tca->challenge;
2019
2022 &thas,
2023 &tca->sender_sig,
2024 &tca->sender.public_key))
2025 {
2027 "Verification of signature failed!\n");
2028 GNUNET_break (0);
2030 return 0;
2031 }
2032 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
2033 {
2035 "Challenge in TCPConfirmationAck not correct!\n");
2036 GNUNET_break (0);
2038 return 0;
2039 }
2040
2041 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
2042 peerstore,
2043 "transport_tcp_communicator",
2044 &queue->target,
2047 queue);
2048
2050 "Handling plaintext, ack processed!\n");
2051
2053 {
2054 send_challenge (queue->challenge_received, queue);
2055 queue->write_task =
2057 queue->sock,
2058 &queue_write,
2059 queue);
2060 }
2061 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2062 {
2064 queue->address->sa_family, NULL);
2065 }
2066
2071 queue->initial_core_kx_done = GNUNET_YES;
2072
2073 {
2074 char *foreign_addr;
2075
2076 switch (queue->address->sa_family)
2077 {
2078 case AF_INET:
2079 GNUNET_asprintf (&foreign_addr,
2080 "%s-%s",
2082 GNUNET_a2s (queue->address, queue->address_len));
2083 break;
2084
2085 case AF_INET6:
2086 GNUNET_asprintf (&foreign_addr,
2087 "%s-%s",
2089 GNUNET_a2s (queue->address, queue->address_len));
2090 break;
2091
2092 default:
2093 GNUNET_assert (0);
2094 }
2096 &queue->target,
2097 foreign_addr,
2098 UINT16_MAX, /* no MTU */
2100 0, /* Priority */
2101 queue->nt,
2102 queue->cs,
2103 queue->mq);
2104
2105 GNUNET_free (foreign_addr);
2106 }
2107
2108 size = ntohs (hdr->size);
2109 break;
2111 /* Special case: header size excludes box itself! */
2112 box = (const struct TCPBox *) queue->pread_buf;
2113 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2114 return 0;
2115 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2116 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2117 {
2118 GNUNET_break_op (0);
2120 return 0;
2121 }
2122 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2123 size = ntohs (hdr->size) + sizeof(*box);
2125 "Handling plaintext, box processed!\n");
2127 "# bytes decrypted with BOX",
2128 size,
2129 GNUNET_NO);
2131 "# messages decrypted with BOX",
2132 1,
2133 GNUNET_NO);
2134 break;
2135
2137 rekey = (const struct TCPRekey *) queue->pread_buf;
2138 if (sizeof(*rekey) > queue->pread_off)
2139 return 0;
2140 if (ntohs (hdr->size) != sizeof(*rekey))
2141 {
2142 GNUNET_break_op (0);
2144 return 0;
2145 }
2146 rekeyz = *rekey;
2147 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2148 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2149 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2150 {
2151 GNUNET_break_op (0);
2153 return 0;
2154 }
2155 do_rekey (queue, rekey);
2156 size = ntohs (hdr->size);
2158 "Handling plaintext, rekey processed!\n");
2160 "# rekeying successful",
2161 1,
2162 GNUNET_NO);
2163 break;
2164
2166 fin = (const struct TCPFinish *) queue->pread_buf;
2167 if (sizeof(*fin) > queue->pread_off)
2168 return 0;
2169 if (ntohs (hdr->size) != sizeof(*fin))
2170 {
2171 GNUNET_break_op (0);
2173 return 0;
2174 }
2175 finz = *fin;
2176 memset (&finz.hmac, 0, sizeof(finz.hmac));
2177 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2178 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2179 {
2180 GNUNET_break_op (0);
2182 return 0;
2183 }
2184 /* handle FINISH by destroying queue */
2187 "Handling plaintext, finish processed!\n");
2188 break;
2189
2190 default:
2192 "Handling plaintext, nothing processed!\n");
2193 GNUNET_break_op (0);
2195 return 0;
2196 }
2197 GNUNET_assert (0 != size);
2198 if (-1 != queue->unverified_size)
2199 queue->unverified_size += size;
2200 return size;
2201}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2743{
2744 queue->nt =
2745 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2747 queue_map,
2748 &queue->key,
2749 queue,
2752 "# queues active",
2754 GNUNET_NO);
2755 queue->timeout =
2758 &mq_destroy,
2759 &mq_cancel,
2760 queue,
2761 NULL,
2762 &mq_error,
2763 queue);
2764}

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

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

References cfg, TcpHandshakeSignature::challenge, TcpHandshakeSignature::ephemeral, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_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 2832 of file gnunet-communicator-tcp.c.

2833{
2835 struct GNUNET_ShortHashCode k;
2836
2838 &c, &k);
2839 setup_out_cipher (queue, &k);
2840 transmit_kx (queue, &c);
2841}

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

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

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

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

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

2946{
2947 const struct GNUNET_PeerIdentity *my_identity;
2948 struct TcpHandshakeSignature ths;
2950
2953
2955 0 ==
2956 gcry_cipher_decrypt (queue->in_cipher,
2957 tc,
2958 sizeof(*tc),
2959 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2960 sizeof(*tc)));
2961 ths.purpose.purpose = htonl (
2963 ths.purpose.size = htonl (sizeof(ths));
2964 ths.sender = tc->sender;
2965 ths.receiver = *my_identity;
2966 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2967 ths.monotonic_time = tc->monotonic_time;
2968 ths.challenge = tc->challenge;
2971 &ths,
2972 &tc->sender_sig,
2973 &tc->sender.public_key);
2974 if (GNUNET_YES == ret)
2975 queue->handshake_monotime_get =
2977 "transport_tcp_communicator",
2978 &queue->target,
2981 queue);
2982 return ret;
2983}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3646{
3647 struct Queue *queue = value;
3648
3649 (void) cls;
3650 (void) target;
3652 return GNUNET_OK;
3653}

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

3663{
3665 "Shutdown %s!\n",
3666 shutdown_running ? "running" : "not running");
3667
3669 return;
3670 else
3672
3673 while (NULL != proto_head)
3675 if (NULL != nat)
3676 {
3678 nat = NULL;
3679 }
3687 if (NULL != ch)
3688 {
3691 ch = NULL;
3692 }
3693 if (NULL != stats)
3694 {
3696 stats = NULL;
3697 }
3698 if (NULL != is)
3699 {
3701 is = NULL;
3702 }
3703 if (NULL != pils)
3704 {
3706 pils = NULL;
3707 }
3708 if (NULL != key_ring)
3709 {
3711 key_ring = NULL;
3712 }
3713 if (NULL != peerstore)
3714 {
3716 peerstore = NULL;
3717 }
3718 if (NULL != resolve_request_handle)
3719 {
3722 }
3724 "Shutdown done!\n");
3725}

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

3743{
3744 (void) cls;
3745 (void) sender;
3746 (void) msg;
3747 GNUNET_break_op (0);
3748}

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

3771{
3772 char *my_addr;
3774
3776 "nat address cb %s %s\n",
3777 add_remove ? "add" : "remove",
3778 GNUNET_a2s (addr, addrlen));
3779
3780 if (GNUNET_YES == add_remove)
3781 {
3783
3784 GNUNET_asprintf (&my_addr,
3785 "%s-%s",
3787 GNUNET_a2s (addr, addrlen));
3788 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3789 ai =
3791 my_addr,
3792 nt,
3794 GNUNET_free (my_addr);
3795 *app_ctx = ai;
3796 }
3797 else
3798 {
3799 ai = *app_ctx;
3801 *app_ctx = NULL;
3802 }
3803}

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

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

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

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

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

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

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

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

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

4104{
4105 char *bindto;
4106 struct sockaddr *in;
4107 socklen_t in_len;
4108 struct sockaddr_in v4;
4109 struct sockaddr_in6 v6;
4110 char *start;
4111 unsigned int port;
4112 char dummy[2];
4113 char *rest = NULL;
4114 struct PortOnlyIpv4Ipv6 *po;
4115 socklen_t addr_len_ipv4;
4116 socklen_t addr_len_ipv6;
4117
4118 (void) cls;
4119
4121 memset (&v4,0,sizeof(struct sockaddr_in));
4122 memset (&v6,0,sizeof(struct sockaddr_in6));
4123 cfg = c;
4124 if (GNUNET_OK !=
4127 "BINDTO",
4128 &bindto))
4129 {
4132 "BINDTO");
4133 return;
4134 }
4135 if (GNUNET_OK !=
4138 "MAX_QUEUE_LENGTH",
4140 {
4142 }
4143 if (GNUNET_OK !=
4146 "REKEY_INTERVAL",
4148 {
4150 }
4151 if (GNUNET_OK !=
4154 "REKEY_MAX_BYTES",
4156 {
4158 }
4160 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4161 (GNUNET_YES ==
4164 "DISABLE_V6")))
4165 {
4167 }
4169 GNUNET_assert (NULL != key_ring);
4170 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
4171 GNUNET_assert (NULL != pils);
4173 if (NULL == peerstore)
4174 {
4175 GNUNET_free (bindto);
4176 GNUNET_break (0);
4178 return;
4179 }
4180
4182
4183 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4184 {
4188 "address po %s\n",
4190 if (NULL != po->addr_ipv4)
4191 {
4193 }
4194 if (NULL != po->addr_ipv6)
4195 {
4198 }
4199 GNUNET_free (po);
4200 nat_register ();
4201 GNUNET_free (bindto);
4202 return;
4203 }
4204
4205 start = extract_address (bindto);
4206 // FIXME: check for NULL == start...
4207 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4208 {
4209 bind_port = extract_port (bindto);
4210
4212 init_socket (in, in_len);
4213 nat_register ();
4215 GNUNET_free (bindto);
4216 return;
4217 }
4218
4219 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4220 {
4221 bind_port = extract_port (bindto);
4223 init_socket (in, in_len);
4224 nat_register ();
4226 GNUNET_free (bindto);
4227 return;
4228 }
4229
4230 bind_port = extract_port (bindto);
4232 ":",
4233 &rest),
4234 AF_UNSPEC,
4237 &port);
4238
4239 GNUNET_free (bindto);
4241}

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

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

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