-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87b332b
commit 2d703ca
Showing
6 changed files
with
81 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List, Tuple | ||
|
||
from pysphinx.payload import Payload | ||
from pysphinx.sphinx import SphinxPacket | ||
|
||
from mixnet.config import MixMembership, NodeInfo | ||
|
||
|
||
class SphinxPacketBuilder: | ||
@staticmethod | ||
def build( | ||
message: bytes, membership: MixMembership, path_len: int | ||
) -> Tuple[SphinxPacket, List[NodeInfo]]: | ||
if path_len <= 0: | ||
raise ValueError("path_len must be greater than 0") | ||
if len(message) > Payload.max_plain_payload_size(): | ||
raise ValueError("message is too long") | ||
|
||
route = membership.generate_route(path_len) | ||
# We don't need the destination (defined in the Loopix Sphinx spec) | ||
# because the last mix will broadcast the fully unwrapped message. | ||
# Later, we will optimize the Sphinx according to our requirements. | ||
dummy_destination = route[-1] | ||
|
||
packet = SphinxPacket.build( | ||
message, | ||
route=[mixnode.sphinx_node() for mixnode in route], | ||
destination=dummy_destination.sphinx_node(), | ||
) | ||
return (packet, route) |
Oops, something went wrong.