コード例 #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
ファイル: krpc.py プロジェクト: norpol/apt-p2p
def make(port):
    from stats import StatsLogger
    af = Receiver()
    a = hostbroker(af, StatsLogger(None, None),
                   {'KRPC_TIMEOUT': 9, 'KRPC_INITIAL_DELAY': 2, 'SPEW': False})
    a.protocol = KRPC
    p = reactor.listenUDP(port, a)
    return af, a, p
コード例 #3
0
 def _startFactory(self):
     log.msg('Starting the main apt_p2p application')
     self.cache_dir = FilePath(config.get('DEFAULT', 'CACHE_DIR'))
     if not self.cache_dir.child(download_dir).exists():
         self.cache_dir.child(download_dir).makedirs()
     if not self.cache_dir.child(peer_dir).exists():
         self.cache_dir.child(peer_dir).makedirs()
     self.db = DB(self.cache_dir.child('apt-p2p.db'))
     self.dht = DHT(self.dhtClass, self.db)
     df = self.dht.start()
     df.addCallback(self._dhtStarted)
     self.stats = StatsLogger(self.db)
     self.http_server = TopLevel(self.cache_dir.child(download_dir),
                                 self.db, self)
     self.http_server.getHTTPFactory().startFactory()
     self.peers = PeerManager(self.cache_dir.child(peer_dir), self.dht,
                              self.stats)
     self.mirrors = MirrorManager(self.cache_dir)
     self.cache = CacheManager(self.cache_dir.child(download_dir), self.db,
                               self)