diff --git a/examples/icmp_echo_client.py b/examples/icmp_echo_client.py index 67a97115..775cb923 100755 --- a/examples/icmp_echo_client.py +++ b/examples/icmp_echo_client.py @@ -96,7 +96,7 @@ def start(self) -> None: click.echo("Starting the ICMP Echo client.") self._run_thread = True - threading.Thread(target=self.__thread__client).start() + threading.Thread(target=self._thread__client).start() time.sleep(0.1) def stop(self) -> None: @@ -108,7 +108,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__client(self) -> None: + def _thread__client(self) -> None: assert self._local_ip_address is not None flow_id = random.randint(0, 65535) diff --git a/examples/lib/service.py b/examples/lib/service.py new file mode 100755 index 00000000..6b4bbb0c --- /dev/null +++ b/examples/lib/service.py @@ -0,0 +1,149 @@ +#!/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 . ## +## ## +## Author's email: ccie18643@gmail.com ## +## Github repository: https://github.com/ccie18643/PyTCP ## +## ## +################################################################################ + + +""" +The 'user space' generic service base class used in examples. + +examples/lib/service.py + +ver 3.0.2 +""" + + +from __future__ import annotations + +import threading +import time +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING + +import click + +from pytcp.lib import socket +from pytcp.lib.net_addr.ip_address import IpAddress + +if TYPE_CHECKING: + from pytcp.lib.socket import Socket + + +class Service(ABC): + """ + Generic service support class. + """ + + _protocol_name: str + + def __init__( + self, *, service_name: str, local_ip_address: IpAddress, local_port: int + ) -> None: + """ + Initialize the Service object. + """ + + self._service_name = service_name + self._local_ip_address = local_ip_address + self._local_port = local_port + self._run_thread = False + + def start(self) -> None: + """ + Start the service thread. + """ + + click.echo( + f"Starting the {self._protocol_name} {self._service_name} service." + ) + self._run_thread = True + threading.Thread(target=self._thread__service).start() + time.sleep(0.1) + + def stop(self) -> None: + """ + Stop the service thread. + """ + + click.echo( + f"Stopinging the {self._protocol_name} {self._service_name} service." + ) + self._run_thread = False + time.sleep(0.1) + + def _get_listening_socket(self) -> Socket | None: + """ + Create and bind the listening socket. + """ + + match self._local_ip_address.version, self._protocol_name: + case 6, "TCP": + listening_socket = socket.socket( + family=socket.AF_INET6, type=socket.SOCK_STREAM + ) + case 4, "TCP": + listening_socket = socket.socket( + family=socket.AF_INET4, type=socket.SOCK_STREAM + ) + case 6, "UDP": + listening_socket = socket.socket( + family=socket.AF_INET6, type=socket.SOCK_DGRAM + ) + case 4, "UDP": + listening_socket = socket.socket( + family=socket.AF_INET4, type=socket.SOCK_DGRAM + ) + + try: + listening_socket.bind( + (str(self._local_ip_address), self._local_port) + ) + click.echo( + f"Service {self._protocol_name} {self._service_name}: Socket created, " + f"bound to {self._local_ip_address}, port {self._local_port}." + ) + + except OSError as error: + click.echo( + f"Service {self._protocol_name} {self._service_name}: bind() call " + f"failed - {error!r}." + ) + return None + + return listening_socket + + @abstractmethod + def _thread__service(self) -> None: + """ + Service thread. + """ + + raise NotImplementedError + + @abstractmethod + def _service(self, *, socket: Socket) -> None: + """ + Service logic handler. + """ + + raise NotImplementedError diff --git a/examples/lib/tcp_service.py b/examples/lib/tcp_service.py index 6903714b..4738e0ad 100755 --- a/examples/lib/tcp_service.py +++ b/examples/lib/tcp_service.py @@ -36,114 +36,52 @@ from __future__ import annotations import threading -import time -from abc import ABC, abstractmethod -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, override import click -from pytcp.lib import socket -from pytcp.lib.net_addr.ip_address import IpAddress +from examples.lib.service import Service if TYPE_CHECKING: from pytcp.lib.socket import Socket -class TcpService(ABC): +class TcpService(Service): """ TCP service support class. """ - def __init__( - self, *, service_name: str, local_ip_address: IpAddress, local_port: int - ) -> None: - """ - Class constructor. - """ - - self._service_name = service_name - self._local_ip_address = local_ip_address - self._local_port = local_port - self._run_thread = False - - def start(self) -> None: - """ - Start the service thread. - """ + _protocol_name = "TCP" - click.echo(f"Starting the TCP {self._service_name} service.") - self._run_thread = True - threading.Thread(target=self.__thread__service).start() - time.sleep(0.1) - - def stop(self) -> None: - """ - Stop the service thread. + @override + def _thread__service(self) -> None: """ - - click.echo(f"Stopinging the TCP {self._service_name} service.") - self._run_thread = False - time.sleep(0.1) - - def __thread__service(self) -> None: + Service thread. """ - Service initialization. - """ - - match self._local_ip_address.version: - case 6: - listening_socket = socket.socket( - family=socket.AF_INET6, type=socket.SOCK_STREAM - ) - case 4: - listening_socket = socket.socket( - family=socket.AF_INET4, type=socket.SOCK_STREAM - ) - - try: - listening_socket.bind( - (str(self._local_ip_address), self._local_port) - ) - click.echo( - f"Service TCP {self._service_name}: Socket created, bound to " - f"{self._local_ip_address}, port {self._local_port}." - ) - - except OSError as error: - click.echo( - f"Service TCP {self._service_name}: bind() call failed - {error!r}." - ) - return - - listening_socket.listen() - click.echo( - f"Service TCP {self._service_name}: Socket set to listening mode." - ) - while True: - connected_socket, _ = listening_socket.accept() + if listening_socket := self._get_listening_socket(): + listening_socket.listen() click.echo( - f"Service TCP {self._service_name}: Inbound connection received from " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"Service {self._protocol_name} {self._service_name}: Socket " + "set to listening mode." ) - threading.Thread( - target=self.__thread__service__connection_handler, - kwargs={"connected_socket": connected_socket}, - ).start() + while True: + connected_socket, _ = listening_socket.accept() + click.echo( + f"Service {self._protocol_name} {self._service_name}: Inbound " + f"connection received from {connected_socket.remote_ip_address}, " + f"port {connected_socket.remote_port}." + ) + threading.Thread( + target=self._thread__service__connection_handler, + kwargs={"connected_socket": connected_socket}, + ).start() - def __thread__service__connection_handler( + def _thread__service__connection_handler( self, *, connected_socket: Socket ) -> None: """ Inbound connection handler. """ - self._service(connected_socket=connected_socket) - - @abstractmethod - def _service(self, *, connected_socket: Socket) -> None: - """ - Service method. - """ - - raise NotImplementedError + self._service(socket=connected_socket) diff --git a/examples/lib/udp_service.py b/examples/lib/udp_service.py index ff7b15f4..e7932f05 100755 --- a/examples/lib/udp_service.py +++ b/examples/lib/udp_service.py @@ -35,95 +35,23 @@ from __future__ import annotations -import threading -import time -from abc import ABC, abstractmethod -from typing import TYPE_CHECKING +from typing import override -import click +from examples.lib.service import Service -from pytcp.lib import socket -from pytcp.lib.net_addr.ip_address import IpAddress -if TYPE_CHECKING: - from pytcp.lib.socket import Socket - - -class UdpService(ABC): +class UdpService(Service): """ UDP service support class. """ - def __init__( - self, *, service_name: str, local_ip_address: IpAddress, local_port: int - ) -> None: - """ - Class constructor. - """ - - self._service_name = service_name - self._local_ip_address = local_ip_address - self._local_port = local_port - self._run_thread = False + _protocol_name = "UDP" - def start(self) -> None: - """ - Start the service thread. - """ - - click.echo(f"Starting the UDP {self._service_name} service.") - self._run_thread = True - threading.Thread(target=self.__thread__service).start() - time.sleep(0.1) - - def stop(self) -> None: - """ - Stop the service thread. - """ - - click.echo(f"Stopinging the UDP {self._service_name} service.") - self._run_thread = False - time.sleep(0.1) - - def __thread__service(self) -> None: + @override + def _thread__service(self) -> None: """ Service initialization. """ - match self._local_ip_address.version: - case 6: - listening_socket = socket.socket( - family=socket.AF_INET6, type=socket.SOCK_DGRAM - ) - case 4: - listening_socket = socket.socket( - family=socket.AF_INET4, type=socket.SOCK_DGRAM - ) - - try: - listening_socket.bind( - (str(self._local_ip_address), self._local_port) - ) - click.echo( - f"Service UDP {self._service_name}: Socket created, bound to " - f"{self._local_ip_address}, port {self._local_port}." - ) - except OSError as error: - click.echo( - f"Service UDP {self._service_name}: bind() call failed - {error!r}." - ) - return - - self._service(listening_socket=listening_socket) - - @abstractmethod - def _service( - self, - *, - listening_socket: Socket, - ) -> None: - """ - Service method. - """ - - raise NotImplementedError + if listening_socket := self._get_listening_socket(): + self._service(socket=listening_socket) diff --git a/examples/tcp_daytime_service.py b/examples/tcp_daytime_service.py index 880a0054..73ab1411 100755 --- a/examples/tcp_daytime_service.py +++ b/examples/tcp_daytime_service.py @@ -88,7 +88,7 @@ def __init__( self._message_delay = message_delay @override - def _service(self, *, connected_socket: Socket) -> None: + def _service(self, *, socket: Socket) -> None: """ Inbound connection handler. """ @@ -98,30 +98,30 @@ def _service(self, *, connected_socket: Socket) -> None: click.echo( "Service TCP Daytime: Sending first message to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT OPEN / SERVICE OPEN***\n") + socket.send(b"***CLIENT OPEN / SERVICE OPEN***\n") while self._run_thread and message_count: message = bytes(str(datetime.now()) + "\n", "utf-8") try: - connected_socket.send(message) + socket.send(message) except OSError as error: click.echo(f"Service TCP Daytime: send() error - {error!r}.") break click.echo( f"Service TCP Daytime: Sent {len(message)} bytes of data " - f"to {connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"to {socket.remote_ip_address}, port {socket.remote_port}." ) time.sleep(self._message_delay) message_count = min(message_count, message_count - 1) - connected_socket.close() + socket.close() click.echo( "Service TCP Daytime: Closed connection to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}.", + f"{socket.remote_ip_address}, port {socket.remote_port}.", ) diff --git a/examples/tcp_discard_service.py b/examples/tcp_discard_service.py index 2c0ec413..97b48e73 100755 --- a/examples/tcp_discard_service.py +++ b/examples/tcp_discard_service.py @@ -76,57 +76,57 @@ def __init__(self, *, local_ip_address: IpAddress, local_port: int): ) @override - def _service(self, *, connected_socket: Socket) -> None: + def _service(self, *, socket: Socket) -> None: """ Inbound connection handler. """ click.echo( "Service TCP Echo: Sending first message to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT OPEN / SERVICE OPEN***\n") + socket.send(b"***CLIENT OPEN / SERVICE OPEN***\n") while self._run_thread: - if not (message := connected_socket.recv()): + if not (message := socket.recv()): click.echo( - f"Service TCP Discard: Connection to {connected_socket.remote_ip_address}, " - f"port {connected_socket.remote_port} has been closed by peer." + f"Service TCP Discard: Connection to {socket.remote_ip_address}, " + f"port {socket.remote_port} has been closed by peer." ) click.echo( "Service TCP Discard: Sending last message to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT CLOSED, SERVICE CLOSING***\n") + socket.send(b"***CLIENT CLOSED, SERVICE CLOSING***\n") click.echo( "Service TCP Discard: Closng connection to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.close() + socket.close() break if message.strip().lower() in {b"quit", b"close", b"bye", b"exit"}: click.echo( "Service TCP Discard: Sending last message to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT OPEN, SERVICE CLOSING***\n") + socket.send(b"***CLIENT OPEN, SERVICE CLOSING***\n") click.echo( "Service TCP Discard: Closng connection to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.close() + socket.close() continue click.echo( f"Service TCP Discard: Received {len(message)} bytes from " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.close() + socket.close() click.echo( - f"Service TCP Discard: Connection from {connected_socket.remote_ip_address}, " - f"port {connected_socket.remote_port} has been closed by peer." + f"Service TCP Discard: Connection from {socket.remote_ip_address}, " + f"port {socket.remote_port} has been closed by peer." ) diff --git a/examples/tcp_echo_client.py b/examples/tcp_echo_client.py index be4be0df..412f9b6d 100755 --- a/examples/tcp_echo_client.py +++ b/examples/tcp_echo_client.py @@ -95,7 +95,7 @@ def start(self) -> None: click.echo("Starting the TCP Echo client.") self._run_thread = True - threading.Thread(target=self.__thread__client).start() + threading.Thread(target=self._thread__client).start() time.sleep(0.1) def stop(self) -> None: @@ -107,7 +107,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__client(self) -> None: + def _thread__client(self) -> None: """ Client thread. """ diff --git a/examples/tcp_echo_service.py b/examples/tcp_echo_service.py index f322de3f..d74eda1c 100755 --- a/examples/tcp_echo_service.py +++ b/examples/tcp_echo_service.py @@ -78,51 +78,51 @@ def __init__(self, *, local_ip_address: IpAddress, local_port: int): ) @override - def _service(self, *, connected_socket: Socket) -> None: + def _service(self, *, socket: Socket) -> None: """ Inbound connection handler. """ click.echo( - f"Service TCP Echo: Sending first message to {connected_socket.remote_ip_address}, " - f"port {connected_socket.remote_port}." + f"Service TCP Echo: Sending first message to {socket.remote_ip_address}, " + f"port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT OPEN / SERVICE OPEN***\n") + socket.send(b"***CLIENT OPEN / SERVICE OPEN***\n") while self._run_thread: - if not (message := connected_socket.recv()): + if not (message := socket.recv()): click.echo( - f"Service TCP Echo: Connection to {connected_socket.remote_ip_address}, " - f"port {connected_socket.remote_port} has been closed by peer." + f"Service TCP Echo: Connection to {socket.remote_ip_address}, " + f"port {socket.remote_port} has been closed by peer." ) click.echo( "Service TCP Echo: Sending last message to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT CLOSED, SERVICE CLOSING***\n") + socket.send(b"***CLIENT CLOSED, SERVICE CLOSING***\n") click.echo( "Service TCP Echo: Closing connection to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.close() + socket.close() break if message.strip().lower() in {b"quit", b"close", b"bye", b"exit"}: click.echo( "Service TCP Echo: Sending last message to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.send(b"***CLIENT OPEN, SERVICE CLOSING***\n") + socket.send(b"***CLIENT OPEN, SERVICE CLOSING***\n") click.echo( "Service TCP Echo: Closing connection to " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) - connected_socket.close() + socket.close() continue click.echo( f"Service TCP Echo: Received {len(message)} bytes from " - f"{connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"{socket.remote_ip_address}, port {socket.remote_port}." ) if b"malpka" in message.strip().lower(): @@ -134,10 +134,10 @@ def _service(self, *, connected_socket: Socket) -> None: elif b"malpi" in message.strip().lower(): message = malpi - if connected_socket.send(message): + if socket.send(message): click.echo( f"Service TCP Echo: Echo'ed {len(message)} bytes back " - f"to {connected_socket.remote_ip_address}, port {connected_socket.remote_port}." + f"to {socket.remote_ip_address}, port {socket.remote_port}." ) diff --git a/examples/udp_daytime_service.py b/examples/udp_daytime_service.py index ca80fce9..d8a5102a 100755 --- a/examples/udp_daytime_service.py +++ b/examples/udp_daytime_service.py @@ -78,15 +78,15 @@ def __init__(self, *, local_ip_address: IpAddress, local_port: int): ) @override - def _service(self, *, listening_socket: Socket) -> None: + def _service(self, *, socket: Socket) -> None: """ Inbound connection handler. """ while self._run_thread: - _, remote_address = listening_socket.recvfrom() + _, remote_address = socket.recvfrom() message = bytes(str(datetime.now()), "utf-8") - listening_socket.sendto(message, remote_address) + socket.sendto(message, remote_address) click.echo( f"Service UDP Daytime: Sent {len(message)} bytes to " f"{remote_address[0]}, port {remote_address[1]}." diff --git a/examples/udp_discard_service.py b/examples/udp_discard_service.py index 81b526be..15918a2d 100755 --- a/examples/udp_discard_service.py +++ b/examples/udp_discard_service.py @@ -77,13 +77,13 @@ def __init__(self, *, local_ip_address: IpAddress, local_port: int): ) @override - def _service(self, *, listening_socket: Socket) -> None: + def _service(self, *, socket: Socket) -> None: """ Inbound connection handler. """ while self._run_thread: - message, remote_address = listening_socket.recvfrom() + message, remote_address = socket.recvfrom() click.echo( f"Service UDP Discard: Received {len(message)} bytes from " f"{remote_address[0]}, port {remote_address[1]}." diff --git a/examples/udp_echo_client.py b/examples/udp_echo_client.py index cc01f570..041d63b1 100755 --- a/examples/udp_echo_client.py +++ b/examples/udp_echo_client.py @@ -95,7 +95,7 @@ def start(self) -> None: click.echo("Starting the UDP Echo client.") self._run_thread = True - threading.Thread(target=self.__thread__client).start() + threading.Thread(target=self._thread__client).start() time.sleep(0.1) def stop(self) -> None: @@ -107,7 +107,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__client(self) -> None: + def _thread__client(self) -> None: match self._local_ip_address.version: case 6: client_socket = socket.socket( diff --git a/examples/udp_echo_service.py b/examples/udp_echo_service.py index 172f509b..e7ac7d51 100755 --- a/examples/udp_echo_service.py +++ b/examples/udp_echo_service.py @@ -78,13 +78,13 @@ def __init__(self, *, local_ip_address: IpAddress, local_port: int): ) @override - def _service(self, *, listening_socket: Socket) -> None: + def _service(self, *, socket: Socket) -> None: """ Inbound connection handler. """ while self._run_thread: - message, remote_address = listening_socket.recvfrom() + message, remote_address = socket.recvfrom() click.echo( f"Service UDP Echo: Received {len(message)} bytes from " @@ -98,7 +98,7 @@ def _service(self, *, listening_socket: Socket) -> None: elif b"malpi" in message.strip().lower(): message = malpi - listening_socket.sendto(message, remote_address) + socket.sendto(message, remote_address) click.echo( f"Service UDP Echo: Echo'ed {len(message)} bytes back to " diff --git a/pytcp/subsystems/arp_cache.py b/pytcp/subsystems/arp_cache.py index 9b574c54..38f19f84 100755 --- a/pytcp/subsystems/arp_cache.py +++ b/pytcp/subsystems/arp_cache.py @@ -83,7 +83,7 @@ def start(self) -> None: self._run_thread = True threading.Thread( - target=self.__thread__arp_cache__maintain_entries + target=self._thread__arp_cache__maintain_entries ).start() time.sleep(0.1) @@ -97,7 +97,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__arp_cache__maintain_entries(self) -> None: + def _thread__arp_cache__maintain_entries(self) -> None: """ Thread responsible for maintaining ARP cache entries. """ diff --git a/pytcp/subsystems/nd_cache.py b/pytcp/subsystems/nd_cache.py index 6b27c7e1..46a8f1a9 100755 --- a/pytcp/subsystems/nd_cache.py +++ b/pytcp/subsystems/nd_cache.py @@ -83,7 +83,7 @@ def start(self) -> None: self._run_thread = True threading.Thread( - target=self.__thread__nd_cache__maintain_entries + target=self._thread__nd_cache__maintain_entries ).start() time.sleep(0.1) @@ -97,7 +97,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__nd_cache__maintain_entries(self) -> None: + def _thread__nd_cache__maintain_entries(self) -> None: """ Method responsible for maintaining ND cache entries. """ diff --git a/pytcp/subsystems/packet_handler.py b/pytcp/subsystems/packet_handler.py index 65d9ef47..dcb8f063 100755 --- a/pytcp/subsystems/packet_handler.py +++ b/pytcp/subsystems/packet_handler.py @@ -209,7 +209,7 @@ def start(self) -> None: __debug__ and log("stack", "Starting packet handler") self._run_thread = True - threading.Thread(target=self.__thread__packet_handler__receive).start() + threading.Thread(target=self._thread__packet_handler__receive).start() time.sleep(0.1) self._acquire_ip4_addresses() @@ -227,7 +227,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__packet_handler__acquire_ip6_addresses(self) -> None: + def _thread__packet_handler__acquire_ip6_addresses(self) -> None: """ Thread to acquire the IPv6 addresses. """ @@ -241,7 +241,7 @@ def __thread__packet_handler__acquire_ip6_addresses(self) -> None: __debug__ and log("stack", "Finished the IPv6 address acquire thread") - def __thread__packet_handler__acquire_ip4_addresses(self) -> None: + def _thread__packet_handler__acquire_ip4_addresses(self) -> None: """ Thread to acquire the IPv4 addresses. """ @@ -258,7 +258,7 @@ def __thread__packet_handler__acquire_ip4_addresses(self) -> None: __debug__ and log("stack", "Finished the IPv4 address acquire thread") - def __thread__packet_handler__receive(self) -> None: + def _thread__packet_handler__receive(self) -> None: """ Thread picks up incoming packets from RX ring and processes them. """ @@ -285,7 +285,7 @@ def _acquire_ip6_addresses(self) -> None: __debug__ and log("stack", "Starting the IPv6 address acquire thread") threading.Thread( - target=self.__thread__packet_handler__acquire_ip6_addresses + target=self._thread__packet_handler__acquire_ip6_addresses ).start() def _acquire_ip4_addresses(self) -> None: @@ -296,7 +296,7 @@ def _acquire_ip4_addresses(self) -> None: __debug__ and log("stack", "Starting the IPv4 address acquire thread") threading.Thread( - target=self.__thread__packet_handler__acquire_ip4_addresses + target=self._thread__packet_handler__acquire_ip4_addresses ).start() def _assign_mac_address(self, *, mac_unicast: MacAddress) -> None: diff --git a/pytcp/subsystems/rx_ring.py b/pytcp/subsystems/rx_ring.py index 208b4192..3acdfe79 100755 --- a/pytcp/subsystems/rx_ring.py +++ b/pytcp/subsystems/rx_ring.py @@ -73,7 +73,7 @@ def start(self, *, fd: int) -> None: self._run_thread = True self._fd = fd - threading.Thread(target=self.__thread__rx_ring__receive).start() + threading.Thread(target=self._thread__rx_ring__receive).start() time.sleep(0.1) def stop(self) -> None: @@ -86,7 +86,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__rx_ring__receive(self) -> None: + def _thread__rx_ring__receive(self) -> None: """ Thread responsible for receiving and enqueuing incoming packets. """ diff --git a/pytcp/subsystems/timer.py b/pytcp/subsystems/timer.py index 97c4ef1a..eb8004f6 100755 --- a/pytcp/subsystems/timer.py +++ b/pytcp/subsystems/timer.py @@ -131,7 +131,7 @@ def start(self) -> None: __debug__ and log("stack", "Starting timer thread") self._run_thread = True - threading.Thread(target=self.__thread__timer__run_tasks).start() + threading.Thread(target=self._thread__timer__run_tasks).start() time.sleep(0.1) def stop(self) -> None: @@ -144,7 +144,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__timer__run_tasks(self) -> None: + def _thread__timer__run_tasks(self) -> None: """ Thread responsible for executing register methods on every timer tick. """ diff --git a/pytcp/subsystems/tx_ring.py b/pytcp/subsystems/tx_ring.py index f010e9dd..8d6afdc0 100755 --- a/pytcp/subsystems/tx_ring.py +++ b/pytcp/subsystems/tx_ring.py @@ -78,7 +78,7 @@ def start(self, *, fd: int, mtu: int) -> None: self._fd = fd self._mtu = mtu self._run_thread = True - threading.Thread(target=self.__thread__tx_ring__transmit).start() + threading.Thread(target=self._thread__tx_ring__transmit).start() time.sleep(0.1) def stop(self) -> None: @@ -91,7 +91,7 @@ def stop(self) -> None: self._run_thread = False time.sleep(0.1) - def __thread__tx_ring__transmit(self) -> None: + def _thread__tx_ring__transmit(self) -> None: """ Dequeue packet from TX Ring and send it out. """