From 396df086ffbccecfd1fe2a7f48837ded3a3622e5 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 3 Apr 2013 12:59:43 -0400 Subject: [PATCH 1/3] refactor sendData function --- bitmessagemain.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index 92f88e01..5738ccdb 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -1287,37 +1287,30 @@ class receiveDataThread(QThread): print 'sending pubkey' headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData += 'pubkey\x00\x00\x00\x00\x00\x00' - headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. + headerData += pack('>L',len(payload)) #payload length. headerData += hashlib.sha512(payload).digest()[:4] self.sock.send(headerData + payload) - elif objectType == 'getpubkey': + elif objectType == 'getpubkey' or objectType == 'pubkeyrequest': print 'sending getpubkey' headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData += 'getpubkey\x00\x00\x00' - headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. + headerData += pack('>L',len(payload)) #payload length. headerData += hashlib.sha512(payload).digest()[:4] self.sock.send(headerData + payload) elif objectType == 'msg': print 'sending msg' headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData += 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00' - headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. + headerData += pack('>L',len(payload)) #payload length. headerData += hashlib.sha512(payload).digest()[:4] self.sock.send(headerData + payload) elif objectType == 'broadcast': print 'sending broadcast' headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData += 'broadcast\x00\x00\x00' - headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. + headerData += pack('>L',len(payload)) #payload length. headerData += hashlib.sha512(payload).digest()[:4] self.sock.send(headerData + payload) - elif objectType == 'getpubkey' or objectType == 'pubkeyrequest': - print 'sending getpubkey' - headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. - headerData += 'getpubkey\x00\x00\x00' #version command - headerData += pack('>L',len(payload)) #payload length - headerData += hashlib.sha512(payload).digest()[0:4] - self.sock.send(headerData + payload) else: sys.stderr.write('Error: sendData has been asked to send a strange objectType: %s\n' % str(objectType)) -- 2.45.1 From 58175b90e730d6a19aefeaa29409370e7c6e1b2e Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 4 Apr 2013 12:32:25 -0400 Subject: [PATCH 2/3] UTC time in pseudo-mailing-list broadcasts --- bitmessagemain.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index 5738ccdb..c082b037 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -46,7 +46,7 @@ import pickle import random import sqlite3 import threading #used for the locks, not for the threads -from time import strftime, localtime +from time import strftime, localtime, gmtime import os import shutil #used for moving the messages.dat file import string @@ -944,8 +944,8 @@ class receiveDataThread(QThread): #Let us send out this message as a broadcast subject = self.addMailingListNameToSubject(subject,mailingListName) #Let us now send this message out as a broadcast - message = 'Message ostensibly from ' + fromAddress + ':\n\n' + body - fromAddress = toAddress #The fromAddress for the broadcast is the toAddress (my address) for the msg message we are currently processing. + message = strftime("%a, %Y-%m-%d %H:%M:%S UTC",gmtime()) + ' Message ostensibly from ' + fromAddress + ':\n\n' + body + fromAddress = toAddress #The fromAddress for the broadcast that we are about to send is the toAddress (my address) for the msg message we are currently processing. ackdata = OpenSSL.rand(32) #We don't actually need the ackdata for acknowledgement since this is a broadcast message but we can use it to update the user interface when the POW is done generating. toAddress = '[Broadcast subscribers]' ripe = '' @@ -4643,20 +4643,16 @@ class MyForm(QtGui.QMainWindow): raise SystemExit def on_action_InboxMessageForceHtml(self): - # Updated to work with all characters. Previously, non-english characters caused errors. - try: - lines = str(self.ui.textEditInboxMessage.toPlainText()).split('\n') - except UnicodeEncodeError: - currentInboxRow = self.ui.tableWidgetInbox.currentRow() - self.ui.textEditInboxMessage.setHtml(self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject()) - return - from_prefix = 'Message ostensibly from ' + currentInboxRow = self.ui.tableWidgetInbox.currentRow() + lines = self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject().split('\n') for i in xrange(len(lines)): - if lines[i].find(from_prefix) != -1: - lines[i] = '

%s%s

' % (from_prefix,lines[i][24:-1]) + if lines[i].contains('Message ostensibly from '): + lines[i] = '

%s

' % (lines[i]) elif lines[i] == '------------------------------------------------------': lines[i] = '
' - content = '\n'.join(lines) + content = '' + for i in xrange(len(lines)): + content += lines[i] + '
' content = content.replace('\n\n', '

') self.ui.textEditInboxMessage.setHtml(QtCore.QString(content)) -- 2.45.1 From b204de9949a01c72724f5a4659213f92a8acd673 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 4 Apr 2013 12:43:45 -0400 Subject: [PATCH 3/3] strip addresses before use rather than saying invalid characters --- addresses.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/addresses.py b/addresses.py index b29748aa..d3423503 100644 --- a/addresses.py +++ b/addresses.py @@ -122,14 +122,8 @@ def encodeAddress(version,stream,ripe): def decodeAddress(address): #returns (status, address version number, stream number, data (almost certainly a ripe hash)) - """#check for the BM- at the front of the address. If it isn't there, this address might be for a different version of Bitmessage - if address[:3] != 'BM-': - status = 'missingbm' - return status,0,0,0 - #take off the BM- - integer = decodeBase58(address[3:])""" + address = str(address).strip() - #changed Bitmessage to accept addresses that lack the "BM-" prefix. if address[:3] == 'BM-': integer = decodeBase58(address[3:]) else: @@ -189,6 +183,7 @@ def decodeAddress(address): return status,addressVersionNumber,streamNumber,'\x00\x00'+data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4] def addBMIfNotPresent(address): + address = str(address).strip() if address[:3] != 'BM-': return 'BM-'+address else: -- 2.45.1