-
Notifications
You must be signed in to change notification settings - Fork 1
/
reconcile_test.go
83 lines (70 loc) · 2.16 KB
/
reconcile_test.go
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
package reconcile
import (
"fmt"
"log"
"math/rand"
"testing"
)
//Functional Steps:
//Both parties start the transaction by informing each other of their set sizes.
//Then Generate strata signatures and exchange in JSON.
//Use this to estimate the size of the difference
//Build IBF of this size and exchange signatures in JSON
//Calculate the difference
//Creates two set of keys
func NewTestSets(keysize, match, uniquea, uniqueb int) (a [][]byte, b [][]byte) {
a = make([][]byte, match+uniquea)
b = make([][]byte, match+uniqueb)
for i := 0; i < match; i++ {
element := make([]byte, keysize)
_, err := rand.Read(element)
if err != nil {
log.Panicln("Could not get random bytes for set element")
}
a[i] = element
b[i] = element
}
for i := match; i < match+uniquea; i++ {
element := make([]byte, keysize)
_, err := rand.Read(element)
if err != nil {
log.Panicln("Could not get random bytes for set element")
}
a[i] = element
}
for i := match; i < match+uniqueb; i++ {
element := make([]byte, keysize)
_, err := rand.Read(element)
if err != nil {
log.Panicln("Could not get random bytes for set element")
}
b[i] = element
}
return
}
func TestReconcile(t *testing.T) {
keysize := 32
matchingcount := 50
uniquea := 40
uniqueb := 20
localset, remoteset := NewTestSets(keysize, matchingcount, uniquea, uniqueb)
local := NewReconcile(localset, len(remoteset))
remote := NewReconcile(remoteset, len(localset))
//Exchange JSON strata signatures
locdiffestimator, _ := local.GetDifferenceSizeEstimator()
remdiffestimator, _ := remote.GetDifferenceSizeEstimator()
locdiffsize, _ := local.EstimateDifferenceSize(locdiffestimator)
remdiffsize, _ := remote.EstimateDifferenceSize(remdiffestimator)
if locdiffsize != remdiffsize {
t.Error("Difference size error")
}
//Exchange IBF signatures and get difference
localsignature, _ := local.GetIBFSignature(locdiffsize)
remotesignature, _ := remote.GetIBFSignature(remdiffsize)
loca, locb, _ := local.GetDifference(locdiffsize, remotesignature)
rema, remb, _ := remote.GetDifference(remdiffsize, localsignature)
fmt.Println(loca)
fmt.Println(locb)
fmt.Println(rema)
fmt.Println(remb)
}