Sendback data size is always 8 bytes.

pull/1202/head
irungentoo 2014-12-14 20:33:31 -05:00
parent 6f3312c137
commit 015a8b7d75
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 11 additions and 19 deletions

View File

@ -578,7 +578,8 @@ START_TEST(test_many_group)
for (i = 0; i < NUM_GROUP_TOX; ++i) {
int num_peers = tox_group_number_peers(toxes[i], 0);
ck_assert_msg(num_peers == NUM_GROUP_TOX, "Bad number of group peers. expected: %u got: %i, tox %u", NUM_GROUP_TOX, num_peers, i);
ck_assert_msg(num_peers == NUM_GROUP_TOX, "Bad number of group peers. expected: %u got: %i, tox %u", NUM_GROUP_TOX,
num_peers, i);
}
printf("group connected\n");
@ -600,7 +601,7 @@ START_TEST(test_many_group)
}
ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
for (k = NUM_GROUP_TOX; k != 0 ; --k) {
tox_del_groupchat(toxes[k - 1], 0);

View File

@ -95,11 +95,11 @@ ping_id = a random integer, the response must contain the exact same number as t
Get nodes (Request):
Packet contents:
```
[byte with value: 02][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[char array: requested_node_id (node_id of which we want the ip), length=32 bytes][Sendback data (must be sent back unmodified by in the response), length=1 to NODES_ENCRYPTED_MESSAGE_LENGTH bytes]]
[byte with value: 02][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[char array: requested_node_id (node_id of which we want the ip), length=32 bytes][Sendback data (must be sent back unmodified by in the response), length=8 bytes]]
```
Valid replies: a send_nodes packet
Send_nodes (response (for all addresses)):
```
[byte with value: 04][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[uint8_t number of nodes in this packet][Nodes in node format, length=?? * (number of nodes (maximum of 8 nodes)) bytes][Sendback data, length=1 to NODES_ENCRYPTED_MESSAGE_LENGTH bytes]]
[byte with value: 04][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[uint8_t number of nodes in this packet][Nodes in node format, length=?? * (number of nodes (maximum of 8 nodes)) bytes][Sendback data, length=8 bytes]]
```

View File

@ -828,8 +828,6 @@ end:
return 0;
}
#define NODES_ENCRYPTED_MESSAGE_LENGTH (crypto_box_NONCEBYTES + sizeof(uint64_t) + sizeof(Node_format) + sizeof(Node_format) + crypto_box_MACBYTES)
/* Send a getnodes request.
sendback_node is the node that it will send back the response to (set to NULL to disable this) */
static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id,
@ -896,7 +894,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
if (id_equal(public_key, dht->self_public_key))
return -1;
if (length > NODES_ENCRYPTED_MESSAGE_LENGTH || length == 0)
if (length != sizeof(uint64_t))
return -1;
size_t Node_format_size = sizeof(Node_format);
@ -940,36 +938,29 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
{
uint32_t cmp_len = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + crypto_box_MACBYTES;
if (length <= cmp_len)
if (length != (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES))
return 1;
if (length > cmp_len + NODES_ENCRYPTED_MESSAGE_LENGTH)
return 1;
uint16_t sendback_data_length = length - cmp_len;
DHT *dht = object;
/* Check if packet is from ourself. */
if (id_equal(packet + 1, dht->self_public_key))
return 1;
uint8_t plain[CLIENT_ID_SIZE + sendback_data_length];
uint8_t plain[CLIENT_ID_SIZE + sizeof(uint64_t)];
uint8_t shared_key[crypto_box_BEFORENMBYTES];
DHT_get_shared_key_recv(dht, shared_key, packet + 1);
int len = decrypt_data_symmetric( shared_key,
packet + 1 + CLIENT_ID_SIZE,
packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES,
CLIENT_ID_SIZE + sendback_data_length + crypto_box_MACBYTES,
CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES,
plain );
if (len != CLIENT_ID_SIZE + sendback_data_length)
if (len != CLIENT_ID_SIZE + sizeof(uint64_t))
return 1;
sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sendback_data_length, shared_key);
sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sizeof(uint64_t), shared_key);
add_to_ping(dht->ping, packet + 1, source);