Permalink
Browse files

handling authorization failure in stratum detection

  • Loading branch information...
m0mchil committed Oct 30, 2012
1 parent 32bc5d3 commit 2fb93afa4fd222ff5059c60dc3f5d209dc57b07e
Showing with 12 additions and 4 deletions.
  1. +12 −4 GetworkSource.py
View
@@ -33,7 +33,10 @@ def __init__(self, switch, server):
self.long_poll_active = False
+ self.authorization_failed = False
+
def loop(self):
+ if self.authorization_failed: return
super(GetworkSource, self).loop()
thread = Thread(target=self.long_poll_thread)
@@ -101,8 +104,11 @@ def request(self, connection, url, headers, data=None, timeout=0):
if data: connection.request('POST', url, data, headers)
else: connection.request('GET', url, headers=headers)
response = self.timeout_response(connection, timeout)
+ if not response:
+ return None
if response.status == httplib.UNAUTHORIZED:
say_line('Wrong username or password for %s', self.switch.server_name())
+ self.authorization_failed = True
raise NotAuthorized()
r = self.max_redirects
while response.status == httplib.TEMPORARY_REDIRECT:
@@ -152,10 +158,10 @@ def getwork(self, data=None):
self.switch.connection_ok()
return result['result']
- except Exception:
- say_exception()
except (IOError, httplib.HTTPException, ValueError, socks.ProxyError, NotAuthorized, RPCError):
self.stop()
+ except Exception:
+ say_exception()
def send_internal(self, result, nonce):
data = ''.join([result.header.encode('hex'), pack('III', long(result.time), long(result.difficulty), long(nonce)).encode('hex'), '000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000'])
@@ -196,12 +202,12 @@ def long_poll_thread(self):
self.queue_work(result['result'])
if self.options.verbose:
say_line('long poll: new block %s%s', (result['result']['data'][56:64], result['result']['data'][48:56]))
- except Exception:
- say_exception()
except (IOError, httplib.HTTPException, ValueError, socks.ProxyError, NotAuthorized, RPCError):
say_exception('long poll IO error')
self.close_lp_connection()
sleep(.5)
+ except Exception:
+ say_exception()
def stop(self):
self.should_stop = True
@@ -227,6 +233,8 @@ def queue_work(self, work, miner=None):
def detect_stratum(self):
work = self.getwork()
+ if self.authorization_failed:
+ return False
if work:
if self.stratum_header:

0 comments on commit 2fb93af

Please sign in to comment.