Created
May 29, 2014 23:29
-
-
Save loadletter/c8aa6be3ed7816faec6e to your computer and use it in GitHub Desktop.
Pyjcdht test2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import binascii, os, random | |
from dht import DHT | |
class TestDHT(DHT): | |
testpeers = [] | |
testhash = binascii.a2b_hex('f919bc3c68eed436c485a564c51984a35af9151c') | |
prevhash = "" | |
cnt = 0 | |
def loop(self): | |
try: | |
print "dht.transmissionbt.com:", self.ping("91.121.60.42", 6881) | |
print "router.bittorent.com:", self.ping("67.215.242.138", 6881) | |
print "localhost:", self.ping('192.168.1.2', 10000) | |
while True: | |
self.do() | |
if self.testpeers: | |
node = self.testpeers.pop() | |
print "P:", repr(node), apply(self.ping, node) | |
nodes = self.nodes(self.IPV4) | |
print "NN:", repr(nodes) | |
#n, n6 = self.get_nodes() | |
#print "N4:", repr(n) | |
#print "N6:", repr(n6) | |
if nodes[0] >= 4 and self.testhash != self.prevhash: | |
print "starting search" | |
self.prevhash = self.testhash | |
self.search(self.testhash) | |
if random.choice([True, False]): | |
self.cnt += 1 | |
if nodes[0] >= 60 and self.cnt > 50: | |
self.prevhash = self.testhash | |
self.testhash = os.urandom(20) | |
self.cnt = 0 | |
except KeyboardInterrupt: | |
pass | |
def on_search(self, ev, infohash, data): | |
print "Nodes", repr(self.nodes(self.IPV4)) | |
print "Nodes6", repr(self.nodes(self.IPV6)) | |
print "Event", repr(ev) | |
print "Hash", repr(infohash) | |
print "Data", repr(data) | |
if data: | |
self.testpeers = list(set(self.testpeers)) + list(set(data)) | |
if random.choice([True, False]): | |
self.prevhash = self.testhash | |
self.testhash = os.urandom(20) | |
testid = '\x12\xc6\xbf\xdf\xdf\x88\xa6\x18\xff\xb6\xc89\xc4j\xed2l\xa4\x98\x9b' | |
testport = 8000 | |
a = TestDHT(testid, testport) | |
a.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment