Changes based on style and lint checks. (final_code_quality_5) #1363

Merged
coffeedogs merged 1 commits from final_code_quality_5 into v0.6 2018-10-31 15:11:22 +01:00
coffeedogs commented 2018-10-10 12:25:05 +02:00 (Migrated from github.com)

Changes based on style and lint checks. (final_code_quality_5)

Changes based on style and lint checks. (final_code_quality_5)
coffeedogs commented 2018-10-11 15:00:07 +02:00 (Migrated from github.com)

src/defaults.py is made use of by src/bitmessagemain.py, though I've bumped that to a later PR since otherwise it was going to start pulling in the kivy files in that I haven't finished yet.

`src/defaults.py` is made use of by `src/bitmessagemain.py`, though I've bumped that to a later PR since otherwise it was going to start pulling in the kivy files in that I haven't finished yet.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 09:50:46 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 09:50:46 +02:00

Yea this is workaround for some Windows crap, it uses winsock which is kind of similar to unix' socket, but it can have its own error numbers, and these aren't defined when running python on other OSes. Maybe there is a nicer workaround but for the time being let's keep it as it is.

Yea this is workaround for some Windows crap, it uses winsock which is kind of similar to unix' socket, but it can have its own error numbers, and these aren't defined when running python on other OSes. Maybe there is a nicer workaround but for the time being let's keep it as it is.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 09:57:42 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 09:57:42 +02:00

I'm not sure it's a FIXME, it could also be just a comment. However, it's not a big deal so I'm accepting this hunk.

I'm not sure it's a FIXME, it could also be just a comment. However, it's not a big deal so I'm accepting this hunk.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:44:59 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 10:44:58 +02:00

This is a defense against the so called intersection attacks. It is called when you notice peer is requesting non-existing objects, or right after the connection is established. It will estimate how long an object will take to propagate across the network, and skip processing "getdata" requests until then. This means an attacker only has one shot per IP to perform the attack.

This is a defense against the so called intersection attacks. It is called when you notice peer is requesting non-existing objects, or right after the connection is established. It will estimate how long an object will take to propagate across the network, and skip processing "getdata" requests until then. This means an attacker only has one shot per IP to perform the attack.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:47:38 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 10:47:38 +02:00

State after the bitmessage protocol handshake is completed (version/verack exchange, and if both side support TLS, the TLS handshake as well).

State after the bitmessage protocol handshake is completed (version/verack exchange, and if both side support TLS, the TLS handshake as well).
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:48:50 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 10:48:50 +02:00

Initiate inventory synchronisation.

Initiate inventory synchronisation.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:49:47 +02:00
@ -101,3 +113,4 @@
def set_connection_fully_established(self):
"""Initiate inventory synchronisation."""
if not self.isOutbound and not self.local:
shared.clientHasReceivedIncomingConnections = True
PeterSurda (Migrated from github.com) commented 2018-10-12 10:49:47 +02:00

Send a partial list of known addresses to peer.

Send a partial list of known addresses to peer.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:51:33 +02:00
@ -101,3 +113,4 @@
def set_connection_fully_established(self):
"""Initiate inventory synchronisation."""
if not self.isOutbound and not self.local:
shared.clientHasReceivedIncomingConnections = True
PeterSurda (Migrated from github.com) commented 2018-10-12 10:51:33 +02:00

Send hashes of all inventory objects, chunked as the protocol has a per-command limit.

Send hashes of all inventory objects, chunked as the protocol has a per-command limit.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:51:50 +02:00
@ -101,3 +113,4 @@
def set_connection_fully_established(self):
"""Initiate inventory synchronisation."""
if not self.isOutbound and not self.local:
shared.clientHasReceivedIncomingConnections = True
PeterSurda (Migrated from github.com) commented 2018-10-12 10:51:50 +02:00

Send one chunk of inv entries in one command

Send one chunk of inv entries in one command
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:52:22 +02:00
@ -182,2 +192,4 @@
for obj_hash, _ in bigInvList.items():
payload += obj_hash
objectCount += 1
PeterSurda (Migrated from github.com) commented 2018-10-12 10:52:22 +02:00

Callback for TCP connection being established.

Callback for TCP connection being established.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:53:27 +02:00
@ -182,2 +192,4 @@
for obj_hash, _ in bigInvList.items():
payload += obj_hash
objectCount += 1
PeterSurda (Migrated from github.com) commented 2018-10-12 10:53:27 +02:00

Callback for reading from a socket

Callback for reading from a socket
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:53:40 +02:00
@ -206,4 +223,4 @@
self.connectedAt = time.time()
receiveDataQueue.put(self.destination)
def handle_read(self):
PeterSurda (Migrated from github.com) commented 2018-10-12 10:53:40 +02:00

Callback for writing to a socket

Callback for writing to a socket
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:53:56 +02:00
@ -206,4 +223,4 @@
self.connectedAt = time.time()
receiveDataQueue.put(self.destination)
def handle_read(self):
PeterSurda (Migrated from github.com) commented 2018-10-12 10:53:56 +02:00

Callback for connection being closed.

Callback for connection being closed.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:54:22 +02:00
@ -220,3 +238,4 @@
def handle_write(self):
"""Callback for writing to a socket"""
TLSDispatcher.handle_write(self)
PeterSurda (Migrated from github.com) commented 2018-10-12 10:54:22 +02:00

SOCKS5 wrapper for TCP connections

SOCKS5 wrapper for TCP connections
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:55:00 +02:00
@ -220,3 +238,4 @@
def handle_write(self):
"""Callback for writing to a socket"""
TLSDispatcher.handle_write(self)
PeterSurda (Migrated from github.com) commented 2018-10-12 10:55:00 +02:00

State when SOCKS5 connection succeeds, we need to send a Bitmessage handshake to peer.

State when SOCKS5 connection succeeds, we need to send a Bitmessage handshake to peer.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:55:16 +02:00
@ -220,3 +238,4 @@
def handle_write(self):
"""Callback for writing to a socket"""
TLSDispatcher.handle_write(self)
PeterSurda (Migrated from github.com) commented 2018-10-12 10:55:16 +02:00

SOCKS4a wrapper for TCP connections

SOCKS4a wrapper for TCP connections
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:55:35 +02:00
@ -220,3 +238,4 @@
def handle_write(self):
"""Callback for writing to a socket"""
TLSDispatcher.handle_write(self)
PeterSurda (Migrated from github.com) commented 2018-10-12 10:55:34 +02:00

State when SOCKS4a connection succeeds, we need to send a Bitmessage handshake to peer.

State when SOCKS4a connection succeeds, we need to send a Bitmessage handshake to peer.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:56:11 +02:00
@ -220,3 +238,4 @@
def handle_write(self):
"""Callback for writing to a socket"""
TLSDispatcher.handle_write(self)
PeterSurda (Migrated from github.com) commented 2018-10-12 10:56:11 +02:00

TCP connection server for Bitmessage protocol

TCP connection server for Bitmessage protocol
PeterSurda (Migrated from github.com) reviewed 2018-10-12 10:56:29 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 10:56:29 +02:00

Is the socket bound?

Is the socket bound?
PeterSurda (Migrated from github.com) reviewed 2018-10-12 11:01:05 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-12 11:01:05 +02:00

Incoming connection callback

Incoming connection callback
PeterSurda (Migrated from github.com) reviewed 2018-10-12 11:24:01 +02:00
@ -286,3 +318,3 @@
from debug import logger
"""Add a port mapping"""
for i in range(50):
PeterSurda (Migrated from github.com) commented 2018-10-12 11:24:00 +02:00

This doesn't do anything so it can be removed.

This doesn't do anything so it can be removed.
PeterSurda (Migrated from github.com) reviewed 2018-10-12 11:24:55 +02:00
PeterSurda (Migrated from github.com) left a comment

Make the small changes (docstrings, obsolete code) and it's ready to go.

Make the small changes (docstrings, obsolete code) and it's ready to go.
coffeedogs (Migrated from github.com) reviewed 2018-10-15 12:38:47 +02:00
coffeedogs (Migrated from github.com) commented 2018-10-15 12:38:46 +02:00

The todo was added to consider the fixme. I consider it now well considered. I've formatted it as part of the docstring.

The todo was added to consider the fixme. I consider it now well considered. I've formatted it as part of the docstring.
coffeedogs (Migrated from github.com) reviewed 2018-10-15 12:39:02 +02:00
coffeedogs (Migrated from github.com) commented 2018-10-15 12:39:02 +02:00

Updated in next commit...

Updated in next commit...
coffeedogs (Migrated from github.com) reviewed 2018-10-15 12:50:16 +02:00
@ -286,3 +318,3 @@
from debug import logger
"""Add a port mapping"""
for i in range(50):
coffeedogs (Migrated from github.com) commented 2018-10-15 12:50:16 +02:00

OK, removed. Where I found unused variables involving unpack I left in the unpacks in case there was some state to do with unpacking lying around.

OK, removed. Where I found unused variables involving unpack I left in the unpacks in case there was some state to do with unpacking lying around.
g1itch (Migrated from github.com) reviewed 2018-10-15 17:11:22 +02:00
g1itch (Migrated from github.com) commented 2018-10-15 17:11:22 +02:00

see 533df80

see 533df80
g1itch (Migrated from github.com) reviewed 2018-10-15 17:23:55 +02:00
@ -230,14 +262,11 @@ class uPnPThread(threading.Thread, StoppableThread):
logger.debug("Found UPnP router at %s", ip)
g1itch (Migrated from github.com) commented 2018-10-15 17:23:54 +02:00

This statement can be probably removed. I cannot find where this shared.alreadyAttemptedConnectionsList used.

This statement can be probably removed. I cannot find where this `shared.alreadyAttemptedConnectionsList` used.
coffeedogs (Migrated from github.com) reviewed 2018-10-18 21:13:48 +02:00
@ -230,14 +262,11 @@ class uPnPThread(threading.Thread, StoppableThread):
logger.debug("Found UPnP router at %s", ip)
coffeedogs (Migrated from github.com) commented 2018-10-18 21:13:48 +02:00

OK, removed that context.
Edit: Actually, removed the whole list / lock, will also remove from shared.py when I commit the changed to that file.

OK, removed that context. Edit: Actually, removed the whole list / lock, will also remove from shared.py when I commit the changed to that file.
PeterSurda (Migrated from github.com) reviewed 2018-10-27 18:06:38 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-27 18:06:37 +02:00
    """Event to read from the object, i.e. its network socket."""
```suggestion """Event to read from the object, i.e. its network socket.""" ```
PeterSurda (Migrated from github.com) reviewed 2018-10-27 18:07:04 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-27 18:07:04 +02:00
    """Event to write to the object, i.e. its network socket."""
```suggestion """Event to write to the object, i.e. its network socket.""" ```
PeterSurda (Migrated from github.com) reviewed 2018-10-27 18:10:08 +02:00
PeterSurda (Migrated from github.com) commented 2018-10-27 18:10:08 +02:00
    """Poll in a loop, until count or timeout is reached"""
```suggestion """Poll in a loop, until count or timeout is reached""" ```
PeterSurda (Migrated from github.com) reviewed 2018-10-28 13:57:42 +01:00
@ -139,2 +149,2 @@
filtered = {k: v for k, v in knownnodes.knownNodes[stream*2].items()
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
if knownnodes.knownNodes[stream * 2] and stream not in self.streams:
filtered = {k: v for k, v in knownnodes.knownNodes[stream * 2].items()
PeterSurda (Migrated from github.com) commented 2018-10-28 13:57:41 +01:00

It looks like ObjectTracker is used as a mixin, but it has an __init__. Other than suppressing the pylint warning, I'm not sure there's anything else to do. We could rename the __init__ to _fake_init, but then we would have to suppress attribute-defined-outside-init. I would leave it as it is unless there's something I'm missing.

It looks like `ObjectTracker` is used as a mixin, but it has an `__init__`. Other than suppressing the pylint warning, I'm not sure there's anything else to do. We could rename the `__init__` to `_fake_init`, but then we would have to suppress `attribute-defined-outside-init`. I would leave it as it is unless there's something I'm missing.
PeterSurda (Migrated from github.com) approved these changes 2018-10-28 14:46:46 +01:00
PeterSurda (Migrated from github.com) left a comment

Minor changes in docstrings, but I don't want to review it again so it's good to go. The docstrings can be adjusted later with a separate PR.

Minor changes in docstrings, but I don't want to review it again so it's good to go. The docstrings can be adjusted later with a separate PR.
coffeedogs (Migrated from github.com) reviewed 2018-10-31 15:03:10 +01:00
@ -139,2 +149,2 @@
filtered = {k: v for k, v in knownnodes.knownNodes[stream*2].items()
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
if knownnodes.knownNodes[stream * 2] and stream not in self.streams:
filtered = {k: v for k, v in knownnodes.knownNodes[stream * 2].items()
coffeedogs (Migrated from github.com) commented 2018-10-31 15:03:09 +01:00

I would expect a mixin class to be defined as a parent: class TCPConnection(BMProto, TLSDispatcher, ObjectTracker): and for the __init__s to be called in an appropriate order, each seeing *args and **kwargs and each updating self as they go, passing off initialisation to the next parent class using super(ThisClass, self).__init__(*args, **kwargs).

However, if this is working as intended, perhaps re-initialisation is both happening and required? Either way, fixing this bad code smell will require some consideration, refactoring and testing.

I would expect a mixin class to be defined as a parent: `class TCPConnection(BMProto, TLSDispatcher, ObjectTracker):` and for the `__init__`s to be called in an appropriate order, each seeing `*args` and `**kwargs` and each updating self as they go, passing off initialisation to the next parent class using `super(ThisClass, self).__init__(*args, **kwargs)`. However, if this is working as intended, perhaps re-initialisation is both happening and required? Either way, fixing this bad code smell will require some consideration, refactoring and testing.
g1itch (Migrated from github.com) reviewed 2018-10-31 15:31:04 +01:00
@ -139,2 +149,2 @@
filtered = {k: v for k, v in knownnodes.knownNodes[stream*2].items()
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
if knownnodes.knownNodes[stream * 2] and stream not in self.streams:
filtered = {k: v for k, v in knownnodes.knownNodes[stream * 2].items()
g1itch (Migrated from github.com) commented 2018-10-31 15:31:04 +01:00

super() wont work without refactoring, I tried.

`super()` wont work without refactoring, I tried.
This repo is archived. You cannot comment on pull requests.
No description provided.