diff --git a/bitmessagemain.py b/bitmessagemain.py index 952cbc6f..827cf4e8 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -312,6 +312,7 @@ class receiveDataThread(QThread): if verbose >= 2: printLock.acquire() sys.stderr.write('The magic bytes were not correct. First 40 bytes of data: %s\n' % repr(self.data[0:40])) + print 'self.data:', self.data.encode('hex') printLock.release() self.data = "" else: @@ -1677,6 +1678,10 @@ class receiveDataThread(QThread): if numberOfAddressesIncluded > 1000 or numberOfAddressesIncluded == 0: return + if self.payloadLength < lengthOfNumberOfAddresses + (34 * numberOfAddressesIncluded): + print 'addr message does not contain enough data. Ignoring.' + return + needToWriteKnownNodesToDisk = False for i in range(0,numberOfAddressesIncluded): try: @@ -1701,7 +1706,8 @@ class receiveDataThread(QThread): sys.stderr.write('ERROR TRYING TO UNPACK recaddr (recaddrStream). Message: %s\n' % str(err)) printLock.release() break #giving up on unpacking any more. We should still be connected however. - + if recaddrStream == 0: + continue try: recaddrServices, = unpack('>Q',self.data[32+lengthOfNumberOfAddresses+(34*i):40+lengthOfNumberOfAddresses+(34*i)]) except Exception, err: @@ -1725,10 +1731,12 @@ class receiveDataThread(QThread): if hostFromAddrMessage == '127.0.0.1': continue timeSomeoneElseReceivedMessageFromThisNode, = unpack('>I',self.data[24+lengthOfNumberOfAddresses+(34*i):28+lengthOfNumberOfAddresses+(34*i)]) #This is the 'time' value in the received addr message. + if recaddrStream not in knownNodes: + knownNodes[recaddrStream] = {} if hostFromAddrMessage not in knownNodes[recaddrStream]: if len(knownNodes[recaddrStream]) < 20000 and timeSomeoneElseReceivedMessageFromThisNode > (int(time.time())-10800) and timeSomeoneElseReceivedMessageFromThisNode < (int(time.time()) + 10800): #If we have more than 20000 nodes in our list already then just forget about adding more. Also, make sure that the time that someone else received a message from this node is within three hours from now. knownNodes[recaddrStream][hostFromAddrMessage] = (recaddrPort, timeSomeoneElseReceivedMessageFromThisNode) - print 'added new node', hostFromAddrMessage, 'to knownNodes.' + print 'added new node', hostFromAddrMessage, 'to knownNodes in stream', recaddrStream needToWriteKnownNodesToDisk = True hostDetails = (timeSomeoneElseReceivedMessageFromThisNode, recaddrStream, recaddrServices, hostFromAddrMessage, recaddrPort) listOfAddressDetailsToBroadcastToPeers.append(hostDetails) @@ -1744,7 +1752,7 @@ class receiveDataThread(QThread): output.close() self.broadcastaddr(listOfAddressDetailsToBroadcastToPeers) printLock.acquire() - print 'knownNodes currently has', len(knownNodes[recaddrStream]), 'nodes for this stream.' + print 'knownNodes currently has', len(knownNodes[self.streamNumber]), 'nodes for this stream.' printLock.release() #Function runs when we want to broadcast an addr message to all of our peers. Runs when we learn of nodes that we didn't previously know about and want to share them with our peers. diff --git a/messages.dat reader.py b/messages.dat reader.py index 7ca966a6..ec116a1e 100644 --- a/messages.dat reader.py +++ b/messages.dat reader.py @@ -39,7 +39,8 @@ def readSent(): cur.execute(item, parameters) output = cur.fetchall() for row in output: - print row + msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, pubkeyretrynumber, msgretrynumber, folder = row + print msgid.encode('hex'), toaddress, 'toripe:', toripe.encode('hex'), 'fromaddress:', fromaddress, 'SUBJECT:', repr(subject), 'MESSAGE:', repr(message), 'ACKDATA:', ackdata.encode('hex'), lastactiontime, status, pubkeyretrynumber, msgretrynumber, folder def readSubscriptions(): print 'Printing everything in subscriptions table:' @@ -90,9 +91,9 @@ def takeSentMessagesOutOfTrash(): #takeInboxMessagesOutOfTrash() #takeSentMessagesOutOfTrash() #readInbox() -#readSent() +readSent() #readPubkeys() -readSubscriptions() +#readSubscriptions() #readInventory()