Skip to content

Commit

Permalink
Major protocol changes, this commit breaks all network compatibility.
Browse files Browse the repository at this point in the history
Removed a bunch of useless space from various structs.

pack_nodes() and unpack_nodes() are now used to transmit lists of
nodes for the DHT and onion parts. They provide a way to transmit
both ipv6 and ipv4 nodes in the same packet in a portable way that
takes as little space as possible without compression.

Using pack_nodes, merged the send nodes and send nodes ipv6 packets
into one packet greatly reducing the risk of amplification attacks.
  • Loading branch information
irungentoo committed Apr 15, 2014
1 parent 229b2b2 commit f9bf7b0
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 299 deletions.
5 changes: 2 additions & 3 deletions auto_tests/network_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ START_TEST(test_struct_sizes)
{
ck_assert_msg(sizeof(IP4) == 4, "sizeof(IP4): expected result 4, got %u.", sizeof(IP4));
ck_assert_msg(sizeof(IP6) == 16, "sizeof(IP6): expected result 16, got %u.", sizeof(IP6));
ck_assert_msg(sizeof(IP) == 20, "sizeof(IP): expected result 20, got %u.", sizeof(IP));
ck_assert_msg(sizeof(IP_Port) == 24, "sizeof(IP_Port): expected result 24, got %u.", sizeof(IP_Port));
ck_assert_msg(sizeof(IP4_Port) == 8, "sizeof(IP4_Port): expected result 8, got %u.", sizeof(IP4_Port));
ck_assert_msg(sizeof(IP) == 17, "sizeof(IP): expected result 17, got %u.", sizeof(IP));
ck_assert_msg(sizeof(IP_Port) == 19, "sizeof(IP_Port): expected result 19, got %u.", sizeof(IP_Port));
}
END_TEST

Expand Down
16 changes: 4 additions & 12 deletions docs/updates/DHT.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ Protocol

Node format:
```
[char array (node_id), length=32 bytes][ip (in network byte order), length=4 bytes][port (in network byte order), length=2 bytes][Padding , length=2 bytes]
[uint8_t family (2 == IPv4, 10 == IPv6, 130 == TCP IPv4, 138 == TCP IPv6)][ip (in network byte order), length=4 bytes if ipv4, 16 bytes if ipv6][port (in network byte order), length=2 bytes][char array (node_id), length=32 bytes]
```
see also: DHT.h (Node4_format struct)

IPv6 Node format:
see: DHT.h (Node_format struct)
see also: DHT.h (pack_nodes() and unpack_nodes())

Valid queries and Responses:

Expand All @@ -102,12 +99,7 @@ Packet contents:
```
Valid replies: a send_nodes packet

Send_nodes (response (for ipv4 addresses)):
```
[byte with value: 03][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[Nodes in node format, length=40 * (number of nodes (maximum of 8 nodes)) bytes][Encrypted data, length=NODES_ENCRYPTED_MESSAGE_LENGTH bytes]]
```

Send_nodes_IPv6 (response (for ipv6 addresses)):
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:[Nodes in ipv6_node format, length=56 * (number of nodes (maximum of 8 nodes)) bytes][Encrypted data, length=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:[Nodes in node format, length=?? * (number of nodes (maximum of 8 nodes)) bytes][Encrypted data, length=NODES_ENCRYPTED_MESSAGE_LENGTH bytes]]
```

0 comments on commit f9bf7b0

Please sign in to comment.