Merge pull request #12 from status-im/light-decrypt

Light decrypt
This commit is contained in:
Jarrad 2016-06-30 15:44:42 +02:00 committed by GitHub
commit 653e5fe406
8 changed files with 209 additions and 148 deletions

188
src/Godeps/Godeps.json generated
View File

@ -22,238 +22,238 @@
},
{
"ImportPath": "github.com/ethereum/go-ethereum/accounts",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/accounts/abi",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/accounts/abi/bind",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/cmd/utils",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/compiler",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/httpclient",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/registrar",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/registrar/ethreg",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core/state",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core/types",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core/vm",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/ecies",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/randentropy",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/secp256k1",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/sha3",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/downloader",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/fetcher",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/filters",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/gasprice",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/ethapi",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/ethdb",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/event",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/event/filter",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/internal/debug",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/jsre",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/les",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/les/flowcontrol",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/light",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/logger",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/logger/glog",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/metrics",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/miner",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/node",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/p2p",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/p2p/discover",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/p2p/nat",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/params",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/pow",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/release",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/rlp",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/rpc",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/trie",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/whisper",
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
"Comment": "v1.0.1-898-g6b7ca77",
"Rev": "6b7ca77653ec3b39c0871b5128d7d14ceb2234d9"
},
{
"ImportPath": "github.com/fatih/color",

View File

@ -15,36 +15,42 @@ import (
)
var (
scryptN = 262144
scryptP = 1
scryptN = 4096
scryptP = 6
)
// createAccount creates an internal geth account
func createAccount(password, keydir string) (string, string, error) {
var sync *[]node.Service
w := true
accman := accounts.NewManager(keydir, scryptN, scryptP, sync)
if currentNode != nil {
// generate the account
account, err := accman.NewAccount(password, w)
if err != nil {
return "", "", errextra.Wrap(err, "Account manager could not create the account")
}
address := fmt.Sprintf("%x", account.Address)
var sync *[]node.Service
w := true
accman := accounts.NewManager(keydir, scryptN, scryptP, sync)
// recover the public key to return
keyContents, err := ioutil.ReadFile(account.File)
if err != nil {
return address, "", errextra.Wrap(err, "Could not load the key contents")
}
key, err := accounts.DecryptKey(keyContents, password)
if err != nil {
return address, "", errextra.Wrap(err, "Could not recover the key")
}
pubKey := common.ToHex(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
// generate the account
account, err := accman.NewAccount(password, w)
if err != nil {
return "", "", errextra.Wrap(err, "Account manager could not create the account")
}
address := fmt.Sprintf("%x", account.Address)
return address, pubKey, nil
// recover the public key to return
keyContents, err := ioutil.ReadFile(account.File)
if err != nil {
return address, "", errextra.Wrap(err, "Could not load the key contents")
}
key, err := accounts.DecryptKey(keyContents, password)
if err != nil {
return address, "", errextra.Wrap(err, "Could not recover the key")
}
pubKey := common.ToHex(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
return address, pubKey, nil
}
return "", "", errors.New("No running node detected for account creation")
}
@ -80,7 +86,7 @@ func createAndStartNode(datadir string) error {
currentNode = MakeNode(datadir)
if currentNode != nil {
StartNode(currentNode)
RunNode(currentNode)
return nil
}

View File

@ -11,13 +11,6 @@ import (
// unlock that account
func TestAccountBindings(t *testing.T) {
// create an account
address, _, err := createAccount("badpassword", ".ethereumtest/keystore")
if err != nil {
fmt.Println(err.Error())
t.Error("Test failed: could not create account")
}
// start geth node and wait for it to initialize
go createAndStartNode(".ethereumtest")
time.Sleep(5 * time.Second)
@ -25,6 +18,13 @@ func TestAccountBindings(t *testing.T) {
t.Error("Test failed: could not start geth node")
}
// create an account
address, _, err := createAccount("badpassword", ".ethereumtest/keystore")
if err != nil {
fmt.Println(err.Error())
t.Error("Test failed: could not create account")
}
// unlock the created account
err = unlockAccount(address, "badpassword", 10)
if err != nil {

View File

@ -7,50 +7,77 @@ import (
"os"
)
//export doCreateAccount
func doCreateAccount(password, keydir *C.char) *C.char {
var emptyError = ""
//export CreateAccount
func CreateAccount(password, keydir *C.char) *C.char {
// This is equivalent to creating an account from the command line,
// just modified to handle the function arg passing
address, pubKey, err := createAccount(C.GoString(password), C.GoString(keydir))
errString := emptyError
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
}
out := AccountInfo{
Address: address,
PubKey: pubKey,
Error: err.Error(),
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
Error: errString,
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
return C.CString(string(outBytes))
}
//export doUnlockAccount
func doUnlockAccount(address, password *C.char, seconds int) *C.char {
//export Login
func Login(address, password *C.char) *C.char {
// Equivalent to unlocking an account briefly, to inject a whisper identity,
// then locking the account again
out := UnlockAccount(address, password, 5)
return out
}
//export UnlockAccount
func UnlockAccount(address, password *C.char, seconds int) *C.char {
// This is equivalent to unlocking an account from the command line,
// just modified to unlock the account for the currently running geth node
// based on the provided arguments
err := unlockAccount(C.GoString(address), C.GoString(password), seconds)
out := JSONError{
Error: err.Error(),
}
errString := emptyError
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
}
out := JSONError{
Error: errString,
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
}
//export doStartNode
func doStartNode(datadir *C.char) *C.char {
//export StartNode
func StartNode(datadir *C.char) *C.char {
// This starts a geth node with the given datadir
err := createAndStartNode(C.GoString(datadir))
out := JSONError{
Error: err.Error(),
}
errString := emptyError
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
}
out := JSONError{
Error: errString,
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
}

View File

@ -27,11 +27,11 @@ const (
)
var (
vString string // Combined textual representation of the version components
vString string // Combined textual representation of the version
rConfig release.Config // Structured version information and release oracle config
currentNode *node.Node
c *cli.Context
accountSync []node.Service
currentNode *node.Node // currently running geth node
c *cli.Context // the CLI context used to start the geth node
accountSync []node.Service // the object used to sync accounts between geth services
)
func main() {
@ -48,6 +48,7 @@ func MakeNode(datadir string) *node.Node {
set.Bool("shh", true, "whisper")
set.Bool("noeth", true, "disable eth")
set.String("datadir", datadir, "data directory for geth")
set.String("logdir", datadir, "log dir for glog")
c = cli.NewContext(nil, set, nil)
// Construct the textual version string from the individual components
@ -60,13 +61,14 @@ func MakeNode(datadir string) *node.Node {
rConfig.Minor = uint32(versionMinor)
rConfig.Patch = uint32(versionPatch)
utils.DebugSetup(c)
currentNode, accountSync = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c)
return currentNode
}
// StartNode starts a geth node entity
func StartNode(nodeIn *node.Node) {
func RunNode(nodeIn *node.Node) {
utils.StartNode(nodeIn)
nodeIn.Wait()
}

View File

@ -40,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/logger"
@ -414,6 +415,13 @@ var (
}
)
// DebugSetup sets up the debugging parameters such that logs can be retrieved when a
// node is started via importing go-ethereum packages, as opposed to starting via CLI
func DebugSetup(ctx *cli.Context) error {
err := debug.Setup(ctx)
return err
}
// MustMakeDataDir retrieves the currently requested data directory, terminating
// if none (or the empty string) is specified. If the node is starting a testnet,
// the a subdirectory of the specified datadir will be used.

View File

@ -84,6 +84,12 @@ func (*HandlerT) GcStats() *debug.GCStats {
return s
}
// SetLogDir overwrites the default log file utilized by glog
func (h *HandlerT) SetLogDir(logDir string) error {
glog.SetLogDir(logDir)
return nil
}
// CpuProfile turns on CPU profiling for nsec seconds and writes
// profile data to file.
func (h *HandlerT) CpuProfile(file string, nsec uint) error {

View File

@ -43,6 +43,10 @@ var (
Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")",
Value: glog.GetTraceLocation(),
}
logdirFlag = cli.StringFlag{
Name: "logdir",
Usage: "Request that glog use the specified log dir location",
}
pprofFlag = cli.BoolFlag{
Name: "pprof",
Usage: "Enable the pprof HTTP server",
@ -73,7 +77,7 @@ var (
// Flags holds all command-line flags required for debugging.
var Flags = []cli.Flag{
verbosityFlag, vmoduleFlag, backtraceAtFlag,
verbosityFlag, vmoduleFlag, logdirFlag, backtraceAtFlag,
pprofFlag, pprofPortFlag,
memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag,
}
@ -81,9 +85,17 @@ var Flags = []cli.Flag{
// Setup initializes profiling and logging based on the CLI flags.
// It should be called as early as possible in the program.
func Setup(ctx *cli.Context) error {
// logging
if logDir := ctx.GlobalString(logdirFlag.Name); logDir != "" {
if err := Handler.SetLogDir(logDir); err != nil {
return err
}
glog.SetToStderr(false)
} else {
glog.SetToStderr(true)
}
glog.CopyStandardLogTo("INFO")
glog.SetToStderr(true)
// profiling, tracing
runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)