commit
cb8541ea96
|
@ -105,20 +105,11 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
count += 1
|
count += 1
|
||||||
if self.command == 'verack'.encode():
|
if self.command == 'verack'.encode():
|
||||||
addr_verack += 1
|
addr_verack += 1
|
||||||
# print('the addr_verack count are -{}'.format(addr_verack))
|
|
||||||
|
|
||||||
if self.command == 'version'.encode():
|
if self.command == 'version'.encode():
|
||||||
addr_version += 1
|
addr_version += 1
|
||||||
# print('the addr_version count are -{}'.format(addr_version))
|
|
||||||
|
|
||||||
if self.command == 'addr'.encode():
|
if self.command == 'addr'.encode():
|
||||||
addr_count += 1
|
addr_count += 1
|
||||||
# print('the addr_count count are -{}'.format(addr_count))
|
|
||||||
|
|
||||||
if self.magic != 0xE9BEB4D9:
|
if self.magic != 0xE9BEB4D9:
|
||||||
# skip 1 byte in order to sync
|
|
||||||
# in the advancedispatched and length commend's
|
|
||||||
# escape the 1 length
|
|
||||||
self.set_state("bm_header", length=1)
|
self.set_state("bm_header", length=1)
|
||||||
self.bm_proto_reset()
|
self.bm_proto_reset()
|
||||||
logger.debug('Bad magic')
|
logger.debug('Bad magic')
|
||||||
|
@ -186,7 +177,6 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
self.set_state("close")
|
self.set_state("close")
|
||||||
return False
|
return False
|
||||||
if retval:
|
if retval:
|
||||||
# print('if retval is true and inside the if ')
|
|
||||||
self.set_state("bm_header", length=self.payloadLength)
|
self.set_state("bm_header", length=self.payloadLength)
|
||||||
self.bm_proto_reset()
|
self.bm_proto_reset()
|
||||||
# else assume the command requires a different state to follow
|
# else assume the command requires a different state to follow
|
||||||
|
@ -451,7 +441,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
|
|
||||||
if self.object.inventoryHash in Inventory() and Dandelion().hasHash(self.object.inventoryHash):
|
if self.object.inventoryHash in Inventory() and Dandelion().hasHash(self.object.inventoryHash):
|
||||||
Dandelion().removeHash(self.object.inventoryHash, "cycle detection")
|
Dandelion().removeHash(self.object.inventoryHash, "cycle detection")
|
||||||
[self.object.inventoryHash] = (
|
Inventory()[self.object.inventoryHash] = (
|
||||||
self.object.objectType, self.object.streamNumber,
|
self.object.objectType, self.object.streamNumber,
|
||||||
memoryview(self.payload[objectOffset:]), self.object.expiresTime,
|
memoryview(self.payload[objectOffset:]), self.object.expiresTime,
|
||||||
memoryview(self.object.tag)
|
memoryview(self.object.tag)
|
||||||
|
@ -539,7 +529,6 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def bm_command_version(self):
|
def bm_command_version(self):
|
||||||
# print('inside the bmproto ')
|
|
||||||
"""
|
"""
|
||||||
Incoming version.
|
Incoming version.
|
||||||
Parse and log, remember important things, like streams, bitfields, etc.
|
Parse and log, remember important things, like streams, bitfields, etc.
|
||||||
|
@ -624,9 +613,6 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
return False
|
return False
|
||||||
if self.destination in connectionpool.BMConnectionPool().inboundConnections:
|
if self.destination in connectionpool.BMConnectionPool().inboundConnections:
|
||||||
try:
|
try:
|
||||||
# print('+++++++++++++++++++++++++++')
|
|
||||||
# print('self destination host -{}'.format(self.destination.host))
|
|
||||||
# print('++++++++++++++++++++++++++++++')
|
|
||||||
if not protocol.checkSocksIP(self.destination.host):
|
if not protocol.checkSocksIP(self.destination.host):
|
||||||
self.append_write_buf(protocol.assembleErrorMessage(
|
self.append_write_buf(protocol.assembleErrorMessage(
|
||||||
errorText="Too many connections from your IP."
|
errorText="Too many connections from your IP."
|
||||||
|
|
|
@ -195,7 +195,6 @@ class BMConnectionPool(object):
|
||||||
port = int(BMConfigParser().safeGet("bitmessagesettings", "port"))
|
port = int(BMConfigParser().safeGet("bitmessagesettings", "port"))
|
||||||
# correct port even if it changed
|
# correct port even if it changed
|
||||||
ls = TCPServer(host=bind, port=port)
|
ls = TCPServer(host=bind, port=port)
|
||||||
print('inside the startListening method')
|
|
||||||
self.listeningSockets[ls.destination] = ls
|
self.listeningSockets[ls.destination] = ls
|
||||||
|
|
||||||
def startUDPSocket(self, bind=None):
|
def startUDPSocket(self, bind=None):
|
||||||
|
@ -344,21 +343,6 @@ class BMConnectionPool(object):
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.errno == errno.ENETUNREACH:
|
if e.errno == errno.ENETUNREACH:
|
||||||
continue
|
continue
|
||||||
# # print('++++++++++++++++++++++++++++++++++++++++++')
|
|
||||||
# # print('self.inboundConnections.values()-{}'.format(self.inboundConnections.values()))
|
|
||||||
# # print('self.outboundConnections.values() -{}'.format(self.outboundConnections.values()))
|
|
||||||
# # print('+++++++++++++++++++++++++++++++++++++++++++')
|
|
||||||
# else:
|
|
||||||
|
|
||||||
# # for i in (
|
|
||||||
# # list(self.inboundConnections.values()) +
|
|
||||||
# # list(self.outboundConnections.values())
|
|
||||||
# # ):
|
|
||||||
# for i in (
|
|
||||||
# [inboundConnections for inboundConnections in self.inboundConnections.values()] +
|
|
||||||
# [inboundConnections for inboundConnections in self.outboundConnections.values()]
|
|
||||||
# ):
|
|
||||||
|
|
||||||
self._lastSpawned = time.time()
|
self._lastSpawned = time.time()
|
||||||
else:
|
else:
|
||||||
for i in self.connections():
|
for i in self.connections():
|
||||||
|
@ -377,7 +361,6 @@ class BMConnectionPool(object):
|
||||||
self.startListening(bind)
|
self.startListening(bind)
|
||||||
logger.info('Listening for incoming connections.')
|
logger.info('Listening for incoming connections.')
|
||||||
if False:
|
if False:
|
||||||
# self.udpSockets :- {'0.0.0.0': <network.udp.UDPSocket connected at 0x7f95cce7d7b8>}
|
|
||||||
if BMConfigParser().safeGet('network', 'bind') == '':
|
if BMConfigParser().safeGet('network', 'bind') == '':
|
||||||
self.startUDPSocket()
|
self.startUDPSocket()
|
||||||
else:
|
else:
|
||||||
|
@ -407,15 +390,6 @@ class BMConnectionPool(object):
|
||||||
|
|
||||||
reaper = []
|
reaper = []
|
||||||
|
|
||||||
# # for i in (
|
|
||||||
# # list(self.inboundConnections.values()) +
|
|
||||||
# # list(self.outboundConnections.values())
|
|
||||||
# # ):
|
|
||||||
# for i in (
|
|
||||||
# [inboundConnections for inboundConnections in self.inboundConnections.values()] +
|
|
||||||
# [outboundConnections for outboundConnections in self.outboundConnections.values()]
|
|
||||||
# ):
|
|
||||||
|
|
||||||
for i in self.connections():
|
for i in self.connections():
|
||||||
minTx = time.time() - 20
|
minTx = time.time() - 20
|
||||||
if i.fullyEstablished:
|
if i.fullyEstablished:
|
||||||
|
@ -427,17 +401,7 @@ class BMConnectionPool(object):
|
||||||
i.close_reason = "Timeout (%is)" % (
|
i.close_reason = "Timeout (%is)" % (
|
||||||
time.time() - i.lastTx)
|
time.time() - i.lastTx)
|
||||||
i.set_state("close")
|
i.set_state("close")
|
||||||
# for i in (
|
|
||||||
# list(self.inboundConnections.values()) +
|
|
||||||
# list(self.outboundConnections.values()) +
|
|
||||||
# list(self.listeningSockets.values()) +
|
|
||||||
# list(self.udpSockets.values())
|
|
||||||
# ):
|
|
||||||
for i in (
|
for i in (
|
||||||
# [inboundConnections for inboundConnections in self.inboundConnections.values()] +
|
|
||||||
# [outboundConnections for outboundConnections in self.outboundConnections.values()] +
|
|
||||||
# [listeningSockets for listeningSockets in self.listeningSockets.values()] +
|
|
||||||
# [udpSockets for udpSockets in self.udpSockets.values()]
|
|
||||||
self.connections() +
|
self.connections() +
|
||||||
[listeningSockets for listeningSockets in self.listeningSockets.values()] +
|
[listeningSockets for listeningSockets in self.listeningSockets.values()] +
|
||||||
[udpSockets for udpSockets in self.udpSockets.values()]
|
[udpSockets for udpSockets in self.udpSockets.values()]
|
||||||
|
|
|
@ -118,14 +118,6 @@ class Dandelion(object):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# for k, v in iter({
|
|
||||||
# k: v for k, v in iter([hasmap for hasamp in self.hashMap.items()])
|
|
||||||
# if v.child is None
|
|
||||||
# }).items():
|
|
||||||
# self.hashMap[k] = Stem(
|
|
||||||
# connection, v.stream, self.poissonTimeout())
|
|
||||||
# invQueue.put((v.stream, k, v.child))
|
|
||||||
|
|
||||||
def maybeRemoveStem(self, connection):
|
def maybeRemoveStem(self, connection):
|
||||||
"""
|
"""
|
||||||
Remove current connection from the stem list (called e.g. when
|
Remove current connection from the stem list (called e.g. when
|
||||||
|
|
|
@ -41,13 +41,6 @@ class DownloadThread(StoppableThread):
|
||||||
def run(self):
|
def run(self):
|
||||||
while not self._stopped:
|
while not self._stopped:
|
||||||
requested = 0
|
requested = 0
|
||||||
# Choose downloading peers randomly
|
|
||||||
# connections = [
|
|
||||||
# x for x in
|
|
||||||
# list(BMConnectionPool().inboundConnections.values()) +
|
|
||||||
# list(BMConnectionPool().outboundConnections.values())
|
|
||||||
# if x.fullyEstablished]
|
|
||||||
|
|
||||||
connections = BMConnectionPool().establishedConnections()
|
connections = BMConnectionPool().establishedConnections()
|
||||||
helper_random.randomshuffle(connections)
|
helper_random.randomshuffle(connections)
|
||||||
requestChunk = max(int(
|
requestChunk = max(int(
|
||||||
|
|
|
@ -130,10 +130,7 @@ class HTTPServer(asyncore.dispatcher):
|
||||||
pair = self.accept()
|
pair = self.accept()
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, _ = pair
|
sock, _ = pair
|
||||||
# print 'Incoming connection from %s' % repr(addr)
|
|
||||||
self.connections += 1
|
self.connections += 1
|
||||||
# if self.connections % 1000 == 0:
|
|
||||||
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
|
||||||
HTTPRequestHandler(sock)
|
HTTPRequestHandler(sock)
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,10 +146,7 @@ class HTTPSServer(HTTPServer):
|
||||||
pair = self.accept()
|
pair = self.accept()
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, _ = pair
|
sock, _ = pair
|
||||||
# print 'Incoming connection from %s' % repr(addr)
|
|
||||||
self.connections += 1
|
self.connections += 1
|
||||||
# if self.connections % 1000 == 0:
|
|
||||||
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
|
||||||
HTTPSRequestHandler(sock)
|
HTTPSRequestHandler(sock)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,12 @@ class RandomTrackingDict(object):
|
||||||
"""
|
"""
|
||||||
Dict with randomised order and tracking.
|
Dict with randomised order and tracking.
|
||||||
|
|
||||||
Keeps a track of how many items have been requested from the dict, and timeouts. Resets after all objects have been
|
Keeps a track of how many items have been requested from the dict, and timeouts.
|
||||||
retrieved and timed out. The main purpose of this isn't as much putting related code together as performance
|
Resets after all objects have been retrieved and timed out.
|
||||||
optimisation and anonymisation of downloading of objects from other peers. If done using a standard dict or array,
|
The main purpose of this isn't as much putting related code together
|
||||||
it takes too much CPU (and looks convoluted). Randomisation helps with anonymity.
|
as performance optimisation and anonymisation of downloading of objects from other peers.
|
||||||
|
If done using a standard dict or array, it takes too much CPU (and looks convoluted).
|
||||||
|
Randomisation helps with anonymity.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
maxPending = 10
|
maxPending = 10
|
||||||
|
|
|
@ -19,21 +19,6 @@ currentSentSpeed = 0
|
||||||
|
|
||||||
def connectedHostsList():
|
def connectedHostsList():
|
||||||
"""List of all the connected hosts"""
|
"""List of all the connected hosts"""
|
||||||
# retval = []
|
|
||||||
# # for i in list(BMConnectionPool().inboundConnections.values()) + \
|
|
||||||
# # list(BMConnectionPool().outboundConnections.values()):
|
|
||||||
|
|
||||||
# outBoundConnections = [outConnection for outConnection in BMConnectionPool().outboundConnections.values()]
|
|
||||||
# inBoundConnections = [inConnection for inConnection in BMConnectionPool().inboundConnections.values()]
|
|
||||||
# for i in outBoundConnections+inBoundConnections:
|
|
||||||
# if not i.fullyEstablished:
|
|
||||||
# continue
|
|
||||||
# try:
|
|
||||||
# retval.append(i)
|
|
||||||
# except AttributeError:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
# return retval
|
|
||||||
return BMConnectionPool().establishedConnections()
|
return BMConnectionPool().establishedConnections()
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,11 +66,4 @@ def pendingDownload():
|
||||||
|
|
||||||
def pendingUpload():
|
def pendingUpload():
|
||||||
"""Getting pending uploads"""
|
"""Getting pending uploads"""
|
||||||
# tmp = {}
|
|
||||||
# for connection in BMConnectionPool().inboundConnections.values() + \
|
|
||||||
# BMConnectionPool().outboundConnections.values():
|
|
||||||
# for k in connection.objectsNewToThem.keys():
|
|
||||||
# tmp[k] = True
|
|
||||||
# This probably isn't the correct logic so it's disabled
|
|
||||||
# return len(tmp)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -94,8 +94,6 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
self.network_group = protocol.network_group(self.destination.host)
|
self.network_group = protocol.network_group(self.destination.host)
|
||||||
ObjectTracker.__init__(self) # pylint: disable=non-parent-init-called
|
ObjectTracker.__init__(self) # pylint: disable=non-parent-init-called
|
||||||
self.bm_proto_reset()
|
self.bm_proto_reset()
|
||||||
# print('--------------tcp------------------')
|
|
||||||
# from network import stats
|
|
||||||
self.set_state("bm_header", expectBytes=protocol.Header.size)
|
self.set_state("bm_header", expectBytes=protocol.Header.size)
|
||||||
|
|
||||||
def antiIntersectionDelay(self, initial=False):
|
def antiIntersectionDelay(self, initial=False):
|
||||||
|
@ -152,7 +150,6 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
))
|
))
|
||||||
self.antiIntersectionDelay(True)
|
self.antiIntersectionDelay(True)
|
||||||
self.fullyEstablished = True
|
self.fullyEstablished = True
|
||||||
# print('inside the set_connection_fully_established in tcp file')
|
|
||||||
if self.isOutbound:
|
if self.isOutbound:
|
||||||
knownnodes.increaseRating(self.destination)
|
knownnodes.increaseRating(self.destination)
|
||||||
Dandelion().maybeAddStem(self)
|
Dandelion().maybeAddStem(self)
|
||||||
|
@ -380,7 +377,6 @@ class TCPServer(AdvancedDispatcher):
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.set_reuse_addr()
|
self.set_reuse_addr()
|
||||||
for attempt in range(50):
|
for attempt in range(50):
|
||||||
print('inside the attempt of line 371')
|
|
||||||
try:
|
try:
|
||||||
if attempt > 0:
|
if attempt > 0:
|
||||||
logger.warning('Failed to bind on port %s', port)
|
logger.warning('Failed to bind on port %s', port)
|
||||||
|
|
|
@ -68,7 +68,6 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
self.isSSL = False
|
self.isSSL = False
|
||||||
|
|
||||||
def state_tls_init(self):
|
def state_tls_init(self):
|
||||||
# print()
|
|
||||||
"""Prepare sockets for TLS handshake"""
|
"""Prepare sockets for TLS handshake"""
|
||||||
# pylint: disable=attribute-defined-outside-init
|
# pylint: disable=attribute-defined-outside-init
|
||||||
self.isSSL = True
|
self.isSSL = True
|
||||||
|
@ -95,9 +94,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
ciphers=self.ciphers, do_handshake_on_connect=False)
|
ciphers=self.ciphers, do_handshake_on_connect=False)
|
||||||
self.sslSocket.setblocking(0)
|
self.sslSocket.setblocking(0)
|
||||||
self.want_read = self.want_write = True
|
self.want_read = self.want_write = True
|
||||||
# print('before tls file python 98 state are :- {}'.format(self.state))
|
|
||||||
self.set_state("tls_handshake")
|
self.set_state("tls_handshake")
|
||||||
# print('after tls file python 100 state are :- {}'.format(self.state))
|
|
||||||
return False
|
return False
|
||||||
# if hasattr(self.socket, "context"):
|
# if hasattr(self.socket, "context"):
|
||||||
# self.socket.context.set_ecdh_curve("secp256k1")
|
# self.socket.context.set_ecdh_curve("secp256k1")
|
||||||
|
@ -186,23 +183,18 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
return
|
return
|
||||||
|
|
||||||
def tls_handshake(self):
|
def tls_handshake(self):
|
||||||
# print('inside the tls_handshake')
|
|
||||||
"""Perform TLS handshake and handle its stages"""
|
"""Perform TLS handshake and handle its stages"""
|
||||||
# wait for flush
|
# wait for flush
|
||||||
if self.write_buf:
|
if self.write_buf:
|
||||||
return False
|
return False
|
||||||
# Perform the handshake.
|
# Perform the handshake.
|
||||||
try:
|
try:
|
||||||
# print "handshaking (internal)"
|
|
||||||
self.sslSocket.do_handshake()
|
self.sslSocket.do_handshake()
|
||||||
except ssl.SSLError as err:
|
except ssl.SSLError as err:
|
||||||
# print "%s:%i: handshake fail" % (self.destination.host, self.destination.port)
|
|
||||||
self.want_read = self.want_write = False
|
self.want_read = self.want_write = False
|
||||||
if err.args[0] == ssl.SSL_ERROR_WANT_READ:
|
if err.args[0] == ssl.SSL_ERROR_WANT_READ:
|
||||||
# print "want read"
|
|
||||||
self.want_read = True
|
self.want_read = True
|
||||||
if err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
|
if err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
|
||||||
# print "want write"
|
|
||||||
self.want_write = True
|
self.want_write = True
|
||||||
if not (self.want_write or self.want_read):
|
if not (self.want_write or self.want_read):
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -65,19 +65,15 @@ class UDPSocket(BMProto): # pylint: disable=too-many-instance-attributes
|
||||||
# only addr (peer discovery), error and object are implemented
|
# only addr (peer discovery), error and object are implemented
|
||||||
|
|
||||||
def bm_command_getdata(self):
|
def bm_command_getdata(self):
|
||||||
# return BMProto.bm_command_getdata(self)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bm_command_inv(self):
|
def bm_command_inv(self):
|
||||||
# return BMProto.bm_command_inv(self)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bm_command_addr(self):
|
def bm_command_addr(self):
|
||||||
addresses = self._decode_addr()
|
addresses = self._decode_addr()
|
||||||
# only allow peer discovery from private IPs in order to avoid
|
# only allow peer discovery from private IPs in order to avoid
|
||||||
# attacks from random IPs on the internet
|
# attacks from random IPs on the internet
|
||||||
# if not self.local:
|
|
||||||
# return True
|
|
||||||
self.local = True
|
self.local = True
|
||||||
remoteport = False
|
remoteport = False
|
||||||
for seenTime, stream, services, ip, port in addresses:
|
for seenTime, stream, services, ip, port in addresses:
|
||||||
|
|
Reference in New Issue
Block a user