@@ -14,11 +14,112 @@ import (
1414 jsonw "github.com/keybase/go-jsonw"
1515)
1616
17+ const (
18+ DBUser = 0x00
19+ DBSig = 0x0f
20+ DBTeamChain = 0x10
21+ DBUserPlusAllKeysV1 = 0x19
22+
23+ DBOfflineRPC = 0xbe
24+ DBChatCollapses = 0xbf
25+ DBMerkleAudit = 0xca
26+ DBUnfurler = 0xcb
27+ DBStellarDisclaimer = 0xcc
28+ DBFTLStorage = 0xcd
29+ DBTeamAuditor = 0xce
30+ DBAttachmentUploader = 0xcf
31+ DBHasRandomPW = 0xd0
32+ DBDiskLRUEntries = 0xda
33+ DBDiskLRUIndex = 0xdb
34+ DBImplicitTeamConflictInfo = 0xdc
35+ DBUidToFullName = 0xdd
36+ DBUidToUsername = 0xde
37+ DBUserPlusKeysVersioned = 0xdf
38+ DBLink = 0xe0
39+ DBLocalTrack = 0xe1
40+ DBPGPKey = 0xe3
41+ DBSigHints = 0xe4
42+ DBProofCheck = 0xe5
43+ DBUserSecretKeys = 0xe6
44+ DBSigChainTailPublic = 0xe7
45+ DBSigChainTailSemiprivate = 0xe8
46+ DBSigChainTailEncrypted = 0xe9
47+ DBChatActive = 0xea
48+ DBUserEKBox = 0xeb
49+ DBTeamEKBox = 0xec
50+ DBChatIndex = 0xed
51+ DBMerkleRoot = 0xf0
52+ DBTrackers = 0xf1
53+ DBGregor = 0xf2
54+ DBTrackers2 = 0xf3
55+ DBTrackers2Reverse = 0xf4
56+ DBNotificationDismiss = 0xf5
57+ DBChatBlockIndex = 0xf6
58+ DBChatBlocks = 0xf7
59+ DBChatOutbox = 0xf8
60+ DBChatInbox = 0xf9
61+ DBIdentify = 0xfa
62+ DBResolveUsernameToUID = 0xfb
63+ DBChatBodyHashIndex = 0xfc
64+ DBMerkleStore = 0xfd
65+ DBChatConvFailures = 0xfe
66+ DBTeamList = 0xff
67+ )
68+
69+ const (
70+ DBLookupUsername = 0x00
71+ DBLookupMerkleRoot = 0x01
72+ )
73+
74+ func DbKeyUID (t ObjType , uid keybase1.UID ) DbKey {
75+ return DbKey {Typ : t , Key : uid .String ()}
76+ }
77+
78+ func DbKeyNotificationDismiss (prefix string , username NormalizedUsername ) DbKey {
79+ return DbKey {
80+ Typ : DBNotificationDismiss ,
81+ Key : fmt .Sprintf ("%s:%s" , prefix , username ),
82+ }
83+ }
84+
85+ // IsPermDbKey returns true for keys ignored by the leveldb cleaner and always
86+ // persisted to disk. Ideally these keys handling some cleanup/size bounding
87+ // themselves.
88+ func IsPermDbKey (typ ObjType ) bool {
89+ switch typ {
90+ case DBDiskLRUEntries ,
91+ DBDiskLRUIndex ,
92+ DBOfflineRPC ,
93+ DBChatCollapses ,
94+ DBHasRandomPW ,
95+ DBStellarDisclaimer :
96+ return true
97+ default :
98+ return false
99+ }
100+ }
101+
102+ type ObjType byte
103+
104+ type DbKey struct {
105+ Typ ObjType
106+ Key string
107+ }
108+
109+ // tablePrefix builds a key prefix for the given table for use in `util.Range`
110+ // or `util.BytesPrefix`
111+ func tablePrefix (table string ) []byte {
112+ return []byte (fmt .Sprintf ("%s:" , table ))
113+ }
114+
17115func (k DbKey ) ToString (table string ) string {
18116 return fmt .Sprintf ("%s:%02x:%s" , table , k .Typ , k .Key )
19117}
20118
21119func (k DbKey ) ToBytes (table string ) []byte {
120+ if IsPermDbKey (k .Typ ) {
121+ table = levelDbTablePerm
122+ }
22123 return []byte (k .ToString (table ))
23124}
24125
@@ -56,6 +157,7 @@ func jsonLocalDbGet(ops LocalDbOps, id DbKey) (*jsonw.Wrapper, error) {
56157 }
57158 return ret , err
58159}
160+
59161func jsonLocalDbGetInto (ops LocalDbOps , obj interface {}, id DbKey ) (found bool , err error ) {
60162 var buf []byte
61163 buf , found , err = ops .Get (id )
@@ -68,6 +170,7 @@ func jsonLocalDbGetInto(ops LocalDbOps, obj interface{}, id DbKey) (found bool,
68170 }
69171 return found , err
70172}
173+
71174func jsonLocalDbPutObj (ops LocalDbOps , id DbKey , aliases []DbKey , obj interface {}) (err error ) {
72175 var bytes []byte
73176 bytes , err = json .Marshal (obj )
@@ -76,6 +179,7 @@ func jsonLocalDbPutObj(ops LocalDbOps, id DbKey, aliases []DbKey, obj interface{
76179 }
77180 return err
78181}
182+
79183func jsonLocalDbLookup (ops LocalDbOps , id DbKey ) (* jsonw.Wrapper , error ) {
80184 bytes , found , err := ops .Lookup (id )
81185 var ret * jsonw.Wrapper
@@ -107,12 +211,13 @@ type JSONLocalDb struct {
107211 engine LocalDb
108212}
109213
110- func NewJSONLocalDb (e LocalDb ) * JSONLocalDb { return & JSONLocalDb {e } }
111- func (j * JSONLocalDb ) Open () error { return j .engine .Open () }
112- func (j * JSONLocalDb ) ForceOpen () error { return j .engine .ForceOpen () }
113- func (j * JSONLocalDb ) Close () error { return j .engine .Close () }
114- func (j * JSONLocalDb ) Nuke () (string , error ) { return j .engine .Nuke () }
115- func (j * JSONLocalDb ) Stats () string { return j .engine .Stats () }
214+ func NewJSONLocalDb (e LocalDb ) * JSONLocalDb { return & JSONLocalDb {e } }
215+ func (j * JSONLocalDb ) Open () error { return j .engine .Open () }
216+ func (j * JSONLocalDb ) ForceOpen () error { return j .engine .ForceOpen () }
217+ func (j * JSONLocalDb ) Close () error { return j .engine .Close () }
218+ func (j * JSONLocalDb ) Nuke () (string , error ) { return j .engine .Nuke () }
219+ func (j * JSONLocalDb ) Clean (force bool ) error { return j .engine .Clean (force ) }
220+ func (j * JSONLocalDb ) Stats () string { return j .engine .Stats () }
116221
117222func (j * JSONLocalDb ) PutRaw (id DbKey , b []byte ) error { return j .engine .Put (id , nil , b ) }
118223func (j * JSONLocalDb ) GetRaw (id DbKey ) ([]byte , bool , error ) { return j .engine .Get (id ) }
@@ -196,71 +301,3 @@ func (j JSONLocalDbTransaction) Commit() error {
196301func (j JSONLocalDbTransaction ) Discard () {
197302 j .tr .Discard ()
198303}
199-
200- const (
201- DBUser = 0x00
202- DBSig = 0x0f
203- DBTeamChain = 0x10
204- DBUserPlusAllKeysV1 = 0x19
205-
206- DBOfflineRPC = 0xbe
207- DBChatCollapses = 0xbf
208- DBMerkleAudit = 0xca
209- DBUnfurler = 0xcb
210- DBStellarDisclaimer = 0xcc
211- DBFTLStorage = 0xcd
212- DBTeamAuditor = 0xce
213- DBAttachmentUploader = 0xcf
214- DBHasRandomPW = 0xd0
215- DBDiskLRUEntries = 0xda
216- DBDiskLRUIndex = 0xdb
217- DBImplicitTeamConflictInfo = 0xdc
218- DBUidToFullName = 0xdd
219- DBUidToUsername = 0xde
220- DBUserPlusKeysVersioned = 0xdf
221- DBLink = 0xe0
222- DBLocalTrack = 0xe1
223- DBPGPKey = 0xe3
224- DBSigHints = 0xe4
225- DBProofCheck = 0xe5
226- DBUserSecretKeys = 0xe6
227- DBSigChainTailPublic = 0xe7
228- DBSigChainTailSemiprivate = 0xe8
229- DBSigChainTailEncrypted = 0xe9
230- DBChatActive = 0xea
231- DBUserEKBox = 0xeb
232- DBTeamEKBox = 0xec
233- DBChatIndex = 0xed
234- DBMerkleRoot = 0xf0
235- DBTrackers = 0xf1
236- DBGregor = 0xf2
237- DBTrackers2 = 0xf3
238- DBTrackers2Reverse = 0xf4
239- DBNotificationDismiss = 0xf5
240- DBChatBlockIndex = 0xf6
241- DBChatBlocks = 0xf7
242- DBChatOutbox = 0xf8
243- DBChatInbox = 0xf9
244- DBIdentify = 0xfa
245- DBResolveUsernameToUID = 0xfb
246- DBChatBodyHashIndex = 0xfc
247- DBMerkleStore = 0xfd
248- DBChatConvFailures = 0xfe
249- DBTeamList = 0xff
250- )
251-
252- const (
253- DBLookupUsername = 0x00
254- DBLookupMerkleRoot = 0x01
255- )
256-
257- func DbKeyUID (t ObjType , uid keybase1.UID ) DbKey {
258- return DbKey {Typ : t , Key : uid .String ()}
259- }
260-
261- func DbKeyNotificationDismiss (prefix string , username NormalizedUsername ) DbKey {
262- return DbKey {
263- Typ : DBNotificationDismiss ,
264- Key : fmt .Sprintf ("%s:%s" , prefix , username ),
265- }
266- }
0 commit comments