Пример #1
0
def init(*args, **kws):
    global dht
    global khashmir_imported
    if khashmir_imported and dht is None:
        dht = UTKhashmir(*args, **kws)
        # Arno: no need for separate thread, it now runs on the regular network thread
        dht.addContact('router.bittorrent.com', 6881)
Пример #2
0
def init(*args, **kws):
    global dht
    global khashmir_imported
    if khashmir_imported and dht is None:
        dht = UTKhashmir(*args, **kws)
        # Arno: no need for separate thread, it now runs on the regular network thread
        dht.addContact('router.bittorrent.com', 6881)
Пример #3
0
class InitTableTest:
    def __init__(self):
        self.config, self.metainfo = self._load_settings()
        self.rawserver = RawServer(self.config)
        self.dht = UTKhashmir(self.config['bind'], self.config['port'],
                              self.config['dumpDir'], self.rawserver)

    def _load_settings(self):
        f = open('config/MyNodes.json')
        settings = json.load(f)
        return settings["config"], settings["metainfo"]

    def start_init(self):
        if self.dht:
            infohash = sha(bencode(self.metainfo['value'])).digest()
            # infohash = 0x0d0d7a9ef71434d31b893cec305264579b7cf262
            nodes = self.dht.table.findNodes(infohash)

            if len(nodes) < const.K:
                for node in self.metainfo['nodes']:
                    host = node['host']
                    port = node['port']
                    self.dht.addContact(host, port)

            # self.rawserver.add_task(30,self.show_table)
            self.rawserver.add_task(10, self.dht.getPeersAndAnnounce, infohash,
                                    self.metainfo['value'], self.show_value)
            # self.rawserver.add_task(10, self.dht.pingQuery, '207.134.242.20', 59464)
            # self.rawserver.add_task(10, self.dht.getPeerQuery,infohash,'176.31.225.184',8999)

            # self.rawserver.add_task(20,self.dht.announcePeer,infohash,self.metainfo['value'])

            # self.rawserver.add_task(10,self.dht.getPeers,infohash,self.show_value)

    def show_value(self, *arg):
        print "here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        try:
            result = arg[0][0]
            # print len(result)
            # ip_hex = result[:4]
            ip_int = struct.unpack(">L", result[:4])[0]
            ip = socket.inet_ntoa(struct.pack('L', socket.htonl(ip_int)))
            port = struct.unpack(">H", result[4:])[0]
            print "ip:port", ip, port
        except IndexError:
            print "not found"

    def show_table(self):
        for bucket in self.dht.table.buckets:
            for node in bucket.l:
                print node.host, node.port, node.num
Пример #4
0
    def _find_port(self, listen_fail_ok=True):
        """Run BitTorrent on the first available port found starting
           from minport in the range [minport, maxport]."""

        exc_info = None

        self.config['minport'] = max(1024, self.config['minport'])

        self.config['maxport'] = max(self.config['minport'],
                                     self.config['maxport'])

        e = (_("maxport less than minport - no ports to check") +
             (": %s %s" % (self.config['minport'], self.config['maxport'])))

        for port in xrange(self.config['minport'], self.config['maxport'] + 1):
            try:
                self.singleport_listener.open_port(port, self.config)
                if self.config['start_trackerless_client']:
                    self.dht = UTKhashmir(self.config['bind'],
                                   self.singleport_listener.get_port(),
                                   self.data_dir, self.rawserver,
                                   int(self.config['max_upload_rate'] * 0.01),
                                   rlcount=self.up_ratelimiter.increase_offset,
                                   config=self.config)
                break
            except socket.error, e:
                exc_info = sys.exc_info()
Пример #5
0
 def simpleSetUp(self):
     #self.kfiles()
     d = dict([(x[0],x[1]) for x in common_options + rare_options])
     self.r = RawServer(Event(), d)
     self.l = []
     for i in range(self.num):
         self.l.append(UTKhashmir(self.bind, self.startport + i, 'kh%s.db' % (self.startport + i), self.r))
     
     for i in self.l:
         i.addContact(self.chost, self.cport)
         self.r.listen_once(1)
         self.r.listen_once(1)            
         self.done = 0
         i.findCloseNodes(self._done)
Пример #6
0
 def _find_port(self, listen_fail_ok=True):
     e = _("maxport less than minport - no ports to check")
     if self.config['minport'] < 1024:
         self.config['minport'] = 1024
     for port in xrange(self.config['minport'], self.config['maxport'] + 1):
         try:
             self.singleport_listener.open_port(port, self.config)
             if self.config['start_trackerless_client']:
                 self.dht = UTKhashmir(self.config['bind'], 
                                         self.singleport_listener.get_port(), 
                                         self.config['data_dir'], self.rawserver, 
                                         int(self.config['max_upload_rate'] * 1024 * 0.01), 
                                         rlcount=self.ratelimiter.increase_offset,
                                         config=self.config)
             break
         except socketerror, e:
             pass
Пример #7
0
 def __init__(self):
     self.config, self.metainfo = self._load_settings()
     self.rawserver = RawServer(self.config)
     self.dht = UTKhashmir(self.config['bind'], self.config['port'],
                           self.config['dumpDir'], self.rawserver)