37 lines
1011 B
Python
37 lines
1011 B
Python
"""
|
|
Contains the Packet class to help with the transmission, reading, and verification of infermation over the network
|
|
"""
|
|
|
|
|
|
class Packet:
|
|
"""
|
|
Class that contains information to be sent over the network. Can self-verify and has methods (will have methods) to
|
|
easily encode and decode packet information
|
|
"""
|
|
VALID_HEADERS = [
|
|
'PYPONGREQ',
|
|
'PYPONGRST'
|
|
]
|
|
VALID_TYPES = [
|
|
'SVRINFO'
|
|
]
|
|
|
|
def __init__(self, header, msg_type, *message):
|
|
self.header = header
|
|
self.msg_type = msg_type
|
|
self.message = []
|
|
for x in message:
|
|
self.message.append(x)
|
|
|
|
def integrity_check(self):
|
|
"""
|
|
Verify that the information in the packet is correct and makes sense
|
|
|
|
:return: True if packet verifies correctly, False if not
|
|
"""
|
|
if self.header not in Packet.VALID_HEADERS:
|
|
return False
|
|
if self.msg_type not in Packet.VALID_TYPES:
|
|
return False
|
|
return True
|