forked from andyleap/go-ssb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.go
45 lines (39 loc) · 947 Bytes
/
dns.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
package dns
import (
"encoding/json"
"github.com/boltdb/bolt"
"github.com/andyleap/go-ssb"
)
type Record struct {
Name string `json:"name"`
Class string `json:"class"`
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
type DNS struct {
ssb.MessageBody
Record Record `json:"record"`
Branch []ssb.Ref `json:"branch"`
}
func init() {
ssb.MessageTypes["ssb-dns"] = func() interface{} { return &DNS{} }
ssb.RebuildClearHooks["dns"] = func(tx *bolt.Tx) error {
tx.DeleteBucket([]byte("dns"))
}
ssb.AddMessageHooks["dns"] = func(m *ssb.SignedMessage, tx *bolt.Tx) error {
_, mb := m.DecodeMessage()
if mbr, ok := mb.(*DNS); ok {
PubBucket, err := tx.CreateBucketIfNotExists([]byte("dns"))
if err != nil {
return err
}
buf, _ := json.Marshal(mbr)
err = PubBucket.Put([]byte(m.Key()), buf)
if err != nil {
return err
}
return nil
}
return nil
}
}