• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pubsub.Pubsub类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stratum.pubsub.Pubsub的典型用法代码示例。如果您正苦于以下问题:Python Pubsub类的具体用法?Python Pubsub怎么用?Python Pubsub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Pubsub类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: on_template

    def on_template(cls, is_new_block):
        """This is called when TemplateRegistry registers
           new block which we have to broadcast clients."""
        
        start = Interfaces.timestamper.time()
        clean_jobs = is_new_block
        
        (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \
            Interfaces.template_registry.get_last_broadcast_args()

        # Push new job to subscribed clients
        for subscription in Pubsub.iterate_subscribers(cls.event):
            try:
                if subscription != None:
                    session = subscription.connection_ref().get_session()
                    session.setdefault('authorized', {})
                    if session['authorized'].keys():
                        worker_name = session['authorized'].keys()[0]
                        difficulty = session['difficulty']
                        work_id = Interfaces.worker_manager.register_work(worker_name, job_id, difficulty)
                        #log.debug("emitting for work id %s job id %s block %s " % (work_id, job_id, prevhash))
                        subscription.emit_single(work_id, prevhash, coinb1, coinb2, merkle_branch, version,
                                                 nbits, ntime, clean_jobs)
                    else:
                        subscription.emit_single(job_id, prevhash, coinb1, coinb2, merkle_branch, version,
                                                 nbits, ntime, clean_jobs)
            except Exception as e:
                log.exception("Error broadcasting work to client %s" % str(e))
                pass
        
        cnt = Pubsub.get_subscription_count(cls.event)
        log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
开发者ID:penner42,项目名称:stratum-mining,代码行数:32,代码来源:subscription.py


示例2: subscribe

    def subscribe(self, *args):
        f = self._get_stratum_proxy().f
        job = self._get_stratum_proxy().jobreg

        if f.client is None or not f.client.connected:
            yield f.on_connect

        conn = self.connection_ref()

        if f.client is None or not f.client.connected or not conn:
            raise UpstreamServiceException("Upstream not connected")

        if job.extranonce1 is None:
            # This should never happen, because _f.on_connect is fired *after*
            # connection receive mining.subscribe response
            raise UpstreamServiceException("Not subscribed on upstream yet")

        (tail, extranonce2_size) = job._get_unused_tail()
        session = self.connection_ref().get_session()
        session['tail'] = tail
        # Remove extranonce from registry when client disconnect
        conn.on_disconnect.addCallback(job._drop_tail, tail)
        subs1 = Pubsub.subscribe(conn, DifficultySubscription())[0]
        subs2 = Pubsub.subscribe(conn, MiningSubscription())[0]
        log.info(
            "Sending subscription to worker: %s/%s" %
            (job.extranonce1 + tail, extranonce2_size))
        defer.returnValue(
            ((subs1, subs2),) + (job.extranonce1 + tail, extranonce2_size))
开发者ID:digideskio,项目名称:stratum-proxy-ng,代码行数:29,代码来源:stratum_listener.py


示例3: subscribe

    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)
开发者ID:frrp,项目名称:bitcoin-mining-pool,代码行数:33,代码来源:service.py


示例4: print_subs

 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)
开发者ID:digideskio,项目名称:stratum-proxy-ng,代码行数:9,代码来源:stratum_listener.py


示例5: login

    def login(self, params, *args):
        if self._f.client == None or not self._f.client.connected:
            yield self._f.on_connect

        if self._f.client == None or not self._f.client.connected:
            raise UpstreamServiceException("Upstream not connected")

        tail = self._get_unused_tail()
        
        session = self.connection_ref().get_session()
        session['tail'] = tail

        custom_user = self.custom_user
        if self.enable_worker_id and params.has_key("login"):
            if self.worker_id_from_ip:
                ip_login = self.connection_ref()._get_ip()
                ip_temp = ip_login.split('.')
                ip_int = int(ip_temp[0])*16777216 + int(ip_temp[1])*65536 + int(ip_temp[2])*256 + int(ip_temp[3])
                custom_user = "%s.%s" % (custom_user, ip_int)
            else:
                params_login = re.sub(r'[^\d]', '', params["login"])
                if params_login and int(params_login)>0:
                    custom_user = "%s.%s" % (custom_user, params_login)

        first_job = (yield self._f.rpc('login', {"login":custom_user, "pass":self.custom_password}))

        try:
            self.connection_ref().on_disconnect.addCallback(self._drop_tail, tail)
        except Exception:
            pass
        subs = Pubsub.subscribe(self.connection_ref(), MiningSubscription())[0]

        MiningSubscription.add_user_id(subs[2], first_job['id'])

        defer.returnValue(first_job)
开发者ID:nikkiman,项目名称:xmr-proxy,代码行数:35,代码来源:stratum_listener.py


示例6: _on_worker_refresh

    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)
开发者ID:frrp,项目名称:bitcoin-mining-pool,代码行数:28,代码来源:worker_manager.py


示例7: emit_single_before_mining_notify

    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
开发者ID:frrp,项目名称:bitcoin-mining-pool,代码行数:11,代码来源:difficulty.py


示例8: subscribe

 def subscribe(self, *args):
     '''Subscribe for receiving mining jobs. This will
     return subscription details, extranonce1_hex and extranonce2_size'''
     
     extranonce1 = Interfaces.template_registry.get_new_extranonce1()
     extranonce2_size = Interfaces.template_registry.extranonce2_size
     extranonce1_hex = binascii.hexlify(extranonce1)
     
     session = self.connection_ref().get_session()
     session['extranonce1'] = extranonce1
     session['difficulty'] = settings.POOL_TARGET  # Following protocol specs, default diff is 1
     return Pubsub.subscribe(self.connection_ref(), MiningSubscription()) + (extranonce1_hex, extranonce2_size)
开发者ID:McKenzy83,项目名称:merged-stratum,代码行数:12,代码来源:service.py


示例9: subscribe

    def subscribe(self, *args):    
        if self._f.client == None or not self._f.client.connected:
            yield self._f.on_connect
            
        if self._f.client == None or not self._f.client.connected:
            raise UpstreamServiceException("Upstream not connected")
         
        if self.extranonce1 == None:
            # This should never happen, because _f.on_connect is fired *after*
            # connection receive mining.subscribe response
            raise UpstreamServiceException("Not subscribed on upstream yet")
        
        (tail, extranonce2_size) = self._get_unused_tail()
        
        session = self.connection_ref().get_session()
        session['tail'] = tail
                
        # Remove extranonce from registry when client disconnect
        self.connection_ref().on_disconnect.addCallback(self._drop_tail, tail)

        subs1 = Pubsub.subscribe(self.connection_ref(), DifficultySubscription())[0]
        subs2 = Pubsub.subscribe(self.connection_ref(), MiningSubscription())[0]            
        defer.returnValue(((subs1, subs2),) + (self.extranonce1+tail, extranonce2_size))
开发者ID:yawkat,项目名称:stratum-mining-proxy,代码行数:23,代码来源:stratum_listener.py


示例10: on_template

 def on_template(cls, is_new_block):
     '''This is called when TemplateRegistry registers
        new block which we have to broadcast clients.'''
     
     start = Interfaces.timestamper.time()
     clean_jobs = is_new_block
     
     (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \
         Interfaces.template_registry.get_last_broadcast_args()
     
     # Push new job to subscribed clients
     cls.emit(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs)
     
     cnt = Pubsub.get_subscription_count(cls.event)
     log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
开发者ID:Devianttwo,项目名称:Stratum-Scrypt-Jane,代码行数:15,代码来源:subscription.py


示例11: get_server_stats

    def get_server_stats(self):
        serialized = '' 
        for subscription in Pubsub.iterate_subscribers(self.event):
            try:
                if subscription != None:
                    session = subscription.connection_ref().get_session()
                    session.setdefault('authorized', {})
                    if session['authorized'].keys():
                        worker_name = session['authorized'].keys()[0]
                        difficulty = session['difficulty']
                        ip = subscription.connection_ref()._get_ip()
                        serialized += json.dumps({'worker_name': worker_name, 'ip': ip, 'difficulty': difficulty})
                    else:
                        pass
            except Exception as e:
                log.exception("Error getting subscriptions %s" % str(e))
                pass

        log.debug("Server stats request: %s" % serialized)
        return '%s' % serialized
开发者ID:McKenzy83,项目名称:merged-stratum,代码行数:20,代码来源:service.py


示例12: get_server_stats

    def get_server_stats(self):
        serialized = ""
        for subscription in Pubsub.iterate_subscribers(self.event):
            try:
                if subscription != None:
                    session = subscription.connection_ref().get_session()
                    session.setdefault("authorized", {})
                    if session["authorized"].keys():
                        worker_name = session["authorized"].keys()[0]
                        difficulty = session["difficulty"]
                        ip = subscription.connection_ref()._get_ip()
                        serialized += json.dumps({"worker_name": worker_name, "ip": ip, "difficulty": difficulty})
                    else:
                        pass
            except Exception as e:
                log.exception("Error getting subscriptions %s" % str(e))
                pass

        log.debug("Server stats request: %s" % serialized)
        return "%s" % serialized
开发者ID:hevoc123,项目名称:stratum-mining,代码行数:20,代码来源:service.py


示例13: on_template

    def on_template(cls, is_new_block):
        '''This is called when TemplateRegistry registers
           new block which we have to broadcast clients.'''

        start = posix_time()

        clean_jobs = is_new_block
        (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \
                        Interfaces.template_registry.get_last_template_broadcast_args()

        if not is_new_block:
            try:
                cls.before_broadcast.callback(True)
                cls.before_broadcast = defer.Deferred()
            except:
                log.exception("before_broadcast callback failed!")

        # Push new job to subscribed clients
        cls.emit("%x"%job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs)

        cnt = Pubsub.get_subscription_count(cls.event)
        log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (posix_time() - start)))
开发者ID:frrp,项目名称:bitcoin-mining-pool,代码行数:22,代码来源:subscription.py


示例14: disconnect_all

 def disconnect_all(cls):
     for subs in Pubsub.iterate_subscribers(cls.event):
         subs.connection_ref().transport.loseConnection()
开发者ID:yawkat,项目名称:stratum-mining-proxy,代码行数:3,代码来源:stratum_listener.py


示例15: get_num_connections

 def get_num_connections(cls):
     return Pubsub.get_subscription_count(cls.event)
开发者ID:digideskio,项目名称:stratum-proxy-ng,代码行数:2,代码来源:stratum_listener.py


示例16: reconnect_all

 def reconnect_all(cls):
     for subs in Pubsub.iterate_subscribers(cls.event):
         if subs.connection_ref().transport is not None:
             subs.connection_ref().transport.loseConnection()
开发者ID:digideskio,项目名称:stratum-proxy-ng,代码行数:4,代码来源:stratum_listener.py



注:本文中的stratum.pubsub.Pubsub类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stratuslab.Util类代码示例发布时间:2022-05-27
下一篇:
Python strategy_test.datetime_from_date函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap