ethlog => logger
This commit is contained in:
parent
fd9da72536
commit
b1c247231b
|
@ -10,12 +10,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var poollogger = ethlog.NewLogger("BPOOL")
|
var poollogger = logger.NewLogger("BPOOL")
|
||||||
|
|
||||||
type block struct {
|
type block struct {
|
||||||
from *Peer
|
from *Peer
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var chainlogger = ethlog.NewLogger("CHAIN")
|
var chainlogger = logger.NewLogger("CHAIN")
|
||||||
|
|
||||||
type ChainManager struct {
|
type ChainManager struct {
|
||||||
Ethereum EthManager
|
Ethereum EthManager
|
||||||
|
|
|
@ -7,12 +7,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/obscuren/sha3"
|
"github.com/obscuren/sha3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var powlogger = ethlog.NewLogger("POW")
|
var powlogger = logger.NewLogger("POW")
|
||||||
|
|
||||||
type PoW interface {
|
type PoW interface {
|
||||||
Search(block *Block, stop <-chan struct{}) []byte
|
Search(block *Block, stop <-chan struct{}) []byte
|
||||||
|
|
|
@ -10,14 +10,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethstate"
|
"github.com/ethereum/go-ethereum/ethstate"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var statelogger = ethlog.NewLogger("BLOCK")
|
var statelogger = logger.NewLogger("BLOCK")
|
||||||
|
|
||||||
type Peer interface {
|
type Peer interface {
|
||||||
Inbound() bool
|
Inbound() bool
|
||||||
|
|
|
@ -7,12 +7,12 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethstate"
|
"github.com/ethereum/go-ethereum/ethstate"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var txplogger = ethlog.NewLogger("TXP")
|
var txplogger = logger.NewLogger("TXP")
|
||||||
|
|
||||||
const txPoolQueueSize = 50
|
const txPoolQueueSize = 50
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,11 @@ func InitJsConsole(ethereum *eth.Ethereum) {
|
||||||
func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
|
func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
|
||||||
file, err := os.Open(InputFile)
|
file, err := os.Open(InputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalln(err)
|
clilogger.Fatalln(err)
|
||||||
}
|
}
|
||||||
content, err := ioutil.ReadAll(file)
|
content, err := ioutil.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalln(err)
|
clilogger.Fatalln(err)
|
||||||
}
|
}
|
||||||
re := javascript.NewJSRE(ethereum)
|
re := javascript.NewJSRE(ethereum)
|
||||||
utils.RegisterInterrupt(func(os.Signal) {
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ func Init() {
|
||||||
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
||||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
||||||
flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
||||||
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
||||||
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
|
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
|
||||||
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
|
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
|
||||||
|
|
|
@ -23,9 +23,10 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
|
"github.com/ethgo.old/ethlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -33,7 +34,7 @@ const (
|
||||||
Version = "0.7.0"
|
Version = "0.7.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("CLI")
|
var clilogger = logger.NewLogger("CLI")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -25,12 +25,12 @@ import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/javascript"
|
"github.com/ethereum/go-ethereum/javascript"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("REPL")
|
var repllogger = logger.NewLogger("REPL")
|
||||||
|
|
||||||
type Repl interface {
|
type Repl interface {
|
||||||
Start()
|
Start()
|
||||||
|
@ -59,7 +59,7 @@ func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
|
||||||
func (self *JSRepl) Start() {
|
func (self *JSRepl) Start() {
|
||||||
if !self.running {
|
if !self.running {
|
||||||
self.running = true
|
self.running = true
|
||||||
logger.Infoln("init JS Console")
|
repllogger.Infoln("init JS Console")
|
||||||
reader := bufio.NewReader(self.history)
|
reader := bufio.NewReader(self.history)
|
||||||
for {
|
for {
|
||||||
line, err := reader.ReadString('\n')
|
line, err := reader.ReadString('\n')
|
||||||
|
@ -80,7 +80,7 @@ func (self *JSRepl) Stop() {
|
||||||
if self.running {
|
if self.running {
|
||||||
self.running = false
|
self.running = false
|
||||||
self.re.Stop()
|
self.re.Stop()
|
||||||
logger.Infoln("exit JS Console")
|
repllogger.Infoln("exit JS Console")
|
||||||
self.history.Close()
|
self.history.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethpipe"
|
"github.com/ethereum/go-ethereum/ethpipe"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ type plugin struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogPrint writes to the GUI log.
|
// LogPrint writes to the GUI log.
|
||||||
func (gui *Gui) LogPrint(level ethlog.LogLevel, msg string) {
|
func (gui *Gui) LogPrint(level logger.LogLevel, msg string) {
|
||||||
/*
|
/*
|
||||||
str := strings.TrimRight(s, "\n")
|
str := strings.TrimRight(s, "\n")
|
||||||
lines := strings.Split(str, "\n")
|
lines := strings.Split(str, "\n")
|
||||||
|
@ -74,14 +74,14 @@ func (gui *Gui) ToggleTurboMining() {
|
||||||
gui.miner.ToggleTurbo()
|
gui.miner.ToggleTurbo()
|
||||||
}
|
}
|
||||||
|
|
||||||
// functions that allow Gui to implement interface ethlog.LogSystem
|
// functions that allow Gui to implement interface guilogger.LogSystem
|
||||||
func (gui *Gui) SetLogLevel(level ethlog.LogLevel) {
|
func (gui *Gui) SetLogLevel(level logger.LogLevel) {
|
||||||
gui.logLevel = level
|
gui.logLevel = level
|
||||||
gui.stdLog.SetLogLevel(level)
|
gui.stdLog.SetLogLevel(level)
|
||||||
gui.config.Save("loglevel", level)
|
gui.config.Save("loglevel", level)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) GetLogLevel() ethlog.LogLevel {
|
func (gui *Gui) GetLogLevel() logger.LogLevel {
|
||||||
return gui.logLevel
|
return gui.logLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ func (self *Gui) DumpState(hash, path string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if block == nil {
|
if block == nil {
|
||||||
logger.Infof("block err: not found %s\n", hash)
|
guilogger.Infof("block err: not found %s\n", hash)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,12 +128,12 @@ func (self *Gui) DumpState(hash, path string) {
|
||||||
|
|
||||||
file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm)
|
file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Infoln("dump err: ", err)
|
guilogger.Infoln("dump err: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
logger.Infof("dumped state (%s) to %s\n", hash, path)
|
guilogger.Infof("dumped state (%s) to %s\n", hash, path)
|
||||||
|
|
||||||
file.Write(stateDump)
|
file.Write(stateDump)
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (app *ExtApplication) run() {
|
||||||
|
|
||||||
err := app.container.Create()
|
err := app.container.Create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln(err)
|
guilogger.Errorln(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"bitbucket.org/kardianos/osext"
|
"bitbucket.org/kardianos/osext"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -117,7 +116,7 @@ func Init() {
|
||||||
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
||||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
||||||
flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
flag.IntVar(&LogLevel, "loglevel", int(repllogger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
||||||
|
|
||||||
flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory")
|
flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory")
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ import (
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethminer"
|
"github.com/ethereum/go-ethereum/ethminer"
|
||||||
"github.com/ethereum/go-ethereum/ethpipe"
|
"github.com/ethereum/go-ethereum/ethpipe"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"gopkg.in/qml.v1"
|
"gopkg.in/qml.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func LoadExtension(path string) (uintptr, error) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("GUI")
|
var guilogger = logger.NewLogger("GUI")
|
||||||
|
|
||||||
type Gui struct {
|
type Gui struct {
|
||||||
// The main application window
|
// The main application window
|
||||||
|
@ -81,7 +81,7 @@ type Gui struct {
|
||||||
|
|
||||||
txDb *ethdb.LDBDatabase
|
txDb *ethdb.LDBDatabase
|
||||||
|
|
||||||
logLevel ethlog.LogLevel
|
logLevel logger.LogLevel
|
||||||
open bool
|
open bool
|
||||||
|
|
||||||
pipe *ethpipe.JSPipe
|
pipe *ethpipe.JSPipe
|
||||||
|
@ -93,7 +93,7 @@ type Gui struct {
|
||||||
plugins map[string]plugin
|
plugins map[string]plugin
|
||||||
|
|
||||||
miner *ethminer.Miner
|
miner *ethminer.Miner
|
||||||
stdLog ethlog.LogSystem
|
stdLog logger.LogSystem
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GUI, but doesn't start it
|
// Create GUI, but doesn't start it
|
||||||
|
@ -104,7 +104,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
|
||||||
}
|
}
|
||||||
|
|
||||||
pipe := ethpipe.NewJSPipe(ethereum)
|
pipe := ethpipe.NewJSPipe(ethereum)
|
||||||
gui := &Gui{eth: ethereum, txDb: db, pipe: pipe, logLevel: ethlog.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config, plugins: make(map[string]plugin)}
|
gui := &Gui{eth: ethereum, txDb: db, pipe: pipe, logLevel: logger.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config, plugins: make(map[string]plugin)}
|
||||||
data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json"))
|
data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json"))
|
||||||
json.Unmarshal([]byte(data), &gui.plugins)
|
json.Unmarshal([]byte(data), &gui.plugins)
|
||||||
|
|
||||||
|
@ -155,36 +155,36 @@ func (gui *Gui) Start(assetPath string) {
|
||||||
addlog = true
|
addlog = true
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err)
|
guilogger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err)
|
||||||
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infoln("Starting GUI")
|
guilogger.Infoln("Starting GUI")
|
||||||
gui.open = true
|
gui.open = true
|
||||||
win.Show()
|
win.Show()
|
||||||
|
|
||||||
// only add the gui logger after window is shown otherwise slider wont be shown
|
// only add the gui guilogger after window is shown otherwise slider wont be shown
|
||||||
if addlog {
|
if addlog {
|
||||||
ethlog.AddLogSystem(gui)
|
logger.AddLogSystem(gui)
|
||||||
}
|
}
|
||||||
win.Wait()
|
win.Wait()
|
||||||
|
|
||||||
// need to silence gui logger after window closed otherwise logsystem hangs (but do not save loglevel)
|
// need to silence gui guilogger after window closed otherwise logsystem hangs (but do not save loglevel)
|
||||||
gui.logLevel = ethlog.Silence
|
gui.logLevel = logger.Silence
|
||||||
gui.open = false
|
gui.open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Stop() {
|
func (gui *Gui) Stop() {
|
||||||
if gui.open {
|
if gui.open {
|
||||||
gui.logLevel = ethlog.Silence
|
gui.logLevel = logger.Silence
|
||||||
gui.open = false
|
gui.open = false
|
||||||
gui.win.Hide()
|
gui.win.Hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.uiLib.jsEngine.Stop()
|
gui.uiLib.jsEngine.Stop()
|
||||||
|
|
||||||
logger.Infoln("Stopped")
|
guilogger.Infoln("Stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
||||||
|
@ -229,17 +229,17 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window {
|
||||||
func (gui *Gui) ImportAndSetPrivKey(secret string) bool {
|
func (gui *Gui) ImportAndSetPrivKey(secret string) bool {
|
||||||
err := gui.eth.KeyManager().InitFromString(gui.Session, 0, secret)
|
err := gui.eth.KeyManager().InitFromString(gui.Session, 0, secret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("unable to import: ", err)
|
guilogger.Errorln("unable to import: ", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
logger.Errorln("successfully imported: ", err)
|
guilogger.Errorln("successfully imported: ", err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) CreateAndSetPrivKey() (string, string, string, string) {
|
func (gui *Gui) CreateAndSetPrivKey() (string, string, string, string) {
|
||||||
err := gui.eth.KeyManager().Init(gui.Session, 0, true)
|
err := gui.eth.KeyManager().Init(gui.Session, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("unable to create key: ", err)
|
guilogger.Errorln("unable to create key: ", err)
|
||||||
return "", "", "", ""
|
return "", "", "", ""
|
||||||
}
|
}
|
||||||
return gui.eth.KeyManager().KeyPair().AsStrings()
|
return gui.eth.KeyManager().KeyPair().AsStrings()
|
||||||
|
@ -387,7 +387,7 @@ func (gui *Gui) update() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for _, plugin := range gui.plugins {
|
for _, plugin := range gui.plugins {
|
||||||
logger.Infoln("Loading plugin ", plugin.Name)
|
guilogger.Infoln("Loading plugin ", plugin.Name)
|
||||||
|
|
||||||
gui.win.Root().Call("addPlugin", plugin.Path, "")
|
gui.win.Root().Call("addPlugin", plugin.Path, "")
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,12 +98,12 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) {
|
||||||
|
|
||||||
app.watcher, err = fsnotify.NewWatcher()
|
app.watcher, err = fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Infoln("Could not create new auto-reload watcher:", err)
|
guilogger.Infoln("Could not create new auto-reload watcher:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = app.watcher.Watch(app.RootFolder())
|
err = app.watcher.Watch(app.RootFolder())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Infoln("Could not start auto-reload watcher:", err)
|
guilogger.Infoln("Could not start auto-reload watcher:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, folder := range app.RecursiveFolders() {
|
for _, folder := range app.RecursiveFolders() {
|
||||||
|
@ -119,11 +119,11 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) {
|
||||||
app.watcher.Close()
|
app.watcher.Close()
|
||||||
break out
|
break out
|
||||||
case <-app.watcher.Event:
|
case <-app.watcher.Event:
|
||||||
//logger.Debugln("Got event:", ev)
|
//guilogger.Debugln("Got event:", ev)
|
||||||
app.webView.Call("reload")
|
app.webView.Call("reload")
|
||||||
case err := <-app.watcher.Error:
|
case err := <-app.watcher.Error:
|
||||||
// TODO: Do something here
|
// TODO: Do something here
|
||||||
logger.Infoln("Watcher error:", err)
|
guilogger.Infoln("Watcher error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"gopkg.in/qml.v1"
|
"gopkg.in/qml.v1"
|
||||||
)
|
)
|
||||||
|
@ -108,5 +108,5 @@ func main() {
|
||||||
}
|
}
|
||||||
// this blocks the thread
|
// this blocks the thread
|
||||||
ethereum.WaitForShutdown()
|
ethereum.WaitForShutdown()
|
||||||
ethlog.Flush()
|
logger.Flush()
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (app *QmlApplication) Create() error {
|
||||||
|
|
||||||
component, err := app.engine.LoadFile(path)
|
component, err := app.engine.LoadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnln(err)
|
guilogger.Warnln(err)
|
||||||
}
|
}
|
||||||
app.win = component.CreateWindow(nil)
|
app.win = component.CreateWindow(nil)
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) Notef(args []interface{}) {
|
func (self *UiLib) Notef(args []interface{}) {
|
||||||
logger.Infoln(args...)
|
guilogger.Infoln(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) LookupDomain(domain string) string {
|
func (self *UiLib) LookupDomain(domain string) string {
|
||||||
|
@ -158,7 +158,7 @@ func (ui *UiLib) OpenBrowser() {
|
||||||
func (ui *UiLib) Muted(content string) {
|
func (ui *UiLib) Muted(content string) {
|
||||||
component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
|
component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Debugln(err)
|
guilogger.Debugln(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
38
ethereum.go
38
ethereum.go
|
@ -16,11 +16,11 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethstate"
|
"github.com/ethereum/go-ethereum/ethstate"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ const (
|
||||||
seedNodeAddress = "poc-7.ethdev.com:30303"
|
seedNodeAddress = "poc-7.ethdev.com:30303"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ethlogger = ethlog.NewLogger("SERV")
|
var loggerger = logger.NewLogger("SERV")
|
||||||
|
|
||||||
func eachPeer(peers *list.List, callback func(*Peer, *list.Element)) {
|
func eachPeer(peers *list.List, callback func(*Peer, *list.Element)) {
|
||||||
// Loop thru the peers and close them (if we had them)
|
// Loop thru the peers and close them (if we had them)
|
||||||
|
@ -104,7 +104,7 @@ func New(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager
|
||||||
if usePnp {
|
if usePnp {
|
||||||
nat, err = Discover()
|
nat, err = Discover()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethlogger.Debugln("UPnP failed", err)
|
loggerger.Debugln("UPnP failed", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func (s *Ethereum) AddPeer(conn net.Conn) {
|
||||||
if s.peers.Len() < s.MaxPeers {
|
if s.peers.Len() < s.MaxPeers {
|
||||||
peer.Start()
|
peer.Start()
|
||||||
} else {
|
} else {
|
||||||
ethlogger.Debugf("Max connected peers reached. Not adding incoming peer.")
|
loggerger.Debugf("Max connected peers reached. Not adding incoming peer.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
|
||||||
|
|
||||||
if phost == chost {
|
if phost == chost {
|
||||||
alreadyConnected = true
|
alreadyConnected = true
|
||||||
//ethlogger.Debugf("Peer %s already added.\n", chost)
|
//loggerger.Debugf("Peer %s already added.\n", chost)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -397,12 +397,12 @@ func (s *Ethereum) Start(seed bool) {
|
||||||
// Bind to addr and port
|
// Bind to addr and port
|
||||||
ln, err := net.Listen("tcp", ":"+s.Port)
|
ln, err := net.Listen("tcp", ":"+s.Port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethlogger.Warnf("Port %s in use. Connection listening disabled. Acting as client", s.Port)
|
loggerger.Warnf("Port %s in use. Connection listening disabled. Acting as client", s.Port)
|
||||||
s.listening = false
|
s.listening = false
|
||||||
} else {
|
} else {
|
||||||
s.listening = true
|
s.listening = true
|
||||||
// Starting accepting connections
|
// Starting accepting connections
|
||||||
ethlogger.Infoln("Ready and accepting connections")
|
loggerger.Infoln("Ready and accepting connections")
|
||||||
// Start the peer handler
|
// Start the peer handler
|
||||||
go s.peerHandler(ln)
|
go s.peerHandler(ln)
|
||||||
}
|
}
|
||||||
|
@ -419,7 +419,7 @@ func (s *Ethereum) Start(seed bool) {
|
||||||
if seed {
|
if seed {
|
||||||
s.Seed()
|
s.Seed()
|
||||||
}
|
}
|
||||||
ethlogger.Infoln("Server started")
|
loggerger.Infoln("Server started")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ethereum) Seed() {
|
func (s *Ethereum) Seed() {
|
||||||
|
@ -428,11 +428,11 @@ func (s *Ethereum) Seed() {
|
||||||
ips := PastPeers()
|
ips := PastPeers()
|
||||||
if len(ips) > 0 {
|
if len(ips) > 0 {
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
ethlogger.Infoln("Connecting to previous peer ", ip)
|
loggerger.Infoln("Connecting to previous peer ", ip)
|
||||||
s.ConnectToPeer(ip)
|
s.ConnectToPeer(ip)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ethlogger.Debugln("Retrieving seed nodes")
|
loggerger.Debugln("Retrieving seed nodes")
|
||||||
|
|
||||||
// Eth-Go Bootstrapping
|
// Eth-Go Bootstrapping
|
||||||
ips, er := net.LookupIP("seed.bysh.me")
|
ips, er := net.LookupIP("seed.bysh.me")
|
||||||
|
@ -440,7 +440,7 @@ func (s *Ethereum) Seed() {
|
||||||
peers := []string{}
|
peers := []string{}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
node := fmt.Sprintf("%s:%d", ip.String(), 30303)
|
node := fmt.Sprintf("%s:%d", ip.String(), 30303)
|
||||||
ethlogger.Debugln("Found DNS Go Peer:", node)
|
loggerger.Debugln("Found DNS Go Peer:", node)
|
||||||
peers = append(peers, node)
|
peers = append(peers, node)
|
||||||
}
|
}
|
||||||
s.ProcessPeerList(peers)
|
s.ProcessPeerList(peers)
|
||||||
|
@ -460,11 +460,11 @@ func (s *Ethereum) Seed() {
|
||||||
for _, a := range addr {
|
for _, a := range addr {
|
||||||
// Build string out of SRV port and Resolved IP
|
// Build string out of SRV port and Resolved IP
|
||||||
peer := net.JoinHostPort(a, port)
|
peer := net.JoinHostPort(a, port)
|
||||||
ethlogger.Debugln("Found DNS Bootstrap Peer:", peer)
|
loggerger.Debugln("Found DNS Bootstrap Peer:", peer)
|
||||||
peers = append(peers, peer)
|
peers = append(peers, peer)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ethlogger.Debugln("Couldn't resolve :", target)
|
loggerger.Debugln("Couldn't resolve :", target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Connect to Peer list
|
// Connect to Peer list
|
||||||
|
@ -480,7 +480,7 @@ func (s *Ethereum) peerHandler(listener net.Listener) {
|
||||||
for {
|
for {
|
||||||
conn, err := listener.Accept()
|
conn, err := listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethlogger.Debugln(err)
|
loggerger.Debugln(err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -519,7 +519,7 @@ func (s *Ethereum) Stop() {
|
||||||
s.stateManager.Stop()
|
s.stateManager.Stop()
|
||||||
s.blockPool.Stop()
|
s.blockPool.Stop()
|
||||||
|
|
||||||
ethlogger.Infoln("Server stopped")
|
loggerger.Infoln("Server stopped")
|
||||||
close(s.shutdownChan)
|
close(s.shutdownChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,13 +541,13 @@ out:
|
||||||
var err error
|
var err error
|
||||||
_, err = s.nat.AddPortMapping("TCP", int(lport), int(lport), "eth listen port", 20*60)
|
_, err = s.nat.AddPortMapping("TCP", int(lport), int(lport), "eth listen port", 20*60)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethlogger.Debugln("can't add UPnP port mapping:", err)
|
loggerger.Debugln("can't add UPnP port mapping:", err)
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
if first && err == nil {
|
if first && err == nil {
|
||||||
_, err = s.nat.GetExternalAddress()
|
_, err = s.nat.GetExternalAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethlogger.Debugln("UPnP can't get external address:", err)
|
loggerger.Debugln("UPnP can't get external address:", err)
|
||||||
continue out
|
continue out
|
||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
|
@ -561,9 +561,9 @@ out:
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
|
|
||||||
if err := s.nat.DeletePortMapping("TCP", int(lport), int(lport)); err != nil {
|
if err := s.nat.DeletePortMapping("TCP", int(lport), int(lport)); err != nil {
|
||||||
ethlogger.Debugln("unable to remove UPnP port mapping:", err)
|
loggerger.Debugln("unable to remove UPnP port mapping:", err)
|
||||||
} else {
|
} else {
|
||||||
ethlogger.Debugln("succesfully disestablished UPnP port mapping")
|
loggerger.Debugln("succesfully disestablished UPnP port mapping")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("MINER")
|
var minerlogger = logger.NewLogger("MINER")
|
||||||
|
|
||||||
type Miner struct {
|
type Miner struct {
|
||||||
pow chain.PoW
|
pow chain.PoW
|
||||||
|
@ -70,12 +70,12 @@ func (miner *Miner) Start() {
|
||||||
//miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
|
//miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
|
||||||
go miner.listener()
|
go miner.listener()
|
||||||
|
|
||||||
logger.Infoln("Started")
|
minerlogger.Infoln("Started")
|
||||||
mux.Post(Event{Started, miner})
|
mux.Post(Event{Started, miner})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (miner *Miner) Stop() {
|
func (miner *Miner) Stop() {
|
||||||
logger.Infoln("Stopping...")
|
minerlogger.Infoln("Stopping...")
|
||||||
miner.events.Unsubscribe()
|
miner.events.Unsubscribe()
|
||||||
miner.ethereum.EventMux().Post(Event{Stopped, miner})
|
miner.ethereum.EventMux().Post(Event{Stopped, miner})
|
||||||
}
|
}
|
||||||
|
@ -91,10 +91,10 @@ func (miner *Miner) listener() {
|
||||||
miner.stopMining()
|
miner.stopMining()
|
||||||
|
|
||||||
block := event.Block
|
block := event.Block
|
||||||
//logger.Infoln("Got new block via Reactor")
|
//minerlogger.Infoln("Got new block via Reactor")
|
||||||
if bytes.Compare(miner.ethereum.ChainManager().CurrentBlock.Hash(), block.Hash()) == 0 {
|
if bytes.Compare(miner.ethereum.ChainManager().CurrentBlock.Hash(), block.Hash()) == 0 {
|
||||||
// TODO: Perhaps continue mining to get some uncle rewards
|
// TODO: Perhaps continue mining to get some uncle rewards
|
||||||
//logger.Infoln("New top block found resetting state")
|
//minerlogger.Infoln("New top block found resetting state")
|
||||||
|
|
||||||
// Filter out which Transactions we have that were not in this block
|
// Filter out which Transactions we have that were not in this block
|
||||||
var newtxs []*chain.Transaction
|
var newtxs []*chain.Transaction
|
||||||
|
@ -112,7 +112,7 @@ func (miner *Miner) listener() {
|
||||||
miner.txs = newtxs
|
miner.txs = newtxs
|
||||||
} else {
|
} else {
|
||||||
if bytes.Compare(block.PrevHash, miner.ethereum.ChainManager().CurrentBlock.PrevHash) == 0 {
|
if bytes.Compare(block.PrevHash, miner.ethereum.ChainManager().CurrentBlock.PrevHash) == 0 {
|
||||||
logger.Infoln("Adding uncle block")
|
minerlogger.Infoln("Adding uncle block")
|
||||||
miner.uncles = append(miner.uncles, block)
|
miner.uncles = append(miner.uncles, block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ func (self *Miner) mineNewBlock() {
|
||||||
coinbase.SetGasPool(self.block.CalcGasLimit(parent))
|
coinbase.SetGasPool(self.block.CalcGasLimit(parent))
|
||||||
receipts, txs, unhandledTxs, erroneous, err := stateManager.ProcessTransactions(coinbase, self.block.State(), self.block, self.block, self.txs)
|
receipts, txs, unhandledTxs, erroneous, err := stateManager.ProcessTransactions(coinbase, self.block.State(), self.block, self.block, self.txs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Debugln(err)
|
minerlogger.Debugln(err)
|
||||||
}
|
}
|
||||||
self.ethereum.TxPool().RemoveSet(erroneous)
|
self.ethereum.TxPool().RemoveSet(erroneous)
|
||||||
self.txs = append(txs, unhandledTxs...)
|
self.txs = append(txs, unhandledTxs...)
|
||||||
|
@ -193,7 +193,7 @@ func (self *Miner) mineNewBlock() {
|
||||||
|
|
||||||
self.block.State().Update()
|
self.block.State().Update()
|
||||||
|
|
||||||
logger.Infof("Mining on block. Includes %v transactions", len(self.txs))
|
minerlogger.Infof("Mining on block. Includes %v transactions", len(self.txs))
|
||||||
|
|
||||||
// Find a valid nonce
|
// Find a valid nonce
|
||||||
nonce := self.pow.Search(self.block, self.powQuitChan)
|
nonce := self.pow.Search(self.block, self.powQuitChan)
|
||||||
|
@ -201,11 +201,11 @@ func (self *Miner) mineNewBlock() {
|
||||||
self.block.Nonce = nonce
|
self.block.Nonce = nonce
|
||||||
err := self.ethereum.StateManager().Process(self.block)
|
err := self.ethereum.StateManager().Process(self.block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Infoln(err)
|
minerlogger.Infoln(err)
|
||||||
} else {
|
} else {
|
||||||
self.ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{self.block.Value().Val})
|
self.ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{self.block.Value().Val})
|
||||||
logger.Infof("🔨 Mined block %x\n", self.block.Hash())
|
minerlogger.Infof("🔨 Mined block %x\n", self.block.Hash())
|
||||||
logger.Infoln(self.block)
|
minerlogger.Infoln(self.block)
|
||||||
// Gather the new batch of transactions currently in the tx pool
|
// Gather the new batch of transactions currently in the tx pool
|
||||||
self.txs = self.ethereum.TxPool().CurrentTransactions()
|
self.txs = self.ethereum.TxPool().CurrentTransactions()
|
||||||
self.ethereum.EventMux().Post(chain.NewBlockEvent{self.block})
|
self.ethereum.EventMux().Post(chain.NewBlockEvent{self.block})
|
||||||
|
|
|
@ -233,7 +233,7 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
|
||||||
self.obj.TxPool().QueueTransaction(tx)
|
self.obj.TxPool().QueueTransaction(tx)
|
||||||
|
|
||||||
if contractCreation {
|
if contractCreation {
|
||||||
logger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
|
pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
|
return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
|
||||||
|
|
|
@ -6,13 +6,13 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethstate"
|
"github.com/ethereum/go-ethereum/ethstate"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("PIPE")
|
var pipelogger = logger.NewLogger("PIPE")
|
||||||
|
|
||||||
type VmVars struct {
|
type VmVars struct {
|
||||||
State *ethstate.State
|
State *ethstate.State
|
||||||
|
@ -143,7 +143,7 @@ func (self *Pipe) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e
|
||||||
|
|
||||||
if contractCreation {
|
if contractCreation {
|
||||||
addr := tx.CreationAddress(self.World().State())
|
addr := tx.CreationAddress(self.World().State())
|
||||||
logger.Infof("Contract addr %x\n", addr)
|
pipelogger.Infof("Contract addr %x\n", addr)
|
||||||
|
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ func (self *Pipe) PushTx(tx *chain.Transaction) ([]byte, error) {
|
||||||
self.obj.TxPool().QueueTransaction(tx)
|
self.obj.TxPool().QueueTransaction(tx)
|
||||||
if tx.Recipient == nil {
|
if tx.Recipient == nil {
|
||||||
addr := tx.CreationAddress(self.World().State())
|
addr := tx.CreationAddress(self.World().State())
|
||||||
logger.Infof("Contract addr %x\n", addr)
|
pipelogger.Infof("Contract addr %x\n", addr)
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
return tx.Hash(), nil
|
return tx.Hash(), nil
|
||||||
|
|
|
@ -3,12 +3,12 @@ package ethstate
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethtrie"
|
"github.com/ethereum/go-ethereum/ethtrie"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var statelogger = ethlog.NewLogger("STATE")
|
var statelogger = logger.NewLogger("STATE")
|
||||||
|
|
||||||
// States within the ethereum protocol are used to store anything
|
// States within the ethereum protocol are used to store anything
|
||||||
// within the merkle trie. States take care of caching and storing
|
// within the merkle trie. States take care of caching and storing
|
||||||
|
|
|
@ -9,16 +9,16 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethpipe"
|
"github.com/ethereum/go-ethereum/ethpipe"
|
||||||
"github.com/ethereum/go-ethereum/ethstate"
|
"github.com/ethereum/go-ethereum/ethstate"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var jsrelogger = ethlog.NewLogger("JSRE")
|
var jsrelogger = logger.NewLogger("JSRE")
|
||||||
|
|
||||||
type JSRE struct {
|
type JSRE struct {
|
||||||
ethereum *eth.Ethereum
|
ethereum *eth.Ethereum
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package ethlog
|
package logger
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Package ethlog implements a multi-output leveled logger.
|
Package logger implements a multi-output leveled logger.
|
||||||
|
|
||||||
Other packages use tagged logger to send log messages to shared
|
Other packages use tagged logger to send log messages to shared
|
||||||
(process-wide) logging engine. The shared logging engine dispatches to
|
(process-wide) logging engine. The shared logging engine dispatches to
|
||||||
|
@ -10,7 +10,7 @@ Logging is asynchronous and does not block the caller. Message
|
||||||
formatting is performed by the caller goroutine to avoid incorrect
|
formatting is performed by the caller goroutine to avoid incorrect
|
||||||
logging of mutable state.
|
logging of mutable state.
|
||||||
*/
|
*/
|
||||||
package ethlog
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package ethlog
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
16
peer.go
16
peer.go
|
@ -13,12 +13,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/chain"
|
"github.com/ethereum/go-ethereum/chain"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var peerlogger = ethlog.NewLogger("PEER")
|
var peerlogger = logger.NewLogger("PEER")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// The size of the output buffer for writing messages
|
// The size of the output buffer for writing messages
|
||||||
|
@ -696,18 +696,18 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if bytes.Compare(self.ethereum.ChainManager().Genesis().Hash(), genesis) != 0 {
|
if bytes.Compare(self.ethereum.ChainManager().Genesis().Hash(), genesis) != 0 {
|
||||||
ethlogger.Warnf("Invalid genisis hash %x. Disabling [eth]\n", genesis)
|
loggerger.Warnf("Invalid genisis hash %x. Disabling [eth]\n", genesis)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if netVersion != NetVersion {
|
if netVersion != NetVersion {
|
||||||
ethlogger.Warnf("Invalid network version %d. Disabling [eth]\n", netVersion)
|
loggerger.Warnf("Invalid network version %d. Disabling [eth]\n", netVersion)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if protoVersion != ProtocolVersion {
|
if protoVersion != ProtocolVersion {
|
||||||
ethlogger.Warnf("Invalid protocol version %d. Disabling [eth]\n", protoVersion)
|
loggerger.Warnf("Invalid protocol version %d. Disabling [eth]\n", protoVersion)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -723,7 +723,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
|
||||||
// fetch hashes from highest TD node.
|
// fetch hashes from highest TD node.
|
||||||
self.FetchHashes()
|
self.FetchHashes()
|
||||||
|
|
||||||
ethlogger.Infof("Peer is [eth] capable. (TD = %v ~ %x)", self.td, self.bestHash)
|
loggerger.Infof("Peer is [eth] capable. (TD = %v ~ %x)", self.td, self.bestHash)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,7 +819,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
||||||
switch cap {
|
switch cap {
|
||||||
case "eth":
|
case "eth":
|
||||||
if ver != ProtocolVersion {
|
if ver != ProtocolVersion {
|
||||||
ethlogger.Warnf("Invalid protocol version %d. Disabling [eth]\n", ver)
|
loggerger.Warnf("Invalid protocol version %d. Disabling [eth]\n", ver)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
p.pushStatus()
|
p.pushStatus()
|
||||||
|
@ -828,7 +828,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
||||||
capsStrs = append(capsStrs, cap)
|
capsStrs = append(capsStrs, cap)
|
||||||
}
|
}
|
||||||
|
|
||||||
ethlogger.Infof("Added peer (%s) %d / %d (%v)\n", p.conn.RemoteAddr(), p.ethereum.Peers().Len(), p.ethereum.MaxPeers, capsStrs)
|
peerlogger.Infof("Added peer (%s) %d / %d (%v)\n", p.conn.RemoteAddr(), p.ethereum.Peers().Len(), p.ethereum.MaxPeers, capsStrs)
|
||||||
|
|
||||||
peerlogger.Debugln(p)
|
peerlogger.Debugln(p)
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error {
|
||||||
i, _ := new(big.Int).SetString(args.Key, 10)
|
i, _ := new(big.Int).SetString(args.Key, 10)
|
||||||
hx = ethutil.Bytes2Hex(i.Bytes())
|
hx = ethutil.Bytes2Hex(i.Bytes())
|
||||||
}
|
}
|
||||||
logger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx)
|
jsonlogger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx)
|
||||||
value := state.Storage(ethutil.Hex2Bytes(hx))
|
value := state.Storage(ethutil.Hex2Bytes(hx))
|
||||||
*reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value.Str()})
|
*reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value.Str()})
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"net/rpc/jsonrpc"
|
"net/rpc/jsonrpc"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethpipe"
|
"github.com/ethereum/go-ethereum/ethpipe"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("JSON")
|
var jsonlogger = logger.NewLogger("JSON")
|
||||||
|
|
||||||
type JsonRpcServer struct {
|
type JsonRpcServer struct {
|
||||||
quit chan bool
|
quit chan bool
|
||||||
|
@ -28,7 +28,7 @@ out:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infoln("Shutdown JSON-RPC server")
|
jsonlogger.Infoln("Shutdown JSON-RPC server")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *JsonRpcServer) Stop() {
|
func (s *JsonRpcServer) Stop() {
|
||||||
|
@ -36,7 +36,7 @@ func (s *JsonRpcServer) Stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *JsonRpcServer) Start() {
|
func (s *JsonRpcServer) Start() {
|
||||||
logger.Infoln("Starting JSON-RPC server")
|
jsonlogger.Infoln("Starting JSON-RPC server")
|
||||||
go s.exitHandler()
|
go s.exitHandler()
|
||||||
rpc.Register(&EthereumApi{pipe: s.pipe})
|
rpc.Register(&EthereumApi{pipe: s.pipe})
|
||||||
rpc.HandleHTTP()
|
rpc.HandleHTTP()
|
||||||
|
@ -44,10 +44,10 @@ func (s *JsonRpcServer) Start() {
|
||||||
for {
|
for {
|
||||||
conn, err := s.listener.Accept()
|
conn, err := s.listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Infoln("Error starting JSON-RPC:", err)
|
jsonlogger.Infoln("Error starting JSON-RPC:", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logger.Debugln("Incoming request.")
|
jsonlogger.Debugln("Incoming request.")
|
||||||
go jsonrpc.ServeConn(conn)
|
go jsonrpc.ServeConn(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
34
utils/cmd.go
34
utils/cmd.go
|
@ -16,15 +16,15 @@ import (
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethminer"
|
"github.com/ethereum/go-ethereum/ethminer"
|
||||||
"github.com/ethereum/go-ethereum/ethpipe"
|
"github.com/ethereum/go-ethereum/ethpipe"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/ethwire"
|
"github.com/ethereum/go-ethereum/ethwire"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("CLI")
|
var clilogger = logger.NewLogger("CLI")
|
||||||
var interruptCallbacks = []func(os.Signal){}
|
var interruptCallbacks = []func(os.Signal){}
|
||||||
|
|
||||||
// Register interrupt handlers callbacks
|
// Register interrupt handlers callbacks
|
||||||
|
@ -38,7 +38,7 @@ func HandleInterrupt() {
|
||||||
go func() {
|
go func() {
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
for sig := range c {
|
for sig := range c {
|
||||||
logger.Errorf("Shutting down (%v) ... \n", sig)
|
clilogger.Errorf("Shutting down (%v) ... \n", sig)
|
||||||
RunInterruptCallbacks(sig)
|
RunInterruptCallbacks(sig)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -100,7 +100,7 @@ func InitDataDir(Datadir string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string) ethlog.LogSystem {
|
func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string) logger.LogSystem {
|
||||||
var writer io.Writer
|
var writer io.Writer
|
||||||
if LogFile == "" {
|
if LogFile == "" {
|
||||||
writer = os.Stdout
|
writer = os.Stdout
|
||||||
|
@ -108,11 +108,11 @@ func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string)
|
||||||
writer = openLogFile(Datadir, LogFile)
|
writer = openLogFile(Datadir, LogFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
sys := ethlog.NewStdLogSystem(writer, log.LstdFlags, ethlog.LogLevel(LogLevel))
|
sys := logger.NewStdLogSystem(writer, log.LstdFlags, logger.LogLevel(LogLevel))
|
||||||
ethlog.AddLogSystem(sys)
|
logger.AddLogSystem(sys)
|
||||||
if DebugFile != "" {
|
if DebugFile != "" {
|
||||||
writer = openLogFile(Datadir, DebugFile)
|
writer = openLogFile(Datadir, DebugFile)
|
||||||
ethlog.AddLogSystem(ethlog.NewStdLogSystem(writer, log.LstdFlags, ethlog.DebugLevel))
|
logger.AddLogSystem(logger.NewStdLogSystem(writer, log.LstdFlags, logger.DebugLevel))
|
||||||
}
|
}
|
||||||
|
|
||||||
return sys
|
return sys
|
||||||
|
@ -129,10 +129,10 @@ func InitConfig(vmType int, ConfigFile string, Datadir string, EnvPrefix string)
|
||||||
func exit(err error) {
|
func exit(err error) {
|
||||||
status := 0
|
status := 0
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("Fatal: ", err)
|
clilogger.Errorln("Fatal: ", err)
|
||||||
status = 1
|
status = 1
|
||||||
}
|
}
|
||||||
ethlog.Flush()
|
logger.Flush()
|
||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +145,14 @@ func NewDatabase() ethutil.Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *ethwire.SimpleClientIdentity {
|
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *ethwire.SimpleClientIdentity {
|
||||||
logger.Infoln("identity created")
|
clilogger.Infoln("identity created")
|
||||||
return ethwire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier)
|
return ethwire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEthereum(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager *crypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
|
func NewEthereum(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager *crypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
|
||||||
ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, usePnp)
|
ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, usePnp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalln("eth start err:", err)
|
clilogger.Fatalln("eth start err:", err)
|
||||||
}
|
}
|
||||||
ethereum.Port = OutboundPort
|
ethereum.Port = OutboundPort
|
||||||
ethereum.MaxPeers = MaxPeer
|
ethereum.MaxPeers = MaxPeer
|
||||||
|
@ -160,16 +160,16 @@ func NewEthereum(db ethutil.Database, clientIdentity ethwire.ClientIdentity, key
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
|
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
|
||||||
logger.Infof("Starting %s", ethereum.ClientIdentity())
|
clilogger.Infof("Starting %s", ethereum.ClientIdentity())
|
||||||
ethereum.Start(UseSeed)
|
ethereum.Start(UseSeed)
|
||||||
RegisterInterrupt(func(sig os.Signal) {
|
RegisterInterrupt(func(sig os.Signal) {
|
||||||
ethereum.Stop()
|
ethereum.Stop()
|
||||||
ethlog.Flush()
|
logger.Flush()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowGenesis(ethereum *eth.Ethereum) {
|
func ShowGenesis(ethereum *eth.Ethereum) {
|
||||||
logger.Infoln(ethereum.ChainManager().Genesis())
|
clilogger.Infoln(ethereum.ChainManager().Genesis())
|
||||||
exit(nil)
|
exit(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
|
||||||
var err error
|
var err error
|
||||||
ethereum.RpcServer, err = rpc.NewJsonRpcServer(ethpipe.NewJSPipe(ethereum), RpcPort)
|
ethereum.RpcServer, err = rpc.NewJsonRpcServer(ethpipe.NewJSPipe(ethereum), RpcPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
||||||
} else {
|
} else {
|
||||||
go ethereum.RpcServer.Start()
|
go ethereum.RpcServer.Start()
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
|
||||||
addr := ethereum.KeyManager().Address()
|
addr := ethereum.KeyManager().Address()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
logger.Infoln("Start mining")
|
clilogger.Infoln("Start mining")
|
||||||
if miner == nil {
|
if miner == nil {
|
||||||
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ func FormatTransactionData(data string) []byte {
|
||||||
func StopMining(ethereum *eth.Ethereum) bool {
|
func StopMining(ethereum *eth.Ethereum) bool {
|
||||||
if ethereum.Mining && miner != nil {
|
if ethereum.Mining && miner != nil {
|
||||||
miner.Stop()
|
miner.Stop()
|
||||||
logger.Infoln("Stopped mining")
|
clilogger.Infoln("Stopped mining")
|
||||||
ethereum.Mining = false
|
ethereum.Mining = false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -3,11 +3,11 @@ package vm
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var vmlogger = ethlog.NewLogger("VM")
|
var vmlogger = logger.NewLogger("VM")
|
||||||
|
|
||||||
type Type int
|
type Type int
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,13 @@ func (c *Client) Listen() {
|
||||||
|
|
||||||
// Listen write request via chanel
|
// Listen write request via chanel
|
||||||
func (c *Client) listenWrite() {
|
func (c *Client) listenWrite() {
|
||||||
logger.Debugln("Listening write to client")
|
wslogger.Debugln("Listening write to client")
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
||||||
// send message to the client
|
// send message to the client
|
||||||
case msg := <-c.ch:
|
case msg := <-c.ch:
|
||||||
logger.Debugln("Send:", msg)
|
wslogger.Debugln("Send:", msg)
|
||||||
ws.JSON.Send(c.ws, msg)
|
ws.JSON.Send(c.ws, msg)
|
||||||
|
|
||||||
// receive done request
|
// receive done request
|
||||||
|
@ -93,7 +93,7 @@ func (c *Client) listenWrite() {
|
||||||
|
|
||||||
// Listen read request via chanel
|
// Listen read request via chanel
|
||||||
func (c *Client) listenRead() {
|
func (c *Client) listenRead() {
|
||||||
logger.Debugln("Listening read from client")
|
wslogger.Debugln("Listening read from client")
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func (c *Client) listenRead() {
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
c.server.Err(err)
|
c.server.Err(err)
|
||||||
} else {
|
} else {
|
||||||
logger.Debugln(&msg)
|
wslogger.Debugln(&msg)
|
||||||
if c.onMessage != nil {
|
if c.onMessage != nil {
|
||||||
c.onMessage(c, &msg)
|
c.onMessage(c, &msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ package websocket
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethlog"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
|
|
||||||
ws "code.google.com/p/go.net/websocket"
|
ws "code.google.com/p/go.net/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("WS")
|
var wslogger = logger.NewLogger("WS")
|
||||||
|
|
||||||
// Chat server.
|
// Chat server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -68,10 +68,10 @@ func (s *Server) Err(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) servHTTP() {
|
func (s *Server) servHTTP() {
|
||||||
logger.Debugln("Serving http", s.httpServ)
|
wslogger.Debugln("Serving http", s.httpServ)
|
||||||
err := http.ListenAndServe(s.httpServ, nil)
|
err := http.ListenAndServe(s.httpServ, nil)
|
||||||
|
|
||||||
logger.Warnln(err)
|
wslogger.Warnln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) MessageFunc(f MsgFunc) {
|
func (s *Server) MessageFunc(f MsgFunc) {
|
||||||
|
@ -81,7 +81,7 @@ func (s *Server) MessageFunc(f MsgFunc) {
|
||||||
// Listen and serve.
|
// Listen and serve.
|
||||||
// It serves client connection and broadcast request.
|
// It serves client connection and broadcast request.
|
||||||
func (s *Server) Listen() {
|
func (s *Server) Listen() {
|
||||||
logger.Debugln("Listening server...")
|
wslogger.Debugln("Listening server...")
|
||||||
|
|
||||||
// ws handler
|
// ws handler
|
||||||
onConnected := func(ws *ws.Conn) {
|
onConnected := func(ws *ws.Conn) {
|
||||||
|
@ -102,7 +102,7 @@ func (s *Server) Listen() {
|
||||||
s := ws.Server{Handler: ws.Handler(onConnected)}
|
s := ws.Server{Handler: ws.Handler(onConnected)}
|
||||||
s.ServeHTTP(w, req)
|
s.ServeHTTP(w, req)
|
||||||
})
|
})
|
||||||
logger.Debugln("Created handler")
|
wslogger.Debugln("Created handler")
|
||||||
|
|
||||||
go s.servHTTP()
|
go s.servHTTP()
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ func (s *Server) Listen() {
|
||||||
delete(s.clients, c.id)
|
delete(s.clients, c.id)
|
||||||
|
|
||||||
case err := <-s.errCh:
|
case err := <-s.errCh:
|
||||||
logger.Debugln("Error:", err.Error())
|
wslogger.Debugln("Error:", err.Error())
|
||||||
|
|
||||||
case <-s.doneCh:
|
case <-s.doneCh:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue