Added new deterministic address and subscription-related commands #163

Merged
Atheros1 merged 4 commits from master into master 2013-05-24 23:08:11 +02:00
4 changed files with 16 additions and 17 deletions
Showing only changes of commit 06992eeb71 - Show all commits

View File

@ -1666,10 +1666,7 @@ class receiveDataThread(threading.Thread):
if data[28+lengthOfNumberOfAddresses+(34*i)] == '\x7F': if data[28+lengthOfNumberOfAddresses+(34*i)] == '\x7F':
print 'Ignoring IP address in loopback range:', hostFromAddrMessage print 'Ignoring IP address in loopback range:', hostFromAddrMessage
continue continue
if data[28+lengthOfNumberOfAddresses+(34*i)] == '\x0A': if isHostInPrivateIPRange(hostFromAddrMessage):
print 'Ignoring IP address in private range:', hostFromAddrMessage
continue
if data[28+lengthOfNumberOfAddresses+(34*i):30+lengthOfNumberOfAddresses+(34*i)] == '\xC0A8':
print 'Ignoring IP address in private range:', hostFromAddrMessage print 'Ignoring IP address in private range:', hostFromAddrMessage
continue continue
timeSomeoneElseReceivedMessageFromThisNode, = unpack('>I',data[lengthOfNumberOfAddresses+(34*i):4+lengthOfNumberOfAddresses+(34*i)]) #This is the 'time' value in the received addr message. timeSomeoneElseReceivedMessageFromThisNode, = unpack('>I',data[lengthOfNumberOfAddresses+(34*i):4+lengthOfNumberOfAddresses+(34*i)]) #This is the 'time' value in the received addr message.
@ -1835,21 +1832,21 @@ class receiveDataThread(threading.Thread):
for i in range(500): for i in range(500):
random.seed() random.seed()
HOST, = random.sample(shared.knownNodes[self.streamNumber], 1) HOST, = random.sample(shared.knownNodes[self.streamNumber], 1)
if self.isHostInPrivateIPRange(HOST): if isHostInPrivateIPRange(HOST):
continue continue
addrsInMyStream[HOST] = shared.knownNodes[self.streamNumber][HOST] addrsInMyStream[HOST] = shared.knownNodes[self.streamNumber][HOST]
if len(shared.knownNodes[self.streamNumber*2]) > 0: if len(shared.knownNodes[self.streamNumber*2]) > 0:
for i in range(250): for i in range(250):
random.seed() random.seed()
HOST, = random.sample(shared.knownNodes[self.streamNumber*2], 1) HOST, = random.sample(shared.knownNodes[self.streamNumber*2], 1)
if self.isHostInPrivateIPRange(HOST): if isHostInPrivateIPRange(HOST):
continue continue
addrsInChildStreamLeft[HOST] = shared.knownNodes[self.streamNumber*2][HOST] addrsInChildStreamLeft[HOST] = shared.knownNodes[self.streamNumber*2][HOST]
if len(shared.knownNodes[(self.streamNumber*2)+1]) > 0: if len(shared.knownNodes[(self.streamNumber*2)+1]) > 0:
for i in range(250): for i in range(250):
random.seed() random.seed()
HOST, = random.sample(shared.knownNodes[(self.streamNumber*2)+1], 1) HOST, = random.sample(shared.knownNodes[(self.streamNumber*2)+1], 1)
if self.isHostInPrivateIPRange(HOST): if isHostInPrivateIPRange(HOST):
continue continue
addrsInChildStreamRight[HOST] = shared.knownNodes[(self.streamNumber*2)+1][HOST] addrsInChildStreamRight[HOST] = shared.knownNodes[(self.streamNumber*2)+1][HOST]
shared.knownNodesLock.release() shared.knownNodesLock.release()
@ -1991,16 +1988,7 @@ class receiveDataThread(threading.Thread):
if self.verackReceived == True: if self.verackReceived == True:
self.connectionFullyEstablished() self.connectionFullyEstablished()
def isHostInPrivateIPRange(self,host):
if host[:3] == '10.':
return True
if host[:4] == '172.':
if host[6] == '.':
if int(host[4:6]) >= 16 and int(host[4:6]) <= 31:
return True
if host[:8] == '192.168.':
return True
return False
#Every connection to a peer has a sendDataThread (and also a receiveDataThread). #Every connection to a peer has a sendDataThread (and also a receiveDataThread).
class sendDataThread(threading.Thread): class sendDataThread(threading.Thread):
@ -2293,6 +2281,17 @@ def assembleVersionMessage(remoteHost,remotePort,myStreamNumber):
datatosend = datatosend + hashlib.sha512(payload).digest()[0:4] datatosend = datatosend + hashlib.sha512(payload).digest()[0:4]
return datatosend + payload return datatosend + payload
def isHostInPrivateIPRange(host):
if host[:3] == '10.':
return True
if host[:4] == '172.':
if host[6] == '.':
if int(host[4:6]) >= 16 and int(host[4:6]) <= 31:
return True
if host[:8] == '192.168.':
return True
return False
#This thread exists because SQLITE3 is so un-threadsafe that we must submit queries to it and it puts results back in a different queue. They won't let us just use locks. #This thread exists because SQLITE3 is so un-threadsafe that we must submit queries to it and it puts results back in a different queue. They won't let us just use locks.
class sqlThread(threading.Thread): class sqlThread(threading.Thread):
def __init__(self): def __init__(self):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB