-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.go
48 lines (42 loc) · 909 Bytes
/
update.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
package quasar
import (
"github.com/vmihailenco/msgpack"
)
type update struct {
NodeId *pubkey
Filters [][]byte
}
func newUpdate(nodeId *pubkey, filters [][]byte) *update {
return &update{NodeId: nodeId, Filters: filters}
}
func (u *update) valid(c *Config) bool {
if u == nil || c == nil || u.NodeId == nil {
return false
}
// TODO check nodeid length
if uint32(len(u.Filters)) != c.FiltersDepth {
return false
}
for _, f := range u.Filters {
if uint64(len(f)) != (c.FiltersM / 8) {
return false
}
}
return true
}
func (u *update) marshal() []byte {
// TODO better more compact serialization
b, err := msgpack.Marshal(u)
if err != nil {
panic(err)
}
return b
}
func unmarshalUpdate(data []byte) (*update, error) {
var u update
err := msgpack.Unmarshal(data, &u)
if err != nil {
return nil, err // TODO can any valid input update actually error?
}
return &u, nil
}