-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes based on style and lint checks. (final_code_quality_19) #1401
Conversation
@Singleton | ||
class Dandelion(): | ||
class Dandelion: | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Dandelion class for tracking stem/fluff stages.""" |
@@ -35,44 +44,52 @@ def __init__(self): | |||
self.lock = RLock() | |||
|
|||
def poissonTimeout(self, start=None, average=0): | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Generate deadline using Poisson distribution""" |
|
||
def addHash(self, hashId, source=None, stream=1): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Add inventory vector to dandelion stem""" |
|
||
def setHashStream(self, hashId, stream=1): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Update stream for inventory vector (as inv/dinv commands don't include streams, we only learn this after receiving the object)""" |
|
||
def removeHash(self, hashId, reason="no reason specified"): | ||
logging.debug("%s entering fluff mode due to %s.", ''.join('%02x'%ord(i) for i in hashId), reason) | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Switch inventory vector from stem to fluff mode""" |
with self.lock: | ||
try: | ||
del self.hashMap[hashId] | ||
except KeyError: | ||
pass | ||
|
||
def hasHash(self, hashId): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Is inventory vector in stem mode?""" |
return hashId in self.hashMap | ||
|
||
def objectChildStem(self, hashId): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Child (i.e. next) node for an inventory vector during stem mode""" |
return self.hashMap[hashId].child | ||
|
||
def maybeAddStem(self, connection): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""If we had too few outbound connections, add the current one to the current stem list. Dandelion as designed by the authors should always have two active stem child connections.""" |
def maybeRemoveStem(self, connection): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Remove current connection from the stem list (called e.g. when a connection is closed).""" |
@@ -96,6 +113,7 @@ def maybeRemoveStem(self, connection): | |||
self.hashMap[k] = Stem(None, v.stream, self.poissonTimeout()) | |||
|
|||
def pickStem(self, parent=None): | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Pick a random active stem, but not the parent one (the one where an object came from)""" |
@@ -112,6 +130,7 @@ def pickStem(self, parent=None): | |||
return None | |||
|
|||
def getNodeStem(self, node=None): | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Return child stem node for a given parent stem node (the mapping is static for about 10 minutes, then it reshuffles)""" |
@@ -120,15 +139,18 @@ def getNodeStem(self, node=None): | |||
return self.nodeMap[node] | |||
|
|||
def expire(self): | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Switch expired objects from stem to fluff mode""" |
for row in toDelete: | ||
self.removeHash(row[1], 'expiration') | ||
invQueue.put((row[0], row[1], row[2])) | ||
|
||
def reRandomiseStems(self): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Re-shuffle stem mapping (parent <-> child pairs)""" |
|
||
class Socks4aError(ProxyError): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""SOCKS4a error base class""" |
|
||
|
||
class Socks4a(Proxy): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""SOCKS4a proxy class""" |
def __init__(self, address=None): | ||
Proxy.__init__(self, address) | ||
self.ipaddr = None | ||
self.destport = address[1] | ||
|
||
def state_init(self): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Protocol initialisation (before connection is established)""" |
self.set_state("auth_done", 0) | ||
return True | ||
|
||
def state_pre_connect(self): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Handle feedback from SOCKS4a while it is connecting on our behalf.""" |
@@ -47,14 +58,17 @@ def state_pre_connect(self): | |||
return True | |||
|
|||
def proxy_sock_name(self): | |||
return socket.inet_ntoa(self.__proxysockname[0]) | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Handle return value when using SOCKS4a for DNS resolving instead of connecting.""" |
|
||
|
||
class Socks4aConnection(Socks4a): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Child SOCKS4a class used for making outbound connections.""" |
def __init__(self, address): | ||
Socks4a.__init__(self, address=address) | ||
|
||
def state_auth_done(self): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Request connection to be made""" |
@@ -83,6 +97,7 @@ def state_auth_done(self): | |||
return True | |||
|
|||
def state_pre_connect(self): | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Tell SOCKS4a to initiate a connection""" |
def __init__(self, host): | ||
self.host = host | ||
self.port = 8444 | ||
Socks4a.__init__(self, address=(self.host, self.port)) | ||
|
||
def state_auth_done(self): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""DNS resolver class using SOCKS4a""" |
@@ -108,4 +125,5 @@ def state_auth_done(self): | |||
return True | |||
|
|||
def resolved(self): | |||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""""" | |
"""Resolving is done, process the return value. To use this within PyBitmessage, a callback needs to be | |
implemented which hasn't been done yet.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update docstrings, otherwise ok.
Changes based on style and lint checks. (final_code_quality_19)