mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
cmd/swarm, swarm/api: add GlobalStoreAPI option
This commit is contained in:
parent
0fa0621c8d
commit
82f1b042c3
4 changed files with 32 additions and 3 deletions
|
|
@ -82,6 +82,7 @@ const (
|
||||||
SWARM_ENV_BOOTNODE_MODE = "SWARM_BOOTNODE_MODE"
|
SWARM_ENV_BOOTNODE_MODE = "SWARM_BOOTNODE_MODE"
|
||||||
SWARM_ACCESS_PASSWORD = "SWARM_ACCESS_PASSWORD"
|
SWARM_ACCESS_PASSWORD = "SWARM_ACCESS_PASSWORD"
|
||||||
SWARM_AUTO_DEFAULTPATH = "SWARM_AUTO_DEFAULTPATH"
|
SWARM_AUTO_DEFAULTPATH = "SWARM_AUTO_DEFAULTPATH"
|
||||||
|
SWARM_GLOBALSTORE_API = "SWARM_GLOBALSTORE_API"
|
||||||
GETH_ENV_DATADIR = "GETH_DATADIR"
|
GETH_ENV_DATADIR = "GETH_DATADIR"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -262,6 +263,10 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
|
||||||
currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name)
|
currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.GlobalIsSet(SwarmGlobalStoreAPIFlag.Name) {
|
||||||
|
currentConfig.GlobalStoreAPI = ctx.GlobalString(SwarmGlobalStoreAPIFlag.Name)
|
||||||
|
}
|
||||||
|
|
||||||
return currentConfig
|
return currentConfig
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -375,6 +380,10 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
|
||||||
currentConfig.BootnodeMode = bootnodeMode
|
currentConfig.BootnodeMode = bootnodeMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if api := os.Getenv(SWARM_GLOBALSTORE_API); api != "" {
|
||||||
|
currentConfig.GlobalStoreAPI = api
|
||||||
|
}
|
||||||
|
|
||||||
return currentConfig
|
return currentConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,4 +176,9 @@ var (
|
||||||
Name: "user",
|
Name: "user",
|
||||||
Usage: "Indicates the user who updates the feed",
|
Usage: "Indicates the user who updates the feed",
|
||||||
}
|
}
|
||||||
|
SwarmGlobalStoreAPIFlag = cli.StringFlag{
|
||||||
|
Name: "globalstore-api",
|
||||||
|
Usage: "URL of the Global Store API provider (only for testing)",
|
||||||
|
EnvVar: SWARM_GLOBALSTORE_API,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,16 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/swarm"
|
"github.com/ethereum/go-ethereum/swarm"
|
||||||
bzzapi "github.com/ethereum/go-ethereum/swarm/api"
|
bzzapi "github.com/ethereum/go-ethereum/swarm/api"
|
||||||
swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics"
|
swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/storage/mock"
|
||||||
|
mockrpc "github.com/ethereum/go-ethereum/swarm/storage/mock/rpc"
|
||||||
"github.com/ethereum/go-ethereum/swarm/tracing"
|
"github.com/ethereum/go-ethereum/swarm/tracing"
|
||||||
sv "github.com/ethereum/go-ethereum/swarm/version"
|
sv "github.com/ethereum/go-ethereum/swarm/version"
|
||||||
|
|
||||||
"gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const clientIdentifier = "swarm"
|
const clientIdentifier = "swarm"
|
||||||
|
|
@ -194,6 +197,7 @@ func init() {
|
||||||
SwarmStorePath,
|
SwarmStorePath,
|
||||||
SwarmStoreCapacity,
|
SwarmStoreCapacity,
|
||||||
SwarmStoreCacheCapacity,
|
SwarmStoreCacheCapacity,
|
||||||
|
SwarmGlobalStoreAPIFlag,
|
||||||
}
|
}
|
||||||
rpcFlags := []cli.Flag{
|
rpcFlags := []cli.Flag{
|
||||||
utils.WSEnabledFlag,
|
utils.WSEnabledFlag,
|
||||||
|
|
@ -322,8 +326,18 @@ func bzzd(ctx *cli.Context) error {
|
||||||
func registerBzzService(bzzconfig *bzzapi.Config, stack *node.Node) {
|
func registerBzzService(bzzconfig *bzzapi.Config, stack *node.Node) {
|
||||||
//define the swarm service boot function
|
//define the swarm service boot function
|
||||||
boot := func(_ *node.ServiceContext) (node.Service, error) {
|
boot := func(_ *node.ServiceContext) (node.Service, error) {
|
||||||
// In production, mockStore must be always nil.
|
var nodeStore *mock.NodeStore
|
||||||
return swarm.NewSwarm(bzzconfig, nil)
|
if bzzconfig.GlobalStoreAPI != "" {
|
||||||
|
// connect to global store
|
||||||
|
client, err := rpc.Dial(bzzconfig.GlobalStoreAPI)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("global store: %v", err)
|
||||||
|
}
|
||||||
|
globalStore := mockrpc.NewGlobalStore(client)
|
||||||
|
// create a node store for this swarm key on global store
|
||||||
|
nodeStore = globalStore.NewNodeStore(common.HexToAddress(bzzconfig.BzzKey))
|
||||||
|
}
|
||||||
|
return swarm.NewSwarm(bzzconfig, nodeStore)
|
||||||
}
|
}
|
||||||
//register within the ethereum node
|
//register within the ethereum node
|
||||||
if err := stack.Register(boot); err != nil {
|
if err := stack.Register(boot); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ type Config struct {
|
||||||
SwapAPI string
|
SwapAPI string
|
||||||
Cors string
|
Cors string
|
||||||
BzzAccount string
|
BzzAccount string
|
||||||
|
GlobalStoreAPI string
|
||||||
privateKey *ecdsa.PrivateKey
|
privateKey *ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue