Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shared node profile #783

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
datadirPrivateKey = "nodekey" // Path within the datadir to the node's private key
apiKeyFileName = "api.key"
LowPowerProfile = "lowpower"
SharedNodeProfile = "shared"
DefaultProfile = "default"
)

type Config struct {
Expand Down Expand Up @@ -188,33 +190,27 @@ func MakeConfig(ctx *cli.Context, cfgTransform func(cfg *Config)) (*Config, erro
}

func applyProfile(ctx *cli.Context, cfg *Config) {
if ctx.IsSet(ProfileFlag.Name) && ctx.String(ProfileFlag.Name) == LowPowerProfile {
cfg.P2P.MaxInboundPeers = LowPowerMaxInboundNotOwnShardPeers
cfg.P2P.MaxOutboundPeers = LowPowerMaxOutboundNotOwnShardPeers
cfg.P2P.MaxInboundOwnShardPeers = LowPowerMaxInboundOwnShardPeers
cfg.P2P.MaxOutboundOwnShardPeers = LowPowerMaxOutboundOwnShardPeers
cfg.IpfsConf.LowWater = 8
cfg.IpfsConf.HighWater = 10
cfg.IpfsConf.GracePeriod = "30s"
cfg.IpfsConf.ReproviderInterval = "0"
cfg.IpfsConf.Routing = "dhtclient"
} else {
if cfg.IpfsConf.LowWater == 0 {
cfg.IpfsConf.LowWater = 30
}
if cfg.IpfsConf.HighWater == 0 {
cfg.IpfsConf.HighWater = 50
}
if cfg.IpfsConf.GracePeriod == "" {
cfg.IpfsConf.GracePeriod = "40s"
}
if cfg.IpfsConf.ReproviderInterval == "" {
cfg.IpfsConf.ReproviderInterval = "12h"
}
if cfg.IpfsConf.Routing == "" {
cfg.IpfsConf.Routing = "dht"
if ctx.IsSet(ProfileFlag.Name) {
switch ctx.String(ProfileFlag.Name) {
case LowPowerProfile:
applyLowPowerProfile(cfg)
case SharedNodeProfile:
applySharedNodeProfile(cfg)
case DefaultProfile:
applyDefaultProfile(cfg)
default:
println("unknown node profile")
}
}
if cfg.IpfsConf.GracePeriod == "" {
cfg.IpfsConf.GracePeriod = "40s"
}
if cfg.IpfsConf.ReproviderInterval == "" {
cfg.IpfsConf.ReproviderInterval = "12h"
}
if cfg.IpfsConf.Routing == "" {
cfg.IpfsConf.Routing = "dht"
}
}

func MakeConfigFromFile(file string) (*Config, error) {
Expand Down
31 changes: 31 additions & 0 deletions config/profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package config

func applyLowPowerProfile(cfg *Config) {
cfg.P2P.MaxInboundPeers = LowPowerMaxInboundNotOwnShardPeers
cfg.P2P.MaxOutboundPeers = LowPowerMaxOutboundNotOwnShardPeers
cfg.P2P.MaxInboundOwnShardPeers = LowPowerMaxInboundOwnShardPeers
cfg.P2P.MaxOutboundOwnShardPeers = LowPowerMaxOutboundOwnShardPeers
cfg.IpfsConf.LowWater = 8
cfg.IpfsConf.HighWater = 10
cfg.IpfsConf.GracePeriod = "30s"
cfg.IpfsConf.ReproviderInterval = "0"
cfg.IpfsConf.Routing = "dhtclient"
}

func applySharedNodeProfile(cfg *Config) {
cfg.P2P.Multishard = true
cfg.Sync.LoadAllFlips = true
cfg.IpfsConf.LowWater = 50
cfg.IpfsConf.HighWater = 100
}

func applyDefaultProfile(cfg *Config) {
cfg.P2P.MaxInboundPeers = DefaultMaxInboundNotOwnShardPeers
cfg.P2P.MaxOutboundPeers = DefaultMaxOutboundNotOwnShardPeers
cfg.P2P.MaxInboundOwnShardPeers = DefaultMaxInboundOwnShardPeers
cfg.P2P.MaxOutboundOwnShardPeers = DefaultMaxOutboundOwnShardPeers
cfg.IpfsConf.LowWater = 30
cfg.IpfsConf.HighWater = 50
cfg.P2P.Multishard = false
cfg.Sync.LoadAllFlips = false
}