forked from pactus-project/pactus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
50 lines (42 loc) · 1.16 KB
/
config.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
package sync
import (
"time"
"github.com/pactus-project/pactus/sync/firewall"
"github.com/pactus-project/pactus/sync/peerset/service"
"github.com/pactus-project/pactus/util"
)
type Config struct {
Moniker string `toml:"moniker"`
SessionTimeout time.Duration `toml:"session_timeout"`
NodeNetwork bool `toml:"node_network"`
Firewall *firewall.Config `toml:"firewall"`
// Private configs
MaxSessions int `toml:"-"`
LatestBlockInterval uint32 `toml:"-"`
BlockPerMessage uint32 `toml:"-"`
}
func DefaultConfig() *Config {
return &Config{
SessionTimeout: time.Second * 10,
NodeNetwork: true,
BlockPerMessage: 60,
MaxSessions: 8,
LatestBlockInterval: 720,
Firewall: firewall.DefaultConfig(),
}
}
// BasicCheck performs basic checks on the configuration.
func (conf *Config) BasicCheck() error {
return nil
}
func (conf *Config) CacheSize() int {
return util.LogScale(
int(conf.BlockPerMessage * conf.LatestBlockInterval))
}
func (conf *Config) Services() service.Services {
s := service.New()
if conf.NodeNetwork {
s.Append(service.Network)
}
return s
}