swarm/api: renamed testapi to inspector; Inspector.Has for multiple addrs

This commit is contained in:
Fabio Barone 2019-02-04 12:46:10 -05:00
parent 9d4f27277e
commit 67c902ee82
6 changed files with 27 additions and 61 deletions

View file

@ -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
}

View file

@ -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",
}
)

View file

@ -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))
}

View file

@ -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,

View file

@ -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 {
type Inspector 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 {
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
}

View file

@ -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
}