From 3396d8e495598c2b8ee1cdb2dd5f748647971c26 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 25 Jun 2013 12:11:11 -0400 Subject: DHT implementation finished. Currently testing it. --- testing/DHT_test.c | 8 +++++++- testing/rect.py | 24 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'testing') 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 @@ #include "../core/DHT.h" +#include + //Sleep function (x = milliseconds) #ifdef WIN32 @@ -100,7 +102,11 @@ int main(int argc, char *argv[]) printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); printf("--------------------BEGIN-----------------------------\n"); for(i = 0; i < length; i++) - printf("%c",data[i]); + { + if(data[i] < 16) + printf("0"); + printf("%X",data[i]); + } printf("\n--------------------END-----------------------------\n\n\n"); } 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 @@ #basic python UDP script #for testing only import socket +import random UDP_IP = "127.0.0.1" UDP_PORT = 5004 @@ -9,11 +10,28 @@ sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) +#our client_id +client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32))) + +print client_id + #send ping request to our DHT on localhost. -sock.sendto("0012345678".decode("hex") + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", ('127.0.0.1', 33445)) +sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445)) #print all packets recieved and respond to ping requests properly while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes - print "received message:", data, " From:", addr - sock.sendto("01".decode('hex') + data[1:5] + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", addr) + print "received message:", data.encode('hex'), " From:", addr + #if we recieve a ping request. + print data[0].encode('hex') + if data[0] == "00".decode('hex'): + print "Sending ping resp" + sock.sendto("01".decode('hex') + data[1:5] + client_id, addr) + + #if we recieve a get_nodes request. + if data[0] == "02".decode('hex'): + print "Sending getn resp" + #send send nodes packet with a couple 127.0.0.1 ips and ports. + #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002 + sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr) + -- cgit v1.2.3