Merge branch '1206' into v0.6
This commit is contained in:
commit
62e80e9ca7
|
@ -1,9 +1,14 @@
|
||||||
import os
|
"""
|
||||||
|
Helper Generic perform generic oprations for threading.
|
||||||
|
|
||||||
|
Also perform some conversion operations.
|
||||||
|
"""
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from multiprocessing import current_process
|
from multiprocessing import current_process
|
||||||
from threading import current_thread, enumerate
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import shared
|
import shared
|
||||||
|
@ -11,16 +16,18 @@ from debug import logger
|
||||||
import queues
|
import queues
|
||||||
import shutdown
|
import shutdown
|
||||||
|
|
||||||
|
|
||||||
def powQueueSize():
|
def powQueueSize():
|
||||||
curWorkerQueue = queues.workerQueue.qsize()
|
curWorkerQueue = queues.workerQueue.qsize()
|
||||||
for thread in enumerate():
|
for thread in threading.enumerate():
|
||||||
try:
|
try:
|
||||||
if thread.name == "singleWorker":
|
if thread.name == "singleWorker":
|
||||||
curWorkerQueue += thread.busy
|
curWorkerQueue += thread.busy
|
||||||
except:
|
except Exception as err:
|
||||||
pass
|
logger.info("Thread error %s", err)
|
||||||
return curWorkerQueue
|
return curWorkerQueue
|
||||||
|
|
||||||
|
|
||||||
def convertIntToString(n):
|
def convertIntToString(n):
|
||||||
a = __builtins__.hex(n)
|
a = __builtins__.hex(n)
|
||||||
if a[-1:] == 'L':
|
if a[-1:] == 'L':
|
||||||
|
@ -30,28 +37,33 @@ def convertIntToString(n):
|
||||||
else:
|
else:
|
||||||
return unhexlify('0' + a[2:])
|
return unhexlify('0' + a[2:])
|
||||||
|
|
||||||
|
|
||||||
def convertStringToInt(s):
|
def convertStringToInt(s):
|
||||||
return int(hexlify(s), 16)
|
return int(hexlify(s), 16)
|
||||||
|
|
||||||
|
|
||||||
def allThreadTraceback(frame):
|
def allThreadTraceback(frame):
|
||||||
id2name = dict([(th.ident, th.name) for th in enumerate()])
|
id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
|
||||||
code = []
|
code = []
|
||||||
for threadId, stack in sys._current_frames().items():
|
for threadId, stack in sys._current_frames().items():
|
||||||
code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,""), threadId))
|
code.append("\n# Thread: %s(%d)" % (
|
||||||
|
id2name.get(threadId, ""), threadId))
|
||||||
for filename, lineno, name, line in traceback.extract_stack(stack):
|
for filename, lineno, name, line in traceback.extract_stack(stack):
|
||||||
code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
|
code.append('File: "%s", line %d, in %s' % (
|
||||||
|
filename, lineno, name))
|
||||||
if line:
|
if line:
|
||||||
code.append(" %s" % (line.strip()))
|
code.append(" %s" % (line.strip()))
|
||||||
print "\n".join(code)
|
print "\n".join(code)
|
||||||
|
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
logger.error("Got signal %i in %s/%s", signal, current_process().name, current_thread().name)
|
logger.error("Got signal %i in %s/%s", signal,
|
||||||
if current_process().name == "RegExParser":
|
current_process().name,
|
||||||
# on Windows this isn't triggered, but it's fine, it has its own process termination thing
|
threading.current_thread().name)
|
||||||
raise SystemExit
|
|
||||||
if "PoolWorker" in current_process().name:
|
if "PoolWorker" in current_process().name:
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
if current_thread().name not in ("PyBitmessage", "MainThread"):
|
if threading.current_thread().name not in (
|
||||||
|
"PyBitmessage", "MainThread"):
|
||||||
return
|
return
|
||||||
logger.error("Got signal %i", signal)
|
logger.error("Got signal %i", signal)
|
||||||
if shared.thisapp.daemon:
|
if shared.thisapp.daemon:
|
||||||
|
@ -60,8 +72,9 @@ def signal_handler(signal, frame):
|
||||||
allThreadTraceback(frame)
|
allThreadTraceback(frame)
|
||||||
print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.'
|
print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.'
|
||||||
|
|
||||||
|
|
||||||
def isHostInPrivateIPRange(host):
|
def isHostInPrivateIPRange(host):
|
||||||
if ":" in host: #IPv6
|
if ":" in host: # IPv6
|
||||||
hostAddr = socket.inet_pton(socket.AF_INET6, host)
|
hostAddr = socket.inet_pton(socket.AF_INET6, host)
|
||||||
if hostAddr == ('\x00' * 15) + '\x01':
|
if hostAddr == ('\x00' * 15) + '\x01':
|
||||||
return False
|
return False
|
||||||
|
@ -69,7 +82,6 @@ def isHostInPrivateIPRange(host):
|
||||||
return False
|
return False
|
||||||
if (ord(hostAddr[0]) & 0xfe) == 0xfc:
|
if (ord(hostAddr[0]) & 0xfe) == 0xfc:
|
||||||
return False
|
return False
|
||||||
pass
|
|
||||||
elif ".onion" not in host:
|
elif ".onion" not in host:
|
||||||
if host[:3] == '10.':
|
if host[:3] == '10.':
|
||||||
return True
|
return True
|
||||||
|
@ -84,5 +96,6 @@ def isHostInPrivateIPRange(host):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def addDataPadding(data, desiredMsgLength = 12, paddingChar = '\x00'):
|
|
||||||
|
def addDataPadding(data, desiredMsgLength=12, paddingChar='\x00'):
|
||||||
return data + paddingChar * (desiredMsgLength - len(data))
|
return data + paddingChar * (desiredMsgLength - len(data))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user