bmproto pylint fixes
This commit is contained in:
parent
469d289a97
commit
5521c16478
|
@ -1,3 +1,8 @@
|
||||||
|
"""
|
||||||
|
src/network/bmproto.py
|
||||||
|
==================================
|
||||||
|
"""
|
||||||
|
# pylint: disable=attribute-defined-outside-init
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import socket
|
import socket
|
||||||
|
@ -43,6 +48,7 @@ class BMProtoExcessiveDataError(BMProtoError):
|
||||||
|
|
||||||
class BMProto(AdvancedDispatcher, ObjectTracker):
|
class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
"""A parser for the Bitmessage Protocol"""
|
"""A parser for the Bitmessage Protocol"""
|
||||||
|
# pylint: disable=too-many-instance-attributes, too-many-public-methods
|
||||||
# ~1.6 MB which is the maximum possible size of an inv message.
|
# ~1.6 MB which is the maximum possible size of an inv message.
|
||||||
maxMessageSize = 1600100
|
maxMessageSize = 1600100
|
||||||
# 2**18 = 256kB is the maximum size of an object payload
|
# 2**18 = 256kB is the maximum size of an object payload
|
||||||
|
@ -57,7 +63,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
maxTimeOffset = 3600
|
maxTimeOffset = 3600
|
||||||
timeOffsetWrongCount = 0
|
timeOffsetWrongCount = 0
|
||||||
|
|
||||||
def __init__(self, address=None, sock=None):
|
def __init__(self, address=None, sock=None): # pylint: disable=unused-argument, super-init-not-called
|
||||||
AdvancedDispatcher.__init__(self, sock)
|
AdvancedDispatcher.__init__(self, sock)
|
||||||
self.isOutbound = False
|
self.isOutbound = False
|
||||||
# packet/connection from a local IP
|
# packet/connection from a local IP
|
||||||
|
@ -97,7 +103,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
length=protocol.Header.size, expectBytes=self.payloadLength)
|
length=protocol.Header.size, expectBytes=self.payloadLength)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def state_bm_command(self):
|
def state_bm_command(self): # pylint: disable=too-many-branches
|
||||||
"""Process incoming command"""
|
"""Process incoming command"""
|
||||||
self.payload = self.read_buf[:self.payloadLength]
|
self.payload = self.read_buf[:self.payloadLength]
|
||||||
if self.checksum != hashlib.sha512(self.payload).digest()[0:4]:
|
if self.checksum != hashlib.sha512(self.payload).digest()[0:4]:
|
||||||
|
@ -181,7 +187,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
|
|
||||||
return Node(services, host, port)
|
return Node(services, host, port)
|
||||||
|
|
||||||
def decode_payload_content(self, pattern="v"):
|
def decode_payload_content(self, pattern="v"): # pylint: disable=too-many-branches, too-many-statements
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Decode the payload depending on pattern:
|
Decode the payload depending on pattern:
|
||||||
|
|
||||||
|
@ -197,7 +204,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
, = end of array
|
, = end of array
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def decode_simple(self, char="v"):
|
def decode_simple(self, char="v"): # pylint: disable=inconsistent-return-statements
|
||||||
"""Decode the payload using one char pattern"""
|
"""Decode the payload using one char pattern"""
|
||||||
if char == "v":
|
if char == "v":
|
||||||
return self.decode_payload_varint()
|
return self.decode_payload_varint()
|
||||||
|
@ -251,6 +258,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
for j in range(parserStack[-1][4], len(parserStack[-1][3])):
|
for j in range(parserStack[-1][4], len(parserStack[-1][3])):
|
||||||
if parserStack[-1][3][j] not in "lL0123456789":
|
if parserStack[-1][3][j] not in "lL0123456789":
|
||||||
break
|
break
|
||||||
|
# pylint: disable=undefined-loop-variable
|
||||||
parserStack.append([
|
parserStack.append([
|
||||||
size, size, isArray,
|
size, size, isArray,
|
||||||
parserStack[-1][3][parserStack[-1][4]:j + 1], 0, []
|
parserStack[-1][3][parserStack[-1][4]:j + 1], 0, []
|
||||||
|
@ -422,7 +430,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
|
|
||||||
def bm_command_addr(self):
|
def bm_command_addr(self):
|
||||||
"""Incoming addresses, process them"""
|
"""Incoming addresses, process them"""
|
||||||
addresses = self._decode_addr()
|
addresses = self._decode_addr() # pylint: disable=redefined-outer-name
|
||||||
for i in addresses:
|
for i in addresses:
|
||||||
seenTime, stream, services, ip, port = i
|
seenTime, stream, services, ip, port = i
|
||||||
decodedIP = protocol.checkIPAddress(str(ip))
|
decodedIP = protocol.checkIPAddress(str(ip))
|
||||||
|
@ -462,7 +470,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
self.append_write_buf(protocol.CreatePacket('pong'))
|
self.append_write_buf(protocol.CreatePacket('pong'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bm_command_pong(self):
|
def bm_command_pong(self): # pylint: disable=no-self-use
|
||||||
"""
|
"""
|
||||||
Incoming pong.
|
Incoming pong.
|
||||||
Ignore it. PyBitmessage pings connections after about 5 minutes
|
Ignore it. PyBitmessage pings connections after about 5 minutes
|
||||||
|
@ -530,7 +538,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
length=self.payloadLength, expectBytes=0)
|
length=self.payloadLength, expectBytes=0)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def peerValidityChecks(self):
|
def peerValidityChecks(self): # pylint: disable=too-many-return-statements
|
||||||
"""Check the validity of the peer"""
|
"""Check the validity of the peer"""
|
||||||
if self.remoteProtocolVersion < 3:
|
if self.remoteProtocolVersion < 3:
|
||||||
self.append_write_buf(protocol.assembleErrorMessage(
|
self.append_write_buf(protocol.assembleErrorMessage(
|
||||||
|
|
Reference in New Issue
Block a user