P2P Network
We instantiate a p2p
network and call start()
. This will begin running a single
p2p network until stop()
is called.
There are 3 session types:
InboundSession
, concerned with incoming connectionsOutboundSession
, concerned with outgoing connectionsSeedSession
is a special session type which connects to seed nodes to populate the hosts pool, then finishes once synced.
Connections are made by either Acceptor
or Connector
for incoming or outgoing
respectively. They have multiple transport types; see src/net/transport/
for the
full list.
Connections are then wrapped in a Channel
abstraction which allows
protocols to be attached. See src/net/protocol/
and run fd protocol
for custom
application specific network protocols. Also see the follow tutorial:
Outbound Session
The outbound session is responsible to ensure the hosts pool is populated, either through currently connected nodes or using the seed session. It performs this algorithm:
- Start slots, and set each slot with
status = ACTIVE
Then each slot performs this algorithm:
- If no addresses matching our filters are in the hosts pool then:
- If there is another slot where
status ≟ DISCOVERY
orstatus ≟ SEED
then letstatus = SLEEP
and wait for a wakeup signal. - If there are channels opened in
p2p
then letstatus = DISCOVERY
else skip this step, and letstatus = SEED
.- If
status ≟ DISCOVERY
and no hosts are found then letstatus = SEED
.
- If
- In either case when
status ≟ DISCOVERY
orstatus = SEED
and we manage to find new hosts, then wakeup the other sleeping slots. - If there are still no hosts found, then let
status = SLEEP
.
- If there is another slot where
The slots are able to communicate to each other through pipes to signal status changes such as wakeup requests.
Sleeping slots are woken up periodically by the session. They can be forcefully woken up
by calling session.wakeup()
.