예제 #1
0
    def refreshFiles(self, result=None):
        """Refresh any files in the DHT that are about to expire."""
        if result is not None:
            log.msg('Storage resulted in: %r' % result)

        if not self.refreshingHashes:
            expireAfter = config.gettime('DEFAULT', 'KEY_REFRESH')
            self.refreshingHashes = self.db.expiredHashes(expireAfter)
            if len(self.refreshingHashes) > 0:
                log.msg('Refreshing the keys of %d DHT values' %
                        len(self.refreshingHashes))

        delay = 60
        if self.refreshingHashes:
            delay = 3
            refresh = self.refreshingHashes.pop(0)
            self.db.refreshHash(refresh['hash'])
            hash = HashObject(refresh['hash'], pieces=refresh['pieces'])
            storeDefer = self.store(hash)
            storeDefer.addBoth(self.refreshFiles)

        if self.nextRefresh.active():
            self.nextRefresh.reset(delay)
        else:
            self.nextRefresh = reactor.callLater(delay, self.refreshFiles)
예제 #2
0
 def load(self):
     """Make sure the package cache is initialized and loaded."""
     # Reset the pending unload call
     if self.unload_later and self.unload_later.active():
         self.unload_later.reset(config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'))
     else:
         self.unload_later = reactor.callLater(config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'), self.unload)
     
     # Check if it's already loaded
     if self.loaded:
         return defer.succeed(True)
     
     # Make sure it's not already being loaded
     if self.loading is None:
         log.msg('Loading the packages cache')
         self.loading_unload = False
         self.loading = threads.deferToThread(self._load)
         self.loading.addCallback(self.doneLoading)
     return self.loading
예제 #3
0
    def load(self):
        """Make sure the package cache is initialized and loaded."""
        # Reset the pending unload call
        if self.unload_later and self.unload_later.active():
            self.unload_later.reset(
                config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'))
        else:
            self.unload_later = reactor.callLater(
                config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'),
                self.unload)

        # Check if it's already loaded
        if self.loaded:
            return defer.succeed(True)

        # Make sure it's not already being loaded
        if self.loading is None:
            log.msg('Loading the packages cache')
            self.loading_unload = False
            self.loading = threads.deferToThread(self._load)
            self.loading.addCallback(self.doneLoading)
        return self.loading
예제 #4
0
    def refreshFiles(self, result = None):
        """Refresh any files in the DHT that are about to expire."""
        if result is not None:
            log.msg('Storage resulted in: %r' % result)

        if not self.refreshingHashes:
            expireAfter = config.gettime('DEFAULT', 'KEY_REFRESH')
            self.refreshingHashes = self.db.expiredHashes(expireAfter)
            if len(self.refreshingHashes) > 0:
                log.msg('Refreshing the keys of %d DHT values' % len(self.refreshingHashes))

        delay = 60
        if self.refreshingHashes:
            delay = 3
            refresh = self.refreshingHashes.pop(0)
            self.db.refreshHash(refresh['hash'])
            hash = HashObject(refresh['hash'], pieces = refresh['pieces'])
            storeDefer = self.store(hash)
            storeDefer.addBoth(self.refreshFiles)

        if self.nextRefresh.active():
            self.nextRefresh.reset(delay)
        else:
            self.nextRefresh = reactor.callLater(delay, self.refreshFiles)