本文整理汇总了Python中stratum.pubsub.Pubsub.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python Pubsub.subscribe方法的具体用法?Python Pubsub.subscribe怎么用?Python Pubsub.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stratum.pubsub.Pubsub
的用法示例。
在下文中一共展示了Pubsub.subscribe方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subscribe
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import subscribe [as 别名]
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: subscribe
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import subscribe [as 别名]
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))
示例3: login
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import subscribe [as 别名]
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)
示例4: subscribe
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import subscribe [as 别名]
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)
示例5: subscribe
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import subscribe [as 别名]
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))