Refactor tcp_abridged
This commit is contained in:
parent
963c4e9a7a
commit
64fe9163d2
@ -26,28 +26,23 @@ log = logging.getLogger(__name__)
|
|||||||
class TCPAbridged(TCP):
|
class TCPAbridged(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"\xef")
|
||||||
|
|
||||||
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) // 4
|
length = len(data) // 4
|
||||||
|
|
||||||
data = (
|
super().sendall(
|
||||||
bytes([length]) + data
|
(bytes([length])
|
||||||
if length <= 126
|
if length <= 126
|
||||||
else b"\x7f" + int.to_bytes(length, 3, "little") + data
|
else b"\x7f" + length.to_bytes(3, "little"))
|
||||||
|
+ data
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.is_first_packet:
|
|
||||||
data = b"\xef" + 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(1)
|
length = super().recvall(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user