diff options
author | irungentoo <irungentoo@gmail.com> | 2013-06-25 12:11:11 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-06-25 12:11:11 -0400 |
commit | 3396d8e495598c2b8ee1cdb2dd5f748647971c26 (patch) | |
tree | de7d07e18488976db5687454ba8c1929cef1a2c8 /testing | |
parent | 338bfc151023474bd09030cbededa49d0816efc6 (diff) |
DHT implementation finished. Currently testing it.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 8 | ||||
-rw-r--r-- | testing/rect.py | 24 |
2 files changed, 28 insertions, 4 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index fae4e001..1c5286e7 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -9,6 +9,8 @@ | |||
9 | 9 | ||
10 | #include "../core/DHT.h" | 10 | #include "../core/DHT.h" |
11 | 11 | ||
12 | #include <string.h> | ||
13 | |||
12 | //Sleep function (x = milliseconds) | 14 | //Sleep function (x = milliseconds) |
13 | #ifdef WIN32 | 15 | #ifdef WIN32 |
14 | 16 | ||
@@ -100,7 +102,11 @@ int main(int argc, char *argv[]) | |||
100 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 102 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
101 | printf("--------------------BEGIN-----------------------------\n"); | 103 | printf("--------------------BEGIN-----------------------------\n"); |
102 | for(i = 0; i < length; i++) | 104 | for(i = 0; i < length; i++) |
103 | printf("%c",data[i]); | 105 | { |
106 | if(data[i] < 16) | ||
107 | printf("0"); | ||
108 | printf("%X",data[i]); | ||
109 | } | ||
104 | printf("\n--------------------END-----------------------------\n\n\n"); | 110 | printf("\n--------------------END-----------------------------\n\n\n"); |
105 | } | 111 | } |
106 | else | 112 | else |
diff --git a/testing/rect.py b/testing/rect.py index 94baeaec..816e6e8c 100644 --- a/testing/rect.py +++ b/testing/rect.py | |||
@@ -1,6 +1,7 @@ | |||
1 | #basic python UDP script | 1 | #basic python UDP script |
2 | #for testing only | 2 | #for testing only |
3 | import socket | 3 | import socket |
4 | import random | ||
4 | 5 | ||
5 | UDP_IP = "127.0.0.1" | 6 | UDP_IP = "127.0.0.1" |
6 | UDP_PORT = 5004 | 7 | UDP_PORT = 5004 |
@@ -9,11 +10,28 @@ sock = socket.socket(socket.AF_INET, # Internet | |||
9 | socket.SOCK_DGRAM) # UDP | 10 | socket.SOCK_DGRAM) # UDP |
10 | sock.bind((UDP_IP, UDP_PORT)) | 11 | sock.bind((UDP_IP, UDP_PORT)) |
11 | 12 | ||
13 | #our client_id | ||
14 | client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32))) | ||
15 | |||
16 | print client_id | ||
17 | |||
12 | #send ping request to our DHT on localhost. | 18 | #send ping request to our DHT on localhost. |
13 | sock.sendto("0012345678".decode("hex") + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", ('127.0.0.1', 33445)) | 19 | sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445)) |
14 | 20 | ||
15 | #print all packets recieved and respond to ping requests properly | 21 | #print all packets recieved and respond to ping requests properly |
16 | while True: | 22 | while True: |
17 | data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes | 23 | data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes |
18 | print "received message:", data, " From:", addr | 24 | print "received message:", data.encode('hex'), " From:", addr |
19 | sock.sendto("01".decode('hex') + data[1:5] + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", addr) | 25 | #if we recieve a ping request. |
26 | print data[0].encode('hex') | ||
27 | if data[0] == "00".decode('hex'): | ||
28 | print "Sending ping resp" | ||
29 | sock.sendto("01".decode('hex') + data[1:5] + client_id, addr) | ||
30 | |||
31 | #if we recieve a get_nodes request. | ||
32 | if data[0] == "02".decode('hex'): | ||
33 | print "Sending getn resp" | ||
34 | #send send nodes packet with a couple 127.0.0.1 ips and ports. | ||
35 | #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002 | ||
36 | sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr) | ||
37 | |||