Another portion of the formatting and import fixes #1789
|
@ -9,28 +9,22 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
if sys.version_info[0] == 3:
|
try:
|
||||||
from . import helper_sql
|
|
||||||
from . import helper_startup
|
|
||||||
from . import paths
|
|
||||||
from . import queues
|
|
||||||
from . import state
|
|
||||||
from . import tr
|
|
||||||
from .bmconfigparser import BMConfigParser
|
|
||||||
from .debug import logger
|
|
||||||
# pylint: disable=attribute-defined-outside-init,protected-access
|
|
||||||
from .addresses import encodeAddress
|
|
||||||
else:
|
|
||||||
import helper_sql
|
import helper_sql
|
||||||
import helper_startup
|
import helper_startup
|
||||||
import paths
|
import paths
|
||||||
import queues
|
import queues
|
||||||
import state
|
import state
|
||||||
import tr
|
from addresses import encodeAddress
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger
|
from debug import logger
|
||||||
# pylint: disable=attribute-defined-outside-init,protected-access
|
from tr import _translate
|
||||||
from addresses import encodeAddress
|
except ImportError:
|
||||||
|
from . import helper_sql, helper_startup, paths, queues, state
|
||||||
|
from .addresses import encodeAddress
|
||||||
|
from .bmconfigparser import BMConfigParser
|
||||||
|
from .debug import logger
|
||||||
|
from .tr import _translate
|
||||||
|
|
||||||
|
|
||||||
class sqlThread(threading.Thread):
|
class sqlThread(threading.Thread):
|
||||||
|
@ -454,10 +448,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
@ -484,10 +478,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
@ -510,10 +504,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
@ -535,10 +529,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
@ -561,10 +555,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
@ -588,10 +582,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
@ -609,10 +603,10 @@ class sqlThread(threading.Thread):
|
||||||
' sqlThread will now exit.')
|
' sqlThread will now exit.')
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert', (
|
'alert', (
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Disk full"),
|
"Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
|
||||||
True)))
|
True)))
|
||||||
|
|
17
src/debug.py
17
src/debug.py
|
@ -35,24 +35,13 @@ Logging is thread-safe so you don't have to worry about locks,
|
||||||
just import and log.
|
just import and log.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# import ConfigParser
|
|
||||||
import sys
|
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
# python 3
|
|
||||||
import configparser as ConfigParser
|
|
||||||
else:
|
|
||||||
# python 2
|
|
||||||
import ConfigParser
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info[0] == 3:
|
from six.moves import configparser
|
||||||
from . import helper_startup
|
|
||||||
from . import state
|
|
||||||
else:
|
|
||||||
import helper_startup
|
import helper_startup
|
||||||
import state
|
import state
|
||||||
|
|
||||||
|
@ -86,7 +75,7 @@ def configureLogging():
|
||||||
False,
|
False,
|
||||||
'Loaded logger configuration from %s' % logging_config
|
'Loaded logger configuration from %s' % logging_config
|
||||||
)
|
)
|
||||||
except (OSError, ConfigParser.NoSectionError, KeyError):
|
except (OSError, configparser.NoSectionError, KeyError):
|
||||||
if os.path.isfile(logging_config):
|
if os.path.isfile(logging_config):
|
||||||
fail_msg = \
|
fail_msg = \
|
||||||
'Failed to load logger configuration from %s, using default' \
|
'Failed to load logger configuration from %s, using default' \
|
||||||
|
|
|
@ -16,20 +16,14 @@ SQLite objects can only be used from one thread.
|
||||||
or isn't thread-safe.
|
or isn't thread-safe.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# import Queue
|
|
||||||
import sys
|
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
import queue as Queue #python3
|
|
||||||
else:
|
|
||||||
import Queue #python2
|
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from six.moves import queue
|
||||||
|
|
||||||
sqlSubmitQueue = Queue.Queue()
|
|
||||||
|
sqlSubmitQueue = queue.Queue()
|
||||||
"""the queue for SQL"""
|
"""the queue for SQL"""
|
||||||
sqlReturnQueue = Queue.Queue()
|
sqlReturnQueue = queue.Queue()
|
||||||
"""the queue for results"""
|
"""the queue for results"""
|
||||||
sql_lock = threading.Lock()
|
sql_lock = threading.Lock()
|
||||||
""" lock to prevent queueing a new request until the previous response
|
""" lock to prevent queueing a new request until the previous response
|
||||||
|
|
|
@ -10,19 +10,15 @@ import sys
|
||||||
import time
|
import time
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
import sys
|
try:
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
from . import defaults
|
|
||||||
from . import helper_random
|
|
||||||
from . import paths
|
|
||||||
from . import state
|
|
||||||
from .bmconfigparser import BMConfigParser
|
|
||||||
else:
|
|
||||||
import defaults
|
import defaults
|
||||||
import helper_random
|
import helper_random
|
||||||
import paths
|
import paths
|
||||||
import state
|
import state
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
except ImportError:
|
||||||
|
from . import defaults, helper_random, paths, state
|
||||||
|
from .bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from plugins.plugin import get_plugin
|
from plugins.plugin import get_plugin
|
||||||
|
@ -180,9 +176,9 @@ def updateConfig():
|
||||||
# acts as a salt
|
# acts as a salt
|
||||||
config.set(
|
config.set(
|
||||||
'bitmessagesettings', 'identiconsuffix', ''.join(
|
'bitmessagesettings', 'identiconsuffix', ''.join(
|
||||||
helper_random.randomchoice("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
|
helper_random.randomchoice(
|
||||||
for x in range(12)
|
"123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
|
||||||
)
|
"abcdefghijkmnopqrstuvwxyz") for x in range(12))
|
||||||
) # a twelve character pseudo-password to salt the identicons
|
) # a twelve character pseudo-password to salt the identicons
|
||||||
|
|
||||||
# Add settings to support no longer resending messages after
|
# Add settings to support no longer resending messages after
|
||||||
|
@ -249,14 +245,15 @@ def updateConfig():
|
||||||
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte') == 0:
|
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte') == 0:
|
||||||
config.set(
|
config.set(
|
||||||
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
|
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
|
||||||
str(defaults.ridiculousDifficulty *
|
str(defaults.ridiculousDifficulty
|
||||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
|
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
|
||||||
)
|
)
|
||||||
if config.safeGetInt('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0:
|
if config.safeGetInt(
|
||||||
|
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0:
|
||||||
config.set(
|
config.set(
|
||||||
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
|
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
|
||||||
str(defaults.ridiculousDifficulty *
|
str(defaults.ridiculousDifficulty
|
||||||
defaults.networkDefaultPayloadLengthExtraBytes)
|
* defaults.networkDefaultPayloadLengthExtraBytes)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not config.has_option('bitmessagesettings', 'onionhostname'):
|
if not config.has_option('bitmessagesettings', 'onionhostname'):
|
||||||
|
@ -298,8 +295,8 @@ def adjustHalfOpenConnectionsLimit():
|
||||||
# connections at a time.
|
# connections at a time.
|
||||||
VER_THIS = StrictVersion(platform.version())
|
VER_THIS = StrictVersion(platform.version())
|
||||||
is_limited = (
|
is_limited = (
|
||||||
StrictVersion("5.1.2600") <= VER_THIS and
|
StrictVersion("5.1.2600") <= VER_THIS
|
||||||
StrictVersion("6.0.6000") >= VER_THIS
|
and StrictVersion("6.0.6000") >= VER_THIS
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -3,21 +3,17 @@ A queue with multiple internal subqueues.
|
||||||
Elements are added into a random subqueue, and retrieval rotates
|
Elements are added into a random subqueue, and retrieval rotates
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
import queue as Queue
|
|
||||||
else:
|
|
||||||
import Queue
|
|
||||||
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
if sys.version_info[0] == 3:
|
from six.moves import queue
|
||||||
from . import helper_random
|
|
||||||
else:
|
try:
|
||||||
import helper_random
|
import helper_random
|
||||||
|
except ImportError:
|
||||||
|
from . import helper_random
|
||||||
|
|
||||||
|
|
||||||
class MultiQueue(Queue.Queue):
|
class MultiQueue(queue.Queue):
|
||||||
"""A base queue class"""
|
"""A base queue class"""
|
||||||
# pylint: disable=redefined-builtin,attribute-defined-outside-init
|
# pylint: disable=redefined-builtin,attribute-defined-outside-init
|
||||||
defaultQueueCount = 10
|
defaultQueueCount = 10
|
||||||
|
@ -27,7 +23,7 @@ class MultiQueue(Queue.Queue):
|
||||||
self.queueCount = MultiQueue.defaultQueueCount
|
self.queueCount = MultiQueue.defaultQueueCount
|
||||||
else:
|
else:
|
||||||
self.queueCount = count
|
self.queueCount = count
|
||||||
Queue.Queue.__init__(self, maxsize)
|
queue.Queue.__init__(self, maxsize)
|
||||||
|
|
||||||
# Initialize the queue representation
|
# Initialize the queue representation
|
||||||
def _init(self, maxsize):
|
def _init(self, maxsize):
|
||||||
|
@ -42,7 +38,8 @@ class MultiQueue(Queue.Queue):
|
||||||
# Put a new item in the queue
|
# Put a new item in the queue
|
||||||
def _put(self, item):
|
def _put(self, item):
|
||||||
# self.queue.append(item)
|
# self.queue.append(item)
|
||||||
self.queues[helper_random.randomrandrange(self.queueCount)].append((item))
|
self.queues[helper_random.randomrandrange(self.queueCount)].append(
|
||||||
|
(item))
|
||||||
|
|
||||||
# Get an item from the queue
|
# Get an item from the queue
|
||||||
def _get(self):
|
def _get(self):
|
||||||
|
|
|
@ -9,7 +9,7 @@ import knownnodes
|
||||||
import protocol
|
import protocol
|
||||||
import state
|
import state
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from queues import Queue, portCheckerQueue
|
from queues import queue, portCheckerQueue
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ def chooseConnection(stream):
|
||||||
retval = portCheckerQueue.get(False)
|
retval = portCheckerQueue.get(False)
|
||||||
portCheckerQueue.task_done()
|
portCheckerQueue.task_done()
|
||||||
return retval
|
return retval
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
# with a probability of 0.5, connect to a discovered peer
|
# with a probability of 0.5, connect to a discovered peer
|
||||||
if random.choice((False, True)) and not haveOnion:
|
if random.choice((False, True)) and not haveOnion:
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
try:
|
|
||||||
import queue as Queue
|
from six.moves import queue
|
||||||
except ImportError:
|
|
||||||
import Queue
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from multiqueue import MultiQueue
|
from multiqueue import MultiQueue
|
||||||
|
@ -13,13 +11,13 @@ except ImportError:
|
||||||
from .multiqueue import MultiQueue
|
from .multiqueue import MultiQueue
|
||||||
|
|
||||||
|
|
||||||
class ObjectProcessorQueue(Queue.Queue):
|
class ObjectProcessorQueue(queue.Queue):
|
||||||
"""Special queue class using lock for `.threads.objectProcessor`"""
|
"""Special queue class using lock for `.threads.objectProcessor`"""
|
||||||
|
|
||||||
maxSize = 32000000
|
maxSize = 32000000
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Queue.Queue.__init__(self)
|
queue.Queue.__init__(self)
|
||||||
self.sizeLock = threading.Lock()
|
self.sizeLock = threading.Lock()
|
||||||
#: in Bytes. We maintain this to prevent nodes from flooding us
|
#: in Bytes. We maintain this to prevent nodes from flooding us
|
||||||
#: with objects which take up too much memory. If this gets
|
#: with objects which take up too much memory. If this gets
|
||||||
|
@ -31,27 +29,27 @@ class ObjectProcessorQueue(Queue.Queue):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
with self.sizeLock:
|
with self.sizeLock:
|
||||||
self.curSize += len(item[1])
|
self.curSize += len(item[1])
|
||||||
Queue.Queue.put(self, item, block, timeout)
|
queue.Queue.put(self, item, block, timeout)
|
||||||
|
|
||||||
def get(self, block=True, timeout=None):
|
def get(self, block=True, timeout=None):
|
||||||
item = Queue.Queue.get(self, block, timeout)
|
item = queue.Queue.get(self, block, timeout)
|
||||||
with self.sizeLock:
|
with self.sizeLock:
|
||||||
self.curSize -= len(item[1])
|
self.curSize -= len(item[1])
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
workerQueue = Queue.Queue()
|
workerQueue = queue.Queue()
|
||||||
UISignalQueue = Queue.Queue()
|
UISignalQueue = queue.Queue()
|
||||||
addressGeneratorQueue = Queue.Queue()
|
addressGeneratorQueue = queue.Queue()
|
||||||
#: `.network.ReceiveQueueThread` instances dump objects they hear
|
#: `.network.ReceiveQueueThread` instances dump objects they hear
|
||||||
#: on the network into this queue to be processed.
|
#: on the network into this queue to be processed.
|
||||||
objectProcessorQueue = ObjectProcessorQueue()
|
objectProcessorQueue = ObjectProcessorQueue()
|
||||||
invQueue = MultiQueue()
|
invQueue = MultiQueue()
|
||||||
addrQueue = MultiQueue()
|
addrQueue = MultiQueue()
|
||||||
portCheckerQueue = Queue.Queue()
|
portCheckerQueue = queue.Queue()
|
||||||
receiveDataQueue = Queue.Queue()
|
receiveDataQueue = queue.Queue()
|
||||||
#: The address generator thread uses this queue to get information back
|
#: The address generator thread uses this queue to get information back
|
||||||
#: to the API thread.
|
#: to the API thread.
|
||||||
apiAddressGeneratorReturnQueue = Queue.Queue()
|
apiAddressGeneratorReturnQueue = queue.Queue()
|
||||||
#: for exceptions
|
#: for exceptions
|
||||||
excQueue = Queue.Queue()
|
excQueue = queue.Queue()
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
"""shutdown function"""
|
"""shutdown function"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import Queue
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from six.moves import queue
|
||||||
|
|
||||||
import state
|
import state
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from helper_sql import sqlQuery, sqlStoredProcedure
|
from helper_sql import sqlQuery, sqlStoredProcedure
|
||||||
|
@ -69,14 +71,14 @@ def doCleanShutdown():
|
||||||
sqlStoredProcedure('exit')
|
sqlStoredProcedure('exit')
|
||||||
|
|
||||||
# flush queues
|
# flush queues
|
||||||
for queue in (
|
for q in (
|
||||||
workerQueue, UISignalQueue, addressGeneratorQueue,
|
workerQueue, UISignalQueue, addressGeneratorQueue,
|
||||||
objectProcessorQueue):
|
objectProcessorQueue):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
queue.get(False)
|
q.get(False)
|
||||||
queue.task_done()
|
q.task_done()
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
if state.thisapp.daemon or not state.enableGUI:
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
|
|
Reference in New Issue
Block a user