From 67c902ee82cba159b0df5799b53e960c7d6f8de5 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Mon, 4 Feb 2019 12:46:10 -0500 Subject: [PATCH] swarm/api: renamed testapi to inspector; Inspector.Has for multiple addrs --- cmd/swarm/config.go | 13 ------ cmd/swarm/flags.go | 4 -- cmd/swarm/main.go | 4 +- swarm/api/config.go | 2 - swarm/api/{testapi.go => inspector.go} | 57 +++++++++++--------------- swarm/swarm.go | 8 +--- 6 files changed, 27 insertions(+), 61 deletions(-) rename swarm/api/{testapi.go => inspector.go} (50%) diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go index d502a532e6..0203a67984 100644 --- a/cmd/swarm/config.go +++ b/cmd/swarm/config.go @@ -80,7 +80,6 @@ const ( SWARM_ENV_STORE_CAPACITY = "SWARM_STORE_CAPACITY" SWARM_ENV_STORE_CACHE_CAPACITY = "SWARM_STORE_CACHE_CAPACITY" SWARM_ENV_BOOTNODE_MODE = "SWARM_BOOTNODE_MODE" - SWARM_ENV_DEBUG_API = "SWARM_DEBUG_API" SWARM_ACCESS_PASSWORD = "SWARM_ACCESS_PASSWORD" SWARM_AUTO_DEFAULTPATH = "SWARM_AUTO_DEFAULTPATH" GETH_ENV_DATADIR = "GETH_DATADIR" @@ -263,10 +262,6 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name) } - if ctx.GlobalIsSet(SwarmDebugAPIFlag.Name) { - currentConfig.DebugAPI = ctx.GlobalBool(SwarmDebugAPIFlag.Name) - } - return currentConfig } @@ -380,14 +375,6 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) { currentConfig.BootnodeMode = bootnodeMode } - if debugAPIenable := os.Getenv(SWARM_ENV_DEBUG_API); debugAPIenable != "" { - debug, err := strconv.ParseBool(debugAPIenable) - if err != nil { - utils.Fatalf("invalid environment variable %s: %v", SWARM_ENV_DEBUG_API, err) - } - currentConfig.DebugAPI = debug - } - return currentConfig } diff --git a/cmd/swarm/flags.go b/cmd/swarm/flags.go index 0ccdb1873a..4c186cc310 100644 --- a/cmd/swarm/flags.go +++ b/cmd/swarm/flags.go @@ -176,8 +176,4 @@ var ( Name: "user", Usage: "Indicates the user who updates the feed", } - SwarmDebugAPIFlag = cli.BoolFlag{ - Name: "debug-api", - Usage: "Make debug APIs available", - } ) diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index ae029372fe..f6083e33df 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -194,8 +194,6 @@ func init() { SwarmStorePath, SwarmStoreCapacity, SwarmStoreCacheCapacity, - // provide debug API endpoints - SwarmDebugAPIFlag, } rpcFlags := []cli.Flag{ utils.WSEnabledFlag, @@ -451,5 +449,5 @@ func setSwarmBootstrapNodes(ctx *cli.Context, cfg *node.Config) { } cfg.P2P.BootstrapNodes = append(cfg.P2P.BootstrapNodes, node) } - log.Debug("added default swarm bootnodes", "length", len(cfg.P2P.BootstrapNodes)) + } diff --git a/swarm/api/config.go b/swarm/api/config.go index 5c48664020..54dd67ba83 100644 --- a/swarm/api/config.go +++ b/swarm/api/config.go @@ -60,7 +60,6 @@ type Config struct { BzzKey string NodeID string NetworkID uint64 - DebugAPI bool SwapEnabled bool SyncEnabled bool SyncingSkipCheck bool @@ -91,7 +90,6 @@ func NewConfig() (c *Config) { EnsAPIs: nil, EnsRoot: ens.TestNetAddress, NetworkID: network.DefaultNetworkID, - DebugAPI: false, SwapEnabled: false, SyncEnabled: true, SyncingSkipCheck: false, diff --git a/swarm/api/testapi.go b/swarm/api/inspector.go similarity index 50% rename from swarm/api/testapi.go rename to swarm/api/inspector.go index 6f412591c8..4477d4435c 100644 --- a/swarm/api/testapi.go +++ b/swarm/api/inspector.go @@ -19,47 +19,40 @@ package api import ( "context" - "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/swarm/network" "github.com/ethereum/go-ethereum/swarm/storage" ) -type Control struct { - api *API - hive *network.Hive -} - -func NewControl(api *API, hive *network.Hive) *Control { - return &Control{api, hive} -} - -func (c *Control) Hive() string { - return c.hive.String() -} - -// DebugAPI is a umbrella structure to provide additional debug API endpoints -type DebugAPI struct { +type Inspector struct { + api *API + hive *network.Hive netStore *storage.NetStore } -func NewDebugAPI(nstore *storage.NetStore) *DebugAPI { - return &DebugAPI{ - netStore: nstore, - } +func NewInspector(api *API, hive *network.Hive, netStore *storage.NetStore) *Inspector { + return &Inspector{api, hive, netStore} } -// HasChunk returns true if the underlying datastore has -// the chunk stored with the given address, false if it does not store it -func (dapi *DebugAPI) HasChunk(chunkAddress storage.Address) bool { - return dapi.netStore.HasChunk(context.Background(), chunkAddress) +// prints the kademlia table +func (inspector *Inspector) Hive() string { + return inspector.hive.String() } -// The description for the DebugAPI to add to the APIs if the flag is set -func GetDebugAPIDesc(nstore *storage.NetStore) rpc.API { - return rpc.API{ - Namespace: "debugapi", - Version: "1.0", - Service: NewDebugAPI(nstore), - Public: false, - } +type HasInfo struct { + Addr string `json:"address"` + Has bool `json: "has"` +} + +// HasChunk returns an array of HasInfo structs, +// the bool indicating if the underlying datastore has +// the chunk stored with the given address (true), or not (false) +func (inspector *Inspector) Has(chunkAddresses []storage.Address) []HasInfo { + results := make([]HasInfo, 0) + for _, addr := range chunkAddresses { + res := HasInfo{} + res.Addr = addr.String() + res.Has = inspector.netStore.Has(context.Background(), addr) + results = append(results, res) + } + return results } diff --git a/swarm/swarm.go b/swarm/swarm.go index 58878989a8..cba4e73efb 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -485,7 +485,7 @@ func (self *Swarm) APIs() []rpc.API { { Namespace: "bzz", Version: "3.0", - Service: api.NewControl(self.api, self.bzz.Hive), + Service: api.NewInspector(self.api, self.bzz.Hive, self.netStore), Public: false, }, { @@ -514,12 +514,6 @@ func (self *Swarm) APIs() []rpc.API { apis = append(apis, self.ps.APIs()...) } - // Only provide certain endpoints if the `debug-api` flag is set - if self.config.DebugAPI { - log.Info("Running node with debug APIs attached") - apis = append(apis, api.GetDebugAPIDesc(self.netStore)) - } - return apis }