Merge pull request #21 from Atheros1/master

Various small changes
This commit is contained in:
Jonathan Warren 2013-01-04 14:37:15 -08:00
commit fa9397f89d
5 changed files with 112 additions and 98 deletions

View File

@ -5,7 +5,7 @@
#Right now, PyBitmessage only support connecting to stream 1. It doesn't yet contain logic to expand into further streams.
softwareVersion = '0.1.4'
softwareVersion = '0.1.5'
verbose = 2
maximumAgeOfAnObjectThatIAmWillingToAccept = 216000 #Equals two days and 12 hours.
lengthOfTimeToLeaveObjectsInInventory = 237600 #Equals two days and 18 hours. This should be longer than maximumAgeOfAnObjectThatIAmWillingToAccept so that we don't process messages twice.
@ -411,7 +411,7 @@ class receiveDataThread(QThread):
self.receivedgetbiginv = True
sqlLock.acquire()
#Select all hashes which are younger than two days old and in this stream.
t = (int(time.time())-172800,self.streamNumber)
t = (int(time.time())-maximumAgeOfObjectsThatIAdvertiseToOthers,self.streamNumber)
sqlSubmitQueue.put('''SELECT hash FROM inventory WHERE receivedtime>? and streamnumber=?''')
sqlSubmitQueue.put(t)
queryreturn = sqlReturnQueue.get()
@ -424,7 +424,7 @@ class receiveDataThread(QThread):
#print 'bigInvList:', bigInvList
for hash, storedValue in inventory.items():
objectType, streamNumber, payload, receivedTime = storedValue
if streamNumber == self.streamNumber and receivedTime > int(time.time())-172800:
if streamNumber == self.streamNumber and receivedTime > int(time.time())-maximumAgeOfObjectsThatIAdvertiseToOthers:
bigInvList[hash] = 0
numberOfObjectsInInvMessage = 0
payload = ''
@ -819,7 +819,7 @@ class receiveDataThread(QThread):
if ackDataValidThusFar:
print 'ackData is valid. Will process it.'
#self.data = self.data[:self.payloadLength+24] + ackData + self.data[self.payloadLength+24:]
self.ackDataThatWeHaveYetToSend.append(ackData) #When we have processed all data
self.ackDataThatWeHaveYetToSend.append(ackData) #When we have processed all data, the processData function will pop the ackData out and process it as if it is a message received from our peer.
#print 'self.data after:', repr(self.data)
'''if ackData[4:16] == 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00':
inventoryHash = calculateInventoryHash(ackData[24:])
@ -890,6 +890,9 @@ class receiveDataThread(QThread):
bitfieldBehaviors = self.data[readPosition:readPosition+4]
readPosition += 4 #for the bitfield of behaviors and features
addressVersion, varintLength = decodeVarint(self.data[readPosition:readPosition+10])
if addressVersion >= 2:
'This version of Bitmessgae cannot handle version', addressVersion,'addresses.'
return
readPosition += varintLength
streamNumber, varintLength = decodeVarint(self.data[readPosition:readPosition+10])
readPosition += varintLength
@ -930,6 +933,13 @@ class receiveDataThread(QThread):
if not self.isProofOfWorkSufficient():
print 'Proof of work in getpubkey message insufficient.'
return
embeddedTime, = unpack('>I',self.data[32:36])
if embeddedTime > int(time.time())+10800:
print 'The time in this getpubkey message is too new. Ignoring it. Time:', embeddedTime
return
if embeddedTime < int(time.time())-maximumAgeOfAnObjectThatIAmWillingToAccept:
print 'The time in this getpubkey message is too old. Ignoring it. Time:', embeddedTime
return
inventoryLock.acquire()
inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24])
if inventoryHash in inventory:
@ -942,25 +952,23 @@ class receiveDataThread(QThread):
return
objectType = 'pubkeyrequest'
inventory[inventoryHash] = (objectType, self.streamNumber, self.data[24:self.payloadLength+24], int(time.time()))
inventory[inventoryHash] = (objectType, self.streamNumber, self.data[24:self.payloadLength+24], embeddedTime)
inventoryLock.release()
#Now let us make sure that the getpubkey request isn't too old or with a fake (future) time.
embeddedTime, = unpack('>I',self.data[32:36])
if embeddedTime > int(time.time())+10800:
print 'The time in this getpubkey message is too new. Ignoring it. Time:', embeddedTime
return
if embeddedTime < int(time.time())-maximumAgeOfAnObjectThatIAmWillingToAccept:
print 'The time in this getpubkey message is too old. Ignoring it. Time:', embeddedTime
return
addressVersionNumber, addressVersionLength = decodeVarint(self.data[36:42])
if addressVersionNumber > 1:
print 'The addressVersionNumber of the pubkey is too high. Can\'t understand. Ignoring it.'
return
streamNumber, streamNumberLength = decodeVarint(self.data[36+addressVersionLength:42+addressVersionLength])
if streamNumber <> self.streamNumber:
print 'The streamNumber', streamNumber, 'doesn\'t match our stream number:', self.streamNumber
return
#This getpubkey request is valid so far. Forward to peers.
broadcastToSendDataQueues((self.streamNumber,'send',self.data[:self.payloadLength+24]))
if addressVersionNumber > 1:
print 'The addressVersionNumber of the pubkey is too high. Can\'t understand. Ignoring it.'
return
if self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength] in myAddressHashes:
print 'Found getpubkey requested hash in my list of hashes.'
#check to see whether we have already calculated the nonce and transmitted this key before
@ -1000,12 +1008,15 @@ class receiveDataThread(QThread):
sqlSubmitQueue.put(t)
queryreturn = sqlReturnQueue.get()
#Now that we have the key either from getting it earlier or making it and storing it ourselves...
#Now that we have the full pubkey message ready either from making it just now or making it earlier, we can send it out.
t = (self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength],) #this prevents SQL injection
sqlSubmitQueue.put('SELECT * FROM pubkeys WHERE hash=?')
sqlSubmitQueue.put('''SELECT * FROM pubkeys WHERE hash=? AND havecorrectnonce=1''')
sqlSubmitQueue.put(t)
queryreturn = sqlReturnQueue.get()
if queryreturn == []:
sys.stderr.write('Error: pubkey which we just put in our pubkey database suddenly is not there. Is the database malfunctioning?')
sqlLock.release()
return
for row in queryreturn:
hash, havecorrectnonce, payload, timeLastRequested = row
if timeLastRequested < int(time.time())+604800: #if the last time anyone asked about this hash was this week, extend the time.
@ -1022,11 +1033,11 @@ class receiveDataThread(QThread):
self.broadcastinv(inventoryHash)
else:
print 'Hash in getpubkey is not mine.'
print 'Hash in getpubkey request is not for any of my keys.'
#..but lets see if we have it stored from when it came in from someone else.
t = (self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength],) #this prevents SQL injection
sqlLock.acquire()
sqlSubmitQueue.put('''SELECT hash, time FROM pubkeys WHERE hash=? AND havecorrectnonce='True' ''')
sqlSubmitQueue.put('''SELECT hash, transmitdata, time FROM pubkeys WHERE hash=? AND havecorrectnonce=1''')
sqlSubmitQueue.put(t)
queryreturn = sqlReturnQueue.get()
sqlLock.release()
@ -1035,20 +1046,17 @@ class receiveDataThread(QThread):
print 'we have the public key. sending it.'
#We have it. Let's send it.
for row in queryreturn:
hash, timeLastRequested = row
hash, transmitdata, timeLastRequested = row
if timeLastRequested < int(time.time())+604800: #if the last time anyone asked about this hash was this week, extend the time.
t = (int(time.time())+604800,hash)
sqlSubmitQueue.put('''UPDATE pubkeys set time=? WHERE hash=? ''')
sqlSubmitQueue.put(t)
queryreturn = sqlReturnQueue.get()
inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24])
inventoryHash = calculateInventoryHash(transmitdata)
objectType = 'pubkey'
inventory[inventoryHash] = (objectType, self.streamNumber, self.data[24:self.payloadLength+24], int(time.time()))
inventory[inventoryHash] = (objectType, self.streamNumber, transmitdata, int(time.time()))
self.broadcastinv(inventoryHash)
else:
#We don't have it. We'll need to forward the getpubkey request to our peers.
print 'We don\' have the public key. Forwarding getpubkey message to peers.'
broadcastToSendDataQueues((self.streamNumber,'send',self.data[:self.payloadLength+24]))
#We have received an inv message
def recinv(self):
@ -1611,7 +1619,7 @@ class sqlThread(QThread):
self.cur.execute( '''CREATE TABLE whitelist (label text, address text, enabled bool)''' )
self.cur.execute( '''CREATE TABLE pubkeys (hash blob, havecorrectnonce bool, transmitdata blob, time blob, UNIQUE(hash, havecorrectnonce, transmitdata) ON CONFLICT REPLACE)''' )
self.cur.execute( '''CREATE TABLE inventory (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE)''' )
self.cur.execute( '''CREATE TABLE knownnodes (timelastseen int, stream int, services blob, host blob, port blob, UNIQUE(host) ON CONFLICT REPLACE)''' ) #This table isn't used in the program yet but I have a feeling that we'll need it.
self.cur.execute( '''CREATE TABLE knownnodes (timelastseen int, stream int, services blob, host blob, port blob, UNIQUE(host, stream, port) ON CONFLICT REPLACE)''' ) #This table isn't used in the program yet but I have a feeling that we'll need it.
self.conn.commit()
print 'Created messages database file'
@ -1895,6 +1903,7 @@ class singleWorker(QThread):
sqlLock.release()
for row in queryreturn:
toaddress, fromaddress, subject, message, ackdata = row
ackdataForWhichImWatching[ackdata] = 0
status,addressVersionNumber,toStreamNumber,hash = decodeAddress(toaddress)
#if hash == toRipe:
self.emit(SIGNAL("updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject)"),ackdata,'Doing work necessary to send the message.')
@ -2129,6 +2138,7 @@ class helpDialog(QtGui.QDialog):
self.ui.setupUi(self)
self.parent = parent
self.ui.labelHelpURI.setOpenExternalLinks(True)
QtGui.QWidget.resize(self,QtGui.QWidget.sizeHint(self))
class aboutDialog(QtGui.QDialog):
def __init__(self,parent):
@ -2230,6 +2240,7 @@ class NewAddressDialog(QtGui.QDialog):
#print self.parent.ui.tableWidgetYourIdentities.item(row-1,1).text()
self.ui.comboBoxExisting.addItem(self.parent.ui.tableWidgetYourIdentities.item(row-1,1).text())
row += 1
#QtGui.QWidget.resize(self,QtGui.QWidget.sizeHint(self))
@ -2784,7 +2795,6 @@ class MyForm(QtGui.QMainWindow):
for i in range(4): #This will make 32 bytes of random data.
random.seed()
ackdata += pack('>Q',random.randrange(1, 18446744073709551615))
ackdataForWhichImWatching[ackdata] = 0
sqlLock.acquire()
t = ('',toAddress,ripe,fromAddress,subject,message,ackdata,int(time.time()),'findingpubkey',1,1,'sent')
sqlSubmitQueue.put('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?)''')

26
help.py
View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'help.ui'
#
# Created: Mon Nov 19 12:25:18 2012
# Created: Wed Dec 19 15:53:53 2012
# by: PyQt4 UI code generator 4.9.4
#
# WARNING! All changes made in this file will be lost!
@ -17,19 +17,23 @@ except AttributeError:
class Ui_helpDialog(object):
def setupUi(self, helpDialog):
helpDialog.setObjectName(_fromUtf8("helpDialog"))
helpDialog.resize(335, 170)
helpDialog.resize(335, 96)
self.formLayout = QtGui.QFormLayout(helpDialog)
self.formLayout.setObjectName(_fromUtf8("formLayout"))
self.labelHelpURI = QtGui.QLabel(helpDialog)
self.labelHelpURI.setObjectName(_fromUtf8("labelHelpURI"))
self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.labelHelpURI)
self.label = QtGui.QLabel(helpDialog)
self.label.setWordWrap(True)
self.label.setObjectName(_fromUtf8("label"))
self.formLayout.setWidget(0, QtGui.QFormLayout.SpanningRole, self.label)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.formLayout.setItem(2, QtGui.QFormLayout.LabelRole, spacerItem)
self.buttonBox = QtGui.QDialogButtonBox(helpDialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 120, 281, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.label = QtGui.QLabel(helpDialog)
self.label.setGeometry(QtCore.QRect(30, 20, 291, 51))
self.label.setWordWrap(True)
self.label.setObjectName(_fromUtf8("label"))
self.labelHelpURI = QtGui.QLabel(helpDialog)
self.labelHelpURI.setGeometry(QtCore.QRect(30, 70, 301, 21))
self.labelHelpURI.setObjectName(_fromUtf8("labelHelpURI"))
self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.buttonBox)
self.retranslateUi(helpDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), helpDialog.accept)
@ -38,6 +42,6 @@ class Ui_helpDialog(object):
def retranslateUi(self, helpDialog):
helpDialog.setWindowTitle(QtGui.QApplication.translate("helpDialog", "Help", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("helpDialog", "As Bitmessage is a collaborative project, help can be found online in the Bitmessage Wiki:", None, QtGui.QApplication.UnicodeUTF8))
self.labelHelpURI.setText(QtGui.QApplication.translate("helpDialog", "<a href=\"http://Bitmessage.org/wiki/PyBitmessage_Help\">http://Bitmessage.org/wiki/PyBitmessage_Help</a>", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("helpDialog", "As Bitmessage is a collaborative project, help can be found online in the Bitmessage Wiki:", None, QtGui.QApplication.UnicodeUTF8))

63
help.ui
View File

@ -7,37 +7,22 @@
<x>0</x>
<y>0</y>
<width>335</width>
<height>170</height>
<height>96</height>
</rect>
</property>
<property name="windowTitle">
<string>Help</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>120</y>
<width>281</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="labelHelpURI">
<property name="text">
<string>&lt;a href=&quot;http://Bitmessage.org/wiki/PyBitmessage_Help&quot;&gt;http://Bitmessage.org/wiki/PyBitmessage_Help&lt;/a&gt;</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>291</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>As Bitmessage is a collaborative project, help can be found online in the Bitmessage Wiki:</string>
</property>
@ -45,19 +30,31 @@
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelHelpURI">
<property name="geometry">
<rect>
<x>30</x>
<y>70</y>
<width>301</width>
<height>21</height>
</rect>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="text">
<string>&lt;a href=&quot;http://Bitmessage.org/wiki/PyBitmessage_Help&quot;&gt;http://Bitmessage.org/wiki/PyBitmessage_Help&lt;/a&gt;</string>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'newaddressdialog.ui'
#
# Created: Tue Sep 25 16:40:04 2012
# Created: Wed Dec 19 15:55:07 2012
# by: PyQt4 UI code generator 4.9.4
#
# WARNING! All changes made in this file will be lost!
@ -17,39 +17,42 @@ except AttributeError:
class Ui_NewAddressDialog(object):
def setupUi(self, NewAddressDialog):
NewAddressDialog.setObjectName(_fromUtf8("NewAddressDialog"))
NewAddressDialog.resize(368, 257)
NewAddressDialog.resize(383, 258)
self.buttonBox = QtGui.QDialogButtonBox(NewAddressDialog)
self.buttonBox.setGeometry(QtCore.QRect(160, 220, 201, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.label = QtGui.QLabel(NewAddressDialog)
self.label.setGeometry(QtCore.QRect(10, 10, 351, 31))
self.label.setGeometry(QtCore.QRect(10, 0, 361, 41))
self.label.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft)
self.label.setWordWrap(True)
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(NewAddressDialog)
self.label_2.setGeometry(QtCore.QRect(20, 50, 301, 20))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.newaddresslabel = QtGui.QLineEdit(NewAddressDialog)
self.newaddresslabel.setGeometry(QtCore.QRect(20, 70, 341, 20))
self.newaddresslabel.setGeometry(QtCore.QRect(20, 70, 351, 20))
self.newaddresslabel.setObjectName(_fromUtf8("newaddresslabel"))
self.radioButtonMostAvailable = QtGui.QRadioButton(NewAddressDialog)
self.radioButtonMostAvailable.setGeometry(QtCore.QRect(20, 110, 401, 16))
self.radioButtonMostAvailable.setChecked(True)
self.radioButtonMostAvailable.setObjectName(_fromUtf8("radioButtonMostAvailable"))
self.radioButtonExisting = QtGui.QRadioButton(NewAddressDialog)
self.radioButtonExisting.setGeometry(QtCore.QRect(20, 150, 271, 18))
self.radioButtonExisting.setGeometry(QtCore.QRect(20, 150, 351, 18))
self.radioButtonExisting.setChecked(False)
self.radioButtonExisting.setObjectName(_fromUtf8("radioButtonExisting"))
self.label_3 = QtGui.QLabel(NewAddressDialog)
self.label_3.setGeometry(QtCore.QRect(33, 123, 331, 21))
self.label_3.setGeometry(QtCore.QRect(35, 127, 351, 20))
self.label_3.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.label_4 = QtGui.QLabel(NewAddressDialog)
self.label_4.setGeometry(QtCore.QRect(37, 167, 341, 16))
self.label_4.setGeometry(QtCore.QRect(37, 167, 351, 21))
self.label_4.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.comboBoxExisting = QtGui.QComboBox(NewAddressDialog)
self.comboBoxExisting.setEnabled(False)
self.comboBoxExisting.setGeometry(QtCore.QRect(40, 190, 321, 22))
self.comboBoxExisting.setGeometry(QtCore.QRect(40, 190, 331, 22))
self.comboBoxExisting.setEditable(True)
self.comboBoxExisting.setObjectName(_fromUtf8("comboBoxExisting"))
@ -61,7 +64,7 @@ class Ui_NewAddressDialog(object):
def retranslateUi(self, NewAddressDialog):
NewAddressDialog.setWindowTitle(QtGui.QApplication.translate("NewAddressDialog", "Create new Address", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("NewAddressDialog", "Here you may generate as many addresses as you like. Indeed, creating many addresses is encouraged.", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("NewAddressDialog", "Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged.", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("NewAddressDialog", "Label (not shown to anyone except you)", None, QtGui.QApplication.UnicodeUTF8))
self.radioButtonMostAvailable.setText(QtGui.QApplication.translate("NewAddressDialog", "Use the most available stream", None, QtGui.QApplication.UnicodeUTF8))
self.radioButtonExisting.setText(QtGui.QApplication.translate("NewAddressDialog", "Use the same stream as an existing address", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>257</height>
<width>383</width>
<height>258</height>
</rect>
</property>
<property name="windowTitle">