mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/api: renamed testapi to inspector; Inspector.Has for multiple addrs
This commit is contained in:
parent
9d4f27277e
commit
67c902ee82
6 changed files with 27 additions and 61 deletions
|
|
@ -80,7 +80,6 @@ const (
|
||||||
SWARM_ENV_STORE_CAPACITY = "SWARM_STORE_CAPACITY"
|
SWARM_ENV_STORE_CAPACITY = "SWARM_STORE_CAPACITY"
|
||||||
SWARM_ENV_STORE_CACHE_CAPACITY = "SWARM_STORE_CACHE_CAPACITY"
|
SWARM_ENV_STORE_CACHE_CAPACITY = "SWARM_STORE_CACHE_CAPACITY"
|
||||||
SWARM_ENV_BOOTNODE_MODE = "SWARM_BOOTNODE_MODE"
|
SWARM_ENV_BOOTNODE_MODE = "SWARM_BOOTNODE_MODE"
|
||||||
SWARM_ENV_DEBUG_API = "SWARM_DEBUG_API"
|
|
||||||
SWARM_ACCESS_PASSWORD = "SWARM_ACCESS_PASSWORD"
|
SWARM_ACCESS_PASSWORD = "SWARM_ACCESS_PASSWORD"
|
||||||
SWARM_AUTO_DEFAULTPATH = "SWARM_AUTO_DEFAULTPATH"
|
SWARM_AUTO_DEFAULTPATH = "SWARM_AUTO_DEFAULTPATH"
|
||||||
GETH_ENV_DATADIR = "GETH_DATADIR"
|
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)
|
currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.GlobalIsSet(SwarmDebugAPIFlag.Name) {
|
|
||||||
currentConfig.DebugAPI = ctx.GlobalBool(SwarmDebugAPIFlag.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentConfig
|
return currentConfig
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -380,14 +375,6 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
|
||||||
currentConfig.BootnodeMode = bootnodeMode
|
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
|
return currentConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,8 +176,4 @@ var (
|
||||||
Name: "user",
|
Name: "user",
|
||||||
Usage: "Indicates the user who updates the feed",
|
Usage: "Indicates the user who updates the feed",
|
||||||
}
|
}
|
||||||
SwarmDebugAPIFlag = cli.BoolFlag{
|
|
||||||
Name: "debug-api",
|
|
||||||
Usage: "Make debug APIs available",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -194,8 +194,6 @@ func init() {
|
||||||
SwarmStorePath,
|
SwarmStorePath,
|
||||||
SwarmStoreCapacity,
|
SwarmStoreCapacity,
|
||||||
SwarmStoreCacheCapacity,
|
SwarmStoreCacheCapacity,
|
||||||
// provide debug API endpoints
|
|
||||||
SwarmDebugAPIFlag,
|
|
||||||
}
|
}
|
||||||
rpcFlags := []cli.Flag{
|
rpcFlags := []cli.Flag{
|
||||||
utils.WSEnabledFlag,
|
utils.WSEnabledFlag,
|
||||||
|
|
@ -451,5 +449,5 @@ func setSwarmBootstrapNodes(ctx *cli.Context, cfg *node.Config) {
|
||||||
}
|
}
|
||||||
cfg.P2P.BootstrapNodes = append(cfg.P2P.BootstrapNodes, node)
|
cfg.P2P.BootstrapNodes = append(cfg.P2P.BootstrapNodes, node)
|
||||||
}
|
}
|
||||||
log.Debug("added default swarm bootnodes", "length", len(cfg.P2P.BootstrapNodes))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ type Config struct {
|
||||||
BzzKey string
|
BzzKey string
|
||||||
NodeID string
|
NodeID string
|
||||||
NetworkID uint64
|
NetworkID uint64
|
||||||
DebugAPI bool
|
|
||||||
SwapEnabled bool
|
SwapEnabled bool
|
||||||
SyncEnabled bool
|
SyncEnabled bool
|
||||||
SyncingSkipCheck bool
|
SyncingSkipCheck bool
|
||||||
|
|
@ -91,7 +90,6 @@ func NewConfig() (c *Config) {
|
||||||
EnsAPIs: nil,
|
EnsAPIs: nil,
|
||||||
EnsRoot: ens.TestNetAddress,
|
EnsRoot: ens.TestNetAddress,
|
||||||
NetworkID: network.DefaultNetworkID,
|
NetworkID: network.DefaultNetworkID,
|
||||||
DebugAPI: false,
|
|
||||||
SwapEnabled: false,
|
SwapEnabled: false,
|
||||||
SyncEnabled: true,
|
SyncEnabled: true,
|
||||||
SyncingSkipCheck: false,
|
SyncingSkipCheck: false,
|
||||||
|
|
|
||||||
|
|
@ -19,47 +19,40 @@ package api
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/network"
|
"github.com/ethereum/go-ethereum/swarm/network"
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Control struct {
|
type Inspector struct {
|
||||||
api *API
|
api *API
|
||||||
hive *network.Hive
|
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
|
netStore *storage.NetStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDebugAPI(nstore *storage.NetStore) *DebugAPI {
|
func NewInspector(api *API, hive *network.Hive, netStore *storage.NetStore) *Inspector {
|
||||||
return &DebugAPI{
|
return &Inspector{api, hive, netStore}
|
||||||
netStore: nstore,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasChunk returns true if the underlying datastore has
|
// prints the kademlia table
|
||||||
// the chunk stored with the given address, false if it does not store it
|
func (inspector *Inspector) Hive() string {
|
||||||
func (dapi *DebugAPI) HasChunk(chunkAddress storage.Address) bool {
|
return inspector.hive.String()
|
||||||
return dapi.netStore.HasChunk(context.Background(), chunkAddress)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The description for the DebugAPI to add to the APIs if the flag is set
|
type HasInfo struct {
|
||||||
func GetDebugAPIDesc(nstore *storage.NetStore) rpc.API {
|
Addr string `json:"address"`
|
||||||
return rpc.API{
|
Has bool `json: "has"`
|
||||||
Namespace: "debugapi",
|
|
||||||
Version: "1.0",
|
|
||||||
Service: NewDebugAPI(nstore),
|
|
||||||
Public: false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
|
@ -485,7 +485,7 @@ func (self *Swarm) APIs() []rpc.API {
|
||||||
{
|
{
|
||||||
Namespace: "bzz",
|
Namespace: "bzz",
|
||||||
Version: "3.0",
|
Version: "3.0",
|
||||||
Service: api.NewControl(self.api, self.bzz.Hive),
|
Service: api.NewInspector(self.api, self.bzz.Hive, self.netStore),
|
||||||
Public: false,
|
Public: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -514,12 +514,6 @@ func (self *Swarm) APIs() []rpc.API {
|
||||||
apis = append(apis, self.ps.APIs()...)
|
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
|
return apis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue