udp pylint fixes

This commit is contained in:
lakshyacis 2019-09-12 15:24:18 +05:30
parent 498232dbea
commit e74affe636
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
1 changed files with 10 additions and 5 deletions

View File

@ -1,3 +1,7 @@
"""
src/network/udp.py
==================
"""
import time import time
import socket import socket
@ -9,15 +13,16 @@ from objectracker import ObjectTracker
from queues import receiveDataQueue from queues import receiveDataQueue
class UDPSocket(BMProto): class UDPSocket(BMProto): # pylint: disable=too-many-instance-attributes
"""Bitmessage protocol over UDP (class)"""
port = 8444 port = 8444
announceInterval = 60 announceInterval = 60
def __init__(self, host=None, sock=None, announcing=False): def __init__(self, host=None, sock=None, announcing=False):
super(BMProto, self).__init__(sock=sock) super(BMProto, self).__init__(sock=sock) # pylint: disable=bad-super-call
self.verackReceived = True self.verackReceived = True
self.verackSent = True self.verackSent = True
# TODO sort out streams # .. todo:: sort out streams
self.streams = [1] self.streams = [1]
self.fullyEstablished = True self.fullyEstablished = True
self.connectedAt = 0 self.connectedAt = 0
@ -44,6 +49,7 @@ class UDPSocket(BMProto):
self.set_state("bm_header", expectBytes=protocol.Header.size) self.set_state("bm_header", expectBytes=protocol.Header.size)
def set_socket_reuse(self): def set_socket_reuse(self):
"""Set socket reuse option"""
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try: try:
@ -73,8 +79,7 @@ class UDPSocket(BMProto):
decodedIP = protocol.checkIPAddress(str(ip)) decodedIP = protocol.checkIPAddress(str(ip))
if stream not in state.streamsInWhichIAmParticipating: if stream not in state.streamsInWhichIAmParticipating:
continue continue
if (seenTime < time.time() - self.maxTimeOffset or if (seenTime < time.time() - self.maxTimeOffset or seenTime > time.time() + self.maxTimeOffset):
seenTime > time.time() + self.maxTimeOffset):
continue continue
if decodedIP is False: if decodedIP is False:
# if the address isn't local, interpret it as # if the address isn't local, interpret it as