small changes and more inline comments

This commit is contained in:
Jonathan Warren 2013-02-04 16:49:02 -05:00
parent f05d2bfb01
commit 7791283f71
2 changed files with 92 additions and 94 deletions

View File

@ -235,7 +235,7 @@ class receiveDataThread(QThread):
self.selfInitiatedConnectionList.append(self) self.selfInitiatedConnectionList.append(self)
self.payloadLength = 0 #This is the protocol payload length thus it doesn't include the 24 byte message header self.payloadLength = 0 #This is the protocol payload length thus it doesn't include the 24 byte message header
self.receivedgetbiginv = False #Gets set to true once we receive a getbiginv message from our peer. An abusive peer might request it too much so we use this variable to check whether they have already asked for a big inv message. self.receivedgetbiginv = False #Gets set to true once we receive a getbiginv message from our peer. An abusive peer might request it too much so we use this variable to check whether they have already asked for a big inv message.
self.objectsThatWeHaveYetToGet = {} self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave = {}
connectedHostsList[self.HOST] = 0 #The very fact that this receiveData thread exists shows that we are connected to the remote host. Let's add it to this list so that the outgoingSynSender thread doesn't try to connect to it. connectedHostsList[self.HOST] = 0 #The very fact that this receiveData thread exists shows that we are connected to the remote host. Let's add it to this list so that the outgoingSynSender thread doesn't try to connect to it.
self.connectionIsOrWasFullyEstablished = False #set to true after the remote node and I accept each other's version messages. This is needed to allow the user interface to accurately reflect the current number of connections. self.connectionIsOrWasFullyEstablished = False #set to true after the remote node and I accept each other's version messages. This is needed to allow the user interface to accurately reflect the current number of connections.
if self.streamNumber == -1: #This was an incoming connection. Send out a version message if we accept the other node's version message. if self.streamNumber == -1: #This was an incoming connection. Send out a version message if we accept the other node's version message.
@ -357,27 +357,27 @@ class receiveDataThread(QThread):
self.data = self.data[self.payloadLength+24:]#take this message out and then process the next message self.data = self.data[self.payloadLength+24:]#take this message out and then process the next message
if self.data == '': if self.data == '':
while len(self.objectsThatWeHaveYetToGet) > 0: while len(self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave) > 0:
random.seed() random.seed()
objectHash, = random.sample(self.objectsThatWeHaveYetToGet, 1) objectHash, = random.sample(self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave, 1)
if objectHash in inventory: if objectHash in inventory:
printLock.acquire() printLock.acquire()
print 'Inventory (in memory) already has object listed in inv message.' print 'Inventory (in memory) already has object listed in inv message.'
printLock.release() printLock.release()
del self.objectsThatWeHaveYetToGet[objectHash] del self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave[objectHash]
elif isInSqlInventory(objectHash): elif isInSqlInventory(objectHash):
printLock.acquire() printLock.acquire()
print 'Inventory (SQL on disk) already has object listed in inv message.' print 'Inventory (SQL on disk) already has object listed in inv message.'
printLock.release() printLock.release()
del self.objectsThatWeHaveYetToGet[objectHash] del self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave[objectHash]
else: else:
#print 'processData function making request for object:', objectHash.encode('hex') #print 'processData function making request for object:', objectHash.encode('hex')
self.sendgetdata(objectHash) self.sendgetdata(objectHash)
del self.objectsThatWeHaveYetToGet[objectHash] #It is possible that the remote node doesn't respond with the object. In that case, we'll very likely get it from someone else anyway. del self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave[objectHash] #It is possible that the remote node doesn't respond with the object. In that case, we'll very likely get it from someone else anyway.
break break
if len(self.objectsThatWeHaveYetToGet) > 0: if len(self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave) > 0:
printLock.acquire() printLock.acquire()
print 'within processData, number of objectsThatWeHaveYetToGet is now', len(self.objectsThatWeHaveYetToGet) print 'within processData, number of objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave is now', len(self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave)
printLock.release() printLock.release()
if len(self.ackDataThatWeHaveYetToSend) > 0: if len(self.ackDataThatWeHaveYetToSend) > 0:
self.data = self.ackDataThatWeHaveYetToSend.pop() self.data = self.ackDataThatWeHaveYetToSend.pop()
@ -476,9 +476,9 @@ class receiveDataThread(QThread):
def sendinvMessageToJustThisOnePeer(self,numberOfObjects,payload): def sendinvMessageToJustThisOnePeer(self,numberOfObjects,payload):
payload = encodeVarint(numberOfObjects) + payload payload = encodeVarint(numberOfObjects) + payload
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'inv\x00\x00\x00\x00\x00\x00\x00\x00\x00' headerData += 'inv\x00\x00\x00\x00\x00\x00\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) headerData += pack('>L',len(payload))
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
print 'Sending huge inv message with', numberOfObjects, 'objects to just this one peer' print 'Sending huge inv message with', numberOfObjects, 'objects to just this one peer'
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
@ -500,7 +500,6 @@ class receiveDataThread(QThread):
return return
inventoryLock.acquire() inventoryLock.acquire()
inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24]) inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24])
self.objectsOfWhichThisRemoteNodeIsAlreadyAware[inventoryHash] = 0
if inventoryHash in inventory: if inventoryHash in inventory:
print 'We have already received this broadcast object. Ignoring.' print 'We have already received this broadcast object. Ignoring.'
inventoryLock.release() inventoryLock.release()
@ -699,11 +698,10 @@ class receiveDataThread(QThread):
readPosition += 4 readPosition += 4
streamNumberAsClaimedByMsg, streamNumberAsClaimedByMsgLength = decodeVarint(self.data[readPosition:readPosition+9]) streamNumberAsClaimedByMsg, streamNumberAsClaimedByMsgLength = decodeVarint(self.data[readPosition:readPosition+9])
if streamNumberAsClaimedByMsg != self.streamNumber: if streamNumberAsClaimedByMsg != self.streamNumber:
print 'The stream number encoded in this msg (' + streamNumberAsClaimedByMsg + ') message does not match the stream number on which it was received. Ignoring it.' print 'The stream number encoded in this msg (' + str(streamNumberAsClaimedByMsg) + ') message does not match the stream number on which it was received. Ignoring it.'
return return
readPosition += streamNumberAsClaimedByMsgLength readPosition += streamNumberAsClaimedByMsgLength
inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24]) inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24])
self.objectsOfWhichThisRemoteNodeIsAlreadyAware[inventoryHash] = 0
inventoryLock.acquire() inventoryLock.acquire()
if inventoryHash in inventory: if inventoryHash in inventory:
print 'We have already received this msg message. Ignoring.' print 'We have already received this msg message. Ignoring.'
@ -925,9 +923,9 @@ class receiveDataThread(QThread):
if ackDataValidThusFar: if ackDataValidThusFar:
print 'ackData is valid. Will process it.' print 'ackData is valid. Will process it.'
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. 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.
return
#This section is for my RSA keys (version 1 addresses). If we don't have any version 1 addresses it will never run. This code will soon be removed.
#This section is for my RSA keys (version 1 addresses). If we don't have any version 1 addresses, then it won't matter.
initialDecryptionSuccessful = False initialDecryptionSuccessful = False
infile = cStringIO.StringIO(self.data[readPosition:self.payloadLength+24]) infile = cStringIO.StringIO(self.data[readPosition:self.payloadLength+24])
outfile = cStringIO.StringIO() outfile = cStringIO.StringIO()
@ -1134,18 +1132,6 @@ class receiveDataThread(QThread):
print 'Proof of work in pubkey message insufficient.' print 'Proof of work in pubkey message insufficient.'
return return
inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24])
self.objectsOfWhichThisRemoteNodeIsAlreadyAware[inventoryHash] = 0
inventoryLock.acquire()
if inventoryHash in inventory:
print 'We have already received this pubkey. Ignoring it.'
inventoryLock.release()
return
elif isInSqlInventory(inventoryHash):
print 'We have already received this pubkey (it is stored on disk in the SQL inventory). Ignoring it.'
inventoryLock.release()
return
readPosition = 24 #for the message header readPosition = 24 #for the message header
readPosition += 8 #for the nonce readPosition += 8 #for the nonce
embeddedTime, = unpack('>I',self.data[readPosition:readPosition+4])#We currently are not checking the embeddedTime for any sort of validity in pubkey messages. embeddedTime, = unpack('>I',self.data[readPosition:readPosition+4])#We currently are not checking the embeddedTime for any sort of validity in pubkey messages.
@ -1158,6 +1144,16 @@ class receiveDataThread(QThread):
print 'stream number embedded in this pubkey doesn\'t match our stream number. Ignoring.' print 'stream number embedded in this pubkey doesn\'t match our stream number. Ignoring.'
return return
inventoryHash = calculateInventoryHash(self.data[24:self.payloadLength+24])
inventoryLock.acquire()
if inventoryHash in inventory:
print 'We have already received this pubkey. Ignoring it.'
inventoryLock.release()
return
elif isInSqlInventory(inventoryHash):
print 'We have already received this pubkey (it is stored on disk in the SQL inventory). Ignoring it.'
inventoryLock.release()
return
objectType = 'pubkey' objectType = 'pubkey'
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], int(time.time()))
inventoryLock.release() inventoryLock.release()
@ -1209,6 +1205,7 @@ class receiveDataThread(QThread):
printLock.release() printLock.release()
workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe)))
#This code which deals with old RSA addresses will soon be removed.
elif addressVersion == 1: elif addressVersion == 1:
nLength, varintLength = decodeVarint(self.data[readPosition:readPosition+10]) nLength, varintLength = decodeVarint(self.data[readPosition:readPosition+10])
readPosition += varintLength readPosition += varintLength
@ -1303,6 +1300,9 @@ class receiveDataThread(QThread):
queryreturn = sqlReturnQueue.get() queryreturn = sqlReturnQueue.get()
sqlLock.release() sqlLock.release()
printLock.acquire()
print 'We have the requested pubkey stored in our database of pubkeys. Sending it.'
printLock.release()
inventoryHash = calculateInventoryHash(payload) inventoryHash = calculateInventoryHash(payload)
objectType = 'pubkey' objectType = 'pubkey'
inventory[inventoryHash] = (objectType, self.streamNumber, payload, int(time.time())) inventory[inventoryHash] = (objectType, self.streamNumber, payload, int(time.time()))
@ -1314,7 +1314,7 @@ class receiveDataThread(QThread):
myAddress = encodeAddress(addressVersionNumber,streamNumber,self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength]) myAddress = encodeAddress(addressVersionNumber,streamNumber,self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength])
workerQueue.put(('doPOWForMyV2Pubkey',myAddress)) workerQueue.put(('doPOWForMyV2Pubkey',myAddress))
#This code which deals with old RSA addresses will soon be removed.
elif self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength] in myRSAAddressHashes: elif self.data[36+addressVersionLength+streamNumberLength:56+addressVersionLength+streamNumberLength] in myRSAAddressHashes:
print 'Found getpubkey requested hash in my list of RSA hashes.' print 'Found getpubkey requested hash in my list of RSA hashes.'
payload = '\x00\x00\x00\x01' #bitfield of features supported by me (see the wiki). payload = '\x00\x00\x00\x01' #bitfield of features supported by me (see the wiki).
@ -1369,19 +1369,18 @@ class receiveDataThread(QThread):
else: else:
print 'inv message lists', numberOfItemsInInv, 'objects.' print 'inv message lists', numberOfItemsInInv, 'objects.'
for i in range(numberOfItemsInInv): #upon finishing dealing with an incoming message, the receiveDataThread will request a random object from the peer. This way if we get multiple inv messages from multiple peers which list mostly the same objects, we will make getdata requests for different random objects from the various peers. for i in range(numberOfItemsInInv): #upon finishing dealing with an incoming message, the receiveDataThread will request a random object from the peer. This way if we get multiple inv messages from multiple peers which list mostly the same objects, we will make getdata requests for different random objects from the various peers.
#print 'Adding object to self.objectsThatWeHaveYetToGet.'
self.objectsOfWhichThisRemoteNodeIsAlreadyAware[self.data[24+lengthOfVarint+(32*i):56+lengthOfVarint+(32*i)]] = 0 self.objectsOfWhichThisRemoteNodeIsAlreadyAware[self.data[24+lengthOfVarint+(32*i):56+lengthOfVarint+(32*i)]] = 0
self.objectsThatWeHaveYetToGet[self.data[24+lengthOfVarint+(32*i):56+lengthOfVarint+(32*i)]] = 0 self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave[self.data[24+lengthOfVarint+(32*i):56+lengthOfVarint+(32*i)]] = 0
print 'length of objectsThatWeHaveYetToGet', len(self.objectsThatWeHaveYetToGet)
#Send a getdata message to our peer to request the object with the given hash #Send a getdata message to our peer to request the object with the given hash
def sendgetdata(self,hash): def sendgetdata(self,hash):
print 'sending getdata to retrieve object with hash:', hash.encode('hex') print 'sending getdata to retrieve object with hash:', hash.encode('hex')
payload = '\x01' + hash payload = '\x01' + hash
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'getdata\x00\x00\x00\x00\x00' headerData += 'getdata\x00\x00\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce.
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
#We have received a getdata request from our peer #We have received a getdata request from our peer
@ -1389,7 +1388,7 @@ class receiveDataThread(QThread):
value, lengthOfVarint = decodeVarint(self.data[24:34]) value, lengthOfVarint = decodeVarint(self.data[24:34])
#print 'Number of items in getdata request:', value #print 'Number of items in getdata request:', value
try: try:
for i in range(value): for i in xrange(value):
hash = self.data[24+lengthOfVarint+(i*32):56+lengthOfVarint+(i*32)] hash = self.data[24+lengthOfVarint+(i*32):56+lengthOfVarint+(i*32)]
printLock.acquire() printLock.acquire()
print 'received getdata request for item:', hash.encode('hex') print 'received getdata request for item:', hash.encode('hex')
@ -1420,37 +1419,37 @@ class receiveDataThread(QThread):
if objectType == 'pubkey': if objectType == 'pubkey':
print 'sending pubkey' print 'sending pubkey'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'pubkey\x00\x00\x00\x00\x00\x00' headerData += 'pubkey\x00\x00\x00\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce.
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
elif objectType == 'getpubkey': elif objectType == 'getpubkey':
print 'sending getpubkey' print 'sending getpubkey'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'getpubkey\x00\x00\x00' headerData += 'getpubkey\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce.
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
elif objectType == 'msg': elif objectType == 'msg':
print 'sending msg' print 'sending msg'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00' headerData += 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce.
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
elif objectType == 'broadcast': elif objectType == 'broadcast':
print 'sending broadcast' print 'sending broadcast'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'broadcast\x00\x00\x00' headerData += 'broadcast\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce.
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
elif objectType == 'getpubkey' or objectType == 'pubkeyrequest': elif objectType == 'getpubkey' or objectType == 'pubkeyrequest':
print 'sending getpubkey' print 'sending getpubkey'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'getpubkey\x00\x00\x00' #version command headerData += 'getpubkey\x00\x00\x00' #version command
headerData = headerData + pack('>L',len(payload)) #payload length headerData += pack('>L',len(payload)) #payload length
headerData = headerData + hashlib.sha512(payload).digest()[0:4] headerData += hashlib.sha512(payload).digest()[0:4]
self.sock.send(headerData + payload) self.sock.send(headerData + payload)
else: else:
sys.stderr.write('Error: sendData has been asked to send a strange objectType: %s\n' % str(objectType)) sys.stderr.write('Error: sendData has been asked to send a strange objectType: %s\n' % str(objectType))
@ -1841,9 +1840,9 @@ class sendDataThread(QThread):
if data not in self.objectsOfWhichThisRemoteNodeIsAlreadyAware: if data not in self.objectsOfWhichThisRemoteNodeIsAlreadyAware:
payload = '\x01' + data payload = '\x01' + data
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'inv\x00\x00\x00\x00\x00\x00\x00\x00\x00' headerData += 'inv\x00\x00\x00\x00\x00\x00\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) headerData += pack('>L',len(payload))
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
#To prevent some network analysis, 'leak' the data out to our peer after waiting a random amount of time #To prevent some network analysis, 'leak' the data out to our peer after waiting a random amount of time
random.seed() random.seed()
time.sleep(random.randrange(0, 10)) time.sleep(random.randrange(0, 10))
@ -2582,7 +2581,9 @@ class singleWorker(QThread):
payload += encodeVarint(addressVersionNumber) payload += encodeVarint(addressVersionNumber)
payload += encodeVarint(streamNumber) payload += encodeVarint(streamNumber)
payload += ripe payload += ripe
printLock.acquire()
print 'making request for pubkey with ripe:', ripe.encode('hex') print 'making request for pubkey with ripe:', ripe.encode('hex')
printLock.release()
nonce = 0 nonce = 0
trialValue = 99999999999999999999 trialValue = 99999999999999999999
#print 'trial value', trialValue #print 'trial value', trialValue
@ -2595,7 +2596,9 @@ class singleWorker(QThread):
while trialValue > target: while trialValue > target:
nonce += 1 nonce += 1
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8]) trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
printLock.acquire()
print 'Found proof of work', trialValue, 'Nonce:', nonce print 'Found proof of work', trialValue, 'Nonce:', nonce
printLock.release()
payload = pack('>Q',nonce) + payload payload = pack('>Q',nonce) + payload
inventoryHash = calculateInventoryHash(payload) inventoryHash = calculateInventoryHash(payload)
@ -2629,9 +2632,9 @@ class singleWorker(QThread):
printLock.release() printLock.release()
payload = pack('>Q',nonce) + payload payload = pack('>Q',nonce) + payload
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData = headerData + 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00' headerData += 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00'
headerData = headerData + pack('>L',len(payload)) headerData += pack('>L',len(payload))
headerData = headerData + hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
return headerData + payload return headerData + payload
class addressGenerator(QThread): class addressGenerator(QThread):
@ -2779,6 +2782,7 @@ class addressGenerator(QThread):
self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),'Done generating address') self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),'Done generating address')
reloadMyAddressHashes() reloadMyAddressHashes()
#This code which deals with old RSA addresses will soon be removed.
elif self.addressVersionNumber == 1: elif self.addressVersionNumber == 1:
statusbar = 'Generating new ' + str(config.getint('bitmessagesettings', 'bitstrength')) + ' bit RSA key. This takes a minute on average. If you want to generate multiple addresses now, you can; they will queue.' statusbar = 'Generating new ' + str(config.getint('bitmessagesettings', 'bitstrength')) + ' bit RSA key. This takes a minute on average. If you want to generate multiple addresses now, you can; they will queue.'
self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),statusbar) self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),statusbar)
@ -2813,7 +2817,7 @@ class addressGenerator(QThread):
self.emit(SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),self.label,address,str(self.streamNumber)) self.emit(SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),self.label,address,str(self.streamNumber))
reloadMyAddressHashes() reloadMyAddressHashes()
#Does an EC point multiplication which basically turns a private key into a public key #Does an EC point multiplication; turns a private key into a public key.
def pointMult(self,secret): def pointMult(self,secret):
#ctx = OpenSSL.BN_CTX_new() #This value proved to cause Seg Faults on Linux. It turns out that it really didn't speed up EC_POINT_mul anyway. #ctx = OpenSSL.BN_CTX_new() #This value proved to cause Seg Faults on Linux. It turns out that it really didn't speed up EC_POINT_mul anyway.
k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1')) k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
@ -2962,6 +2966,7 @@ class NewAddressDialog(QtGui.QDialog):
self.ui.setupUi(self) self.ui.setupUi(self)
self.parent = parent self.parent = parent
row = 1 row = 1
#Let's fill out the 'existing address' combo box with addresses from the 'Your Identities' tab.
while self.parent.ui.tableWidgetYourIdentities.item(row-1,1): while self.parent.ui.tableWidgetYourIdentities.item(row-1,1):
self.ui.radioButtonExisting.click() self.ui.radioButtonExisting.click()
#print self.parent.ui.tableWidgetYourIdentities.item(row-1,1).text() #print self.parent.ui.tableWidgetYourIdentities.item(row-1,1).text()
@ -3041,8 +3046,6 @@ class MyForm(QtGui.QMainWindow):
self.actionReply = self.ui.inboxContextMenuToolbar.addAction("Reply", self.on_action_InboxReply) self.actionReply = self.ui.inboxContextMenuToolbar.addAction("Reply", self.on_action_InboxReply)
self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction("Add sender to your Address Book", self.on_action_InboxAddSenderToAddressBook) self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction("Add sender to your Address Book", self.on_action_InboxAddSenderToAddressBook)
self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction("Move to Trash", self.on_action_InboxTrash) self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction("Move to Trash", self.on_action_InboxTrash)
#self.actionDisable = self.ui.inboxContextMenuToolbar.addAction("Disable", self.on_action_YourIdentitiesDisable)
#self.actionClipboard = self.ui.inboxContextMenuToolbar.addAction("Copy address to clipboard", self.on_action_YourIdentitiesClipboard)
self.ui.tableWidgetInbox.setContextMenuPolicy( QtCore.Qt.CustomContextMenu ) self.ui.tableWidgetInbox.setContextMenuPolicy( QtCore.Qt.CustomContextMenu )
self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox) self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox)
self.popMenuInbox = QtGui.QMenu( self ) self.popMenuInbox = QtGui.QMenu( self )
@ -3445,12 +3448,9 @@ class MyForm(QtGui.QMainWindow):
def updateSentItemStatusByHash(self,toRipe,textToDisplay): def updateSentItemStatusByHash(self,toRipe,textToDisplay):
for i in range(self.ui.tableWidgetSent.rowCount()): for i in range(self.ui.tableWidgetSent.rowCount()):
toAddress = str(self.ui.tableWidgetSent.item(i,0).data(Qt.UserRole).toPyObject()) toAddress = str(self.ui.tableWidgetSent.item(i,0).data(Qt.UserRole).toPyObject())
# messageState = str(self.ui.tableWidgetSent.item(i,3).data(Qt.UserRole).toPyObject())
status,addressVersionNumber,streamNumber,ripe = decodeAddress(toAddress) status,addressVersionNumber,streamNumber,ripe = decodeAddress(toAddress)
if ripe == toRipe: if ripe == toRipe:
self.ui.tableWidgetSent.item(i,3).setText(unicode(textToDisplay,'utf-8')) self.ui.tableWidgetSent.item(i,3).setText(unicode(textToDisplay,'utf-8'))
#if textToDisplay == 'Sent':
# self.ui.tableWidgetSent.item(i,3).setData(Qt.UserRole,'sent')
def updateSentItemStatusByAckdata(self,ackdata,textToDisplay): def updateSentItemStatusByAckdata(self,ackdata,textToDisplay):
for i in range(self.ui.tableWidgetSent.rowCount()): for i in range(self.ui.tableWidgetSent.rowCount()):
@ -3459,8 +3459,6 @@ class MyForm(QtGui.QMainWindow):
status,addressVersionNumber,streamNumber,ripe = decodeAddress(toAddress) status,addressVersionNumber,streamNumber,ripe = decodeAddress(toAddress)
if ackdata == tableAckdata: if ackdata == tableAckdata:
self.ui.tableWidgetSent.item(i,3).setText(unicode(textToDisplay,'utf-8')) self.ui.tableWidgetSent.item(i,3).setText(unicode(textToDisplay,'utf-8'))
#if textToDisplay == 'Sent':
# self.ui.tableWidgetSent.item(i,3).setData(Qt.UserRole,'sent')
def rerenderInboxFromLabels(self): def rerenderInboxFromLabels(self):
for i in range(self.ui.tableWidgetInbox.rowCount()): for i in range(self.ui.tableWidgetInbox.rowCount()):
@ -3621,6 +3619,7 @@ class MyForm(QtGui.QMainWindow):
self.ui.labelFrom.setText('') self.ui.labelFrom.setText('')
self.ui.tabWidget.setCurrentIndex(2) self.ui.tabWidget.setCurrentIndex(2)
self.ui.tableWidgetSent.setCurrentCell(0,0)
else: else:
self.statusBar().showMessage('Your \'To\' field is empty.') self.statusBar().showMessage('Your \'To\' field is empty.')
else: #User selected 'Broadcast' else: #User selected 'Broadcast'
@ -3673,6 +3672,7 @@ class MyForm(QtGui.QMainWindow):
self.ui.labelFrom.setText('') self.ui.labelFrom.setText('')
self.ui.tabWidget.setCurrentIndex(2) self.ui.tabWidget.setCurrentIndex(2)
self.ui.tableWidgetSent.setCurrentCell(0,0)
def click_pushButtonLoadFromAddressBook(self): def click_pushButtonLoadFromAddressBook(self):
@ -3795,11 +3795,10 @@ class MyForm(QtGui.QMainWindow):
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())
self.ui.tableWidgetInbox.setCurrentCell(0,0)
def click_pushButtonAddAddressBook(self): def click_pushButtonAddAddressBook(self):
self.NewSubscriptionDialogInstance = NewSubscriptionDialog(self) self.NewSubscriptionDialogInstance = NewSubscriptionDialog(self)
if self.NewSubscriptionDialogInstance.exec_(): if self.NewSubscriptionDialogInstance.exec_():
if self.NewSubscriptionDialogInstance.ui.labelSubscriptionAddressCheck.text() == 'Address is valid.': if self.NewSubscriptionDialogInstance.ui.labelSubscriptionAddressCheck.text() == 'Address is valid.':
#First we must check to see if the address is already in the address book. The user cannot add it again or else it will cause problems when updating and deleting the entry. #First we must check to see if the address is already in the address book. The user cannot add it again or else it will cause problems when updating and deleting the entry.
@ -3955,9 +3954,7 @@ class MyForm(QtGui.QMainWindow):
self.ui.tabWidget.setTabText(6,'Whitelist') self.ui.tabWidget.setTabText(6,'Whitelist')
def click_pushButtonAddBlacklist(self): def click_pushButtonAddBlacklist(self):
print 'click_pushButtonAddBlacklist'
self.NewBlacklistDialogInstance = NewSubscriptionDialog(self) self.NewBlacklistDialogInstance = NewSubscriptionDialog(self)
if self.NewBlacklistDialogInstance.exec_(): if self.NewBlacklistDialogInstance.exec_():
if self.NewBlacklistDialogInstance.ui.labelSubscriptionAddressCheck.text() == 'Address is valid.': if self.NewBlacklistDialogInstance.ui.labelSubscriptionAddressCheck.text() == 'Address is valid.':
#First we must check to see if the address is already in the address book. The user cannot add it again or else it will cause problems when updating and deleting the entry. #First we must check to see if the address is already in the address book. The user cannot add it again or else it will cause problems when updating and deleting the entry.
@ -4025,12 +4022,6 @@ class MyForm(QtGui.QMainWindow):
print 'new address dialog box rejected' print 'new address dialog box rejected'
def closeEvent(self, event): def closeEvent(self, event):
broadcastToSendDataQueues((0, 'shutdown', 'all'))
print 'Closing. Flushing inventory in memory out to disk...'
self.statusBar().showMessage('Flushing inventory in memory out to disk.')
flushInventory()
'''quit_msg = "Are you sure you want to exit Bitmessage?" '''quit_msg = "Are you sure you want to exit Bitmessage?"
reply = QtGui.QMessageBox.question(self, 'Message', reply = QtGui.QMessageBox.question(self, 'Message',
quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
@ -4040,6 +4031,12 @@ class MyForm(QtGui.QMainWindow):
else: else:
event.ignore()''' event.ignore()'''
broadcastToSendDataQueues((0, 'shutdown', 'all'))
print 'Closing. Flushing inventory in memory out to disk...'
self.statusBar().showMessage('Flushing inventory in memory out to disk.')
flushInventory()
#This one last useless query will guarantee that the previous query committed before we close the program. #This one last useless query will guarantee that the previous query committed before we close the program.
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put('SELECT address FROM subscriptions') sqlSubmitQueue.put('SELECT address FROM subscriptions')
@ -4349,7 +4346,6 @@ if useVeryEasyProofOfWorkForTesting:
payloadLengthExtraBytes = payloadLengthExtraBytes / 10 payloadLengthExtraBytes = payloadLengthExtraBytes / 10
if __name__ == "__main__": if __name__ == "__main__":
#sqlite_version = sqlite3.sqlite_version_info
# Check the Major version, the first element in the array # Check the Major version, the first element in the array
if sqlite3.sqlite_version_info[0] < 3: if sqlite3.sqlite_version_info[0] < 3:
print 'This program requires sqlite version 3 or higher because 2 and lower cannot store NULL values. I see version:', sqlite3.sqlite_version_info print 'This program requires sqlite version 3 or higher because 2 and lower cannot store NULL values. I see version:', sqlite3.sqlite_version_info
@ -4430,19 +4426,22 @@ if __name__ == "__main__":
print 'Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.' print 'Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.'
raise SystemExit raise SystemExit
#DNS bootstrap method. Note that this lookup doesn't use the proxy server if configured; adding that feature will require more careful testing to verify that it is working. #DNS bootstrap. This could be programmed to use the SOCKS proxy to do the DNS lookup some day but for now we will just rely on the entries in defaultKnownNodes.py. Hopefully either they are up to date or the user has run Bitmessage recently without SOCKS turned on and received good bootstrap nodes using that method.
try: if config.get('bitmessagesettings', 'socksproxytype') == 'none':
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org',80): try:
print 'Adding', item[4][0],'to knownNodes based on DNS boostrap method' for item in socket.getaddrinfo('bootstrap8080.bitmessage.org',80):
knownNodes[1][item[4][0]] = (8080,int(time.time())) print 'Adding', item[4][0],'to knownNodes based on DNS boostrap method'
except: knownNodes[1][item[4][0]] = (8080,int(time.time()))
print 'bootstrap8080.bitmessage.org DNS bootstraping failed.' except:
try: print 'bootstrap8080.bitmessage.org DNS bootstraping failed.'
for item in socket.getaddrinfo('bootstrap8444.bitmessage.org',80): try:
print 'Adding', item[4][0],'to knownNodes based on DNS boostrap method' for item in socket.getaddrinfo('bootstrap8444.bitmessage.org',80):
knownNodes[1][item[4][0]] = (8444,int(time.time())) print 'Adding', item[4][0],'to knownNodes based on DNS boostrap method'
except: knownNodes[1][item[4][0]] = (8444,int(time.time()))
print 'bootstrap8444.bitmessage.org DNS bootstrapping failed.' except:
print 'bootstrap8444.bitmessage.org DNS bootstrapping failed.'
else:
print 'DNS bootstrap skipped because SOCKS is used.'
app = QtGui.QApplication(sys.argv) app = QtGui.QApplication(sys.argv)
app.setStyleSheet("QStatusBar::item { border: 0px solid black }") app.setStyleSheet("QStatusBar::item { border: 0px solid black }")

View File

@ -10,10 +10,9 @@ def createDefaultKnownNodes(appdata):
############## Stream 1 ################ ############## Stream 1 ################
stream1 = {} stream1 = {}
#stream1['75.186.58.44'] = (8080,int(time.time())) stream1['98.14.199.232'] = (8080,int(time.time()))
#stream1['74.66.249.244'] = (8080,int(time.time())) stream1['60.242.109.18'] = (8444,int(time.time()))
#stream1['76.113.50.103'] = (8444,int(time.time())) stream1['84.48.88.49'] = (8444,int(time.time()))
#stream1['188.122.235.58'] = (8444,int(time.time()))
############# Stream 2 ################# ############# Stream 2 #################
stream2 = {} stream2 = {}