Reduce cyclic dependencies
- rearranged code to reduce cyclic dependencies - doCleanShutdown is separated in shutdown.py - shared queues are separated in queues.py - some default values were moved to defaults.py - knownnodes partially moved to knownnodes.py
This commit is contained in:
parent
7da36eccbd
commit
59f3a2fbe7
67
src/api.py
67
src/api.py
|
@ -27,6 +27,7 @@ import hashlib
|
|||
import protocol
|
||||
import state
|
||||
from pyelliptic.openssl import OpenSSL
|
||||
import queues
|
||||
from struct import pack
|
||||
|
||||
# Classes
|
||||
|
@ -217,9 +218,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
raise APIError(16, 'You already have this address in your address book.')
|
||||
|
||||
sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address)
|
||||
shared.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
shared.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
shared.UISignalQueue.put(('rerenderAddressBook',''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
queues.UISignalQueue.put(('rerenderAddressBook',''))
|
||||
return "Added address %s to address book" % address
|
||||
|
||||
def HandleDeleteAddressBookEntry(self, params):
|
||||
|
@ -229,9 +230,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
address = addBMIfNotPresent(address)
|
||||
self._verifyAddress(address)
|
||||
sqlExecute('DELETE FROM addressbook WHERE address=?', address)
|
||||
shared.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
shared.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
shared.UISignalQueue.put(('rerenderAddressBook',''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
queues.UISignalQueue.put(('rerenderAddressBook',''))
|
||||
return "Deleted address book entry for %s if it existed" % address
|
||||
|
||||
def HandleCreateRandomAddress(self, params):
|
||||
|
@ -269,11 +270,11 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
unicode(label, 'utf-8')
|
||||
except:
|
||||
raise APIError(17, 'Label is not valid UTF-8 data.')
|
||||
shared.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
streamNumberForAddress = 1
|
||||
shared.addressGeneratorQueue.put((
|
||||
queues.addressGeneratorQueue.put((
|
||||
'createRandomAddress', 4, streamNumberForAddress, label, 1, "", eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes))
|
||||
return shared.apiAddressGeneratorReturnQueue.get()
|
||||
return queues.apiAddressGeneratorReturnQueue.get()
|
||||
|
||||
def HandleCreateDeterministicAddresses(self, params):
|
||||
if len(params) == 0:
|
||||
|
@ -349,13 +350,13 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
raise APIError(4, 'Why would you ask me to generate 0 addresses for you?')
|
||||
if numberOfAddresses > 999:
|
||||
raise APIError(5, 'You have (accidentally?) specified too many addresses to make. Maximum 999. This check only exists to prevent mischief; if you really want to create more addresses than this, contact the Bitmessage developers and we can modify the check or you can do it yourself by searching the source code for this message.')
|
||||
shared.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
logger.debug('Requesting that the addressGenerator create %s addresses.', numberOfAddresses)
|
||||
shared.addressGeneratorQueue.put(
|
||||
queues.addressGeneratorQueue.put(
|
||||
('createDeterministicAddresses', addressVersionNumber, streamNumber,
|
||||
'unused API address', numberOfAddresses, passphrase, eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes))
|
||||
data = '{"addresses":['
|
||||
queueReturn = shared.apiAddressGeneratorReturnQueue.get()
|
||||
queueReturn = queues.apiAddressGeneratorReturnQueue.get()
|
||||
for item in queueReturn:
|
||||
if len(data) > 20:
|
||||
data += ','
|
||||
|
@ -376,12 +377,12 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
raise APIError(2, 'The address version number currently must be 3 or 4. ' + addressVersionNumber + ' isn\'t supported.')
|
||||
if streamNumber != 1:
|
||||
raise APIError(3, ' The stream number must be 1. Others aren\'t supported.')
|
||||
shared.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
logger.debug('Requesting that the addressGenerator create %s addresses.', numberOfAddresses)
|
||||
shared.addressGeneratorQueue.put(
|
||||
queues.addressGeneratorQueue.put(
|
||||
('getDeterministicAddress', addressVersionNumber,
|
||||
streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe))
|
||||
return shared.apiAddressGeneratorReturnQueue.get()
|
||||
return queues.apiAddressGeneratorReturnQueue.get()
|
||||
|
||||
def HandleCreateChan(self, params):
|
||||
if len(params) == 0:
|
||||
|
@ -401,10 +402,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
|
||||
addressVersionNumber = 4
|
||||
streamNumber = 1
|
||||
shared.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
logger.debug('Requesting that the addressGenerator create chan %s.', passphrase)
|
||||
shared.addressGeneratorQueue.put(('createChan', addressVersionNumber, streamNumber, label, passphrase, True))
|
||||
queueReturn = shared.apiAddressGeneratorReturnQueue.get()
|
||||
queues.addressGeneratorQueue.put(('createChan', addressVersionNumber, streamNumber, label, passphrase, True))
|
||||
queueReturn = queues.apiAddressGeneratorReturnQueue.get()
|
||||
if len(queueReturn) == 0:
|
||||
raise APIError(24, 'Chan address is already present.')
|
||||
address = queueReturn[0]
|
||||
|
@ -428,9 +429,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
|
||||
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(suppliedAddress)
|
||||
suppliedAddress = addBMIfNotPresent(suppliedAddress)
|
||||
shared.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
shared.addressGeneratorQueue.put(('joinChan', suppliedAddress, label, passphrase, True))
|
||||
addressGeneratorReturnValue = shared.apiAddressGeneratorReturnQueue.get()
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
queues.addressGeneratorQueue.put(('joinChan', suppliedAddress, label, passphrase, True))
|
||||
addressGeneratorReturnValue = queues.apiAddressGeneratorReturnQueue.get()
|
||||
|
||||
if addressGeneratorReturnValue[0] == 'chan name does not match address':
|
||||
raise APIError(18, 'Chan name does not match address.')
|
||||
|
@ -468,8 +469,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
BMConfigParser().remove_section(address)
|
||||
with open(state.appdata + 'keys.dat', 'wb') as configfile:
|
||||
BMConfigParser().write(configfile)
|
||||
shared.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
shared.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
shared.reloadMyAddressHashes()
|
||||
return 'success'
|
||||
|
||||
|
@ -514,7 +515,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
# UPDATE is slow, only update if status is different
|
||||
if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus:
|
||||
sqlExecute('''UPDATE inbox set read = ? WHERE msgid=?''', readStatus, msgid)
|
||||
shared.UISignalQueue.put(('changedInboxUnread', None))
|
||||
queues.UISignalQueue.put(('changedInboxUnread', None))
|
||||
queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox WHERE msgid=?''', msgid)
|
||||
data = '{"inboxMessage":['
|
||||
for row in queryreturn:
|
||||
|
@ -695,10 +696,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
for row in queryreturn:
|
||||
toLabel, = row
|
||||
# apiSignalQueue.put(('displayNewSentMessage',(toAddress,toLabel,fromAddress,subject,message,ackdata)))
|
||||
shared.UISignalQueue.put(('displayNewSentMessage', (
|
||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
||||
|
||||
shared.workerQueue.put(('sendmessage', toAddress))
|
||||
queues.workerQueue.put(('sendmessage', toAddress))
|
||||
|
||||
return hexlify(ackdata)
|
||||
|
||||
|
@ -753,9 +754,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
helper_sent.insert(t)
|
||||
|
||||
toLabel = '[Broadcast subscribers]'
|
||||
shared.UISignalQueue.put(('displayNewSentMessage', (
|
||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
||||
shared.workerQueue.put(('sendbroadcast', ''))
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
return hexlify(ackdata)
|
||||
|
||||
|
@ -799,8 +800,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
raise APIError(16, 'You are already subscribed to that address.')
|
||||
sqlExecute('''INSERT INTO subscriptions VALUES (?,?,?)''',label, address, True)
|
||||
shared.reloadBroadcastSendersForWhichImWatching()
|
||||
shared.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||
shared.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||
queues.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||
return 'Added subscription.'
|
||||
|
||||
def HandleDeleteSubscription(self, params):
|
||||
|
@ -810,8 +811,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
address = addBMIfNotPresent(address)
|
||||
sqlExecute('''DELETE FROM subscriptions WHERE address=?''', address)
|
||||
shared.reloadBroadcastSendersForWhichImWatching()
|
||||
shared.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||
shared.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||
queues.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||
return 'Deleted subscription if it existed.'
|
||||
|
||||
def ListSubscriptions(self, params):
|
||||
|
@ -972,7 +973,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
|
||||
def HandleStatusBar(self, params):
|
||||
message, = params
|
||||
shared.UISignalQueue.put(('updateStatusBar', message))
|
||||
queues.UISignalQueue.put(('updateStatusBar', message))
|
||||
|
||||
def HandleDeleteAndVacuum(self, params):
|
||||
sqlStoredProcedure('deleteandvacuume')
|
||||
|
|
|
@ -21,13 +21,15 @@ import dialog
|
|||
from dialog import Dialog
|
||||
from helper_sql import *
|
||||
|
||||
import shared
|
||||
from addresses import *
|
||||
import ConfigParser
|
||||
from configparser import BMConfigParser
|
||||
from addresses import *
|
||||
from pyelliptic.openssl import OpenSSL
|
||||
import l10n
|
||||
from inventory import Inventory
|
||||
import l10n
|
||||
from pyelliptic.openssl import OpenSSL
|
||||
import queues
|
||||
import shared
|
||||
import shutdown
|
||||
|
||||
quit = False
|
||||
menutab = 1
|
||||
|
@ -446,7 +448,7 @@ def handlech(c, stdscr):
|
|||
choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
|
||||
if r == d.DIALOG_OK and "1" in t:
|
||||
shorten = True
|
||||
shared.addressGeneratorQueue.put(("createRandomAddress", 4, stream, label, 1, "", shorten))
|
||||
queues.addressGeneratorQueue.put(("createRandomAddress", 4, stream, label, 1, "", shorten))
|
||||
elif t == "2":
|
||||
set_background_title(d, "Make deterministic addresses")
|
||||
r, t = d.passwordform("Enter passphrase",
|
||||
|
@ -469,7 +471,7 @@ def handlech(c, stdscr):
|
|||
scrollbox(d, unicode("In addition to your passphrase, be sure to remember the following numbers:\n"
|
||||
"\n * Address version number: "+str(4)+"\n"
|
||||
" * Stream number: "+str(stream)))
|
||||
shared.addressGeneratorQueue.put(('createDeterministicAddresses', 4, stream, "unused deterministic address", number, str(passphrase), shorten))
|
||||
queues.addressGeneratorQueue.put(('createDeterministicAddresses', 4, stream, "unused deterministic address", number, str(passphrase), shorten))
|
||||
else:
|
||||
scrollbox(d, unicode("Passphrases do not match"))
|
||||
elif t == "2": # Send a message
|
||||
|
@ -795,7 +797,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
"sent",
|
||||
2, # encodingType
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
shared.workerQueue.put(("sendmessage", addr))
|
||||
queues.workerQueue.put(("sendmessage", addr))
|
||||
else: # Broadcast
|
||||
if recv == "":
|
||||
set_background_title(d, "Empty sender error")
|
||||
|
@ -821,7 +823,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
"sent", # folder
|
||||
2, # encodingType
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
shared.workerQueue.put(('sendbroadcast', ''))
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
def loadInbox():
|
||||
sys.stdout = sys.__stdout__
|
||||
|
@ -1052,7 +1054,7 @@ def shutdown():
|
|||
sys.stdout = sys.__stdout__
|
||||
print("Shutting down...")
|
||||
sys.stdout = printlog
|
||||
shared.doCleanShutdown()
|
||||
shutdown.doCleanShutdown()
|
||||
sys.stdout = sys.__stdout__
|
||||
sys.stderr = sys.__stderr__
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import shared
|
|||
from helper_sql import sqlQuery
|
||||
import state
|
||||
import protocol
|
||||
import shutdown
|
||||
import threading
|
||||
|
||||
# Classes
|
||||
|
@ -287,7 +288,7 @@ class Main:
|
|||
def stop(self):
|
||||
with shared.printLock:
|
||||
print('Stopping Bitmessage Deamon.')
|
||||
shared.doCleanShutdown()
|
||||
shutdown.doCleanShutdown()
|
||||
|
||||
|
||||
#TODO: nice function but no one is using this
|
||||
|
|
|
@ -73,14 +73,18 @@ import types
|
|||
from utils import *
|
||||
from collections import OrderedDict
|
||||
from account import *
|
||||
from dialogs import AddAddressDialog
|
||||
from class_objectHashHolder import objectHashHolder
|
||||
from class_singleWorker import singleWorker
|
||||
import defaults
|
||||
from dialogs import AddAddressDialog
|
||||
from helper_generic import powQueueSize
|
||||
from inventory import PendingDownload, PendingUpload, PendingUploadDeadlineException
|
||||
import knownnodes
|
||||
import paths
|
||||
from proofofwork import getPowType
|
||||
import protocol
|
||||
import queues
|
||||
import shutdown
|
||||
import state
|
||||
from statusbar import BMStatusBar
|
||||
import throttle
|
||||
|
@ -1587,7 +1591,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
QMessageBox.about(self, _translate("MainWindow", "Bad address version number"), _translate(
|
||||
"MainWindow", "Your address version number must be either 3 or 4."))
|
||||
return
|
||||
shared.addressGeneratorQueue.put(('createDeterministicAddresses', addressVersionNumber, streamNumberForAddress, "regenerated deterministic address", self.regenerateAddressesDialogInstance.ui.spinBoxNumberOfAddressesToMake.value(
|
||||
queues.addressGeneratorQueue.put(('createDeterministicAddresses', addressVersionNumber, streamNumberForAddress, "regenerated deterministic address", self.regenerateAddressesDialogInstance.ui.spinBoxNumberOfAddressesToMake.value(
|
||||
), self.regenerateAddressesDialogInstance.ui.lineEditPassphrase.text().toUtf8(), self.regenerateAddressesDialogInstance.ui.checkBoxEighteenByteRipe.isChecked()))
|
||||
self.ui.tabWidget.setCurrentIndex(3)
|
||||
|
||||
|
@ -2042,7 +2046,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
|
||||
self.displayNewSentMessage(
|
||||
toAddress, toLabel, fromAddress, subject, message, ackdata)
|
||||
shared.workerQueue.put(('sendmessage', toAddress))
|
||||
queues.workerQueue.put(('sendmessage', toAddress))
|
||||
|
||||
self.ui.comboBoxSendFrom.setCurrentIndex(0)
|
||||
self.ui.lineEditTo.setText('')
|
||||
|
@ -2093,7 +2097,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.displayNewSentMessage(
|
||||
toAddress, toLabel, fromAddress, subject, message, ackdata)
|
||||
|
||||
shared.workerQueue.put(('sendbroadcast', ''))
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
self.ui.comboBoxSendFromBroadcast.setCurrentIndex(0)
|
||||
self.ui.lineEditSubjectBroadcast.setText('')
|
||||
|
@ -2304,7 +2308,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
addressVersion) + encodeVarint(streamNumber) + ripe).digest()).digest()
|
||||
tag = doubleHashOfAddressData[32:]
|
||||
for value in shared.inventory.by_type_and_tag(3, tag):
|
||||
shared.objectProcessorQueue.put((value.type, value.payload))
|
||||
queues.objectProcessorQueue.put((value.type, value.payload))
|
||||
|
||||
def click_pushButtonStatusIcon(self):
|
||||
logger.debug('click_pushButtonStatusIcon')
|
||||
|
@ -2443,7 +2447,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# mark them as toodifficult if the receiver's required difficulty is still higher than
|
||||
# we are willing to do.
|
||||
sqlExecute('''UPDATE sent SET status='msgqueued' WHERE status='toodifficult' ''')
|
||||
shared.workerQueue.put(('sendmessage', ''))
|
||||
queues.workerQueue.put(('sendmessage', ''))
|
||||
|
||||
#start:UI setting to stop trying to send messages after X days/months
|
||||
# I'm open to changing this UI to something else if someone has a better idea.
|
||||
|
@ -2503,11 +2507,11 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
with open(paths.lookupExeFolder() + 'keys.dat', 'wb') as configfile:
|
||||
BMConfigParser().write(configfile)
|
||||
# Write the knownnodes.dat file to disk in the new location
|
||||
shared.knownNodesLock.acquire()
|
||||
knownnodes.knownNodesLock.acquire()
|
||||
output = open(paths.lookupExeFolder() + 'knownnodes.dat', 'wb')
|
||||
pickle.dump(shared.knownNodes, output)
|
||||
pickle.dump(knownnodes.knownNodes, output)
|
||||
output.close()
|
||||
shared.knownNodesLock.release()
|
||||
knownnodes.knownNodesLock.release()
|
||||
os.remove(state.appdata + 'keys.dat')
|
||||
os.remove(state.appdata + 'knownnodes.dat')
|
||||
previousAppdataLocation = state.appdata
|
||||
|
@ -2527,11 +2531,11 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# Write the keys.dat file to disk in the new location
|
||||
BMConfigParser().save()
|
||||
# Write the knownnodes.dat file to disk in the new location
|
||||
shared.knownNodesLock.acquire()
|
||||
knownnodes.knownNodesLock.acquire()
|
||||
output = open(state.appdata + 'knownnodes.dat', 'wb')
|
||||
pickle.dump(shared.knownNodes, output)
|
||||
pickle.dump(knownnodes.knownNodes, output)
|
||||
output.close()
|
||||
shared.knownNodesLock.release()
|
||||
knownnodes.knownNodesLock.release()
|
||||
os.remove(paths.lookupExeFolder() + 'keys.dat')
|
||||
os.remove(paths.lookupExeFolder() + 'knownnodes.dat')
|
||||
debug.restartLoggingInUpdatedAppdataLocation()
|
||||
|
@ -2681,7 +2685,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# address.'
|
||||
streamNumberForAddress = decodeAddress(
|
||||
self.dialog.ui.comboBoxExisting.currentText())[2]
|
||||
shared.addressGeneratorQueue.put(('createRandomAddress', 4, streamNumberForAddress, str(
|
||||
queues.addressGeneratorQueue.put(('createRandomAddress', 4, streamNumberForAddress, str(
|
||||
self.dialog.ui.newaddresslabel.text().toUtf8()), 1, "", self.dialog.ui.checkBoxEighteenByteRipe.isChecked()))
|
||||
else:
|
||||
if self.dialog.ui.lineEditPassphrase.text() != self.dialog.ui.lineEditPassphraseAgain.text():
|
||||
|
@ -2692,7 +2696,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
"MainWindow", "Choose a passphrase"), _translate("MainWindow", "You really do need a passphrase."))
|
||||
else:
|
||||
streamNumberForAddress = 1 # this will eventually have to be replaced by logic to determine the most available stream number.
|
||||
shared.addressGeneratorQueue.put(('createDeterministicAddresses', 4, streamNumberForAddress, "unused deterministic address", self.dialog.ui.spinBoxNumberOfAddressesToMake.value(
|
||||
queues.addressGeneratorQueue.put(('createDeterministicAddresses', 4, streamNumberForAddress, "unused deterministic address", self.dialog.ui.spinBoxNumberOfAddressesToMake.value(
|
||||
), self.dialog.ui.lineEditPassphrase.text().toUtf8(), self.dialog.ui.checkBoxEighteenByteRipe.isChecked()))
|
||||
else:
|
||||
logger.debug('new address dialog box rejected')
|
||||
|
@ -2817,7 +2821,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
|
||||
self.statusBar().showMessage(_translate("MainWindow", "Shutting down core... %1%").arg(str(80)))
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
shared.doCleanShutdown()
|
||||
shutdown.doCleanShutdown()
|
||||
self.statusBar().showMessage(_translate("MainWindow", "Stopping notifications... %1%").arg(str(90)))
|
||||
self.tray.hide()
|
||||
# unregister the messaging system
|
||||
|
@ -3217,9 +3221,9 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
queryreturn = sqlQuery('''select ackdata FROM sent WHERE status='forcepow' ''')
|
||||
for row in queryreturn:
|
||||
ackdata, = row
|
||||
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
|
||||
queues.UISignalQueue.put(('updateSentItemStatusByAckdata', (
|
||||
ackdata, 'Overriding maximum-difficulty setting. Work queued.')))
|
||||
shared.workerQueue.put(('sendmessage', ''))
|
||||
queues.workerQueue.put(('sendmessage', ''))
|
||||
|
||||
def on_action_SentClipboard(self):
|
||||
currentRow = self.ui.tableWidgetInbox.currentRow()
|
||||
|
@ -4228,7 +4232,7 @@ class settingsDialog(QtGui.QDialog):
|
|||
self.ui.labelNamecoinPassword.setEnabled(isNamecoind)
|
||||
|
||||
if isNamecoind:
|
||||
self.ui.lineEditNamecoinPort.setText(shared.namecoinDefaultRpcPort)
|
||||
self.ui.lineEditNamecoinPort.setText(defaults.namecoinDefaultRpcPort)
|
||||
else:
|
||||
self.ui.lineEditNamecoinPort.setText("9000")
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
import shared
|
||||
import queues
|
||||
import re
|
||||
import sys
|
||||
import inspect
|
||||
|
@ -172,7 +172,7 @@ class GatewayAccount(BMAccount):
|
|||
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2) # not necessary to have a TTL higher than 2 days
|
||||
)
|
||||
|
||||
shared.workerQueue.put(('sendmessage', self.toAddress))
|
||||
queues.workerQueue.put(('sendmessage', self.toAddress))
|
||||
|
||||
def parseMessage(self, toAddress, fromAddress, subject, message):
|
||||
super(GatewayAccount, self).parseMessage(toAddress, fromAddress, subject, message)
|
||||
|
|
|
@ -3,7 +3,7 @@ from Queue import Empty
|
|||
|
||||
from addresses import decodeAddress, addBMIfNotPresent
|
||||
from account import getSortedAccounts
|
||||
from shared import apiAddressGeneratorReturnQueue, addressGeneratorQueue
|
||||
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue
|
||||
from tr import _translate
|
||||
from utils import str_chan
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from PyQt4 import QtCore, QtGui
|
|||
|
||||
from addresses import addBMIfNotPresent
|
||||
from addressvalidator import AddressValidator, PassPhraseValidator
|
||||
from shared import apiAddressGeneratorReturnQueue, addressGeneratorQueue, UISignalQueue
|
||||
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue, UISignalQueue
|
||||
from retranslateui import RetranslateMixin
|
||||
from tr import _translate
|
||||
from utils import str_chan
|
||||
|
|
|
@ -6,7 +6,7 @@ import Queue
|
|||
from urllib import quote, quote_plus
|
||||
from urlparse import urlparse
|
||||
from debug import logger
|
||||
from shared import parserInputQueue, parserOutputQueue, parserProcess, parserLock
|
||||
from queues import parserInputQueue, parserOutputQueue, parserProcess, parserLock
|
||||
|
||||
def regexpSubprocess(parserInputQueue, parserOutputQueue):
|
||||
for data in iter(parserInputQueue.get, None):
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import ctypes
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from os import path
|
||||
import ssl
|
||||
import sys
|
||||
import time
|
||||
|
@ -16,6 +15,7 @@ import paths
|
|||
from proofofwork import bmpow
|
||||
import protocol
|
||||
from pyelliptic.openssl import OpenSSL
|
||||
import queues
|
||||
import shared
|
||||
import state
|
||||
from version import softwareVersion
|
||||
|
@ -67,7 +67,7 @@ def checkHasNormalAddress():
|
|||
|
||||
def createAddressIfNeeded(myapp):
|
||||
if not checkHasNormalAddress():
|
||||
shared.addressGeneratorQueue.put(('createRandomAddress', 4, 1, str(QtGui.QApplication.translate("Support", SUPPORT_MY_LABEL)), 1, "", False, protocol.networkDefaultProofOfWorkNonceTrialsPerByte, protocol.networkDefaultPayloadLengthExtraBytes))
|
||||
queues.addressGeneratorQueue.put(('createRandomAddress', 4, 1, str(QtGui.QApplication.translate("Support", SUPPORT_MY_LABEL)), 1, "", False, protocol.networkDefaultProofOfWorkNonceTrialsPerByte, protocol.networkDefaultPayloadLengthExtraBytes))
|
||||
while state.shutdown == 0 and not checkHasNormalAddress():
|
||||
time.sleep(.2)
|
||||
myapp.rerenderComboBoxSendFrom()
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
from PyQt4.QtCore import QThread, SIGNAL
|
||||
import shared
|
||||
import sys
|
||||
|
||||
import queues
|
||||
|
||||
|
||||
class UISignaler(QThread):
|
||||
_instance = None
|
||||
|
@ -18,7 +19,7 @@ class UISignaler(QThread):
|
|||
|
||||
def run(self):
|
||||
while True:
|
||||
command, data = shared.UISignalQueue.get()
|
||||
command, data = queues.UISignalQueue.get()
|
||||
if command == 'writeNewAddressToTable':
|
||||
label, address, streamNumber = data
|
||||
self.emit(SIGNAL(
|
||||
|
|
|
@ -14,6 +14,7 @@ import protocol
|
|||
from pyelliptic import arithmetic
|
||||
import tr
|
||||
from binascii import hexlify
|
||||
import queues
|
||||
import state
|
||||
|
||||
class addressGenerator(threading.Thread, StoppableThread):
|
||||
|
@ -25,14 +26,14 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
|
||||
def stopThread(self):
|
||||
try:
|
||||
shared.addressGeneratorQueue.put(("stopThread", "data"))
|
||||
queues.addressGeneratorQueue.put(("stopThread", "data"))
|
||||
except:
|
||||
pass
|
||||
super(addressGenerator, self).stopThread()
|
||||
|
||||
def run(self):
|
||||
while state.shutdown == 0:
|
||||
queueValue = shared.addressGeneratorQueue.get()
|
||||
queueValue = queues.addressGeneratorQueue.get()
|
||||
nonceTrialsPerByte = 0
|
||||
payloadLengthExtraBytes = 0
|
||||
live = True
|
||||
|
@ -87,7 +88,7 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
if payloadLengthExtraBytes < protocol.networkDefaultPayloadLengthExtraBytes:
|
||||
payloadLengthExtraBytes = protocol.networkDefaultPayloadLengthExtraBytes
|
||||
if command == 'createRandomAddress':
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', tr._translate("MainWindow", "Generating one new address")))
|
||||
# This next section is a little bit strange. We're going to generate keys over and over until we
|
||||
# find one that starts with either \x00 or \x00\x00. Then when we pack them into a Bitmessage address,
|
||||
|
@ -147,18 +148,18 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
|
||||
# The API and the join and create Chan functionality
|
||||
# both need information back from the address generator.
|
||||
shared.apiAddressGeneratorReturnQueue.put(address)
|
||||
queues.apiAddressGeneratorReturnQueue.put(address)
|
||||
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', tr._translate("MainWindow", "Done generating address. Doing work necessary to broadcast it...")))
|
||||
shared.UISignalQueue.put(('writeNewAddressToTable', (
|
||||
queues.UISignalQueue.put(('writeNewAddressToTable', (
|
||||
label, address, streamNumber)))
|
||||
shared.reloadMyAddressHashes()
|
||||
if addressVersionNumber == 3:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'sendOutOrStoreMyV3Pubkey', ripe.digest()))
|
||||
elif addressVersionNumber == 4:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'sendOutOrStoreMyV4Pubkey', address))
|
||||
|
||||
elif command == 'createDeterministicAddresses' or command == 'getDeterministicAddress' or command == 'createChan' or command == 'joinChan':
|
||||
|
@ -166,7 +167,7 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
sys.stderr.write(
|
||||
'WARNING: You are creating deterministic address(es) using a blank passphrase. Bitmessage will do it but it is rather stupid.')
|
||||
if command == 'createDeterministicAddresses':
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', tr._translate("MainWindow","Generating %1 new addresses.").arg(str(numberOfAddressesToMake))))
|
||||
signingKeyNonce = 0
|
||||
encryptionKeyNonce = 1
|
||||
|
@ -243,7 +244,7 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
|
||||
if addressAlreadyExists:
|
||||
logger.info('%s already exists. Not adding it again.' % address)
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', tr._translate("MainWindow","%1 is already in 'Your Identities'. Not adding it again.").arg(address)))
|
||||
else:
|
||||
logger.debug('label: %s' % label)
|
||||
|
@ -262,7 +263,7 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
address, 'privEncryptionKey', privEncryptionKeyWIF)
|
||||
BMConfigParser().save()
|
||||
|
||||
shared.UISignalQueue.put(('writeNewAddressToTable', (
|
||||
queues.UISignalQueue.put(('writeNewAddressToTable', (
|
||||
label, address, str(streamNumber))))
|
||||
listOfNewAddressesToSendOutThroughTheAPI.append(
|
||||
address)
|
||||
|
@ -273,24 +274,24 @@ class addressGenerator(threading.Thread, StoppableThread):
|
|||
addressVersionNumber) + encodeVarint(streamNumber) + ripe.digest()).digest()).digest()[32:]
|
||||
shared.myAddressesByTag[tag] = address
|
||||
if addressVersionNumber == 3:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'sendOutOrStoreMyV3Pubkey', ripe.digest())) # If this is a chan address,
|
||||
# the worker thread won't send out the pubkey over the network.
|
||||
elif addressVersionNumber == 4:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'sendOutOrStoreMyV4Pubkey', address))
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', tr._translate("MainWindow", "Done generating address")))
|
||||
elif saveAddressToDisk and not live and not BMConfigParser().has_section(address):
|
||||
listOfNewAddressesToSendOutThroughTheAPI.append(address)
|
||||
|
||||
# Done generating addresses.
|
||||
if command == 'createDeterministicAddresses' or command == 'joinChan' or command == 'createChan':
|
||||
shared.apiAddressGeneratorReturnQueue.put(
|
||||
queues.apiAddressGeneratorReturnQueue.put(
|
||||
listOfNewAddressesToSendOutThroughTheAPI)
|
||||
elif command == 'getDeterministicAddress':
|
||||
shared.apiAddressGeneratorReturnQueue.put(address)
|
||||
queues.apiAddressGeneratorReturnQueue.put(address)
|
||||
else:
|
||||
raise Exception(
|
||||
"Error in the addressGenerator thread. Thread was given a command it could not understand: " + command)
|
||||
shared.addressGeneratorQueue.task_done()
|
||||
queues.addressGeneratorQueue.task_done()
|
||||
|
|
|
@ -22,6 +22,7 @@ import helper_msgcoding
|
|||
import helper_sent
|
||||
from helper_sql import *
|
||||
import protocol
|
||||
import queues
|
||||
import state
|
||||
import tr
|
||||
from debug import logger
|
||||
|
@ -46,14 +47,14 @@ class objectProcessor(threading.Thread):
|
|||
'''SELECT objecttype, data FROM objectprocessorqueue''')
|
||||
for row in queryreturn:
|
||||
objectType, data = row
|
||||
shared.objectProcessorQueue.put((objectType,data))
|
||||
queues.objectProcessorQueue.put((objectType,data))
|
||||
sqlExecute('''DELETE FROM objectprocessorqueue''')
|
||||
logger.debug('Loaded %s objects from disk into the objectProcessorQueue.' % str(len(queryreturn)))
|
||||
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
objectType, data = shared.objectProcessorQueue.get()
|
||||
objectType, data = queues.objectProcessorQueue.get()
|
||||
|
||||
try:
|
||||
if objectType == 0: # getpubkey
|
||||
|
@ -77,8 +78,8 @@ class objectProcessor(threading.Thread):
|
|||
time.sleep(.5) # Wait just a moment for most of the connections to close
|
||||
numberOfObjectsThatWereInTheObjectProcessorQueue = 0
|
||||
with SqlBulkExecute() as sql:
|
||||
while shared.objectProcessorQueue.curSize > 0:
|
||||
objectType, data = shared.objectProcessorQueue.get()
|
||||
while queues.objectProcessorQueue.curSize > 0:
|
||||
objectType, data = queues.objectProcessorQueue.get()
|
||||
sql.execute('''INSERT INTO objectprocessorqueue VALUES (?,?)''',
|
||||
objectType,data)
|
||||
numberOfObjectsThatWereInTheObjectProcessorQueue += 1
|
||||
|
@ -146,19 +147,19 @@ class objectProcessor(threading.Thread):
|
|||
return
|
||||
logger.info('Found getpubkey-requested-hash in my list of EC hashes. Telling Worker thread to do the POW for a pubkey message and send it out.')
|
||||
if requestedAddressVersionNumber == 2:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'doPOWForMyV2Pubkey', requestedHash))
|
||||
elif requestedAddressVersionNumber == 3:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'sendOutOrStoreMyV3Pubkey', requestedHash))
|
||||
elif requestedAddressVersionNumber == 4:
|
||||
shared.workerQueue.put((
|
||||
queues.workerQueue.put((
|
||||
'sendOutOrStoreMyV4Pubkey', myAddress))
|
||||
|
||||
def processpubkey(self, data):
|
||||
pubkeyProcessingStartTime = time.time()
|
||||
shared.numberOfPubkeysProcessed += 1
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateNumberOfPubkeysProcessed', 'no data'))
|
||||
embeddedTime, = unpack('>Q', data[8:16])
|
||||
readPosition = 20 # bypass the nonce, time, and object type
|
||||
|
@ -307,7 +308,7 @@ class objectProcessor(threading.Thread):
|
|||
def processmsg(self, data):
|
||||
messageProcessingStartTime = time.time()
|
||||
shared.numberOfMessagesProcessed += 1
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateNumberOfMessagesProcessed', 'no data'))
|
||||
readPosition = 20 # bypass the nonce, time, and object type
|
||||
msgVersion, msgVersionLength = decodeVarint(data[readPosition:readPosition + 9])
|
||||
|
@ -329,7 +330,7 @@ class objectProcessor(threading.Thread):
|
|||
'ackreceived',
|
||||
int(time.time()),
|
||||
data[-32:])
|
||||
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (data[-32:], tr._translate("MainWindow",'Acknowledgement of the message received %1').arg(l10n.formatTimestamp()))))
|
||||
queues.UISignalQueue.put(('updateSentItemStatusByAckdata', (data[-32:], tr._translate("MainWindow",'Acknowledgement of the message received %1').arg(l10n.formatTimestamp()))))
|
||||
return
|
||||
else:
|
||||
logger.info('This was NOT an acknowledgement bound for me.')
|
||||
|
@ -505,7 +506,7 @@ class objectProcessor(threading.Thread):
|
|||
time.time()), body, 'inbox', messageEncodingType, 0, sigHash)
|
||||
helper_inbox.insert(t)
|
||||
|
||||
shared.UISignalQueue.put(('displayNewInboxMessage', (
|
||||
queues.UISignalQueue.put(('displayNewInboxMessage', (
|
||||
inventoryHash, toAddress, fromAddress, subject, body)))
|
||||
|
||||
# If we are behaving as an API then we might need to run an
|
||||
|
@ -561,9 +562,9 @@ class objectProcessor(threading.Thread):
|
|||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
shared.UISignalQueue.put(('displayNewSentMessage', (
|
||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||
toAddress, '[Broadcast subscribers]', fromAddress, subject, message, ackdataForBroadcast)))
|
||||
shared.workerQueue.put(('sendbroadcast', ''))
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
# Don't send ACK if invalid, blacklisted senders, invisible messages, disabled or chan
|
||||
if self.ackDataHasAValidHeader(ackData) and \
|
||||
|
@ -590,7 +591,7 @@ class objectProcessor(threading.Thread):
|
|||
def processbroadcast(self, data):
|
||||
messageProcessingStartTime = time.time()
|
||||
shared.numberOfBroadcastsProcessed += 1
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateNumberOfBroadcastsProcessed', 'no data'))
|
||||
inventoryHash = calculateInventoryHash(data)
|
||||
readPosition = 20 # bypass the nonce, time, and object type
|
||||
|
@ -753,7 +754,7 @@ class objectProcessor(threading.Thread):
|
|||
time.time()), body, 'inbox', messageEncodingType, 0, sigHash)
|
||||
helper_inbox.insert(t)
|
||||
|
||||
shared.UISignalQueue.put(('displayNewInboxMessage', (
|
||||
queues.UISignalQueue.put(('displayNewInboxMessage', (
|
||||
inventoryHash, toAddress, fromAddress, subject, body)))
|
||||
|
||||
# If we are behaving as an API then we might need to run an
|
||||
|
@ -808,7 +809,7 @@ class objectProcessor(threading.Thread):
|
|||
sqlExecute(
|
||||
'''UPDATE sent SET status='doingmsgpow', retrynumber=0 WHERE toaddress=? AND (status='awaitingpubkey' or status='doingpubkeypow') AND folder='sent' ''',
|
||||
address)
|
||||
shared.workerQueue.put(('sendmessage', ''))
|
||||
queues.workerQueue.put(('sendmessage', ''))
|
||||
|
||||
def ackDataHasAValidHeader(self, ackData):
|
||||
if len(ackData) < protocol.Header.size:
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import shared
|
||||
|
||||
import Queue
|
||||
import threading
|
||||
import time
|
||||
|
|
|
@ -13,6 +13,8 @@ from class_sendDataThread import *
|
|||
from class_receiveDataThread import *
|
||||
from configparser import BMConfigParser
|
||||
from helper_threading import *
|
||||
import knownnodes
|
||||
import queues
|
||||
import state
|
||||
|
||||
# For each stream to which we connect, several outgoingSynSender threads
|
||||
|
@ -33,21 +35,21 @@ class outgoingSynSender(threading.Thread, StoppableThread):
|
|||
# ever connect to that. Otherwise we'll pick a random one from
|
||||
# the known nodes
|
||||
if state.trustedPeer:
|
||||
shared.knownNodesLock.acquire()
|
||||
knownnodes.knownNodesLock.acquire()
|
||||
peer = state.trustedPeer
|
||||
shared.knownNodes[self.streamNumber][peer] = time.time()
|
||||
shared.knownNodesLock.release()
|
||||
knownnodes.knownNodes[self.streamNumber][peer] = time.time()
|
||||
knownnodes.knownNodesLock.release()
|
||||
else:
|
||||
while not state.shutdown:
|
||||
shared.knownNodesLock.acquire()
|
||||
knownnodes.knownNodesLock.acquire()
|
||||
try:
|
||||
peer, = random.sample(shared.knownNodes[self.streamNumber], 1)
|
||||
peer, = random.sample(knownnodes.knownNodes[self.streamNumber], 1)
|
||||
except ValueError: # no known nodes
|
||||
shared.knownNodesLock.release()
|
||||
knownnodes.knownNodesLock.release()
|
||||
self.stop.wait(1)
|
||||
continue
|
||||
priority = (183600 - (time.time() - shared.knownNodes[self.streamNumber][peer])) / 183600 # 2 days and 3 hours
|
||||
shared.knownNodesLock.release()
|
||||
priority = (183600 - (time.time() - knownnodes.knownNodes[self.streamNumber][peer])) / 183600 # 2 days and 3 hours
|
||||
knownnodes.knownNodesLock.release()
|
||||
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') != 'none':
|
||||
if peer.host.find(".onion") == -1:
|
||||
priority /= 10 # hidden services have 10x priority over plain net
|
||||
|
@ -131,13 +133,13 @@ class outgoingSynSender(threading.Thread, StoppableThread):
|
|||
|
||||
So let us remove the offending address from our knownNodes file.
|
||||
"""
|
||||
shared.knownNodesLock.acquire()
|
||||
knownnodes.knownNodesLock.acquire()
|
||||
try:
|
||||
del shared.knownNodes[self.streamNumber][peer]
|
||||
del knownnodes.knownNodes[self.streamNumber][peer]
|
||||
except:
|
||||
pass
|
||||
shared.knownNodesLock.release()
|
||||
logger.debug('deleting ' + str(peer) + ' from shared.knownNodes because it caused a socks.socksocket exception. We must not be 64-bit compatible.')
|
||||
knownnodes.knownNodesLock.release()
|
||||
logger.debug('deleting ' + str(peer) + ' from knownnodes.knownNodes because it caused a socks.socksocket exception. We must not be 64-bit compatible.')
|
||||
continue
|
||||
# This option apparently avoids the TIME_WAIT state so that we
|
||||
# can rebind faster
|
||||
|
@ -220,7 +222,7 @@ class outgoingSynSender(threading.Thread, StoppableThread):
|
|||
except socks.GeneralProxyError as err:
|
||||
if err[0][0] in [7, 8, 9]:
|
||||
logger.error('Error communicating with proxy: %s', str(err))
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar',
|
||||
tr._translate(
|
||||
"MainWindow", "Problem communicating with proxy: %1. Please check your network settings.").arg(str(err[0][1]))
|
||||
|
@ -231,25 +233,25 @@ class outgoingSynSender(threading.Thread, StoppableThread):
|
|||
logger.debug('Could NOT connect to ' + str(peer) + ' during outgoing attempt. ' + str(err))
|
||||
|
||||
deletedPeer = None
|
||||
with shared.knownNodesLock:
|
||||
with knownnodes.knownNodesLock:
|
||||
"""
|
||||
It is remotely possible that peer is no longer in shared.knownNodes.
|
||||
It is remotely possible that peer is no longer in knownnodes.knownNodes.
|
||||
This could happen if two outgoingSynSender threads both try to
|
||||
connect to the same peer, both fail, and then both try to remove
|
||||
it from shared.knownNodes. This is unlikely because of the
|
||||
it from knownnodes.knownNodes. This is unlikely because of the
|
||||
alreadyAttemptedConnectionsList but because we clear that list once
|
||||
every half hour, it can happen.
|
||||
"""
|
||||
if peer in shared.knownNodes[self.streamNumber]:
|
||||
timeLastSeen = shared.knownNodes[self.streamNumber][peer]
|
||||
if (int(time.time()) - timeLastSeen) > 172800 and len(shared.knownNodes[self.streamNumber]) > 1000: # for nodes older than 48 hours old if we have more than 1000 hosts in our list, delete from the shared.knownNodes data-structure.
|
||||
del shared.knownNodes[self.streamNumber][peer]
|
||||
if peer in knownnodes.knownNodes[self.streamNumber]:
|
||||
timeLastSeen = knownnodes.knownNodes[self.streamNumber][peer]
|
||||
if (int(time.time()) - timeLastSeen) > 172800 and len(knownnodes.knownNodes[self.streamNumber]) > 1000: # for nodes older than 48 hours old if we have more than 1000 hosts in our list, delete from the knownnodes.knownNodes data-structure.
|
||||
del knownnodes.knownNodes[self.streamNumber][peer]
|
||||
deletedPeer = peer
|
||||
if deletedPeer:
|
||||
str ('deleting ' + str(peer) + ' from shared.knownNodes because it is more than 48 hours old and we could not connect to it.')
|
||||
str ('deleting ' + str(peer) + ' from knownnodes.knownNodes because it is more than 48 hours old and we could not connect to it.')
|
||||
|
||||
except socks.Socks5AuthError as err:
|
||||
shared.UISignalQueue.put((
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', tr._translate(
|
||||
"MainWindow", "SOCKS5 Authentication problem: %1. Please check your SOCKS5 settings.").arg(str(err))))
|
||||
except socks.Socks5Error as err:
|
||||
|
@ -272,22 +274,22 @@ class outgoingSynSender(threading.Thread, StoppableThread):
|
|||
logger.debug('Could NOT connect to ' + str(peer) + 'during outgoing attempt. ' + str(err))
|
||||
|
||||
deletedPeer = None
|
||||
with shared.knownNodesLock:
|
||||
with knownnodes.knownNodesLock:
|
||||
"""
|
||||
It is remotely possible that peer is no longer in shared.knownNodes.
|
||||
It is remotely possible that peer is no longer in knownnodes.knownNodes.
|
||||
This could happen if two outgoingSynSender threads both try to
|
||||
connect to the same peer, both fail, and then both try to remove
|
||||
it from shared.knownNodes. This is unlikely because of the
|
||||
it from knownnodes.knownNodes. This is unlikely because of the
|
||||
alreadyAttemptedConnectionsList but because we clear that list once
|
||||
every half hour, it can happen.
|
||||
"""
|
||||
if peer in shared.knownNodes[self.streamNumber]:
|
||||
timeLastSeen = shared.knownNodes[self.streamNumber][peer]
|
||||
if (int(time.time()) - timeLastSeen) > 172800 and len(shared.knownNodes[self.streamNumber]) > 1000: # for nodes older than 48 hours old if we have more than 1000 hosts in our list, delete from the shared.knownNodes data-structure.
|
||||
del shared.knownNodes[self.streamNumber][peer]
|
||||
if peer in knownnodes.knownNodes[self.streamNumber]:
|
||||
timeLastSeen = knownnodes.knownNodes[self.streamNumber][peer]
|
||||
if (int(time.time()) - timeLastSeen) > 172800 and len(knownnodes.knownNodes[self.streamNumber]) > 1000: # for nodes older than 48 hours old if we have more than 1000 hosts in our list, delete from the knownnodes.knownNodes data-structure.
|
||||
del knownnodes.knownNodes[self.streamNumber][peer]
|
||||
deletedPeer = peer
|
||||
if deletedPeer:
|
||||
logger.debug('deleting ' + str(peer) + ' from shared.knownNodes because it is more than 48 hours old and we could not connect to it.')
|
||||
logger.debug('deleting ' + str(peer) + ' from knownnodes.knownNodes because it is more than 48 hours old and we could not connect to it.')
|
||||
|
||||
except Exception as err:
|
||||
import traceback
|
||||
|
|
|
@ -28,10 +28,12 @@ from configparser import BMConfigParser
|
|||
from class_objectHashHolder import objectHashHolder
|
||||
from helper_generic import addDataPadding, isHostInPrivateIPRange
|
||||
from helper_sql import sqlQuery
|
||||
import knownnodes
|
||||
from debug import logger
|
||||
import paths
|
||||
import protocol
|
||||
from inventory import Inventory, PendingDownload, PendingUpload
|
||||
import queues
|
||||
import state
|
||||
import throttle
|
||||
import tr
|
||||
|
@ -147,13 +149,13 @@ class receiveDataThread(threading.Thread):
|
|||
logger.error('Could not delete ' + str(self.hostIdent) + ' from shared.connectedHostsList.' + str(err))
|
||||
|
||||
PendingDownload().threadEnd()
|
||||
shared.UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
|
||||
queues.UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
|
||||
self.checkTimeOffsetNotification()
|
||||
logger.debug('receiveDataThread ending. ID ' + str(id(self)) + '. The size of the shared.connectedHostsList is now ' + str(len(shared.connectedHostsList)))
|
||||
|
||||
def antiIntersectionDelay(self, initial = False):
|
||||
# estimated time for a small object to propagate across the whole network
|
||||
delay = math.ceil(math.log(max(len(shared.knownNodes[x]) for x in shared.knownNodes) + 2, 20)) * (0.2 + objectHashHolder.size/2)
|
||||
delay = math.ceil(math.log(max(len(knownnodes.knownNodes[x]) for x in knownnodes.knownNodes) + 2, 20)) * (0.2 + objectHashHolder.size/2)
|
||||
# take the stream with maximum amount of nodes
|
||||
# +2 is to avoid problems with log(0) and log(1)
|
||||
# 20 is avg connected nodes count
|
||||
|
@ -168,7 +170,7 @@ class receiveDataThread(threading.Thread):
|
|||
|
||||
def checkTimeOffsetNotification(self):
|
||||
if shared.timeOffsetWrongCount >= 4 and not self.connectionIsOrWasFullyEstablished:
|
||||
shared.UISignalQueue.put(('updateStatusBar', tr._translate("MainWindow", "The time on your computer, %1, may be wrong. Please verify your settings.").arg(datetime.datetime.now().strftime("%H:%M:%S"))))
|
||||
queues.UISignalQueue.put(('updateStatusBar', tr._translate("MainWindow", "The time on your computer, %1, may be wrong. Please verify your settings.").arg(datetime.datetime.now().strftime("%H:%M:%S"))))
|
||||
|
||||
def processData(self):
|
||||
if len(self.data) < protocol.Header.size: # if so little of the data has arrived that we can't even read the checksum then wait for more data.
|
||||
|
@ -198,9 +200,9 @@ class receiveDataThread(threading.Thread):
|
|||
# just received valid data from it. So update the knownNodes list so
|
||||
# that other peers can be made aware of its existance.
|
||||
if self.initiatedConnection and self.connectionIsOrWasFullyEstablished: # The remote port is only something we should share with others if it is the remote node's incoming port (rather than some random operating-system-assigned outgoing port).
|
||||
with shared.knownNodesLock:
|
||||
with knownnodes.knownNodesLock:
|
||||
for stream in self.streamNumber:
|
||||
shared.knownNodes[stream][self.peer] = int(time.time())
|
||||
knownnodes.knownNodes[stream][self.peer] = int(time.time())
|
||||
|
||||
#Strip the nulls
|
||||
command = command.rstrip('\x00')
|
||||
|
@ -359,10 +361,10 @@ class receiveDataThread(threading.Thread):
|
|||
|
||||
if not self.initiatedConnection:
|
||||
shared.clientHasReceivedIncomingConnections = True
|
||||
shared.UISignalQueue.put(('setStatusIcon', 'green'))
|
||||
queues.UISignalQueue.put(('setStatusIcon', 'green'))
|
||||
self.sock.settimeout(
|
||||
600) # We'll send out a ping every 5 minutes to make sure the connection stays alive if there has been no other traffic to send lately.
|
||||
shared.UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
|
||||
queues.UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
|
||||
logger.debug('Connection fully established with ' + str(self.peer) + "\n" + \
|
||||
'The size of the connectedHostsList is now ' + str(len(shared.connectedHostsList)) + "\n" + \
|
||||
'The length of sendDataQueues is now: ' + str(len(state.sendDataQueues)) + "\n" + \
|
||||
|
@ -611,14 +613,14 @@ class receiveDataThread(threading.Thread):
|
|||
continue
|
||||
timeSomeoneElseReceivedMessageFromThisNode, = unpack('>Q', data[lengthOfNumberOfAddresses + (
|
||||
38 * i):8 + lengthOfNumberOfAddresses + (38 * i)]) # This is the 'time' value in the received addr message. 64-bit.
|
||||
if recaddrStream not in shared.knownNodes: # knownNodes is a dictionary of dictionaries with one outer dictionary for each stream. If the outer stream dictionary doesn't exist yet then we must make it.
|
||||
with shared.knownNodesLock:
|
||||
shared.knownNodes[recaddrStream] = {}
|
||||
if recaddrStream not in knownnodes.knownNodes: # knownNodes is a dictionary of dictionaries with one outer dictionary for each stream. If the outer stream dictionary doesn't exist yet then we must make it.
|
||||
with knownnodes.knownNodesLock:
|
||||
knownnodes.knownNodes[recaddrStream] = {}
|
||||
peerFromAddrMessage = state.Peer(hostStandardFormat, recaddrPort)
|
||||
if peerFromAddrMessage not in shared.knownNodes[recaddrStream]:
|
||||
if len(shared.knownNodes[recaddrStream]) < 20000 and timeSomeoneElseReceivedMessageFromThisNode > (int(time.time()) - 10800) and timeSomeoneElseReceivedMessageFromThisNode < (int(time.time()) + 10800): # If we have more than 20000 nodes in our list already then just forget about adding more. Also, make sure that the time that someone else received a message from this node is within three hours from now.
|
||||
with shared.knownNodesLock:
|
||||
shared.knownNodes[recaddrStream][peerFromAddrMessage] = timeSomeoneElseReceivedMessageFromThisNode
|
||||
if peerFromAddrMessage not in knownnodes.knownNodes[recaddrStream]:
|
||||
if len(knownnodes.knownNodes[recaddrStream]) < 20000 and timeSomeoneElseReceivedMessageFromThisNode > (int(time.time()) - 10800) and timeSomeoneElseReceivedMessageFromThisNode < (int(time.time()) + 10800): # If we have more than 20000 nodes in our list already then just forget about adding more. Also, make sure that the time that someone else received a message from this node is within three hours from now.
|
||||
with knownnodes.knownNodesLock:
|
||||
knownnodes.knownNodes[recaddrStream][peerFromAddrMessage] = timeSomeoneElseReceivedMessageFromThisNode
|
||||
logger.debug('added new node ' + str(peerFromAddrMessage) + ' to knownNodes in stream ' + str(recaddrStream))
|
||||
|
||||
shared.needToWriteKnownNodesToDisk = True
|
||||
|
@ -628,14 +630,14 @@ class receiveDataThread(threading.Thread):
|
|||
protocol.broadcastToSendDataQueues((
|
||||
recaddrStream, 'advertisepeer', hostDetails))
|
||||
else:
|
||||
timeLastReceivedMessageFromThisNode = shared.knownNodes[recaddrStream][
|
||||
timeLastReceivedMessageFromThisNode = knownnodes.knownNodes[recaddrStream][
|
||||
peerFromAddrMessage]
|
||||
if (timeLastReceivedMessageFromThisNode < timeSomeoneElseReceivedMessageFromThisNode) and (timeSomeoneElseReceivedMessageFromThisNode < int(time.time())+900): # 900 seconds for wiggle-room in case other nodes' clocks aren't quite right.
|
||||
with shared.knownNodesLock:
|
||||
shared.knownNodes[recaddrStream][peerFromAddrMessage] = timeSomeoneElseReceivedMessageFromThisNode
|
||||
with knownnodes.knownNodesLock:
|
||||
knownnodes.knownNodes[recaddrStream][peerFromAddrMessage] = timeSomeoneElseReceivedMessageFromThisNode
|
||||
|
||||
for stream in self.streamNumber:
|
||||
logger.debug('knownNodes currently has %i nodes for stream %i', len(shared.knownNodes[stream]), stream)
|
||||
logger.debug('knownNodes currently has %i nodes for stream %i', len(knownnodes.knownNodes[stream]), stream)
|
||||
|
||||
|
||||
# Send a huge addr message to our peer. This is only used
|
||||
|
@ -651,8 +653,8 @@ class receiveDataThread(threading.Thread):
|
|||
addrsInChildStreamLeft = {}
|
||||
addrsInChildStreamRight = {}
|
||||
|
||||
with shared.knownNodesLock:
|
||||
if len(shared.knownNodes[stream]) > 0:
|
||||
with knownnodes.knownNodesLock:
|
||||
if len(knownnodes.knownNodes[stream]) > 0:
|
||||
ownPosition = random.randint(0, 499)
|
||||
sentOwn = False
|
||||
for i in range(500):
|
||||
|
@ -662,29 +664,29 @@ class receiveDataThread(threading.Thread):
|
|||
peer = state.Peer(BMConfigParser().get("bitmessagesettings", "onionhostname"), BMConfigParser().getint("bitmessagesettings", "onionport"))
|
||||
else:
|
||||
# still may contain own onion address, but we don't change it
|
||||
peer, = random.sample(shared.knownNodes[stream], 1)
|
||||
peer, = random.sample(knownnodes.knownNodes[stream], 1)
|
||||
if isHostInPrivateIPRange(peer.host):
|
||||
continue
|
||||
if peer.host == BMConfigParser().get("bitmessagesettings", "onionhostname") and peer.port == BMConfigParser().getint("bitmessagesettings", "onionport") :
|
||||
sentOwn = True
|
||||
addrsInMyStream[peer] = shared.knownNodes[
|
||||
addrsInMyStream[peer] = knownnodes.knownNodes[
|
||||
stream][peer]
|
||||
# sent 250 only if the remote isn't interested in it
|
||||
if len(shared.knownNodes[stream * 2]) > 0 and stream not in self.streamNumber:
|
||||
if len(knownnodes.knownNodes[stream * 2]) > 0 and stream not in self.streamNumber:
|
||||
for i in range(250):
|
||||
peer, = random.sample(shared.knownNodes[
|
||||
peer, = random.sample(knownnodes.knownNodes[
|
||||
stream * 2], 1)
|
||||
if isHostInPrivateIPRange(peer.host):
|
||||
continue
|
||||
addrsInChildStreamLeft[peer] = shared.knownNodes[
|
||||
addrsInChildStreamLeft[peer] = knownnodes.knownNodes[
|
||||
stream * 2][peer]
|
||||
if len(shared.knownNodes[(stream * 2) + 1]) > 0 and stream not in self.streamNumber:
|
||||
if len(knownnodes.knownNodes[(stream * 2) + 1]) > 0 and stream not in self.streamNumber:
|
||||
for i in range(250):
|
||||
peer, = random.sample(shared.knownNodes[
|
||||
peer, = random.sample(knownnodes.knownNodes[
|
||||
(stream * 2) + 1], 1)
|
||||
if isHostInPrivateIPRange(peer.host):
|
||||
continue
|
||||
addrsInChildStreamRight[peer] = shared.knownNodes[
|
||||
addrsInChildStreamRight[peer] = knownnodes.knownNodes[
|
||||
(stream * 2) + 1][peer]
|
||||
numberOfAddressesInAddrMessage = 0
|
||||
payload = ''
|
||||
|
@ -772,7 +774,7 @@ class receiveDataThread(threading.Thread):
|
|||
try:
|
||||
if cmp(remoteVersion, myVersion) > 0 and \
|
||||
(myVersion[1] % 2 == remoteVersion[1] % 2):
|
||||
shared.UISignalQueue.put(('newVersionAvailable', remoteVersion))
|
||||
queues.UISignalQueue.put(('newVersionAvailable', remoteVersion))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -804,11 +806,11 @@ class receiveDataThread(threading.Thread):
|
|||
self.sendDataThreadQueue.put((0, 'setRemoteProtocolVersion', self.remoteProtocolVersion))
|
||||
|
||||
if not isHostInPrivateIPRange(self.peer.host):
|
||||
with shared.knownNodesLock:
|
||||
with knownnodes. |