X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_p2p%2Fapt_p2p.py;h=4200f6299b78377593ce17cd6ad7b6973de7578e;hb=09472169824fc47c359cdee65652a12a7ba46806;hp=889ebd96243bddd83d77cafad10cec1504138abf;hpb=d563aab35fc0fd1fab59e0f6d594fbb05735cf21;p=quix0rs-apt-p2p.git diff --git a/apt_p2p/apt_p2p.py b/apt_p2p/apt_p2p.py index 889ebd9..4200f62 100644 --- a/apt_p2p/apt_p2p.py +++ b/apt_p2p/apt_p2p.py @@ -6,7 +6,7 @@ @var TORRENT_PIECES: the maximum number of pieces to store as a separate entry in the DHT @var download_dir: the name of the directory to use for downloaded files - +@var peer_dir: the name of the directory to use for peer downloads """ from binascii import b2a_hex @@ -34,6 +34,7 @@ DHT_PIECES = 4 TORRENT_PIECES = 70 download_dir = 'cache' +peer_dir = 'peers' class AptP2P: """The main code object that does all of the work. @@ -77,6 +78,8 @@ class AptP2P: 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 = dhtClass() self.dht.loadConfig(config, config.get('DEFAULT', 'DHT')) @@ -84,12 +87,17 @@ class AptP2P: self.stats = StatsLogger(self.db) self.http_server = TopLevel(self.cache_dir.child(download_dir), self.db, self) self.getHTTPFactory = self.http_server.getHTTPFactory - self.peers = PeerManager(self.cache_dir, self.dht, self.stats) + 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) self.my_contact = None + reactor.addSystemEventTrigger('before', 'shutdown', self.shutdown) - #{ DHT maintenance + #{ Maintenance + def shutdown(self): + self.stats.save() + self.db.close() + def joinComplete(self, result): """Complete the DHT join process and determine our download information.