def main(options, args): port = int(options.port) my_addr = (options.ip, port) local_ip = options.my_ip logs_path = options.path logs_level = options.logs_level or default_logs_level logging_conf.setup(logs_path, logs_level) print 'Using the following plug-ins:' print '*', options.routing_m_file print '*', options.lookup_m_file routing_m_name = '.'.join(os.path.split(options.routing_m_file))[:-3] routing_m_mod = __import__(routing_m_name, fromlist=['']) lookup_m_name = '.'.join(os.path.split(options.lookup_m_file))[:-3] lookup_m_mod = __import__(lookup_m_name, fromlist=['']) global dht dht = pymdht.Pymdht(my_addr, logs_path, routing_m_mod, lookup_m_mod, '', logs_level) global geo_score if options.geoip_mode: import geo geo_score = geo.Geo(local_ip) else: geo_score = None global server server = SocketServer.TCPServer(('', port), SessionHandler) while not stop_server: server.handle_request()
def main(options, args): my_addr = (options.ip, int(options.port)) logs_path = options.path logging_conf.setup(logs_path, logs_level) print 'Using the following plug-ins:' print '*', options.routing_m_file print '*', options.lookup_m_file routing_m_name = '.'.join(os.path.split(options.routing_m_file))[:-3] routing_m_mod = __import__(routing_m_name, fromlist=['']) lookup_m_name = '.'.join(os.path.split(options.lookup_m_file))[:-3] lookup_m_mod = __import__(lookup_m_name, fromlist=['']) dht = pymdht.Pymdht(my_addr, logs_path, routing_m_mod, lookup_m_mod) print '\nType "exit" to stop the DHT and exit' print 'Type an info_hash (in hex digits): ', while (1): input = sys.stdin.readline()[:-1] if input == 'exit': dht.stop() break try: info_hash = identifier.Id(input) except (identifier.IdError): print 'Invalid input (%s)' % input continue print 'Getting peers for info_hash %r' % info_hash global start_ts start_ts = time.time() dht.get_peers(None, info_hash, _on_peers_found)
def main(options, args): my_addr = (options.ip, int(options.port)) logs_path = options.path print 'Using the following plug-ins:' print '*', options.routing_m_file print '*', options.lookup_m_file print 'Private DHT name:', options.private_dht_name routing_m_name = '.'.join(os.path.split(options.routing_m_file))[:-3] routing_m_mod = __import__(routing_m_name, fromlist=['']) lookup_m_name = '.'.join(os.path.split(options.lookup_m_file))[:-3] lookup_m_mod = __import__(lookup_m_name, fromlist=['']) dht = pymdht.Pymdht(my_addr, logs_path, routing_m_mod, lookup_m_mod, options.private_dht_name, logs_level) print '\nType "exit" to stop the DHT and exit' print 'Type "help" if you need' while (1): input = sys.stdin.readline().strip().split() if not input: continue command = input[0] if command == 'help': print ''' Available commands are: - help - fast info_hash bt_port - exit - m Memory information ''' elif command == 'exit': dht.stop() break elif command == 'm': import guppy h = guppy.hpy() print h.heap() elif command == 'fast': if len(input) != 3: print 'usage: fast info_hash bt_port' continue try: info_hash = identifier.Id(input[1]) except (identifier.IdError): print 'Invalid info_hash (%s)' % input[1] try: bt_port = int(input[2]) except: print 'Invalid bt_port (%r)' % input[2] continue success = dht.get_peers(time.time(), info_hash, _on_peers_found, bt_port) if not success: print 'Lookup failed'
def _DEPRECATED_init_main_of_idht(self): parser = OptionParser() parser.add_option("-a", "--address", dest="ip", metavar='IP', default='127.0.0.1', help="IP address to be used") parser.add_option("-p", "--port", dest="port", metavar='INT', default=7000, help="port to be used") parser.add_option("-x", "--path", dest="path", metavar='PATH', default='.', help="state.dat and logs location") parser.add_option("-r", "--routing-plug-in", dest="routing_m_file", metavar='FILE', default='plugins/routing_nice_rtt.py', help="file containing the routing_manager code") parser.add_option("-l", "--lookup-plug-in", dest="lookup_m_file", metavar='FILE', default='plugins/lookup_a4.py', help="file containing the lookup_manager code") parser.add_option("-z", "--logs-level", dest="logs_level", metavar='INT', help="logging level") parser.add_option("-d", "--private-dht", dest="private_dht_name", metavar='STRING', default=None, help="private DHT name") parser.add_option("-e", "--experimental-plug-in",dest="experimental_m_file", metavar='FILE',default='core/exp_plugin_template.py', help="file containing ping-manager code") options, args= parser.parse_args() my_addr = (options.ip, int(options.port)) logs_path = options.path print 'Using the following plug-ins:' print '*', options.routing_m_file print '*', options.lookup_m_file print '*', options.experimental_m_file print 'Private DHT name:', options.private_dht_name routing_m_name = '.'.join(os.path.split(options.routing_m_file))[:-3] routing_m_mod = __import__(routing_m_name, fromlist=['']) lookup_m_name = '.'.join(os.path.split(options.lookup_m_file))[:-3] lookup_m_mod = __import__(lookup_m_name, fromlist=['']) experimental_m_name = '.'.join(os.path.split(options.experimental_m_file))[:-3] experimental_m_mod = __import__(experimental_m_name, fromlist=['']) self.dht = pymdht.Pymdht(my_addr, logs_path, routing_m_mod, lookup_m_mod, experimental_m_mod, options.private_dht_name, logs_level)
def main(options, args): port = int(options.port) my_addr = (options.ip, port) logs_path = options.path logging_conf.setup(logs_path, logs_level) print 'Using the following plug-ins:' print '*', options.routing_m_file print '*', options.lookup_m_file routing_m_name = '.'.join(os.path.split(options.routing_m_file))[:-3] routing_m_mod = __import__(routing_m_name, fromlist=['']) lookup_m_name = '.'.join(os.path.split(options.lookup_m_file))[:-3] lookup_m_mod = __import__(lookup_m_name, fromlist=['']) global dht dht = pymdht.Pymdht(my_addr, logs_path, routing_m_mod, lookup_m_mod) server = SocketServer.TCPServer(('', port), SessionHandler) server.serve_forever()
import time import sys import string import core.identifier as identifier import core.pymdht as pymdht import logging import plugins.lookup_a16 as lookup_m_mod import plugins.routing_nice_rtt as routing_m_mod #logs_path = './interactive_logs/' logs_path = '.' logs_level = logging.DEBUG # This generates HUGE (and useful) logs #logs_level = logging.INFO # This generates some (useful) logs #logs_level = logging.WARNING # This generates warning and error logs if len(sys.argv) == 4: my_addr = ('127.0.0.1', int(sys.argv[1])) id_ = identifier.Id(sys.argv[2]).generate_close_id(int(sys.argv[3])) dht = pymdht.Pymdht(my_addr, logs_path, routing_m_mod, lookup_m_mod, None, logs_level, id_) while (True): time.sleep(5) else: print 'usage: python incoming_traffic.py dht_port info_hash log_distance'
def main(options, args): if not os.path.isdir(options.path): if os.path.exists(options.path): print >> sys.stderr, 'FATAL:', options.path, 'must be a directory' return print >> sys.stderr, options.path, 'does not exist. Creating directory...' os.mkdir(options.path) logs_path = options.path if options.lookup_delay and not options.daemon: print >> sys.stderr, 'Switching to DAEMON mode (no user interface)' if options.lookup_delay or options.daemon: # redirect output stdout_file = os.path.join(options.path, 'pymdht.stdout') stderr_file = os.path.join(options.path, 'pymdht.stderr') print >> sys.stderr, 'Redirecting output to %s and %s' % (stdout_file, stderr_file) sys.stdout = open(stdout_file, 'w') sys.stderr = open(stderr_file, 'w') my_addr = (options.ip, int(options.port)) my_id = None if options.node_id: base_id = identifier.Id(options.node_id) my_id = base_id.generate_close_id(options.log_distance) my_node = node.Node(my_addr, my_id, version=pymdht.VERSION_LABEL) if options.debug: logs_level = logging.DEBUG # This generates HUGE (and useful) logs else: # logs_level = logging.INFO # This generates some (useful) logs logs_level = logging.WARNING # This generates warning and error logs print 'Using the following plug-ins:' print '*', options.routing_m_file print '*', options.lookup_m_file print '*', options.experimental_m_file print 'Path:', options.path print 'Private DHT name:', options.private_dht_name print 'debug mode:', options.debug print 'bootstrap mode:', options.bootstrap_mode print 'Swift tracker port:', options.swift_port routing_m_name = '.'.join(os.path.split(options.routing_m_file))[:-3] routing_m_mod = __import__(routing_m_name, fromlist=['']) lookup_m_name = '.'.join(os.path.split(options.lookup_m_file))[:-3] lookup_m_mod = __import__(lookup_m_name, fromlist=['']) experimental_m_name = '.'.join(os.path.split( options.experimental_m_file))[:-3] experimental_m_mod = __import__(experimental_m_name, fromlist=['']) dht = pymdht.Pymdht(my_node, logs_path, routing_m_mod, lookup_m_mod, experimental_m_mod, options.private_dht_name, logs_level, options.bootstrap_mode, options.swift_port) if options.lookup_delay: loop_forever = not options.num_lookups remaining_lookups = options.num_lookups while loop_forever or remaining_lookups: time.sleep(options.lookup_delay) if options.lookup_target: target = identifier.Id(options.lookup_target) else: target = identifier.RandomId() print 'lookup', target dht.get_peers(None, target, None, options.announce_port) remaining_lookups = remaining_lookups - 1 time.sleep(options.stop_delay) dht.stop() elif options.ttl: stop_timestamp = time.time() + int(options.ttl) while time.time() < stop_timestamp: time.sleep(1) dht.stop() elif options.daemon: # Just loop for ever while True: time.sleep(10) elif options.gui: import wx import ui.gui app = wx.PySimpleApp() frame = ui.gui.Interactive_GUI(None, "Interactive Look@MDHT", None, (1440, 900), dht, logs_path) frame.Show(True) app.MainLoop() elif options.telnet_port: import ui.telnet telnet_ui = ui.telnet.Telnet(dht, options.telnet_port) telnet_ui.start() elif options.cli: import ui.cli ui.cli.command_user_interface(dht)
if peers: msg = 'got %d peers\n' % len(peers) else: msg = 'END OF LOOKUP\n' button.text += msg class LookupButton(Button): def __init__(self): Button.__init__(self, text='DHT lookup\n') def on_press(self): dht.get_peers( self, identifier.Id('e936e73881ee1920b8edbd263d001fffed424c5f'), _on_peers_handler) class MyApp(App): def build(self): return LookupButton() if __name__ in ('__android__', '__main__'): my_addr = ('127.0.0.1', 7000) my_node = node.Node(my_addr, identifier.RandomId(), version=pymdht.VERSION_LABEL) dht = pymdht.Pymdht(my_node, '.', routing_m_mod, lookup_m_mod, exp_mod, None, 0, False) MyApp().run()