2020-06-10 08:41:12 +00:00
|
|
|
use structopt::StructOpt;
|
|
|
|
|
2021-07-15 07:13:31 +00:00
|
|
|
use syndicate::actor::*;
|
2021-09-23 19:46:10 +00:00
|
|
|
use syndicate::enclose;
|
2021-07-15 07:13:31 +00:00
|
|
|
use syndicate::relay;
|
|
|
|
use syndicate::sturdy;
|
|
|
|
use syndicate::value::Value;
|
|
|
|
|
|
|
|
use tokio::net::TcpStream;
|
2020-06-10 08:41:12 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, StructOpt)]
|
|
|
|
pub struct Config {
|
|
|
|
#[structopt(short = "a", default_value = "1")]
|
|
|
|
action_count: u32,
|
2020-06-15 20:13:21 +00:00
|
|
|
|
|
|
|
#[structopt(short = "b", default_value = "0")]
|
|
|
|
bytes_padding: usize,
|
2021-07-15 07:13:31 +00:00
|
|
|
|
|
|
|
#[structopt(short = "d", default_value = "b4b303726566b10973796e646963617465b584b210a6480df5306611ddd0d3882b546e197784")]
|
|
|
|
dataspace: String,
|
2020-06-10 08:41:12 +00:00
|
|
|
}
|
2020-05-11 21:31:00 +00:00
|
|
|
|
2020-06-15 14:15:52 +00:00
|
|
|
#[inline]
|
2021-08-11 21:16:01 +00:00
|
|
|
fn says(who: AnyValue, what: AnyValue) -> AnyValue {
|
2020-06-15 14:15:52 +00:00
|
|
|
let mut r = Value::simple_record("Says", 2);
|
|
|
|
r.fields_vec_mut().push(who);
|
|
|
|
r.fields_vec_mut().push(what);
|
|
|
|
r.finish().wrap()
|
|
|
|
}
|
|
|
|
|
2020-05-11 21:31:00 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2021-07-15 07:13:31 +00:00
|
|
|
syndicate::convenient_logging()?;
|
2021-09-28 11:00:48 +00:00
|
|
|
let config = Config::from_args();
|
|
|
|
let sturdyref = sturdy::SturdyRef::from_hex(&config.dataspace)?;
|
|
|
|
let (i, o) = TcpStream::connect("127.0.0.1:8001").await?.into_split();
|
2021-07-24 21:22:01 +00:00
|
|
|
Actor::new().boot(syndicate::name!("producer"), |t| {
|
2021-10-05 19:11:16 +00:00
|
|
|
relay::connect_stream(t, i, o, false, sturdyref, (), move |_state, t, ds| {
|
2021-09-28 11:00:48 +00:00
|
|
|
let padding: AnyValue = Value::ByteString(vec![0; config.bytes_padding]).wrap();
|
|
|
|
let action_count = config.action_count;
|
|
|
|
let account = Account::new(syndicate::name!("account"));
|
|
|
|
t.linked_task(syndicate::name!("sender"), async move {
|
|
|
|
loop {
|
|
|
|
account.ensure_clear_funds().await;
|
|
|
|
let mut events: PendingEventQueue = Vec::new();
|
|
|
|
for _ in 0..action_count {
|
|
|
|
events.push(Box::new(enclose!((ds, padding) move |t| t.with_entity(
|
|
|
|
&ds.underlying, |t, e| e.message(
|
|
|
|
t, says(Value::from("producer").wrap(), padding))))));
|
|
|
|
}
|
|
|
|
external_events(&ds.underlying.mailbox, &account, events)?;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Ok(None)
|
|
|
|
});
|
|
|
|
Ok(())
|
2021-07-24 21:22:01 +00:00
|
|
|
}).await??;
|
2021-07-15 07:13:31 +00:00
|
|
|
Ok(())
|
2020-05-11 21:31:00 +00:00
|
|
|
}
|