No more arg() call on result of _translate()
This commit is contained in:
parent
1cae520191
commit
3202082e76
|
@ -144,11 +144,10 @@ class objectProcessor(threading.Thread):
|
||||||
" WHERE ackdata=?", int(time.time()), data[readPosition:])
|
" WHERE ackdata=?", int(time.time()), data[readPosition:])
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
data[readPosition:],
|
data[readPosition:], _translate(
|
||||||
_translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Acknowledgement of the message received %1"
|
"Acknowledgement of the message received {0}"
|
||||||
).arg(l10n.formatTimestamp()))
|
).format(l10n.formatTimestamp()))
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
logger.debug('This object is not an acknowledgement bound for me.')
|
logger.debug('This object is not an acknowledgement bound for me.')
|
||||||
|
|
|
@ -12,6 +12,8 @@ from binascii import hexlify, unhexlify
|
||||||
from struct import pack
|
from struct import pack
|
||||||
from subprocess import call # nosec
|
from subprocess import call # nosec
|
||||||
|
|
||||||
|
from six.moves import configparser, queue
|
||||||
|
|
||||||
import defaults
|
import defaults
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
import helper_msgcoding
|
import helper_msgcoding
|
||||||
|
@ -24,15 +26,13 @@ import protocol
|
||||||
import queues
|
import queues
|
||||||
import shared
|
import shared
|
||||||
import state
|
import state
|
||||||
import tr
|
|
||||||
from addresses import (
|
from addresses import (
|
||||||
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
|
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint)
|
||||||
)
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from helper_sql import sqlExecute, sqlQuery
|
from helper_sql import sqlExecute, sqlQuery
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from network import knownnodes, StoppableThread
|
from network import knownnodes, StoppableThread
|
||||||
from six.moves import configparser, queue
|
from tr import _translate
|
||||||
|
|
||||||
|
|
||||||
def sizeof_fmt(num, suffix='h/s'):
|
def sizeof_fmt(num, suffix='h/s'):
|
||||||
|
@ -216,9 +216,8 @@ class singleWorker(StoppableThread):
|
||||||
return privSigningKeyHex, privEncryptionKeyHex, \
|
return privSigningKeyHex, privEncryptionKeyHex, \
|
||||||
pubSigningKey, pubEncryptionKey
|
pubSigningKey, pubEncryptionKey
|
||||||
|
|
||||||
def _doPOWDefaults(self, payload, TTL,
|
def _doPOWDefaults(
|
||||||
log_prefix='',
|
self, payload, TTL, log_prefix='', log_time=False):
|
||||||
log_time=False):
|
|
||||||
target = 2 ** 64 / (
|
target = 2 ** 64 / (
|
||||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * (
|
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * (
|
||||||
len(payload) + 8
|
len(payload) + 8
|
||||||
|
@ -244,14 +243,16 @@ class singleWorker(StoppableThread):
|
||||||
'PoW took %.1f seconds, speed %s.',
|
'PoW took %.1f seconds, speed %s.',
|
||||||
delta, sizeof_fmt(nonce / delta)
|
delta, sizeof_fmt(nonce / delta)
|
||||||
)
|
)
|
||||||
except: # noqa:E722 # NameError
|
except NameError:
|
||||||
self.logger.warning("Proof of Work exception")
|
self.logger.warning("Proof of Work exception")
|
||||||
payload = pack('>Q', nonce) + payload
|
payload = pack('>Q', nonce) + payload
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
def doPOWForMyV2Pubkey(self, adressHash):
|
def doPOWForMyV2Pubkey(self, adressHash):
|
||||||
""" This function also broadcasts out the pubkey
|
"""
|
||||||
message once it is done with the POW"""
|
This function also broadcasts out the pubkey message once it is
|
||||||
|
done with the POW
|
||||||
|
"""
|
||||||
# Look up my stream number based on my address hash
|
# Look up my stream number based on my address hash
|
||||||
myAddress = shared.myAddressesByHash[adressHash]
|
myAddress = shared.myAddressesByHash[adressHash]
|
||||||
# status
|
# status
|
||||||
|
@ -311,9 +312,10 @@ class singleWorker(StoppableThread):
|
||||||
|
|
||||||
def sendOutOrStoreMyV3Pubkey(self, adressHash):
|
def sendOutOrStoreMyV3Pubkey(self, adressHash):
|
||||||
"""
|
"""
|
||||||
If this isn't a chan address, this function assembles the pubkey data, does the necessary POW and sends it out.
|
If this isn't a chan address, this function assembles the pubkey
|
||||||
If it *is* a chan then it assembles the pubkey and stores is in the pubkey table so that we can send messages
|
data, does the necessary POW and sends it out.
|
||||||
to "ourselves".
|
If it *is* a chan then it assembles the pubkey and stores it in
|
||||||
|
the pubkey table so that we can send messages to "ourselves".
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
myAddress = shared.myAddressesByHash[adressHash]
|
myAddress = shared.myAddressesByHash[adressHash]
|
||||||
|
@ -399,9 +401,10 @@ class singleWorker(StoppableThread):
|
||||||
|
|
||||||
def sendOutOrStoreMyV4Pubkey(self, myAddress):
|
def sendOutOrStoreMyV4Pubkey(self, myAddress):
|
||||||
"""
|
"""
|
||||||
It doesn't send directly anymore. It put is to a queue for another thread to send at an appropriate time,
|
It doesn't send directly anymore. It put is to a queue for
|
||||||
whereas in the past it directly appended it to the outgoing buffer, I think. Same with all the other methods in
|
another thread to send at an appropriate time, whereas in the
|
||||||
this class.
|
past it directly appended it to the outgoing buffer, I think.
|
||||||
|
Same with all the other methods in this class.
|
||||||
"""
|
"""
|
||||||
if not BMConfigParser().has_section(myAddress):
|
if not BMConfigParser().has_section(myAddress):
|
||||||
# The address has been deleted.
|
# The address has been deleted.
|
||||||
|
@ -530,7 +533,10 @@ class singleWorker(StoppableThread):
|
||||||
queues.invQueue.put((streamNumber, inventoryHash))
|
queues.invQueue.put((streamNumber, inventoryHash))
|
||||||
|
|
||||||
def sendBroadcast(self):
|
def sendBroadcast(self):
|
||||||
"""Send a broadcast-type object (assemble the object, perform PoW and put it to the inv announcement queue)"""
|
"""
|
||||||
|
Send a broadcast-type object (assemble the object, perform PoW
|
||||||
|
and put it to the inv announcement queue)
|
||||||
|
"""
|
||||||
# Reset just in case
|
# Reset just in case
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'''UPDATE sent SET status='broadcastqueued' '''
|
'''UPDATE sent SET status='broadcastqueued' '''
|
||||||
|
@ -562,8 +568,7 @@ class singleWorker(StoppableThread):
|
||||||
self.logger.warning("Section or Option did not found: %s", err)
|
self.logger.warning("Section or Option did not found: %s", err)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Error! Could not find sender address"
|
"Error! Could not find sender address"
|
||||||
" (your address) in the keys.dat file."))
|
" (your address) in the keys.dat file."))
|
||||||
|
@ -577,7 +582,7 @@ class singleWorker(StoppableThread):
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata,
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Error, can't send."))
|
"Error, can't send."))
|
||||||
))
|
))
|
||||||
|
@ -666,8 +671,7 @@ class singleWorker(StoppableThread):
|
||||||
|
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Doing work necessary to send broadcast..."))
|
"Doing work necessary to send broadcast..."))
|
||||||
))
|
))
|
||||||
|
@ -699,11 +703,9 @@ class singleWorker(StoppableThread):
|
||||||
|
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
"MainWindow", "Broadcast sent on {0}"
|
||||||
"MainWindow",
|
).format(l10n.formatTimestamp()))
|
||||||
"Broadcast sent on %1"
|
|
||||||
).arg(l10n.formatTimestamp()))
|
|
||||||
))
|
))
|
||||||
|
|
||||||
# Update the status of the message in the 'sent' table to have
|
# Update the status of the message in the 'sent' table to have
|
||||||
|
@ -715,7 +717,10 @@ class singleWorker(StoppableThread):
|
||||||
)
|
)
|
||||||
|
|
||||||
def sendMsg(self):
|
def sendMsg(self):
|
||||||
"""Send a message-type object (assemble the object, perform PoW and put it to the inv announcement queue)"""
|
"""
|
||||||
|
Send a message-type object (assemble the object, perform PoW
|
||||||
|
and put it to the inv announcement queue)
|
||||||
|
"""
|
||||||
# pylint: disable=too-many-nested-blocks
|
# pylint: disable=too-many-nested-blocks
|
||||||
# Reset just in case
|
# Reset just in case
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
|
@ -811,8 +816,7 @@ class singleWorker(StoppableThread):
|
||||||
)
|
)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByToAddress', (
|
'updateSentItemStatusByToAddress', (
|
||||||
toaddress,
|
toaddress, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Encryption key was requested earlier."))
|
"Encryption key was requested earlier."))
|
||||||
))
|
))
|
||||||
|
@ -884,8 +888,7 @@ class singleWorker(StoppableThread):
|
||||||
)
|
)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByToAddress', (
|
'updateSentItemStatusByToAddress', (
|
||||||
toaddress,
|
toaddress, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Sending a request for the"
|
"Sending a request for the"
|
||||||
" recipient\'s encryption key."))
|
" recipient\'s encryption key."))
|
||||||
|
@ -909,8 +912,7 @@ class singleWorker(StoppableThread):
|
||||||
state.ackdataForWhichImWatching[ackdata] = 0
|
state.ackdataForWhichImWatching[ackdata] = 0
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Looking up the receiver\'s public key"))
|
"Looking up the receiver\'s public key"))
|
||||||
))
|
))
|
||||||
|
@ -967,15 +969,14 @@ class singleWorker(StoppableThread):
|
||||||
)
|
)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Problem: Destination is a mobile"
|
"Problem: Destination is a mobile"
|
||||||
" device who requests that the"
|
" device who requests that the"
|
||||||
" destination be included in the"
|
" destination be included in the"
|
||||||
" message but this is disallowed in"
|
" message but this is disallowed in"
|
||||||
" your settings. %1"
|
" your settings. {0}"
|
||||||
).arg(l10n.formatTimestamp()))
|
).format(l10n.formatTimestamp()))
|
||||||
))
|
))
|
||||||
# if the human changes their setting and then
|
# if the human changes their setting and then
|
||||||
# sends another message or restarts their client,
|
# sends another message or restarts their client,
|
||||||
|
@ -998,8 +999,7 @@ class singleWorker(StoppableThread):
|
||||||
defaults.networkDefaultPayloadLengthExtraBytes
|
defaults.networkDefaultPayloadLengthExtraBytes
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Doing work necessary to send message.\n"
|
"Doing work necessary to send message.\n"
|
||||||
"There is no required difficulty for"
|
"There is no required difficulty for"
|
||||||
|
@ -1031,32 +1031,19 @@ class singleWorker(StoppableThread):
|
||||||
requiredAverageProofOfWorkNonceTrialsPerByte,
|
requiredAverageProofOfWorkNonceTrialsPerByte,
|
||||||
requiredPayloadLengthExtraBytes
|
requiredPayloadLengthExtraBytes
|
||||||
)
|
)
|
||||||
|
queues.UISignalQueue.put((
|
||||||
queues.UISignalQueue.put(
|
'updateSentItemStatusByAckdata', (
|
||||||
(
|
ackdata, _translate(
|
||||||
'updateSentItemStatusByAckdata',
|
|
||||||
(
|
|
||||||
ackdata,
|
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Doing work necessary to send message.\n"
|
"Doing work necessary to send message.\n"
|
||||||
"Receiver\'s required difficulty: %1"
|
"Receiver\'s required difficulty: {0} and {1}"
|
||||||
" and %2"
|
).format(
|
||||||
).arg(
|
|
||||||
str(
|
|
||||||
float(requiredAverageProofOfWorkNonceTrialsPerByte)
|
float(requiredAverageProofOfWorkNonceTrialsPerByte)
|
||||||
/ defaults.networkDefaultProofOfWorkNonceTrialsPerByte
|
/ defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
|
||||||
)
|
|
||||||
).arg(
|
|
||||||
str(
|
|
||||||
float(requiredPayloadLengthExtraBytes)
|
float(requiredPayloadLengthExtraBytes)
|
||||||
/ defaults.networkDefaultPayloadLengthExtraBytes
|
/ defaults.networkDefaultPayloadLengthExtraBytes
|
||||||
)
|
))
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if status != 'forcepow':
|
if status != 'forcepow':
|
||||||
maxacceptablenoncetrialsperbyte = BMConfigParser().getint(
|
maxacceptablenoncetrialsperbyte = BMConfigParser().getint(
|
||||||
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')
|
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')
|
||||||
|
@ -1076,18 +1063,19 @@ class singleWorker(StoppableThread):
|
||||||
ackdata)
|
ackdata)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Problem: The work demanded by"
|
"Problem: The work demanded by the"
|
||||||
" the recipient (%1 and %2) is"
|
" recipient ({0} and {1}) is more"
|
||||||
" more difficult than you are"
|
" difficult than you are willing"
|
||||||
" willing to do. %3"
|
" to do. {2}"
|
||||||
).arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte)
|
).format(
|
||||||
/ defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
|
float(requiredAverageProofOfWorkNonceTrialsPerByte)
|
||||||
).arg(str(float(requiredPayloadLengthExtraBytes)
|
/ defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
|
||||||
/ defaults.networkDefaultPayloadLengthExtraBytes)
|
float(requiredPayloadLengthExtraBytes)
|
||||||
).arg(l10n.formatTimestamp()))))
|
/ defaults.networkDefaultPayloadLengthExtraBytes,
|
||||||
|
l10n.formatTimestamp()))
|
||||||
|
))
|
||||||
continue
|
continue
|
||||||
else: # if we are sending a message to ourselves or a chan..
|
else: # if we are sending a message to ourselves or a chan..
|
||||||
self.logger.info('Sending a message.')
|
self.logger.info('Sending a message.')
|
||||||
|
@ -1101,15 +1089,14 @@ class singleWorker(StoppableThread):
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError) as err:
|
except (configparser.NoSectionError, configparser.NoOptionError) as err:
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Problem: You are trying to send a"
|
"Problem: You are trying to send a"
|
||||||
" message to yourself or a chan but your"
|
" message to yourself or a chan but your"
|
||||||
" encryption key could not be found in"
|
" encryption key could not be found in"
|
||||||
" the keys.dat file. Could not encrypt"
|
" the keys.dat file. Could not encrypt"
|
||||||
" message. %1"
|
" message. {0}"
|
||||||
).arg(l10n.formatTimestamp()))
|
).format(l10n.formatTimestamp()))
|
||||||
))
|
))
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'Error within sendMsg. Could not read the keys'
|
'Error within sendMsg. Could not read the keys'
|
||||||
|
@ -1126,8 +1113,7 @@ class singleWorker(StoppableThread):
|
||||||
defaults.networkDefaultPayloadLengthExtraBytes
|
defaults.networkDefaultPayloadLengthExtraBytes
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Doing work necessary to send message."))
|
"Doing work necessary to send message."))
|
||||||
))
|
))
|
||||||
|
@ -1150,8 +1136,7 @@ class singleWorker(StoppableThread):
|
||||||
self.logger.warning("Section or Option did not found: %s", err)
|
self.logger.warning("Section or Option did not found: %s", err)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Error! Could not find sender address"
|
"Error! Could not find sender address"
|
||||||
" (your address) in the keys.dat file."))
|
" (your address) in the keys.dat file."))
|
||||||
|
@ -1165,7 +1150,7 @@ class singleWorker(StoppableThread):
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata,
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Error, can't send."))
|
"Error, can't send."))
|
||||||
))
|
))
|
||||||
|
@ -1217,8 +1202,7 @@ class singleWorker(StoppableThread):
|
||||||
# The fullAckPayload is a normal msg protocol message
|
# The fullAckPayload is a normal msg protocol message
|
||||||
# with the proof of work already completed that the
|
# with the proof of work already completed that the
|
||||||
# receiver of this message can easily send out.
|
# receiver of this message can easily send out.
|
||||||
fullAckPayload = self.generateFullAckMessage(
|
fullAckPayload = self.generateFullAckMessage(ackdata, TTL)
|
||||||
ackdata, toStreamNumber, TTL)
|
|
||||||
payload += encodeVarint(len(fullAckPayload))
|
payload += encodeVarint(len(fullAckPayload))
|
||||||
payload += fullAckPayload
|
payload += fullAckPayload
|
||||||
dataToSign = pack('>Q', embeddedTime) + '\x00\x00\x00\x02' + \
|
dataToSign = pack('>Q', embeddedTime) + '\x00\x00\x00\x02' + \
|
||||||
|
@ -1240,12 +1224,11 @@ class singleWorker(StoppableThread):
|
||||||
)
|
)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Problem: The recipient\'s encryption key is"
|
"Problem: The recipient\'s encryption key is"
|
||||||
" no good. Could not encrypt message. %1"
|
" no good. Could not encrypt message. {0}"
|
||||||
).arg(l10n.formatTimestamp()))
|
).format(l10n.formatTimestamp()))
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1309,21 +1292,19 @@ class singleWorker(StoppableThread):
|
||||||
not protocol.checkBitfield(behaviorBitfield, protocol.BITFIELD_DOESACK):
|
not protocol.checkBitfield(behaviorBitfield, protocol.BITFIELD_DOESACK):
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
"MainWindow", "Message sent. Sent at {0}"
|
||||||
"MainWindow",
|
).format(l10n.formatTimestamp()))
|
||||||
"Message sent. Sent at %1"
|
))
|
||||||
).arg(l10n.formatTimestamp()))))
|
|
||||||
else:
|
else:
|
||||||
# not sending to a chan or one of my addresses
|
# not sending to a chan or one of my addresses
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByAckdata', (
|
'updateSentItemStatusByAckdata', (
|
||||||
ackdata,
|
ackdata, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Message sent. Waiting for acknowledgement."
|
"Message sent. Waiting for acknowledgement."
|
||||||
" Sent on %1"
|
" Sent on {0}"
|
||||||
).arg(l10n.formatTimestamp()))
|
).format(l10n.formatTimestamp()))
|
||||||
))
|
))
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
'Broadcasting inv for my msg(within sendmsg function): %s',
|
'Broadcasting inv for my msg(within sendmsg function): %s',
|
||||||
|
@ -1451,8 +1432,7 @@ class singleWorker(StoppableThread):
|
||||||
queues.UISignalQueue.put(('updateStatusBar', statusbar))
|
queues.UISignalQueue.put(('updateStatusBar', statusbar))
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByToAddress', (
|
'updateSentItemStatusByToAddress', (
|
||||||
toAddress,
|
toAddress, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Doing work necessary to request encryption key."))
|
"Doing work necessary to request encryption key."))
|
||||||
))
|
))
|
||||||
|
@ -1476,30 +1456,31 @@ class singleWorker(StoppableThread):
|
||||||
int(time.time()), retryNumber + 1, sleeptill, toAddress)
|
int(time.time()), retryNumber + 1, sleeptill, toAddress)
|
||||||
|
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateStatusBar',
|
'updateStatusBar', _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Broadcasting the public key request. This program will"
|
"Broadcasting the public key request. This program will"
|
||||||
" auto-retry if they are offline.")
|
" auto-retry if they are offline.")
|
||||||
))
|
))
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateSentItemStatusByToAddress', (
|
'updateSentItemStatusByToAddress', (
|
||||||
toAddress,
|
toAddress, _translate(
|
||||||
tr._translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Sending public key request. Waiting for reply."
|
"Sending public key request. Waiting for reply."
|
||||||
" Requested at %1"
|
" Requested at {0}"
|
||||||
).arg(l10n.formatTimestamp()))
|
).format(l10n.formatTimestamp()))
|
||||||
))
|
))
|
||||||
|
|
||||||
def generateFullAckMessage(self, ackdata, _, TTL):
|
def generateFullAckMessage(self, ackdata, TTL):
|
||||||
"""
|
"""Create ACK packet"""
|
||||||
It might be perfectly fine to just use the same TTL for the ackdata that we use for the message. But I would
|
# It might be perfectly fine to just use the same TTL for
|
||||||
rather it be more difficult for attackers to associate ackData with the associated msg object. However, users
|
# the ackdata that we use for the message. But I would rather
|
||||||
would want the TTL of the acknowledgement to be about the same as they set for the message itself. So let's set
|
# it be more difficult for attackers to associate ackData with
|
||||||
the TTL of the acknowledgement to be in one of three 'buckets': 1 hour, 7 days, or 28 days, whichever is
|
# the associated msg object. However, users would want the TTL
|
||||||
relatively close to what the user specified.
|
# of the acknowledgement to be about the same as they set
|
||||||
"""
|
# for the message itself. So let's set the TTL of the
|
||||||
|
# acknowledgement to be in one of three 'buckets': 1 hour, 7
|
||||||
|
# days, or 28 days, whichever is relatively close to what the
|
||||||
|
# user specified.
|
||||||
if TTL < 24 * 60 * 60: # 1 day
|
if TTL < 24 * 60 * 60: # 1 day
|
||||||
TTL = 24 * 60 * 60 # 1 day
|
TTL = 24 * 60 * 60 # 1 day
|
||||||
elif TTL < 7 * 24 * 60 * 60: # 1 week
|
elif TTL < 7 * 24 * 60 * 60: # 1 week
|
||||||
|
|
109
src/namecoin.py
109
src/namecoin.py
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Namecoin queries
|
Namecoin queries
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-branches,protected-access
|
# pylint: disable=too-many-branches
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import httplib
|
import httplib
|
||||||
|
@ -14,14 +14,14 @@ import defaults
|
||||||
from addresses import decodeAddress
|
from addresses import decodeAddress
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from tr import _translate # translate
|
from tr import _translate
|
||||||
|
|
||||||
|
|
||||||
configSection = "bitmessagesettings"
|
configSection = "bitmessagesettings"
|
||||||
|
|
||||||
|
|
||||||
class RPCError(Exception):
|
class RPCError(Exception):
|
||||||
"""Error thrown when the RPC call returns an error."""
|
"""Error thrown when the RPC call returns an error."""
|
||||||
|
|
||||||
error = None
|
error = None
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
@ -29,7 +29,7 @@ class RPCError(Exception):
|
||||||
self.error = data
|
self.error = data
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0}: {1}".format(type(self).__name__, self.error)
|
return '{0}: {1}'.format(type(self).__name__, self.error)
|
||||||
|
|
||||||
|
|
||||||
class namecoinConnection(object):
|
class namecoinConnection(object):
|
||||||
|
@ -54,12 +54,10 @@ class namecoinConnection(object):
|
||||||
if options is None:
|
if options is None:
|
||||||
self.nmctype = BMConfigParser().get(
|
self.nmctype = BMConfigParser().get(
|
||||||
configSection, "namecoinrpctype")
|
configSection, "namecoinrpctype")
|
||||||
self.host = BMConfigParser().get(
|
self.host = BMConfigParser().get(configSection, "namecoinrpchost")
|
||||||
configSection, "namecoinrpchost")
|
|
||||||
self.port = int(BMConfigParser().get(
|
self.port = int(BMConfigParser().get(
|
||||||
configSection, "namecoinrpcport"))
|
configSection, "namecoinrpcport"))
|
||||||
self.user = BMConfigParser().get(
|
self.user = BMConfigParser().get(configSection, "namecoinrpcuser")
|
||||||
configSection, "namecoinrpcuser")
|
|
||||||
self.password = BMConfigParser().get(
|
self.password = BMConfigParser().get(
|
||||||
configSection, "namecoinrpcpassword")
|
configSection, "namecoinrpcpassword")
|
||||||
else:
|
else:
|
||||||
|
@ -69,7 +67,7 @@ class namecoinConnection(object):
|
||||||
self.user = options["user"]
|
self.user = options["user"]
|
||||||
self.password = options["password"]
|
self.password = options["password"]
|
||||||
|
|
||||||
assert self.nmctype == "namecoind" or self.nmctype == "nmcontrol"
|
assert self.nmctype in ("namecoind", "nmcontrol")
|
||||||
if self.nmctype == "namecoind":
|
if self.nmctype == "namecoind":
|
||||||
self.con = httplib.HTTPConnection(self.host, self.port, timeout=3)
|
self.con = httplib.HTTPConnection(self.host, self.port, timeout=3)
|
||||||
|
|
||||||
|
@ -96,8 +94,8 @@ class namecoinConnection(object):
|
||||||
res = res["reply"]
|
res = res["reply"]
|
||||||
if not res:
|
if not res:
|
||||||
return (_translate(
|
return (_translate(
|
||||||
"MainWindow", "The name %1 was not found."
|
"MainWindow", "The name {0} was not found."
|
||||||
).arg(identity.decode("utf-8", "ignore")), None)
|
).format(identity.decode('utf-8', 'ignore')), None)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
except RPCError as exc:
|
except RPCError as exc:
|
||||||
|
@ -107,12 +105,12 @@ class namecoinConnection(object):
|
||||||
else:
|
else:
|
||||||
errmsg = exc.error
|
errmsg = exc.error
|
||||||
return (_translate(
|
return (_translate(
|
||||||
"MainWindow", "The namecoin query failed (%1)"
|
"MainWindow", "The namecoin query failed ({0})"
|
||||||
).arg(errmsg.decode("utf-8", "ignore")), None)
|
).format(errmsg.decode('utf-8', 'ignore')), None)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return (_translate(
|
return (_translate(
|
||||||
"MainWindow", "Unknown namecoin interface type: %1"
|
"MainWindow", "Unknown namecoin interface type: {0}"
|
||||||
).arg(self.nmctype.decode("utf-8", "ignore")), None)
|
).format(self.nmctype.decode('utf-8', 'ignore')), None)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Namecoin query exception")
|
logger.exception("Namecoin query exception")
|
||||||
return (_translate(
|
return (_translate(
|
||||||
|
@ -135,8 +133,8 @@ class namecoinConnection(object):
|
||||||
) if valid else (
|
) if valid else (
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"The name %1 has no associated Bitmessage address."
|
"The name {0} has no associated Bitmessage address."
|
||||||
).arg(identity.decode("utf-8", "ignore")), None)
|
).format(identity.decode('utf-8', 'ignore')), None)
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
"""
|
"""
|
||||||
|
@ -160,44 +158,36 @@ class namecoinConnection(object):
|
||||||
versStr = "0.%d.%d" % (v1, v2)
|
versStr = "0.%d.%d" % (v1, v2)
|
||||||
else:
|
else:
|
||||||
versStr = "0.%d.%d.%d" % (v1, v2, v3)
|
versStr = "0.%d.%d.%d" % (v1, v2, v3)
|
||||||
message = (
|
return (
|
||||||
"success",
|
'success', _translate(
|
||||||
_translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Success! Namecoind version %1 running.").arg(
|
"Success! Namecoind version {0} running."
|
||||||
versStr.decode("utf-8", "ignore")))
|
).format(versStr.decode('utf-8', 'ignore'))
|
||||||
|
)
|
||||||
|
|
||||||
elif self.nmctype == "nmcontrol":
|
elif self.nmctype == "nmcontrol":
|
||||||
res = self.callRPC("data", ["status"])
|
res = self.callRPC("data", ["status"])
|
||||||
prefix = "Plugin data running"
|
prefix = "Plugin data running"
|
||||||
if ("reply" in res) and res["reply"][:len(prefix)] == prefix:
|
if ("reply" in res) and res["reply"][:len(prefix)] == prefix:
|
||||||
return (
|
return (
|
||||||
"success",
|
'success', _translate(
|
||||||
_translate(
|
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Success! NMControll is up and running."
|
"Success! NMControll is up and running.")
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.error("Unexpected nmcontrol reply: %s", res)
|
logger.error("Unexpected nmcontrol reply: %s", res)
|
||||||
message = (
|
return (
|
||||||
"failed",
|
'failed', _translate(
|
||||||
_translate(
|
"MainWindow", "Couldn\'t understand NMControl.")
|
||||||
"MainWindow",
|
|
||||||
"Couldn\'t understand NMControl."
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sys.exit("Unsupported Namecoin type")
|
sys.exit("Unsupported Namecoin type")
|
||||||
|
|
||||||
return message
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.info("Namecoin connection test failure")
|
logger.info("Namecoin connection test failure")
|
||||||
return (
|
return (
|
||||||
"failed",
|
'failed', _translate(
|
||||||
_translate(
|
|
||||||
"MainWindow", "The connection to namecoin failed.")
|
"MainWindow", "The connection to namecoin failed.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -245,26 +235,24 @@ class namecoinConnection(object):
|
||||||
"Authorization", "Basic %s" % base64.b64encode(authstr))
|
"Authorization", "Basic %s" % base64.b64encode(authstr))
|
||||||
self.con.endheaders()
|
self.con.endheaders()
|
||||||
self.con.send(data)
|
self.con.send(data)
|
||||||
except: # noqa:E722
|
|
||||||
logger.info("HTTP connection error")
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = self.con.getresponse()
|
resp = self.con.getresponse()
|
||||||
result = resp.read()
|
result = resp.read()
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Namecoin returned status"
|
"Namecoin returned status %i: %s" %
|
||||||
" %i: %s" % (resp.status, resp.reason))
|
(resp.status, resp.reason))
|
||||||
except: # noqa:E722
|
except: # noqa:E722
|
||||||
logger.info("HTTP receive error")
|
logger.info("HTTP receive error")
|
||||||
return None
|
except: # noqa:E722
|
||||||
|
logger.info("HTTP connection error")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def queryServer(self, data):
|
def queryServer(self, data):
|
||||||
"""Helper routine sending data to the RPC "
|
"""
|
||||||
"server and returning the result."""
|
Helper routine sending data to the RPC server and returning the result.
|
||||||
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
@ -296,23 +284,24 @@ def lookupNamecoinFolder():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
app = "namecoin"
|
app = "namecoin"
|
||||||
from os import path, environ
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
if "HOME" in environ:
|
try:
|
||||||
dataFolder = path.join(os.environ["HOME"],
|
dataFolder = os.path.join(
|
||||||
"Library/Application Support/", app) + "/"
|
os.getenv("HOME"), "Library/Application Support/", app)
|
||||||
else:
|
except TypeError: # getenv is None
|
||||||
sys.exit(
|
sys.exit(
|
||||||
"Could not find home folder, please report this message"
|
"Could not find home folder, please report this message"
|
||||||
" and your OS X version to the BitMessage Github."
|
" and your OS X version to the BitMessage Github."
|
||||||
|
) # TODO: remove exits from utility modules
|
||||||
|
|
||||||
|
dataFolder = (
|
||||||
|
os.path.join(os.getenv("APPDATA"), app)
|
||||||
|
if sys.platform.startswith('win') else
|
||||||
|
os.path.join(os.getenv("HOME"), ".%s" % app)
|
||||||
)
|
)
|
||||||
|
|
||||||
elif "win32" in sys.platform or "win64" in sys.platform:
|
return dataFolder + os.path.sep
|
||||||
dataFolder = path.join(environ["APPDATA"], app) + "\\"
|
|
||||||
else:
|
|
||||||
dataFolder = path.join(environ["HOME"], ".%s" % app) + "/"
|
|
||||||
|
|
||||||
return dataFolder
|
|
||||||
|
|
||||||
|
|
||||||
def ensureNamecoinOptions():
|
def ensureNamecoinOptions():
|
||||||
|
@ -357,8 +346,8 @@ def ensureNamecoinOptions():
|
||||||
nmc.close()
|
nmc.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"%s unreadable or missing, Namecoin support deactivated",
|
"%s unreadable or missing, Namecoin support deactivated", nmcConfig
|
||||||
nmcConfig)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning("Error processing namecoin.conf", exc_info=True)
|
logger.warning("Error processing namecoin.conf", exc_info=True)
|
||||||
|
|
||||||
|
@ -370,5 +359,5 @@ def ensureNamecoinOptions():
|
||||||
|
|
||||||
# Set default port now, possibly to found value.
|
# Set default port now, possibly to found value.
|
||||||
if not hasPort:
|
if not hasPort:
|
||||||
BMConfigParser().set(configSection, "namecoinrpcport",
|
BMConfigParser().set(
|
||||||
defaults.namecoinDefaultRpcPort)
|
configSection, "namecoinrpcport", defaults.namecoinDefaultRpcPort)
|
||||||
|
|
|
@ -138,9 +138,10 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
'updateStatusBar',
|
'updateStatusBar',
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"The time on your computer, %1, may be wrong. "
|
"The time on your computer, {0}, may be wrong. "
|
||||||
"Please verify your settings."
|
"Please verify your settings."
|
||||||
).arg(l10n.formatTimestamp())))
|
).format(l10n.formatTimestamp())
|
||||||
|
))
|
||||||
|
|
||||||
def state_connection_fully_established(self):
|
def state_connection_fully_established(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -266,9 +266,12 @@ class uPnPThread(StoppableThread):
|
||||||
with knownnodes.knownNodesLock:
|
with knownnodes.knownNodesLock:
|
||||||
knownnodes.addKnownNode(
|
knownnodes.addKnownNode(
|
||||||
1, self_peer, is_self=True)
|
1, self_peer, is_self=True)
|
||||||
queues.UISignalQueue.put(('updateStatusBar', tr._translate(
|
queues.UISignalQueue.put((
|
||||||
"MainWindow", 'UPnP port mapping established on port %1'
|
'updateStatusBar', tr._translate(
|
||||||
).arg(str(self.extPort))))
|
"MainWindow",
|
||||||
|
"UPnP port mapping established on port {0}"
|
||||||
|
).format(self.extPort)
|
||||||
|
))
|
||||||
break
|
break
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
|
|
Reference in New Issue
Block a user