/
schema.go
39 lines (30 loc) · 831 Bytes
/
schema.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
package db
import (
"encoding/binary"
)
var (
// localKey register immutable local node ID
localKey = []byte("LocalID")
// "F-"
friendPrefix = []byte("F-")
// "M-"
// p2pMessageLookupPrefix = []byte("M-")
// "S-"
p2pSessionPrefix = []byte("S-")
)
// append encoded uint64 in big endian
func appendUint64(prefix []byte, number uint64) []byte {
return binary.BigEndian.AppendUint64(prefix, number)
}
// "F-" + [32]byte -> friend stock
func friendKey(nodeID [32]byte) []byte {
return append(friendPrefix, nodeID[:]...)
}
// "M-" + [32]byte hash -> session ID
// func p2pMessageLookupKey(messageID uint64) []byte {
// return appendUint64(p2pMessageLookupPrefix, messageID)
// }
// "S-" + [32]byte -> session stock
func p2pSessionKey(sessionID [32]byte) []byte {
return append(p2pSessionPrefix, sessionID[:]...)
}