mirror of
https://github.com/TokTok/c-toxcore
synced 2026-05-25 20:44:29 +00:00
Make DHT a module-private type.
This commit is contained in:
@@ -51,8 +51,7 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(message, "Bound successfully to ", strlen("Bound successfully to ")) ||
|
||||
strncmp(message, "Found node in LAN: ", strlen("Found node in LAN: "))) {
|
||||
if (strncmp(message, "Bound successfully to ", strlen("Bound successfully to "))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+32
-22
@@ -102,7 +102,8 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui
|
||||
#if 0
|
||||
print_client_id(packet, length);
|
||||
#endif
|
||||
int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
||||
int len = decrypt_data(test_3_pub_key, dht_get_self_secret_key(onion->dht),
|
||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
|
||||
1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain);
|
||||
|
||||
@@ -140,7 +141,7 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui
|
||||
return 1;
|
||||
}
|
||||
|
||||
int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion->dht->self_secret_key, packet + 1,
|
||||
int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, dht_get_self_secret_key(onion->dht), packet + 1,
|
||||
packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain);
|
||||
|
||||
if (len == -1) {
|
||||
@@ -165,12 +166,12 @@ START_TEST(test_basic)
|
||||
|
||||
IP_Port on1 = {ip, net_port(onion1->net)};
|
||||
Node_format n1;
|
||||
memcpy(n1.public_key, onion1->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(n1.public_key, dht_get_self_public_key(onion1->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
n1.ip_port = on1;
|
||||
|
||||
IP_Port on2 = {ip, net_port(onion2->net)};
|
||||
Node_format n2;
|
||||
memcpy(n2.public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(n2.public_key, dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
n2.ip_port = on2;
|
||||
|
||||
Node_format nodes[4];
|
||||
@@ -208,9 +209,12 @@ START_TEST(test_basic)
|
||||
uint64_t s;
|
||||
memcpy(&s, sb_data, sizeof(uint64_t));
|
||||
memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key,
|
||||
onion1->dht->self_secret_key,
|
||||
zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s);
|
||||
ret = send_announce_request(onion1->net, &path, nodes[3],
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
dht_get_self_secret_key(onion1->dht),
|
||||
zeroes,
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
dht_get_self_public_key(onion1->dht), s);
|
||||
ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet.");
|
||||
handled_test_3 = 0;
|
||||
|
||||
@@ -222,13 +226,18 @@ START_TEST(test_basic)
|
||||
|
||||
random_bytes(sb_data, sizeof(sb_data));
|
||||
memcpy(&s, sb_data, sizeof(uint64_t));
|
||||
memcpy(onion_announce_entry_public_key(onion2_a, 1), onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(onion_announce_entry_public_key(onion2_a, 1), dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
onion_announce_entry_set_time(onion2_a, 1, unix_time());
|
||||
networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
|
||||
send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key,
|
||||
test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s);
|
||||
send_announce_request(onion1->net, &path, nodes[3],
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
dht_get_self_secret_key(onion1->dht),
|
||||
test_3_ping_id,
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
dht_get_self_public_key(onion1->dht), s);
|
||||
|
||||
while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2), onion1->dht->self_public_key,
|
||||
while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2),
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
CRYPTO_PUBLIC_KEY_SIZE) != 0) {
|
||||
do_onion(onion1);
|
||||
do_onion(onion2);
|
||||
@@ -240,8 +249,9 @@ START_TEST(test_basic)
|
||||
ck_assert_msg((onion3 != NULL), "Onion failed initializing.");
|
||||
|
||||
random_nonce(nonce);
|
||||
ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key,
|
||||
onion1->dht->self_public_key,
|
||||
ret = send_data_request(onion3->net, &path, nodes[3].ip_port,
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
dht_get_self_public_key(onion1->dht),
|
||||
nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo"));
|
||||
ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet.");
|
||||
handled_test_4 = 0;
|
||||
@@ -258,7 +268,7 @@ START_TEST(test_basic)
|
||||
{
|
||||
Onion *onion = onion1;
|
||||
|
||||
Networking_Core *net = onion->dht->net;
|
||||
Networking_Core *net = dht_get_net(onion->dht);
|
||||
DHT *dht = onion->dht;
|
||||
kill_onion(onion);
|
||||
kill_DHT(dht);
|
||||
@@ -268,7 +278,7 @@ START_TEST(test_basic)
|
||||
{
|
||||
Onion *onion = onion2;
|
||||
|
||||
Networking_Core *net = onion->dht->net;
|
||||
Networking_Core *net = dht_get_net(onion->dht);
|
||||
DHT *dht = onion->dht;
|
||||
kill_onion(onion);
|
||||
kill_DHT(dht);
|
||||
@@ -278,7 +288,7 @@ START_TEST(test_basic)
|
||||
{
|
||||
Onion *onion = onion3;
|
||||
|
||||
Networking_Core *net = onion->dht->net;
|
||||
Networking_Core *net = dht_get_net(onion->dht);
|
||||
DHT *dht = onion->dht;
|
||||
kill_onion(onion);
|
||||
kill_DHT(dht);
|
||||
@@ -361,7 +371,7 @@ static void do_onions(Onions *on)
|
||||
|
||||
static void kill_onions(Onions *on)
|
||||
{
|
||||
Networking_Core *net = on->onion->dht->net;
|
||||
Networking_Core *net = dht_get_net(on->onion->dht);
|
||||
DHT *dht = on->onion->dht;
|
||||
Net_Crypto *c = onion_get_net_crypto(on->onion_c);
|
||||
kill_onion_client(on->onion_c);
|
||||
@@ -444,11 +454,11 @@ START_TEST(test_announce)
|
||||
|
||||
for (i = 3; i < NUM_ONIONS; ++i) {
|
||||
IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)};
|
||||
DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key);
|
||||
DHT_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht));
|
||||
IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)};
|
||||
DHT_bootstrap(onions[i]->onion->dht, ip_port1, onions[i - 2]->onion->dht->self_public_key);
|
||||
DHT_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht));
|
||||
IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)};
|
||||
DHT_bootstrap(onions[i]->onion->dht, ip_port2, onions[i - 3]->onion->dht->self_public_key);
|
||||
DHT_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht));
|
||||
}
|
||||
|
||||
uint32_t connected = 0;
|
||||
@@ -474,8 +484,8 @@ START_TEST(test_announce)
|
||||
c_sleep(50);
|
||||
}
|
||||
|
||||
memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(first_dht_pk, dht_get_self_public_key(onions[NUM_FIRST]->onion->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(last_dht_pk, dht_get_self_public_key(onions[NUM_LAST]->onion->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
||||
printf("adding friend\n");
|
||||
int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c,
|
||||
|
||||
+11
-10
@@ -70,12 +70,12 @@ static void manage_keys(DHT *dht)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memcpy(dht->self_public_key, keys, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(dht->self_secret_key, keys + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_SECRET_KEY_SIZE);
|
||||
dht_set_self_public_key(dht, keys);
|
||||
dht_set_self_public_key(dht, keys + CRYPTO_PUBLIC_KEY_SIZE);
|
||||
printf("Keys loaded successfully.\n");
|
||||
} else {
|
||||
memcpy(keys, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht->self_secret_key, CRYPTO_SECRET_KEY_SIZE);
|
||||
memcpy(keys, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE);
|
||||
keys_file = fopen("key", "w");
|
||||
|
||||
if (keys_file == NULL) {
|
||||
@@ -120,7 +120,7 @@ int main(int argc, char *argv[])
|
||||
Onion_Announce *onion_a = new_onion_announce(dht);
|
||||
|
||||
#ifdef DHT_NODE_EXTRA_PACKETS
|
||||
bootstrap_set_callbacks(dht->net, DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
||||
bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
||||
#endif
|
||||
|
||||
if (!(onion && onion_a)) {
|
||||
@@ -137,7 +137,7 @@ int main(int argc, char *argv[])
|
||||
#ifdef TCP_RELAY_ENABLED
|
||||
#define NUM_PORTS 3
|
||||
uint16_t ports[NUM_PORTS] = {443, 3389, PORT};
|
||||
TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht->self_secret_key, onion);
|
||||
TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion);
|
||||
|
||||
if (tcp_s == NULL) {
|
||||
printf("TCP server failed to initialize.\n");
|
||||
@@ -155,14 +155,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
printf("%02hhX", dht->self_public_key[i]);
|
||||
fprintf(file, "%02hhX", dht->self_public_key[i]);
|
||||
const uint8_t *const self_public_key = dht_get_self_public_key(dht);
|
||||
printf("%02hhX", self_public_key[i]);
|
||||
fprintf(file, "%02hhX", self_public_key[i]);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
printf("\n");
|
||||
printf("Port: %u\n", net_ntohs(net_port(dht->net)));
|
||||
printf("Port: %u\n", net_ntohs(net_port(dht_get_net(dht))));
|
||||
|
||||
if (argc > argvoffset + 3) {
|
||||
printf("Trying to bootstrap into the network...\n");
|
||||
@@ -199,7 +200,7 @@ int main(int argc, char *argv[])
|
||||
#ifdef TCP_RELAY_ENABLED
|
||||
do_TCP_server(tcp_s);
|
||||
#endif
|
||||
networking_poll(dht->net, NULL);
|
||||
networking_poll(dht_get_net(dht), NULL);
|
||||
|
||||
c_sleep(1);
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ static int manage_keys(DHT *dht, char *keys_file_path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(dht->self_public_key, keys, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(dht->self_secret_key, keys + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_SECRET_KEY_SIZE);
|
||||
dht_set_self_public_key(dht, keys);
|
||||
dht_set_self_secret_key(dht, keys + CRYPTO_PUBLIC_KEY_SIZE);
|
||||
} else {
|
||||
// Otherwise save new keys
|
||||
memcpy(keys, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht->self_secret_key, CRYPTO_SECRET_KEY_SIZE);
|
||||
memcpy(keys, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE);
|
||||
|
||||
keys_file = fopen(keys_file_path, "w");
|
||||
|
||||
@@ -261,7 +261,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (enable_motd) {
|
||||
if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) {
|
||||
if (bootstrap_set_callbacks(dht_get_net(dht), DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) {
|
||||
log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n");
|
||||
} else {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd);
|
||||
@@ -288,7 +288,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht->self_secret_key, onion);
|
||||
tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht_get_self_secret_key(dht), onion);
|
||||
|
||||
// tcp_relay_port_count != 0 at this point
|
||||
free(tcp_relay_ports);
|
||||
@@ -308,7 +308,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
print_public_key(dht->self_public_key);
|
||||
print_public_key(dht_get_self_public_key(dht));
|
||||
|
||||
uint64_t last_LANdiscovery = 0;
|
||||
const uint16_t net_htons_port = net_htons(port);
|
||||
@@ -332,7 +332,7 @@ int main(int argc, char *argv[])
|
||||
do_TCP_server(tcp_server);
|
||||
}
|
||||
|
||||
networking_poll(dht->net, NULL);
|
||||
networking_poll(dht_get_net(dht), NULL);
|
||||
|
||||
if (waiting_for_dht_connection && DHT_isconnected(dht)) {
|
||||
log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");
|
||||
|
||||
+14
-12
@@ -49,7 +49,7 @@
|
||||
|
||||
static uint8_t zeroes_cid[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
|
||||
static void print_client_id(uint8_t *public_key)
|
||||
static void print_client_id(const uint8_t *public_key)
|
||||
{
|
||||
uint32_t j;
|
||||
|
||||
@@ -58,7 +58,7 @@ static void print_client_id(uint8_t *public_key)
|
||||
}
|
||||
}
|
||||
|
||||
static void print_hardening(Hardening *h)
|
||||
static void print_hardening(const Hardening *h)
|
||||
{
|
||||
printf("Hardening:\n");
|
||||
printf("routes_requests_ok: %hhu\n", h->routes_requests_ok);
|
||||
@@ -76,9 +76,9 @@ static void print_hardening(Hardening *h)
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
static void print_assoc(IPPTsPng *assoc, uint8_t ours)
|
||||
static void print_assoc(const IPPTsPng *assoc, uint8_t ours)
|
||||
{
|
||||
IP_Port *ipp = &assoc->ip_port;
|
||||
const IP_Port *ipp = &assoc->ip_port;
|
||||
char ip_str[IP_NTOA_LEN];
|
||||
printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), net_ntohs(ipp->port));
|
||||
printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp);
|
||||
@@ -102,7 +102,7 @@ static void print_clientlist(DHT *dht)
|
||||
printf("___________________CLOSE________________________________\n");
|
||||
|
||||
for (i = 0; i < LCLIENT_LIST; i++) {
|
||||
Client_data *client = &dht->close_clientlist[i];
|
||||
const Client_data *client = dht_get_close_client(dht, i);
|
||||
|
||||
if (public_key_cmp(client->public_key, zeroes_cid) == 0) {
|
||||
continue;
|
||||
@@ -122,20 +122,20 @@ static void print_friendlist(DHT *dht)
|
||||
IP_Port p_ip;
|
||||
printf("_________________FRIENDS__________________________________\n");
|
||||
|
||||
for (k = 0; k < dht->num_friends; k++) {
|
||||
for (k = 0; k < dht_get_num_friends(dht); k++) {
|
||||
printf("FRIEND %u\n", k);
|
||||
printf("ID: ");
|
||||
|
||||
print_client_id(dht->friends_list[k].public_key);
|
||||
print_client_id(dht_get_friend_public_key(dht, k));
|
||||
|
||||
int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip);
|
||||
int friendok = DHT_getfriendip(dht, dht_get_friend_public_key(dht, k), &p_ip);
|
||||
char ip_str[IP_NTOA_LEN];
|
||||
printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), net_ntohs(p_ip.port), friendok);
|
||||
|
||||
printf("\nCLIENTS IN LIST:\n\n");
|
||||
|
||||
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
|
||||
Client_data *client = &dht->friends_list[k].client_list[i];
|
||||
const Client_data *client = &dht_get_friend(dht, k)->client_list[i];
|
||||
|
||||
if (public_key_cmp(client->public_key, zeroes_cid) == 0) {
|
||||
continue;
|
||||
@@ -195,11 +195,13 @@ int main(int argc, char *argv[])
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (dht->self_public_key[i] < 16) {
|
||||
const uint8_t *const self_public_key = dht_get_self_public_key(dht);
|
||||
|
||||
if (self_public_key[i] < 16) {
|
||||
printf("0");
|
||||
}
|
||||
|
||||
printf("%hhX", dht->self_public_key[i]);
|
||||
printf("%hhX", self_public_key[i]);
|
||||
}
|
||||
|
||||
char temp_id[128];
|
||||
@@ -250,7 +252,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#endif
|
||||
networking_poll(dht->net, NULL);
|
||||
networking_poll(dht_get_net(dht), NULL);
|
||||
|
||||
print_clientlist(dht);
|
||||
print_friendlist(dht);
|
||||
|
||||
@@ -59,6 +59,94 @@
|
||||
|
||||
#define ASSOC_COUNT 2
|
||||
|
||||
struct DHT {
|
||||
Logger *log;
|
||||
Networking_Core *net;
|
||||
|
||||
bool hole_punching_enabled;
|
||||
|
||||
Client_data close_clientlist[LCLIENT_LIST];
|
||||
uint64_t close_lastgetnodes;
|
||||
uint32_t close_bootstrap_times;
|
||||
|
||||
/* Note: this key should not be/is not used to transmit any sensitive materials */
|
||||
uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
|
||||
/* DHT keypair */
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
DHT_Friend *friends_list;
|
||||
uint16_t num_friends;
|
||||
|
||||
Node_format *loaded_nodes_list;
|
||||
uint32_t loaded_num_nodes;
|
||||
unsigned int loaded_nodes_index;
|
||||
|
||||
Shared_Keys shared_keys_recv;
|
||||
Shared_Keys shared_keys_sent;
|
||||
|
||||
struct Ping *ping;
|
||||
Ping_Array *dht_ping_array;
|
||||
Ping_Array *dht_harden_ping_array;
|
||||
uint64_t last_run;
|
||||
|
||||
Cryptopacket_Handles cryptopackethandlers[256];
|
||||
|
||||
Node_format to_bootstrap[MAX_CLOSE_TO_BOOTSTRAP_NODES];
|
||||
unsigned int num_to_bootstrap;
|
||||
};
|
||||
|
||||
const uint8_t *dht_get_self_public_key(const DHT *dht)
|
||||
{
|
||||
return dht->self_public_key;
|
||||
}
|
||||
const uint8_t *dht_get_self_secret_key(const DHT *dht)
|
||||
{
|
||||
return dht->self_secret_key;
|
||||
}
|
||||
|
||||
void dht_set_self_public_key(DHT *dht, const uint8_t *key)
|
||||
{
|
||||
memcpy(dht->self_public_key, key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
void dht_set_self_secret_key(DHT *dht, const uint8_t *key)
|
||||
{
|
||||
memcpy(dht->self_secret_key, key, CRYPTO_SECRET_KEY_SIZE);
|
||||
}
|
||||
|
||||
Networking_Core *dht_get_net(const DHT *dht)
|
||||
{
|
||||
return dht->net;
|
||||
}
|
||||
struct Ping *dht_get_ping(const DHT *dht)
|
||||
{
|
||||
return dht->ping;
|
||||
}
|
||||
const Client_data *dht_get_close_clientlist(const DHT *dht)
|
||||
{
|
||||
return dht->close_clientlist;
|
||||
}
|
||||
const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num)
|
||||
{
|
||||
assert(client_num < sizeof(dht->close_clientlist) / sizeof(dht->close_clientlist[0]));
|
||||
return &dht->close_clientlist[client_num];
|
||||
}
|
||||
uint16_t dht_get_num_friends(const DHT *dht)
|
||||
{
|
||||
return dht->num_friends;
|
||||
}
|
||||
|
||||
DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num)
|
||||
{
|
||||
assert(friend_num < dht->num_friends);
|
||||
return &dht->friends_list[friend_num];
|
||||
}
|
||||
const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num)
|
||||
{
|
||||
assert(friend_num < dht->num_friends);
|
||||
return dht->friends_list[friend_num].public_key;
|
||||
}
|
||||
|
||||
/* Compares pk1 and pk2 with pk.
|
||||
*
|
||||
* return 0 if both are same distance.
|
||||
|
||||
+12
-32
@@ -240,42 +240,22 @@ typedef struct {
|
||||
} Cryptopacket_Handles;
|
||||
|
||||
#define DHT_DEFINED
|
||||
typedef struct DHT {
|
||||
Logger *log;
|
||||
Networking_Core *net;
|
||||
typedef struct DHT DHT;
|
||||
|
||||
bool hole_punching_enabled;
|
||||
const uint8_t *dht_get_self_public_key(const DHT *dht);
|
||||
const uint8_t *dht_get_self_secret_key(const DHT *dht);
|
||||
void dht_set_self_public_key(DHT *dht, const uint8_t *key);
|
||||
void dht_set_self_secret_key(DHT *dht, const uint8_t *key);
|
||||
|
||||
Client_data close_clientlist[LCLIENT_LIST];
|
||||
uint64_t close_lastgetnodes;
|
||||
uint32_t close_bootstrap_times;
|
||||
Networking_Core *dht_get_net(const DHT *dht);
|
||||
struct Ping *dht_get_ping(const DHT *dht);
|
||||
const Client_data *dht_get_close_clientlist(const DHT *dht);
|
||||
const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num);
|
||||
uint16_t dht_get_num_friends(const DHT *dht);
|
||||
|
||||
/* Note: this key should not be/is not used to transmit any sensitive materials */
|
||||
uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
|
||||
/* DHT keypair */
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num);
|
||||
const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num);
|
||||
|
||||
DHT_Friend *friends_list;
|
||||
uint16_t num_friends;
|
||||
|
||||
Node_format *loaded_nodes_list;
|
||||
uint32_t loaded_num_nodes;
|
||||
unsigned int loaded_nodes_index;
|
||||
|
||||
Shared_Keys shared_keys_recv;
|
||||
Shared_Keys shared_keys_sent;
|
||||
|
||||
struct Ping *ping;
|
||||
Ping_Array *dht_ping_array;
|
||||
Ping_Array *dht_harden_ping_array;
|
||||
uint64_t last_run;
|
||||
|
||||
Cryptopacket_Handles cryptopackethandlers[256];
|
||||
|
||||
Node_format to_bootstrap[MAX_CLOSE_TO_BOOTSTRAP_NODES];
|
||||
unsigned int num_to_bootstrap;
|
||||
} DHT;
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
|
||||
/* Shared key generations are costly, it is therefor smart to store commonly used
|
||||
|
||||
@@ -356,7 +356,6 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack
|
||||
|
||||
char ip_str[IP_NTOA_LEN] = { 0 };
|
||||
ip_ntoa(&source.ip, ip_str, sizeof(ip_str));
|
||||
LOGGER_DEBUG(dht->log, "Found node in LAN: %s", ip_str);
|
||||
|
||||
DHT_bootstrap(dht, source, packet + 1);
|
||||
return 0;
|
||||
@@ -367,30 +366,30 @@ int lan_discovery_send(uint16_t port, DHT *dht)
|
||||
{
|
||||
uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
|
||||
data[0] = NET_PACKET_LAN_DISCOVERY;
|
||||
id_copy(data + 1, dht->self_public_key);
|
||||
id_copy(data + 1, dht_get_self_public_key(dht));
|
||||
|
||||
send_broadcasts(dht->net, port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);
|
||||
send_broadcasts(dht_get_net(dht), port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
||||
int res = -1;
|
||||
IP_Port ip_port;
|
||||
ip_port.port = port;
|
||||
|
||||
/* IPv6 multicast */
|
||||
if (net_family(dht->net) == TOX_AF_INET6) {
|
||||
if (net_family(dht_get_net(dht)) == TOX_AF_INET6) {
|
||||
ip_port.ip = broadcast_ip(TOX_AF_INET6, TOX_AF_INET6);
|
||||
|
||||
if (ip_isset(&ip_port.ip)) {
|
||||
if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
|
||||
if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is TOX_AF_INET6 */
|
||||
ip_port.ip = broadcast_ip(net_family(dht->net), TOX_AF_INET);
|
||||
ip_port.ip = broadcast_ip(net_family(dht_get_net(dht)), TOX_AF_INET);
|
||||
|
||||
if (ip_isset(&ip_port.ip)) {
|
||||
if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
|
||||
if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
@@ -401,10 +400,10 @@ int lan_discovery_send(uint16_t port, DHT *dht)
|
||||
|
||||
void lan_discovery_init(DHT *dht)
|
||||
{
|
||||
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht);
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht);
|
||||
}
|
||||
|
||||
void lan_discovery_kill(DHT *dht)
|
||||
{
|
||||
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, NULL, NULL);
|
||||
}
|
||||
|
||||
+10
-9
@@ -2010,7 +2010,8 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
|
||||
}
|
||||
|
||||
if (options->tcp_server_port) {
|
||||
m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, m->dht->self_secret_key, m->onion);
|
||||
m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, dht_get_self_secret_key(m->dht),
|
||||
m->onion);
|
||||
|
||||
if (m->tcp_server == NULL) {
|
||||
kill_friend_connections(m->fr_c);
|
||||
@@ -2571,8 +2572,8 @@ void do_messenger(Messenger *m, void *userdata)
|
||||
uint32_t client, last_pinged;
|
||||
|
||||
for (client = 0; client < LCLIENT_LIST; client++) {
|
||||
Client_data *cptr = &m->dht->close_clientlist[client];
|
||||
IPPTsPng *assoc = NULL;
|
||||
const Client_data *cptr = dht_get_close_client(m->dht, client);
|
||||
const IPPTsPng *assoc = NULL;
|
||||
uint32_t a;
|
||||
|
||||
for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
|
||||
@@ -2597,7 +2598,7 @@ void do_messenger(Messenger *m, void *userdata)
|
||||
uint32_t friend_idx, dhtfriend;
|
||||
|
||||
/* dht contains additional "friends" (requests) */
|
||||
uint32_t num_dhtfriends = m->dht->num_friends;
|
||||
uint32_t num_dhtfriends = dht_get_num_friends(m->dht);
|
||||
VLA(int32_t, m2dht, num_dhtfriends);
|
||||
VLA(int32_t, dht2m, num_dhtfriends);
|
||||
|
||||
@@ -2609,8 +2610,8 @@ void do_messenger(Messenger *m, void *userdata)
|
||||
continue;
|
||||
}
|
||||
|
||||
for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) {
|
||||
if (id_equal(m->friendlist[friend_idx].real_pk, m->dht->friends_list[dhtfriend].public_key)) {
|
||||
for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); dhtfriend++) {
|
||||
if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) {
|
||||
m2dht[friend_idx] = dhtfriend;
|
||||
break;
|
||||
}
|
||||
@@ -2623,8 +2624,8 @@ void do_messenger(Messenger *m, void *userdata)
|
||||
}
|
||||
}
|
||||
|
||||
if (m->numfriends != m->dht->num_friends) {
|
||||
LOGGER_TRACE(m->log, "Friend num in DHT %u != friend num in msger %u\n", m->dht->num_friends, m->numfriends);
|
||||
if (m->numfriends != dht_get_num_friends(m->dht)) {
|
||||
LOGGER_TRACE(m->log, "Friend num in DHT %u != friend num in msger %u\n", dht_get_num_friends(m->dht), m->numfriends);
|
||||
}
|
||||
|
||||
Friend *msgfptr;
|
||||
@@ -2637,7 +2638,7 @@ void do_messenger(Messenger *m, void *userdata)
|
||||
msgfptr = NULL;
|
||||
}
|
||||
|
||||
dhtfptr = &m->dht->friends_list[friend_idx];
|
||||
dhtfptr = dht_get_friend(m->dht, friend_idx);
|
||||
|
||||
if (msgfptr) {
|
||||
char id_str[IDSTRING_LEN];
|
||||
|
||||
+1
-1
@@ -744,7 +744,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
|
||||
g->identifier[0] = type;
|
||||
g->peer_number = 0; /* Founder is peer 0. */
|
||||
memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
int peer_index = addpeer(g_c, groupnumber, g->real_pk, g_c->m->dht->self_public_key, 0, NULL, false);
|
||||
int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, NULL, false);
|
||||
|
||||
if (peer_index == -1) {
|
||||
return -1;
|
||||
|
||||
+13
-13
@@ -223,7 +223,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *
|
||||
uint8_t nonce[CRYPTO_NONCE_SIZE];
|
||||
random_nonce(nonce);
|
||||
packet[0] = NET_PACKET_COOKIE_REQUEST;
|
||||
memcpy(packet + 1, c->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(packet + 1, dht_get_self_public_key(c->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE);
|
||||
int len = encrypt_data_symmetric(shared_key, nonce, plain, sizeof(plain),
|
||||
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE);
|
||||
@@ -362,7 +362,7 @@ static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((uint32_t)sendpacket(c->dht->net, source, data, sizeof(data)) != sizeof(data)) {
|
||||
if ((uint32_t)sendpacket(dht_get_net(c->dht), source, data, sizeof(data)) != sizeof(data)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
|
||||
crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL);
|
||||
|
||||
if (direct_connected) {
|
||||
if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) {
|
||||
if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) {
|
||||
pthread_mutex_unlock(&conn->mutex);
|
||||
return 0;
|
||||
}
|
||||
@@ -676,7 +676,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
|
||||
|
||||
if ((((UDP_DIRECT_TIMEOUT / 2) + conn->direct_send_attempt_time) > current_time && length < 96)
|
||||
|| data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS) {
|
||||
if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) {
|
||||
if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) {
|
||||
direct_send_attempt = 1;
|
||||
conn->direct_send_attempt_time = unix_time();
|
||||
}
|
||||
@@ -2941,7 +2941,7 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
|
||||
|
||||
temp->log = log;
|
||||
|
||||
temp->tcp_c = new_tcp_connections(dht->self_secret_key, proxy_info);
|
||||
temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info);
|
||||
|
||||
if (temp->tcp_c == NULL) {
|
||||
free(temp);
|
||||
@@ -2965,10 +2965,10 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
|
||||
|
||||
temp->current_sleep_time = CRYPTO_SEND_PACKET_INTERVAL;
|
||||
|
||||
networking_registerhandler(dht->net, NET_PACKET_COOKIE_REQUEST, &udp_handle_cookie_request, temp);
|
||||
networking_registerhandler(dht->net, NET_PACKET_COOKIE_RESPONSE, &udp_handle_packet, temp);
|
||||
networking_registerhandler(dht->net, NET_PACKET_CRYPTO_HS, &udp_handle_packet, temp);
|
||||
networking_registerhandler(dht->net, NET_PACKET_CRYPTO_DATA, &udp_handle_packet, temp);
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_COOKIE_REQUEST, &udp_handle_cookie_request, temp);
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_COOKIE_RESPONSE, &udp_handle_packet, temp);
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_CRYPTO_HS, &udp_handle_packet, temp);
|
||||
networking_registerhandler(dht_get_net(dht), NET_PACKET_CRYPTO_DATA, &udp_handle_packet, temp);
|
||||
|
||||
bs_list_init(&temp->ip_port_list, sizeof(IP_Port), 8);
|
||||
|
||||
@@ -3039,10 +3039,10 @@ void kill_net_crypto(Net_Crypto *c)
|
||||
|
||||
kill_tcp_connections(c->tcp_c);
|
||||
bs_list_free(&c->ip_port_list);
|
||||
networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_REQUEST, NULL, NULL);
|
||||
networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_RESPONSE, NULL, NULL);
|
||||
networking_registerhandler(c->dht->net, NET_PACKET_CRYPTO_HS, NULL, NULL);
|
||||
networking_registerhandler(c->dht->net, NET_PACKET_CRYPTO_DATA, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, NULL, NULL);
|
||||
crypto_memzero(c, sizeof(Net_Crypto));
|
||||
free(c);
|
||||
}
|
||||
|
||||
+6
-6
@@ -120,8 +120,8 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
|
||||
return -1;
|
||||
}
|
||||
|
||||
encrypt_precompute(nodes[0].public_key, dht->self_secret_key, new_path->shared_key1);
|
||||
memcpy(new_path->public_key1, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
encrypt_precompute(nodes[0].public_key, dht_get_self_secret_key(dht), new_path->shared_key1);
|
||||
memcpy(new_path->public_key1, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
||||
uint8_t random_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t random_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
@@ -338,7 +338,7 @@ static int handle_send_initial(void *object, IP_Port source, const uint8_t *pack
|
||||
|
||||
uint8_t plain[ONION_MAX_PACKET_SIZE];
|
||||
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
|
||||
get_shared_key(&onion->shared_keys_1, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE);
|
||||
get_shared_key(&onion->shared_keys_1, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE);
|
||||
int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
|
||||
length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), plain);
|
||||
|
||||
@@ -407,7 +407,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
|
||||
|
||||
uint8_t plain[ONION_MAX_PACKET_SIZE];
|
||||
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
|
||||
get_shared_key(&onion->shared_keys_2, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE);
|
||||
get_shared_key(&onion->shared_keys_2, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE);
|
||||
int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
|
||||
length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_1), plain);
|
||||
|
||||
@@ -463,7 +463,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
|
||||
|
||||
uint8_t plain[ONION_MAX_PACKET_SIZE];
|
||||
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
|
||||
get_shared_key(&onion->shared_keys_3, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE);
|
||||
get_shared_key(&onion->shared_keys_3, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE);
|
||||
int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
|
||||
length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_2), plain);
|
||||
|
||||
@@ -646,7 +646,7 @@ Onion *new_onion(DHT *dht)
|
||||
}
|
||||
|
||||
onion->dht = dht;
|
||||
onion->net = dht->net;
|
||||
onion->net = dht_get_net(dht);
|
||||
new_symmetric_key(onion->secret_symmetric_key);
|
||||
onion->timestamp = unix_time();
|
||||
|
||||
|
||||
@@ -343,7 +343,7 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const ui
|
||||
}
|
||||
|
||||
if (pos == -1) {
|
||||
if (id_closest(onion_a->dht->self_public_key, public_key, onion_a->entries[0].public_key) == 1) {
|
||||
if (id_closest(dht_get_self_public_key(onion_a->dht), public_key, onion_a->entries[0].public_key) == 1) {
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
@@ -358,7 +358,7 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const ui
|
||||
memcpy(onion_a->entries[pos].data_public_key, data_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
onion_a->entries[pos].time = unix_time();
|
||||
|
||||
sort_onion_announce_list(onion_a->entries, ONION_ANNOUNCE_MAX_ENTRIES, onion_a->dht->self_public_key);
|
||||
sort_onion_announce_list(onion_a->entries, ONION_ANNOUNCE_MAX_ENTRIES, dht_get_self_public_key(onion_a->dht));
|
||||
return in_entries(onion_a, public_key);
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ static int handle_announce_request(void *object, IP_Port source, const uint8_t *
|
||||
|
||||
const uint8_t *packet_public_key = packet + 1 + CRYPTO_NONCE_SIZE;
|
||||
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
|
||||
get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key);
|
||||
get_shared_key(&onion_a->shared_keys_recv, shared_key, dht_get_self_secret_key(onion_a->dht), packet_public_key);
|
||||
|
||||
uint8_t plain[ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE +
|
||||
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
|
||||
@@ -504,7 +504,7 @@ Onion_Announce *new_onion_announce(DHT *dht)
|
||||
}
|
||||
|
||||
onion_a->dht = dht;
|
||||
onion_a->net = dht->net;
|
||||
onion_a->net = dht_get_net(dht);
|
||||
new_symmetric_key(onion_a->secret_bytes);
|
||||
|
||||
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_announce_request, onion_a);
|
||||
|
||||
@@ -1133,7 +1133,7 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin
|
||||
}
|
||||
|
||||
uint8_t packet[MAX_CRYPTO_REQUEST_SIZE];
|
||||
len = create_request(onion_c->dht->self_public_key, onion_c->dht->self_secret_key, packet,
|
||||
len = create_request(dht_get_self_public_key(onion_c->dht), dht_get_self_secret_key(onion_c->dht), packet,
|
||||
onion_c->friends_list[friend_num].dht_public_key, temp, SIZEOF_VLA(temp), CRYPTO_PACKET_DHTPK);
|
||||
|
||||
if (len == -1) {
|
||||
@@ -1192,7 +1192,7 @@ static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8
|
||||
uint64_t no_replay = unix_time();
|
||||
host_to_net((uint8_t *)&no_replay, sizeof(no_replay));
|
||||
memcpy(data + 1, &no_replay, sizeof(no_replay));
|
||||
memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(data + 1 + sizeof(uint64_t), dht_get_self_public_key(onion_c->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
Node_format nodes[MAX_SENT_NODES];
|
||||
uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, (MAX_SENT_NODES / 2));
|
||||
uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays);
|
||||
@@ -1864,7 +1864,7 @@ Onion_Client *new_onion_client(Net_Crypto *c)
|
||||
}
|
||||
|
||||
onion_c->dht = nc_get_dht(c);
|
||||
onion_c->net = onion_c->dht->net;
|
||||
onion_c->net = dht_get_net(onion_c->dht);
|
||||
onion_c->c = c;
|
||||
new_symmetric_key(onion_c->secret_symmetric_key);
|
||||
crypto_new_keypair(onion_c->temp_public_key, onion_c->temp_secret_key);
|
||||
|
||||
+16
-16
@@ -64,7 +64,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
|
||||
int rc;
|
||||
uint64_t ping_id;
|
||||
|
||||
if (id_equal(public_key, ping->dht->self_public_key)) {
|
||||
if (id_equal(public_key, dht_get_self_public_key(ping->dht))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
|
||||
memcpy(ping_plain + 1, &ping_id, sizeof(ping_id));
|
||||
|
||||
pk[0] = NET_PACKET_PING_REQUEST;
|
||||
id_copy(pk + 1, ping->dht->self_public_key); // Our pubkey
|
||||
id_copy(pk + 1, dht_get_self_public_key(ping->dht)); // Our pubkey
|
||||
random_nonce(pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
|
||||
return sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk));
|
||||
}
|
||||
|
||||
static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id,
|
||||
@@ -109,7 +109,7 @@ static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key
|
||||
uint8_t pk[DHT_PING_SIZE];
|
||||
int rc;
|
||||
|
||||
if (id_equal(public_key, ping->dht->self_public_key)) {
|
||||
if (id_equal(public_key, dht_get_self_public_key(ping->dht))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key
|
||||
memcpy(ping_plain + 1, &ping_id, sizeof(ping_id));
|
||||
|
||||
pk[0] = NET_PACKET_PING_RESPONSE;
|
||||
id_copy(pk + 1, ping->dht->self_public_key); // Our pubkey
|
||||
id_copy(pk + 1, dht_get_self_public_key(ping->dht)); // Our pubkey
|
||||
random_nonce(pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce
|
||||
|
||||
// Encrypt ping_id using recipient privkey
|
||||
@@ -131,7 +131,7 @@ static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key
|
||||
return 1;
|
||||
}
|
||||
|
||||
return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
|
||||
return sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk));
|
||||
}
|
||||
|
||||
static int handle_ping_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
|
||||
@@ -143,9 +143,9 @@ static int handle_ping_request(void *object, IP_Port source, const uint8_t *pack
|
||||
return 1;
|
||||
}
|
||||
|
||||
Ping *ping = dht->ping;
|
||||
Ping *ping = dht_get_ping(dht);
|
||||
|
||||
if (id_equal(packet + 1, ping->dht->self_public_key)) {
|
||||
if (id_equal(packet + 1, dht_get_self_public_key(ping->dht))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -186,9 +186,9 @@ static int handle_ping_response(void *object, IP_Port source, const uint8_t *pac
|
||||
return 1;
|
||||
}
|
||||
|
||||
Ping *ping = dht->ping;
|
||||
Ping *ping = dht_get_ping(dht);
|
||||
|
||||
if (id_equal(packet + 1, ping->dht->self_public_key)) {
|
||||
if (id_equal(packet + 1, dht_get_self_public_key(ping->dht))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, public_key, ip_port)) {
|
||||
if (in_list(dht_get_close_clientlist(ping->dht), LCLIENT_LIST, public_key, ip_port)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port)
|
||||
}
|
||||
}
|
||||
|
||||
if (add_to_list(ping->to_ping, MAX_TO_PING, public_key, ip_port, ping->dht->self_public_key)) {
|
||||
if (add_to_list(ping->to_ping, MAX_TO_PING, public_key, ip_port, dht_get_self_public_key(ping->dht))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -367,16 +367,16 @@ Ping *ping_new(DHT *dht)
|
||||
}
|
||||
|
||||
ping->dht = dht;
|
||||
networking_registerhandler(ping->dht->net, NET_PACKET_PING_REQUEST, &handle_ping_request, dht);
|
||||
networking_registerhandler(ping->dht->net, NET_PACKET_PING_RESPONSE, &handle_ping_response, dht);
|
||||
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, &handle_ping_request, dht);
|
||||
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, &handle_ping_response, dht);
|
||||
|
||||
return ping;
|
||||
}
|
||||
|
||||
void ping_kill(Ping *ping)
|
||||
{
|
||||
networking_registerhandler(ping->dht->net, NET_PACKET_PING_REQUEST, NULL, NULL);
|
||||
networking_registerhandler(ping->dht->net, NET_PACKET_PING_RESPONSE, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, NULL, NULL);
|
||||
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, NULL, NULL);
|
||||
ping_array_kill(ping->ping_array);
|
||||
|
||||
free(ping);
|
||||
|
||||
+1
-1
@@ -1519,7 +1519,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
|
||||
{
|
||||
if (dht_id) {
|
||||
const Messenger *m = tox;
|
||||
memcpy(dht_id, m->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(dht_id, dht_get_self_public_key(m->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user