2022-02-11 06:56:19 +00:00
|
|
|
from typing import TYPE_CHECKING, Set
|
|
|
|
from gossip.peer import Peer
|
2022-02-10 01:29:16 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
import queue
|
|
|
|
from onionrblocks import Block
|
|
|
|
|
|
|
|
from onionrthreads import add_onionr_thread
|
2022-02-11 06:56:19 +00:00
|
|
|
import onionrplugins
|
|
|
|
|
|
|
|
from .client import gossip_client
|
|
|
|
from .server import gossip_server
|
2022-02-10 01:29:16 +00:00
|
|
|
"""
|
|
|
|
Onionr uses a flavor of Dandelion++ epidemic routing
|
|
|
|
|
|
|
|
The starter creates a peer set and passes it to the client and server
|
|
|
|
as well as each of the plugins.
|
|
|
|
|
|
|
|
The transports forward incoming requests to the gossip server
|
|
|
|
|
|
|
|
When a new peer announcement is recieved an event is fired and the transport plugin that handles it will (or wont)
|
|
|
|
create a new peer object by connecting to that peer
|
|
|
|
|
|
|
|
When a new block is generated, it is added to a queue in raw form passed to the starter
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2022-02-11 06:56:19 +00:00
|
|
|
def start_gossip_threads(peer_set: Set[Peer], block_queue: queue.Queue[Block]):
|
2022-02-10 01:29:16 +00:00
|
|
|
# Peer set is largely handled by the transport plugins
|
|
|
|
# There is a unified set so gossip logic is not repeated
|
2022-02-11 06:56:19 +00:00
|
|
|
|
|
|
|
add_onionr_thread(gossip_server, 1, peer_set, block_queue, initial_sleep=0.2)
|
|
|
|
add_onionr_thread(gossip_client, 1, peer_set, block_queue, initial_sleep=0)
|
|
|
|
onionrplugins.events.event('gossip_start', data=peer_set, threaded=True)
|
2022-02-10 01:29:16 +00:00
|
|
|
|
|
|
|
|