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)))
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) 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)))
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)
def reconnect_all(cls, stp): for subs in Pubsub.iterate_subscribers(cls.event): conn = subs.connection_ref() if conn is None or conn.transport is None: continue session = conn.get_session() if session['proxy'] is stp: conn.transport.loseConnection()
def set_difficulty(self, diff): if 600 <= diff <= settings.VDIFF_MAX_TARGET: settings.POOL_TARGET = diff settings.VDIFF_MIN_TARGET = diff for subscription in Pubsub.iterate_subscribers(self.event): try: if subscription and subscription.connection_ref(): subscription.connection_ref().rpc( 'mining.set_difficulty', [diff], is_notification=True) except: pass return True return False
def on_template(cls, is_new_block): u'''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 is not None: session = subscription.connection_ref().get_session() session.setdefault(u'authorized', {}) if list(session[u'authorized'].keys()): worker_name = list(session[u'authorized'].keys())[0] difficulty = session[u'difficulty'] work_id = Interfaces.worker_manager.register_work( worker_name, job_id, difficulty) 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, e: log.exception(u"Error broadcasting work to client %s" % unicode(e)) pass
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, 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] extranonce1 = session.get('extranonce1', None) extranonce2 = struct.pack('>L', 0) coinbase_bin = Interfaces.template_registry.last_block.serialize_coinbase( extranonce1, extranonce2) coinbase_hash = util.doublesha(coinbase_bin) merkle_root_bin = Interfaces.template_registry.last_block.merkletree.withFirst( coinbase_hash) merkle_root = binascii.hexlify(merkle_root_bin) job = {} job['data'] = version + prevhash + merkle_root + ntime + nbits job['difficulty'] = session['difficulty'] work_id = Interfaces.worker_manager.register_work( extranonce1, merkle_root, session['difficulty'], job_id, session['basediff']) subscription.emit_single(job) else: continue 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)))
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
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
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
def get_server_stats(self): serialized = u'' for subscription in Pubsub.iterate_subscribers(self.event): try: if subscription is not None: session = subscription.connection_ref().get_session() session.setdefault(u'authorized', {}) if list(session[u'authorized'].keys()): worker_name = list(session[u'authorized'].keys())[0] difficulty = session[u'difficulty'] ip = subscription.connection_ref()._get_ip() serialized += json.dumps({ u'worker_name': worker_name, u'ip': ip, u'difficulty': difficulty }) else: pass except Exception, e: log.exception(u"Error getting subscriptions %s" % unicode(e)) pass
def disconnect_all(cls): for subs in Pubsub.iterate_subscribers(cls.event): subs.connection_ref().transport.loseConnection()
def disconnect_all(cls): for subs in Pubsub.iterate_subscribers(cls.event): if subs.connection_ref().transport != None: subs.connection_ref().transport.loseConnection()
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()