aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-22 08:53:25 +0800
committerobscuren <geffobscura@gmail.com>2014-02-22 08:53:25 +0800
commit73b9ae95797ce8c38d82cfcb7c793efea268f476 (patch)
tree05c54709bc0cae394de239564a3746bac6d0b731 /peer.go
parent4bfd717ba2b753f183e9e3fecd91d7e4083aaffc (diff)
downloaddexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.tar
dexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.tar.gz
dexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.tar.bz2
dexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.tar.lz
dexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.tar.xz
dexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.tar.zst
dexon-73b9ae95797ce8c38d82cfcb7c793efea268f476.zip
Updated some of the log statements to use the ethutil logger
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/peer.go b/peer.go
index ed81ddd8e..9538e6500 100644
--- a/peer.go
+++ b/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])
}
}