-
Notifications
You must be signed in to change notification settings - Fork 2
/
proto_test.go
154 lines (127 loc) · 3.22 KB
/
proto_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package treekeys
import (
//"fmt"
"reflect"
"testing"
//"time"
)
func TestPerformance(t *testing.T) {
// Uncomment for performance test
/*
for _, logNPeers := range []uint{2, 3, 7, 10, 15, 17} {
nPeers := (1 << logNPeers) - 1
peers := make([]*Endpoint, nPeers)
for i := range peers {
peers[i] = NewEndpoint()
}
// Peer 0 initiates to the rest of the peers
beforeSetup := time.Now()
π0, sm := peers[0].SetupGroup(peers[1:])
afterSetup := time.Now()
// Have peer 1 accept the setup message
beforeProcessSetup := time.Now()
π1 := peers[1].ProcessSetupMessage(sm[0])
afterProcessSetup := time.Now()
// Have peer 0 update its key
beforeUpdate := time.Now()
um := π0.UpdateKey()
afterUpdate := time.Now()
// Have peer 1 accept the update message
beforeProcessUpdate := time.Now()
π1.ProcessUpdateMessage(um)
afterProcessUpdate := time.Now()
fmt.Printf("%7d %7d %7d %7d %7d\n",
nPeers,
afterSetup.Sub(beforeSetup)/time.Millisecond,
afterProcessSetup.Sub(beforeProcessSetup)/time.Millisecond,
afterUpdate.Sub(beforeUpdate)/time.Millisecond,
afterProcessUpdate.Sub(beforeProcessUpdate)/time.Millisecond)
}
*/
}
func TestProtoMAC(t *testing.T) {
key := []byte{0, 1, 2, 3}
// TODO Populate some fields
sm := &SetupMessage{}
msm, err := NewMACMessage(key, sm)
if err != nil {
t.Fatalf("Setup MAC", err)
}
smsm, err := msm.ToSetupMessage()
if err != nil {
t.Fatalf("Setup Verify", err)
}
if !reflect.DeepEqual(sm, smsm) {
t.Fatalf("Setup Mismatch [%+v] [%+v]", sm, smsm)
}
// TODO Populate some fields
um := &UpdateMessage{}
mum, err := NewMACMessage(key, um)
if err != nil {
t.Fatalf("Setup MAC", err)
}
umum, err := mum.ToUpdateMessage()
if err != nil {
t.Fatalf("Setup Verify", err)
}
if !reflect.DeepEqual(um, umum) {
t.Fatalf("Setup Mismatch [%+v] [%+v]", um, umum)
}
}
func TestProtoSetup(t *testing.T) {
nPeers := 2
peers := make([]*Endpoint, nPeers)
for i := range peers {
peers[i] = NewEndpoint()
}
// Peer 0 initiates to the rest of the peers
π0, m := peers[0].SetupGroup(peers[1:])
// Verify that when each peer receives its setup message, it computes the
// same tree key that the first peer did
for i := range peers {
if i == 0 {
continue
}
π := peers[i].ProcessSetupMessage(m[i-1])
if π.tk != π0.tk {
t.Fatalf("Tree key mismatch [%d]", i)
}
if π.sk != π0.sk {
t.Fatalf("Stage key mismatch [%d]", i)
}
}
}
func TestProtoUpdate(t *testing.T) {
nPeers := 15
peers := make([]*Endpoint, nPeers)
for i := range peers {
peers[i] = NewEndpoint()
}
// Setup
π := make([]*GroupState, nPeers)
var sm []*MACMessage
π[0], sm = peers[0].SetupGroup(peers[1:])
for i := range peers {
if i == 0 {
continue
}
π[i] = peers[i].ProcessSetupMessage(sm[i-1])
}
// Have each endpoint update its key. At each step, verify that all peers
// arrive at the same results
for i := range peers {
um := π[i].UpdateKey()
for j := range peers {
if j == i {
continue
}
π[j].ProcessUpdateMessage(um)
if π[j].tk != π[i].tk {
t.Fatalf("Tree key mismatch [%d] [%d]", i, j)
}
if π[j].sk != π[i].sk {
t.Fatalf("Stage key mismatch [%d] [%d]", i, j)
}
}
}
}