Crates.io | stronghold-communication |
lib.rs | stronghold-communication |
version | 0.4.1 |
source | src |
created_at | 2021-04-21 22:18:36.822407 |
updated_at | 2021-04-21 22:18:36.822407 |
description | libp2p-noise based communication system for IOTA Stronghold |
homepage | https://stronghold.docs.iota.org |
repository | https://github.com/iotaledger/stronghold.rs |
max_upload_size | |
id | 387884 |
size | 253,308 |
This library enables strongholds on different devices and in different networks to communicate with each other. The main basis for its functionality is the rust-libp2p library, which is a system of protocols, specifications and libraries that enable the development of peer-to-peer network applications (https://libp2p.io/).
module behaviour.rs:
Stronghold-communication implements the P2PNetworkBehaviour
for sending messages and reacting upon the outcome of the operation.
It combines multiple protocols of Libp2p:
PeerId
and listening addresses when connecting to a new peer.Upon creating a new instance, a transport is created and upgraded, and combined with the P2PNetworkBehaviour into a ExpandedSwarm. This Swarm is returned to the caller and serves as entry-point for all communication to other peers. Additional to the Libp2p methods of the ExpandedSwarm
, it enables sending outbound messages, and manages the known peers. Incoming P2PEvents
can be handled by polling from the swarm, e.g. via the next
method.
module actor.rs:
The Communication Actor
is using the Riker Framwork to implement the actor pattern.
When creating a new Communication Actor
, the actor creates a P2PNetworkBehaviour
and continuously polls for events,
incoming requests are sent to the client actor that has to be provided in the CommunicationConfig
.
All swarm interaction, and configuration of the Communication Actor
is accomplished by sending the appropriate CommunicationRequest
to it, for each CommunicationRequest
a CommunicationResults
is returned to the sender, this also allows using the ask pattern.
The communication actor implements a firewall that checks the permission of each outgoing and incoming requests and drops them if the necessary permission has not been set. The required ToPermissionVariants
trait for messages can be derived with the communication-macros, this allows in case of enum Request types to accept specific variants while rejecting others.