forked from keybase/kbfs
/
modes.go
334 lines (257 loc) · 6.55 KB
/
modes.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// Copyright 2018 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libkbfs
import (
"fmt"
"github.com/keybase/client/go/protocol/keybase1"
)
// NewInitModeFromType returns an InitMode object corresponding to the
// given type.
func NewInitModeFromType(t InitModeType) InitMode {
switch t {
case InitDefault:
return modeDefault{}
case InitMinimal:
return modeMinimal{}
case InitSingleOp:
return modeSingleOp{modeDefault{}}
case InitConstrained:
return modeConstrained{modeDefault{}}
default:
panic(fmt.Sprintf("Unknown mode: %s", t))
}
}
// Default mode:
type modeDefault struct {
}
func (md modeDefault) Type() InitModeType {
return InitDefault
}
func (md modeDefault) BlockWorkers() int {
return defaultBlockRetrievalWorkerQueueSize
}
func (md modeDefault) PrefetchWorkers() int {
return defaultPrefetchWorkerQueueSize
}
func (md modeDefault) RekeyWorkers() int {
return 16
}
func (md modeDefault) IsTestMode() bool {
return false
}
func (md modeDefault) DirtyBlockCacheEnabled() bool {
return true
}
func (md modeDefault) BackgroundFlushesEnabled() bool {
return true
}
func (md modeDefault) MetricsEnabled() bool {
return true
}
func (md modeDefault) ConflictResolutionEnabled() bool {
return true
}
func (md modeDefault) BlockManagementEnabled() bool {
return true
}
func (md modeDefault) QuotaReclamationEnabled() bool {
return true
}
func (md modeDefault) NodeCacheEnabled() bool {
return true
}
func (md modeDefault) TLFUpdatesEnabled() bool {
return true
}
func (md modeDefault) KBFSServiceEnabled() bool {
return true
}
func (md modeDefault) JournalEnabled() bool {
return true
}
func (md modeDefault) UnmergedTLFsEnabled() bool {
return true
}
func (md modeDefault) ServiceKeepaliveEnabled() bool {
return true
}
func (md modeDefault) TLFEditHistoryEnabled() bool {
return true
}
func (md modeDefault) ClientType() keybase1.ClientType {
return keybase1.ClientType_KBFS
}
func (md modeDefault) LocalHTTPServerEnabled() bool {
return true
}
// Minimal mode:
type modeMinimal struct {
}
func (mm modeMinimal) Type() InitModeType {
return InitMinimal
}
func (mm modeMinimal) BlockWorkers() int {
// In minimal mode, block re-embedding is not required, so we
// don't fetch the unembedded blocks..
return 0
}
func (mm modeMinimal) PrefetchWorkers() int {
return 0
}
func (mm modeMinimal) RekeyWorkers() int {
return 4
}
func (mm modeMinimal) IsTestMode() bool {
return false
}
func (mm modeMinimal) DirtyBlockCacheEnabled() bool {
// No blocks will be dirtied in minimal mode, so don't bother with
// the dirty block cache.
return false
}
func (mm modeMinimal) BackgroundFlushesEnabled() bool {
// Don't do background flushes when in minimal mode, since there
// shouldn't be any data writes.
return false
}
func (mm modeMinimal) MetricsEnabled() bool {
return false
}
func (mm modeMinimal) ConflictResolutionEnabled() bool {
// No need to run CR if there won't be any data writes on this
// device. (There may still be rekey writes, but we don't allow
// conflicts to happen in that case.)
return false
}
func (mm modeMinimal) BlockManagementEnabled() bool {
// If this device is in minimal mode and won't be doing any data
// writes, no need deal with block-level cleanup operations.
// TODO: in the future it might still be useful to have
// e.g. mobile devices doing QR.
return false
}
func (mm modeMinimal) QuotaReclamationEnabled() bool {
return false
}
func (mm modeMinimal) NodeCacheEnabled() bool {
// If we're in minimal mode, let the node cache remain nil to
// ensure that the user doesn't try any data reads or writes.
return false
}
func (mm modeMinimal) TLFUpdatesEnabled() bool {
return true
}
func (mm modeMinimal) KBFSServiceEnabled() bool {
return false
}
func (mm modeMinimal) JournalEnabled() bool {
return false
}
func (mm modeMinimal) UnmergedTLFsEnabled() bool {
// Writes aren't allowed, so unmerged TLFs on this device
// shouldn't be possible.
return false
}
func (mm modeMinimal) ServiceKeepaliveEnabled() bool {
return false
}
func (mm modeMinimal) TLFEditHistoryEnabled() bool {
return false
}
func (mm modeMinimal) ClientType() keybase1.ClientType {
return keybase1.ClientType_KBFS
}
func (mm modeMinimal) LocalHTTPServerEnabled() bool {
return false
}
// Single op mode:
type modeSingleOp struct {
InitMode
}
func (mso modeSingleOp) Type() InitModeType {
return InitSingleOp
}
func (mso modeSingleOp) RekeyWorkers() int {
// Just block all rekeys and don't bother cleaning up requests
// since the process is short lived anyway.
return 0
}
func (mso modeSingleOp) QuotaReclamationEnabled() bool {
return false
}
func (mso modeSingleOp) TLFUpdatesEnabled() bool {
return false
}
func (mso modeSingleOp) KBFSServiceEnabled() bool {
return false
}
func (mso modeSingleOp) UnmergedTLFsEnabled() bool {
// There's basically no way for a TLF to start off as unmerged
// since single-ops should be using a fresh journal.
return false
}
func (mso modeSingleOp) TLFEditHistoryEnabled() bool {
return false
}
func (mso modeSingleOp) ClientType() keybase1.ClientType {
return keybase1.ClientType_NONE
}
func (mso modeSingleOp) LocalHTTPServerEnabled() bool {
return false
}
// Constrained mode:
type modeConstrained struct {
InitMode
}
func (mc modeConstrained) Type() InitModeType {
return InitConstrained
}
func (mc modeConstrained) BlockWorkers() int {
return 1
}
func (mc modeConstrained) PrefetchWorkers() int {
return 0
}
func (mc modeConstrained) RekeyWorkers() int {
return 4
}
func (mc modeConstrained) BackgroundFlushesEnabled() bool {
// TODO: turn this on once we allow mobile writes.
return false
}
func (mc modeConstrained) ConflictResolutionEnabled() bool {
// TODO: turn this on once we allow mobile writes.
return false
}
func (mc modeConstrained) QuotaReclamationEnabled() bool {
// TODO: turn this on once we allow mobile writes.
return false
}
func (mc modeConstrained) KBFSServiceEnabled() bool {
return false
}
func (mc modeConstrained) JournalEnabled() bool {
// TODO: turn this on once we allow mobile writes.
return false
}
func (mc modeConstrained) UnmergedTLFsEnabled() bool {
// TODO: turn this on once we allow mobile writes.
return false
}
func (mc modeConstrained) ServiceKeepaliveEnabled() bool {
return false
}
func (mc modeConstrained) TLFEditHistoryEnabled() bool {
return false
}
func (mc modeConstrained) LocalHTTPServerEnabled() bool {
return true
}
// Wrapper for tests.
type modeTest struct {
InitMode
}
func (mt modeTest) IsTestMode() bool {
return true
}