do not declare class variables

This commit is contained in:
Youngjoon Lee 2024-07-11 16:56:19 +09:00
parent ad669abc6b
commit e1abc44592
No known key found for this signature in database
GPG Key ID: B4253AFBA618BF4D
3 changed files with 4 additions and 23 deletions

View File

@ -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
):

View File

@ -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

View File

@ -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: