aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/disasm/main.go14
-rw-r--r--cmd/ethtest/main.go7
-rw-r--r--cmd/geth/accountcmd_test.go8
-rw-r--r--cmd/geth/main.go1
-rw-r--r--cmd/swarm/main.go8
-rw-r--r--cmd/swarm/upload.go82
-rw-r--r--cmd/utils/cmd.go3
-rw-r--r--cmd/utils/flags.go31
8 files changed, 89 insertions, 65 deletions
diff --git a/cmd/disasm/main.go b/cmd/disasm/main.go
index d792e8ee5..e6a9a6676 100644
--- a/cmd/disasm/main.go
+++ b/cmd/disasm/main.go
@@ -18,10 +18,10 @@
package main
import (
+ "encoding/hex"
"fmt"
"io/ioutil"
"os"
- "encoding/hex"
"strings"
"github.com/ethereum/go-ethereum/core/vm"
@@ -42,15 +42,19 @@ func main() {
for pc := uint64(0); pc < uint64(len(code)); pc++ {
op := vm.OpCode(code[pc])
- fmt.Printf("%-5d %v", pc, op)
switch op {
case vm.PUSH1, vm.PUSH2, vm.PUSH3, vm.PUSH4, vm.PUSH5, vm.PUSH6, vm.PUSH7, vm.PUSH8, vm.PUSH9, vm.PUSH10, vm.PUSH11, vm.PUSH12, vm.PUSH13, vm.PUSH14, vm.PUSH15, vm.PUSH16, vm.PUSH17, vm.PUSH18, vm.PUSH19, vm.PUSH20, vm.PUSH21, vm.PUSH22, vm.PUSH23, vm.PUSH24, vm.PUSH25, vm.PUSH26, vm.PUSH27, vm.PUSH28, vm.PUSH29, vm.PUSH30, vm.PUSH31, vm.PUSH32:
a := uint64(op) - uint64(vm.PUSH1) + 1
- fmt.Printf(" => %x", code[pc+1:pc+1+a])
-
+ u := pc + 1 + a
+ if uint64(len(code)) <= pc || uint64(len(code)) < u {
+ fmt.Printf("Error: incomplete push instruction at %v\n", pc)
+ return
+ }
+ fmt.Printf("%-5d %v => %x\n", pc, op, code[pc+1:u])
pc += a
+ default:
+ fmt.Printf("%-5d %v\n", pc, op)
}
- fmt.Println()
}
}
diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go
index 7ce663dc0..14b839579 100644
--- a/cmd/ethtest/main.go
+++ b/cmd/ethtest/main.go
@@ -88,12 +88,7 @@ func runTestWithReader(test string, r io.Reader) error {
default:
err = fmt.Errorf("Invalid test type specified: %v", test)
}
-
- if err != nil {
- return err
- }
-
- return nil
+ return err
}
func getFiles(path string) ([]string, error) {
diff --git a/cmd/geth/accountcmd_test.go b/cmd/geth/accountcmd_test.go
index b6abde6d8..113df983e 100644
--- a/cmd/geth/accountcmd_test.go
+++ b/cmd/geth/accountcmd_test.go
@@ -148,7 +148,7 @@ Passphrase: {{.InputLine "foobar"}}
"Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
}
for _, m := range wantMessages {
- if strings.Index(geth.stderrText(), m) == -1 {
+ if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m)
}
}
@@ -193,7 +193,7 @@ Passphrase: {{.InputLine "foobar"}}
"Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
}
for _, m := range wantMessages {
- if strings.Index(geth.stderrText(), m) == -1 {
+ if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m)
}
}
@@ -212,7 +212,7 @@ func TestUnlockFlagPasswordFile(t *testing.T) {
"Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
}
for _, m := range wantMessages {
- if strings.Index(geth.stderrText(), m) == -1 {
+ if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m)
}
}
@@ -260,7 +260,7 @@ In order to avoid this warning, you need to remove the following duplicate key f
"Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
}
for _, m := range wantMessages {
- if strings.Index(geth.stderrText(), m) == -1 {
+ if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m)
}
}
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 332e1ae8d..766e49f49 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -168,7 +168,6 @@ func init() {
}
app.After = func(ctx *cli.Context) error {
- logger.Flush()
debug.Exit()
console.Stdin.Close() // Resets terminal mode.
return nil
diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go
index 954ad3b13..87e21fb7f 100644
--- a/cmd/swarm/main.go
+++ b/cmd/swarm/main.go
@@ -114,7 +114,7 @@ var (
}
CorsStringFlag = cli.StringFlag{
Name: "corsdomain",
- Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied seperated by a ',')",
+ Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied separated by a ',')",
}
)
@@ -129,7 +129,7 @@ func init() {
app.HideVersion = true // we have a command to print the version
app.Copyright = "Copyright 2013-2016 The go-ethereum Authors"
app.Commands = []cli.Command{
- cli.Command{
+ {
Action: version,
Name: "version",
Usage: "Print version numbers",
@@ -138,7 +138,7 @@ func init() {
The output of this command is supposed to be machine-readable.
`,
},
- cli.Command{
+ {
Action: upload,
Name: "up",
Usage: "upload a file or directory to swarm using the HTTP API",
@@ -147,7 +147,7 @@ The output of this command is supposed to be machine-readable.
"upload a file or directory to swarm using the HTTP API and prints the root hash",
`,
},
- cli.Command{
+ {
Action: hash,
Name: "hash",
Usage: "print the swarm hash of a file or directory",
diff --git a/cmd/swarm/upload.go b/cmd/swarm/upload.go
index d048bbc40..d8039d45b 100644
--- a/cmd/swarm/upload.go
+++ b/cmd/swarm/upload.go
@@ -50,8 +50,6 @@ func upload(ctx *cli.Context) {
var (
file = args[0]
client = &client{api: bzzapi}
- mroot manifest
- entry manifestEntry
)
fi, err := os.Stat(expandPath(file))
if err != nil {
@@ -61,14 +59,21 @@ func upload(ctx *cli.Context) {
if !recursive {
log.Fatal("argument is a directory and recursive upload is disabled")
}
- mroot, err = client.uploadDirectory(file, defaultPath)
- } else {
- entry, err = client.uploadFile(file, fi)
- mroot = manifest{[]manifestEntry{entry}}
+ if !wantManifest {
+ log.Fatal("manifest is required for directory uploads")
+ }
+ mhash, err := client.uploadDirectory(file, defaultPath)
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Println(mhash)
+ return
}
+ entry, err := client.uploadFile(file, fi)
if err != nil {
log.Fatalln("upload failed:", err)
}
+ mroot := manifest{[]manifestEntry{entry}}
if !wantManifest {
// Print the manifest. This is the only output to stdout.
mrootJSON, _ := json.MarshalIndent(mroot, "", " ")
@@ -123,43 +128,43 @@ type manifest struct {
Entries []manifestEntry `json:"entries,omitempty"`
}
-func (c *client) uploadFile(file string, fi os.FileInfo) (manifestEntry, error) {
- hash, err := c.uploadFileContent(file, fi)
- m := manifestEntry{
- Hash: hash,
- ContentType: mime.TypeByExtension(filepath.Ext(fi.Name())),
+func (c *client) uploadDirectory(dir string, defaultPath string) (string, error) {
+ mhash, err := c.postRaw("application/json", 2, ioutil.NopCloser(bytes.NewReader([]byte("{}"))))
+ if err != nil {
+ return "", fmt.Errorf("failed to upload empty manifest")
}
- return m, err
-}
-
-func (c *client) uploadDirectory(dir string, defaultPath string) (manifest, error) {
- dirm := manifest{}
if len(defaultPath) > 0 {
fi, err := os.Stat(defaultPath)
if err != nil {
- log.Fatal(err)
+ return "", err
}
- entry, err := c.uploadFile(defaultPath, fi)
+ mhash, err = c.uploadToManifest(mhash, "", defaultPath, fi)
if err != nil {
- log.Fatal(err)
+ return "", err
}
- entry.Path = ""
- dirm.Entries = append(dirm.Entries, entry)
}
prefix := filepath.ToSlash(filepath.Clean(dir)) + "/"
- err := filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
+ err = filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
if err != nil || fi.IsDir() {
return err
}
if !strings.HasPrefix(path, dir) {
return fmt.Errorf("path %s outside directory %s", path, dir)
}
- entry, err := c.uploadFile(path, fi)
- entry.Path = strings.TrimPrefix(filepath.ToSlash(filepath.Clean(path)), prefix)
- dirm.Entries = append(dirm.Entries, entry)
+ uripath := strings.TrimPrefix(filepath.ToSlash(filepath.Clean(path)), prefix)
+ mhash, err = c.uploadToManifest(mhash, uripath, path, fi)
return err
})
- return dirm, err
+ return mhash, err
+}
+
+func (c *client) uploadFile(file string, fi os.FileInfo) (manifestEntry, error) {
+ hash, err := c.uploadFileContent(file, fi)
+ m := manifestEntry{
+ Hash: hash,
+ ContentType: mime.TypeByExtension(filepath.Ext(fi.Name())),
+ }
+ return m, err
}
func (c *client) uploadFileContent(file string, fi os.FileInfo) (string, error) {
@@ -181,6 +186,31 @@ func (c *client) uploadManifest(m manifest) (string, error) {
return c.postRaw("application/json", int64(len(jsm)), ioutil.NopCloser(bytes.NewReader(jsm)))
}
+func (c *client) uploadToManifest(mhash string, path string, fpath string, fi os.FileInfo) (string, error) {
+ fd, err := os.Open(fpath)
+ if err != nil {
+ return "", err
+ }
+ defer fd.Close()
+ log.Printf("uploading file %s (%d bytes) and adding path %v", fpath, fi.Size(), path)
+ req, err := http.NewRequest("PUT", c.api+"/bzz:/"+mhash+"/"+path, fd)
+ if err != nil {
+ return "", err
+ }
+ req.Header.Set("content-type", mime.TypeByExtension(filepath.Ext(fi.Name())))
+ req.ContentLength = fi.Size()
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return "", err
+ }
+ defer resp.Body.Close()
+ if resp.StatusCode >= 400 {
+ return "", fmt.Errorf("bad status: %s", resp.Status)
+ }
+ content, err := ioutil.ReadAll(resp.Body)
+ return string(content), err
+}
+
func (c *client) postRaw(mimetype string, size int64, body io.ReadCloser) (string, error) {
req, err := http.NewRequest("POST", c.api+"/bzzr:/", body)
if err != nil {
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index a56507e4d..8666f3775 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -67,7 +67,6 @@ func Fatalf(format string, args ...interface{}) {
}
}
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
- logger.Flush()
os.Exit(1)
}
@@ -95,7 +94,7 @@ func StartNode(stack *node.Node) {
func FormatTransactionData(data string) []byte {
d := common.StringToByteFunc(data, func(s string) (ret []byte) {
- slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
+ slice := regexp.MustCompile(`\n|\s`).Split(s, 1000000000)
for _, dataItem := range slice {
d := common.FormatData(dataItem)
ret = append(ret, d...)
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index c5f38fe93..18745e557 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -337,10 +337,10 @@ var (
Usage: "Network listening port",
Value: 30303,
}
- BootnodesFlag = cli.StringFlag{
+ BootnodesFlag = cli.StringSliceFlag{
Name: "bootnodes",
Usage: "Comma separated enode URLs for P2P discovery bootstrap",
- Value: "",
+ Value: nil,
}
NodeKeyFileFlag = cli.StringFlag{
Name: "nodekey",
@@ -485,17 +485,15 @@ func makeNodeUserIdent(ctx *cli.Context) string {
// MakeBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func MakeBootstrapNodes(ctx *cli.Context) []*discover.Node {
- // Return pre-configured nodes if none were manually requested
- if !ctx.GlobalIsSet(BootnodesFlag.Name) {
- if ctx.GlobalBool(TestNetFlag.Name) {
- return params.TestnetBootnodes
- }
- return params.MainnetBootnodes
+ urls := params.MainnetBootnodes
+ if ctx.GlobalIsSet(BootnodesFlag.Name) {
+ urls = ctx.GlobalStringSlice(BootnodesFlag.Name)
+ } else if ctx.GlobalBool(TestNetFlag.Name) {
+ urls = params.TestnetBootnodes
}
- // Otherwise parse and use the CLI bootstrap nodes
- bootnodes := []*discover.Node{}
- for _, url := range strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",") {
+ bootnodes := make([]*discover.Node, 0, len(urls))
+ for _, url := range urls {
node, err := discover.ParseNode(url)
if err != nil {
glog.V(logger.Error).Infof("Bootstrap URL %s: %v\n", url, err)
@@ -509,14 +507,13 @@ func MakeBootstrapNodes(ctx *cli.Context) []*discover.Node {
// MakeBootstrapNodesV5 creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func MakeBootstrapNodesV5(ctx *cli.Context) []*discv5.Node {
- // Return pre-configured nodes if none were manually requested
- if !ctx.GlobalIsSet(BootnodesFlag.Name) {
- return params.DiscoveryV5Bootnodes
+ urls := params.DiscoveryV5Bootnodes
+ if ctx.GlobalIsSet(BootnodesFlag.Name) {
+ urls = ctx.GlobalStringSlice(BootnodesFlag.Name)
}
- // Otherwise parse and use the CLI bootstrap nodes
- bootnodes := []*discv5.Node{}
- for _, url := range strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",") {
+ bootnodes := make([]*discv5.Node, 0, len(urls))
+ for _, url := range urls {
node, err := discv5.ParseNode(url)
if err != nil {
glog.V(logger.Error).Infof("Bootstrap URL %s: %v\n", url, err)