Merge pull request #422 from ethersphere/nosync-flag

swarm: Change sync params to neg. assert + remove optnl pss/resource
This commit is contained in:
lash 2018-04-25 12:59:13 +02:00 committed by GitHub
commit 41d5566716
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 76 deletions

View file

@ -66,7 +66,7 @@ const (
SWARM_ENV_NETWORK_ID = "SWARM_NETWORK_ID" SWARM_ENV_NETWORK_ID = "SWARM_NETWORK_ID"
SWARM_ENV_SWAP_ENABLE = "SWARM_SWAP_ENABLE" SWARM_ENV_SWAP_ENABLE = "SWARM_SWAP_ENABLE"
SWARM_ENV_SWAP_API = "SWARM_SWAP_API" SWARM_ENV_SWAP_API = "SWARM_SWAP_API"
SWARM_ENV_SYNC_ENABLE = "SWARM_SYNC_ENABLE" SWARM_ENV_SYNC_DISABLE = "SWARM_SYNC_DISABLE"
SWARM_ENV_SYNC_UPDATE_DELAY = "SWARM_ENV_SYNC_UPDATE_DELAY" SWARM_ENV_SYNC_UPDATE_DELAY = "SWARM_ENV_SYNC_UPDATE_DELAY"
SWARM_ENV_ENS_API = "SWARM_ENS_API" SWARM_ENV_ENS_API = "SWARM_ENS_API"
SWARM_ENV_ENS_ADDR = "SWARM_ENS_ADDR" SWARM_ENV_ENS_ADDR = "SWARM_ENS_ADDR"
@ -197,8 +197,8 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
currentConfig.SwapEnabled = true currentConfig.SwapEnabled = true
} }
if ctx.GlobalIsSet(SwarmSyncEnabledFlag.Name) { if ctx.GlobalIsSet(SwarmSyncDisabledFlag.Name) {
currentConfig.SyncEnabled = true currentConfig.SyncEnabled = false
} }
if d := ctx.GlobalDuration(SwarmSyncUpdateDelay.Name); d > 0 { if d := ctx.GlobalDuration(SwarmSyncUpdateDelay.Name); d > 0 {
@ -231,10 +231,6 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
currentConfig.BootNodes = ctx.GlobalString(utils.BootnodesFlag.Name) currentConfig.BootNodes = ctx.GlobalString(utils.BootnodesFlag.Name)
} }
if ctx.GlobalIsSet(SwarmPssEnabledFlag.Name) {
currentConfig.PssEnabled = true
}
if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" { if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" {
currentConfig.LocalStoreParams.ChunkDbPath = storePath currentConfig.LocalStoreParams.ChunkDbPath = storePath
} }
@ -288,9 +284,9 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
} }
} }
if syncenable := os.Getenv(SWARM_ENV_SYNC_ENABLE); syncenable != "" { if syncdisable := os.Getenv(SWARM_ENV_SYNC_DISABLE); syncdisable != "" {
if sync, err := strconv.ParseBool(syncenable); err != nil { if sync, err := strconv.ParseBool(syncdisable); err != nil {
currentConfig.SyncEnabled = sync currentConfig.SyncEnabled = !sync
} }
} }
@ -324,12 +320,6 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
currentConfig.BootNodes = bootnodes currentConfig.BootNodes = bootnodes
} }
if pssenable := os.Getenv(SWARM_ENV_PSS_ENABLE); pssenable != "" {
if ps, err := strconv.ParseBool(pssenable); err != nil {
currentConfig.PssEnabled = ps
}
}
return currentConfig return currentConfig
} }

View file

@ -85,8 +85,7 @@ func TestConfigCmdLineOverrides(t *testing.T) {
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "42", fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "42",
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
fmt.Sprintf("--%s", SwarmSyncEnabledFlag.Name), fmt.Sprintf("--%s", SwarmSyncDisabledFlag.Name),
fmt.Sprintf("--%s", SwarmPssEnabledFlag.Name),
fmt.Sprintf("--%s", CorsStringFlag.Name), "*", fmt.Sprintf("--%s", CorsStringFlag.Name), "*",
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
fmt.Sprintf("--%s", EnsAPIFlag.Name), "", fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
@ -125,12 +124,8 @@ func TestConfigCmdLineOverrides(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
}
if !info.PssEnabled {
t.Fatal("Expected Pss to be enabled, but is false")
} }
if info.Cors != "*" { if info.Cors != "*" {
@ -152,8 +147,7 @@ func TestConfigFileOverrides(t *testing.T) {
//first, create a default conf //first, create a default conf
defaultConf := api.NewConfig() defaultConf := api.NewConfig()
//change some values in order to test if they have been loaded //change some values in order to test if they have been loaded
defaultConf.SyncEnabled = true defaultConf.SyncEnabled = false
defaultConf.PssEnabled = true
defaultConf.NetworkId = 54 defaultConf.NetworkId = 54
defaultConf.Port = httpPort defaultConf.Port = httpPort
defaultConf.DbCapacity = 9000000 defaultConf.DbCapacity = 9000000
@ -224,12 +218,8 @@ func TestConfigFileOverrides(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
}
if !info.PssEnabled {
t.Fatal("Expected Pss to be enabled, but is false")
} }
if info.DbCapacity != 9000000 { if info.DbCapacity != 9000000 {
@ -262,8 +252,7 @@ func TestConfigEnvVars(t *testing.T) {
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmPortFlag.EnvVar, httpPort)) envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmPortFlag.EnvVar, httpPort))
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmNetworkIdFlag.EnvVar, "999")) envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmNetworkIdFlag.EnvVar, "999"))
envVars = append(envVars, fmt.Sprintf("%s=%s", CorsStringFlag.EnvVar, "*")) envVars = append(envVars, fmt.Sprintf("%s=%s", CorsStringFlag.EnvVar, "*"))
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmSyncEnabledFlag.EnvVar, "true")) envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmSyncDisabledFlag.EnvVar, "true"))
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmPssEnabledFlag.EnvVar, "true"))
dir, err := ioutil.TempDir("", "bzztest") dir, err := ioutil.TempDir("", "bzztest")
if err != nil { if err != nil {
@ -340,12 +329,8 @@ func TestConfigEnvVars(t *testing.T) {
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors) t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
}
if !info.PssEnabled {
t.Fatal("Expected Pss to be enabled, but is false")
} }
node.Shutdown() node.Shutdown()
@ -364,8 +349,7 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
//first, create a default conf //first, create a default conf
defaultConf := api.NewConfig() defaultConf := api.NewConfig()
//change some values in order to test if they have been loaded //change some values in order to test if they have been loaded
defaultConf.SyncEnabled = false defaultConf.SyncEnabled = true
defaultConf.PssEnabled = false
defaultConf.NetworkId = 54 defaultConf.NetworkId = 54
defaultConf.Port = "8588" defaultConf.Port = "8588"
defaultConf.DbCapacity = 9000000 defaultConf.DbCapacity = 9000000
@ -404,8 +388,7 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "77", fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "77",
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
fmt.Sprintf("--%s", SwarmSyncEnabledFlag.Name), fmt.Sprintf("--%s", SwarmSyncDisabledFlag.Name),
fmt.Sprintf("--%s", SwarmPssEnabledFlag.Name),
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(), fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(),
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
"--ens-api", "", "--ens-api", "",
@ -444,8 +427,8 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
} }
if info.LocalStoreParams.DbCapacity != 9000000 { if info.LocalStoreParams.DbCapacity != 9000000 {
@ -460,10 +443,6 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval) t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval)
} }
if !info.PssEnabled {
t.Fatal("Expected Pss to be enabled, but is false")
}
// if info.SyncParams.KeyBufferSize != 512 { // if info.SyncParams.KeyBufferSize != 512 {
// t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize) // t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize)
// } // }

View file

@ -101,10 +101,10 @@ var (
Usage: "URL of the Ethereum API provider to use to settle SWAP payments", Usage: "URL of the Ethereum API provider to use to settle SWAP payments",
EnvVar: SWARM_ENV_SWAP_API, EnvVar: SWARM_ENV_SWAP_API,
} }
SwarmSyncEnabledFlag = cli.BoolTFlag{ SwarmSyncDisabledFlag = cli.BoolTFlag{
Name: "sync", Name: "nosync",
Usage: "Swarm Syncing enabled (default true)", Usage: "Disable swarm syncing",
EnvVar: SWARM_ENV_SYNC_ENABLE, EnvVar: SWARM_ENV_SYNC_DISABLE,
} }
SwarmSyncUpdateDelay = cli.DurationFlag{ SwarmSyncUpdateDelay = cli.DurationFlag{
Name: "sync-update-delay", Name: "sync-update-delay",
@ -145,10 +145,6 @@ var (
Name: "encrypted", Name: "encrypted",
Usage: "use encrypted upload", Usage: "use encrypted upload",
} }
SwarmPssEnabledFlag = cli.BoolFlag{
Name: "pss",
Usage: "Enable pss (message passing over swarm)",
}
CorsStringFlag = cli.StringFlag{ CorsStringFlag = cli.StringFlag{
Name: "corsdomain", Name: "corsdomain",
Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied separated by a ',')", Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied separated by a ',')",
@ -360,7 +356,7 @@ Remove corrupt entries from a local chunk database.
SwarmConfigPathFlag, SwarmConfigPathFlag,
SwarmSwapEnabledFlag, SwarmSwapEnabledFlag,
SwarmSwapAPIFlag, SwarmSwapAPIFlag,
SwarmSyncEnabledFlag, SwarmSyncDisabledFlag,
SwarmSyncUpdateDelay, SwarmSyncUpdateDelay,
SwarmListenAddrFlag, SwarmListenAddrFlag,
SwarmPortFlag, SwarmPortFlag,
@ -374,8 +370,6 @@ Remove corrupt entries from a local chunk database.
SwarmUploadDefaultPath, SwarmUploadDefaultPath,
SwarmUpFromStdinFlag, SwarmUpFromStdinFlag,
SwarmUploadMimeType, SwarmUploadMimeType,
// pss flags
SwarmPssEnabledFlag,
// storage flags // storage flags
SwarmStorePath, SwarmStorePath,
SwarmStoreCapacity, SwarmStoreCapacity,
@ -440,9 +434,7 @@ func bzzd(ctx *cli.Context) error {
cfg := defaultNodeConfig cfg := defaultNodeConfig
//pss operates on ws //pss operates on ws
if bzzconfig.PssEnabled { cfg.WSModules = append(cfg.WSModules, "pss")
cfg.WSModules = append(cfg.WSModules, "pss")
}
//geth only supports --datadir via command line //geth only supports --datadir via command line
//in order to be consistent within swarm, if we pass --datadir via environment variable //in order to be consistent within swarm, if we pass --datadir via environment variable

View file

@ -61,8 +61,6 @@ type Config struct {
SwapEnabled bool SwapEnabled bool
SyncEnabled bool SyncEnabled bool
SyncUpdateDelay time.Duration SyncUpdateDelay time.Duration
PssEnabled bool
ResourceEnabled bool
SwapApi string SwapApi string
Cors string Cors string
BzzAccount string BzzAccount string
@ -88,8 +86,6 @@ func NewConfig() (self *Config) {
SwapEnabled: false, SwapEnabled: false,
SyncEnabled: true, SyncEnabled: true,
SyncUpdateDelay: 15 * time.Second, SyncUpdateDelay: 15 * time.Second,
PssEnabled: true,
ResourceEnabled: true,
SwapApi: "", SwapApi: "",
BootNodes: "", BootNodes: "",
} }

View file

@ -211,7 +211,6 @@ func testSwarmNetwork(t *testing.T, timeout time.Duration, steps ...testSwarmNet
services := map[string]adapters.ServiceFunc{ services := map[string]adapters.ServiceFunc{
"swarm": func(ctx *adapters.ServiceContext) (node.Service, error) { "swarm": func(ctx *adapters.ServiceContext) (node.Service, error) {
config := api.NewConfig() config := api.NewConfig()
config.PssEnabled = false
dir, err := ioutil.TempDir(dir, "node") dir, err := ioutil.TempDir(dir, "node")
if err != nil { if err != nil {

View file

@ -178,7 +178,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
var resourceHandler *storage.ResourceHandler var resourceHandler *storage.ResourceHandler
// if use resource updates // if use resource updates
if self.config.ResourceEnabled && resolver != nil { if resolver != nil {
resolver.SetNameHash(ens.EnsNode) resolver.SetNameHash(ens.EnsNode)
rhparams := &storage.ResourceHandlerParams{ rhparams := &storage.ResourceHandlerParams{
// TODO: config parameter to set limits // TODO: config parameter to set limits
@ -196,6 +196,8 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
return nil, err return nil, err
} }
resourceHandler.SetStore(self.lstore) resourceHandler.SetStore(self.lstore)
} else {
log.Warn("No ENS API specified, resource updates will be disabled")
} }
var validators []storage.ChunkValidator var validators []storage.ChunkValidator
@ -227,12 +229,10 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
self.bzz = network.NewBzz(bzzconfig, to, stateStore, stream.Spec, self.streamer.Run) self.bzz = network.NewBzz(bzzconfig, to, stateStore, stream.Spec, self.streamer.Run)
// Pss = postal service over swarm (devp2p over bzz) // Pss = postal service over swarm (devp2p over bzz)
if config.PssEnabled { pssparams := pss.NewPssParams(self.privateKey)
pssparams := pss.NewPssParams(self.privateKey) self.ps = pss.NewPss(to, pssparams)
self.ps = pss.NewPss(to, pssparams) if pss.IsActiveHandshake {
if pss.IsActiveHandshake { pss.SetHandshakeController(self.ps, pss.NewHandshakeParams())
pss.SetHandshakeController(self.ps, pss.NewHandshakeParams())
}
} }
self.api = api.NewApi(self.dpa, self.dns, resourceHandler) self.api = api.NewApi(self.dpa, self.dns, resourceHandler)