mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
cmd/swarm: chunk-explorer query
This commit is contained in:
parent
871740c7b2
commit
5ed219efe2
4 changed files with 128 additions and 0 deletions
58
cmd/swarm/explore.go
Normal file
58
cmd/swarm/explore.go
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
// Copyright 2016 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Command bzzhash computes a swarm tree hash.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||||
|
"gopkg.in/urfave/cli.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var chunkExploreCommand = cli.Command{
|
||||||
|
Action: explore,
|
||||||
|
CustomHelpTemplate: helpTemplate,
|
||||||
|
Name: "explore",
|
||||||
|
Usage: "print all hashes of a file to STDOUT",
|
||||||
|
ArgsUsage: "<file>",
|
||||||
|
Description: "Prints all hashes of a file to STDOUT",
|
||||||
|
}
|
||||||
|
|
||||||
|
func explore(ctx *cli.Context) {
|
||||||
|
args := ctx.Args()
|
||||||
|
if len(args) < 1 {
|
||||||
|
utils.Fatalf("Usage: swarm explore <file name>")
|
||||||
|
}
|
||||||
|
f, err := os.Open(args[0])
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf("Error opening file " + args[1])
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams())
|
||||||
|
_, err = fileStore.StoreToExplore(context.TODO(), f)
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf("%v\n", err)
|
||||||
|
} else {
|
||||||
|
//fmt.Printf("%v\n", addr)
|
||||||
|
fmt.Println("Done.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -142,6 +142,8 @@ func init() {
|
||||||
dbCommand,
|
dbCommand,
|
||||||
// See config.go
|
// See config.go
|
||||||
DumpConfigCommand,
|
DumpConfigCommand,
|
||||||
|
// chunkExploreCommand
|
||||||
|
chunkExploreCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
// append a hidden help subcommand to all commands that have subcommands
|
// append a hidden help subcommand to all commands that have subcommands
|
||||||
|
|
|
||||||
56
cmd/swarm/swarm-smoke/chunkExplorer.go
Normal file
56
cmd/swarm/swarm-smoke/chunkExplorer.go
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
// Copyright 2018 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
addr string
|
||||||
|
)
|
||||||
|
|
||||||
|
func chunkExplorer(c *cli.Context) error {
|
||||||
|
fmt.Println("generate endpoints...")
|
||||||
|
//generateEndpoints(scheme, cluster, appName, from, to)
|
||||||
|
fmt.Println("done.")
|
||||||
|
|
||||||
|
var has bool
|
||||||
|
//for _, e := range endpoints {
|
||||||
|
e := "ws://localhost"
|
||||||
|
fmt.Println("dialing...." + e + ":8546")
|
||||||
|
client, _ := rpc.Dial(e + ":8546")
|
||||||
|
fmt.Println("Trying...." + e)
|
||||||
|
if err := client.Call(&has, "debugapi_hasChunk", addr); err != nil {
|
||||||
|
fmt.Println("err")
|
||||||
|
log.Error("Error requesting hasChunk from endpoint", "endpoint", e, "chunkAddress", addr, "err", err)
|
||||||
|
} else {
|
||||||
|
if has {
|
||||||
|
fmt.Println("has")
|
||||||
|
log.Info("Endpoint "+e+" reports to HAVE chunk", "chunk", addr)
|
||||||
|
} else {
|
||||||
|
fmt.Println("not")
|
||||||
|
log.Debug("Endpoint "+e+" reports to NOT have chunk", "chunk", addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -88,6 +88,12 @@ func main() {
|
||||||
Usage: "http or https",
|
Usage: "http or https",
|
||||||
Destination: &scheme,
|
Destination: &scheme,
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "addr",
|
||||||
|
Value: "<hash>",
|
||||||
|
Usage: "chunk address",
|
||||||
|
Destination: &addr,
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "include-localhost",
|
Name: "include-localhost",
|
||||||
Usage: "whether to include localhost:8500 as an endpoint",
|
Usage: "whether to include localhost:8500 as an endpoint",
|
||||||
|
|
@ -160,6 +166,12 @@ func main() {
|
||||||
Usage: "measure network aggregate capacity",
|
Usage: "measure network aggregate capacity",
|
||||||
Action: wrapCliCommand("sliding-window", false, slidingWindow),
|
Action: wrapCliCommand("sliding-window", false, slidingWindow),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "chunk_explorer",
|
||||||
|
Aliases: []string{"x"},
|
||||||
|
Usage: "query nodes if they are storing a specific chunk (by address)",
|
||||||
|
Action: wrapCliCommand("chunkExplorer", false, chunkExplorer),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(cli.FlagsByName(app.Flags))
|
sort.Sort(cli.FlagsByName(app.Flags))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue