コード例 #1
0
ファイル: raw_srvr.py プロジェクト: EverlastingFire/neubot
 def _waiting_rawtest(self, stream, data):
     ''' Waiting for RAWTEST message from client '''
     context = stream.opaque
     context.bufferise(data)
     tmp = context.pullup(len(RAWTEST))
     if not tmp:
         stream.recv(len(RAWTEST), self._waiting_rawtest)
         return
     if tmp[4:5] == PING_CODE:
         logging.debug('< PING')
         stream.send(PINGBACK, self._sent_pingback)
         logging.debug('> PINGBACK')
         return
     if tmp[4:5] != RAWTEST_CODE:
         raise RuntimeError('raw_srvr: received invalid message')
     logging.debug('< RAWTEST')
     logging.info('raw_srvr: waiting for RAWTEST message... complete')
     logging.info('raw_srvr: raw test... in progress')
     context.count = context.snap_count = stream.bytes_out
     context.ticks = context.snap_ticks = utils.ticks()
     context.snap_utime, context.snap_stime = os.times()[:2]
     message = PIECE_CODE + context.auth * int(LEN_MESSAGE / AUTH_LEN)
     context.message = struct.pack('!I', len(message)) + message
     stream.send(context.message, self._piece_sent)
     #logging.debug('> PIECE')
     POLLER.sched(1, self._periodic, stream)
     stream.recv(1, self._waiting_eof)
コード例 #2
0
ファイル: raw_clnt.py プロジェクト: neubot/neubot
 def _periodic(self, args):
     """ Periodically snap goodput """
     stream = args[0]
     if stream.opaque:
         deferred = Deferred()
         deferred.add_callback(self._periodic_internal)
         deferred.add_errback(lambda err: self._periodic_error(stream, err))
         deferred.callback(stream)
         POLLER.sched(1, self._periodic, stream)
コード例 #3
0
 def _schedule_after(self, interval):
     ''' Schedule next rendezvous after interval seconds '''
     logging.info('background_rendezvous: next rendezvous in %d seconds',
                  interval)
     timestamp = POLLER.sched(interval, self.run)
     STATE.update('idle', publish=False)
     STATE.update('next_rendezvous', timestamp)
コード例 #4
0
ファイル: skype_clnt.py プロジェクト: claudiuperta/neubot
 def _waiting_piece(self, stream, data):
     ''' Invoked when new data is available '''
     # Note: this loop cannot be adapted to process other messages
     # easily, as pointed out in <skype_defs.py>.
     context = stream.opaque
     context.bufferise(data)
     context.state['rcvr_data'].append((utils.ticks(), len(data)))
     while True:
         if context.left > 0:
             context.left = context.skip(context.left)
             if context.left > 0:
                 break
         elif context.left == 0:
             tmp = context.pullup(4)
             if not tmp:
                 break
             context.left, = struct.unpack('!I', tmp)
             if context.left > MAXRECV:
                 raise RuntimeError('skype_clnt: PIECE too large')
             if not context.ticks:
                 context.ticks = context.snap_ticks = utils.ticks()
                 context.count = context.snap_count = stream.bytes_in
                 context.snap_utime, context.snap_stime = os.times()[:2]
                 POLLER.sched(1, self._periodic, stream)
             if context.left == 0:
                 logging.debug('< {empty-message}')
                 logging.info('skype_clnt: skype goodput test... complete')
                 ticks = utils.ticks()
                 timediff = ticks - context.ticks
                 bytesdiff = stream.bytes_in - context.count
                 context.state['goodput'] = {
                                             'ticks': ticks,
                                             'bytesdiff': bytesdiff,
                                             'timediff': timediff,
                                            }
                 if timediff > 1e-06:
                     speed = utils.speed_formatter(bytesdiff / timediff)
                     logging.info('skype_clnt: goodput: %s', speed)
                     STATE.update('test_download', speed, publish=0)
                     STATE.update('test_upload', 'N/A')
                 self._periodic_internal(stream)
                 context.state['complete'] = 1
                 stream.close()
                 return
         else:
             raise RuntimeError('skype_clnt: internal error')
     stream.recv(MAXRECV, self._waiting_piece)
コード例 #5
0
ファイル: notify.py プロジェクト: EverlastingFire/neubot
    def _periodic(self):
        ''' Periodically generate notification for old events '''
        POLLER.sched(INTERVAL, self._periodic)
        self._tofire, queue = [], self._tofire
        for event in queue:

            #
            # WARNING! Please resist the temptation of merging
            # the [] and the del into a single pop() because that
            # will not work: this is a defaultdict and so here
            # event might not be in _subscribers.
            #
            queue = self._subscribers[event]
            del self._subscribers[event]

            logging.debug("notify: periodically publish event: %s", event)

            self._fireq(event, queue)
コード例 #6
0
ファイル: raw_clnt.py プロジェクト: neubot/neubot
 def _waiting_piece(self, stream, data):
     """ Invoked when new data is available """
     # Note: this loop cannot be adapted to process other messages
     # easily, as pointed out in <raw_defs.py>.
     context = stream.opaque
     context.bufferise(data)
     context.state["rcvr_data"].append((utils.ticks(), len(data)))
     while True:
         if context.left > 0:
             context.left = context.skip(context.left)
             if context.left > 0:
                 break
         elif context.left == 0:
             tmp = context.pullup(4)
             if not tmp:
                 break
             context.left, = struct.unpack("!I", tmp)
             if context.left > MAXRECV:
                 raise RuntimeError("raw_clnt: PIECE too large")
             if not context.ticks:
                 context.ticks = context.snap_ticks = utils.ticks()
                 context.count = context.snap_count = stream.bytes_in
                 context.snap_utime, context.snap_stime = os.times()[:2]
                 POLLER.sched(1, self._periodic, stream)
             if context.left == 0:
                 logging.debug("< {empty-message}")
                 logging.info("raw_clnt: raw goodput test... complete")
                 ticks = utils.ticks()
                 timediff = ticks - context.ticks
                 bytesdiff = stream.bytes_in - context.count
                 context.state["goodput"] = {"ticks": ticks, "bytesdiff": bytesdiff, "timediff": timediff}
                 if timediff > 1e-06:
                     speed = utils.speed_formatter(bytesdiff / timediff)
                     logging.info("raw_clnt: goodput: %s", speed)
                     STATE.update("test_progress", "100%", publish=False)
                     STATE.update("test_download", speed, publish=0)
                     STATE.update("test_upload", "N/A")
                 self._periodic_internal(stream)
                 context.state["complete"] = 1
                 stream.close()
                 return
         else:
             raise RuntimeError("raw_clnt: internal error")
     stream.recv(MAXRECV, self._waiting_piece)
コード例 #7
0
 def _schedule_after(self, interval):
     """ Schedule next rendezvous after interval seconds """
     logging.info("background_rendezvous: next rendezvous in %d seconds", interval)
     timestamp = POLLER.sched(interval, self.run)
     STATE.update("idle", publish=False)
     STATE.update("next_rendezvous", timestamp)
コード例 #8
0
ファイル: notify.py プロジェクト: EverlastingFire/neubot
 def __init__(self):
     self._timestamps = collections.defaultdict(int)
     self._subscribers = collections.defaultdict(list)
     self._tofire = []
     POLLER.sched(INTERVAL, self._periodic)
コード例 #9
0
 def _schedule(self):
     ''' Schedule next check for updates '''
     interval = CONFIG['win32_updater_interval']
     logging.debug('updater_runner: next check in %d seconds',
                   interval)
     POLLER.sched(interval, self.retrieve_versioninfo)
コード例 #10
0
 def _schedule(self):
     ''' Schedule next check for updates '''
     # TODO remember to raise this to 1800 seconds
     POLLER.sched(60, self.retrieve_versioninfo)