diff --git a/config/config.go b/config/config.go index afcd723b..7bc218b6 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { @@ -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) { diff --git a/config/profiles.go b/config/profiles.go new file mode 100644 index 00000000..68eb33be --- /dev/null +++ b/config/profiles.go @@ -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 +}