예제 #1
0
    def subscribe(self, *args):
        connection = self.connection_ref()
        session = connection.get_session()

        if session.get('extranonce1'):
            # Already subscribed

            subs1 = Pubsub.get_subscription(connection, DifficultySubscription.event)
            subs2 = Pubsub.get_subscription(connection, MiningSubscription.event)

            extranonce1_hex = binascii.hexlify(session['extranonce1'])
            extranonce2_size = Interfaces.template_registry.extranonce2_size

            log.warning('Already subscribed')
            return (((subs1.event, subs1.get_key()), (subs2.event, subs2.get_key())),) + \
                   (extranonce1_hex, extranonce2_size)

        extranonce1 = Interfaces.template_registry.get_new_extranonce1()
        extranonce2_size = Interfaces.template_registry.extranonce2_size
        extranonce1_hex = binascii.hexlify(extranonce1)

        session['extranonce1'] = extranonce1
        session['subscribed_at'] = posix_time()
        # Don't accept job_id if job_id < min_job_id
        session['min_job_id'] = 0
        session['client_sw'] = self._get_client_sw(*args)

        subs1 = Pubsub.subscribe(connection, DifficultySubscription())[0]
        subs2 = Pubsub.subscribe(connection, MiningSubscription())[0]

        Interfaces.reporter.new_subscription(session)

        return ((subs1, subs2),) + (extranonce1_hex, extranonce2_size)
예제 #2
0
    def _on_worker_refresh(self, facts):
        '''
        Callback passed to WorkerDB's refresh method for being
        notified about refreshed workers. We update the memory worker
        data appropriately.

        See WorkerDB.refresh_from_source for details about passed
        'facts' dictionary.
        '''
        worker_name = facts['worker_name']

        # The worker is not in memory, there is nothing to be updated
        worker = self.workers.get(worker_name)
        if not worker:
            return

        # We should update the id and password unconditionally
        worker['worker_id'] = facts['worker_id']

        # Suggested difficulty has been changed ..
        if worker['difficulty_suggested'] != facts['difficulty_suggested']:
            # Assign the new suggested difficulty
            worker['difficulty_suggested'] = facts['difficulty_suggested']
            # .. so let's poke DifficultySubscription and let it
            # recalculate difficulties
            for conn in worker['connections'].keys():
                diff_sub = Pubsub.get_subscription(conn, DifficultySubscription.event)
                diff_sub.recalculate_difficulty(worker_name)
예제 #3
0
    def _on_worker_refresh(self, facts):
        '''
        Callback passed to WorkerDB's refresh method for being
        notified about refreshed workers. We update the memory worker
        data appropriately.

        See WorkerDB.refresh_from_source for details about passed
        'facts' dictionary.
        '''
        worker_name = facts['worker_name']

        # The worker is not in memory, there is nothing to be updated
        worker = self.workers.get(worker_name)
        if not worker:
            return

        # We should update the id and password unconditionally
        worker['worker_id'] = facts['worker_id']

        # Suggested difficulty has been changed ..
        if worker['difficulty_suggested'] != facts['difficulty_suggested']:
            # Assign the new suggested difficulty
            worker['difficulty_suggested'] = facts['difficulty_suggested']
            # .. so let's poke DifficultySubscription and let it
            # recalculate difficulties
            for conn in worker['connections'].keys():
                diff_sub = Pubsub.get_subscription(
                    conn, DifficultySubscription.event)
                diff_sub.recalculate_difficulty(worker_name)
예제 #4
0
 def print_subs(cls):
     c = Pubsub.get_subscription_count(cls.event)
     log.info(c)
     for subs in Pubsub.iterate_subscribers(cls.event):
         s = Pubsub.get_subscription(subs.connection_ref(),
                                     cls.event,
                                     key=None)
         log.info(s)
 def print_subs(cls):
     c = Pubsub.get_subscription_count(cls.event)
     log.info(c)
     for subs in Pubsub.iterate_subscribers(cls.event):
         s = Pubsub.get_subscription(
             subs.connection_ref(),
             cls.event,
             key=None)
         log.info(s)
예제 #6
0
    def emit_single_before_mining_notify(self, connection):
        try:
            # Get the related subscription if there is some already
            diff_subs = Pubsub.get_subscription(connection, DifficultySubscription.event)

            # Plan the emission
            diff_subs.plan_single_emission()

        except PubsubException:
            # Connection is not subscribed for mining yet
            pass
예제 #7
0
    def emit_single_before_mining_notify(self, connection):
        try:
            # Get the related subscription if there is some already
            diff_subs = Pubsub.get_subscription(connection,
                                                DifficultySubscription.event)

            # Plan the emission
            diff_subs.plan_single_emission()

        except PubsubException:
            # Connection is not subscribed for mining yet
            pass