Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

coffeedogs
Copy link
Contributor

Changes based on style and lint checks. (final_code_quality_19)

@Singleton
class Dandelion():
class Dandelion:
""""""
Copy link
Member

@PeterSurda PeterSurda Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Dandelion class for tracking stem/fluff stages."""

@@ -35,44 +44,52 @@ def __init__(self):
self.lock = RLock()

def poissonTimeout(self, start=None, average=0):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Generate deadline using Poisson distribution"""


def addHash(self, hashId, source=None, stream=1):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Add inventory vector to dandelion stem"""


def setHashStream(self, hashId, stream=1):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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)
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Switch inventory vector from stem to fluff mode"""

with self.lock:
try:
del self.hashMap[hashId]
except KeyError:
pass

def hasHash(self, hashId):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Is inventory vector in stem mode?"""

return hashId in self.hashMap

def objectChildStem(self, hashId):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Child (i.e. next) node for an inventory vector during stem mode"""

return self.hashMap[hashId].child

def maybeAddStem(self, connection):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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):
""""""
Copy link
Member

@PeterSurda PeterSurda Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Re-shuffle stem mapping (parent <-> child pairs)"""


class Socks4aError(ProxyError):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""SOCKS4a error base class"""



class Socks4a(Proxy):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""SOCKS4a proxy class"""

def __init__(self, address=None):
Proxy.__init__(self, address)
self.ipaddr = None
self.destport = address[1]

def state_init(self):
""""""
Copy link
Member

@PeterSurda PeterSurda Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Protocol initialisation (before connection is established)"""

self.set_state("auth_done", 0)
return True

def state_pre_connect(self):
""""""
Copy link
Member

@PeterSurda PeterSurda Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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])
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Handle return value when using SOCKS4a for DNS resolving instead of connecting."""



class Socks4aConnection(Socks4a):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Child SOCKS4a class used for making outbound connections."""

def __init__(self, address):
Socks4a.__init__(self, address=address)

def state_auth_done(self):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Request connection to be made"""

@@ -83,6 +97,7 @@ def state_auth_done(self):
return True

def state_pre_connect(self):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""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):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""DNS resolver class using SOCKS4a"""

@@ -108,4 +125,5 @@ def state_auth_done(self):
return True

def resolved(self):
""""""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""""""
"""Resolving is done, process the return value. To use this within PyBitmessage, a callback needs to be
implemented which hasn't been done yet."""

Copy link
Member

@PeterSurda PeterSurda left a 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.

g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 8, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 8, 2019
@g1itch g1itch closed this Jul 8, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 8, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 8, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 10, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 10, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 11, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 11, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 25, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 25, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Jul 26, 2019
g1itch added a commit to g1itch/PyBitmessage that referenced this pull request Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants