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):
|
||||
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])
|
||||
|
|
|
|||
Loading…
Reference in a new issue