Code Formatting

This commit is contained in:
lakshyacis 2020-01-10 19:43:59 +05:30
parent 5fc20221b9
commit eb98abbabf
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
8 changed files with 6 additions and 87 deletions

View File

@ -624,9 +624,6 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
return False
if self.destination in connectionpool.BMConnectionPool().inboundConnections:
try:
# print('+++++++++++++++++++++++++++')
# print('self destination host -{}'.format(self.destination.host))
# print('++++++++++++++++++++++++++++++')
if not protocol.checkSocksIP(self.destination.host):
self.append_write_buf(protocol.assembleErrorMessage(
errorText="Too many connections from your IP."

View File

@ -344,21 +344,6 @@ class BMConnectionPool(object):
except socket.error as e:
if e.errno == errno.ENETUNREACH:
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()
else:
for i in self.connections():
@ -377,7 +362,6 @@ class BMConnectionPool(object):
self.startListening(bind)
logger.info('Listening for incoming connections.')
if False:
# self.udpSockets :- {'0.0.0.0': <network.udp.UDPSocket connected at 0x7f95cce7d7b8>}
if BMConfigParser().safeGet('network', 'bind') == '':
self.startUDPSocket()
else:
@ -407,15 +391,6 @@ class BMConnectionPool(object):
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():
minTx = time.time() - 20
if i.fullyEstablished:
@ -427,17 +402,7 @@ class BMConnectionPool(object):
i.close_reason = "Timeout (%is)" % (
time.time() - i.lastTx)
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 (
# [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() +
[listeningSockets for listeningSockets in self.listeningSockets.values()] +
[udpSockets for udpSockets in self.udpSockets.values()]

View File

@ -118,14 +118,6 @@ class Dandelion(object):
except AttributeError:
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):
"""
Remove current connection from the stem list (called e.g. when

View File

@ -41,13 +41,6 @@ class DownloadThread(StoppableThread):
def run(self):
while not self._stopped:
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()
helper_random.randomshuffle(connections)
requestChunk = max(int(

View File

@ -130,10 +130,7 @@ class HTTPServer(asyncore.dispatcher):
pair = self.accept()
if pair is not None:
sock, _ = pair
# print 'Incoming connection from %s' % repr(addr)
self.connections += 1
# if self.connections % 1000 == 0:
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
HTTPRequestHandler(sock)
@ -149,10 +146,7 @@ class HTTPSServer(HTTPServer):
pair = self.accept()
if pair is not None:
sock, _ = pair
# print 'Incoming connection from %s' % repr(addr)
self.connections += 1
# if self.connections % 1000 == 0:
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
HTTPSRequestHandler(sock)

View File

@ -14,10 +14,12 @@ class RandomTrackingDict(object):
"""
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
retrieved and timed out. The main purpose of this isn't as much putting related code together 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.
Keeps a track of how many items have been requested from the dict, and timeouts.
Resets after all objects have been retrieved and timed out.
The main purpose of this isn't as much putting related code together
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
maxPending = 10

View File

@ -19,21 +19,6 @@ currentSentSpeed = 0
def connectedHostsList():
"""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()
@ -81,11 +66,4 @@ def pendingDownload():
def pendingUpload():
"""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

View File

@ -94,8 +94,6 @@ class TCPConnection(BMProto, TLSDispatcher):
self.network_group = protocol.network_group(self.destination.host)
ObjectTracker.__init__(self) # pylint: disable=non-parent-init-called
self.bm_proto_reset()
# print('--------------tcp------------------')
# from network import stats
self.set_state("bm_header", expectBytes=protocol.Header.size)
def antiIntersectionDelay(self, initial=False):