all: blidly swap out glog to our log15, logs need rework
This commit is contained in:
@ -35,8 +35,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/internal/debug"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
@ -278,7 +277,7 @@ func bzzd(ctx *cli.Context) error {
|
||||
signal.Notify(sigc, syscall.SIGTERM)
|
||||
defer signal.Stop(sigc)
|
||||
<-sigc
|
||||
glog.V(logger.Info).Infoln("Got sigterm, shutting down...")
|
||||
log.Info(fmt.Sprint("Got sigterm, shutting down..."))
|
||||
stack.Stop()
|
||||
}()
|
||||
networkId := ctx.GlobalUint64(SwarmNetworkIdFlag.Name)
|
||||
@ -308,7 +307,7 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
|
||||
|
||||
bzzconfig, err := bzzapi.NewConfig(bzzdir, chbookaddr, prvkey, ctx.GlobalUint64(SwarmNetworkIdFlag.Name))
|
||||
if err != nil {
|
||||
utils.Fatalf("unable to configure swarm: %v", err)
|
||||
log.Crit(fmt.Sprintf("unable to configure swarm: %v", err))
|
||||
}
|
||||
bzzport := ctx.GlobalString(SwarmPortFlag.Name)
|
||||
if len(bzzport) > 0 {
|
||||
@ -325,13 +324,13 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
|
||||
if len(ethapi) > 0 {
|
||||
client, err = ethclient.Dial(ethapi)
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't connect: %v", err)
|
||||
log.Crit(fmt.Sprintf("Can't connect: %v", err))
|
||||
}
|
||||
}
|
||||
return swarm.NewSwarm(ctx, client, bzzconfig, swapEnabled, syncEnabled, cors)
|
||||
}
|
||||
if err := stack.Register(boot); err != nil {
|
||||
utils.Fatalf("Failed to register the Swarm service: %v", err)
|
||||
log.Crit(fmt.Sprintf("Failed to register the Swarm service: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,11 +338,11 @@ func getAccount(ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey {
|
||||
keyid := ctx.GlobalString(SwarmAccountFlag.Name)
|
||||
|
||||
if keyid == "" {
|
||||
utils.Fatalf("Option %q is required", SwarmAccountFlag.Name)
|
||||
log.Crit(fmt.Sprintf("Option %q is required", SwarmAccountFlag.Name))
|
||||
}
|
||||
// Try to load the arg as a hex key file.
|
||||
if key, err := crypto.LoadECDSA(keyid); err == nil {
|
||||
glog.V(logger.Info).Infof("swarm account key loaded: %#x", crypto.PubkeyToAddress(key.PublicKey))
|
||||
log.Info(fmt.Sprintf("swarm account key loaded: %#x", crypto.PubkeyToAddress(key.PublicKey)))
|
||||
return key
|
||||
}
|
||||
// Otherwise try getting it from the keystore.
|
||||
@ -365,14 +364,14 @@ func decryptStoreAccount(ks *keystore.KeyStore, account string) *ecdsa.PrivateKe
|
||||
err = fmt.Errorf("index %d higher than number of accounts %d", ix, len(accounts))
|
||||
}
|
||||
} else {
|
||||
utils.Fatalf("Can't find swarm account key %s", account)
|
||||
log.Crit(fmt.Sprintf("Can't find swarm account key %s", account))
|
||||
}
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't find swarm account key: %v", err)
|
||||
log.Crit(fmt.Sprintf("Can't find swarm account key: %v", err))
|
||||
}
|
||||
keyjson, err := ioutil.ReadFile(a.URL.Path)
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't load swarm account key: %v", err)
|
||||
log.Crit(fmt.Sprintf("Can't load swarm account key: %v", err))
|
||||
}
|
||||
for i := 1; i <= 3; i++ {
|
||||
passphrase := promptPassphrase(fmt.Sprintf("Unlocking swarm account %s [%d/3]", a.Address.Hex(), i))
|
||||
@ -381,7 +380,7 @@ func decryptStoreAccount(ks *keystore.KeyStore, account string) *ecdsa.PrivateKe
|
||||
return key.PrivateKey
|
||||
}
|
||||
}
|
||||
utils.Fatalf("Can't decrypt swarm account key")
|
||||
log.Crit(fmt.Sprintf("Can't decrypt swarm account key"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -391,7 +390,7 @@ func promptPassphrase(prompt string) string {
|
||||
}
|
||||
password, err := console.Stdin.PromptPassword("Passphrase: ")
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read passphrase: %v", err)
|
||||
log.Crit(fmt.Sprintf("Failed to read passphrase: %v", err))
|
||||
}
|
||||
return password
|
||||
}
|
||||
@ -400,7 +399,7 @@ func injectBootnodes(srv *p2p.Server, nodes []string) {
|
||||
for _, url := range nodes {
|
||||
n, err := discover.ParseNode(url)
|
||||
if err != nil {
|
||||
glog.Errorf("invalid bootnode %q", err)
|
||||
log.Error(fmt.Sprintf("invalid bootnode %q", err))
|
||||
continue
|
||||
}
|
||||
srv.AddPeer(n)
|
||||
|
@ -18,13 +18,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
|
||||
func add(ctx *cli.Context) {
|
||||
@ -35,23 +36,22 @@ func add(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
var (
|
||||
mhash = args[0]
|
||||
path = args[1]
|
||||
hash = args[2]
|
||||
mhash = args[0]
|
||||
path = args[1]
|
||||
hash = args[2]
|
||||
|
||||
ctype string
|
||||
ctype string
|
||||
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
|
||||
mroot manifest
|
||||
mroot manifest
|
||||
)
|
||||
|
||||
|
||||
if len(args) > 3 {
|
||||
ctype = args[3]
|
||||
} else {
|
||||
ctype = mime.TypeByExtension(filepath.Ext(path))
|
||||
}
|
||||
|
||||
newManifest := addEntryToManifest (ctx, mhash, path, hash, ctype)
|
||||
newManifest := addEntryToManifest(ctx, mhash, path, hash, ctype)
|
||||
fmt.Println(newManifest)
|
||||
|
||||
if !wantManifest {
|
||||
@ -70,13 +70,13 @@ func update(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
var (
|
||||
mhash = args[0]
|
||||
path = args[1]
|
||||
hash = args[2]
|
||||
mhash = args[0]
|
||||
path = args[1]
|
||||
hash = args[2]
|
||||
|
||||
ctype string
|
||||
ctype string
|
||||
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
|
||||
mroot manifest
|
||||
mroot manifest
|
||||
)
|
||||
if len(args) > 3 {
|
||||
ctype = args[3]
|
||||
@ -84,7 +84,7 @@ func update(ctx *cli.Context) {
|
||||
ctype = mime.TypeByExtension(filepath.Ext(path))
|
||||
}
|
||||
|
||||
newManifest := updateEntryInManifest (ctx, mhash, path, hash, ctype)
|
||||
newManifest := updateEntryInManifest(ctx, mhash, path, hash, ctype)
|
||||
fmt.Println(newManifest)
|
||||
|
||||
if !wantManifest {
|
||||
@ -102,14 +102,14 @@ func remove(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
var (
|
||||
mhash = args[0]
|
||||
path = args[1]
|
||||
mhash = args[0]
|
||||
path = args[1]
|
||||
|
||||
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
|
||||
mroot manifest
|
||||
mroot manifest
|
||||
)
|
||||
|
||||
newManifest := removeEntryFromManifest (ctx, mhash, path)
|
||||
newManifest := removeEntryFromManifest(ctx, mhash, path)
|
||||
fmt.Println(newManifest)
|
||||
|
||||
if !wantManifest {
|
||||
@ -120,15 +120,15 @@ func remove(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) string {
|
||||
func addEntryToManifest(ctx *cli.Context, mhash, path, hash, ctype string) string {
|
||||
|
||||
var (
|
||||
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
|
||||
client = &client{api: bzzapi}
|
||||
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
|
||||
client = &client{api: bzzapi}
|
||||
longestPathEntry = manifestEntry{
|
||||
Path: "",
|
||||
Hash: "",
|
||||
ContentType: "",
|
||||
ContentType: "",
|
||||
}
|
||||
)
|
||||
|
||||
@ -143,12 +143,11 @@ func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) st
|
||||
log.Fatalln("hash to add is not present:", err)
|
||||
}
|
||||
|
||||
|
||||
// See if we path is in this Manifest or do we have to dig deeper
|
||||
for _, entry := range mroot.Entries {
|
||||
if path == entry.Path {
|
||||
log.Fatal(path, "Already present, not adding anything")
|
||||
}else {
|
||||
} else {
|
||||
if entry.ContentType == "application/bzz-manifest+json" {
|
||||
prfxlen := strings.HasPrefix(path, entry.Path)
|
||||
if prfxlen && len(path) > len(longestPathEntry.Path) {
|
||||
@ -161,7 +160,7 @@ func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) st
|
||||
if longestPathEntry.Path != "" {
|
||||
// Load the child Manifest add the entry there
|
||||
newPath := path[len(longestPathEntry.Path):]
|
||||
newHash := addEntryToManifest (ctx, longestPathEntry.Hash, newPath, hash, ctype)
|
||||
newHash := addEntryToManifest(ctx, longestPathEntry.Hash, newPath, hash, ctype)
|
||||
|
||||
// Replace the hash for parent Manifests
|
||||
newMRoot := manifest{}
|
||||
@ -182,31 +181,28 @@ func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) st
|
||||
mroot.Entries = append(mroot.Entries, newEntry)
|
||||
}
|
||||
|
||||
|
||||
newManifestHash, err := client.uploadManifest(mroot)
|
||||
if err != nil {
|
||||
log.Fatalln("manifest upload failed:", err)
|
||||
}
|
||||
return newManifestHash
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string) string {
|
||||
func updateEntryInManifest(ctx *cli.Context, mhash, path, hash, ctype string) string {
|
||||
|
||||
var (
|
||||
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
|
||||
client = &client{api: bzzapi}
|
||||
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
|
||||
client = &client{api: bzzapi}
|
||||
newEntry = manifestEntry{
|
||||
Path: "",
|
||||
Hash: "",
|
||||
ContentType: "",
|
||||
ContentType: "",
|
||||
}
|
||||
longestPathEntry = manifestEntry{
|
||||
Path: "",
|
||||
Hash: "",
|
||||
ContentType: "",
|
||||
ContentType: "",
|
||||
}
|
||||
)
|
||||
|
||||
@ -217,12 +213,11 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
|
||||
|
||||
//TODO: check if the "hash" with which to update is valid and present in swarm
|
||||
|
||||
|
||||
// See if we path is in this Manifest or do we have to dig deeper
|
||||
for _, entry := range mroot.Entries {
|
||||
if path == entry.Path {
|
||||
newEntry = entry
|
||||
}else {
|
||||
} else {
|
||||
if entry.ContentType == "application/bzz-manifest+json" {
|
||||
prfxlen := strings.HasPrefix(path, entry.Path)
|
||||
if prfxlen && len(path) > len(longestPathEntry.Path) {
|
||||
@ -239,7 +234,7 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
|
||||
if longestPathEntry.Path != "" {
|
||||
// Load the child Manifest add the entry there
|
||||
newPath := path[len(longestPathEntry.Path):]
|
||||
newHash := updateEntryInManifest (ctx, longestPathEntry.Hash, newPath, hash, ctype)
|
||||
newHash := updateEntryInManifest(ctx, longestPathEntry.Hash, newPath, hash, ctype)
|
||||
|
||||
// Replace the hash for parent Manifests
|
||||
newMRoot := manifest{}
|
||||
@ -271,7 +266,6 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
|
||||
mroot = newMRoot
|
||||
}
|
||||
|
||||
|
||||
newManifestHash, err := client.uploadManifest(mroot)
|
||||
if err != nil {
|
||||
log.Fatalln("manifest upload failed:", err)
|
||||
@ -279,20 +273,20 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
|
||||
return newManifestHash
|
||||
}
|
||||
|
||||
func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
|
||||
func removeEntryFromManifest(ctx *cli.Context, mhash, path string) string {
|
||||
|
||||
var (
|
||||
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
|
||||
client = &client{api: bzzapi}
|
||||
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
|
||||
client = &client{api: bzzapi}
|
||||
entryToRemove = manifestEntry{
|
||||
Path: "",
|
||||
Hash: "",
|
||||
ContentType: "",
|
||||
ContentType: "",
|
||||
}
|
||||
longestPathEntry = manifestEntry{
|
||||
Path: "",
|
||||
Hash: "",
|
||||
ContentType: "",
|
||||
ContentType: "",
|
||||
}
|
||||
)
|
||||
|
||||
@ -301,13 +295,11 @@ func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
|
||||
log.Fatalln("manifest download failed:", err)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// See if we path is in this Manifest or do we have to dig deeper
|
||||
for _, entry := range mroot.Entries {
|
||||
if path == entry.Path {
|
||||
entryToRemove = entry
|
||||
}else {
|
||||
} else {
|
||||
if entry.ContentType == "application/bzz-manifest+json" {
|
||||
prfxlen := strings.HasPrefix(path, entry.Path)
|
||||
if prfxlen && len(path) > len(longestPathEntry.Path) {
|
||||
@ -324,7 +316,7 @@ func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
|
||||
if longestPathEntry.Path != "" {
|
||||
// Load the child Manifest remove the entry there
|
||||
newPath := path[len(longestPathEntry.Path):]
|
||||
newHash := removeEntryFromManifest (ctx, longestPathEntry.Hash, newPath)
|
||||
newHash := removeEntryFromManifest(ctx, longestPathEntry.Hash, newPath)
|
||||
|
||||
// Replace the hash for parent Manifests
|
||||
newMRoot := manifest{}
|
||||
@ -348,13 +340,10 @@ func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
|
||||
mroot = newMRoot
|
||||
}
|
||||
|
||||
|
||||
newManifestHash, err := client.uploadManifest(mroot)
|
||||
if err != nil {
|
||||
log.Fatalln("manifest upload failed:", err)
|
||||
}
|
||||
return newManifestHash
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ func (c *client) postRaw(mimetype string, size int64, body io.ReadCloser) (strin
|
||||
func (c *client) downloadManifest(mhash string) (manifest, error) {
|
||||
|
||||
mroot := manifest{}
|
||||
req, err := http.NewRequest("GET", c.api + "/bzzr:/" + mhash, nil)
|
||||
req, err := http.NewRequest("GET", c.api+"/bzzr:/"+mhash, nil)
|
||||
if err != nil {
|
||||
return mroot, err
|
||||
}
|
||||
@ -254,4 +254,4 @@ func (c *client) downloadManifest(mhash string) (manifest, error) {
|
||||
return mroot, fmt.Errorf("Manifest %v is malformed: %v", mhash, err)
|
||||
}
|
||||
return mroot, err
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user