コード例 #1
0
ファイル: DNSFarm.py プロジェクト: B-Rich/mixminion
 def run(self):
     """Thread body: pull questions from the DNS thread queue and
        answer them."""
     queue = self.dnscache.queue
     _lookupDone = self.dnscache._lookupDone
     _adjBusyThreads = self.dnscache._adjBusyThreads
     _adjLiveThreads = self.dnscache._adjLiveThreads
     try:
         _adjLiveThreads(1)
         try:
             while 1:
                 # Get a question from the queue, but don't wait more than
                 # MAX_THREAD_IDLE seconds
                 hostname = queue.get(timeout=MAX_THREAD_IDLE)
                 # If the question is None, shutdown.
                 if hostname is None:
                     return
                 # Else, resolve the IP and send the answer to the dnscache
                 _adjBusyThreads(1)
                 result = mixminion.NetUtils.getIP(hostname)
                 _lookupDone(hostname, result)
                 _adjBusyThreads(-1)
         except QueueEmpty:
             LOG.debug("DNS thread shutting down: idle for %s seconds.",
                      MAX_THREAD_IDLE)
         except:
             LOG.error_exc(sys.exc_info(),
                           "Exception in DNS thread; shutting down.")
     finally:
         _adjLiveThreads(-1)
コード例 #2
0
ファイル: ServerQueue.py プロジェクト: vanilsski/mixminion
    def deliveryFailed(self, handle, retriable=0, now=None):
        assert self.retrySchedule is not None
        if now is None:
            now = time.time()
        self._lock.acquire()
        try:
            try:
                mState = self.store.getMetadata(handle)
            except KeyError:
                mState = None
            except CorruptedFile:
                mState = None

            if mState is None:
                # This should never happen
                LOG.error_exc(sys.exc_info(),
                              "Handle %s had no state; removing", handle)
                self.removeMessage(handle)
                return
            elif not mState.isPending():
                LOG.error("Handle %s was not pending", handle)
                return

            last = mState.pending
            mState.setNonPending()
            if not retriable:
                LOG.trace("     (Giving up on %s)", handle)
                self.removeMessage(handle)

            aState = self._getAddressState(mState.address, now)
            aState.failed(attempt=last, now=now)
            aState.setNextAttempt(self.retrySchedule, now=now)
            self.addressStateDB[str(aState.address)] = aState  # flush to db.
        finally:
            self._lock.release()
コード例 #3
0
ファイル: ServerQueue.py プロジェクト: B-Rich/mixminion
    def deliveryFailed(self, handle, retriable=0, now=None):
        assert self.retrySchedule is not None
        if now is None:
            now = time.time()
        self._lock.acquire()
        try:
            try:
                mState = self.store.getMetadata(handle)
            except KeyError:
                mState = None
            except CorruptedFile:
                mState = None

            if mState is None:
                # This should never happen
                LOG.error_exc(sys.exc_info(),
                              "Handle %s had no state; removing", handle)
                self.removeMessage(handle)
                return
            elif not mState.isPending():
                LOG.error("Handle %s was not pending", handle)
                return

            last = mState.pending
            mState.setNonPending()
            if not retriable:
                LOG.trace("     (Giving up on %s)", handle)
                self.removeMessage(handle)

            aState = self._getAddressState(mState.address, now)
            aState.failed(attempt=last,now=now)
            aState.setNextAttempt(self.retrySchedule,now=now)
            self.addressStateDB[str(aState.address)] = aState # flush to db.
        finally:
            self._lock.release()
コード例 #4
0
ファイル: ServerQueue.py プロジェクト: B-Rich/mixminion
    def deliveryFailed(self, handle, retriable=0, now=None):
        """Removes a message from the outgoing queue, or requeues it
           for delivery at a later time.  This method should be
           invoked after the corresponding message has been
           unsuccessfully delivered."""
        assert self.retrySchedule is not None
        LOG.trace("DeliveryQueue failed to deliver %s from %s",
                  handle, self.qname)
        try:
            self._lock.acquire()
            try:
                ds = self.store.getMetadata(handle)
            except KeyError:
                ds = None
            except CorruptedFile:
                return

            if ds is None:
                # This should never happen
                LOG.error_exc(sys.exc_info(),
                              "Handle %s had no state", handle)
                ds = _DeliveryState(now)
                ds.setNextAttempt(self.retrySchedule, now)
                self.store.setMetadata(handle, ds)
                return

            if not ds.isPending():
                LOG.error("Handle %s was not pending", handle)
                return

            last = ds.pending
            ds.setNonPending()

            if retriable:
                # If we can retry the message, update the deliveryState
                # with the most recent attempt, and see if there's another
                # attempt in the future.
                ds.setLastAttempt(last)
                ds.setNextAttempt(self.retrySchedule, now)
                if ds.nextAttempt is not None:
                    # There is another scheduled delivery attempt.  Remember
                    # it, mark the message sendable again, and save our state.
                    LOG.trace("     (We'll try %s again at %s)", handle,
                              formatTime(ds.nextAttempt, 1))

                    self.store.setMetadata(handle, ds)
                    return
                else:
                    assert ds.isRemovable()
                # Otherwise, fallthrough.

            # If we reach this point, the message is undeliverable, either
            # because 'retriable' is false, or because we've run out of
            # retries.
            LOG.trace("     (Giving up on %s)", handle)
            self.removeMessage(handle)
        finally:
            self._lock.release()
コード例 #5
0
ファイル: ServerQueue.py プロジェクト: vanilsski/mixminion
    def deliveryFailed(self, handle, retriable=0, now=None):
        """Removes a message from the outgoing queue, or requeues it
           for delivery at a later time.  This method should be
           invoked after the corresponding message has been
           unsuccessfully delivered."""
        assert self.retrySchedule is not None
        LOG.trace("DeliveryQueue failed to deliver %s from %s", handle,
                  self.qname)
        try:
            self._lock.acquire()
            try:
                ds = self.store.getMetadata(handle)
            except KeyError:
                ds = None
            except CorruptedFile:
                return

            if ds is None:
                # This should never happen
                LOG.error_exc(sys.exc_info(), "Handle %s had no state", handle)
                ds = _DeliveryState(now)
                ds.setNextAttempt(self.retrySchedule, now)
                self.store.setMetadata(handle, ds)
                return

            if not ds.isPending():
                LOG.error("Handle %s was not pending", handle)
                return

            last = ds.pending
            ds.setNonPending()

            if retriable:
                # If we can retry the message, update the deliveryState
                # with the most recent attempt, and see if there's another
                # attempt in the future.
                ds.setLastAttempt(last)
                ds.setNextAttempt(self.retrySchedule, now)
                if ds.nextAttempt is not None:
                    # There is another scheduled delivery attempt.  Remember
                    # it, mark the message sendable again, and save our state.
                    LOG.trace("     (We'll try %s again at %s)", handle,
                              formatTime(ds.nextAttempt, 1))

                    self.store.setMetadata(handle, ds)
                    return
                else:
                    assert ds.isRemovable()
                # Otherwise, fallthrough.

            # If we reach this point, the message is undeliverable, either
            # because 'retriable' is false, or because we've run out of
            # retries.
            LOG.trace("     (Giving up on %s)", handle)
            self.removeMessage(handle)
        finally:
            self._lock.release()
コード例 #6
0
ファイル: ThreadUtils.py プロジェクト: B-Rich/mixminion
 def run(self):
     """Internal: main body of processing thread."""
     try:
         while 1:
             job = self.mqueue.get()
             job()
     except ProcessingThread._Shutdown:
         LOG.info("Shutting down %s",self.threadName)
         return
     except:
         LOG.error_exc(sys.exc_info(),
                       "Exception in %s; shutting down thread.",
                       self.threadName)
コード例 #7
0
 def run(self):
     """Internal: main body of processing thread."""
     try:
         while 1:
             job = self.mqueue.get()
             job()
     except ProcessingThread._Shutdown:
         LOG.info("Shutting down %s", self.threadName)
         return
     except:
         LOG.error_exc(sys.exc_info(),
                       "Exception in %s; shutting down thread.",
                       self.threadName)
コード例 #8
0
ファイル: ServerKeys.py プロジェクト: vanilsski/mixminion
 def publish(self, url):
     """Try to publish this descriptor to a given directory URL.  Returns
        'accept' if the publication was successful, 'reject' if the
        server refused to accept the descriptor, and 'error' if
        publication failed for some other reason."""
     fname = self.getDescriptorFileName()
     descriptor = readFile(fname)
     fields = urllib.urlencode({"desc": descriptor})
     f = None
     try:
         try:
             f = urllib2.urlopen(url, fields)
             info = f.info()
             reply = f.read()
         except IOError, e:
             LOG.error("Error while publishing server descriptor: %s", e)
             return 'error'
         except:
             LOG.error_exc(sys.exc_info(),
                           "Error publishing server descriptor")
             return 'error'
コード例 #9
0
ファイル: ServerKeys.py プロジェクト: B-Rich/mixminion
 def publish(self, url):
     """Try to publish this descriptor to a given directory URL.  Returns
        'accept' if the publication was successful, 'reject' if the
        server refused to accept the descriptor, and 'error' if
        publication failed for some other reason."""
     fname = self.getDescriptorFileName()
     descriptor = readFile(fname)
     fields = urllib.urlencode({"desc" : descriptor})
     f = None
     try:
         try:
             f = urllib2.urlopen(url, fields)
             info = f.info()
             reply = f.read()
         except IOError, e:
             LOG.error("Error while publishing server descriptor: %s",e)
             return 'error'
         except:
             LOG.error_exc(sys.exc_info(),
                           "Error publishing server descriptor")
             return 'error'
コード例 #10
0
ファイル: ServerKeys.py プロジェクト: rxcomm/mixminion
 def publish(self, url):
     """Try to publish this descriptor to a given directory URL.  Returns
        'accept' if the publication was successful, 'reject' if the
        server refused to accept the descriptor, and 'error' if
        publication failed for some other reason."""
     fname = self.getDescriptorFileName()
     descriptor = readFile(fname)
     fields = urllib.urlencode({"desc" : descriptor})
     f = None
     try:
         try:
             #############################################
             # some python versions verify certificates
             # anemone.mooo.com uses a self-signed cert
             # this workaround is not a problem because
             # the directory information is already signed
             # (although as Zax says, it is certainly a
             # kludge ;)
             if sys.version_info >= (2,7,9):
                 ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
                 ctx.check_hostname = False
                 ctx.verify_mode = ssl.CERT_NONE
                 f = urllib2.urlopen(url, fields, context=ctx)
             else:
                 f = urllib2.urlopen(url, fields)
             #############################################
             #f = urllib2.urlopen(url, fields)
             info = f.info()
             reply = f.read()
         except IOError, e:
             LOG.error("Error while publishing server descriptor: %s",e)
             return 'error'
         except:
             LOG.error_exc(sys.exc_info(),
                           "Error publishing server descriptor")
             return 'error'