-
Notifications
You must be signed in to change notification settings - Fork 32
Issue #368: Bad packet size handling in built-in server handlers #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
180aa55
cedc7cb
ec2ebab
921b1ad
4e12180
e58e893
613da40
4aca498
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,27 +19,48 @@ def __init__(self, input_type=None, output_type=None, **kwargs): | |
| If packet is specified but not present in default tlm dict. | ||
| """ | ||
| super(PacketHandler, self).__init__(input_type, output_type) | ||
| self.packet = kwargs.get("packet", None) | ||
| self.packet_type = kwargs.get("packet", None) | ||
| self.tlm_dict = tlm.getDefaultDict() | ||
|
|
||
| if not self.packet: | ||
| msg = 'PacketHandler: No packet name provided in handler config as key "packet"' | ||
| if not self.packet_type: | ||
| msg = f'PacketHandler: No packet type provided in handler config as key "packet"' | ||
| raise ValueError(msg) | ||
|
|
||
| tlm_dict = tlm.getDefaultDict() | ||
| if self.packet not in tlm_dict: | ||
| msg = "PacketHandler: Packet name {} not present in telemetry dictionary".format( | ||
| self.packet | ||
| ) | ||
| msg += " Available packet types are {}".format(tlm_dict.keys()) | ||
| if self.packet_type not in self.tlm_dict: | ||
| msg = f"PacketHandler: Packet name '{self.packet_type}' not present in telemetry dictionary." | ||
| msg += f" Available packet types are {self.tlm_dict.keys()}" | ||
| raise ValueError(msg) | ||
|
|
||
| self._pkt_defn = tlm_dict[self.packet] | ||
| self._pkt_defn = self.tlm_dict[self.packet_type] | ||
|
||
|
|
||
| def handle(self, input_data): | ||
| def get_packet_lengths(self): | ||
| """ | ||
| Makes a dictionary of packet.name : number of bytes in the packet | ||
| e.g. 'Ethernet_HS_Packet': 37 | ||
|
|
||
| Return: dictionary | ||
|
|
||
| """ | ||
| pkt_len_dict = {} | ||
| for i in self.tlm_dict.keys(): | ||
| pkt_len_dict[i] = self.tlm_dict[i].nbytes | ||
|
|
||
| return pkt_len_dict | ||
|
|
||
| def handle(self, packet): | ||
| """ | ||
| Params: | ||
| input_data: message received by stream | ||
| packet: message received by stream (packet) | ||
| Returns: | ||
| tuple of packet UID and message received by stream | ||
| """ | ||
| return pickle.dumps((self._pkt_defn.uid, input_data), 2) | ||
|
|
||
| # TODO validate the packet (if this is the place to do the validation) | ||
|
|
||
| defined_packet_lengths = self.get_packet_lengths() | ||
|
|
||
| if defined_packet_lengths[self.packet_type] != packet.nbytes: | ||
nttoole marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| msg = f"PacketHandler: Packet length of packet does not match packet definition." | ||
|
||
| raise ValueError(msg) | ||
|
||
|
|
||
| return pickle.dumps((self._pkt_defn.uid, packet), 2) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update this field to be
packet_name?