-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,089 additions
and
1,367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
__pycache__/ | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python3 | ||
|
||
############################################################################ | ||
# # | ||
# PyTCP - Python TCP/IP stack # | ||
# Copyright (C) 2020-present Sebastian Majewski # | ||
# # | ||
# This program is free software: you can redistribute it and/or modify # | ||
# it under the terms of the GNU General Public License as published by # | ||
# the Free Software Foundation, either version 3 of the License, or # | ||
# (at your option) any later version. # | ||
# # | ||
# This program is distributed in the hope that it will be useful, # | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
# GNU General Public License for more details. # | ||
# # | ||
# You should have received a copy of the GNU General Public License # | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. # | ||
# # | ||
# Author's email: [email protected] # | ||
# Github repository: https://github.com/ccie18643/PyTCP # | ||
# # | ||
############################################################################ | ||
|
||
|
||
""" | ||
Module contains methods supporting errors. | ||
pytcp/lib/errors.py | ||
ver 2.7 | ||
""" | ||
|
||
|
||
from __future__ import annotations | ||
|
||
|
||
class PyTcpError(Exception): | ||
""" | ||
Base class for all PyTCP exceptions. | ||
""" | ||
|
||
... | ||
|
||
|
||
class UnsupportedCaseError(PyTcpError): | ||
""" | ||
Exception raised when the not supposed to be reached | ||
'match' case is being reached for whatever reason. | ||
""" | ||
|
||
... | ||
|
||
|
||
class PacketValidationError(PyTcpError): | ||
""" | ||
Exception raised when packet validation fails. | ||
""" | ||
|
||
... | ||
|
||
|
||
class PacketIntegrityError(PacketValidationError): | ||
""" | ||
Exception raised when integrity check fails. | ||
""" | ||
|
||
def __init__(self, message: str): | ||
super().__init__("[INTEGRITY]" + message) | ||
|
||
|
||
class PacketSanityError(PacketValidationError): | ||
""" | ||
Exception raised when sanity check fails. | ||
""" | ||
|
||
def __init__(self, message: str): | ||
super().__init__("[SANITY]" + message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
############################################################################ | ||
# # | ||
# PyTCP - Python TCP/IP stack # | ||
# Copyright (C) 2020-present Sebastian Majewski # | ||
# # | ||
# This program is free software: you can redistribute it and/or modify # | ||
# it under the terms of the GNU General Public License as published by # | ||
# the Free Software Foundation, either version 3 of the License, or # | ||
# (at your option) any later version. # | ||
# # | ||
# This program is distributed in the hope that it will be useful, # | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
# GNU General Public License for more details. # | ||
# # | ||
# You should have received a copy of the GNU General Public License # | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. # | ||
# # | ||
# Author's email: [email protected] # | ||
# Github repository: https://github.com/ccie18643/PyTCP # | ||
# # | ||
############################################################################ | ||
|
||
|
||
""" | ||
Module contains the ProtocolEnum class. | ||
pytcp/lib/protocol_enum.py | ||
ver 2.7 | ||
""" | ||
|
||
|
||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import Self | ||
|
||
|
||
class ProtocolEnum(Enum): | ||
def __int__(self) -> int: | ||
return int(self.value) | ||
|
||
def __str__(self) -> str: | ||
return str(self.value) | ||
|
||
@staticmethod | ||
def _extract(frame: bytes) -> int: | ||
raise NotImplementedError | ||
|
||
@classmethod | ||
def from_frame(cls, /, frame: bytes) -> Self: | ||
return cls(cls._extract(frame)) | ||
|
||
@classmethod | ||
def sanity_check(cls, /, frame: bytes) -> bool: | ||
return cls._extract(frame) in cls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.