forked from cerc-io/plugeth
Updated some of the log statements to use the ethutil logger
This commit is contained in:
parent
4bfd717ba2
commit
73b9ae9579
@ -2,7 +2,6 @@ package ethchain
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"log"
|
||||
"math"
|
||||
@ -119,7 +118,6 @@ func (bc *BlockChain) GetChain(hash []byte, amount int) []*Block {
|
||||
var blocks []*Block
|
||||
|
||||
for i := 0; i < amount && block != nil; block = bc.GetBlock(block.PrevHash) {
|
||||
fmt.Println(block)
|
||||
blocks = append([]*Block{block}, blocks...)
|
||||
|
||||
if bytes.Compare(genHash, block.Hash()) == 0 {
|
||||
|
16
ethereum.go
16
ethereum.go
@ -70,7 +70,7 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
|
||||
if usePnp {
|
||||
nat, err = Discover()
|
||||
if err != nil {
|
||||
log.Println("UPnP failed", err)
|
||||
ethutil.Config.Log.Debugln("UPnP failed", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ func (s *Ethereum) Start() {
|
||||
log.Println("Connection listening disabled. Acting as client")
|
||||
} else {
|
||||
// Starting accepting connections
|
||||
log.Println("Ready and accepting connections")
|
||||
ethutil.Config.Log.Infoln("Ready and accepting connections")
|
||||
// Start the peer handler
|
||||
go s.peerHandler(ln)
|
||||
}
|
||||
@ -250,7 +250,7 @@ func (s *Ethereum) Start() {
|
||||
s.TxPool.Start()
|
||||
|
||||
if ethutil.Config.Seed {
|
||||
log.Println("Seeding")
|
||||
ethutil.Config.Log.Debugln("Seeding")
|
||||
// Testnet seed bootstrapping
|
||||
resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
|
||||
if err != nil {
|
||||
@ -272,7 +272,7 @@ func (s *Ethereum) peerHandler(listener net.Listener) {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
ethutil.Config.Log.Debugln(err)
|
||||
|
||||
continue
|
||||
}
|
||||
@ -315,13 +315,13 @@ out:
|
||||
var err error
|
||||
_, err = s.nat.AddPortMapping("TCP", int(lport), int(lport), "eth listen port", 20*60)
|
||||
if err != nil {
|
||||
log.Println("can't add UPnP port mapping:", err)
|
||||
ethutil.Config.Log.Debugln("can't add UPnP port mapping:", err)
|
||||
break out
|
||||
}
|
||||
if first && err == nil {
|
||||
_, err = s.nat.GetExternalAddress()
|
||||
if err != nil {
|
||||
log.Println("UPnP can't get external address:", err)
|
||||
ethutil.Config.Log.Debugln("UPnP can't get external address:", err)
|
||||
continue out
|
||||
}
|
||||
first = false
|
||||
@ -335,8 +335,8 @@ out:
|
||||
timer.Stop()
|
||||
|
||||
if err := s.nat.DeletePortMapping("TCP", int(lport), int(lport)); err != nil {
|
||||
log.Println("unable to remove UPnP port mapping:", err)
|
||||
ethutil.Config.Log.Debugln("unable to remove UPnP port mapping:", err)
|
||||
} else {
|
||||
log.Println("succesfully disestablished UPnP port mapping")
|
||||
ethutil.Config.Log.Debugln("succesfully disestablished UPnP port mapping")
|
||||
}
|
||||
}
|
||||
|
30
peer.go
30
peer.go
@ -6,7 +6,6 @@ import (
|
||||
"github.com/ethereum/eth-go/ethchain"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/ethereum/eth-go/ethwire"
|
||||
"log"
|
||||
"net"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@ -165,7 +164,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
|
||||
conn, err := net.DialTimeout("tcp", addr, 30*time.Second)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Connection to peer failed", err)
|
||||
ethutil.Config.Log.Debugln("Connection to peer failed", err)
|
||||
p.Stop()
|
||||
return
|
||||
}
|
||||
@ -202,7 +201,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
|
||||
|
||||
err := ethwire.WriteMessage(p.conn, msg)
|
||||
if err != nil {
|
||||
log.Println("Can't send message:", err)
|
||||
ethutil.Config.Log.Debugln("Can't send message:", err)
|
||||
// Stop the client if there was an error writing to it
|
||||
p.Stop()
|
||||
return
|
||||
@ -264,7 +263,7 @@ func (p *Peer) HandleInbound() {
|
||||
// Wait for a message from the peer
|
||||
msgs, err := ethwire.ReadMessages(p.conn)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
ethutil.Config.Log.Debugln(err)
|
||||
}
|
||||
for _, msg := range msgs {
|
||||
switch msg.Type {
|
||||
@ -277,7 +276,7 @@ func (p *Peer) HandleInbound() {
|
||||
}
|
||||
case ethwire.MsgDiscTy:
|
||||
p.Stop()
|
||||
log.Println("Disconnect peer:", DiscReason(msg.Data.Get(0).Uint()))
|
||||
ethutil.Config.Log.Infoln("Disconnect peer:", DiscReason(msg.Data.Get(0).Uint()))
|
||||
case ethwire.MsgPingTy:
|
||||
// Respond back with pong
|
||||
p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
|
||||
@ -296,9 +295,8 @@ func (p *Peer) HandleInbound() {
|
||||
|
||||
if err != nil {
|
||||
if ethutil.Config.Debug {
|
||||
log.Printf("[PEER] Block %x failed\n", block.Hash())
|
||||
log.Printf("[PEER] %v\n", err)
|
||||
log.Println(block)
|
||||
ethutil.Config.Log.Infof("[PEER] Block %x failed\n", block.Hash())
|
||||
ethutil.Config.Log.Infof("[PEER] %v\n", err)
|
||||
}
|
||||
break
|
||||
} else {
|
||||
@ -309,7 +307,7 @@ func (p *Peer) HandleInbound() {
|
||||
if err != nil {
|
||||
// If the parent is unknown try to catch up with this peer
|
||||
if ethchain.IsParentErr(err) {
|
||||
log.Println("Attempting to catch up")
|
||||
ethutil.Config.Log.Infoln("Attempting to catch up")
|
||||
p.catchingUp = false
|
||||
p.CatchupWithPeer()
|
||||
} else if ethchain.IsValidationErr(err) {
|
||||
@ -321,7 +319,7 @@ func (p *Peer) HandleInbound() {
|
||||
if p.catchingUp && msg.Data.Len() > 1 {
|
||||
if ethutil.Config.Debug && lastBlock != nil {
|
||||
blockInfo := lastBlock.BlockInfo()
|
||||
log.Printf("Synced to block height #%d %x %x\n", blockInfo.Number, lastBlock.Hash(), blockInfo.Hash)
|
||||
ethutil.Config.Log.Infof("Synced to block height #%d %x %x\n", blockInfo.Number, lastBlock.Hash(), blockInfo.Hash)
|
||||
}
|
||||
p.catchingUp = false
|
||||
p.CatchupWithPeer()
|
||||
@ -392,12 +390,12 @@ func (p *Peer) HandleInbound() {
|
||||
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()}))
|
||||
}
|
||||
case ethwire.MsgNotInChainTy:
|
||||
log.Printf("Not in chain %x\n", msg.Data)
|
||||
ethutil.Config.Log.Infoln("Not in chain %x\n", msg.Data)
|
||||
// TODO
|
||||
|
||||
// Unofficial but fun nonetheless
|
||||
case ethwire.MsgTalkTy:
|
||||
log.Printf("%v says: %s\n", p.conn.RemoteAddr(), msg.Data.Str())
|
||||
ethutil.Config.Log.Infoln("%v says: %s\n", p.conn.RemoteAddr(), msg.Data.Str())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -440,7 +438,7 @@ func (p *Peer) Start() {
|
||||
|
||||
err := p.pushHandshake()
|
||||
if err != nil {
|
||||
log.Println("Peer can't send outbound version ack", err)
|
||||
ethutil.Config.Log.Debugln("Peer can't send outbound version ack", err)
|
||||
|
||||
p.Stop()
|
||||
|
||||
@ -499,7 +497,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
||||
c := msg.Data
|
||||
|
||||
if c.Get(0).Uint() != 5 {
|
||||
log.Println("Invalid peer version. Require protocol v4")
|
||||
ethutil.Config.Log.Debugln("Invalid peer version. Require protocol v5")
|
||||
p.Stop()
|
||||
return
|
||||
}
|
||||
@ -531,7 +529,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
||||
// Get a reference to the peers version
|
||||
p.Version = c.Get(2).Str()
|
||||
|
||||
log.Println("[PEER]", p)
|
||||
ethutil.Config.Log.Debugln("[PEER]", p)
|
||||
}
|
||||
|
||||
func (p *Peer) String() string {
|
||||
@ -558,7 +556,7 @@ func (p *Peer) CatchupWithPeer() {
|
||||
msg := ethwire.NewMessage(ethwire.MsgGetChainTy, []interface{}{p.ethereum.BlockManager.BlockChain().CurrentBlock.Hash(), uint64(50)})
|
||||
p.QueueMessage(msg)
|
||||
|
||||
log.Printf("Requesting blockchain %x...\n", p.ethereum.BlockManager.BlockChain().CurrentBlock.Hash()[:4])
|
||||
ethutil.Config.Log.Debugln("Requesting blockchain %x...\n", p.ethereum.BlockManager.BlockChain().CurrentBlock.Hash()[:4])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user