mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-07 15:43:07 +00:00
add cover
This commit is contained in:
parent
76b3cb0547
commit
610d95a6fa
@ -10,6 +10,8 @@ from p2p import P2p
|
|||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
N_MIXES_IN_PATH = 2
|
N_MIXES_IN_PATH = 2
|
||||||
|
REAL_PAYLOAD = b"BLOCK"
|
||||||
|
COVER_PAYLOAD = b"COVER"
|
||||||
|
|
||||||
def __init__(self, id: int, env: simpy.Environment, p2p: P2p):
|
def __init__(self, id: int, env: simpy.Environment, p2p: P2p):
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -38,7 +40,8 @@ class Node:
|
|||||||
public_keys = [mix.public_key for mix in mixes]
|
public_keys = [mix.public_key for mix in mixes]
|
||||||
# TODO: replace with realistic tx
|
# TODO: replace with realistic tx
|
||||||
incentive_txs = [Node.create_incentive_tx(mix.public_key) for mix in mixes]
|
incentive_txs = [Node.create_incentive_tx(mix.public_key) for mix in mixes]
|
||||||
return SphinxPacket(public_keys, incentive_txs, b"Hello, world!")
|
payload = random.choice([self.REAL_PAYLOAD, self.COVER_PAYLOAD])
|
||||||
|
return SphinxPacket(public_keys, incentive_txs, payload)
|
||||||
|
|
||||||
def receive_message(self, msg: SphinxPacket | bytes):
|
def receive_message(self, msg: SphinxPacket | bytes):
|
||||||
"""
|
"""
|
||||||
@ -53,7 +56,7 @@ class Node:
|
|||||||
msg, incentive_tx = msg.unwrap(self.private_key)
|
msg, incentive_tx = msg.unwrap(self.private_key)
|
||||||
if self.is_my_incentive_tx(incentive_tx):
|
if self.is_my_incentive_tx(incentive_tx):
|
||||||
self.log("Receiving SphinxPacket. It's mine!")
|
self.log("Receiving SphinxPacket. It's mine!")
|
||||||
if msg.is_all_unwrapped():
|
if msg.is_all_unwrapped() and msg.payload == self.REAL_PAYLOAD:
|
||||||
self.env.process(self.p2p.broadcast(msg.payload))
|
self.env.process(self.p2p.broadcast(msg.payload))
|
||||||
else:
|
else:
|
||||||
# TODO: use Poisson delay
|
# TODO: use Poisson delay
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user