Skip to content

Commit

Permalink
refactor(p2p): rename library communication -> p2p
Browse files Browse the repository at this point in the history
Rename:
- Package `stronghold-communication` -> `stronghold-p2p`
- Interface `ShCommunication` -> `StrongholdP2p`
- Actor `CommunicationActor` -> `NetworkActor`
- `CommunicationProtocol` -> `MessageProtocol`
  • Loading branch information
elenaf9 committed Jul 27, 2021
1 parent 442f846 commit dc18c19
Show file tree
Hide file tree
Showing 35 changed files with 208 additions and 211 deletions.
9 changes: 8 additions & 1 deletion .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
"stronghold-utils"
]
},
"stronghold-p2p": {
"path": "./p2p/",
"manager": "rust",
"dependencies": [
"stronghold-utils"
]
},
"stronghold-communication": {
"path": "./communication/",
"manager": "rust",
Expand All @@ -106,7 +113,7 @@
"manager": "rust",
"dependencies": [
"stronghold-engine",
"stronghold-communication",
"stronghold-p2p",
"stronghold-utils",
"stronghold-runtime"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ updates:
open-pull-requests-limit: 3

- package-ecosystem: "cargo"
directory: "/communication"
directory: "/p2p"
schedule:
interval: "daily"
open-pull-requests-limit: 3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
project: [engine, client, products/commandline, derive, utils, communication-refactored]
project: [engine, client, products/commandline, derive, utils, p2p]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
project: [engine, client, products/commandline, derive, utils, communication-refactored]
project: [engine, client, products/commandline, derive, utils, p2p]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
project: [engine, client, products/commandline, derive, utils, communication-refactored]
project: [engine, client, products/commandline, derive, utils, p2p]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [
"engine",
"engine/runtime",
"client",
"communication-refactored",
"p2p",
"utils",
"derive"
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
There are four main components of Stronghold:
1. **Client**: The high-level interface to Stronghold (prefers Riker, functional integration also available)
2. **Engine**: Combines a persistence store (Snapshot) with an in-memory state interface (Vault), a read/write key:value system (Store) and memory protection services (Runtime).
3. **Communication**: Enables Strongholds in different processes or on different devices to communicate with each other securely.
3. **P2P**: Enables Strongholds in different processes or on different devices to communicate with each other securely.

## 3rd Party Independent Security Audit
In April of 2021, F-Secure performed a security assessment of the core crates of IOTA Stronghold and found nothing of concern. This is not an explicit declaration of fitness or freedom of error, but it is an indicator of the high quality of the code. You may review [the audit here](https://github.com/iotaledger/stronghold.rs/blob/dev/docs/meta/Audit.pdf).
Expand Down
6 changes: 0 additions & 6 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,11 @@ features = [
"chacha"
]

[dependencies.stronghold-communication]
path = "../communication"
optional = true
version = "0.4.1"

[dependencies.stronghold-utils]
path = "../utils"
version = "0.3"

[features]
communication = [ "stronghold-communication" ]

[dev-dependencies]
hex = "0.4.2"
Expand Down
2 changes: 2 additions & 0 deletions client/examples/comm/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused)]

/// # Strong Communications Examples
///
/// The communication examples show the networking capabilities of stronghold.
Expand Down
5 changes: 1 addition & 4 deletions client/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

use riker::actors::*;

use futures::{
channel::mpsc::{channel, Receiver, Sender},
future::RemoteHandle,
};
use futures::future::RemoteHandle;

#[cfg(feature = "communication")]
use futures::{executor::block_on, StreamExt};
Expand Down
1 change: 0 additions & 1 deletion communication-refactored/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn derive_guard_debug(input: TokenStream) -> TokenStream {
/// by assigning different `PermissionValue` for each variant. The permission value is the "index" in the enum as
/// exponent for the power of 2, thus from top to bottom 1, 2, 4, 8...
/// Additionally, it implements `Borrow` from the new original enum to the new enum, to satisfy the trait bounds of
/// `ShCommunication`.
/// `StrongholdP2p`.
#[proc_macro_derive(RequestPermissions)]
pub fn permissions(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let derive_input = syn::parse_macro_input!(input as DeriveInput);
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions communication-refactored/Cargo.toml → p2p/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "stronghold-communication-refactored"
name = "stronghold-p2p-refactored"
version = "0.3.0"
authors = [
"IOTA Stiftung",
Expand All @@ -12,7 +12,7 @@ repository = "https://github.com/iotaledger/stronghold.rs"
homepage = "https://stronghold.docs.iota.org"

[lib]
name = "communication_refactored"
name = "p2p"

[dependencies]
actix = { version = "0.12", optional = true }
Expand Down
1 change: 1 addition & 0 deletions p2p/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Stronghold P2p
22 changes: 11 additions & 11 deletions communication-refactored/src/actor.rs → p2p/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

pub mod messages;
use crate::{ListenErr, Multiaddr, OutboundFailure, PeerId, ReceiveRequest, RqRsMessage, ShCommunication};
use crate::{ListenErr, Multiaddr, OutboundFailure, PeerId, ReceiveRequest, RqRsMessage, StrongholdP2p};
use actix::{dev::ToEnvelope, prelude::*};
use futures::{channel::mpsc, FutureExt, TryFutureExt};
use messages::*;
Expand All @@ -11,7 +11,7 @@ use std::{borrow::Borrow, io, marker::PhantomData};
#[macro_use]
macro_rules! impl_handler {
($mty:ty => $rty:ty, |$cid:ident, $mid:ident| $($body:stmt)+ ) => {
impl<ARegistry, C, Rq, Rs, TRq> Handler<$mty> for CommunicationActor<ARegistry, C, Rq, Rs, TRq>
impl<ARegistry, C, Rq, Rs, TRq> Handler<$mty> for NetworkActor<ARegistry, C, Rq, Rs, TRq>
where
ARegistry: ArbiterService + Handler<GetClient<Rq, C>>,
ARegistry::Context: ToEnvelope<ARegistry, GetClient<Rq, C>>,
Expand All @@ -37,19 +37,19 @@ pub struct GetClient<Rq: Message, C: Actor + Handler<Rq>> {
_marker: (PhantomData<C>, PhantomData<Rq>),
}

pub struct CommunicationActor<ARegistry, C, Rq, Rs, TRq = Rq>
pub struct NetworkActor<ARegistry, C, Rq, Rs, TRq = Rq>
where
ARegistry: Actor,
Rq: Message + RqRsMessage + Borrow<TRq>,
Rs: RqRsMessage,
TRq: Clone + Send + 'static,
{
comms: ShCommunication<Rq, Rs, TRq>,
comms: StrongholdP2p<Rq, Rs, TRq>,
inbound_request_rx: Option<mpsc::Receiver<ReceiveRequest<Rq, Rs>>>,
_marker: (PhantomData<ARegistry>, PhantomData<C>),
}

impl<ARegistry, C, Rq, Rs, TRq> CommunicationActor<ARegistry, C, Rq, Rs, TRq>
impl<ARegistry, C, Rq, Rs, TRq> NetworkActor<ARegistry, C, Rq, Rs, TRq>
where
ARegistry: Actor,
Rq: Message + RqRsMessage + Borrow<TRq>,
Expand All @@ -60,7 +60,7 @@ where
pub async fn new() -> Result<Self, io::Error> {
let (firewall_tx, _) = mpsc::channel(0);
let (inbound_request_tx, inbound_request_rx) = mpsc::channel(1);
let comms = ShCommunication::new(firewall_tx, inbound_request_tx, None).await?;
let comms = StrongholdP2p::new(firewall_tx, inbound_request_tx, None).await?;
let actor = Self {
comms,
inbound_request_rx: Some(inbound_request_rx),
Expand All @@ -70,7 +70,7 @@ where
}
}

impl<ARegistry, C, Rq, Rs, TRq> Actor for CommunicationActor<ARegistry, C, Rq, Rs, TRq>
impl<ARegistry, C, Rq, Rs, TRq> Actor for NetworkActor<ARegistry, C, Rq, Rs, TRq>
where
ARegistry: ArbiterService + Handler<GetClient<Rq, C>>,
ARegistry::Context: ToEnvelope<ARegistry, GetClient<Rq, C>>,
Expand All @@ -88,7 +88,7 @@ where
}
}

impl<ARegistry, C, Rq, Rs, TRq> StreamHandler<ReceiveRequest<Rq, Rs>> for CommunicationActor<ARegistry, C, Rq, Rs, TRq>
impl<ARegistry, C, Rq, Rs, TRq> StreamHandler<ReceiveRequest<Rq, Rs>> for NetworkActor<ARegistry, C, Rq, Rs, TRq>
where
ARegistry: ArbiterService + Handler<GetClient<Rq, C>>,
ARegistry::Context: ToEnvelope<ARegistry, GetClient<Rq, C>>,
Expand Down Expand Up @@ -120,15 +120,15 @@ where
}
}

impl<ARegistry, C, Rq, Rs, TRq> From<(ShCommunication<Rq, Rs, TRq>, mpsc::Receiver<ReceiveRequest<Rq, Rs>>)>
for CommunicationActor<ARegistry, C, Rq, Rs, TRq>
impl<ARegistry, C, Rq, Rs, TRq> From<(StrongholdP2p<Rq, Rs, TRq>, mpsc::Receiver<ReceiveRequest<Rq, Rs>>)>
for NetworkActor<ARegistry, C, Rq, Rs, TRq>
where
ARegistry: Actor,
Rq: Message + RqRsMessage + Borrow<TRq>,
Rs: RqRsMessage,
TRq: Clone + Send + 'static,
{
fn from((comms, request_rx): (ShCommunication<Rq, Rs, TRq>, mpsc::Receiver<ReceiveRequest<Rq, Rs>>)) -> Self {
fn from((comms, request_rx): (StrongholdP2p<Rq, Rs, TRq>, mpsc::Receiver<ReceiveRequest<Rq, Rs>>)) -> Self {
Self {
comms,
inbound_request_rx: Some(request_rx),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use futures::{
task::{Context, Poll},
FutureExt, StreamExt, TryFutureExt,
};
pub use handler::CommunicationProtocol;
pub use handler::MessageProtocol;
use handler::{ConnectionHandler, HandlerInEvent, HandlerOutEvent, ProtocolSupport};
#[cfg(feature = "mdns")]
use libp2p::mdns::Mdns;
Expand Down Expand Up @@ -128,8 +128,8 @@ pub enum BehaviourEvent<Rq, Rs> {

/// Configuration of the [`NetBehaviour`].
pub struct NetBehaviourConfig<TRq: Clone> {
/// Supported versions of the `CommunicationProtocol`.
pub supported_protocols: SmallVec<[CommunicationProtocol; 2]>,
/// Supported versions of the `MessageProtocol`.
pub supported_protocols: SmallVec<[MessageProtocol; 2]>,
/// Timeout for inbound and outbound requests.
pub request_timeout: Duration,
/// Keep-alive timeout of idle connections.
Expand All @@ -141,7 +141,7 @@ pub struct NetBehaviourConfig<TRq: Clone> {
impl<TRq: Clone> Default for NetBehaviourConfig<TRq> {
fn default() -> Self {
Self {
supported_protocols: smallvec![CommunicationProtocol::new_version(1, 0, 0)],
supported_protocols: smallvec![MessageProtocol::new_version(1, 0, 0)],
connection_timeout: Duration::from_secs(10),
request_timeout: Duration::from_secs(10),
firewall: FirewallConfiguration::default(),
Expand Down Expand Up @@ -170,7 +170,7 @@ where
relay: Relay,

// List of supported protocol versions.
supported_protocols: SmallVec<[CommunicationProtocol; 2]>,
supported_protocols: SmallVec<[MessageProtocol; 2]>,
// Timeout for inbound and outbound requests.
request_timeout: Duration,
// Keep-alive timeout of idle connections.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<TRq: Clone> FirewallRules<TRq> {
/// This config specifies what inbound and requests from/ to which peer are allowed.
/// If there are neither default rules, nor a peer specific rule for a request from/ to a peer,
/// a [`FirewallRequest::PeerSpecificRule`] will be sent through the firewall-channel that is passed to
/// `ShCommunication`.
/// `StrongholdP2p`.
pub struct FirewallConfiguration<TRq: Clone> {
/// Default rules that are used if there are no peer-specific ones for a peer.
default: FirewallRules<TRq>,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use libp2p::{
SubstreamProtocol,
},
};
pub use protocol::{CommunicationProtocol, RequestProtocol, ResponseProtocol};
pub use protocol::{MessageProtocol, RequestProtocol, ResponseProtocol};
use smallvec::SmallVec;
use std::{
collections::VecDeque,
Expand All @@ -48,7 +48,7 @@ type ProtocolsHandlerEventType<Rq, Rs> = ProtocolsHandlerEvent<

type PendingInboundFuture<Rq, Rs> = BoxFuture<'static, Result<(RequestId, Rq, oneshot::Sender<Rs>), oneshot::Canceled>>;

// The level of support for the [`CommunicationProtocol`] protocol.
// The level of support for the [`MessageProtocol`] protocol.
// This is set according to the currently effective firewall rules for the remote peer.
#[derive(Debug, Clone, PartialEq)]
pub enum ProtocolSupport {
Expand Down Expand Up @@ -156,7 +156,7 @@ where
Rs: RqRsMessage,
{
// Protocol versions that are potentially supported.
supported_protocols: SmallVec<[CommunicationProtocol; 2]>,
supported_protocols: SmallVec<[MessageProtocol; 2]>,
// Protocol support according to the firewall configuration for the remote peer.
protocol_support: ProtocolSupport,
// Timeout for negotiating a handshake on a substream i.g. sending a requests and receiving the response.
Expand Down Expand Up @@ -187,7 +187,7 @@ where
Rs: RqRsMessage,
{
pub fn new(
supported_protocols: SmallVec<[CommunicationProtocol; 2]>,
supported_protocols: SmallVec<[MessageProtocol; 2]>,
protocol_support: ProtocolSupport,
keep_alive_timeout: Duration,
request_timeout: Duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ use smallvec::SmallVec;
use std::{fmt::Debug, io, marker::PhantomData};

/// Protocol Name.
/// A Request-Response messages will only be successful if both peers support the [`CommunicationProtocol`].
/// A Request-Response messages will only be successful if both peers support the [`MessageProtocol`].
#[derive(Debug, Clone)]
pub struct CommunicationProtocol {
pub struct MessageProtocol {
version: String,
}

impl CommunicationProtocol {
impl MessageProtocol {
pub fn new_version(major: u8, minor: u8, patch: u8) -> Self {
let version = format!("/stronghold-communication/{}.{}.{}", major, minor, patch);
CommunicationProtocol { version }
let version = format!("/stronghold-p2p/{}.{}.{}", major, minor, patch);
MessageProtocol { version }
}
}

impl ProtocolName for CommunicationProtocol {
impl ProtocolName for MessageProtocol {
fn protocol_name(&self) -> &[u8] {
self.version.as_bytes()
}
Expand All @@ -57,7 +57,7 @@ where
{
// Supported protocols for inbound requests.
// Rejects all inbound requests if empty.
pub protocols: SmallVec<[CommunicationProtocol; 2]>,
pub protocols: SmallVec<[MessageProtocol; 2]>,
// Channel for forwarding the inbound request.
pub request_tx: oneshot::Sender<(Rq, oneshot::Sender<Rs>)>,
}
Expand All @@ -67,7 +67,7 @@ where
Rq: RqRsMessage,
Rs: RqRsMessage,
{
type Info = CommunicationProtocol;
type Info = MessageProtocol;
type InfoIter = smallvec::IntoIter<[Self::Info; 2]>;

fn protocol_info(&self) -> Self::InfoIter {
Expand Down Expand Up @@ -117,7 +117,7 @@ where
{
// Supported protocols for outbound requests.
// Rejects all outbound requests if empty.
pub protocols: SmallVec<[CommunicationProtocol; 2]>,
pub protocols: SmallVec<[MessageProtocol; 2]>,
// Outbound request.
pub request: Rq,

Expand All @@ -129,7 +129,7 @@ where
Rq: RqRsMessage,
Rs: RqRsMessage,
{
type Info = CommunicationProtocol;
type Info = MessageProtocol;
type InfoIter = smallvec::IntoIter<[Self::Info; 2]>;

fn protocol_info(&self) -> Self::InfoIter {
Expand Down
File renamed without changes.
Loading

0 comments on commit dc18c19

Please sign in to comment.