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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
@ -119,7 +118,6 @@ func (bc *BlockChain) GetChain(hash []byte, amount int) []*Block {
|
|||||||
var blocks []*Block
|
var blocks []*Block
|
||||||
|
|
||||||
for i := 0; i < amount && block != nil; block = bc.GetBlock(block.PrevHash) {
|
for i := 0; i < amount && block != nil; block = bc.GetBlock(block.PrevHash) {
|
||||||
fmt.Println(block)
|
|
||||||
blocks = append([]*Block{block}, blocks...)
|
blocks = append([]*Block{block}, blocks...)
|
||||||
|
|
||||||
if bytes.Compare(genHash, block.Hash()) == 0 {
|
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 {
|
if usePnp {
|
||||||
nat, err = Discover()
|
nat, err = Discover()
|
||||||
if err != nil {
|
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")
|
log.Println("Connection listening disabled. Acting as client")
|
||||||
} else {
|
} else {
|
||||||
// Starting accepting connections
|
// Starting accepting connections
|
||||||
log.Println("Ready and accepting connections")
|
ethutil.Config.Log.Infoln("Ready and accepting connections")
|
||||||
// Start the peer handler
|
// Start the peer handler
|
||||||
go s.peerHandler(ln)
|
go s.peerHandler(ln)
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ func (s *Ethereum) Start() {
|
|||||||
s.TxPool.Start()
|
s.TxPool.Start()
|
||||||
|
|
||||||
if ethutil.Config.Seed {
|
if ethutil.Config.Seed {
|
||||||
log.Println("Seeding")
|
ethutil.Config.Log.Debugln("Seeding")
|
||||||
// Testnet seed bootstrapping
|
// Testnet seed bootstrapping
|
||||||
resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
|
resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -272,7 +272,7 @@ func (s *Ethereum) peerHandler(listener net.Listener) {
|
|||||||
for {
|
for {
|
||||||
conn, err := listener.Accept()
|
conn, err := listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
ethutil.Config.Log.Debugln(err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -315,13 +315,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 {
|
||||||
log.Println("can't add UPnP port mapping:", err)
|
ethutil.Config.Log.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 {
|
||||||
log.Println("UPnP can't get external address:", err)
|
ethutil.Config.Log.Debugln("UPnP can't get external address:", err)
|
||||||
continue out
|
continue out
|
||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
@ -335,8 +335,8 @@ 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 {
|
||||||
log.Println("unable to remove UPnP port mapping:", err)
|
ethutil.Config.Log.Debugln("unable to remove UPnP port mapping:", err)
|
||||||
} else {
|
} 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/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/eth-go/ethwire"
|
"github.com/ethereum/eth-go/ethwire"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -165,7 +164,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
|
|||||||
conn, err := net.DialTimeout("tcp", addr, 30*time.Second)
|
conn, err := net.DialTimeout("tcp", addr, 30*time.Second)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Connection to peer failed", err)
|
ethutil.Config.Log.Debugln("Connection to peer failed", err)
|
||||||
p.Stop()
|
p.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -202,7 +201,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
|
|||||||
|
|
||||||
err := ethwire.WriteMessage(p.conn, msg)
|
err := ethwire.WriteMessage(p.conn, msg)
|
||||||
if err != nil {
|
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
|
// Stop the client if there was an error writing to it
|
||||||
p.Stop()
|
p.Stop()
|
||||||
return
|
return
|
||||||
@ -264,7 +263,7 @@ func (p *Peer) HandleInbound() {
|
|||||||
// Wait for a message from the peer
|
// Wait for a message from the peer
|
||||||
msgs, err := ethwire.ReadMessages(p.conn)
|
msgs, err := ethwire.ReadMessages(p.conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
ethutil.Config.Log.Debugln(err)
|
||||||
}
|
}
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
@ -277,7 +276,7 @@ func (p *Peer) HandleInbound() {
|
|||||||
}
|
}
|
||||||
case ethwire.MsgDiscTy:
|
case ethwire.MsgDiscTy:
|
||||||
p.Stop()
|
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:
|
case ethwire.MsgPingTy:
|
||||||
// Respond back with pong
|
// Respond back with pong
|
||||||
p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
|
||||||
@ -296,9 +295,8 @@ func (p *Peer) HandleInbound() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ethutil.Config.Debug {
|
if ethutil.Config.Debug {
|
||||||
log.Printf("[PEER] Block %x failed\n", block.Hash())
|
ethutil.Config.Log.Infof("[PEER] Block %x failed\n", block.Hash())
|
||||||
log.Printf("[PEER] %v\n", err)
|
ethutil.Config.Log.Infof("[PEER] %v\n", err)
|
||||||
log.Println(block)
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
@ -309,7 +307,7 @@ func (p *Peer) HandleInbound() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// If the parent is unknown try to catch up with this peer
|
// If the parent is unknown try to catch up with this peer
|
||||||
if ethchain.IsParentErr(err) {
|
if ethchain.IsParentErr(err) {
|
||||||
log.Println("Attempting to catch up")
|
ethutil.Config.Log.Infoln("Attempting to catch up")
|
||||||
p.catchingUp = false
|
p.catchingUp = false
|
||||||
p.CatchupWithPeer()
|
p.CatchupWithPeer()
|
||||||
} else if ethchain.IsValidationErr(err) {
|
} else if ethchain.IsValidationErr(err) {
|
||||||
@ -321,7 +319,7 @@ func (p *Peer) HandleInbound() {
|
|||||||
if p.catchingUp && msg.Data.Len() > 1 {
|
if p.catchingUp && msg.Data.Len() > 1 {
|
||||||
if ethutil.Config.Debug && lastBlock != nil {
|
if ethutil.Config.Debug && lastBlock != nil {
|
||||||
blockInfo := lastBlock.BlockInfo()
|
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.catchingUp = false
|
||||||
p.CatchupWithPeer()
|
p.CatchupWithPeer()
|
||||||
@ -392,12 +390,12 @@ func (p *Peer) HandleInbound() {
|
|||||||
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()}))
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()}))
|
||||||
}
|
}
|
||||||
case ethwire.MsgNotInChainTy:
|
case ethwire.MsgNotInChainTy:
|
||||||
log.Printf("Not in chain %x\n", msg.Data)
|
ethutil.Config.Log.Infoln("Not in chain %x\n", msg.Data)
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
// Unofficial but fun nonetheless
|
// Unofficial but fun nonetheless
|
||||||
case ethwire.MsgTalkTy:
|
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()
|
err := p.pushHandshake()
|
||||||
if err != nil {
|
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()
|
p.Stop()
|
||||||
|
|
||||||
@ -499,7 +497,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
|||||||
c := msg.Data
|
c := msg.Data
|
||||||
|
|
||||||
if c.Get(0).Uint() != 5 {
|
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()
|
p.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -531,7 +529,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
|||||||
// Get a reference to the peers version
|
// Get a reference to the peers version
|
||||||
p.Version = c.Get(2).Str()
|
p.Version = c.Get(2).Str()
|
||||||
|
|
||||||
log.Println("[PEER]", p)
|
ethutil.Config.Log.Debugln("[PEER]", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) String() string {
|
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)})
|
msg := ethwire.NewMessage(ethwire.MsgGetChainTy, []interface{}{p.ethereum.BlockManager.BlockChain().CurrentBlock.Hash(), uint64(50)})
|
||||||
p.QueueMessage(msg)
|
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