Esempio n. 1
0
    def run(self):
        self.running = True
        while self.running:
            # this syncs the blacklist
            try:
                if self.blacklist.outsynced:
                    self.blacklist.save()
                else:
                    self.blacklist.update()
            except Exception, e:
                # in case something goes wrong
                # we log it but don't want our thread to die.
                from keyexchange.filtering import logger
                logger.error(str(e))

            time.sleep(self.frequency)
Esempio n. 2
0
    def save(self):
        """Save the IP into memcached if needed."""
        if self._cache_server is None or not self._dirty:
            return

        self._lock.acquire()
        try:
            # XXX will use CAS/GETS once pylibmc 1.1.2 is released
            self._update()
            data = self.ips, self._ttls
            if not self._cache_server.set('keyexchange:blacklist', data):
                from keyexchange.filtering import logger
                logger.error('Could not update the backlist')
            self._dirty = False
        finally:
            self._lock.release()