self.processbroadcast(data)#When this function returns, we will have either successfully processed this broadcast because we are interested in it, ignored it because we aren't interested in it, or found problem with the broadcast that warranted ignoring it.
self.processbroadcast(readPosition,data)#When this function returns, we will have either successfully processed this broadcast because we are interested in it, ignored it because we aren't interested in it, or found problem with the broadcast that warranted ignoring it.
# Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are mostly the same values used for msg messages although broadcast messages are processed faster.
iflen(data)>100000000:#Size is greater than 100 megabytes
@ -563,8 +572,7 @@ class receiveDataThread(QThread):
printLock.release()
#A broadcast message has a valid time and POW and requires processing. The recbroadcast function calls this one.
#Cannot decode incoming broadcast versions higher than 1. Assuming the sender isn\' being silly, you should upgrade Bitmessage because this message shall be ignored.
@ -693,13 +701,20 @@ class receiveDataThread(QThread):
print'The stream number encoded in this msg ('+str(streamNumberAsClaimedByMsg)+') message does not match the stream number on which it was received. Ignoring it.'
@ -1024,6 +1039,14 @@ 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.
ifrecaddrStream==0:
continue
ifrecaddrStream!=self.streamNumberandrecaddrStream!=(self.streamNumber*2)andrecaddrStream!=((self.streamNumber*2)+1):#if the embedded stream number is not in my stream or either of my child streams then ignore it. Someone might be trying funny business.
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.
ifrecaddrStream==0:
continue
ifrecaddrStream!=self.streamNumberandrecaddrStream!=(self.streamNumber*2)andrecaddrStream!=((self.streamNumber*2)+1):#if the embedded stream number is not in my stream or either of my child streams then ignore it. Someone might be trying funny business.
print'Ignoring IP address in private range:',hostFromAddrMessage
continue
timeSomeoneElseReceivedMessageFromThisNode,=unpack('>I',data[lengthOfNumberOfAddresses+(34*i):4+lengthOfNumberOfAddresses+(34*i)])#This is the 'time' value in the received addr message.
ifrecaddrStreamnotinknownNodes:#knownNodes is a dictionary of dictionaries with one outer dictionary for each stream. If the outer stream dictionary doesn't exist yet then we must make it.
iflen(knownNodes[recaddrStream])<20000andtimeSomeoneElseReceivedMessageFromThisNode>(int(time.time())-10800)andtimeSomeoneElseReceivedMessageFromThisNode<(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.
print'Ignoring IP address in private range:',hostFromAddrMessage
continue
timeSomeoneElseReceivedMessageFromThisNode,=unpack('>I',data[lengthOfNumberOfAddresses+(34*i):4+lengthOfNumberOfAddresses+(34*i)])#This is the 'time' value in the received addr message.
ifrecaddrStreamnotinknownNodes:#knownNodes is a dictionary of dictionaries with one outer dictionary for each stream. If the outer stream dictionary doesn't exist yet then we must make it.
PORT,timeLastReceivedMessageFromThisNode=knownNodes[recaddrStream][hostFromAddrMessage]#PORT in this case is either the port we used to connect to the remote node, or the port that was specified by someone else in a past addr message.
iflen(knownNodes[recaddrStream])<20000andtimeSomeoneElseReceivedMessageFromThisNode>(int(time.time())-10800)andtimeSomeoneElseReceivedMessageFromThisNode<(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.
PORT,timeLastReceivedMessageFromThisNode=knownNodes[recaddrStream][hostFromAddrMessage]#PORT in this case is either the port we used to connect to the remote node, or the port that was specified by someone else in a past addr message.
print'Strange occurance: The port specified in an addr message',str(recaddrPort),'does not match the port',str(PORT),'that this program (or some other peer) used to connect to it',str(hostFromAddrMessage),'. Perhaps they changed their port or are using a strange NAT configuration.'
ifneedToWriteKnownNodesToDisk:#Runs if any nodes were new to us. Also, share those nodes with our peers.
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.
ifrecaddrStream==0:
continue
ifrecaddrStream!=self.streamNumberandrecaddrStream!=(self.streamNumber*2)andrecaddrStream!=((self.streamNumber*2)+1):#if the embedded stream number is not in my stream or either of my child streams then ignore it. Someone might be trying funny business.
print'Ignoring IP address in private range:',hostFromAddrMessage
continue
timeSomeoneElseReceivedMessageFromThisNode,=unpack('>Q',data[lengthOfNumberOfAddresses+(38*i):8+lengthOfNumberOfAddresses+(38*i)])#This is the 'time' value in the received addr message. 64-bit.
ifrecaddrStreamnotinknownNodes:#knownNodes is a dictionary of dictionaries with one outer dictionary for each stream. If the outer stream dictionary doesn't exist yet then we must make it.
print'Strange occurance: The port specified in an addr message',str(recaddrPort),'does not match the port',str(PORT),'that this program (or some other peer) used to connect to it',str(hostFromAddrMessage),'. Perhaps they changed their port or are using a strange NAT configuration.'
ifneedToWriteKnownNodesToDisk:#Runs if any nodes were new to us. Also, share those nodes with our peers.
iflen(knownNodes[recaddrStream])<20000andtimeSomeoneElseReceivedMessageFromThisNode>(int(time.time())-10800)andtimeSomeoneElseReceivedMessageFromThisNode<(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.
PORT,timeLastReceivedMessageFromThisNode=knownNodes[recaddrStream][hostFromAddrMessage]#PORT in this case is either the port we used to connect to the remote node, or the port that was specified by someone else in a past addr message.
print'Strange occurance: The port specified in an addr message',str(recaddrPort),'does not match the port',str(PORT),'that this program (or some other peer) used to connect to it',str(hostFromAddrMessage),'. Perhaps they changed their port or are using a strange NAT configuration.'
ifneedToWriteKnownNodesToDisk:#Runs if any nodes were new to us. Also, share those nodes with our peers.
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.
#To prevent some network analysis, 'leak' the data out to our peer after waiting a random amount of time unless we have a long list of messages in our queue to send.
random.seed()
time.sleep(random.randrange(0,10))
self.sock.sendall(data)
self.lastTimeISentData=int(time.time())
except:
print'self.sock.sendall failed'
self.sock.close()
sendDataQueues.remove(self.mailbox)
print'sendDataThread thread',self,'ending now'
break
ifself.remoteProtocolVersion==1:
printLock.acquire()
print'a sendData thread is not sending an addr message to this particular peer ('+self.HOST+') because their protocol version is 1.'
printLock.release()
else:
try:
#To prevent some network analysis, 'leak' the data out to our peer after waiting a random amount of time unless we have a long list of messages in our queue to send.