Skip to content

Instantly share code, notes, and snippets.

@ardhipoetra
Created April 11, 2016 09:55
Show Gist options
  • Save ardhipoetra/24b00ff0c8f81231e22719acf40ab6bd to your computer and use it in GitHub Desktop.
Save ardhipoetra/24b00ff0c8f81231e22719acf40ab6bd to your computer and use it in GitHub Desktop.
Test get_peers on pymdht
import sys
import logging
import time
sys.path.append('/home/ardhipoetra/git/thesis/tribler/Tribler/Core/DecentralizedTracking')
from pymdht.core.pymdht import Pymdht as DHT
from pymdht.core.node import Node
from pymdht.plugins import lookup_a4
from pymdht.plugins import routing_nice_rtt
from pymdht.core import exp_plugin_template
from pymdht.core.identifier import Id
my_node = Node(['127.0.0.1', 12345])
conf_path = '.'
private_dht_name = None
debug_level = logging.DEBUG
auto_bootstrap = True
bootstrap_mode = False
dht = DHT(my_node, conf_path, routing_nice_rtt, lookup_a4, exp_plugin_template,
private_dht_name, debug_level)
info_hash = '5aec5ee9f2d044316fe1de29d221452103ceb958'
peers = set()
def f(lookup_id, peer_list, node):
if peer_list is None:
print(peers)
print(len(peers))
else:
for i in peer_list:
peers.add(i)
dht.get_peers(info_hash, Id(info_hash), f)
#let's wait 30sec to find peer
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment