From e1abc4459224456cf6dfe373252b01e1f57edf6b Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:56:19 +0900 Subject: [PATCH] do not declare class variables --- mixnet/connection.py | 8 -------- mixnet/node.py | 5 ----- mixnet/nomssip.py | 14 ++++---------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/mixnet/connection.py b/mixnet/connection.py index 9b6acf6..5fc319d 100644 --- a/mixnet/connection.py +++ b/mixnet/connection.py @@ -12,9 +12,6 @@ class DuplexConnection: This is to mimic duplex communication in a real network (such as TCP or QUIC). """ - inbound: SimplexConnection - outbound: MixSimplexConnection - def __init__(self, inbound: SimplexConnection, outbound: MixSimplexConnection): self.inbound = inbound self.outbound = outbound @@ -31,11 +28,6 @@ class MixSimplexConnection: Wraps a SimplexConnection to add a transmission rate and noise to the connection. """ - queue: NetworkPacketQueue - conn: SimplexConnection - transmission_rate_per_sec: int - noise_msg: bytes - def __init__( self, conn: SimplexConnection, transmission_rate_per_sec: int, noise_msg: bytes ): diff --git a/mixnet/node.py b/mixnet/node.py index 1868b7b..f6b011f 100644 --- a/mixnet/node.py +++ b/mixnet/node.py @@ -24,11 +24,6 @@ class Node: - generates noise """ - config: NodeConfig - global_config: GlobalConfig - nomssip: Nomssip - broadcast_channel: BroadcastChannel - def __init__(self, config: NodeConfig, global_config: GlobalConfig): self.config = config self.global_config = global_config diff --git a/mixnet/nomssip.py b/mixnet/nomssip.py index 71b1a5c..5e76523 100644 --- a/mixnet/nomssip.py +++ b/mixnet/nomssip.py @@ -19,25 +19,19 @@ class Nomssip: peering_degree: int msg_size: int - config: Config - conns: list[DuplexConnection] - # A handler to process inbound messages. - handler: Callable[[bytes], Awaitable[None]] - # A set of packet hashes to prevent gossiping/processing the same packet twice. - packet_cache: set[bytes] - def __init__( self, config: Config, handler: Callable[[bytes], Awaitable[None]], ): self.config = config - self.conns = [] + self.conns: list[DuplexConnection] = [] + # A handler to process inbound messages. self.handler = handler - self.packet_cache = set() + self.packet_cache: set[bytes] = set() # A set just for gathering a reference of tasks to prevent them from being garbage collected. # https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task - self.tasks = set() + self.tasks: set[asyncio.Task] = set() def add_conn(self, inbound: SimplexConnection, outbound: SimplexConnection): if len(self.conns) >= self.config.peering_degree: