Minimal integration example
What we are building
Project setup
[dependencies]
derec-library = "0.0.1-alpha.7"
derec-proto = "0.0.1-alpha.7"
tokio = { version = "1", features = ["macros", "rt"] }The store traits (in-memory)
use std::collections::HashMap;
use derec_library::protocol::{
ChannelStoreFuture, DeRecChannelStore, DeRecSecretStore, DeRecShareStore,
DeRecUserSecretStore, MissingPolicy, SecretKind, SecretStoreFuture, SecretValue,
Share, ShareStoreFuture,
};
use derec_library::protocol::types::{Channel, UserSecrets};
use derec_library::types::ChannelId;
#[derive(Default)]
struct ChannelStore { data: HashMap<(u64, u64), Channel> }
impl DeRecChannelStore for ChannelStore {
fn load(&self, sid: u64, cid: ChannelId) -> ChannelStoreFuture<'_, Option<Channel>> {
Box::pin(std::future::ready(Ok(self.data.get(&(sid, cid.0)).cloned())))
}
fn save(&mut self, sid: u64, ch: Channel) -> ChannelStoreFuture<'_, ()> {
self.data.insert((sid, ch.id.0), ch);
Box::pin(std::future::ready(Ok(())))
}
fn remove(&mut self, sid: u64, cid: ChannelId) -> ChannelStoreFuture<'_, bool> {
Box::pin(std::future::ready(Ok(self.data.remove(&(sid, cid.0)).is_some())))
}
fn channels(&self, sid: u64) -> ChannelStoreFuture<'_, Vec<Channel>> {
let out = self.data.iter()
.filter(|((s, _), _)| *s == sid)
.map(|(_, c)| c.clone())
.collect();
Box::pin(std::future::ready(Ok(out)))
}
fn link_channel(&mut self, _: u64, _: ChannelId, _: ChannelId) -> ChannelStoreFuture<'_, ()> {
Box::pin(std::future::ready(Ok(())))
}
fn linked_channels(&self, _: u64, cid: ChannelId) -> ChannelStoreFuture<'_, Vec<ChannelId>> {
Box::pin(std::future::ready(Ok(vec![cid])))
}
}The transport
Wiring a Peer
PeerThe event loop
The full handshake + protect round
What you should see
What this leaves out
Last updated