Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
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
48 changes: 34 additions & 14 deletions cmd/swarm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,24 @@ var (

//constants for environment variables
const (
SWARM_ENV_CHEQUEBOOK_ADDR = "SWARM_CHEQUEBOOK_ADDR"
SWARM_ENV_ACCOUNT = "SWARM_ACCOUNT"
SWARM_ENV_LISTEN_ADDR = "SWARM_LISTEN_ADDR"
SWARM_ENV_PORT = "SWARM_PORT"
SWARM_ENV_NETWORK_ID = "SWARM_NETWORK_ID"
SWARM_ENV_SWAP_ENABLE = "SWARM_SWAP_ENABLE"
SWARM_ENV_SWAP_API = "SWARM_SWAP_API"
SWARM_ENV_SYNC_ENABLE = "SWARM_SYNC_ENABLE"
SWARM_ENV_ENS_API = "SWARM_ENS_API"
SWARM_ENV_ENS_ADDR = "SWARM_ENS_ADDR"
SWARM_ENV_CORS = "SWARM_CORS"
SWARM_ENV_BOOTNODES = "SWARM_BOOTNODES"
SWARM_ENV_PSS_ENABLE = "SWARM_PSS_ENABLE"
GETH_ENV_DATADIR = "GETH_DATADIR"
SWARM_ENV_CHEQUEBOOK_ADDR = "SWARM_CHEQUEBOOK_ADDR"
SWARM_ENV_ACCOUNT = "SWARM_ACCOUNT"
SWARM_ENV_LISTEN_ADDR = "SWARM_LISTEN_ADDR"
SWARM_ENV_PORT = "SWARM_PORT"
SWARM_ENV_NETWORK_ID = "SWARM_NETWORK_ID"
SWARM_ENV_SWAP_ENABLE = "SWARM_SWAP_ENABLE"
SWARM_ENV_SWAP_API = "SWARM_SWAP_API"
SWARM_ENV_SYNC_ENABLE = "SWARM_SYNC_ENABLE"
SWARM_ENV_ENS_API = "SWARM_ENS_API"
SWARM_ENV_ENS_ADDR = "SWARM_ENS_ADDR"
SWARM_ENV_CORS = "SWARM_CORS"
SWARM_ENV_BOOTNODES = "SWARM_BOOTNODES"
SWARM_ENV_PSS_ENABLE = "SWARM_PSS_ENABLE"
SWARM_ENV_STORE_PATH = "SWARM_STORE_PATH"
SWARM_ENV_STORE_CAPACITY = "SWARM_STORE_CAPACITY"
SWARM_ENV_STORE_CACHE_CAPACITY = "SWARM_STORE_CACHE_CAPACITY"
SWARM_ENV_STORE_RADIUS = "SWARM_STORE_RADIUS"
GETH_ENV_DATADIR = "GETH_DATADIR"
)

// These settings ensure that TOML keys use the same names as Go struct fields.
Expand Down Expand Up @@ -216,6 +220,22 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
currentConfig.PssEnabled = true
}

if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" {
currentConfig.StoreParams.ChunkDbPath = storePath
}

if storeCapacity := ctx.GlobalUint64(SwarmStoreCapacity.Name); storeCapacity != 0 {
currentConfig.StoreParams.DbCapacity = uint64(storeCapacity)
}

if storeCacheCapacity := ctx.GlobalUint(SwarmStoreCacheCapacity.Name); storeCacheCapacity != 0 {
currentConfig.StoreParams.CacheCapacity = uint(storeCacheCapacity)
}

if storeRadius := ctx.GlobalInt(SwarmStoreRadius.Name); storeRadius != 0 {
currentConfig.StoreParams.Radius = int(storeRadius)
}

return currentConfig

}
Expand Down
25 changes: 25 additions & 0 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ var (
Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied separated by a ',')",
EnvVar: SWARM_ENV_CORS,
}
SwarmStorePath = cli.StringFlag{
Name: "store.path",
Usage: "Path to leveldb chunk DB (default <$GETH_ENV_DIR>/swarm/bzz-<$BZZ_KEY>/chunks)",
EnvVar: SWARM_ENV_STORE_PATH,
}
SwarmStoreCapacity = cli.Uint64Flag{
Name: "store.size",
Usage: "Number of chunks (5M is roughly 20-25GB) (default 5000000)",
EnvVar: SWARM_ENV_STORE_CAPACITY,
}
SwarmStoreCacheCapacity = cli.UintFlag{
Name: "store.cache.size",
Usage: "Number of recent chunks cached in memory (default 5000)",
EnvVar: SWARM_ENV_STORE_CACHE_CAPACITY,
}
SwarmStoreRadius = cli.IntFlag{
Name: "store.radius",
Usage: "Minimum proximity order (number of identical prefix bits of address key) for chunks to warrant storage (default 0)",
EnvVar: SWARM_ENV_STORE_RADIUS,
}

// the following flags are deprecated and should be removed in the future
DeprecatedEthAPIFlag = cli.StringFlag{
Expand Down Expand Up @@ -367,6 +387,11 @@ DEPRECATED: use 'swarm db clean'.
SwarmUploadMimeType,
// pss flags
SwarmPssEnabledFlag,
// storage flags
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename comment to store

SwarmStorePath,
SwarmStoreCapacity,
SwarmStoreCacheCapacity,
SwarmStoreRadius,
//deprecated flags
DeprecatedEthAPIFlag,
}
Expand Down
4 changes: 3 additions & 1 deletion swarm/storage/netstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func NewDefaultStoreParams() (self *StoreParams) {
//this can only finally be set after all config options (file, cmd line, env vars)
//have been evaluated
func (self *StoreParams) Init(path string) {
self.ChunkDbPath = filepath.Join(path, "chunks")
if self.ChunkDbPath == "" {
self.ChunkDbPath = filepath.Join(path, "chunks")
}
Copy link
Copy Markdown
Author

@christopherdro christopherdro Jan 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best way to handle this or does it make more sense to add this to NewDefaultStoreParams ? https://github.com/async-la/go-ethereum/blob/872aeef800ee6368704bec7fc8108d4a235b6e19/swarm/storage/netstore.go#L61

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be here because the default for a path can be overridden by command line or env var later.

}

// netstore contructor, takes path argument that is used to initialise dbStore,
Expand Down