mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
client_id -> public_key
This commit is contained in:
parent
c989c246ea
commit
dfc154cc9e
|
@ -124,7 +124,7 @@ START_TEST(test_fillup)
|
|||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
for (j = 0; j < 8; ++j) {
|
||||
if (id_equal(entri[j]->client_id, closest[i].id))
|
||||
if (id_equal(entri[j]->public_key, closest[i].id))
|
||||
++good;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,25 +54,25 @@ void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6)
|
|||
}
|
||||
}
|
||||
|
||||
/* Returns 1 if client_id has a furthest distance to comp_client_id
|
||||
than all client_id's in the list */
|
||||
uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *client_id)
|
||||
/* Returns 1 if public_key has a furthest distance to comp_client_id
|
||||
than all public_key's in the list */
|
||||
uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *public_key)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
if (id_closest(comp_client_id, client_id, list[i].client_id) == 1)
|
||||
if (id_closest(comp_client_id, public_key, list[i].public_key) == 1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int client_in_list(Client_data *list, uint32_t length, const uint8_t *client_id)
|
||||
int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int)length; ++i)
|
||||
if (id_equal(client_id, list[i].client_id))
|
||||
if (id_equal(public_key, list[i].public_key))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
|
@ -104,7 +104,7 @@ void test_addto_lists_update(DHT *dht,
|
|||
// check ip_port update for existing id
|
||||
test = rand() % length;
|
||||
test_ipp.port = rand() % TOX_PORT_DEFAULT;
|
||||
id_copy(test_id, list[test].client_id);
|
||||
id_copy(test_id, list[test].public_key);
|
||||
|
||||
used = addto_lists(dht, test_ipp, test_id);
|
||||
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
||||
|
@ -118,7 +118,7 @@ void test_addto_lists_update(DHT *dht,
|
|||
test2 = rand() % (length / 2) + length / 2;
|
||||
|
||||
ipport_copy(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port);
|
||||
id_copy(test_id, list[test2].client_id);
|
||||
id_copy(test_id, list[test2].public_key);
|
||||
|
||||
if (ipv6) list[test2].assoc6.ip_port.port = -1;
|
||||
else list[test2].assoc4.ip_port.port = -1;
|
||||
|
@ -134,7 +134,7 @@ void test_addto_lists_update(DHT *dht,
|
|||
test2 = rand() % (length / 2) + length / 2;
|
||||
|
||||
ipport_copy(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port);
|
||||
id_copy(test_id, list[test1].client_id);
|
||||
id_copy(test_id, list[test1].public_key);
|
||||
|
||||
if (ipv6) list[test1].assoc6.ip_port.port = -1;
|
||||
else list[test1].assoc4.ip_port.port = -1;
|
||||
|
@ -153,10 +153,10 @@ void test_addto_lists_bad(DHT *dht,
|
|||
{
|
||||
// check "bad" clients replacement
|
||||
int used, test1, test2, test3;
|
||||
uint8_t client_id[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
randombytes(client_id, sizeof(client_id));
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
mark_all_good(list, length, ipv6);
|
||||
|
||||
test1 = rand() % (length / 3);
|
||||
|
@ -164,9 +164,9 @@ void test_addto_lists_bad(DHT *dht,
|
|||
test3 = rand() % (length / 3) + 2 * length / 3;
|
||||
ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen");
|
||||
|
||||
id_copy((uint8_t *)&test_id1, list[test1].client_id);
|
||||
id_copy((uint8_t *)&test_id2, list[test2].client_id);
|
||||
id_copy((uint8_t *)&test_id3, list[test3].client_id);
|
||||
id_copy((uint8_t *)&test_id1, list[test1].public_key);
|
||||
id_copy((uint8_t *)&test_id2, list[test2].public_key);
|
||||
id_copy((uint8_t *)&test_id3, list[test3].public_key);
|
||||
|
||||
// mark nodes as "bad"
|
||||
if (ipv6) {
|
||||
|
@ -180,10 +180,10 @@ void test_addto_lists_bad(DHT *dht,
|
|||
}
|
||||
|
||||
ip_port->port += 1;
|
||||
used = addto_lists(dht, *ip_port, client_id);
|
||||
used = addto_lists(dht, *ip_port, public_key);
|
||||
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
||||
|
||||
ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Client id is not in the list");
|
||||
ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Client id is not in the list");
|
||||
ck_assert_msg(client_in_list(list, length, test_id2) >= 0, "Wrong bad client removed");
|
||||
ck_assert_msg(client_in_list(list, length, test_id3) >= 0, "Wrong bad client removed");
|
||||
}
|
||||
|
@ -196,10 +196,10 @@ void test_addto_lists_possible_bad(DHT *dht,
|
|||
{
|
||||
// check "possibly bad" clients replacement
|
||||
int used, test1, test2, test3;
|
||||
uint8_t client_id[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
randombytes(client_id, sizeof(client_id));
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
mark_all_good(list, length, ipv6);
|
||||
|
||||
test1 = rand() % (length / 3);
|
||||
|
@ -207,9 +207,9 @@ void test_addto_lists_possible_bad(DHT *dht,
|
|||
test3 = rand() % (length / 3) + 2 * length / 3;
|
||||
ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen");
|
||||
|
||||
id_copy((uint8_t *)&test_id1, list[test1].client_id);
|
||||
id_copy((uint8_t *)&test_id2, list[test2].client_id);
|
||||
id_copy((uint8_t *)&test_id3, list[test3].client_id);
|
||||
id_copy((uint8_t *)&test_id1, list[test1].public_key);
|
||||
id_copy((uint8_t *)&test_id2, list[test2].public_key);
|
||||
id_copy((uint8_t *)&test_id3, list[test3].public_key);
|
||||
|
||||
// mark nodes as "possibly bad"
|
||||
if (ipv6) {
|
||||
|
@ -223,10 +223,10 @@ void test_addto_lists_possible_bad(DHT *dht,
|
|||
}
|
||||
|
||||
ip_port->port += 1;
|
||||
used = addto_lists(dht, *ip_port, client_id);
|
||||
used = addto_lists(dht, *ip_port, public_key);
|
||||
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
||||
|
||||
ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Client id is not in the list");
|
||||
ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Client id is not in the list");
|
||||
|
||||
int inlist_id1 = client_in_list(list, length, test_id1) >= 0;
|
||||
int inlist_id2 = client_in_list(list, length, test_id2) >= 0;
|
||||
|
@ -258,28 +258,28 @@ void test_addto_lists_good(DHT *dht,
|
|||
IP_Port *ip_port,
|
||||
const uint8_t *comp_client_id)
|
||||
{
|
||||
uint8_t client_id[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[CLIENT_ID_SIZE];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
mark_all_good(list, length, ipv6);
|
||||
|
||||
// check "good" client id replacement
|
||||
do {
|
||||
randombytes(client_id, sizeof(client_id));
|
||||
} while (is_furthest(comp_client_id, list, length, client_id));
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
} while (is_furthest(comp_client_id, list, length, public_key));
|
||||
|
||||
ip_port->port += 1;
|
||||
addto_lists(dht, *ip_port, client_id);
|
||||
ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Good client id is not in the list");
|
||||
addto_lists(dht, *ip_port, public_key);
|
||||
ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Good client id is not in the list");
|
||||
|
||||
// check "good" client id skip
|
||||
do {
|
||||
randombytes(client_id, sizeof(client_id));
|
||||
} while (!is_furthest(comp_client_id, list, length, client_id));
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
} while (!is_furthest(comp_client_id, list, length, public_key));
|
||||
|
||||
ip_port->port += 1;
|
||||
addto_lists(dht, *ip_port, client_id);
|
||||
ck_assert_msg(client_in_list(list, length, client_id) == -1, "Good client id is in the list");
|
||||
addto_lists(dht, *ip_port, public_key);
|
||||
ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list");
|
||||
}
|
||||
|
||||
void test_addto_lists(IP ip)
|
||||
|
@ -291,26 +291,26 @@ void test_addto_lists(IP ip)
|
|||
ck_assert_msg(dht != 0, "Failed to create DHT");
|
||||
|
||||
IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT };
|
||||
uint8_t client_id[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[CLIENT_ID_SIZE];
|
||||
int i, used;
|
||||
|
||||
// check lists filling
|
||||
for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
|
||||
randombytes(client_id, sizeof(client_id));
|
||||
used = addto_lists(dht, ip_port, client_id);
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
used = addto_lists(dht, ip_port, public_key);
|
||||
ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing ip_port");
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
|
||||
ip_port.port += 1;
|
||||
used = addto_lists(dht, ip_port, client_id);
|
||||
ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing client_id");
|
||||
used = addto_lists(dht, ip_port, public_key);
|
||||
ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing public_key");
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
|
||||
ip_port.port += 1;
|
||||
randombytes(client_id, sizeof(client_id));
|
||||
used = addto_lists(dht, ip_port, client_id);
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
used = addto_lists(dht, ip_port, public_key);
|
||||
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
||||
}
|
||||
|
||||
|
@ -333,14 +333,14 @@ void test_addto_lists(IP ip)
|
|||
|
||||
for (i = 0; i < dht->num_friends; ++i)
|
||||
test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port,
|
||||
dht->friends_list[i].client_id);
|
||||
dht->friends_list[i].public_key);
|
||||
*/
|
||||
// check "good" entries
|
||||
test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key);
|
||||
|
||||
for (i = 0; i < dht->num_friends; ++i)
|
||||
test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port,
|
||||
dht->friends_list[i].client_id);
|
||||
dht->friends_list[i].public_key);
|
||||
|
||||
kill_DHT(dht);
|
||||
kill_networking(net);
|
||||
|
|
|
@ -54,12 +54,12 @@
|
|||
|
||||
uint8_t zeroes_cid[CLIENT_ID_SIZE];
|
||||
|
||||
void print_client_id(uint8_t *client_id)
|
||||
void print_client_id(uint8_t *public_key)
|
||||
{
|
||||
uint32_t j;
|
||||
|
||||
for (j = 0; j < CLIENT_ID_SIZE; j++) {
|
||||
printf("%02hhX", client_id[j]);
|
||||
printf("%02hhX", public_key[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,11 +108,11 @@ void print_clientlist(DHT *dht)
|
|||
for (i = 0; i < LCLIENT_LIST; i++) {
|
||||
Client_data *client = &dht->close_clientlist[i];
|
||||
|
||||
if (memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
||||
if (memcmp(client->public_key, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
||||
continue;
|
||||
|
||||
printf("ClientID: ");
|
||||
print_client_id(client->client_id);
|
||||
print_client_id(client->public_key);
|
||||
|
||||
print_assoc(&client->assoc4, 1);
|
||||
print_assoc(&client->assoc6, 1);
|
||||
|
@ -129,9 +129,9 @@ void print_friendlist(DHT *dht)
|
|||
printf("FRIEND %u\n", k);
|
||||
printf("ID: ");
|
||||
|
||||
print_client_id(dht->friends_list[k].client_id);
|
||||
print_client_id(dht->friends_list[k].public_key);
|
||||
|
||||
int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip);
|
||||
int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip);
|
||||
printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip), ntohs(p_ip.port), friendok);
|
||||
|
||||
printf("\nCLIENTS IN LIST:\n\n");
|
||||
|
@ -139,11 +139,11 @@ void print_friendlist(DHT *dht)
|
|||
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
|
||||
Client_data *client = &dht->friends_list[k].client_list[i];
|
||||
|
||||
if (memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
||||
if (memcmp(client->public_key, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
||||
continue;
|
||||
|
||||
printf("ClientID: ");
|
||||
print_client_id(client->client_id);
|
||||
print_client_id(client->public_key);
|
||||
|
||||
print_assoc(&client->assoc4, 0);
|
||||
print_assoc(&client->assoc6, 0);
|
||||
|
@ -199,7 +199,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
char temp_id[128];
|
||||
printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n");
|
||||
printf("\nEnter the public_key of the friend you wish to add (32 bytes HEX format):\n");
|
||||
|
||||
if (!fgets(temp_id, sizeof(temp_id), stdin))
|
||||
exit(0);
|
||||
|
|
|
@ -431,15 +431,15 @@ static int client_in_nodelist(const Node_format *list, uint16_t length, const ui
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* return friend number from the client_id.
|
||||
/* return friend number from the public_key.
|
||||
* return -1 if a failure occurs.
|
||||
*/
|
||||
static int friend_number(const DHT *dht, const uint8_t *client_id)
|
||||
static int friend_number(const DHT *dht, const uint8_t *public_key)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < dht->num_friends; ++i) {
|
||||
if (id_equal(dht->friends_list[i].client_id, client_id))
|
||||
if (id_equal(dht->friends_list[i].public_key, public_key))
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -740,22 +740,22 @@ static int replace_all( Client_data *list,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Check if the node obtained with a get_nodes with client_id should be pinged.
|
||||
/* Check if the node obtained with a get_nodes with public_key should be pinged.
|
||||
* NOTE: for best results call it after addto_lists;
|
||||
*
|
||||
* return 0 if the node should not be pinged.
|
||||
* return 1 if it should.
|
||||
*/
|
||||
static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *client_id)
|
||||
static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key)
|
||||
{
|
||||
if (store_node_ok(&dht->close_clientlist[0], client_id, dht->self_public_key)) {
|
||||
if (store_node_ok(&dht->close_clientlist[0], public_key, dht->self_public_key)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < dht->num_friends; ++i) {
|
||||
if (store_node_ok(&dht->friends_list[i].client_list[0], client_id, dht->self_public_key)) {
|
||||
if (store_node_ok(&dht->friends_list[i].client_list[0], public_key, dht->self_public_key)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -763,12 +763,12 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *client_i
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Attempt to add client with ip_port and client_id to the friends client list
|
||||
/* Attempt to add client with ip_port and public_key to the friends client list
|
||||
* and close_clientlist.
|
||||
*
|
||||
* returns 1+ if the item is used in any list, 0 else
|
||||
*/
|
||||
int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id)
|
||||
int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
|
||||
{
|
||||
uint32_t i, used = 0;
|
||||
|
||||
|
@ -781,8 +781,8 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id)
|
|||
/* NOTE: Current behavior if there are two clients with the same id is
|
||||
* to replace the first ip by the second.
|
||||
*/
|
||||
if (!client_or_ip_port_in_list(dht->close_clientlist, LCLIENT_LIST, client_id, ip_port)) {
|
||||
if (replace_all(dht->close_clientlist, LCLIENT_LIST, client_id, ip_port, dht->self_public_key))
|
||||
if (!client_or_ip_port_in_list(dht->close_clientlist, LCLIENT_LIST, public_key, ip_port)) {
|
||||
if (replace_all(dht->close_clientlist, LCLIENT_LIST, public_key, ip_port, dht->self_public_key))
|
||||
used++;
|
||||
} else
|
||||
used++;
|
||||
|
@ -791,13 +791,13 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id)
|
|||
|
||||
for (i = 0; i < dht->num_friends; ++i) {
|
||||
if (!client_or_ip_port_in_list(dht->friends_list[i].client_list,
|
||||
MAX_FRIEND_CLIENTS, client_id, ip_port)) {
|
||||
MAX_FRIEND_CLIENTS, public_key, ip_port)) {
|
||||
if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
|
||||
client_id, ip_port, dht->friends_list[i].client_id)) {
|
||||
public_key, ip_port, dht->friends_list[i].public_key)) {
|
||||
|
||||
DHT_Friend *friend = &dht->friends_list[i];
|
||||
|
||||
if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) {
|
||||
if (memcmp(public_key, friend->public_key, CLIENT_ID_SIZE) == 0) {
|
||||
friend_foundip = friend;
|
||||
}
|
||||
|
||||
|
@ -806,7 +806,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id)
|
|||
} else {
|
||||
DHT_Friend *friend = &dht->friends_list[i];
|
||||
|
||||
if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) {
|
||||
if (memcmp(public_key, friend->public_key, CLIENT_ID_SIZE) == 0) {
|
||||
friend_foundip = friend;
|
||||
}
|
||||
|
||||
|
@ -832,7 +832,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id)
|
|||
ippts.ip_port = ip_port;
|
||||
ippts.timestamp = unix_time();
|
||||
|
||||
Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0);
|
||||
Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, used ? 1 : 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -872,7 +872,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key
|
|||
}
|
||||
} else {
|
||||
for (i = 0; i < dht->num_friends; ++i) {
|
||||
if (id_equal(public_key, dht->friends_list[i].client_id)) {
|
||||
if (id_equal(public_key, dht->friends_list[i].public_key)) {
|
||||
for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
|
||||
if (id_equal(nodeclient_id, dht->friends_list[i].client_list[j].public_key)) {
|
||||
if (ip_port.ip.family == AF_INET) {
|
||||
|
@ -1197,7 +1197,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *client_id, void (*ip_callback)(void *
|
|||
dht->friends_list = temp;
|
||||
DHT_Friend *friend = &dht->friends_list[dht->num_friends];
|
||||
memset(friend, 0, sizeof(DHT_Friend));
|
||||
memcpy(friend->client_id, client_id, CLIENT_ID_SIZE);
|
||||
memcpy(friend->public_key, client_id, CLIENT_ID_SIZE);
|
||||
|
||||
friend->nat.NATping_id = random_64b();
|
||||
++dht->num_friends;
|
||||
|
@ -1291,7 +1291,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *client_id, uint16_t lock_count)
|
|||
}
|
||||
|
||||
/* TODO: Optimize this. */
|
||||
int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port)
|
||||
int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
|
||||
{
|
||||
uint32_t i, j;
|
||||
|
||||
|
@ -1300,11 +1300,11 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port)
|
|||
|
||||
for (i = 0; i < dht->num_friends; ++i) {
|
||||
/* Equal */
|
||||
if (id_equal(dht->friends_list[i].client_id, client_id)) {
|
||||
if (id_equal(dht->friends_list[i].public_key, public_key)) {
|
||||
for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
|
||||
Client_data *client = &dht->friends_list[i].client_list[j];
|
||||
|
||||
if (id_equal(client->public_key, client_id)) {
|
||||
if (id_equal(client->public_key, public_key)) {
|
||||
IPPTsPng *assoc = NULL;
|
||||
uint32_t a;
|
||||
|
||||
|
@ -1378,7 +1378,7 @@ static void do_DHT_friends(DHT *dht)
|
|||
uint32_t i;
|
||||
|
||||
for (i = 0; i < dht->num_friends; ++i)
|
||||
do_ping_and_sendnode_requests(dht, &dht->friends_list[i].lastgetnode, dht->friends_list[i].client_id,
|
||||
do_ping_and_sendnode_requests(dht, &dht->friends_list[i].lastgetnode, dht->friends_list[i].public_key,
|
||||
dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &dht->friends_list[i].bootstrap_times);
|
||||
}
|
||||
|
||||
|
@ -1517,7 +1517,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
|
|||
++num_ipv6s;
|
||||
}
|
||||
|
||||
if (id_equal(client->public_key, friend->client_id))
|
||||
if (id_equal(client->public_key, friend->public_key))
|
||||
if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT))
|
||||
return 0; /* direct connectivity */
|
||||
}
|
||||
|
@ -1792,7 +1792,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
|
|||
IP_Port pinging;
|
||||
ip_copy(&pinging.ip, &ip);
|
||||
pinging.port = htons(firstport);
|
||||
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id);
|
||||
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key);
|
||||
} else {
|
||||
for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) {
|
||||
/* TODO: Improve port guessing algorithm. */
|
||||
|
@ -1800,7 +1800,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
|
|||
IP_Port pinging;
|
||||
ip_copy(&pinging.ip, &ip);
|
||||
pinging.port = htons(port);
|
||||
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id);
|
||||
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key);
|
||||
}
|
||||
|
||||
dht->friends_list[friend_num].nat.punching_index = i;
|
||||
|
@ -1814,7 +1814,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
|
|||
|
||||
for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) {
|
||||
pinging.port = htons(port + i);
|
||||
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id);
|
||||
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key);
|
||||
}
|
||||
|
||||
dht->friends_list[friend_num].nat.punching_index2 = i - (MAX_PUNCHING_PORTS / 2);
|
||||
|
@ -1837,7 +1837,7 @@ static void do_NAT(DHT *dht)
|
|||
continue;
|
||||
|
||||
if (dht->friends_list[i].nat.NATping_timestamp + PUNCH_INTERVAL < temp_time) {
|
||||
send_NATping(dht, dht->friends_list[i].client_id, dht->friends_list[i].nat.NATping_id, NAT_PING_REQUEST);
|
||||
send_NATping(dht, dht->friends_list[i].public_key, dht->friends_list[i].nat.NATping_id, NAT_PING_REQUEST);
|
||||
dht->friends_list[i].nat.NATping_timestamp = temp_time;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ typedef struct {
|
|||
#define DHT_FRIEND_MAX_LOCKS 32
|
||||
|
||||
typedef struct {
|
||||
uint8_t client_id[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[CLIENT_ID_SIZE];
|
||||
Client_data client_list[MAX_FRIEND_CLIENTS];
|
||||
|
||||
/* Time at which the last get_nodes request was sent. */
|
||||
|
|
|
@ -2340,7 +2340,7 @@ void do_messenger(Messenger *m)
|
|||
|
||||
LOGGER_TRACE("C[%2u] %s:%u [%3u] %s",
|
||||
client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port),
|
||||
last_pinged, ID2String(cptr->client_id));
|
||||
last_pinged, ID2String(cptr->public_key));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2360,7 +2360,7 @@ void do_messenger(Messenger *m)
|
|||
continue;
|
||||
|
||||
for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++)
|
||||
if (id_equal(m->friendlist[friend].real_pk, m->dht->friends_list[dhtfriend].client_id)) {
|
||||
if (id_equal(m->friendlist[friend].real_pk, m->dht->friends_list[dhtfriend].public_key)) {
|
||||
m2dht[friend] = dhtfriend;
|
||||
break;
|
||||
}
|
||||
|
@ -2390,7 +2390,7 @@ void do_messenger(Messenger *m)
|
|||
dht2m[friend], friend, msgfptr->name,
|
||||
ID2String(msgfptr->real_pk));
|
||||
} else {
|
||||
LOGGER_TRACE("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id));
|
||||
LOGGER_TRACE("F[--:%2u] %s", friend, ID2String(dhtfptr->public_key));
|
||||
}
|
||||
|
||||
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
|
||||
|
@ -2408,7 +2408,7 @@ void do_messenger(Messenger *m)
|
|||
LOGGER_TRACE("F[%2u] => C[%2u] %s:%u [%3u] %s",
|
||||
friend, client, ip_ntoa(&assoc->ip_port.ip),
|
||||
ntohs(assoc->ip_port.port), last_pinged,
|
||||
ID2String(cptr->client_id));
|
||||
ID2String(cptr->public_key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,13 +157,13 @@ static Client_entry *dist_index_entry(Assoc *assoc, uint64_t dist_ind)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* get actual entry's client_id to a distance_index */
|
||||
/* get actual entry's public_key to a distance_index */
|
||||
static uint8_t *dist_index_id(Assoc *assoc, uint64_t dist_ind)
|
||||
{
|
||||
Client_entry *entry = dist_index_entry(assoc, dist_ind);
|
||||
|
||||
if (entry)
|
||||
return entry->client.client_id;
|
||||
return entry->client.public_key;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ static uint8_t candidates_search(const Assoc *assoc, const uint8_t *id, hash_t h
|
|||
Client_entry *entry = &cnd_bckt->list[pos];
|
||||
|
||||
if (entry->hash == hash)
|
||||
if (id_equal(entry->client.client_id, id)) {
|
||||
if (id_equal(entry->client.public_key, id)) {
|
||||
*entryptr = entry;
|
||||
return 1;
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ static uint8_t candidates_create_new(const Assoc *assoc, hash_t hash, const uint
|
|||
return 0;
|
||||
|
||||
entry->hash = hash;
|
||||
id_copy(entry->client.client_id, id);
|
||||
id_copy(entry->client.public_key, id);
|
||||
|
||||
if (used)
|
||||
entry->used_at = unix_time();
|
||||
|
@ -536,7 +536,7 @@ static void client_id_self_update(Assoc *assoc)
|
|||
Client_entry *entry = &cnd_bckt->list[pos];
|
||||
|
||||
if (entry->hash == assoc->self_hash)
|
||||
if (id_equal(entry->client.client_id, assoc->self_client_id))
|
||||
if (id_equal(entry->client.public_key, assoc->self_client_id))
|
||||
entry->hash = 0;
|
||||
}
|
||||
}
|
||||
|
@ -648,7 +648,7 @@ uint8_t Assoc_get_close_entries(Assoc *assoc, Assoc_close_entries *state)
|
|||
continue;
|
||||
}
|
||||
|
||||
uint64_t dist = state->distance_absolute_func(assoc, state->custom_data, state->wanted_id, entry->client.client_id);
|
||||
uint64_t dist = state->distance_absolute_func(assoc, state->custom_data, state->wanted_id, entry->client.public_key);
|
||||
uint32_t index = b * assoc->candidates_bucket_size + i;
|
||||
dist_list[index] = (dist << DISTANCE_INDEX_INDEX_BITS) | index;
|
||||
}
|
||||
|
@ -914,7 +914,7 @@ void do_Assoc(Assoc *assoc, DHT *dht)
|
|||
continue;
|
||||
|
||||
if (!target_id)
|
||||
target_id = entry->client.client_id;
|
||||
target_id = entry->client.public_key;
|
||||
|
||||
if (entry->seen_at) {
|
||||
if (!seen)
|
||||
|
@ -940,9 +940,9 @@ void do_Assoc(Assoc *assoc, DHT *dht)
|
|||
IPPTsPng *ippts = seen->seen_family == AF_INET ? &seen->client.assoc4 : &seen->client.assoc6;
|
||||
|
||||
LOGGER_DEBUG("[%u] => S[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count),
|
||||
idpart2str(seen->client.client_id, 8), ip_ntoa(&ippts->ip_port.ip), htons(ippts->ip_port.port));
|
||||
idpart2str(seen->client.public_key, 8), ip_ntoa(&ippts->ip_port.ip), htons(ippts->ip_port.port));
|
||||
|
||||
DHT_getnodes(dht, &ippts->ip_port, seen->client.client_id, target_id);
|
||||
DHT_getnodes(dht, &ippts->ip_port, seen->client.public_key, target_id);
|
||||
seen->getnodes = unix_time();
|
||||
}
|
||||
|
||||
|
@ -950,9 +950,9 @@ void do_Assoc(Assoc *assoc, DHT *dht)
|
|||
IP_Port *ipp = heard->heard_family == AF_INET ? &heard->assoc_heard4 : &heard->assoc_heard6;
|
||||
|
||||
LOGGER_DEBUG("[%u] => H[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count),
|
||||
idpart2str(heard->client.client_id, 8), ip_ntoa(&ipp->ip), htons(ipp->port));
|
||||
idpart2str(heard->client.public_key, 8), ip_ntoa(&ipp->ip), htons(ipp->port));
|
||||
|
||||
DHT_getnodes(dht, ipp, heard->client.client_id, target_id);
|
||||
DHT_getnodes(dht, ipp, heard->client.public_key, target_id);
|
||||
heard->getnodes = unix_time();
|
||||
}
|
||||
|
||||
|
@ -1012,7 +1012,7 @@ void Assoc_status(const Assoc *assoc)
|
|||
total++;
|
||||
|
||||
LOGGER_TRACE("[%3i:%3i] %08x => [%s...] %i, %i(%c), %i(%c)\n",
|
||||
(int)bid, (int)cid, entry->hash, idpart2str(entry->client.client_id, 8),
|
||||
(int)bid, (int)cid, entry->hash, idpart2str(entry->client.public_key, 8),
|
||||
entry->used_at ? (int)(unix_time() - entry->used_at) : 0,
|
||||
entry->seen_at ? (int)(unix_time() - entry->seen_at) : 0,
|
||||
entry->seen_at ? (entry->seen_family == AF_INET ? '4' : (entry->seen_family == AF_INET6 ? '6' : '?')) : '?',
|
||||
|
|
|
@ -58,22 +58,22 @@ struct PING {
|
|||
#define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES)
|
||||
#define PING_DATA_SIZE (CLIENT_ID_SIZE + sizeof(IP_Port))
|
||||
|
||||
int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id)
|
||||
int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key)
|
||||
{
|
||||
uint8_t pk[DHT_PING_SIZE];
|
||||
int rc;
|
||||
uint64_t ping_id;
|
||||
|
||||
if (id_equal(client_id, ping->dht->self_public_key))
|
||||
if (id_equal(public_key, ping->dht->self_public_key))
|
||||
return 1;
|
||||
|
||||
uint8_t shared_key[crypto_box_BEFORENMBYTES];
|
||||
|
||||
// generate key to encrypt ping_id with recipient privkey
|
||||
DHT_get_shared_key_sent(ping->dht, shared_key, client_id);
|
||||
DHT_get_shared_key_sent(ping->dht, shared_key, public_key);
|
||||
// Generate random ping_id.
|
||||
uint8_t data[PING_DATA_SIZE];
|
||||
id_copy(data, client_id);
|
||||
id_copy(data, public_key);
|
||||
memcpy(data + CLIENT_ID_SIZE, &ipp, sizeof(IP_Port));
|
||||
ping_id = ping_array_add(&ping->ping_array, data, sizeof(data));
|
||||
|
||||
|
@ -100,13 +100,13 @@ int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id)
|
|||
return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
|
||||
}
|
||||
|
||||
static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *client_id, uint64_t ping_id,
|
||||
static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id,
|
||||
uint8_t *shared_encryption_key)
|
||||
{
|
||||
uint8_t pk[DHT_PING_SIZE];
|
||||
int rc;
|
||||
|
||||
if (id_equal(client_id, ping->dht->self_public_key))
|
||||
if (id_equal(public_key, ping->dht->self_public_key))
|
||||
return 1;
|
||||
|
||||
uint8_t ping_plain[PING_PLAIN_SIZE];
|
||||
|
@ -220,17 +220,17 @@ static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packe
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Check if client_id with ip_port is in the list.
|
||||
/* Check if public_key with ip_port is in the list.
|
||||
*
|
||||
* return 1 if it is.
|
||||
* return 0 if it isn't.
|
||||
*/
|
||||
static int in_list(const Client_data *list, uint16_t length, const uint8_t *client_id, IP_Port ip_port)
|
||||
static int in_list(const Client_data *list, uint16_t length, const uint8_t *public_key, IP_Port ip_port)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < length; ++i) {
|
||||
if (id_equal(list[i].client_id, client_id)) {
|
||||
if (id_equal(list[i].public_key, public_key)) {
|
||||
const IPPTsPng *ipptp;
|
||||
|
||||
if (ip_port.ip.family == AF_INET) {
|
||||
|
@ -250,31 +250,31 @@ static int in_list(const Client_data *list, uint16_t length, const uint8_t *clie
|
|||
/* Add nodes to the to_ping list.
|
||||
* All nodes in this list are pinged every TIME_TO_PING seconds
|
||||
* and are then removed from the list.
|
||||
* If the list is full the nodes farthest from our client_id are replaced.
|
||||
* If the list is full the nodes farthest from our public_key are replaced.
|
||||
* The purpose of this list is to enable quick integration of new nodes into the
|
||||
* network while preventing amplification attacks.
|
||||
*
|
||||
* return 0 if node was added.
|
||||
* return -1 if node was not added.
|
||||
*/
|
||||
int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port)
|
||||
int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port)
|
||||
{
|
||||
if (!ip_isset(&ip_port.ip))
|
||||
return -1;
|
||||
|
||||
if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, client_id, ip_port))
|
||||
if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, public_key, ip_port))
|
||||
return -1;
|
||||
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < MAX_TO_PING; ++i) {
|
||||
if (!ip_isset(&ping->to_ping[i].ip_port.ip)) {
|
||||
memcpy(ping->to_ping[i].public_key, client_id, CLIENT_ID_SIZE);
|
||||
memcpy(ping->to_ping[i].public_key, public_key, CLIENT_ID_SIZE);
|
||||
ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (memcmp(ping->to_ping[i].public_key, client_id, CLIENT_ID_SIZE) == 0) {
|
||||
if (memcmp(ping->to_ping[i].public_key, public_key, CLIENT_ID_SIZE) == 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -282,8 +282,8 @@ int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port)
|
|||
uint32_t r = rand();
|
||||
|
||||
for (i = 0; i < MAX_TO_PING; ++i) {
|
||||
if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].public_key, client_id) == 2) {
|
||||
memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, client_id, CLIENT_ID_SIZE);
|
||||
if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key) == 2) {
|
||||
memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key, CLIENT_ID_SIZE);
|
||||
ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,19 +29,19 @@ typedef struct PING PING;
|
|||
/* Add nodes to the to_ping list.
|
||||
* All nodes in this list are pinged every TIME_TOPING seconds
|
||||
* and are then removed from the list.
|
||||
* If the list is full the nodes farthest from our client_id are replaced.
|
||||
* If the list is full the nodes farthest from our public_key are replaced.
|
||||
* The purpose of this list is to enable quick integration of new nodes into the
|
||||
* network while preventing amplification attacks.
|
||||
*
|
||||
* return 0 if node was added.
|
||||
* return -1 if node was not added.
|
||||
*/
|
||||
int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port);
|
||||
int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port);
|
||||
void do_to_ping(PING *ping);
|
||||
|
||||
PING *new_ping(DHT *dht);
|
||||
void kill_ping(PING *ping);
|
||||
|
||||
int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id);
|
||||
int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key);
|
||||
|
||||
#endif /* __PING_H__ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user