Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Cleanup of conditional dependencies to support a wider range of compilation targets #138

Merged
merged 17 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ js-sys = "0.3.46"
serde = { version = "1.0", features = ["derive"] }
iota-streams = {path = "../../", default-features = false, features = ["tangle", "wasm-client"]}
client-wasm = { git = "https://github.com/iotaledger/iota.rs", rev = "250ed55", default-features = false }
futures = { version = "0.3.8", default-features = false, features = ["executor"]}

# Needed to specify the js/wasm feature for a sub-crate
getrandom = {version = "0.2.2", features = ["js"]}
rand = { version = "0.7", default-features = false, features = ["wasm-bindgen"] }

[dev-dependencies]
wasm-bindgen-test = "0.3.28"
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/author/authorw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use futures::executor::block_on;
use wasm_bindgen::prelude::*;

use crate::{
Expand All @@ -15,7 +16,6 @@ use core::cell::RefCell;
/// Streams imports
use iota_streams::{
app::{
futures::executor::block_on,
identifier::Identifier,
transport::{
tangle::client::Client as ApiClient,
Expand Down
10 changes: 4 additions & 6 deletions bindings/wasm/src/subscriber/subscriberw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use futures::executor::block_on;
use js_sys::Array;
use wasm_bindgen::prelude::*;

Expand All @@ -8,12 +9,9 @@ use crate::{

use core::cell::RefCell;
use iota_streams::{
app::{
futures::executor::block_on,
transport::{
tangle::client::Client as ApiClient,
TransportOptions,
},
app::transport::{
tangle::client::Client as ApiClient,
TransportOptions,
},
app_channels::api::{
psk_from_seed,
Expand Down
7 changes: 3 additions & 4 deletions bindings/wasm/src/user/userw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::cell::RefCell;

use wasm_bindgen::prelude::*;

use crate::types::{
Expand All @@ -18,10 +20,7 @@ use iota_streams::{
TransportDetails,
TransportOptions,
},
core::prelude::{
Rc,
RefCell,
},
core::prelude::Rc,
};

#[wasm_bindgen]
Expand Down
3 changes: 2 additions & 1 deletion examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![allow(dead_code)]
//#![no_std]

use core::cell::RefCell;

use std::env;

use rand::Rng;
Expand All @@ -15,7 +17,6 @@ use iota_streams::{
core::{
prelude::{
Rc,
RefCell,
String,
},
Result,
Expand Down
2 changes: 1 addition & 1 deletion iota-streams-app-channels/src/api/tangle/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<Trans: Transport + Clone> Author<Trans> {

let ann = author.user.user.announce().await?;
let retrieved: Message = author.user.transport.recv_message(announcement).await?;
assert!(retrieved.binary == ann.message);
assert!(retrieved == ann.message);

author.user.commit_wrapped(ann.wrapped, MsgInfo::Announce)?;

Expand Down
2 changes: 1 addition & 1 deletion iota-streams-app-channels/src/api/tangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub use msginfo::MsgInfo;
// However, chances are it is the most frequent variant, therefore a profile must confirm there's
// enough performance improvement to justify the ergonomic drawback of re-enabling this lint
#[allow(clippy::large_enum_variant)]
/// Message body returned as part of handle message routine.
#[derive(Clone, Debug, PartialEq, Eq)]
/// Message body returned as part of handle message routine.
pub enum MessageContent {
Announce,
Keyload,
Expand Down
41 changes: 14 additions & 27 deletions iota-streams-app-channels/src/api/tangle/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<Trans: Transport + Clone> User<Trans> {
wrapped: wrapped_state,
},
) => {
self.transport.send_message(&Message::new(message)).await?;
self.transport.send_message(&message).await?;
self.user.commit_sequence(cursor, wrapped_state, MsgInfo::Sequence)
}
WrappedSequence::SingleBranch(cursor) => {
Expand All @@ -255,7 +255,7 @@ impl<Trans: Transport + Clone> User<Trans> {

/// Send a message without using sequencing logic. Reserved for Announce and Subscribe messages
async fn send_message(&mut self, msg: WrappedMessage, info: MsgInfo) -> Result<Address> {
self.transport.send_message(&Message::new(msg.message)).await?;
self.transport.send_message(&msg.message).await?;
self.commit_wrapped(msg.wrapped, info)
}

Expand All @@ -272,7 +272,7 @@ impl<Trans: Transport + Clone> User<Trans> {
info: MsgInfo,
) -> Result<(Address, Option<Address>)> {
// Send & commit original message
self.transport.send_message(&Message::new(msg.message)).await?;
self.transport.send_message(&msg.message).await?;
let msg_link = self.commit_wrapped(msg.wrapped, info)?;

// Send & commit associated sequence message
Expand Down Expand Up @@ -374,11 +374,7 @@ impl<Trans: Transport + Clone> User<Trans> {
pub async fn receive_sequence(&mut self, link: &Address) -> Result<Address> {
let msg = self.transport.recv_message(link).await?;
if let Some(_addr) = &self.user.appinst {
let seq_msg = self
.user
.handle_sequence(msg.binary, MsgInfo::Sequence, true)
.await?
.body;
let seq_msg = self.user.handle_sequence(msg, MsgInfo::Sequence, true).await?.body;
let msg_id = self.user.link_gen.link_from(
seq_msg.id,
Cursor::new_at(&seq_msg.ref_link, 0, seq_msg.seq_num.0 as u32),
Expand All @@ -396,11 +392,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link` - Address of the message to be processed
pub async fn receive_signed_packet(&mut self, link: &Address) -> Result<(PublicKey, Bytes, Bytes)> {
let msg = self.transport.recv_message(link).await?;
// TODO: msg.timestamp is lost
let m = self
.user
.handle_signed_packet(msg.binary, MsgInfo::SignedPacket)
.await?;
let m = self.user.handle_signed_packet(msg, MsgInfo::SignedPacket).await?;
Ok(m.body)
}

Expand All @@ -410,10 +402,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link` - Address of the message to be processed
pub async fn receive_tagged_packet(&mut self, link: &Address) -> Result<(Bytes, Bytes)> {
let msg = self.transport.recv_message(link).await?;
let m = self
.user
.handle_tagged_packet(msg.binary, MsgInfo::TaggedPacket)
.await?;
let m = self.user.handle_tagged_packet(msg, MsgInfo::TaggedPacket).await?;
Ok(m.body)
}

Expand All @@ -423,8 +412,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link` - Address of the message to be processed
pub async fn receive_subscribe(&mut self, link: &Address) -> Result<()> {
let msg = self.transport.recv_message(link).await?;
// TODO: Timestamp is lost.
self.user.handle_subscribe(msg.binary, MsgInfo::Subscribe).await
self.user.handle_subscribe(msg, MsgInfo::Subscribe).await
}

/// Receive and process an unsubscribe message [Author].
Expand All @@ -433,8 +421,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link` - Address of the message to be processed
pub async fn receive_unsubscribe(&mut self, link: &Address) -> Result<()> {
let msg = self.transport.recv_message(link).await?;
// TODO: Timestamp is lost.
self.user.handle_unsubscribe(msg.binary, MsgInfo::Unsubscribe).await
self.user.handle_unsubscribe(msg, MsgInfo::Unsubscribe).await
}

/// Receive and Process an announcement message [Subscriber].
Expand All @@ -443,7 +430,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link_to` - Address of the Channel Announcement message
pub async fn receive_announcement(&mut self, link: &Address) -> Result<()> {
let msg = self.transport.recv_message(link).await?;
self.user.handle_announcement(msg.binary, MsgInfo::Announce).await
self.user.handle_announcement(msg, MsgInfo::Announce).await
}

/// Receive and process a keyload message [Subscriber].
Expand All @@ -452,7 +439,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link` - Address of the message to be processed
pub async fn receive_keyload(&mut self, link: &Address) -> Result<bool> {
let msg = self.transport.recv_message(link).await?;
let m = self.user.handle_keyload(msg.binary, MsgInfo::Keyload).await?;
let m = self.user.handle_keyload(msg, MsgInfo::Keyload).await?;
Ok(m.body)
}

Expand Down Expand Up @@ -491,7 +478,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// * `link` - Address of message to act as root of previous message fetching
pub async fn fetch_prev_msg(&mut self, link: &Address) -> Result<UnwrappedMessage> {
let msg = self.transport.recv_message(link).await?;
let preparsed: Preparsed = msg.binary.parse_header().await?;
let preparsed: Preparsed = msg.parse_header().await?;
let header = preparsed.header;
let prev_msg_link = Address::try_from_bytes(&header.previous_msg_link.0)
.or_else(|_| err!(NoPreviousMessage(link.to_string())))?;
Expand All @@ -512,7 +499,7 @@ impl<Trans: Transport + Clone> User<Trans> {
for _ in 0..max {
msg_info = unwrap_or_break!(self.parse_msg_info(&msg_info.0).await);
if msg_info.1 == message::SEQUENCE {
let msg_link = self.process_sequence(msg_info.2.binary, false).await?;
let msg_link = self.process_sequence(msg_info.2, false).await?;
msg_info = self.parse_msg_info(&msg_link).await?;
}
to_process.push(msg_info.2);
Expand All @@ -536,7 +523,7 @@ impl<Trans: Transport + Clone> User<Trans> {
let mut sequenced = false;
loop {
// Forget TangleMessage and timestamp
let msg = msg0.binary;
let msg = msg0;
let preparsed: Preparsed = msg.parse_header().await?;
let link = preparsed.header.link;
let prev_link = Address::try_from_bytes(&preparsed.header.previous_msg_link.0)?;
Expand Down Expand Up @@ -581,7 +568,7 @@ impl<Trans: Transport + Clone> User<Trans> {
/// the message itself
async fn parse_msg_info(&mut self, link: &Address) -> Result<(Address, u8, Message)> {
let msg = self.transport.recv_message(link).await?;
let preparsed: Preparsed = msg.binary.parse_header().await?;
let preparsed: Preparsed = msg.parse_header().await?;
let header = preparsed.header;
let link = Address::try_from_bytes(&header.previous_msg_link.0)
.or_else(|_| err!(NoPreviousMessage(link.to_string())))?;
Expand Down
6 changes: 4 additions & 2 deletions iota-streams-app-channels/src/message/unsubscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
//!
//! * `sig` -- message signature generated with the senders private key.

use core::marker::PhantomData;

use iota_streams_app::message::{
self,
HasLink,
Expand All @@ -45,7 +47,7 @@ use iota_streams_ddml::{
pub struct ContentWrap<'a, F, Link: HasLink> {
pub(crate) link: &'a <Link as HasLink>::Rel,
pub(crate) sig_kp: &'a ed25519::Keypair,
pub(crate) _phantom: std::marker::PhantomData<(F, Link)>,
pub(crate) _phantom: PhantomData<(F, Link)>,
}

#[async_trait(?Send)]
Expand Down Expand Up @@ -90,7 +92,7 @@ where
pub struct ContentUnwrap<F, Link: HasLink> {
pub(crate) link: <Link as HasLink>::Rel,
pub(crate) sig_pk: ed25519::PublicKey,
_phantom: std::marker::PhantomData<(F, Link)>,
_phantom: PhantomData<(F, Link)>,
}

#[async_trait(?Send)]
Expand Down
9 changes: 4 additions & 5 deletions iota-streams-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ default = ["std", "client"]
std = ["iota-streams-core/std", "iota-streams-core-edsig/std", "iota-streams-ddml/std", "hex/std"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add rand/std as well, otherwise rand doesnt support it with default-features = false. To be correct :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually, you helped me realize that rand does not need to be a dependency on iota-streams-app. As per rand/std, in iota-streams-core it is already done as you suggest: https://github.com/iotaledger/streams/pull/138/files#diff-3350ed2612e4263878a1a2e5ba8025625b76c0ec06cc80b7211f586991da47f3R14

# rust doesn't support async traits, `async-trait` crate emulates `async` keyword
# `async` implies `std` for now
tangle = ["num_cpus", "futures"]
client = ["iota-client/default", "tangle", "std"]
tangle = []
client = ["iota-client/default", "futures", "tangle", "std"]
# `iota-client` support is implemented as a feature (as opposed to a separate crate) in order to
# implement Transport for iota_client::Client.
wasm-client = ["iota-client/wasm", "tangle", "std"]
wasm-client = ["iota-client/wasm", "futures", "tangle", "std"]
sync-parking-lot = ["iota-streams-core/sync-parking-lot"]
sync-spin = ["iota-streams-core/sync-spin"]

Expand All @@ -28,11 +28,10 @@ iota-streams-core-edsig = { version = "0.1.2", path = "../iota-streams-core-edsi
iota-streams-ddml = { version = "0.1.2", path = "../iota-streams-ddml", default-features = false }

hex = { version = "0.4", default-features = false, optional = false }
futures = { version = "0.3.8", default-features = false, features = ["executor"], optional = true }

# Dependencies for "client" feature
iota-client = { version = "1.1.1", default-features = false, optional = true }
num_cpus = { version = "1.10", optional = true }
futures = { version = "0.3.8", default-features = false, features = ["executor"], optional = true }

cstr_core = { version = "0.2.2", default-features = false, features = ["alloc"] }
cty = { version = "0.2.1" }
Expand Down
2 changes: 0 additions & 2 deletions iota-streams-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ pub mod transport;

pub use cstr_core;
pub use cty;
#[cfg(feature = "tangle")]
pub use futures;
// pub trait TrustProvider<PublicKey> {
// fn check_trusted(pk: &PublicKey) -> Result<()>;
// }
2 changes: 1 addition & 1 deletion iota-streams-app/src/message/hdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ where
impl<F, Link, Store> ContentUnwrap<F, Store> for HDF<Link>
where
F: PRP,
Link: AbsorbExternalFallback<F> + std::fmt::Debug + Clone,
Link: AbsorbExternalFallback<F> + fmt::Debug + Clone,
{
async fn unwrap<'c, IS: io::IStream>(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion iota-streams-app/src/transport/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use iota_streams_core::{
Errors::MessageNotUnique,
};

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct BucketTransport<Link, Msg> {
bucket: HashMap<Link, Vec<Msg>>,
}
Expand Down
21 changes: 10 additions & 11 deletions iota-streams-app/src/transport/tangle/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use core::fmt;

use futures::{
executor::block_on,
future::join_all,
};

use iota_streams_core::{
async_trait,
prelude::Box,
Expand Down Expand Up @@ -27,10 +33,6 @@ use iota_streams_core::{
};

use crate::{
futures::{
executor::block_on,
future::join_all,
},
message::BinaryMessage,
transport::{
tangle::*,
Expand Down Expand Up @@ -84,10 +86,7 @@ pub fn msg_from_tangle_message(message: &Message, link: &TangleAddress) -> Resul
}

let binary = BinaryMessage::new(*link, TangleAddress::default(), bytes.into());
// TODO get timestamp
let timestamp: u64 = 0;

Ok(TangleMessage { binary, timestamp })
Ok(binary)
} else {
err!(BadMessagePayload)
}
Expand All @@ -113,13 +112,13 @@ async fn get_messages(client: &iota_client::Client, link: &TangleAddress) -> Res

/// Send a message to the Tangle using a node client
pub async fn async_send_message_with_options(client: &iota_client::Client, msg: &TangleMessage) -> Result<()> {
let hash = msg.binary.link.to_msg_index();
let hash = msg.link.to_msg_index();

// TODO: Get rid of copy caused by to_owned
client
.message()
.with_index(hash)
.with_data(msg.binary.body.to_bytes())
.with_data(msg.body.to_bytes())
.finish()
.await?;
Ok(())
Expand Down Expand Up @@ -237,7 +236,7 @@ impl TransportOptions for Client {

#[async_trait(?Send)]
impl Transport<TangleAddress, TangleMessage> for Client {
/// Send a Streams message over the Tangle with the current timestamp and default SendOptions.
/// Send a Streams message over the Tangle with default SendOptions.
async fn send_message(&mut self, msg: &TangleMessage) -> Result<()> {
async_send_message_with_options(&self.client, msg).await
}
Expand Down
Loading