Merge branch 'master' of github.com:Atheros1/PyBitmessage

This commit is contained in:
Jonathan Warren 2012-12-10 14:50:23 -05:00
commit 48187170d7

View File

@ -79,7 +79,9 @@ class outgoingSynSender(QThread):
resetTime = int(time.time()) resetTime = int(time.time())
self.alreadyAttemptedConnectionsList.append(HOST) self.alreadyAttemptedConnectionsList.append(HOST)
PORT, timeNodeLastSeen = knownNodes[self.streamNumber][HOST] PORT, timeNodeLastSeen = knownNodes[self.streamNumber][HOST]
printLock.acquire()
print 'Trying an outgoing connection to', HOST, ':', PORT print 'Trying an outgoing connection to', HOST, ':', PORT
printLock.release()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: try:
sock.connect((HOST, PORT)) sock.connect((HOST, PORT))
@ -87,7 +89,9 @@ class outgoingSynSender(QThread):
self.emit(SIGNAL("passObjectThrough(PyQt_PyObject)"),rd) self.emit(SIGNAL("passObjectThrough(PyQt_PyObject)"),rd)
rd.setup(sock,HOST,PORT,self.streamNumber,self.selfInitiatedConnectionList) rd.setup(sock,HOST,PORT,self.streamNumber,self.selfInitiatedConnectionList)
rd.start() rd.start()
printLock.acquire()
print self, 'connected to', HOST, 'during outgoing attempt.' print self, 'connected to', HOST, 'during outgoing attempt.'
printLock.release()
sd = sendDataThread() sd = sendDataThread()
sd.setup(sock,HOST,PORT,self.streamNumber) sd.setup(sock,HOST,PORT,self.streamNumber)
@ -380,10 +384,6 @@ class receiveDataThread(QThread):
#We have received a broadcast message #We have received a broadcast message
def recbroadcast(self): def recbroadcast(self):
#First we must check to make sure the proof of work is sufficient. #First we must check to make sure the proof of work is sufficient.
#POW, = unpack('>Q',hashlib.sha512(self.data[24:24+self.payloadLength]).digest()[4:12])
#if POW > 2**64 / ((self.payloadLength+payloadLengthExtraBytes) * averageProofOfWorkNonceTrialsPerByte):
# print 'The proof of work in this broadcast message is insufficient. Ignoring message.'
# return
if not self.isProofOfWorkSufficient(): if not self.isProofOfWorkSufficient():
print 'Proof of work in broadcast message insufficient.' print 'Proof of work in broadcast message insufficient.'
return return
@ -506,12 +506,6 @@ class receiveDataThread(QThread):
#We have received a msg message. #We have received a msg message.
def recmsg(self): def recmsg(self):
#First we must check to make sure the proof of work is sufficient. #First we must check to make sure the proof of work is sufficient.
#POW, = unpack('>Q',hashlib.sha512(self.data[24:24+self.payloadLength]).digest()[4:12])
#print 'POW:', POW
#if POW > 2**64 / ((self.payloadLength+payloadLengthExtraBytes) * averageProofOfWorkNonceTrialsPerByte):
# print 'Proof of work in msg message insufficient.'
# return
if not self.isProofOfWorkSufficient(): if not self.isProofOfWorkSufficient():
print 'Proof of work in msg message insufficient.' print 'Proof of work in msg message insufficient.'
return return
@ -628,7 +622,9 @@ class receiveDataThread(QThread):
readPosition += ackLength readPosition += ackLength
payloadSigniture = data[readPosition:readPosition+sendersNLength] #We're using the length of the sender's n because it should match the signiture size. payloadSigniture = data[readPosition:readPosition+sendersNLength] #We're using the length of the sender's n because it should match the signiture size.
sendersPubkey = rsa.PublicKey(convertStringToInt(sendersN),convertStringToInt(sendersE)) sendersPubkey = rsa.PublicKey(convertStringToInt(sendersN),convertStringToInt(sendersE))
print 'senders Pubkey', sendersPubkey print 'sender\'s Pubkey', sendersPubkey
#Check the cryptographic signiture
verifyPassed = False verifyPassed = False
try: try:
rsa.verify(data[:-len(payloadSigniture)],payloadSigniture, sendersPubkey) rsa.verify(data[:-len(payloadSigniture)],payloadSigniture, sendersPubkey)
@ -643,9 +639,9 @@ class receiveDataThread(QThread):
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
ripe.update(sha.digest()) ripe.update(sha.digest())
#We have reached the end of the public key. Let's store it in case we want to reply to this person. #Let's store the public key in case we want to reply to this person.
#We don't have the correct nonce in order to send out a pubkey message so we'll just fill it with 1's. We won't be able to send this pubkey to others (without doing the proof of work ourselves, which this program is programmed to not do.) #We don't have the correct nonce in order to send out a pubkey message so we'll just fill it with 1's. We won't be able to send this pubkey to others (without doing the proof of work ourselves, which this program is programmed to not do.)
t = (ripe.digest(),False,'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'+data[20+messageVersionLength:endOfThePublicKeyPosition],int(time.time())+2419200) #after one month we may remove this pub key from our database. t = (ripe.digest(),False,'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'+data[20+messageVersionLength:endOfThePublicKeyPosition],int(time.time())+2419200) #after one month we may remove this pub key from our database. (2419200 = a month)
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put('''INSERT INTO pubkeys VALUES (?,?,?,?)''') sqlSubmitQueue.put('''INSERT INTO pubkeys VALUES (?,?,?,?)''')
sqlSubmitQueue.put(t) sqlSubmitQueue.put(t)
@ -654,7 +650,7 @@ class receiveDataThread(QThread):
blockMessage = False #Gets set to True if the user shouldn't see the message according to black or white lists. blockMessage = False #Gets set to True if the user shouldn't see the message according to black or white lists.
fromAddress = encodeAddress(sendersAddressVersionNumber,sendersStreamNumber,ripe.digest()) fromAddress = encodeAddress(sendersAddressVersionNumber,sendersStreamNumber,ripe.digest())
if config.get('bitmessagesettings', 'blackwhitelist') == 'black': if config.get('bitmessagesettings', 'blackwhitelist') == 'black': #If we are using a blacklist
t = (fromAddress,) t = (fromAddress,)
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put('''SELECT label, enabled FROM blacklist where address=?''') sqlSubmitQueue.put('''SELECT label, enabled FROM blacklist where address=?''')
@ -686,10 +682,10 @@ class receiveDataThread(QThread):
print 'fromAddress:', fromAddress print 'fromAddress:', fromAddress
print 'First 150 characters of message:', repr(message[:150]) print 'First 150 characters of message:', repr(message[:150])
#Now I would like to find the destination address (my address). Right now all I have is the ripe hash. I realize that I #Look up the destination address (my address) based on the destination ripe hash.
#could have a data structure devoted to this task, or maintain an indexed table in the sql database, but I would prefer to #I realize that I could have a data structure devoted to this task, or maintain an indexed table
#minimize the number of data structures this program uses, and searching linearly through a short list for each message #in the sql database, but I would prefer to minimize the number of data structures this program
#received doesn't take very long anyway. #uses. Searching linearly through the user's short list of addresses doesn't take very long anyway.
configSections = config.sections() configSections = config.sections()
for addressInKeysFile in configSections: for addressInKeysFile in configSections:
if addressInKeysFile <> 'bitmessagesettings': if addressInKeysFile <> 'bitmessagesettings':
@ -1091,7 +1087,7 @@ class receiveDataThread(QThread):
numberOfAddressesIncluded, lengthOfNumberOfAddresses = decodeVarint(self.data[24:29]) numberOfAddressesIncluded, lengthOfNumberOfAddresses = decodeVarint(self.data[24:29])
if verbose >= 1: if verbose >= 1:
print 'addr message contains', numberOfAddressesIncluded, 'addresses.' print 'addr message contains', numberOfAddressesIncluded, 'IP addresses.'
#print 'lengthOfNumberOfAddresses', lengthOfNumberOfAddresses #print 'lengthOfNumberOfAddresses', lengthOfNumberOfAddresses
if numberOfAddressesIncluded > 1000: if numberOfAddressesIncluded > 1000:
@ -2344,8 +2340,9 @@ class MyForm(QtGui.QMainWindow):
newItem.setData(Qt.UserRole,unicode(message,'utf-8)')) newItem.setData(Qt.UserRole,unicode(message,'utf-8)'))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetInbox.setItem(0,2,newItem) self.ui.tableWidgetInbox.setItem(0,2,newItem)
newItem = QtGui.QTableWidgetItem(strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(received)))) newItem = myTableWidgetItem(strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(received))))
newItem.setData(Qt.UserRole,QByteArray(msgid)) newItem.setData(Qt.UserRole,QByteArray(msgid))
newItem.setData(33,int(received))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetInbox.setItem(0,3,newItem) self.ui.tableWidgetInbox.setItem(0,3,newItem)
#self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject()) #self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject())
@ -2393,20 +2390,21 @@ class MyForm(QtGui.QMainWindow):
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetSent.setItem(0,2,newItem) self.ui.tableWidgetSent.setItem(0,2,newItem)
if status == 'findingpubkey': if status == 'findingpubkey':
newItem = QtGui.QTableWidgetItem('Waiting on their public key. Will request it again soon.') newItem = myTableWidgetItem('Waiting on their public key. Will request it again soon.')
elif status == 'sentmessage': elif status == 'sentmessage':
newItem = QtGui.QTableWidgetItem('Message sent. Waiting on acknowledgement. Sent at ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(lastactiontime))) newItem = myTableWidgetItem('Message sent. Waiting on acknowledgement. Sent at ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(lastactiontime)))
elif status == 'doingpow': elif status == 'doingpow':
newItem = QtGui.QTableWidgetItem('Need to do work to send message. Work is queued.') newItem = myTableWidgetItem('Need to do work to send message. Work is queued.')
elif status == 'ackreceived': elif status == 'ackreceived':
newItem = QtGui.QTableWidgetItem('Acknowledgement of the message received ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(lastactiontime)))) newItem = myTableWidgetItem('Acknowledgement of the message received ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(lastactiontime))))
elif status == 'broadcastpending': elif status == 'broadcastpending':
newItem = QtGui.QTableWidgetItem('Doing the work necessary to send broadcast...') newItem = myTableWidgetItem('Doing the work necessary to send broadcast...')
elif status == 'broadcastsent': elif status == 'broadcastsent':
newItem = QtGui.QTableWidgetItem('Broadcast on ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(lastactiontime)))) newItem = myTableWidgetItem('Broadcast on ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(lastactiontime))))
else: else:
newItem = QtGui.QTableWidgetItem('Unknown status. ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(lastactiontime)))) newItem = myTableWidgetItem('Unknown status. ' + strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(lastactiontime))))
newItem.setData(Qt.UserRole,ackdata) newItem.setData(Qt.UserRole,ackdata)
newItem.setData(33,int(lastactiontime))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetSent.setItem(0,3,newItem) self.ui.tableWidgetSent.setItem(0,3,newItem)
@ -2735,8 +2733,9 @@ class MyForm(QtGui.QMainWindow):
newItem = QtGui.QTableWidgetItem(unicode(subject,'utf-8)')) newItem = QtGui.QTableWidgetItem(unicode(subject,'utf-8)'))
newItem.setData(Qt.UserRole,unicode(message,'utf-8)')) newItem.setData(Qt.UserRole,unicode(message,'utf-8)'))
self.ui.tableWidgetSent.setItem(0,2,newItem) self.ui.tableWidgetSent.setItem(0,2,newItem)
newItem = QtGui.QTableWidgetItem('Just pressed ''send'' '+strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time())))) newItem = myTableWidgetItem('Just pressed ''send'' '+strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time()))))
newItem.setData(Qt.UserRole,ackdata) newItem.setData(Qt.UserRole,ackdata)
newItem.setData(33,int(time.time()))
self.ui.tableWidgetSent.setItem(0,3,newItem) self.ui.tableWidgetSent.setItem(0,3,newItem)
self.ui.textEditSentMessage.setText(self.ui.tableWidgetSent.item(0,2).data(Qt.UserRole).toPyObject()) self.ui.textEditSentMessage.setText(self.ui.tableWidgetSent.item(0,2).data(Qt.UserRole).toPyObject())
@ -2915,8 +2914,9 @@ class MyForm(QtGui.QMainWindow):
newItem = QtGui.QTableWidgetItem(unicode(subject,'utf-8)')) newItem = QtGui.QTableWidgetItem(unicode(subject,'utf-8)'))
newItem.setData(Qt.UserRole,unicode(message,'utf-8)')) newItem.setData(Qt.UserRole,unicode(message,'utf-8)'))
self.ui.tableWidgetInbox.setItem(0,2,newItem) self.ui.tableWidgetInbox.setItem(0,2,newItem)
newItem = QtGui.QTableWidgetItem(strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time())))) newItem = myTableWidgetItem(strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time()))))
newItem.setData(Qt.UserRole,QByteArray(inventoryHash)) newItem.setData(Qt.UserRole,QByteArray(inventoryHash))
newItem.setData(33,int(time.time()))
self.ui.tableWidgetInbox.setItem(0,3,newItem) self.ui.tableWidgetInbox.setItem(0,3,newItem)
self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject()) self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject())
@ -3331,13 +3331,11 @@ class MyForm(QtGui.QMainWindow):
def tableWidgetYourIdentitiesItemChanged(self): def tableWidgetYourIdentitiesItemChanged(self):
currentRow = self.ui.tableWidgetYourIdentities.currentRow() currentRow = self.ui.tableWidgetYourIdentities.currentRow()
try: if currentRow >= 0:
addressAtCurrentRow = self.ui.tableWidgetYourIdentities.item(currentRow,1).text() addressAtCurrentRow = self.ui.tableWidgetYourIdentities.item(currentRow,1).text()
config.set(str(addressAtCurrentRow),'label',str(self.ui.tableWidgetYourIdentities.item(currentRow,0).text().toUtf8())) config.set(str(addressAtCurrentRow),'label',str(self.ui.tableWidgetYourIdentities.item(currentRow,0).text().toUtf8()))
with open(appdata + 'keys.dat', 'wb') as configfile: with open(appdata + 'keys.dat', 'wb') as configfile:
config.write(configfile) config.write(configfile)
except Exception, err:
print 'Program Exception in tableWidgetYourIdentitiesItemChanged:', err
self.rerenderComboBoxSendFrom() self.rerenderComboBoxSendFrom()
#self.rerenderInboxFromLabels() #self.rerenderInboxFromLabels()
self.rerenderInboxToLabels() self.rerenderInboxToLabels()
@ -3420,6 +3418,10 @@ class MyForm(QtGui.QMainWindow):
status,addressVersionNumber,streamNumber,hash = decodeAddress(address) status,addressVersionNumber,streamNumber,hash = decodeAddress(address)
broadcastSendersForWhichImWatching[hash] = 0 broadcastSendersForWhichImWatching[hash] = 0
#In order for the time columns on the Inbox and Sent tabs to be sorted correctly (rather than alphabetically), we need to overload the < operator and use this class instead of QTableWidgetItem.
class myTableWidgetItem(QTableWidgetItem):
def __lt__(self,other):
return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject())
sendDataQueues = [] #each sendData thread puts its queue in this list. sendDataQueues = [] #each sendData thread puts its queue in this list.