diff options
Diffstat (limited to 'testing/rect.py')
-rw-r--r-- | testing/rect.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/testing/rect.py b/testing/rect.py index 2f9c9256..59d6c158 100644 --- a/testing/rect.py +++ b/testing/rect.py | |||
@@ -2,7 +2,6 @@ | |||
2 | #for testing only | 2 | #for testing only |
3 | import socket | 3 | import socket |
4 | import random | 4 | import random |
5 | import code | ||
6 | 5 | ||
7 | UDP_IP = "127.0.0.1" | 6 | UDP_IP = "127.0.0.1" |
8 | UDP_PORT = 5004 | 7 | UDP_PORT = 5004 |
@@ -14,7 +13,7 @@ sock.bind((UDP_IP, UDP_PORT)) | |||
14 | #our client_id | 13 | #our client_id |
15 | client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32))) | 14 | client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32))) |
16 | 15 | ||
17 | print (client_id) | 16 | print client_id |
18 | a = 1; | 17 | a = 1; |
19 | #send ping request to our DHT on localhost. | 18 | #send ping request to our DHT on localhost. |
20 | sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445)) | 19 | sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445)) |
@@ -22,25 +21,25 @@ sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445)) | |||
22 | #print all packets recieved and respond to ping requests properly | 21 | #print all packets recieved and respond to ping requests properly |
23 | while True: | 22 | while True: |
24 | data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes | 23 | data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes |
25 | print ("received message:", data.encode('hex'), " From:", addr) | 24 | print "received message:", data.encode('hex'), " From:", addr |
26 | #if we recieve a ping request. | 25 | #if we recieve a ping request. |
27 | print (data[0].encode('hex')) | 26 | print data[0].encode('hex') |
28 | if data[0] == "00".decode('hex'): | 27 | if data[0] == "00".decode('hex'): |
29 | print ("Sending ping resp") | 28 | print "Sending ping resp" |
30 | sock.sendto("01".decode('hex') + data[1:5] + client_id, addr) | 29 | sock.sendto("01".decode('hex') + data[1:5] + client_id, addr) |
31 | 30 | ||
32 | #if we recieve a get_nodes request. | 31 | #if we recieve a get_nodes request. |
33 | if data[0] == "02".decode('hex'): | 32 | if data[0] == "02".decode('hex'): |
34 | print ("Sending getn resp") | 33 | print "Sending getn resp" |
35 | #send send nodes packet with a couple 127.0.0.1 ips and ports. | 34 | #send send nodes packet with a couple 127.0.0.1 ips and ports. |
36 | #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002 | 35 | #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002 |
37 | sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr) | 36 | sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr) |
38 | 37 | ||
39 | if data[0] == "10".decode('hex'): | 38 | if data[0] == "10".decode('hex'): |
40 | print ("Sending handshake resp") | 39 | print "Sending handshake resp" |
41 | sock.sendto("10".decode('hex') + data[1:5] + client_id[:4], addr) | 40 | sock.sendto("10".decode('hex') + data[1:5] + client_id[:4], addr) |
42 | if data[0] == "11".decode('hex'): | 41 | if data[0] == "11".decode('hex'): |
43 | print ("Sending SYNC resp") | 42 | print "Sending SYNC resp" |
44 | a+=1 | 43 | a+=1 |
45 | sock.sendto("11".decode('hex') + chr(a) + data[1:9], addr) | 44 | sock.sendto("11".decode('hex') + chr(a) + data[1:9], addr) |
46 | 45 | ||