Corrected style a bit
This commit is contained in:
parent
49985a435f
commit
625e83f4b4
|
@ -1,7 +1,6 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
import shared
|
import shared
|
||||||
import string
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
@ -34,13 +33,11 @@ class objectProcessor(threading.Thread):
|
||||||
objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads.
|
objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
# It may be the case that the last time Bitmessage was running,
|
||||||
It may be the case that the last time Bitmessage was running,
|
# the user closed it before it finished processing everything in the
|
||||||
the user closed it before it finished processing everything in the
|
# objectProcessorQueue. Assuming that Bitmessage wasn't closed
|
||||||
objectProcessorQueue. Assuming that Bitmessage wasn't closed
|
# forcefully, it should have saved the data in the queue into the
|
||||||
forcefully, it should have saved the data in the queue into the
|
# objectprocessorqueue table. Let's pull it out.
|
||||||
objectprocessorqueue table. Let's pull it out.
|
|
||||||
"""
|
|
||||||
threading.Thread.__init__(self, name="objectProcessor")
|
threading.Thread.__init__(self, name="objectProcessor")
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''SELECT objecttype, data FROM objectprocessorqueue''')
|
'''SELECT objecttype, data FROM objectprocessorqueue''')
|
||||||
|
@ -60,13 +57,13 @@ class objectProcessor(threading.Thread):
|
||||||
self.checkackdata(data)
|
self.checkackdata(data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if objectType == 0: # getpubkey
|
if objectType == protocol.OBJECT_GETPUBKEY:
|
||||||
self.processgetpubkey(data)
|
self.processgetpubkey(data)
|
||||||
elif objectType == 1: # pubkey
|
elif objectType == protocol.OBJECT_PUBKEY:
|
||||||
self.processpubkey(data)
|
self.processpubkey(data)
|
||||||
elif objectType == 2: # msg
|
elif objectType == protocol.OBJECT_MSG:
|
||||||
self.processmsg(data)
|
self.processmsg(data)
|
||||||
elif objectType == 3: # broadcast
|
elif objectType == protocol.OBJECT_BROADCAST:
|
||||||
self.processbroadcast(data)
|
self.processbroadcast(data)
|
||||||
# is more of a command, not an object type. Is used to get
|
# is more of a command, not an object type. Is used to get
|
||||||
# this thread past the queue.get() so that it will check
|
# this thread past the queue.get() so that it will check
|
||||||
|
@ -222,11 +219,8 @@ class objectProcessor(threading.Thread):
|
||||||
' chan addresses. The other party should already have'
|
' chan addresses. The other party should already have'
|
||||||
' the pubkey.')
|
' the pubkey.')
|
||||||
return
|
return
|
||||||
try:
|
lastPubkeySendTime = BMConfigParser().safeGetInt(
|
||||||
lastPubkeySendTime = int(BMConfigParser().get(
|
myAddress, 'lastpubkeysendtime')
|
||||||
myAddress, 'lastpubkeysendtime'))
|
|
||||||
except:
|
|
||||||
lastPubkeySendTime = 0
|
|
||||||
# If the last time we sent our pubkey was more recent than
|
# If the last time we sent our pubkey was more recent than
|
||||||
# 28 days ago...
|
# 28 days ago...
|
||||||
if lastPubkeySendTime > time.time() - 2419200:
|
if lastPubkeySendTime > time.time() - 2419200:
|
||||||
|
@ -472,8 +466,8 @@ class objectProcessor(threading.Thread):
|
||||||
return
|
return
|
||||||
|
|
||||||
# This is a message bound for me.
|
# This is a message bound for me.
|
||||||
toAddress = shared.myAddressesByHash[
|
# Look up my address based on the RIPE hash.
|
||||||
toRipe] # Look up my address based on the RIPE hash.
|
toAddress = shared.myAddressesByHash[toRipe]
|
||||||
readPosition = 0
|
readPosition = 0
|
||||||
sendersAddressVersionNumber, sendersAddressVersionNumberLength = \
|
sendersAddressVersionNumber, sendersAddressVersionNumberLength = \
|
||||||
decodeVarint(decryptedData[readPosition:readPosition + 10])
|
decodeVarint(decryptedData[readPosition:readPosition + 10])
|
||||||
|
@ -500,11 +494,9 @@ class objectProcessor(threading.Thread):
|
||||||
return
|
return
|
||||||
readPosition += sendersStreamNumberLength
|
readPosition += sendersStreamNumberLength
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
pubSigningKey = '\x04' + decryptedData[
|
pubSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition:readPosition + 64]
|
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
pubEncryptionKey = '\x04' + decryptedData[
|
pubEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition:readPosition + 64]
|
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
if sendersAddressVersionNumber >= 3:
|
if sendersAddressVersionNumber >= 3:
|
||||||
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = \
|
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = \
|
||||||
|
@ -829,7 +821,7 @@ class objectProcessor(threading.Thread):
|
||||||
time.time() - messageProcessingStartTime)
|
time.time() - messageProcessingStartTime)
|
||||||
return
|
return
|
||||||
elif broadcastVersion == 5:
|
elif broadcastVersion == 5:
|
||||||
embeddedTag = data[readPosition:readPosition+32]
|
embeddedTag = data[readPosition:readPosition + 32]
|
||||||
readPosition += 32
|
readPosition += 32
|
||||||
if embeddedTag not in shared.MyECSubscriptionCryptorObjects:
|
if embeddedTag not in shared.MyECSubscriptionCryptorObjects:
|
||||||
logger.debug('We\'re not interested in this broadcast.')
|
logger.debug('We\'re not interested in this broadcast.')
|
||||||
|
@ -917,10 +909,10 @@ class objectProcessor(threading.Thread):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
elif broadcastVersion == 5:
|
elif broadcastVersion == 5:
|
||||||
calculatedTag = hashlib.sha512(hashlib.sha512(encodeVarint(
|
calculatedTag = hashlib.sha512(hashlib.sha512(
|
||||||
sendersAddressVersion) + encodeVarint(sendersStream)
|
encodeVarint(sendersAddressVersion) +
|
||||||
+ calculatedRipe).digest()
|
encodeVarint(sendersStream) + calculatedRipe
|
||||||
).digest()[32:]
|
).digest()).digest()[32:]
|
||||||
if calculatedTag != embeddedTag:
|
if calculatedTag != embeddedTag:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'The tag and encryption key used to encrypt this'
|
'The tag and encryption key used to encrypt this'
|
||||||
|
@ -1034,9 +1026,8 @@ class objectProcessor(threading.Thread):
|
||||||
# for it.
|
# for it.
|
||||||
elif addressVersion >= 4:
|
elif addressVersion >= 4:
|
||||||
tag = hashlib.sha512(hashlib.sha512(
|
tag = hashlib.sha512(hashlib.sha512(
|
||||||
encodeVarint(addressVersion) + encodeVarint(streamNumber)
|
encodeVarint(addressVersion) + encodeVarint(streamNumber) + ripe
|
||||||
+ ripe).digest()
|
).digest()).digest()[32:]
|
||||||
).digest()[32:]
|
|
||||||
if tag in state.neededPubkeys:
|
if tag in state.neededPubkeys:
|
||||||
del state.neededPubkeys[tag]
|
del state.neededPubkeys[tag]
|
||||||
self.sendMessages(address)
|
self.sendMessages(address)
|
||||||
|
@ -1098,19 +1089,3 @@ class objectProcessor(threading.Thread):
|
||||||
return subject
|
return subject
|
||||||
else:
|
else:
|
||||||
return '[' + mailingListName + '] ' + subject
|
return '[' + mailingListName + '] ' + subject
|
||||||
|
|
||||||
def decodeType2Message(self, message):
|
|
||||||
bodyPositionIndex = string.find(message, '\nBody:')
|
|
||||||
if bodyPositionIndex > 1:
|
|
||||||
subject = message[8:bodyPositionIndex]
|
|
||||||
# Only save and show the first 500 characters of the subject.
|
|
||||||
# Any more is probably an attack.
|
|
||||||
subject = subject[:500]
|
|
||||||
body = message[bodyPositionIndex + 6:]
|
|
||||||
else:
|
|
||||||
subject = ''
|
|
||||||
body = message
|
|
||||||
# Throw away any extra lines (headers) after the subject.
|
|
||||||
if subject:
|
|
||||||
subject = subject.splitlines()[0]
|
|
||||||
return subject, body
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user