예제 #1
0
파일: khashmir.py 프로젝트: norpol/apt-p2p
 def setup(self, config, cache_dir):
     """Setup all the Khashmir sub-modules.
     
     @type config: C{dictionary}
     @param config: the configuration parameters for the DHT
     @type cache_dir: C{string}
     @param cache_dir: the directory to store all files in
     """
     self.config = config
     self.port = config['PORT']
     self.store = DB(os.path.join(cache_dir, 'khashmir.' + str(self.port) + '.db'))
     self.node = self._loadSelfNode('', self.port)
     self.table = KTable(self.node, config)
     self.token_secrets = [newID()]
     self.stats = StatsLogger(self.table, self.store)
     
     # Start listening
     self.udp = krpc.hostbroker(self, self.stats, config)
     self.udp.protocol = krpc.KRPC
     self.listenport = reactor.listenUDP(self.port, self.udp)
     
     # Load the routing table and begin checkpointing
     self._loadRoutingTable()
     self.refreshTable(force = True)
     self.next_checkpoint = reactor.callLater(60, self.checkpoint)
예제 #2
0
 def setup(self, host, port, db='khashmir.db'):
     self._findDB(db)
     self.port = port
     self.node = self._loadSelfNode(host, port)
     self.table = KTable(self.node)
     #self.app = service.Application("krpc")
     self.udp = krpc.hostbroker(self)
     self.udp.protocol = krpc.KRPC
     self.listenport = reactor.listenUDP(port, self.udp)
     self.last = time.time()
     self._loadRoutingTable()
     KeyExpirer(store=self.store)
     self.refreshTable(force=1)
     reactor.callLater(60, self.checkpoint, (1, ))
예제 #3
0
 def _load(self):
     do_load = False
     try:
         s = open(os.path.join(self.ddir, "routing_table"), 'r').read()
         dict = bdecode(s)
     except:
         id = newID()
     else:
         id = dict['id']
         do_load = True
         
     self.node = self._Node(self.udp.connectionForAddr).init(id, self.host, self.port)
     self.table = KTable(self.node)
     if do_load:
         self._loadRoutingTable(dict['rt'])