1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2023 Yuki Kishimoto
// Distributed under the MIT software license

use negentropy::{Bytes, Negentropy, NegentropyStorageVector};

fn main() {
    // Client
    let mut storage_client = NegentropyStorageVector::new();
    storage_client
        .insert(
            0,
            Bytes::from_hex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .unwrap(),
        )
        .unwrap();
    storage_client
        .insert(
            1,
            Bytes::from_hex("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
                .unwrap(),
        )
        .unwrap();
    storage_client.seal().unwrap();
    let mut client = Negentropy::new(storage_client, 0).unwrap();
    let init_output = client.initiate().unwrap();
    println!("Initiator Output: {}", init_output.as_hex());

    // Relay
    let mut storage_relay = NegentropyStorageVector::new();
    storage_relay
        .insert(
            0,
            Bytes::from_hex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .unwrap(),
        )
        .unwrap();
    storage_relay
        .insert(
            2,
            Bytes::from_hex("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")
                .unwrap(),
        )
        .unwrap();
    storage_relay
        .insert(
            3,
            Bytes::from_hex("1111111111111111111111111111111111111111111111111111111111111111")
                .unwrap(),
        )
        .unwrap();
    storage_relay
        .insert(
            5,
            Bytes::from_hex("2222222222222222222222222222222222222222222222222222222222222222")
                .unwrap(),
        )
        .unwrap();
    storage_relay
        .insert(
            10,
            Bytes::from_hex("3333333333333333333333333333333333333333333333333333333333333333")
                .unwrap(),
        )
        .unwrap();
    storage_relay.seal().unwrap();
    let mut relay = Negentropy::new(storage_relay, 0).unwrap();
    let reconcile_output = relay.reconcile(&init_output).unwrap();
    println!("Reconcile Output: {}", reconcile_output.as_hex());

    // Client
    let mut have_ids = Vec::new();
    let mut need_ids = Vec::new();
    client
        .reconcile_with_ids(&reconcile_output, &mut have_ids, &mut need_ids)
        .unwrap();
    println!(
        "Have IDs: {}",
        have_ids
            .into_iter()
            .map(|b| b.to_hex())
            .collect::<Vec<_>>()
            .join("")
    );
    println!(
        "Need IDs: {}",
        need_ids
            .into_iter()
            .map(|b| b.to_hex())
            .collect::<Vec<_>>()
            .join("")
    );
}