Code cleanups.

Rename array in Node_format from client_id to public_key.
This commit is contained in:
irungentoo 2015-01-29 19:38:44 -05:00
parent b83ff00c27
commit f463cb52a2
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
9 changed files with 76 additions and 75 deletions

View File

@ -138,12 +138,12 @@ START_TEST(test_basic)
IP_Port on1 = {ip, onion1->net->port};
Node_format n1;
memcpy(n1.client_id, onion1->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
memcpy(n1.public_key, onion1->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
n1.ip_port = on1;
IP_Port on2 = {ip, onion2->net->port};
Node_format n2;
memcpy(n2.client_id, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
memcpy(n2.public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
n2.ip_port = on2;
Node_format nodes[4];
@ -180,7 +180,7 @@ START_TEST(test_basic)
randombytes(sb_data, sizeof(sb_data));
uint64_t s;
memcpy(&s, sb_data, sizeof(uint64_t));
memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(test_3_pub_key, nodes[3].public_key, crypto_box_PUBLICKEYBYTES);
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);

View File

@ -207,7 +207,7 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
}
if (ipv6 == 0) {
uint32_t size = 1 + sizeof(IP4) + sizeof(uint16_t) + CLIENT_ID_SIZE;
uint32_t size = 1 + sizeof(IP4) + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES;
if (packed_length + size > length)
return -1;
@ -215,10 +215,10 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
data[packed_length] = net_family;
memcpy(data + packed_length + 1, &nodes[i].ip_port.ip.ip4, sizeof(IP4));
memcpy(data + packed_length + 1 + sizeof(IP4), &nodes[i].ip_port.port, sizeof(uint16_t));
memcpy(data + packed_length + 1 + sizeof(IP4) + sizeof(uint16_t), nodes[i].client_id, CLIENT_ID_SIZE);
memcpy(data + packed_length + 1 + sizeof(IP4) + sizeof(uint16_t), nodes[i].public_key, crypto_box_PUBLICKEYBYTES);
packed_length += size;
} else if (ipv6 == 1) {
uint32_t size = 1 + sizeof(IP6) + sizeof(uint16_t) + CLIENT_ID_SIZE;
uint32_t size = 1 + sizeof(IP6) + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES;
if (packed_length + size > length)
return -1;
@ -226,7 +226,7 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
data[packed_length] = net_family;
memcpy(data + packed_length + 1, &nodes[i].ip_port.ip.ip6, sizeof(IP6));
memcpy(data + packed_length + 1 + sizeof(IP6), &nodes[i].ip_port.port, sizeof(uint16_t));
memcpy(data + packed_length + 1 + sizeof(IP6) + sizeof(uint16_t), nodes[i].client_id, CLIENT_ID_SIZE);
memcpy(data + packed_length + 1 + sizeof(IP6) + sizeof(uint16_t), nodes[i].public_key, crypto_box_PUBLICKEYBYTES);
packed_length += size;
} else {
return -1;
@ -275,7 +275,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
}
if (ipv6 == 0) {
uint32_t size = 1 + sizeof(IP4) + sizeof(uint16_t) + CLIENT_ID_SIZE;
uint32_t size = 1 + sizeof(IP4) + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES;
if (len_processed + size > length)
return -1;
@ -283,11 +283,11 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
nodes[num].ip_port.ip.family = host_family;
memcpy(&nodes[num].ip_port.ip.ip4, data + len_processed + 1, sizeof(IP4));
memcpy(&nodes[num].ip_port.port, data + len_processed + 1 + sizeof(IP4), sizeof(uint16_t));
memcpy(nodes[num].client_id, data + len_processed + 1 + sizeof(IP4) + sizeof(uint16_t), CLIENT_ID_SIZE);
memcpy(nodes[num].public_key, data + len_processed + 1 + sizeof(IP4) + sizeof(uint16_t), crypto_box_PUBLICKEYBYTES);
len_processed += size;
++num;
} else if (ipv6 == 1) {
uint32_t size = 1 + sizeof(IP6) + sizeof(uint16_t) + CLIENT_ID_SIZE;
uint32_t size = 1 + sizeof(IP6) + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES;
if (len_processed + size > length)
return -1;
@ -295,7 +295,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
nodes[num].ip_port.ip.family = host_family;
memcpy(&nodes[num].ip_port.ip.ip6, data + len_processed + 1, sizeof(IP6));
memcpy(&nodes[num].ip_port.port, data + len_processed + 1 + sizeof(IP6), sizeof(uint16_t));
memcpy(nodes[num].client_id, data + len_processed + 1 + sizeof(IP6) + sizeof(uint16_t), CLIENT_ID_SIZE);
memcpy(nodes[num].public_key, data + len_processed + 1 + sizeof(IP6) + sizeof(uint16_t), crypto_box_PUBLICKEYBYTES);
len_processed += size;
++num;
} else {
@ -397,12 +397,12 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u
* return 1 if true.
* return 0 if false.
*/
static int client_in_nodelist(const Node_format *list, uint16_t length, const uint8_t *client_id)
static int client_in_nodelist(const Node_format *list, uint16_t length, const uint8_t *public_key)
{
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))
return 1;
}
@ -484,9 +484,9 @@ static void get_close_nodes_inner(const uint8_t *client_id, Node_format *nodes_l
continue;
if (num_nodes < MAX_SENT_NODES) {
memcpy(nodes_list[num_nodes].client_id,
memcpy(nodes_list[num_nodes].public_key,
client->client_id,
CLIENT_ID_SIZE );
crypto_box_PUBLICKEYBYTES );
nodes_list[num_nodes].ip_port = ipptp->ip_port;
num_nodes++;
@ -497,14 +497,14 @@ static void get_close_nodes_inner(const uint8_t *client_id, Node_format *nodes_l
*/
for (j = 0; j < MAX_SENT_NODES; ++j) {
closest = id_closest( client_id,
nodes_list[j].client_id,
nodes_list[j].public_key,
client->client_id );
/* second client_id is closer than current: change to it */
if (closest == 2) {
memcpy( nodes_list[j].client_id,
memcpy( nodes_list[j].public_key,
client->client_id,
CLIENT_ID_SIZE);
crypto_box_PUBLICKEYBYTES);
nodes_list[j].ip_port = ipptp->ip_port;
break;
@ -583,7 +583,7 @@ int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes
Client_data *client = result[i];
if (client) {
id_copy(nodes_list[num_returned].client_id, client->client_id);
id_copy(nodes_list[num_returned].public_key, client->client_id);
if (sa_family == AF_INET)
if (ipport_isset(&client->assoc4.ip_port)) {
@ -897,7 +897,7 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
uint8_t plain_message[sizeof(Node_format) * 2] = {0};
Node_format receiver;
memcpy(receiver.client_id, public_key, CLIENT_ID_SIZE);
memcpy(receiver.public_key, public_key, CLIENT_ID_SIZE);
receiver.ip_port = ip_port;
memcpy(plain_message, &receiver, sizeof(receiver));
@ -1041,7 +1041,7 @@ static uint8_t sent_getnode_to_node(DHT *dht, const uint8_t *client_id, IP_Port
Node_format test;
memcpy(&test, data, sizeof(Node_format));
if (!ipport_equal(&test.ip_port, &node_ip_port) || memcmp(test.client_id, client_id, CLIENT_ID_SIZE) != 0)
if (!ipport_equal(&test.ip_port, &node_ip_port) || memcmp(test.public_key, client_id, CLIENT_ID_SIZE) != 0)
return 0;
return 1;
@ -1129,9 +1129,9 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *pa
for (i = 0; i < num_nodes; i++) {
if (ipport_isset(&plain_nodes[i].ip_port) && (LAN_ip(plain_nodes[i].ip_port.ip) == 0
|| ping_node_from_getnodes_ok(dht, plain_nodes[i].client_id))) {
send_ping_request(dht->ping, plain_nodes[i].ip_port, plain_nodes[i].client_id);
returnedip_ports(dht, plain_nodes[i].ip_port, plain_nodes[i].client_id, packet + 1);
|| ping_node_from_getnodes_ok(dht, plain_nodes[i].public_key))) {
send_ping_request(dht->ping, plain_nodes[i].ip_port, plain_nodes[i].public_key);
returnedip_ports(dht, plain_nodes[i].ip_port, plain_nodes[i].public_key, packet + 1);
}
}
@ -1885,7 +1885,7 @@ static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8
uint8_t data[HARDREQ_DATA_SIZE] = {0};
data[0] = type;
memcpy(data + 1, contents, length);
int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->client_id, data,
int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data,
sizeof(data), CRYPTO_PACKET_HARDENING);
if (len == -1)
@ -1915,7 +1915,7 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto,
data[0] = CHECK_TYPE_GETNODE_RES;
memcpy(data + 1, queried_client_id, CLIENT_ID_SIZE);
memcpy(data + 1 + CLIENT_ID_SIZE, nodes_data, nodes_data_length);
int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->client_id, data,
int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data,
sizeof(data), CRYPTO_PACKET_HARDENING);
if (len == -1)
@ -1952,12 +1952,12 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num)
uint32_t i;
for (i = 0; i < num; ++i) {
if (id_equal(nodes[i].client_id, dht->self_public_key)) {
if (id_equal(nodes[i].public_key, dht->self_public_key)) {
++counter;
continue;
}
IPPTsPng *temp = get_closelist_IPPTsPng(dht, nodes[i].client_id, nodes[i].ip_port.ip.family);
IPPTsPng *temp = get_closelist_IPPTsPng(dht, nodes[i].public_key, nodes[i].ip_port.ip.family);
if (temp) {
if (!is_timeout(temp->timestamp, BAD_NODE_TIMEOUT)) {
@ -1990,10 +1990,10 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
Node_format node, tocheck_node;
node.ip_port = source;
memcpy(node.client_id, source_pubkey, CLIENT_ID_SIZE);
memcpy(node.public_key, source_pubkey, crypto_box_PUBLICKEYBYTES);
memcpy(&tocheck_node, packet + 1, sizeof(Node_format));
if (getnodes(dht, tocheck_node.ip_port, tocheck_node.client_id, packet + 1 + sizeof(Node_format), &node) == -1)
if (getnodes(dht, tocheck_node.ip_port, tocheck_node.public_key, packet + 1 + sizeof(Node_format), &node) == -1)
return 1;
return 0;
@ -2090,7 +2090,7 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
}
if (assoc != NULL) {
memcpy(nodes[count].client_id, list[i - 1].client_id, CLIENT_ID_SIZE);
memcpy(nodes[count].public_key, list[i - 1].client_id, CLIENT_ID_SIZE);
nodes[count].ip_port = assoc->ip_port;
++count;
@ -2129,16 +2129,16 @@ void do_hardening(DHT *dht)
if (!ipport_isset(&rand_node.ip_port))
continue;
if (id_equal(client_id, rand_node.client_id))
if (id_equal(client_id, rand_node.public_key))
continue;
Node_format to_test;
to_test.ip_port = cur_iptspng->ip_port;
memcpy(to_test.client_id, client_id, CLIENT_ID_SIZE);
memcpy(to_test.public_key, client_id, crypto_box_PUBLICKEYBYTES);
//TODO: The search id should maybe not be ours?
if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) {
memcpy(cur_iptspng->hardening.send_nodes_pingedid, rand_node.client_id, CLIENT_ID_SIZE);
memcpy(cur_iptspng->hardening.send_nodes_pingedid, rand_node.public_key, crypto_box_PUBLICKEYBYTES);
cur_iptspng->hardening.send_nodes_timestamp = unix_time();
}
}

View File

@ -148,7 +148,7 @@ typedef struct {
} DHT_Friend;
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
IP_Port ip_port;
}
Node_format;

View File

@ -2234,7 +2234,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
int i;
for (i = 0; i < n; i++) {
add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id);
add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].public_key);
}
break;
@ -2359,7 +2359,7 @@ void do_messenger(Messenger *m)
int i;
for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) {
add_tcp_relay(m->net_crypto, m->loaded_relays[i].ip_port, m->loaded_relays[i].client_id);
add_tcp_relay(m->net_crypto, m->loaded_relays[i].ip_port, m->loaded_relays[i].public_key);
}
}
@ -2767,7 +2767,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
uint32_t i;
for (i = 0; i < NUM_SAVED_PATH_NODES; ++i) {
onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].client_id);
onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key);
}
break;

View File

@ -1798,7 +1798,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
uint32_t i;
for (i = 0; i < conn->num_tcp_relays; ++i) {
if (memcmp(TCP_con->public_key, conn->tcp_relays[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) {
if (memcmp(TCP_con->public_key, conn->tcp_relays[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) {
set_conn_tcp_status(conn, location, STATUS_TCP_INVISIBLE);
return 0;
}
@ -1977,7 +1977,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
uint32_t i;
for (i = 0; i < conn->num_tcp_relays; ++i) {
if (memcmp(conn->tcp_relays[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) {
if (memcmp(conn->tcp_relays[i].public_key, public_key, crypto_box_PUBLICKEYBYTES) == 0) {
conn->tcp_relays[i].ip_port = ip_port;
return 0;
}
@ -1986,10 +1986,10 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
if (conn->num_tcp_relays == MAX_TCP_RELAYS_PEER) {
uint16_t index = rand() % MAX_TCP_RELAYS_PEER;
conn->tcp_relays[index].ip_port = ip_port;
memcpy(conn->tcp_relays[index].client_id, public_key, crypto_box_PUBLICKEYBYTES);
memcpy(conn->tcp_relays[index].public_key, public_key, crypto_box_PUBLICKEYBYTES);
} else {
conn->tcp_relays[conn->num_tcp_relays].ip_port = ip_port;
memcpy(conn->tcp_relays[conn->num_tcp_relays].client_id, public_key, crypto_box_PUBLICKEYBYTES);
memcpy(conn->tcp_relays[conn->num_tcp_relays].public_key, public_key, crypto_box_PUBLICKEYBYTES);
++conn->num_tcp_relays;
}
@ -2108,7 +2108,7 @@ unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_rel
for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
if (c->tcp_connections[i] != NULL) {
memcpy(tcp_relays[copied].client_id, c->tcp_connections[i]->public_key, crypto_box_PUBLICKEYBYTES);
memcpy(tcp_relays[copied].public_key, c->tcp_connections[i]->public_key, crypto_box_PUBLICKEYBYTES);
tcp_relays[copied].ip_port = c->tcp_connections[i]->ip_port;
if (tcp_relays[copied].ip_port.ip.family == AF_INET) {

View File

@ -116,27 +116,27 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
if (!new_path || !nodes)
return -1;
encrypt_precompute(nodes[0].client_id, dht->self_secret_key, new_path->shared_key1);
encrypt_precompute(nodes[0].public_key, dht->self_secret_key, new_path->shared_key1);
memcpy(new_path->public_key1, dht->self_public_key, crypto_box_PUBLICKEYBYTES);
uint8_t random_public_key[crypto_box_PUBLICKEYBYTES];
uint8_t random_secret_key[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(random_public_key, random_secret_key);
encrypt_precompute(nodes[1].client_id, random_secret_key, new_path->shared_key2);
encrypt_precompute(nodes[1].public_key, random_secret_key, new_path->shared_key2);
memcpy(new_path->public_key2, random_public_key, crypto_box_PUBLICKEYBYTES);
crypto_box_keypair(random_public_key, random_secret_key);
encrypt_precompute(nodes[2].client_id, random_secret_key, new_path->shared_key3);
encrypt_precompute(nodes[2].public_key, random_secret_key, new_path->shared_key3);
memcpy(new_path->public_key3, random_public_key, crypto_box_PUBLICKEYBYTES);
new_path->ip_port1 = nodes[0].ip_port;
new_path->ip_port2 = nodes[1].ip_port;
new_path->ip_port3 = nodes[2].ip_port;
memcpy(new_path->node_public_key1, nodes[0].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key2, nodes[1].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key3, nodes[2].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key1, nodes[0].public_key, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key2, nodes[1].public_key, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key3, nodes[2].public_key, crypto_box_PUBLICKEYBYTES);
return 0;
}
@ -155,9 +155,9 @@ int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_
nodes[1].ip_port = path->ip_port2;
nodes[2].ip_port = path->ip_port3;
memcpy(nodes[0].client_id, path->node_public_key1, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[1].client_id, path->node_public_key2, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[2].client_id, path->node_public_key3, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[0].public_key, path->node_public_key1, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[1].public_key, path->node_public_key2, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[2].public_key, path->node_public_key3, crypto_box_PUBLICKEYBYTES);
return 0;
}

View File

@ -134,7 +134,7 @@ int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_for
uint64_t sendback_data)
{
uint8_t request[ONION_ANNOUNCE_REQUEST_SIZE];
int len = create_announce_request(request, sizeof(request), dest.client_id, public_key, secret_key, ping_id, client_id,
int len = create_announce_request(request, sizeof(request), dest.public_key, public_key, secret_key, ping_id, client_id,
data_public_key, sendback_data);
if (len != sizeof(request))

View File

@ -38,7 +38,7 @@
* return -1 on failure
* return 0 on success
*/
int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id)
int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key)
{
if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6)
return -1;
@ -46,12 +46,12 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t
unsigned int i;
for (i = 0; i < MAX_PATH_NODES; ++i) {
if (memcmp(client_id, onion_c->path_nodes_bs[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
if (memcmp(public_key, onion_c->path_nodes_bs[i].public_key, crypto_box_PUBLICKEYBYTES) == 0)
return -1;
}
onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].ip_port = ip_port;
memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].client_id, client_id,
memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].public_key, public_key,
crypto_box_PUBLICKEYBYTES);
uint16_t last = onion_c->path_nodes_index_bs;
@ -68,7 +68,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t
* return -1 on failure
* return 0 on success
*/
static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id)
static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key)
{
if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6)
return -1;
@ -76,12 +76,13 @@ static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uin
unsigned int i;
for (i = 0; i < MAX_PATH_NODES; ++i) {
if (memcmp(client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
if (memcmp(public_key, onion_c->path_nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0)
return -1;
}
onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port;
memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].client_id, client_id, crypto_box_PUBLICKEYBYTES);
memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].public_key, public_key,
crypto_box_PUBLICKEYBYTES);
uint16_t last = onion_c->path_nodes_index;
++onion_c->path_nodes_index;
@ -273,7 +274,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t
unsigned int i;
for (i = 0; i < path_len; ++i) {
onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].client_id);
onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key);
}
}
@ -571,16 +572,16 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
continue;
if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT)
|| id_closest(reference_id, list_nodes[0].client_id, nodes[i].client_id) == 2) {
|| id_closest(reference_id, list_nodes[0].client_id, nodes[i].public_key) == 2) {
/* check if node is already in list. */
for (j = 0; j < MAX_ONION_CLIENTS; ++j) {
if (memcmp(list_nodes[j].client_id, nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) {
if (memcmp(list_nodes[j].client_id, nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) {
break;
}
}
if (j == MAX_ONION_CLIENTS && good_to_ping(last_pinged, last_pinged_index, nodes[i].client_id)) {
client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL, ~0);
if (j == MAX_ONION_CLIENTS && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) {
client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, NULL, ~0);
}
}
}
@ -727,12 +728,12 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co
uint8_t family = nodes[i].ip_port.ip.family;
if (family == AF_INET || family == AF_INET6) {
DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].client_id, onion_c->friends_list[friend_num].fake_client_id);
DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].fake_client_id);
} else if (family == TCP_INET || family == TCP_INET6) {
if (onion_c->friends_list[friend_num].tcp_relay_node_callback) {
void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object;
uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number;
onion_c->friends_list[friend_num].tcp_relay_node_callback(obj, number, nodes[i].ip_port, nodes[i].client_id);
onion_c->friends_list[friend_num].tcp_relay_node_callback(obj, number, nodes[i].ip_port, nodes[i].public_key);
}
}
}
@ -1191,7 +1192,7 @@ static void populate_path_nodes(Onion_Client *onion_c)
unsigned int i;
for (i = 0; i < num_nodes; ++i) {
onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].client_id);
onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key);
}
}
@ -1203,7 +1204,7 @@ static void populate_path_nodes_tcp(Onion_Client *onion_c)
unsigned int i;
for (i = 0; i < num_nodes; ++i) {
onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].client_id);
onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key);
}
}
@ -1263,7 +1264,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
for (j = 0; j < n; ++j) {
unsigned int num = rand() % num_nodes;
client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port,
onion_c->path_nodes[num].client_id, 0, ~0);
onion_c->path_nodes[num].public_key, 0, ~0);
}
++onion_c->friends_list[friendnum].run_count;
@ -1342,7 +1343,7 @@ static void do_announce(Onion_Client *onion_c)
if (num_nodes != 0) {
for (i = 0; i < (MAX_ONION_CLIENTS / 2); ++i) {
unsigned int num = rand() % num_nodes;
client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].client_id, 0, ~0);
client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, 0, ~0);
}
}
}

View File

@ -269,12 +269,12 @@ int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port)
for (i = 0; i < MAX_TO_PING; ++i) {
if (!ip_isset(&ping->to_ping[i].ip_port.ip)) {
memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE);
memcpy(ping->to_ping[i].public_key, client_id, CLIENT_ID_SIZE);
ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
return 0;
}
if (memcmp(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE) == 0) {
if (memcmp(ping->to_ping[i].public_key, client_id, 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].client_id, client_id) == 2) {
memcpy(ping->to_ping[(i + r) % MAX_TO_PING].client_id, client_id, CLIENT_ID_SIZE);
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);
ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port);
return 0;
}
@ -311,7 +311,7 @@ void do_to_ping(PING *ping)
if (!ip_isset(&ping->to_ping[i].ip_port.ip))
return;
send_ping_request(ping, ping->to_ping[i].ip_port, ping->to_ping[i].client_id);
send_ping_request(ping, ping->to_ping[i].ip_port, ping->to_ping[i].public_key);
ip_reset(&ping->to_ping[i].ip_port.ip);
}
}