Skip to content

Commit

Permalink
rename gossip to nomssip
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjoon-lee committed Jul 11, 2024
1 parent 78d4ab9 commit 953b2d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions mixnet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class NodeConfig:

private_key: X25519PrivateKey
mix_path_length: int
gossip: GossipConfig
nomssip: NomssipConfig


@dataclass
class GossipConfig:
class NomssipConfig:
# The target number of peers a node should maintain in its p2p network
peering_degree: int

Expand Down
14 changes: 6 additions & 8 deletions mixnet/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from mixnet.config import GlobalConfig, NodeConfig
from mixnet.connection import DuplexConnection, MixSimplexConnection
from mixnet.gossip import GossipChannel
from mixnet.nomssip import Nomssip
from mixnet.packet import Fragment, MessageFlag, MessageReconstructor, PacketBuilder

BroadcastChannel: TypeAlias = asyncio.Queue[bytes]
Expand All @@ -29,7 +29,7 @@ class Node:

config: NodeConfig
global_config: GlobalConfig
mixgossip_channel: GossipChannel
nomssip: Nomssip
reconstructor: MessageReconstructor
broadcast_channel: BroadcastChannel
# The actual packet size is calculated based on the max length of mix path by Sphinx encoding
Expand All @@ -39,7 +39,7 @@ class Node:
def __init__(self, config: NodeConfig, global_config: GlobalConfig):
self.config = config
self.global_config = global_config
self.mixgossip_channel = GossipChannel(config.gossip, self.__process_msg)
self.nomssip = Nomssip(config.nomssip, self.__process_msg)
self.reconstructor = MessageReconstructor()
self.broadcast_channel = asyncio.Queue()

Expand Down Expand Up @@ -102,7 +102,7 @@ def connect(self, peer: Node):
inbound_conn, outbound_conn = asyncio.Queue(), asyncio.Queue()

# Register a duplex connection for its own use
self.mixgossip_channel.add_conn(
self.nomssip.add_conn(
DuplexConnection(
inbound_conn,
MixSimplexConnection(
Expand All @@ -113,7 +113,7 @@ def connect(self, peer: Node):
)
)
# Register the same duplex connection for the peer
peer.mixgossip_channel.add_conn(
peer.nomssip.add_conn(
DuplexConnection(
outbound_conn,
MixSimplexConnection(
Expand All @@ -135,9 +135,7 @@ async def send_message(self, msg: bytes):
self.global_config.membership,
self.config.mix_path_length,
):
await self.mixgossip_channel.gossip(
Node.__build_msg(MsgType.REAL, packet.bytes())
)
await self.nomssip.gossip(Node.__build_msg(MsgType.REAL, packet.bytes()))

@staticmethod
def __build_msg(flag: MsgType, data: bytes) -> bytes:
Expand Down
11 changes: 5 additions & 6 deletions mixnet/gossip.py → mixnet/nomssip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
import hashlib
from typing import Awaitable, Callable

from mixnet.config import GossipConfig
from mixnet.config import NomssipConfig
from mixnet.connection import DuplexConnection


class GossipChannel:
class Nomssip:
"""
A gossip channel that broadcasts messages to all connected peers.
A NomMix gossip channel that broadcasts messages to all connected peers.
Peers are connected via DuplexConnection.
This class simplifies and simulates the libp2p gossipsub.
"""

config: GossipConfig
config: NomssipConfig
conns: list[DuplexConnection]
# A handler to process inbound messages.
handler: Callable[[bytes], Awaitable[bytes | None]]
Expand All @@ -22,7 +21,7 @@ class GossipChannel:

def __init__(
self,
config: GossipConfig,
config: NomssipConfig,
handler: Callable[[bytes], Awaitable[bytes | None]],
):
self.config = config
Expand Down
4 changes: 2 additions & 2 deletions mixnet/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from mixnet.config import (
GlobalConfig,
GossipConfig,
MixMembership,
NodeConfig,
NodeInfo,
NomssipConfig,
)


Expand All @@ -14,7 +14,7 @@ def init_mixnet_config(
) -> tuple[GlobalConfig, list[NodeConfig], dict[bytes, X25519PrivateKey]]:
transmission_rate_per_sec = 3
max_mix_path_length = 3
gossip_config = GossipConfig(peering_degree=6)
gossip_config = NomssipConfig(peering_degree=6)
node_configs = [
NodeConfig(X25519PrivateKey.generate(), max_mix_path_length, gossip_config)
for _ in range(num_nodes)
Expand Down

0 comments on commit 953b2d6

Please sign in to comment.