Moved most of variables from shared elsewhere (mostly to state)
This commit is contained in:
parent
7fd6200fb1
commit
185ad66ea5
17
src/api.py
17
src/api.py
|
@ -27,6 +27,7 @@ import queues
|
||||||
import shared
|
import shared
|
||||||
import shutdown
|
import shutdown
|
||||||
import state
|
import state
|
||||||
|
import threads
|
||||||
from addresses import (
|
from addresses import (
|
||||||
addBMIfNotPresent,
|
addBMIfNotPresent,
|
||||||
calculateInventoryHash,
|
calculateInventoryHash,
|
||||||
|
@ -1206,7 +1207,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8
|
len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8
|
||||||
) * requiredAverageProofOfWorkNonceTrialsPerByte
|
) * requiredAverageProofOfWorkNonceTrialsPerByte
|
||||||
)
|
)
|
||||||
with shared.printLock:
|
with threads.printLock:
|
||||||
print(
|
print(
|
||||||
'(For msg message via API) Doing proof of work.'
|
'(For msg message via API) Doing proof of work.'
|
||||||
'Total required difficulty:',
|
'Total required difficulty:',
|
||||||
|
@ -1221,7 +1222,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
powStartTime = time.time()
|
powStartTime = time.time()
|
||||||
initialHash = hashlib.sha512(encryptedPayload).digest()
|
initialHash = hashlib.sha512(encryptedPayload).digest()
|
||||||
trialValue, nonce = proofofwork.run(target, initialHash)
|
trialValue, nonce = proofofwork.run(target, initialHash)
|
||||||
with shared.printLock:
|
with threads.printLock:
|
||||||
print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce
|
print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce
|
||||||
try:
|
try:
|
||||||
print(
|
print(
|
||||||
|
@ -1240,7 +1241,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
objectType, toStreamNumber, encryptedPayload,
|
objectType, toStreamNumber, encryptedPayload,
|
||||||
int(time.time()) + TTL, ''
|
int(time.time()) + TTL, ''
|
||||||
)
|
)
|
||||||
with shared.printLock:
|
with threads.printLock:
|
||||||
print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash)
|
print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash)
|
||||||
queues.invQueue.put((toStreamNumber, inventoryHash))
|
queues.invQueue.put((toStreamNumber, inventoryHash))
|
||||||
|
|
||||||
|
@ -1294,7 +1295,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
Inventory()[inventoryHash] = (
|
Inventory()[inventoryHash] = (
|
||||||
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
|
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
|
||||||
)
|
)
|
||||||
with shared.printLock:
|
with threads.printLock:
|
||||||
print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)
|
print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)
|
||||||
queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
|
queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
|
||||||
|
|
||||||
|
@ -1347,15 +1348,15 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
connections_num = len(network.stats.connectedHostsList())
|
connections_num = len(network.stats.connectedHostsList())
|
||||||
if connections_num == 0:
|
if connections_num == 0:
|
||||||
networkStatus = 'notConnected'
|
networkStatus = 'notConnected'
|
||||||
elif shared.clientHasReceivedIncomingConnections:
|
elif state.clientHasReceivedIncomingConnections:
|
||||||
networkStatus = 'connectedAndReceivingIncomingConnections'
|
networkStatus = 'connectedAndReceivingIncomingConnections'
|
||||||
else:
|
else:
|
||||||
networkStatus = 'connectedButHaveNotReceivedIncomingConnections'
|
networkStatus = 'connectedButHaveNotReceivedIncomingConnections'
|
||||||
return json.dumps({
|
return json.dumps({
|
||||||
'networkConnections': connections_num,
|
'networkConnections': connections_num,
|
||||||
'numberOfMessagesProcessed': shared.numberOfMessagesProcessed,
|
'numberOfMessagesProcessed': state.numberOfMessagesProcessed,
|
||||||
'numberOfBroadcastsProcessed': shared.numberOfBroadcastsProcessed,
|
'numberOfBroadcastsProcessed': state.numberOfBroadcastsProcessed,
|
||||||
'numberOfPubkeysProcessed': shared.numberOfPubkeysProcessed,
|
'numberOfPubkeysProcessed': state.numberOfPubkeysProcessed,
|
||||||
'networkStatus': networkStatus,
|
'networkStatus': networkStatus,
|
||||||
'softwareName': 'PyBitmessage',
|
'softwareName': 'PyBitmessage',
|
||||||
'softwareVersion': softwareVersion
|
'softwareVersion': softwareVersion
|
||||||
|
|
|
@ -24,6 +24,7 @@ import network.stats
|
||||||
import queues
|
import queues
|
||||||
import shared
|
import shared
|
||||||
import shutdown
|
import shutdown
|
||||||
|
import state
|
||||||
|
|
||||||
from addresses import addBMIfNotPresent, decodeAddress
|
from addresses import addBMIfNotPresent, decodeAddress
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
@ -274,11 +275,11 @@ def drawtab(stdscr):
|
||||||
# Uptime and processing data
|
# Uptime and processing data
|
||||||
stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False))
|
stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False))
|
||||||
stdscr.addstr(7, 40, "Processed " + str(
|
stdscr.addstr(7, 40, "Processed " + str(
|
||||||
shared.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.")
|
state.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.")
|
||||||
stdscr.addstr(8, 40, "Processed " + str(
|
stdscr.addstr(8, 40, "Processed " + str(
|
||||||
shared.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
|
state.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
|
||||||
stdscr.addstr(9, 40, "Processed " + str(
|
stdscr.addstr(9, 40, "Processed " + str(
|
||||||
shared.numberOfPubkeysProcessed).ljust(4) + " public keys.")
|
state.numberOfPubkeysProcessed).ljust(4) + " public keys.")
|
||||||
|
|
||||||
# Inventory data
|
# Inventory data
|
||||||
stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3))
|
stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3))
|
||||||
|
|
|
@ -51,9 +51,8 @@ from network import (
|
||||||
from singleinstance import singleinstance
|
from singleinstance import singleinstance
|
||||||
# Synchronous threads
|
# Synchronous threads
|
||||||
from threads import (
|
from threads import (
|
||||||
set_thread_name, addressGenerator, objectProcessor, singleCleaner,
|
set_thread_name, printLock,
|
||||||
singleWorker, sqlThread
|
addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def connectToStream(streamNumber):
|
def connectToStream(streamNumber):
|
||||||
|
@ -157,7 +156,7 @@ def signal_handler(signum, frame):
|
||||||
logger.error("Got signal %i", signum)
|
logger.error("Got signal %i", signum)
|
||||||
# there are possible non-UI variants to run bitmessage
|
# there are possible non-UI variants to run bitmessage
|
||||||
# which should shutdown especially test-mode
|
# which should shutdown especially test-mode
|
||||||
if shared.thisapp.daemon or not state.enableGUI:
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
shutdown.doCleanShutdown()
|
shutdown.doCleanShutdown()
|
||||||
else:
|
else:
|
||||||
print('# Thread: %s(%d)' % (thread.name, thread.ident))
|
print('# Thread: %s(%d)' % (thread.name, thread.ident))
|
||||||
|
@ -233,10 +232,10 @@ class Main(object):
|
||||||
' \'-c\' as a commandline argument.'
|
' \'-c\' as a commandline argument.'
|
||||||
)
|
)
|
||||||
# is the application already running? If yes then exit.
|
# is the application already running? If yes then exit.
|
||||||
shared.thisapp = singleinstance("", daemon)
|
state.thisapp = singleinstance("", daemon)
|
||||||
|
|
||||||
if daemon:
|
if daemon:
|
||||||
with shared.printLock:
|
with printLock:
|
||||||
print('Running as a daemon. Send TERM signal to end.')
|
print('Running as a daemon. Send TERM signal to end.')
|
||||||
self.daemonize()
|
self.daemonize()
|
||||||
|
|
||||||
|
@ -413,7 +412,7 @@ class Main(object):
|
||||||
try:
|
try:
|
||||||
if os.fork():
|
if os.fork():
|
||||||
# unlock
|
# unlock
|
||||||
shared.thisapp.cleanup()
|
state.thisapp.cleanup()
|
||||||
# wait until grandchild ready
|
# wait until grandchild ready
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -423,7 +422,7 @@ class Main(object):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
parentPid = os.getpid()
|
parentPid = os.getpid()
|
||||||
shared.thisapp.lock() # relock
|
state.thisapp.lock() # relock
|
||||||
|
|
||||||
os.umask(0)
|
os.umask(0)
|
||||||
try:
|
try:
|
||||||
|
@ -434,7 +433,7 @@ class Main(object):
|
||||||
try:
|
try:
|
||||||
if os.fork():
|
if os.fork():
|
||||||
# unlock
|
# unlock
|
||||||
shared.thisapp.cleanup()
|
state.thisapp.cleanup()
|
||||||
# wait until child ready
|
# wait until child ready
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -443,8 +442,8 @@ class Main(object):
|
||||||
# fork not implemented
|
# fork not implemented
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
shared.thisapp.lock() # relock
|
state.thisapp.lock() # relock
|
||||||
shared.thisapp.lockPid = None # indicate we're the final child
|
state.thisapp.lockPid = None # indicate we're the final child
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
if not sys.platform.startswith('win'):
|
if not sys.platform.startswith('win'):
|
||||||
|
@ -483,7 +482,7 @@ All parameters are optional.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
"""Stop main application"""
|
"""Stop main application"""
|
||||||
with shared.printLock:
|
with printLock:
|
||||||
print('Stopping Bitmessage Deamon.')
|
print('Stopping Bitmessage Deamon.')
|
||||||
shutdown.doCleanShutdown()
|
shutdown.doCleanShutdown()
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,11 @@ from sqlite3 import register_adapter
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from PyQt4.QtNetwork import QLocalSocket, QLocalServer
|
from PyQt4.QtNetwork import QLocalSocket, QLocalServer
|
||||||
|
|
||||||
|
import shared
|
||||||
|
import state
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from tr import _translate
|
from tr import _translate
|
||||||
from addresses import decodeAddress, addBMIfNotPresent
|
from addresses import decodeAddress, addBMIfNotPresent
|
||||||
import shared
|
|
||||||
from bitmessageui import Ui_MainWindow
|
from bitmessageui import Ui_MainWindow
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
import namecoin
|
import namecoin
|
||||||
|
@ -730,9 +731,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL(
|
||||||
"clicked()"), self.click_pushButtonStatusIcon)
|
"clicked()"), self.click_pushButtonStatusIcon)
|
||||||
|
|
||||||
self.numberOfMessagesProcessed = 0
|
|
||||||
self.numberOfBroadcastsProcessed = 0
|
|
||||||
self.numberOfPubkeysProcessed = 0
|
|
||||||
self.unreadCount = 0
|
self.unreadCount = 0
|
||||||
|
|
||||||
# Set the icon sizes for the identicons
|
# Set the icon sizes for the identicons
|
||||||
|
@ -1668,7 +1666,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if color == 'red':
|
if color == 'red':
|
||||||
self.pushButtonStatusIcon.setIcon(
|
self.pushButtonStatusIcon.setIcon(
|
||||||
QtGui.QIcon(":/newPrefix/images/redicon.png"))
|
QtGui.QIcon(":/newPrefix/images/redicon.png"))
|
||||||
shared.statusIconColor = 'red'
|
state.statusIconColor = 'red'
|
||||||
# if the connection is lost then show a notification
|
# if the connection is lost then show a notification
|
||||||
if self.connected and _notifications_enabled:
|
if self.connected and _notifications_enabled:
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
|
@ -1694,7 +1692,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.statusbar.clearMessage()
|
self.statusbar.clearMessage()
|
||||||
self.pushButtonStatusIcon.setIcon(
|
self.pushButtonStatusIcon.setIcon(
|
||||||
QtGui.QIcon(":/newPrefix/images/yellowicon.png"))
|
QtGui.QIcon(":/newPrefix/images/yellowicon.png"))
|
||||||
shared.statusIconColor = 'yellow'
|
state.statusIconColor = 'yellow'
|
||||||
# if a new connection has been established then show a notification
|
# if a new connection has been established then show a notification
|
||||||
if not self.connected and _notifications_enabled:
|
if not self.connected and _notifications_enabled:
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
|
@ -1712,7 +1710,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.statusbar.clearMessage()
|
self.statusbar.clearMessage()
|
||||||
self.pushButtonStatusIcon.setIcon(
|
self.pushButtonStatusIcon.setIcon(
|
||||||
QtGui.QIcon(":/newPrefix/images/greenicon.png"))
|
QtGui.QIcon(":/newPrefix/images/greenicon.png"))
|
||||||
shared.statusIconColor = 'green'
|
state.statusIconColor = 'green'
|
||||||
if not self.connected and _notifications_enabled:
|
if not self.connected and _notifications_enabled:
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
'Bitmessage',
|
'Bitmessage',
|
||||||
|
@ -2119,7 +2117,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
"MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber)))
|
"MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber)))
|
||||||
continue
|
continue
|
||||||
self.statusbar.clearMessage()
|
self.statusbar.clearMessage()
|
||||||
if shared.statusIconColor == 'red':
|
if state.statusIconColor == 'red':
|
||||||
self.updateStatusBar(_translate(
|
self.updateStatusBar(_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Warning: You are currently not connected."
|
"Warning: You are currently not connected."
|
||||||
|
@ -2632,7 +2630,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
elif reply == QtGui.QMessageBox.Cancel:
|
elif reply == QtGui.QMessageBox.Cancel:
|
||||||
return
|
return
|
||||||
|
|
||||||
if shared.statusIconColor == 'red' and not BMConfigParser().safeGetBoolean(
|
if state.statusIconColor == 'red' and not BMConfigParser().safeGetBoolean(
|
||||||
'bitmessagesettings', 'dontconnect'):
|
'bitmessagesettings', 'dontconnect'):
|
||||||
reply = QtGui.QMessageBox.question(
|
reply = QtGui.QMessageBox.question(
|
||||||
self, _translate("MainWindow", "Not connected"),
|
self, _translate("MainWindow", "Not connected"),
|
||||||
|
@ -2660,7 +2658,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if waitForConnection:
|
if waitForConnection:
|
||||||
self.updateStatusBar(_translate(
|
self.updateStatusBar(_translate(
|
||||||
"MainWindow", "Waiting for network connection..."))
|
"MainWindow", "Waiting for network connection..."))
|
||||||
while shared.statusIconColor == 'red':
|
while state.statusIconColor == 'red':
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
QtCore.QCoreApplication.processEvents(
|
QtCore.QCoreApplication.processEvents(
|
||||||
QtCore.QEventLoop.AllEvents, 1000
|
QtCore.QEventLoop.AllEvents, 1000
|
||||||
|
|
|
@ -11,7 +11,7 @@ from PyQt4 import QtCore, QtGui
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import l10n
|
import l10n
|
||||||
import network.stats
|
import network.stats
|
||||||
import shared
|
import state
|
||||||
import widgets
|
import widgets
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from network import BMConnectionPool
|
from network import BMConnectionPool
|
||||||
|
@ -108,7 +108,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
|
||||||
"Processed %n person-to-person message(s).",
|
"Processed %n person-to-person message(s).",
|
||||||
None,
|
None,
|
||||||
QtCore.QCoreApplication.CodecForTr,
|
QtCore.QCoreApplication.CodecForTr,
|
||||||
shared.numberOfMessagesProcessed))
|
state.numberOfMessagesProcessed))
|
||||||
|
|
||||||
def updateNumberOfBroadcastsProcessed(self):
|
def updateNumberOfBroadcastsProcessed(self):
|
||||||
"""Update the counter for the number of processed broadcasts"""
|
"""Update the counter for the number of processed broadcasts"""
|
||||||
|
@ -119,7 +119,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
|
||||||
"Processed %n broadcast message(s).",
|
"Processed %n broadcast message(s).",
|
||||||
None,
|
None,
|
||||||
QtCore.QCoreApplication.CodecForTr,
|
QtCore.QCoreApplication.CodecForTr,
|
||||||
shared.numberOfBroadcastsProcessed))
|
state.numberOfBroadcastsProcessed))
|
||||||
|
|
||||||
def updateNumberOfPubkeysProcessed(self):
|
def updateNumberOfPubkeysProcessed(self):
|
||||||
"""Update the counter for the number of processed pubkeys"""
|
"""Update the counter for the number of processed pubkeys"""
|
||||||
|
@ -130,7 +130,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
|
||||||
"Processed %n public key(s).",
|
"Processed %n public key(s).",
|
||||||
None,
|
None,
|
||||||
QtCore.QCoreApplication.CodecForTr,
|
QtCore.QCoreApplication.CodecForTr,
|
||||||
shared.numberOfPubkeysProcessed))
|
state.numberOfPubkeysProcessed))
|
||||||
|
|
||||||
def updateNumberOfBytes(self):
|
def updateNumberOfBytes(self):
|
||||||
"""
|
"""
|
||||||
|
@ -225,9 +225,9 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
|
||||||
# FYI: The 'singlelistener' thread sets the icon color to green when it
|
# FYI: The 'singlelistener' thread sets the icon color to green when it
|
||||||
# receives an incoming connection, meaning that the user's firewall is
|
# receives an incoming connection, meaning that the user's firewall is
|
||||||
# configured correctly.
|
# configured correctly.
|
||||||
if self.tableWidgetConnectionCount.rowCount() and shared.statusIconColor == 'red':
|
if self.tableWidgetConnectionCount.rowCount() and state.statusIconColor == 'red':
|
||||||
self.window().setStatusIcon('yellow')
|
self.window().setStatusIcon('yellow')
|
||||||
elif self.tableWidgetConnectionCount.rowCount() == 0 and shared.statusIconColor != "red":
|
elif self.tableWidgetConnectionCount.rowCount() == 0 and state.statusIconColor != "red":
|
||||||
self.window().setStatusIcon('red')
|
self.window().setStatusIcon('red')
|
||||||
|
|
||||||
# timer driven
|
# timer driven
|
||||||
|
|
|
@ -11,7 +11,6 @@ import namecoin
|
||||||
import openclpow
|
import openclpow
|
||||||
import paths
|
import paths
|
||||||
import queues
|
import queues
|
||||||
import shared
|
|
||||||
import state
|
import state
|
||||||
import tempfile
|
import tempfile
|
||||||
import widgets
|
import widgets
|
||||||
|
@ -338,7 +337,7 @@ class SettingsDialog(QtGui.QDialog):
|
||||||
|
|
||||||
proxytype_index = self.comboBoxProxyType.currentIndex()
|
proxytype_index = self.comboBoxProxyType.currentIndex()
|
||||||
if proxytype_index == 0:
|
if proxytype_index == 0:
|
||||||
if self._proxy_type and shared.statusIconColor != 'red':
|
if self._proxy_type and state.statusIconColor != 'red':
|
||||||
self.net_restart_needed = True
|
self.net_restart_needed = True
|
||||||
elif self.comboBoxProxyType.currentText() != self._proxy_type:
|
elif self.comboBoxProxyType.currentText() != self._proxy_type:
|
||||||
self.net_restart_needed = True
|
self.net_restart_needed = True
|
||||||
|
@ -482,7 +481,7 @@ class SettingsDialog(QtGui.QDialog):
|
||||||
# default behavior. The input is blank/blank
|
# default behavior. The input is blank/blank
|
||||||
self.config.set('bitmessagesettings', 'stopresendingafterxdays', '')
|
self.config.set('bitmessagesettings', 'stopresendingafterxdays', '')
|
||||||
self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
|
self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
|
||||||
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf')
|
state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
|
||||||
stopResendingDefaults = True
|
stopResendingDefaults = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -497,9 +496,9 @@ class SettingsDialog(QtGui.QDialog):
|
||||||
months = 0.0
|
months = 0.0
|
||||||
|
|
||||||
if days >= 0 and months >= 0 and not stopResendingDefaults:
|
if days >= 0 and months >= 0 and not stopResendingDefaults:
|
||||||
shared.maximumLengthOfTimeToBotherResendingMessages = \
|
state.maximumLengthOfTimeToBotherResendingMessages = \
|
||||||
days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12
|
days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12
|
||||||
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000:
|
if state.maximumLengthOfTimeToBotherResendingMessages < 432000:
|
||||||
# If the time period is less than 5 hours, we give
|
# If the time period is less than 5 hours, we give
|
||||||
# zero values to all fields. No message will be sent again.
|
# zero values to all fields. No message will be sent again.
|
||||||
QtGui.QMessageBox.about(
|
QtGui.QMessageBox.about(
|
||||||
|
@ -516,7 +515,7 @@ class SettingsDialog(QtGui.QDialog):
|
||||||
'bitmessagesettings', 'stopresendingafterxdays', '0')
|
'bitmessagesettings', 'stopresendingafterxdays', '0')
|
||||||
self.config.set(
|
self.config.set(
|
||||||
'bitmessagesettings', 'stopresendingafterxmonths', '0')
|
'bitmessagesettings', 'stopresendingafterxmonths', '0')
|
||||||
shared.maximumLengthOfTimeToBotherResendingMessages = 0.0
|
state.maximumLengthOfTimeToBotherResendingMessages = 0.0
|
||||||
else:
|
else:
|
||||||
self.config.set(
|
self.config.set(
|
||||||
'bitmessagesettings', 'stopresendingafterxdays', str(days))
|
'bitmessagesettings', 'stopresendingafterxdays', str(days))
|
||||||
|
|
|
@ -140,9 +140,9 @@ class objectProcessor(threading.Thread):
|
||||||
# bypass nonce and time, retain object type/version/stream + body
|
# bypass nonce and time, retain object type/version/stream + body
|
||||||
readPosition = 16
|
readPosition = 16
|
||||||
|
|
||||||
if data[readPosition:] in shared.ackdataForWhichImWatching:
|
if data[readPosition:] in state.ackdataForWhichImWatching:
|
||||||
logger.info('This object is an acknowledgement bound for me.')
|
logger.info('This object is an acknowledgement bound for me.')
|
||||||
del shared.ackdataForWhichImWatching[data[readPosition:]]
|
del state.ackdataForWhichImWatching[data[readPosition:]]
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'UPDATE sent SET status=?, lastactiontime=?'
|
'UPDATE sent SET status=?, lastactiontime=?'
|
||||||
' WHERE ackdata=?',
|
' WHERE ackdata=?',
|
||||||
|
@ -286,7 +286,7 @@ class objectProcessor(threading.Thread):
|
||||||
def processpubkey(self, data):
|
def processpubkey(self, data):
|
||||||
"""Process a pubkey object"""
|
"""Process a pubkey object"""
|
||||||
pubkeyProcessingStartTime = time.time()
|
pubkeyProcessingStartTime = time.time()
|
||||||
shared.numberOfPubkeysProcessed += 1
|
state.numberOfPubkeysProcessed += 1
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateNumberOfPubkeysProcessed', 'no data'))
|
'updateNumberOfPubkeysProcessed', 'no data'))
|
||||||
readPosition = 20 # bypass the nonce, time, and object type
|
readPosition = 20 # bypass the nonce, time, and object type
|
||||||
|
@ -459,7 +459,7 @@ class objectProcessor(threading.Thread):
|
||||||
def processmsg(self, data):
|
def processmsg(self, data):
|
||||||
"""Process a message object"""
|
"""Process a message object"""
|
||||||
messageProcessingStartTime = time.time()
|
messageProcessingStartTime = time.time()
|
||||||
shared.numberOfMessagesProcessed += 1
|
state.numberOfMessagesProcessed += 1
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateNumberOfMessagesProcessed', 'no data'))
|
'updateNumberOfMessagesProcessed', 'no data'))
|
||||||
readPosition = 20 # bypass the nonce, time, and object type
|
readPosition = 20 # bypass the nonce, time, and object type
|
||||||
|
@ -808,7 +808,7 @@ class objectProcessor(threading.Thread):
|
||||||
def processbroadcast(self, data):
|
def processbroadcast(self, data):
|
||||||
"""Process a broadcast object"""
|
"""Process a broadcast object"""
|
||||||
messageProcessingStartTime = time.time()
|
messageProcessingStartTime = time.time()
|
||||||
shared.numberOfBroadcastsProcessed += 1
|
state.numberOfBroadcastsProcessed += 1
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateNumberOfBroadcastsProcessed', 'no data'))
|
'updateNumberOfBroadcastsProcessed', 'no data'))
|
||||||
inventoryHash = calculateInventoryHash(data)
|
inventoryHash = calculateInventoryHash(data)
|
||||||
|
|
|
@ -25,7 +25,6 @@ import time
|
||||||
|
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import queues
|
import queues
|
||||||
import shared
|
|
||||||
import state
|
import state
|
||||||
import tr
|
import tr
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
@ -34,6 +33,13 @@ from inventory import Inventory
|
||||||
from network import BMConnectionPool, StoppableThread
|
from network import BMConnectionPool, StoppableThread
|
||||||
|
|
||||||
|
|
||||||
|
#: Equals 4 weeks. You could make this longer if you want
|
||||||
|
#: but making it shorter would not be advisable because
|
||||||
|
#: there is a very small possibility that it could keep you
|
||||||
|
#: from obtaining a needed pubkey for a period of time.
|
||||||
|
lengthOfTimeToHoldOnToAllPubkeys = 2419200
|
||||||
|
|
||||||
|
|
||||||
class singleCleaner(StoppableThread):
|
class singleCleaner(StoppableThread):
|
||||||
"""The singleCleaner thread class"""
|
"""The singleCleaner thread class"""
|
||||||
name = "singleCleaner"
|
name = "singleCleaner"
|
||||||
|
@ -44,7 +50,7 @@ class singleCleaner(StoppableThread):
|
||||||
gc.disable()
|
gc.disable()
|
||||||
timeWeLastClearedInventoryAndPubkeysTables = 0
|
timeWeLastClearedInventoryAndPubkeysTables = 0
|
||||||
try:
|
try:
|
||||||
shared.maximumLengthOfTimeToBotherResendingMessages = (
|
state.maximumLengthOfTimeToBotherResendingMessages = (
|
||||||
float(BMConfigParser().get(
|
float(BMConfigParser().get(
|
||||||
'bitmessagesettings', 'stopresendingafterxdays'))
|
'bitmessagesettings', 'stopresendingafterxdays'))
|
||||||
* 24 * 60 * 60
|
* 24 * 60 * 60
|
||||||
|
@ -56,7 +62,7 @@ class singleCleaner(StoppableThread):
|
||||||
# Either the user hasn't set stopresendingafterxdays and
|
# Either the user hasn't set stopresendingafterxdays and
|
||||||
# stopresendingafterxmonths yet or the options are missing
|
# stopresendingafterxmonths yet or the options are missing
|
||||||
# from the config file.
|
# from the config file.
|
||||||
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf')
|
state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
|
||||||
|
|
||||||
# initial wait
|
# initial wait
|
||||||
if state.shutdown == 0:
|
if state.shutdown == 0:
|
||||||
|
@ -74,7 +80,7 @@ class singleCleaner(StoppableThread):
|
||||||
# queue which will never be handled by a UI. We should clear it to
|
# queue which will never be handled by a UI. We should clear it to
|
||||||
# save memory.
|
# save memory.
|
||||||
# FIXME redundant?
|
# FIXME redundant?
|
||||||
if shared.thisapp.daemon or not state.enableGUI:
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
queues.UISignalQueue.queue.clear()
|
queues.UISignalQueue.queue.clear()
|
||||||
if timeWeLastClearedInventoryAndPubkeysTables < \
|
if timeWeLastClearedInventoryAndPubkeysTables < \
|
||||||
int(time.time()) - 7380:
|
int(time.time()) - 7380:
|
||||||
|
@ -84,7 +90,7 @@ class singleCleaner(StoppableThread):
|
||||||
# pubkeys
|
# pubkeys
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
"DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'",
|
"DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'",
|
||||||
int(time.time()) - shared.lengthOfTimeToHoldOnToAllPubkeys)
|
int(time.time()) - lengthOfTimeToHoldOnToAllPubkeys)
|
||||||
|
|
||||||
# Let us resend getpubkey objects if we have not yet heard
|
# Let us resend getpubkey objects if we have not yet heard
|
||||||
# a pubkey, and also msg objects if we have not yet heard
|
# a pubkey, and also msg objects if we have not yet heard
|
||||||
|
@ -94,7 +100,7 @@ class singleCleaner(StoppableThread):
|
||||||
" WHERE ((status='awaitingpubkey' OR status='msgsent')"
|
" WHERE ((status='awaitingpubkey' OR status='msgsent')"
|
||||||
" AND folder='sent' AND sleeptill<? AND senttime>?)",
|
" AND folder='sent' AND sleeptill<? AND senttime>?)",
|
||||||
int(time.time()), int(time.time())
|
int(time.time()), int(time.time())
|
||||||
- shared.maximumLengthOfTimeToBotherResendingMessages
|
- state.maximumLengthOfTimeToBotherResendingMessages
|
||||||
)
|
)
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
if len(row) < 2:
|
if len(row) < 2:
|
||||||
|
@ -131,7 +137,8 @@ class singleCleaner(StoppableThread):
|
||||||
' is full. Bitmessage will now exit.'),
|
' is full. Bitmessage will now exit.'),
|
||||||
True)
|
True)
|
||||||
))
|
))
|
||||||
if shared.thisapp.daemon or not state.enableGUI:
|
# FIXME redundant?
|
||||||
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
# inv/object tracking
|
# inv/object tracking
|
||||||
|
|
|
@ -94,25 +94,25 @@ class singleWorker(StoppableThread):
|
||||||
hexlify(privEncryptionKey))
|
hexlify(privEncryptionKey))
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialize the shared.ackdataForWhichImWatching data structure
|
# Initialize the state.ackdataForWhichImWatching data structure
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
|
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
ackdata, = row
|
ackdata, = row
|
||||||
self.logger.info('Watching for ackdata %s', hexlify(ackdata))
|
self.logger.info('Watching for ackdata %s', hexlify(ackdata))
|
||||||
shared.ackdataForWhichImWatching[ackdata] = 0
|
state.ackdataForWhichImWatching[ackdata] = 0
|
||||||
|
|
||||||
# Fix legacy (headerless) watched ackdata to include header
|
# Fix legacy (headerless) watched ackdata to include header
|
||||||
for oldack in shared.ackdataForWhichImWatching:
|
for oldack in state.ackdataForWhichImWatching:
|
||||||
if len(oldack) == 32:
|
if len(oldack) == 32:
|
||||||
# attach legacy header, always constant (msg/1/1)
|
# attach legacy header, always constant (msg/1/1)
|
||||||
newack = '\x00\x00\x00\x02\x01\x01' + oldack
|
newack = '\x00\x00\x00\x02\x01\x01' + oldack
|
||||||
shared.ackdataForWhichImWatching[newack] = 0
|
state.ackdataForWhichImWatching[newack] = 0
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'UPDATE sent SET ackdata=? WHERE ackdata=?',
|
'UPDATE sent SET ackdata=? WHERE ackdata=?',
|
||||||
newack, oldack
|
newack, oldack
|
||||||
)
|
)
|
||||||
del shared.ackdataForWhichImWatching[oldack]
|
del state.ackdataForWhichImWatching[oldack]
|
||||||
|
|
||||||
# give some time for the GUI to start
|
# give some time for the GUI to start
|
||||||
# before we start on existing POW tasks.
|
# before we start on existing POW tasks.
|
||||||
|
@ -864,7 +864,7 @@ class singleWorker(StoppableThread):
|
||||||
|
|
||||||
# if we aren't sending this to ourselves or a chan
|
# if we aren't sending this to ourselves or a chan
|
||||||
if not BMConfigParser().has_section(toaddress):
|
if not BMConfigParser().has_section(toaddress):
|
||||||
shared.ackdataForWhichImWatching[ackdata] = 0
|
state.ackdataForWhichImWatching[ackdata] = 0
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata,
|
||||||
|
|
|
@ -14,7 +14,6 @@ import connectionpool
|
||||||
import helper_random
|
import helper_random
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import protocol
|
import protocol
|
||||||
import shared
|
|
||||||
import state
|
import state
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from helper_random import randomBytes
|
from helper_random import randomBytes
|
||||||
|
@ -34,6 +33,9 @@ from queues import invQueue, receiveDataQueue, UISignalQueue
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
|
||||||
|
maximumAgeOfNodesThatIAdvertiseToOthers = 10800 #: Equals three hours
|
||||||
|
|
||||||
|
|
||||||
class TCPConnection(BMProto, TLSDispatcher):
|
class TCPConnection(BMProto, TLSDispatcher):
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
"""
|
"""
|
||||||
|
@ -136,7 +138,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
def set_connection_fully_established(self):
|
def set_connection_fully_established(self):
|
||||||
"""Initiate inventory synchronisation."""
|
"""Initiate inventory synchronisation."""
|
||||||
if not self.isOutbound and not self.local:
|
if not self.isOutbound and not self.local:
|
||||||
shared.clientHasReceivedIncomingConnections = True
|
state.clientHasReceivedIncomingConnections = True
|
||||||
UISignalQueue.put(('setStatusIcon', 'green'))
|
UISignalQueue.put(('setStatusIcon', 'green'))
|
||||||
UISignalQueue.put(
|
UISignalQueue.put(
|
||||||
('updateNetworkStatusTab', (
|
('updateNetworkStatusTab', (
|
||||||
|
@ -170,7 +172,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
filtered = [
|
filtered = [
|
||||||
(k, v) for k, v in nodes.iteritems()
|
(k, v) for k, v in nodes.iteritems()
|
||||||
if v["lastseen"] > int(time.time()) -
|
if v["lastseen"] > int(time.time()) -
|
||||||
shared.maximumAgeOfNodesThatIAdvertiseToOthers and
|
maximumAgeOfNodesThatIAdvertiseToOthers and
|
||||||
v["rating"] >= 0 and len(k.host) <= 22
|
v["rating"] >= 0 and len(k.host) <= 22
|
||||||
]
|
]
|
||||||
# sent 250 only if the remote isn't interested in it
|
# sent 250 only if the remote isn't interested in it
|
||||||
|
|
|
@ -13,7 +13,6 @@ import os
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
||||||
# Project imports.
|
# Project imports.
|
||||||
|
@ -27,19 +26,6 @@ from helper_sql import sqlQuery
|
||||||
from pyelliptic import arithmetic
|
from pyelliptic import arithmetic
|
||||||
|
|
||||||
|
|
||||||
verbose = 1
|
|
||||||
# This is obsolete with the change to protocol v3
|
|
||||||
# but the singleCleaner thread still hasn't been updated
|
|
||||||
# so we need this a little longer.
|
|
||||||
maximumAgeOfAnObjectThatIAmWillingToAccept = 216000
|
|
||||||
# Equals 4 weeks. You could make this longer if you want
|
|
||||||
# but making it shorter would not be advisable because
|
|
||||||
# there is a very small possibility that it could keep you
|
|
||||||
# from obtaining a needed pubkey for a period of time.
|
|
||||||
lengthOfTimeToHoldOnToAllPubkeys = 2419200
|
|
||||||
maximumAgeOfNodesThatIAdvertiseToOthers = 10800 # Equals three hours
|
|
||||||
|
|
||||||
|
|
||||||
myECCryptorObjects = {}
|
myECCryptorObjects = {}
|
||||||
MyECSubscriptionCryptorObjects = {}
|
MyECSubscriptionCryptorObjects = {}
|
||||||
# The key in this dictionary is the RIPE hash which is encoded
|
# The key in this dictionary is the RIPE hash which is encoded
|
||||||
|
@ -48,19 +34,6 @@ myAddressesByHash = {}
|
||||||
# The key in this dictionary is the tag generated from the address.
|
# The key in this dictionary is the tag generated from the address.
|
||||||
myAddressesByTag = {}
|
myAddressesByTag = {}
|
||||||
broadcastSendersForWhichImWatching = {}
|
broadcastSendersForWhichImWatching = {}
|
||||||
printLock = threading.Lock()
|
|
||||||
statusIconColor = 'red'
|
|
||||||
|
|
||||||
thisapp = None # singleton lock instance
|
|
||||||
|
|
||||||
ackdataForWhichImWatching = {}
|
|
||||||
# used by API command clientStatus
|
|
||||||
clientHasReceivedIncomingConnections = False
|
|
||||||
numberOfMessagesProcessed = 0
|
|
||||||
numberOfBroadcastsProcessed = 0
|
|
||||||
numberOfPubkeysProcessed = 0
|
|
||||||
|
|
||||||
maximumLengthOfTimeToBotherResendingMessages = 0
|
|
||||||
|
|
||||||
|
|
||||||
def isAddressInMyAddressBook(address):
|
def isAddressInMyAddressBook(address):
|
||||||
|
|
|
@ -4,7 +4,6 @@ import Queue
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import shared
|
|
||||||
import state
|
import state
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from helper_sql import sqlQuery, sqlStoredProcedure
|
from helper_sql import sqlQuery, sqlStoredProcedure
|
||||||
|
@ -80,9 +79,9 @@ def doCleanShutdown():
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
if shared.thisapp.daemon or not state.enableGUI: # ..fixme:: redundant?
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
logger.info('Clean shutdown complete.')
|
logger.info('Clean shutdown complete.')
|
||||||
shared.thisapp.cleanup()
|
state.thisapp.cleanup()
|
||||||
os._exit(0) # pylint: disable=protected-access
|
os._exit(0) # pylint: disable=protected-access
|
||||||
else:
|
else:
|
||||||
logger.info('Core shutdown complete.')
|
logger.info('Core shutdown complete.')
|
||||||
|
|
20
src/state.py
20
src/state.py
|
@ -39,6 +39,8 @@ sqlReady = False
|
||||||
|
|
||||||
maximumNumberOfHalfOpenConnections = 0
|
maximumNumberOfHalfOpenConnections = 0
|
||||||
|
|
||||||
|
maximumLengthOfTimeToBotherResendingMessages = 0
|
||||||
|
|
||||||
invThread = None
|
invThread = None
|
||||||
addrThread = None
|
addrThread = None
|
||||||
downloadThread = None
|
downloadThread = None
|
||||||
|
@ -55,3 +57,21 @@ testmode = False
|
||||||
kivy = False
|
kivy = False
|
||||||
|
|
||||||
association = ''
|
association = ''
|
||||||
|
|
||||||
|
clientHasReceivedIncomingConnections = False
|
||||||
|
"""used by API command clientStatus"""
|
||||||
|
|
||||||
|
numberOfMessagesProcessed = 0
|
||||||
|
numberOfBroadcastsProcessed = 0
|
||||||
|
numberOfPubkeysProcessed = 0
|
||||||
|
|
||||||
|
statusIconColor = 'red'
|
||||||
|
"""
|
||||||
|
GUI status icon color
|
||||||
|
.. note:: bad style, refactor it
|
||||||
|
"""
|
||||||
|
|
||||||
|
ackdataForWhichImWatching = {}
|
||||||
|
|
||||||
|
thisapp = None
|
||||||
|
"""Singleton instance"""
|
||||||
|
|
|
@ -40,7 +40,9 @@ else:
|
||||||
threading.Thread._Thread__bootstrap = _thread_name_hack
|
threading.Thread._Thread__bootstrap = _thread_name_hack
|
||||||
|
|
||||||
|
|
||||||
|
printLock = threading.Lock()
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"addressGenerator", "objectProcessor", "singleCleaner", "singleWorker",
|
"addressGenerator", "objectProcessor", "singleCleaner", "singleWorker",
|
||||||
"sqlThread"
|
"sqlThread", "printLock"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user