cmd/swarm: add config file (#15548)

This commit adds a TOML configuration option to swarm. It reuses
the TOML configuration structure used in geth with swarm
customized items.

The commit:

* Adds a "dumpconfig" command to the swarm executable which
  allows printing the (default) configuration to stdout, which
  then can be redirected to a file in order to customize it.
* Adds a "--config <file>" option to the swarm executable which will
  allow to load a configuration file in TOML format from the
  specified location in order to initialize the Swarm node The
  override priorities are like follows: environment variables
  override command line arguments override config file override
  default config.
This commit is contained in:
holisticode
2017-12-11 16:56:06 -05:00
committed by Felix Lange
parent 1a32bdf92c
commit 32516c768e
13 changed files with 1015 additions and 292 deletions

View File

@@ -70,19 +70,25 @@ type HiveParams struct {
*kademlia.KadParams
}
func NewHiveParams(path string) *HiveParams {
kad := kademlia.NewKadParams()
//create default params
func NewDefaultHiveParams() *HiveParams {
kad := kademlia.NewDefaultKadParams()
// kad.BucketSize = bucketSize
// kad.MaxProx = maxProx
// kad.ProxBinSize = proxBinSize
return &HiveParams{
CallInterval: callInterval,
KadDbPath: filepath.Join(path, "bzz-peers.json"),
KadParams: kad,
}
}
//this can only finally be set after all config options (file, cmd line, env vars)
//have been evaluated
func (self *HiveParams) Init(path string) {
self.KadDbPath = filepath.Join(path, "bzz-peers.json")
}
func NewHive(addr common.Hash, params *HiveParams, swapEnabled, syncEnabled bool) *Hive {
kad := kademlia.New(kademlia.Address(addr), params.KadParams)
return &Hive{

View File

@@ -52,7 +52,7 @@ type KadParams struct {
ConnRetryExp int
}
func NewKadParams() *KadParams {
func NewDefaultKadParams() *KadParams {
return &KadParams{
MaxProx: maxProx,
ProxBinSize: proxBinSize,

View File

@@ -63,7 +63,7 @@ func TestOn(t *testing.T) {
if !ok1 || !ok2 {
t.Errorf("oops")
}
kad := New(addr, NewKadParams())
kad := New(addr, NewDefaultKadParams())
err := kad.On(&testNode{addr: other}, nil)
_ = err
}
@@ -72,7 +72,7 @@ func TestBootstrap(t *testing.T) {
test := func(test *bootstrapTest) bool {
// for any node kad.le, Target and N
params := NewKadParams()
params := NewDefaultKadParams()
params.MaxProx = test.MaxProx
params.BucketSize = test.BucketSize
params.ProxBinSize = test.BucketSize
@@ -127,7 +127,7 @@ func TestFindClosest(t *testing.T) {
test := func(test *FindClosestTest) bool {
// for any node kad.le, Target and N
params := NewKadParams()
params := NewDefaultKadParams()
params.MaxProx = 7
kad := New(test.Self, params)
var err error
@@ -198,7 +198,7 @@ var (
func TestProxAdjust(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
self := gen(Address{}, r).(Address)
params := NewKadParams()
params := NewDefaultKadParams()
params.MaxProx = 7
kad := New(self, params)
@@ -232,7 +232,7 @@ func TestSaveLoad(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
addresses := gen([]Address{}, r).([]Address)
self := RandomAddress()
params := NewKadParams()
params := NewDefaultKadParams()
params.MaxProx = 7
kad := New(self, params)

View File

@@ -131,9 +131,8 @@ type SyncParams struct {
}
// constructor with default values
func NewSyncParams(bzzdir string) *SyncParams {
func NewDefaultSyncParams() *SyncParams {
return &SyncParams{
RequestDbPath: filepath.Join(bzzdir, "requests"),
RequestDbBatchSize: requestDbBatchSize,
KeyBufferSize: keyBufferSize,
SyncBufferSize: syncBufferSize,
@@ -144,6 +143,12 @@ func NewSyncParams(bzzdir string) *SyncParams {
}
}
//this can only finally be set after all config options (file, cmd line, env vars)
//have been evaluated
func (self *SyncParams) Init(path string) {
self.RequestDbPath = filepath.Join(path, "requests")
}
// syncer is the agent that manages content distribution/storage replication/chunk storeRequest forwarding
type syncer struct {
*SyncParams // sync parameters