This commit is contained in:
Dave Hrycyszyn
2022-12-05 16:41:55 +00:00
parent 60884849d4
commit c3a66c32ca
3 changed files with 14 additions and 13 deletions
+10 -9
View File
@@ -1,16 +1,17 @@
use std::path::PathBuf;
use nym_sdk::mixnet;
#[tokio::main]
async fn main() {
// specify some config options
let config = mixnet::Config {
option: value,
option2: value2,
keyfiles: "~/.flappapapappa/keys/",
};
let keys = Some(PathBuf::from("~/.nym/clients/superfoomp"));
let config = mixnet::Config { keys };
let client = mixnet::Client::new(&config); // passing a config allows the user to set values
let client = mixnet::Client::new(Some(config)); // passing a config allows the user to set values
let show_receive = move || println!("got a message from the mixnet: {}", message); // might need to bury this in a struct as a `FnOnce`, see https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rust
client.on_receive(show_receive); // have some way to pipe any received info to a function for processing
// let show_receive = move || println!("got a message from the mixnet: {}", message); // might need to bury this in a struct as a `FnOnce`, see https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rust
// client.on_receive(show_receive); // have some way to pipe any received info to a function for processing
// connect to the mixnet, now we're listening for incoming
client.connect_to_mixnet();
@@ -19,5 +20,5 @@ async fn main() {
println!("Our client address is {}", client.nym_address);
// send important info up the pipe to a buddy
client.send("foo.bar@blah", "flappappa");
client.send_str("foo.bar@blah", "flappappa");
}
+3 -3
View File
@@ -5,9 +5,7 @@ async fn main() {
// here's what I'd actually like to write
let client = mixnet::Client::new(None); // passing no config makes the client fire up an ephemeral session and figure shit out on its own
let show_receive = move || println!("got a message from the mixnet: {}", message); // might need to bury this in a struct as a `FnMut`, see https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rust
client.on_receive(show_receive); // have some way to pipe any received info to a function for processing
// let show_receive = move || println!("got a message from the mixnet: {}", message); // might need to bury this in a struct as a `FnMut`, see https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rust
// connect to the mixnet, now we're listening for incoming
client.connect_to_mixnet();
@@ -19,4 +17,6 @@ async fn main() {
// send some bytes to a buddy
client.send_bytes("foo.bar@blah", "flappappa".as_bytes().to_vec());
}
+1 -1
View File
@@ -58,5 +58,5 @@ impl Client {
}
pub struct Config {
keys: Option<PathBuf>,
pub keys: Option<PathBuf>,
}