Refactor tcp_intermediate

This commit is contained in:
Dan 2018-05-16 21:14:05 +02:00
parent 64fe9163d2
commit 5f414626ef

View File

@ -27,22 +27,15 @@ log = logging.getLogger(__name__)
class TCPIntermediate(TCP):
def __init__(self, proxy: dict):
super().__init__(proxy)
self.is_first_packet = None
def connect(self, address: tuple):
super().connect(address)
self.is_first_packet = True
super().sendall(b"\xee" * 4)
log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else ""))
def sendall(self, data: bytes, *args):
length = len(data)
data = pack("<i", length) + data
if self.is_first_packet:
data = b"\xee" * 4 + data
self.is_first_packet = False
super().sendall(data)
super().sendall(pack("<i", len(data)) + data)
def recvall(self, length: int = 0) -> bytes or None:
length = super().recvall(4)
@ -50,4 +43,4 @@ class TCPIntermediate(TCP):
if length is None:
return None
return super().recvall(unpack("<I", length)[0])
return super().recvall(unpack("<i", length)[0])