mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Refactor tcp_intermediate
This commit is contained in:
parent
64fe9163d2
commit
5f414626ef
1 changed files with 4 additions and 11 deletions
|
|
@ -27,22 +27,15 @@ log = logging.getLogger(__name__)
|
||||||
class TCPIntermediate(TCP):
|
class TCPIntermediate(TCP):
|
||||||
def __init__(self, proxy: dict):
|
def __init__(self, proxy: dict):
|
||||||
super().__init__(proxy)
|
super().__init__(proxy)
|
||||||
self.is_first_packet = None
|
|
||||||
|
|
||||||
def connect(self, address: tuple):
|
def connect(self, address: tuple):
|
||||||
super().connect(address)
|
super().connect(address)
|
||||||
self.is_first_packet = True
|
super().sendall(b"\xee" * 4)
|
||||||
|
|
||||||
log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else ""))
|
log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else ""))
|
||||||
|
|
||||||
def sendall(self, data: bytes, *args):
|
def sendall(self, data: bytes, *args):
|
||||||
length = len(data)
|
super().sendall(pack("<i", len(data)) + data)
|
||||||
data = pack("<i", length) + data
|
|
||||||
|
|
||||||
if self.is_first_packet:
|
|
||||||
data = b"\xee" * 4 + data
|
|
||||||
self.is_first_packet = False
|
|
||||||
|
|
||||||
super().sendall(data)
|
|
||||||
|
|
||||||
def recvall(self, length: int = 0) -> bytes or None:
|
def recvall(self, length: int = 0) -> bytes or None:
|
||||||
length = super().recvall(4)
|
length = super().recvall(4)
|
||||||
|
|
@ -50,4 +43,4 @@ class TCPIntermediate(TCP):
|
||||||
if length is None:
|
if length is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return super().recvall(unpack("<I", length)[0])
|
return super().recvall(unpack("<i", length)[0])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue