forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_local.go
1788 lines (1575 loc) · 48.9 KB
/
config_local.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 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 (
"flag"
"os"
"path/filepath"
"strings"
"sync"
"time"
"github.com/keybase/client/go/kbfs/cache"
"github.com/keybase/client/go/kbfs/data"
"github.com/keybase/client/go/kbfs/idutil"
"github.com/keybase/client/go/kbfs/ioutil"
"github.com/keybase/client/go/kbfs/kbfscodec"
"github.com/keybase/client/go/kbfs/kbfscrypto"
"github.com/keybase/client/go/kbfs/kbfsedits"
"github.com/keybase/client/go/kbfs/kbfsmd"
"github.com/keybase/client/go/kbfs/ldbutils"
"github.com/keybase/client/go/kbfs/libkey"
"github.com/keybase/client/go/kbfs/tlf"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/logger"
"github.com/keybase/client/go/protocol/keybase1"
"github.com/pkg/errors"
metrics "github.com/rcrowley/go-metrics"
"github.com/shirou/gopsutil/mem"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/storage"
"golang.org/x/net/context"
"golang.org/x/net/trace"
)
const (
// Default time after setting the rekey bit before prompting for a
// paper key.
rekeyWithPromptWaitTimeDefault = 10 * time.Minute
// see Config doc for the purpose of DelayedCancellationGracePeriod
delayedCancellationGracePeriodDefault = 2 * time.Second
// tlfValidDurationDefault is the default for tlf validity before redoing identify.
tlfValidDurationDefault = 6 * time.Hour
// bgFlushDirOpThresholdDefault is the default for how many
// directory operations should be batched together in a single
// background flush.
bgFlushDirOpBatchSizeDefault = 100
// bgFlushPeriodDefault is the default for how long to wait for a
// batch to fill up before syncing a set of changes to the servers.
bgFlushPeriodDefault = 1 * time.Second
keyBundlesCacheCapacityBytes = 10 * cache.MB
// folder name for persisted config parameters.
syncedTlfConfigFolderName = "synced_tlf_config"
// By default, this will be the block type given to all blocks
// that aren't explicitly some other type.
defaultBlockTypeDefault = keybase1.BlockType_DATA
// By default, allow 10% of the free bytes on disk to be used in the disk block cache.
defaultDiskBlockCacheFraction = 0.10
// By default, allow 100% of the free bytes on disk to be used in the sync
// block cache.
defaultSyncBlockCacheFraction = 1.00
// By default, use v2 block encryption.
defaultBlockCryptVersion = kbfscrypto.EncryptionSecretboxWithKeyNonce
)
// ConfigLocal implements the Config interface using purely local
// server objects (no KBFS operations used RPCs).
type ConfigLocal struct {
lock sync.RWMutex
kbfs KBFSOps
keyman KeyManager
rep Reporter
kcache KeyCache
kbcache kbfsmd.KeyBundleCache
bcache data.BlockCache
dirtyBcache data.DirtyBlockCache
diskBlockCache DiskBlockCache
diskMDCache DiskMDCache
diskQuotaCache DiskQuotaCache
blockMetadataStore BlockMetadataStore
xattrStore XattrStore
codec kbfscodec.Codec
mdops MDOps
kops libkey.KeyOps
crypto Crypto
chat Chat
mdcache MDCache
bops BlockOps
mdserv MDServer
bserv BlockServer
keyserv libkey.KeyServer
service KeybaseService
bsplit data.BlockSplitter
notifier Notifier
clock Clock
kbpki KBPKI
renamer ConflictRenamer
userHistory *kbfsedits.UserHistory
registry metrics.Registry
loggerFn func(prefix string) logger.Logger
noBGFlush bool // logic opposite so the default value is the common setting
rwpWaitTime time.Duration
diskLimiter DiskLimiter
syncedTlfs map[tlf.ID]FolderSyncConfig
syncedTlfPaths map[string]bool
defaultBlockType keybase1.BlockType
kbfsService *KBFSService
kbCtx Context
rootNodeWrappers []func(Node) Node
tlfClearCancels map[tlf.ID]context.CancelFunc
vdebugSetting string
vlogs []*libkb.VDebugLog
maxNameBytes uint32
rekeyQueue RekeyQueue
storageRoot string
diskCacheMode DiskCacheMode
diskBlockCacheFraction float64
syncBlockCacheFraction float64
traceLock sync.RWMutex
traceEnabled bool
delayedCancellationGracePeriod time.Duration
// allKnownConfigsForTesting is used for testing, and contains all created
// Config objects in this test.
allKnownConfigsForTesting *[]Config
// tlfValidDuration is the time TLFs are valid before redoing identification.
tlfValidDuration time.Duration
// bgFlushDirOpBatchSize indicates how many directory operations
// should be batched together in a single background flush.
bgFlushDirOpBatchSize int
// bgFlushPeriod indicates how long to wait for a batch to fill up
// before syncing a set of changes to the servers.
bgFlushPeriod time.Duration
// metadataVersion is the version to use when creating new metadata.
metadataVersion kbfsmd.MetadataVer
// blockCryptVersion is the version to use when encrypting blocks.
blockCryptVersion kbfscrypto.EncryptionVer
// conflictResolutionDB stores information about failed CRs
conflictResolutionDB *ldbutils.LevelDb
// settingsDB stores information about local KBFS settings
settingsDB *SettingsDB
mode InitMode
quotaUsage map[keybase1.UserOrTeamID]*EventuallyConsistentQuotaUsage
rekeyFSMLimiter *OngoingWorkLimiter
subscriptionManager SubscriptionManager
subscriptionManagerPublisher SubscriptionManagerPublisher
}
// DiskCacheMode represents the mode of initialization for the disk cache.
type DiskCacheMode int
var _ flag.Value = (*DiskCacheMode)(nil)
const (
// DiskCacheModeOff indicates to leave off the disk cache.
DiskCacheModeOff DiskCacheMode = iota
// DiskCacheModeLocal indicates to use a local disk cache.
DiskCacheModeLocal
// DiskCacheModeRemote indicates to use a remote disk cache.
DiskCacheModeRemote
)
// String outputs a human-readable description of this DiskBlockCacheMode.
func (m DiskCacheMode) String() string {
switch m {
case DiskCacheModeOff:
return "off"
case DiskCacheModeLocal:
return "local"
case DiskCacheModeRemote:
return "remote"
}
return "unknown"
}
// Set parses a string representing a disk block cache initialization mode,
// and outputs the mode value corresponding to that string. Defaults to
// DiskCacheModeOff.
func (m *DiskCacheMode) Set(s string) error {
*m = DiskCacheModeOff
switch strings.ToLower(strings.TrimSpace(s)) {
case "local":
*m = DiskCacheModeLocal
case "remote":
*m = DiskCacheModeRemote
}
return nil
}
var _ Config = (*ConfigLocal)(nil)
// getDefaultCleanBlockCacheCapacity returns the default clean block
// cache capacity. If we can get total RAM of the system, we cap at
// the smaller of <1/4 of available memory> and
// <MaxBlockSizeBytesDefault * DefaultBlocksInMemCache>; otherwise,
// fallback to latter.
func getDefaultCleanBlockCacheCapacity(mode InitMode) uint64 {
const minCapacity = 10 * uint64(data.MaxBlockSizeBytesDefault) // 5mb
capacity := uint64(data.MaxBlockSizeBytesDefault) * DefaultBlocksInMemCache
vmstat, err := mem.VirtualMemory()
if err == nil {
ramBased := vmstat.Total / 8
if ramBased < minCapacity {
ramBased = minCapacity
}
if ramBased < capacity {
capacity = ramBased
}
}
if capacity > mode.MaxCleanBlockCacheCapacity() {
capacity = mode.MaxCleanBlockCacheCapacity()
}
return capacity
}
type keyOpsConfigWrapper struct {
Config
}
func (k keyOpsConfigWrapper) KBPKI() idutil.KBPKI {
return k.Config.KBPKI()
}
// NewConfigLocal constructs a new ConfigLocal with some default
// components that don't depend on a logger. The caller will have to
// fill in the rest.
//
// TODO: Now that NewConfigLocal takes loggerFn, add more default
// components.
func NewConfigLocal(mode InitMode,
loggerFn func(module string) logger.Logger,
storageRoot string, diskCacheMode DiskCacheMode,
kbCtx Context) *ConfigLocal {
config := &ConfigLocal{
loggerFn: loggerFn,
storageRoot: storageRoot,
mode: mode,
diskCacheMode: diskCacheMode,
kbCtx: kbCtx,
tlfClearCancels: make(map[tlf.ID]context.CancelFunc),
}
config.SetCodec(kbfscodec.NewMsgpack())
if diskCacheMode == DiskCacheModeLocal {
// Any error is logged in the function itself.
_ = config.loadSyncedTlfsLocked()
}
config.SetClock(data.WallClock{})
config.SetReporter(NewReporterSimple(config.Clock(), 10))
config.SetConflictRenamer(WriterDeviceDateConflictRenamer{config})
config.ResetCaches()
config.SetKeyOps(libkey.NewKeyOpsStandard(keyOpsConfigWrapper{config}))
config.SetRekeyQueue(NewRekeyQueueStandard(config))
uhLog := config.MakeLogger("HIS")
config.SetUserHistory(kbfsedits.NewUserHistory(
uhLog, config.MakeVLogger(uhLog)))
config.maxNameBytes = data.MaxNameBytesDefault
config.rwpWaitTime = rekeyWithPromptWaitTimeDefault
config.delayedCancellationGracePeriod = delayedCancellationGracePeriodDefault
// Don't bother creating the registry if UseNilMetrics is set, or
// if we're in minimal mode.
if !metrics.UseNilMetrics && config.Mode().MetricsEnabled() {
registry := metrics.NewRegistry()
config.SetMetricsRegistry(registry)
}
config.tlfValidDuration = tlfValidDurationDefault
config.bgFlushDirOpBatchSize = bgFlushDirOpBatchSizeDefault
config.bgFlushPeriod = bgFlushPeriodDefault
config.metadataVersion = defaultClientMetadataVer
config.defaultBlockType = defaultBlockTypeDefault
config.quotaUsage =
make(map[keybase1.UserOrTeamID]*EventuallyConsistentQuotaUsage)
config.rekeyFSMLimiter = NewOngoingWorkLimiter(config.Mode().RekeyWorkers())
config.diskBlockCacheFraction = defaultDiskBlockCacheFraction
config.syncBlockCacheFraction = defaultSyncBlockCacheFraction
config.blockCryptVersion = defaultBlockCryptVersion
config.conflictResolutionDB = openCRDB(config)
config.settingsDB = openSettingsDB(config)
config.subscriptionManager, config.subscriptionManagerPublisher =
newSubscriptionManager(config)
return config
}
// KBFSOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KBFSOps() KBFSOps {
c.lock.RLock()
defer c.lock.RUnlock()
return c.kbfs
}
// SetKBFSOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKBFSOps(k KBFSOps) {
c.lock.Lock()
defer c.lock.Unlock()
c.kbfs = k
}
// KBPKI implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KBPKI() KBPKI {
c.lock.RLock()
defer c.lock.RUnlock()
return c.kbpki
}
// CurrentSessionGetter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) CurrentSessionGetter() idutil.CurrentSessionGetter {
c.lock.RLock()
defer c.lock.RUnlock()
return c.kbpki
}
// SetKBPKI implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKBPKI(k KBPKI) {
c.lock.Lock()
defer c.lock.Unlock()
c.kbpki = k
}
// KeyManager implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KeyManager() KeyManager {
c.lock.RLock()
defer c.lock.RUnlock()
return c.keyman
}
// SetKeyManager implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKeyManager(k KeyManager) {
c.lock.Lock()
defer c.lock.Unlock()
c.keyman = k
}
// KeyGetter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) keyGetter() blockKeyGetter {
c.lock.RLock()
defer c.lock.RUnlock()
return c.keyman
}
// Reporter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Reporter() Reporter {
c.lock.RLock()
defer c.lock.RUnlock()
return c.rep
}
// SetReporter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetReporter(r Reporter) {
c.lock.Lock()
defer c.lock.Unlock()
c.rep = r
}
// KeyCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KeyCache() KeyCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.kcache
}
// SetKeyCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKeyCache(k KeyCache) {
c.lock.Lock()
defer c.lock.Unlock()
c.kcache = k
}
// KeyBundleCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KeyBundleCache() kbfsmd.KeyBundleCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.kbcache
}
// SetKeyBundleCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKeyBundleCache(k kbfsmd.KeyBundleCache) {
c.lock.Lock()
defer c.lock.Unlock()
c.kbcache = k
}
// BlockCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) BlockCache() data.BlockCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.bcache
}
// SetBlockCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetBlockCache(b data.BlockCache) {
c.lock.Lock()
defer c.lock.Unlock()
c.bcache = b
}
// DirtyBlockCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DirtyBlockCache() data.DirtyBlockCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.dirtyBcache
}
// SetDirtyBlockCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetDirtyBlockCache(d data.DirtyBlockCache) {
c.lock.Lock()
defer c.lock.Unlock()
c.dirtyBcache = d
}
// DiskBlockCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DiskBlockCache() DiskBlockCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.diskBlockCache
}
// SetDiskBlockCacheFraction implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetDiskBlockCacheFraction(fraction float64) {
c.lock.Lock()
defer c.lock.Unlock()
c.diskBlockCacheFraction = fraction
}
// SetSyncBlockCacheFraction implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetSyncBlockCacheFraction(fraction float64) {
c.lock.Lock()
defer c.lock.Unlock()
c.syncBlockCacheFraction = fraction
}
// DiskMDCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DiskMDCache() DiskMDCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.diskMDCache
}
// DiskQuotaCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DiskQuotaCache() DiskQuotaCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.diskQuotaCache
}
// XattrStore implements the Config interface for ConfigLocal.
func (c *ConfigLocal) XattrStore() XattrStore {
c.lock.RLock()
defer c.lock.RUnlock()
return c.xattrStore
}
// DiskLimiter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DiskLimiter() DiskLimiter {
c.lock.RLock()
defer c.lock.RUnlock()
return c.diskLimiter
}
// Crypto implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Crypto() Crypto {
c.lock.RLock()
defer c.lock.RUnlock()
return c.crypto
}
// Chat implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Chat() Chat {
c.lock.RLock()
defer c.lock.RUnlock()
return c.chat
}
// Signer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Signer() kbfscrypto.Signer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.crypto
}
// SetCrypto implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetCrypto(cr Crypto) {
c.lock.Lock()
defer c.lock.Unlock()
c.crypto = cr
}
// SetChat implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetChat(ch Chat) {
c.lock.Lock()
defer c.lock.Unlock()
c.chat = ch
}
// CryptoPure implements the Config interface for ConfigLocal.
func (c *ConfigLocal) cryptoPure() cryptoPure {
c.lock.RLock()
defer c.lock.RUnlock()
return c.crypto
}
// Codec implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Codec() kbfscodec.Codec {
c.lock.RLock()
defer c.lock.RUnlock()
return c.codec
}
// SetCodec implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetCodec(co kbfscodec.Codec) {
c.lock.Lock()
defer c.lock.Unlock()
c.codec = co
RegisterOps(c.codec)
}
// MDOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MDOps() MDOps {
c.lock.RLock()
defer c.lock.RUnlock()
return c.mdops
}
// SetMDOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetMDOps(m MDOps) {
c.lock.Lock()
defer c.lock.Unlock()
c.mdops = m
}
// KeyOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KeyOps() libkey.KeyOps {
c.lock.RLock()
defer c.lock.RUnlock()
return c.kops
}
// SetKeyOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKeyOps(k libkey.KeyOps) {
c.lock.Lock()
defer c.lock.Unlock()
c.kops = k
}
// MDCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MDCache() MDCache {
c.lock.RLock()
defer c.lock.RUnlock()
return c.mdcache
}
// SetMDCache implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetMDCache(m MDCache) {
c.lock.Lock()
defer c.lock.Unlock()
c.mdcache = m
}
// BlockOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) BlockOps() BlockOps {
c.lock.RLock()
defer c.lock.RUnlock()
return c.bops
}
// SetBlockOps implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetBlockOps(b BlockOps) {
c.lock.Lock()
defer c.lock.Unlock()
c.bops = b
}
// MDServer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MDServer() MDServer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.mdserv
}
// SetMDServer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetMDServer(m MDServer) {
c.lock.Lock()
defer c.lock.Unlock()
c.mdserv = m
}
// BlockServer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) BlockServer() BlockServer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.bserv
}
// SetBlockServer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetBlockServer(b BlockServer) {
c.lock.Lock()
defer c.lock.Unlock()
c.bserv = b
}
// KeyServer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KeyServer() libkey.KeyServer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.keyserv
}
// SetKeyServer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKeyServer(k libkey.KeyServer) {
c.lock.Lock()
defer c.lock.Unlock()
c.keyserv = k
}
// KeybaseService implements the Config interface for ConfigLocal.
func (c *ConfigLocal) KeybaseService() KeybaseService {
c.lock.RLock()
defer c.lock.RUnlock()
return c.service
}
// SetKeybaseService implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetKeybaseService(k KeybaseService) {
c.lock.Lock()
defer c.lock.Unlock()
c.service = k
}
// BlockSplitter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) BlockSplitter() data.BlockSplitter {
c.lock.RLock()
defer c.lock.RUnlock()
return c.bsplit
}
// SetBlockSplitter implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetBlockSplitter(b data.BlockSplitter) {
c.lock.Lock()
defer c.lock.Unlock()
c.bsplit = b
}
// Notifier implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Notifier() Notifier {
c.lock.RLock()
defer c.lock.RUnlock()
return c.notifier
}
// SetNotifier implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetNotifier(n Notifier) {
c.lock.Lock()
defer c.lock.Unlock()
c.notifier = n
}
// Clock implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Clock() Clock {
c.lock.RLock()
defer c.lock.RUnlock()
return c.clock
}
// SetClock implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetClock(cl Clock) {
c.lock.Lock()
defer c.lock.Unlock()
c.clock = cl
}
// ConflictRenamer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) ConflictRenamer() ConflictRenamer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.renamer
}
// SetConflictRenamer implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetConflictRenamer(cr ConflictRenamer) {
c.lock.Lock()
defer c.lock.Unlock()
c.renamer = cr
}
// UserHistory implements the Config interface for ConfigLocal.
func (c *ConfigLocal) UserHistory() *kbfsedits.UserHistory {
c.lock.RLock()
defer c.lock.RUnlock()
return c.userHistory
}
// SetUserHistory implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetUserHistory(uh *kbfsedits.UserHistory) {
c.lock.Lock()
defer c.lock.Unlock()
c.userHistory = uh
}
// MetadataVersion implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MetadataVersion() kbfsmd.MetadataVer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.metadataVersion
}
// SetMetadataVersion implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetMetadataVersion(mdVer kbfsmd.MetadataVer) {
c.lock.Lock()
defer c.lock.Unlock()
c.metadataVersion = mdVer
}
// DataVersion implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DataVersion() data.Ver {
return data.IndirectDirsVer
}
// BlockCryptVersion implements the Config interface for ConfigLocal.
func (c *ConfigLocal) BlockCryptVersion() kbfscrypto.EncryptionVer {
c.lock.RLock()
defer c.lock.RUnlock()
return c.blockCryptVersion
}
// SetBlockCryptVersion implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetBlockCryptVersion(ver kbfscrypto.EncryptionVer) {
c.lock.Lock()
defer c.lock.Unlock()
c.blockCryptVersion = ver
}
// DefaultBlockType implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DefaultBlockType() keybase1.BlockType {
c.lock.RLock()
defer c.lock.RUnlock()
return c.defaultBlockType
}
// SetDefaultBlockType implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetDefaultBlockType(blockType keybase1.BlockType) {
c.lock.Lock()
defer c.lock.Unlock()
c.defaultBlockType = blockType
}
// DoBackgroundFlushes implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DoBackgroundFlushes() bool {
if !c.Mode().BackgroundFlushesEnabled() {
return false
}
c.lock.RLock()
defer c.lock.RUnlock()
return !c.noBGFlush
}
// SetDoBackgroundFlushes implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetDoBackgroundFlushes(doBGFlush bool) {
c.lock.Lock()
defer c.lock.Unlock()
c.noBGFlush = !doBGFlush
}
// RekeyWithPromptWaitTime implements the Config interface for
// ConfigLocal.
func (c *ConfigLocal) RekeyWithPromptWaitTime() time.Duration {
c.lock.Lock()
defer c.lock.Unlock()
return c.rwpWaitTime
}
// SetRekeyWithPromptWaitTime implements the Config interface for
// ConfigLocal.
func (c *ConfigLocal) SetRekeyWithPromptWaitTime(d time.Duration) {
c.lock.RLock()
defer c.lock.RUnlock()
c.rwpWaitTime = d
}
// Mode implements the Config interface for ConfigLocal.
func (c *ConfigLocal) Mode() InitMode {
c.lock.RLock()
defer c.lock.RUnlock()
return c.mode
}
// SetMode implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetMode(mode InitMode) {
c.lock.Lock()
defer c.lock.Unlock()
c.mode = mode
}
// IsTestMode implements the Config interface for ConfigLocal.
func (c *ConfigLocal) IsTestMode() bool {
c.lock.RLock()
defer c.lock.RUnlock()
return c.mode.IsTestMode()
}
// DelayedCancellationGracePeriod implements the Config interface for ConfigLocal.
func (c *ConfigLocal) DelayedCancellationGracePeriod() time.Duration {
return c.delayedCancellationGracePeriod
}
// SetDelayedCancellationGracePeriod implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetDelayedCancellationGracePeriod(d time.Duration) {
c.delayedCancellationGracePeriod = d
}
// ReqsBufSize implements the Config interface for ConfigLocal.
func (c *ConfigLocal) ReqsBufSize() int {
return 20
}
// MaxNameBytes implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MaxNameBytes() uint32 {
return c.maxNameBytes
}
// StorageRoot implements the Config interface for ConfigLocal.
func (c *ConfigLocal) StorageRoot() string {
return c.storageRoot
}
func (c *ConfigLocal) resetCachesWithoutShutdown() data.DirtyBlockCache {
c.lock.Lock()
defer c.lock.Unlock()
c.mdcache = NewMDCacheStandard(defaultMDCacheCapacity)
c.kcache = NewKeyCacheStandard(defaultMDCacheCapacity)
c.kbcache = kbfsmd.NewKeyBundleCacheLRU(keyBundlesCacheCapacityBytes)
log := c.MakeLogger("")
var capacity uint64
if c.bcache == nil {
capacity = getDefaultCleanBlockCacheCapacity(c.mode)
log.Debug("setting default clean block cache capacity to %d",
capacity)
} else {
capacity = c.bcache.GetCleanBytesCapacity()
log.Debug("setting clean block cache capacity based on existing value %d",
capacity)
}
c.bcache = data.NewBlockCacheStandard(10000, capacity)
if !c.mode.DirtyBlockCacheEnabled() {
return nil
}
oldDirtyBcache := c.dirtyBcache
// TODO: we should probably fail or re-schedule this reset if
// there is anything dirty in the dirty block cache.
// The minimum number of bytes we'll try to sync in parallel.
// This should be roughly the minimum amount of bytes we expect
// our worst supported connection to send within the timeout
// forced on us by the upper layer (19 seconds on OS X). With the
// current default of a single block, this minimum works out to
// ~1MB, so we can support a connection speed as low as ~54 KB/s.
minSyncBufferSize := int64(data.MaxBlockSizeBytesDefault)
// The maximum number of bytes we can try to sync at once (also limits the
// amount of memory used by dirty blocks). We use the same value from clean
// block cache capacity here.
maxSyncBufferSize := int64(capacity)
// Start off conservatively to avoid getting immediate timeouts on
// slow connections.
startSyncBufferSize := minSyncBufferSize
dbcLog := c.MakeLogger("DBC")
c.dirtyBcache = data.NewDirtyBlockCacheStandard(
c.clock, dbcLog, c.makeVLoggerLocked(dbcLog),
minSyncBufferSize, maxSyncBufferSize, startSyncBufferSize)
return oldDirtyBcache
}
// ResetCaches implements the Config interface for ConfigLocal.
func (c *ConfigLocal) ResetCaches() {
oldDirtyBcache := c.resetCachesWithoutShutdown()
jManager, err := GetJournalManager(c)
if err == nil {
if err := c.journalizeBcaches(jManager); err != nil {
if log := c.MakeLogger(""); log != nil {
log.CWarningf(
context.TODO(),
"Error journalizing dirty block cache: %+v", err)
}
}
}
if oldDirtyBcache != nil {
// Shutdown outside of the lock so it doesn't block other
// access to this config.
if err := oldDirtyBcache.Shutdown(); err != nil {
if log := c.MakeLogger(""); log != nil {
log.CWarningf(
context.TODO(),
"Error shutting down old dirty block cache: %+v", err)
}
}
}
}
// MakeLogger implements the logMaker interface for ConfigLocal.
func (c *ConfigLocal) MakeLogger(module string) logger.Logger {
// No need to lock since c.loggerFn is initialized once at
// construction. Also resetCachesWithoutShutdown would deadlock.
return c.loggerFn(module)
}
func (c *ConfigLocal) makeVLoggerLocked(log logger.Logger) *libkb.VDebugLog {
vlog := libkb.NewVDebugLog(log)
vlog.Configure(c.vdebugSetting)
c.vlogs = append(c.vlogs, vlog)
return vlog
}
// MakeVLogger implements the logMaker interface for ConfigLocal.
func (c *ConfigLocal) MakeVLogger(log logger.Logger) *libkb.VDebugLog {
c.lock.Lock()
defer c.lock.Unlock()
return c.makeVLoggerLocked(log)
}
// MetricsRegistry implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MetricsRegistry() metrics.Registry {
return c.registry
}
// SetRekeyQueue implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetRekeyQueue(r RekeyQueue) {
c.rekeyQueue = r
}
// RekeyQueue implements the Config interface for ConfigLocal.
func (c *ConfigLocal) RekeyQueue() RekeyQueue {
return c.rekeyQueue
}
// SetMetricsRegistry implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetMetricsRegistry(r metrics.Registry) {
c.registry = r
}
// SetTraceOptions implements the Config interface for ConfigLocal.
func (c *ConfigLocal) SetTraceOptions(enabled bool) {
c.traceLock.Lock()
defer c.traceLock.Unlock()
c.traceEnabled = enabled
}
// MaybeStartTrace implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MaybeStartTrace(
ctx context.Context, family, title string) context.Context {
traceEnabled := func() bool {
c.traceLock.RLock()
defer c.traceLock.RUnlock()
return c.traceEnabled
}()
if !traceEnabled {
return ctx
}
tr := trace.New(family, title)
tr.SetMaxEvents(25)
ctx = trace.NewContext(ctx, tr)
return ctx
}
// MaybeFinishTrace implements the Config interface for ConfigLocal.
func (c *ConfigLocal) MaybeFinishTrace(ctx context.Context, err error) {
if tr, ok := trace.FromContext(ctx); ok {
if err != nil {
tr.LazyPrintf("err=%+v", err)
tr.SetError()