import from pijul repo / WIP

This commit is contained in:
2020-12-24 11:25:50 +01:00
commit 6ce29d99fb
22 changed files with 2369 additions and 0 deletions

View File

@@ -0,0 +1 @@
/data

16
examples/test/Cargo.toml Normal file
View File

@@ -0,0 +1,16 @@
[package]
name = "example-test"
version = "0.1.0"
authors = ["Thomas Heck <t@b128.net>"]
edition = "2018"
[dependencies]
crdt-enc = {path="../../crdt-enc"}
crdt-enc-tokio = {path="../../crdt-enc-tokio"}
crdt-enc-sodium = {path="../../crdt-enc-sodium"}
crdt-enc-gpgme = {path="../../crdt-enc-gpgme"}
uuid = {version = "0.8", features = ["serde", "v4"]}
crdts = "4"
tokio = {version = "0.2", features = ["macros"]}
anyhow = "1"
futures = "0.3"

57
examples/test/src/main.rs Normal file
View File

@@ -0,0 +1,57 @@
use anyhow::Result;
use crdt_enc_gpgme::KeyHandler;
use crdt_enc_sodium::EncHandler;
use crdt_enc_tokio::Storage;
use futures::future::FutureExt;
use uuid::Uuid;
const CURRENT_DATA_VERSION: Uuid = Uuid::from_u128(1u128);
#[tokio::main]
async fn main() -> Result<()> {
crdt_enc_sodium::init();
let data_dir = std::fs::canonicalize("./").unwrap().join("data");
let storage = Storage::new(data_dir.join("local"), data_dir.join("remote"))?;
let cryptor = EncHandler::new();
let key_cryptor = KeyHandler::new();
let open_options = crdt_enc::OpenOptions {
storage,
cryptor,
key_cryptor,
create: true,
supported_data_versions: [CURRENT_DATA_VERSION].iter().cloned().collect(),
current_data_version: CURRENT_DATA_VERSION,
};
let (repo, info) = crdt_enc::Core::open(open_options).await?;
// let actor_id = repo.actor_id();
// repo.run(futures::stream::empty()).try_for_each(|state| {
// dbg!(state);
// });
// dbg!(&repo);
repo.read_remote().await?;
// dbg!(&repo);
// repo.compact().await?;
// dbg!(&repo);
let op = repo.with_state(|s: &crdts::MVReg<u64, Uuid>| {
let read_ctx = s.read();
let add_ctx = read_ctx.derive_add_ctx(info.actor());
let op = s.write(read_ctx.val.into_iter().max().unwrap_or(0) + 1, add_ctx);
Ok(op)
})?;
dbg!(&op);
repo.apply_ops(vec![op]).await?;
Ok(())
}