summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-12-07 19:06:41 -0500
committerirungentoo <irungentoo@gmail.com>2013-12-07 19:06:41 -0500
commit1c45e5993858a4fc0e85858975e3206a657b9f94 (patch)
treec79b883aeb3cfefba7f1a2d86cbe97fda887dd4c /docs
parentd078c5e9c2f1727502bce7db1b7de7e2fc4880ce (diff)
Added/updated some basic docs and cleaned up some things.
Diffstat (limited to 'docs')
-rw-r--r--docs/Hardening_docs.txt21
-rw-r--r--docs/updates/DHT.md113
2 files changed, 134 insertions, 0 deletions
diff --git a/docs/Hardening_docs.txt b/docs/Hardening_docs.txt
new file mode 100644
index 00000000..08c6ef13
--- /dev/null
+++ b/docs/Hardening_docs.txt
@@ -0,0 +1,21 @@
1Hardening request packets are sent as crypto request packets (see crypto docs.)
2NOTE: currently only get nodes requests are tested in the code which is why there is only one test (more will be added soon.)
3
4All hardening requests must contain exactly 768 bytes of data. (The data sent must be padded with zeros if it is smaller than that.)
5
61. Get the information (IP_port, client_id) of the node we want to test.
72. Find a couple random nodes that is not that node (one for each test.)
83. Send crypto request packets to each of these random nodes with the data being:
9
10[byte with value: 02 (get nodes test request)][struct Node_format (the node to test.)][client_id(32 bytes) the id to query the node with.][padding]
11
124. The random node receives a packet.
13-The packet is a get nodes test request:
14 send a get_node request to that node with the id to query in the request.
15 when a send_node response is received, send the following response to the person who sent us the get nodes test request packet:
16 [byte with value: 03 (get nodes test response)][client_id(32 bytes): the id that the node was queried with][The list of nodes it responded with in IPv6 Node format (struct Node_Format)]
17 PROTIP: (get node requests and response contain an encrypted part that you can use to store information so that you don't
18 have to store in your memory where/if to send back the response from the send node)
19
205. Receive the test responses.
21-If the test(s) pass (the nodes behave in a satisfactory manner), make these nodes have priority over those who don't pass the test(s).
diff --git a/docs/updates/DHT.md b/docs/updates/DHT.md
new file mode 100644
index 00000000..79ec8c4b
--- /dev/null
+++ b/docs/updates/DHT.md
@@ -0,0 +1,113 @@
1DHT protocol
2============
3
4Follows pretty much the principle of the torrent DHT: http://www.bittorrent.org/beps/bep_0005.html (READ IT)
5
6But:
7Vastly simplified packet format and encryption.
8
9Boostrapping:
10The first time you install the client we bootstrap it with a node on our servers.(bandwidth should not be a problem as the client only needs to be sent one reply.)
11
12
13Basics
14------
15(All the numbers here are just guesses and are probably not optimal values)
16
17client list: A list of node ids closest (mathematically see bittorrent doc) to ours matched with ip addresses + port number corresponding to that id and a timestamp containing the time or time since the client was successfully pinged.
18
19"friends" list: A list containing the node_ids of all our "friends" or clients we want to connect to.
20Also contains the ip addresses + port + node_ids + timestamp(of last ping like in the client list) of the 8 clients closest (mathematically see bittorrent doc) to each "friend"
21
22One pinged lists:
23-One for storing a list of ips along with their ping_ids and a timestamp for the ping requests
24Entries in the pinged lists expire after 5 seconds.
25If one of the lists becomes full, the expire rate reduces itself one second or the new ping takes the place of the oldest one.
26
27
28Entries in client list and "friends" list expire after 300 seconds without ping response.
29Each client stores a maximum of 32 entries in its client list.
30Each client in the client list and "friends" list is pinged every 60 seconds.
31Each client in the client list and "friends" list has a timestamp which denote the last time it was successfully pinged.
32If the corresponding clients timestamp is more than 130 seconds old it is considered bad.
33Send a get nodes request every 20 seconds to a random good node for each "friend" in our "friends" list.
34Send a get nodes request every 20 seconds to a random good node in the client list.
35
36
37When a client receives any request from another
38-----------------------------------------------
39-Respond to the request
40 -Ping request is replied to with with a ping response containing the same encrypted data
41 -Get nodes request is replied with a send nodes reply containing the same encrypted data and the good nodes from the client list and/or the "friends" list that are closest to the requested_node_id
42
43-If the requesting client is not in the client list:
44 -If there are no bad clients in the list and the list is full:
45 -If the id of the other client is closer (mathematically see bittorrent doc) than at least one of the clients in the list or our "friends" list:
46 -Send a ping request to the client.
47 -if not forget about the client.
48
49 -If there are bad clients and/or the list isn't full:
50 -Send a ping request to the client
51
52When a client receives a response
53---------------------------------
54-Ping response
55 -If the node was previously pinged with a matching ping_id (check in the corresponding pinged list.)
56 -If the node is in the client list the matching client's timestamp is set to current time.
57 -If the node is in the "friends" list the matching client's timestamp is set to current time for every occurrence.
58 -If the node is not in the client list:
59 -If the list isn't full, add it to the list.
60 -If the list is full, the furthest away (mathematically see bittorrent doc) bad client is replaced by the new one.
61 -If the list is filled with good nodes replace the furthest client with it only if it is closer than the replaced node.
62 -for each friend in the "friends" list:
63 -If that friend's client list isn't full, add that client to it
64 -If that friend's client list contains bad clients, replace the furthest one with that client.
65 -If that friend's client list contains only good clients
66 -If the client is closer to the friend than one of the other clients, it replaces the farthest one
67 -If not, nothing happens.
68
69 -Send nodes
70 -If the ping_id matches what we sent previously (check in the corresponding pinged list.):
71 -Each node in the response is pinged.
72
73
74
75
76
77Protocol
78--------
79
80Node format:
81```
82[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]
83```
84see also: DHT.h (Node4_format struct)
85
86IPv6 Node format:
87see: DHT.h (Node_format struct)
88
89Valid queries and Responses:
90
91Ping(Request and response):
92```
93[byte with value: 00 for request, 01 for response][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender: [random 8 byte (ping_id)]]
94```
95ping_id = a random integer, the response must contain the exact same number as the request
96
97
98Get nodes (Request):
99Packet contents:
100```
101[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][Encrypted data (must be sent back unmodified by in the response), length=NODES_ENCRYPTED_MESSAGE_LENGTH bytes]]
102```
103Valid replies: a send_nodes packet
104
105Send_nodes (response (for ipv4 addresses)):
106```
107[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]]
108```
109
110Send_nodes_IPv6 (response (for ipv6 addresses)):
111```
112[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]]
113```