-
Notifications
You must be signed in to change notification settings - Fork 199
/
common.go
47 lines (41 loc) · 1.52 KB
/
common.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
package factory
import (
"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/storage/storageUnit"
)
const allFiles = -1
// GetCacherFromConfig will return the cache config needed for storage unit from a config came from the toml file
func GetCacherFromConfig(cfg config.CacheConfig) storageUnit.CacheConfig {
return storageUnit.CacheConfig{
Name: cfg.Name,
Capacity: cfg.Capacity,
SizePerSender: cfg.SizePerSender,
SizeInBytes: cfg.SizeInBytes,
SizeInBytesPerSender: cfg.SizeInBytesPerSender,
Type: storageUnit.CacheType(cfg.Type),
Shards: cfg.Shards,
}
}
// GetDBFromConfig will return the db config needed for storage unit from a config came from the toml file
func GetDBFromConfig(cfg config.DBConfig) storageUnit.DBConfig {
return storageUnit.DBConfig{
Type: storageUnit.DBType(cfg.Type),
MaxBatchSize: cfg.MaxBatchSize,
BatchDelaySeconds: cfg.BatchDelaySeconds,
MaxOpenFiles: cfg.MaxOpenFiles,
}
}
// GetBloomFromConfig will return the bloom config needed for storage unit from a config came from the toml file
func GetBloomFromConfig(cfg config.BloomFilterConfig) storageUnit.BloomConfig {
var hashFuncs []storageUnit.HasherType
if cfg.HashFunc != nil {
hashFuncs = make([]storageUnit.HasherType, len(cfg.HashFunc))
for idx, hf := range cfg.HashFunc {
hashFuncs[idx] = storageUnit.HasherType(hf)
}
}
return storageUnit.BloomConfig{
Size: cfg.Size,
HashFunc: hashFuncs,
}
}