feat: implement dict on control messages

This commit is contained in:
ChillerDragon 2024-06-16 10:52:48 +08:00
parent c19f0dfdab
commit 545c93cff1
11 changed files with 70 additions and 0 deletions

View file

@ -7,6 +7,11 @@ class CtrlAccept(PrettyPrint):
self.message_name: str = 'accept' self.message_name: str = 'accept'
self.message_id: int = 3 self.message_id: int = 3
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
return False return False

View file

@ -15,6 +15,13 @@ class CtrlClose(PrettyPrint):
self.reason: Optional[str] = reason self.reason: Optional[str] = reason
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'reason', self.reason
# first byte of data # first byte of data
# has to be the first byte of the message payload # has to be the first byte of the message payload
# NOT the chunk header and NOT the message id # NOT the chunk header and NOT the message id

View file

@ -19,6 +19,13 @@ class CtrlConnect(PrettyPrint):
self.response_token: bytes = response_token self.response_token: bytes = response_token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'response_token', self.response_token
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
# anti reflection attack # anti reflection attack
if len(data) < 512: if len(data) < 512:

View file

@ -18,6 +18,13 @@ class CtrlConnectAccept(PrettyPrint):
self.response_token: bytes = response_token self.response_token: bytes = response_token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'response_token', self.response_token
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
self.response_token = data[0:4] self.response_token = data[0:4]
return True return True

View file

@ -7,6 +7,11 @@ class CtrlKeepAlive(PrettyPrint):
self.message_name: str = 'keep_alive' self.message_name: str = 'keep_alive'
self.message_id: int = 0 self.message_id: int = 0
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
return False return False

View file

@ -12,6 +12,14 @@ class CtrlToken(PrettyPrint):
self.response_token: bytes = response_token self.response_token: bytes = response_token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'response_token', self.response_token
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
if not we_are_a_client: if not we_are_a_client:
# anti reflection attack # anti reflection attack

View file

@ -7,6 +7,11 @@ class CtrlAccept(PrettyPrint):
self.message_name: str = 'accept' self.message_name: str = 'accept'
self.message_id: int = 2 self.message_id: int = 2
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
return False return False

View file

@ -15,6 +15,13 @@ class CtrlClose(PrettyPrint):
self.reason: Optional[str] = reason self.reason: Optional[str] = reason
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'reason', self.reason
# first byte of data # first byte of data
# has to be the first byte of the message payload # has to be the first byte of the message payload
# NOT the chunk header and NOT the message id # NOT the chunk header and NOT the message id

View file

@ -12,6 +12,13 @@ class CtrlConnect(PrettyPrint):
self.response_token: bytes = response_token self.response_token: bytes = response_token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'response_token', self.response_token
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
# anti reflection attack # anti reflection attack
if len(data) < 512: if len(data) < 512:

View file

@ -7,6 +7,11 @@ class CtrlKeepAlive(PrettyPrint):
self.message_name: str = 'keep_alive' self.message_name: str = 'keep_alive'
self.message_id: int = 0 self.message_id: int = 0
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
return False return False

View file

@ -12,6 +12,13 @@ class CtrlToken(PrettyPrint):
self.response_token: bytes = response_token self.response_token: bytes = response_token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'response_token', self.response_token
def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool: def unpack(self, data: bytes, we_are_a_client: bool = True) -> bool:
if not we_are_a_client: if not we_are_a_client:
# anti reflection attack # anti reflection attack