Skip to content

Commit

Permalink
Cleaning up config
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 15, 2024
1 parent 7c6667f commit d9cdd39
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 21 deletions.
6 changes: 0 additions & 6 deletions pytcp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@

from __future__ import annotations

# IPv6 default Hop Limit value.
IP6__DEFAULT_HOP_LIMIT = 64

# IPv4/IPv6 minimum MTU values.
IP4__MIN_MTU = 576 # RFC 791
IP6__MIN_MTU = 1280 # RFC 8200

# IPv4 default TTL value.
IP4__DEFAULT_TTL = 64

# TCP/UDP ephemeral port range to be used by outbound connections.
EPHEMERAL_PORT_RANGE = range(32168, 60700, 2)

Expand Down
40 changes: 40 additions & 0 deletions pytcp/protocols/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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 ##
## ##
################################################################################


"""
This module contains protocols related defaults.
pytcp/protocols/defaults.py
ver 3.0.2
"""


from __future__ import annotations

IP4__DEFAULT_TTL = 64

IP6__DEFAULT_HOP_LIMIT = 64
6 changes: 3 additions & 3 deletions pytcp/protocols/ip4/ip4__assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
from typing import TYPE_CHECKING

from net_addr import Ip4Address
from pytcp import config
from pytcp.lib.int_checks import is_4_byte_alligned
from pytcp.lib.proto_assembler import ProtoAssembler
from pytcp.lib.tracker import Tracker
from pytcp.protocols.defaults import IP4__DEFAULT_TTL
from pytcp.protocols.enums import IpProto
from pytcp.protocols.ip4.ip4__base import Ip4
from pytcp.protocols.ip4.ip4__header import IP4__HEADER__LEN, Ip4Header
Expand All @@ -68,7 +68,7 @@ def __init__(
*,
ip4__src: Ip4Address = Ip4Address(),
ip4__dst: Ip4Address = Ip4Address(),
ip4__ttl: int = config.IP4__DEFAULT_TTL,
ip4__ttl: int = IP4__DEFAULT_TTL,
ip4__dscp: int = 0,
ip4__ecn: int = 0,
ip4__id: int = 0,
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(
*,
ip4_frag__src: Ip4Address = Ip4Address(),
ip4_frag__dst: Ip4Address = Ip4Address(),
ip4_frag__ttl: int = config.IP4__DEFAULT_TTL,
ip4_frag__ttl: int = IP4__DEFAULT_TTL,
ip4_frag__dscp: int = 0,
ip4_frag__ecn: int = 0,
ip4_frag__id: int = 0,
Expand Down
4 changes: 2 additions & 2 deletions pytcp/protocols/ip6/ip6__assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from typing import TYPE_CHECKING

from net_addr import Ip6Address
from pytcp import config
from pytcp.lib.proto_assembler import ProtoAssembler
from pytcp.protocols.defaults import IP6__DEFAULT_HOP_LIMIT
from pytcp.protocols.enums import IpProto
from pytcp.protocols.ip6.ip6__base import Ip6
from pytcp.protocols.ip6.ip6__header import Ip6Header
Expand All @@ -62,7 +62,7 @@ def __init__(
*,
ip6__src: Ip6Address = Ip6Address(),
ip6__dst: Ip6Address = Ip6Address(),
ip6__hop: int = config.IP6__DEFAULT_HOP_LIMIT,
ip6__hop: int = IP6__DEFAULT_HOP_LIMIT,
ip6__dscp: int = 0,
ip6__ecn: int = 0,
ip6__flow: int = 0,
Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__icmp4__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class PacketHandlerIcmp4Tx(ABC):

if TYPE_CHECKING:
from net_addr import Ip4Address
from pytcp.config import IP4__DEFAULT_TTL
from pytcp.lib.packet_stats import PacketStatsTx
from pytcp.protocols.defaults import IP4__DEFAULT_TTL
from pytcp.protocols.ip4.ip4__base import Ip4Payload
from pytcp.protocols.raw.raw__assembler import RawAssembler

Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__icmp6__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class PacketHandlerIcmp6Tx(ABC):
"""

if TYPE_CHECKING:
from pytcp.config import IP6__DEFAULT_HOP_LIMIT
from pytcp.lib.packet_stats import PacketStatsTx
from pytcp.protocols.defaults import IP6__DEFAULT_HOP_LIMIT
from pytcp.protocols.ip6.ip6__base import Ip6Payload
from pytcp.protocols.raw.raw__assembler import RawAssembler

Expand Down
4 changes: 2 additions & 2 deletions pytcp/stack/packet_handler/packet_handler__ip4__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
from typing import TYPE_CHECKING

from net_addr import Ip4Address, MacAddress
from pytcp import config
from pytcp.lib.logger import log
from pytcp.lib.tx_status import TxStatus
from pytcp.protocols.defaults import IP4__DEFAULT_TTL
from pytcp.protocols.ip4.ip4__assembler import Ip4Assembler, Ip4FragAssembler
from pytcp.protocols.raw.raw__assembler import RawAssembler
from pytcp.protocols.tcp.tcp__assembler import TcpAssembler
Expand Down Expand Up @@ -90,7 +90,7 @@ def _phtx_ip4(
*,
ip4__dst: Ip4Address,
ip4__src: Ip4Address,
ip4__ttl: int = config.IP4__DEFAULT_TTL,
ip4__ttl: int = IP4__DEFAULT_TTL,
ip4__payload: Ip4Payload = RawAssembler(),
) -> TxStatus:
"""
Expand Down
4 changes: 2 additions & 2 deletions pytcp/stack/packet_handler/packet_handler__ip6__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
from typing import TYPE_CHECKING

from net_addr import Ip6Address, MacAddress
from pytcp import config
from pytcp.lib.logger import log
from pytcp.lib.tx_status import TxStatus
from pytcp.protocols.defaults import IP6__DEFAULT_HOP_LIMIT
from pytcp.protocols.icmp6.icmp6__base import Icmp6
from pytcp.protocols.icmp6.message.mld2.icmp6_mld2_message__report import (
Icmp6Mld2ReportMessage,
Expand Down Expand Up @@ -95,7 +95,7 @@ def _phtx_ip6(
*,
ip6__dst: Ip6Address,
ip6__src: Ip6Address,
ip6__hop: int = config.IP6__DEFAULT_HOP_LIMIT,
ip6__hop: int = IP6__DEFAULT_HOP_LIMIT,
ip6__payload: Ip6Payload = RawAssembler(),
) -> TxStatus:
"""
Expand Down
4 changes: 2 additions & 2 deletions pytcp/stack/packet_handler/packet_handler__ip6_frag__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from abc import ABC
from typing import TYPE_CHECKING

from pytcp import config
from pytcp.lib.logger import log
from pytcp.lib.tx_status import TxStatus
from pytcp.protocols.icmp6.icmp6__assembler import Icmp6Assembler
Expand All @@ -57,6 +56,7 @@ class PacketHandlerIp6FragTx(ABC):
if TYPE_CHECKING:
from net_addr import Ip6Address
from pytcp.lib.packet_stats import PacketStatsTx
from pytcp.protocols.defaults import IP6__DEFAULT_HOP_LIMIT
from pytcp.protocols.ip6.ip6__assembler import Ip6Assembler, Ip6Payload
from pytcp.protocols.raw.raw__assembler import RawAssembler

Expand All @@ -71,7 +71,7 @@ def _phtx_ip6(
*,
ip6__dst: Ip6Address,
ip6__src: Ip6Address,
ip6__hop: int = config.IP6__DEFAULT_HOP_LIMIT,
ip6__hop: int = IP6__DEFAULT_HOP_LIMIT,
ip6__payload: Ip6Payload = RawAssembler(),
) -> TxStatus: ...

Expand Down
5 changes: 4 additions & 1 deletion pytcp/stack/packet_handler/packet_handler__tcp__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class PacketHandlerTcpTx(ABC):

if TYPE_CHECKING:
from net_addr import IpAddress
from pytcp.config import IP4__DEFAULT_TTL, IP6__DEFAULT_HOP_LIMIT
from pytcp.lib.packet_stats import PacketStatsTx
from pytcp.protocols.defaults import (
IP4__DEFAULT_TTL,
IP6__DEFAULT_HOP_LIMIT,
)
from pytcp.protocols.icmp4.icmp4__assembler import Icmp4Assembler
from pytcp.protocols.icmp6.icmp6__assembler import Icmp6Assembler
from pytcp.protocols.ip4.ip4__assembler import Ip4Payload
Expand Down
5 changes: 4 additions & 1 deletion pytcp/stack/packet_handler/packet_handler__udp__tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ class PacketHandlerUdpTx(ABC):

if TYPE_CHECKING:
from net_addr import IpAddress
from pytcp.config import IP4__DEFAULT_TTL, IP6__DEFAULT_HOP_LIMIT
from pytcp.lib.packet_stats import PacketStatsTx
from pytcp.protocols.defaults import (
IP4__DEFAULT_TTL,
IP6__DEFAULT_HOP_LIMIT,
)
from pytcp.protocols.icmp4.icmp4__assembler import Icmp4Assembler
from pytcp.protocols.icmp6.icmp6__assembler import Icmp6Assembler
from pytcp.protocols.ip4.ip4__assembler import Ip4Payload
Expand Down

0 comments on commit d9cdd39

Please sign in to comment.