/work/toxcore/onion_announce.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2018 The TokTok team. |
3 | | * Copyright © 2013 Tox project. |
4 | | */ |
5 | | |
6 | | /** |
7 | | * Implementation of the announce part of docs/Prevent_Tracking.txt |
8 | | */ |
9 | | #ifndef C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H |
10 | | #define C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H |
11 | | |
12 | | #include "logger.h" |
13 | | #include "onion.h" |
14 | | #include "timed_auth.h" |
15 | | |
16 | 12.5M | #define ONION_ANNOUNCE_MAX_ENTRIES 160 |
17 | 21.4M | #define ONION_ANNOUNCE_TIMEOUT 300 |
18 | 1.34M | #define ONION_PING_ID_SIZE TIMED_AUTH_SIZE |
19 | 65.1k | #define ONION_MAX_EXTRA_DATA_SIZE 136 |
20 | | |
21 | 849k | #define ONION_ANNOUNCE_SENDBACK_DATA_LENGTH (sizeof(uint64_t)) |
22 | | |
23 | 528 | #define MAX_SENT_GC_NODES 1 |
24 | 226k | #define ONION_ANNOUNCE_REQUEST_MIN_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_MAC_SIZE) |
25 | 4.83k | #define ONION_ANNOUNCE_REQUEST_MAX_SIZE (ONION_ANNOUNCE_REQUEST_MIN_SIZE + ONION_MAX_EXTRA_DATA_SIZE) |
26 | | |
27 | 249k | #define ONION_ANNOUNCE_RESPONSE_MIN_SIZE (2 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE + ONION_PING_ID_SIZE + CRYPTO_MAC_SIZE) |
28 | 61.8k | #define ONION_ANNOUNCE_RESPONSE_MAX_SIZE (ONION_ANNOUNCE_RESPONSE_MIN_SIZE + ONION_MAX_EXTRA_DATA_SIZE * MAX_SENT_NODES) |
29 | | |
30 | | /* TODO: DEPRECATE */ |
31 | 61.3k | #define ONION_ANNOUNCE_REQUEST_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_MAC_SIZE) |
32 | | |
33 | 8.32k | #define ONION_DATA_RESPONSE_MIN_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE) |
34 | | |
35 | 56.7k | #define ONION_DATA_REQUEST_MIN_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE) |
36 | 34.3k | #define MAX_DATA_REQUEST_SIZE (ONION_MAX_DATA_SIZE - ONION_DATA_REQUEST_MIN_SIZE) |
37 | | |
38 | | typedef struct Onion_Announce Onion_Announce; |
39 | | |
40 | | /** These two are not public; they are for tests only! */ |
41 | | non_null() |
42 | | uint8_t *onion_announce_entry_public_key(Onion_Announce *onion_a, uint32_t entry); |
43 | | non_null() |
44 | | void onion_announce_entry_set_time(Onion_Announce *onion_a, uint32_t entry, uint64_t announce_time); |
45 | | |
46 | | /** @brief Create an onion announce request packet in packet of max_packet_length. |
47 | | * |
48 | | * Recommended value for max_packet_length is ONION_ANNOUNCE_REQUEST_MIN_SIZE. |
49 | | * |
50 | | * dest_client_id is the public key of the node the packet will be sent to. |
51 | | * public_key and secret_key is the kepair which will be used to encrypt the request. |
52 | | * ping_id is the ping id that will be sent in the request. |
53 | | * client_id is the client id of the node we are searching for. |
54 | | * data_public_key is the public key we want others to encrypt their data packets with. |
55 | | * sendback_data is the data of ONION_ANNOUNCE_SENDBACK_DATA_LENGTH length that we expect to |
56 | | * receive back in the response. |
57 | | * |
58 | | * return -1 on failure. |
59 | | * return packet length on success. |
60 | | */ |
61 | | non_null() |
62 | | int create_announce_request(const Random *rng, uint8_t *packet, uint16_t max_packet_length, const uint8_t *dest_client_id, |
63 | | const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, |
64 | | const uint8_t *data_public_key, uint64_t sendback_data); |
65 | | |
66 | | /** @brief Create an onion data request packet in packet of max_packet_length. |
67 | | * |
68 | | * Recommended value for max_packet_length is ONION_ANNOUNCE_REQUEST_SIZE. |
69 | | * |
70 | | * public_key is the real public key of the node which we want to send the data of length length to. |
71 | | * encrypt_public_key is the public key used to encrypt the data packet. |
72 | | * |
73 | | * nonce is the nonce to encrypt this packet with |
74 | | * |
75 | | * return -1 on failure. |
76 | | * return 0 on success. |
77 | | */ |
78 | | non_null() |
79 | | int create_data_request(const Random *rng, uint8_t *packet, uint16_t max_packet_length, const uint8_t *public_key, |
80 | | const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length); |
81 | | |
82 | | /** @brief Create and send an onion announce request packet. |
83 | | * |
84 | | * path is the path the request will take before it is sent to dest. |
85 | | * |
86 | | * public_key and secret_key is the kepair which will be used to encrypt the request. |
87 | | * ping_id is the ping id that will be sent in the request. |
88 | | * client_id is the client id of the node we are searching for. |
89 | | * data_public_key is the public key we want others to encrypt their data packets with. |
90 | | * sendback_data is the data of ONION_ANNOUNCE_SENDBACK_DATA_LENGTH length that we expect to |
91 | | * receive back in the response. |
92 | | * |
93 | | * return -1 on failure. |
94 | | * return 0 on success. |
95 | | */ |
96 | | non_null() |
97 | | int send_announce_request( |
98 | | const Logger *log, const Networking_Core *net, const Random *rng, |
99 | | const Onion_Path *path, const Node_format *dest, |
100 | | const uint8_t *public_key, const uint8_t *secret_key, |
101 | | const uint8_t *ping_id, const uint8_t *client_id, |
102 | | const uint8_t *data_public_key, uint64_t sendback_data); |
103 | | |
104 | | /** @brief Create and send an onion data request packet. |
105 | | * |
106 | | * path is the path the request will take before it is sent to dest. |
107 | | * (if dest knows the person with the public_key they should |
108 | | * send the packet to that person in the form of a response) |
109 | | * |
110 | | * public_key is the real public key of the node which we want to send the data of length length to. |
111 | | * encrypt_public_key is the public key used to encrypt the data packet. |
112 | | * |
113 | | * nonce is the nonce to encrypt this packet with |
114 | | * |
115 | | * The maximum length of data is MAX_DATA_REQUEST_SIZE. |
116 | | * |
117 | | * return -1 on failure. |
118 | | * return 0 on success. |
119 | | */ |
120 | | non_null() |
121 | | int send_data_request( |
122 | | const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest, |
123 | | const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, |
124 | | const uint8_t *data, uint16_t length); |
125 | | |
126 | | |
127 | | typedef int pack_extra_data_cb(void *object, const Logger *logger, const Mono_Time *mono_time, |
128 | | uint8_t num_nodes, uint8_t *plain, uint16_t plain_size, |
129 | | uint8_t *response, uint16_t response_size, uint16_t offset); |
130 | | |
131 | | non_null() |
132 | | void onion_announce_extra_data_callback(Onion_Announce *onion_a, uint16_t extra_data_max_size, |
133 | | pack_extra_data_cb *extra_data_callback, void *extra_data_object); |
134 | | |
135 | | non_null() |
136 | | Onion_Announce *new_onion_announce(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht); |
137 | | |
138 | | nullable(1) |
139 | | void kill_onion_announce(Onion_Announce *onion_a); |
140 | | |
141 | | #endif /* C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H */ |