aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'p2p')
-rw-r--r--p2p/dial.go17
-rw-r--r--p2p/discover/database.go14
-rw-r--r--p2p/discover/ntp.go13
-rw-r--r--p2p/discover/table.go24
-rw-r--r--p2p/discover/udp.go23
-rw-r--r--p2p/discv5/database.go12
-rw-r--r--p2p/discv5/net.go27
-rw-r--r--p2p/discv5/ntp.go13
-rw-r--r--p2p/discv5/sim_test.go8
-rw-r--r--p2p/discv5/udp.go17
-rw-r--r--p2p/nat/nat.go13
-rw-r--r--p2p/peer.go19
-rw-r--r--p2p/server.go55
-rw-r--r--p2p/server_test.go3
14 files changed, 118 insertions, 140 deletions
diff --git a/p2p/dial.go b/p2p/dial.go
index 1f5c0f15a..65180e029 100644
--- a/p2p/dial.go
+++ b/p2p/dial.go
@@ -24,8 +24,7 @@ import (
"net"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/netutil"
)
@@ -134,7 +133,7 @@ func (s *dialstate) newTasks(nRunning int, peers map[discover.NodeID]*Peer, now
var newtasks []task
addDial := func(flag connFlag, n *discover.Node) bool {
if err := s.checkDial(n, peers); err != nil {
- glog.V(logger.Debug).Infof("skipping dial candidate %x@%v:%d: %v", n.ID[:8], n.IP, n.TCP, err)
+ log.Debug(fmt.Sprintf("skipping dial candidate %x@%v:%d: %v", n.ID[:8], n.IP, n.TCP, err))
return false
}
s.dialing[n.ID] = flag
@@ -163,7 +162,7 @@ func (s *dialstate) newTasks(nRunning int, peers map[discover.NodeID]*Peer, now
err := s.checkDial(t.dest, peers)
switch err {
case errNotWhitelisted, errSelf:
- glog.V(logger.Debug).Infof("removing static dial candidate %x@%v:%d: %v", t.dest.ID[:8], t.dest.IP, t.dest.TCP, err)
+ log.Debug(fmt.Sprintf("removing static dial candidate %x@%v:%d: %v", t.dest.ID[:8], t.dest.IP, t.dest.TCP, err))
delete(s.static, t.dest.ID)
case nil:
s.dialing[id] = t.flags
@@ -267,7 +266,7 @@ func (t *dialTask) Do(srv *Server) {
// The backoff delay resets when the node is found.
func (t *dialTask) resolve(srv *Server) bool {
if srv.ntab == nil {
- glog.V(logger.Debug).Infof("can't resolve node %x: discovery is disabled", t.dest.ID[:6])
+ log.Debug(fmt.Sprintf("can't resolve node %x: discovery is disabled", t.dest.ID[:6]))
return false
}
if t.resolveDelay == 0 {
@@ -283,23 +282,23 @@ func (t *dialTask) resolve(srv *Server) bool {
if t.resolveDelay > maxResolveDelay {
t.resolveDelay = maxResolveDelay
}
- glog.V(logger.Debug).Infof("resolving node %x failed (new delay: %v)", t.dest.ID[:6], t.resolveDelay)
+ log.Debug(fmt.Sprintf("resolving node %x failed (new delay: %v)", t.dest.ID[:6], t.resolveDelay))
return false
}
// The node was found.
t.resolveDelay = initialResolveDelay
t.dest = resolved
- glog.V(logger.Debug).Infof("resolved node %x: %v:%d", t.dest.ID[:6], t.dest.IP, t.dest.TCP)
+ log.Debug(fmt.Sprintf("resolved node %x: %v:%d", t.dest.ID[:6], t.dest.IP, t.dest.TCP))
return true
}
// dial performs the actual connection attempt.
func (t *dialTask) dial(srv *Server, dest *discover.Node) bool {
addr := &net.TCPAddr{IP: dest.IP, Port: int(dest.TCP)}
- glog.V(logger.Debug).Infof("dial tcp %v (%x)", addr, dest.ID[:6])
+ log.Debug(fmt.Sprintf("dial tcp %v (%x)", addr, dest.ID[:6]))
fd, err := srv.Dialer.Dial("tcp", addr.String())
if err != nil {
- glog.V(logger.Detail).Infof("%v", err)
+ log.Trace(fmt.Sprintf("%v", err))
return false
}
mfd := newMeteredConn(fd, false)
diff --git a/p2p/discover/database.go b/p2p/discover/database.go
index 8d20d1ec7..a8b32d31e 100644
--- a/p2p/discover/database.go
+++ b/p2p/discover/database.go
@@ -23,13 +23,13 @@ import (
"bytes"
"crypto/rand"
"encoding/binary"
+ "fmt"
"os"
"sync"
"time"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
@@ -180,12 +180,12 @@ func (db *nodeDB) storeInt64(key []byte, n int64) error {
func (db *nodeDB) node(id NodeID) *Node {
blob, err := db.lvl.Get(makeKey(id, nodeDBDiscoverRoot), nil)
if err != nil {
- glog.V(logger.Detail).Infof("failed to retrieve node %v: %v", id, err)
+ log.Trace(fmt.Sprintf("failed to retrieve node %v: %v", id, err))
return nil
}
node := new(Node)
if err := rlp.DecodeBytes(blob, node); err != nil {
- glog.V(logger.Warn).Infof("failed to decode node RLP: %v", err)
+ log.Warn(fmt.Sprintf("failed to decode node RLP: %v", err))
return nil
}
node.sha = crypto.Keccak256Hash(node.ID[:])
@@ -233,7 +233,7 @@ func (db *nodeDB) expirer() {
select {
case <-tick:
if err := db.expireNodes(); err != nil {
- glog.V(logger.Error).Infof("Failed to expire nodedb items: %v", err)
+ log.Error(fmt.Sprintf("Failed to expire nodedb items: %v", err))
}
case <-db.quit:
@@ -352,9 +352,7 @@ func nextNode(it iterator.Iterator) *Node {
}
var n Node
if err := rlp.DecodeBytes(it.Value(), &n); err != nil {
- if glog.V(logger.Warn) {
- glog.Errorf("invalid node %x: %v", id, err)
- }
+ log.Warn(fmt.Sprintf("invalid node %x: %v", id, err))
continue
}
return &n
diff --git a/p2p/discover/ntp.go b/p2p/discover/ntp.go
index c1a4b3af1..df67e1c5b 100644
--- a/p2p/discover/ntp.go
+++ b/p2p/discover/ntp.go
@@ -26,8 +26,7 @@ import (
"strings"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
const (
@@ -55,12 +54,12 @@ func checkClockDrift() {
howtofix := fmt.Sprintf("Please enable network time synchronisation in system settings")
separator := strings.Repeat("-", len(warning))
- glog.V(logger.Warn).Info(separator)
- glog.V(logger.Warn).Info(warning)
- glog.V(logger.Warn).Info(howtofix)
- glog.V(logger.Warn).Info(separator)
+ log.Warn(fmt.Sprint(separator))
+ log.Warn(fmt.Sprint(warning))
+ log.Warn(fmt.Sprint(howtofix))
+ log.Warn(fmt.Sprint(separator))
} else {
- glog.V(logger.Debug).Infof("Sanity NTP check reported %v drift, all ok", drift)
+ log.Debug(fmt.Sprintf("Sanity NTP check reported %v drift, all ok", drift))
}
}
diff --git a/p2p/discover/table.go b/p2p/discover/table.go
index 839e3ec7e..03392b563 100644
--- a/p2p/discover/table.go
+++ b/p2p/discover/table.go
@@ -34,8 +34,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
const (
@@ -278,10 +277,10 @@ func (tab *Table) lookup(targetID NodeID, refreshIfEmpty bool) []*Node {
// Bump the failure counter to detect and evacuate non-bonded entries
fails := tab.db.findFails(n.ID) + 1
tab.db.updateFindFails(n.ID, fails)
- glog.V(logger.Detail).Infof("Bumping failures for %x: %d", n.ID[:8], fails)
+ log.Trace(fmt.Sprintf("Bumping failures for %x: %d", n.ID[:8], fails))
if fails >= maxFindnodeFailures {
- glog.V(logger.Detail).Infof("Evacuating node %x: %d findnode failures", n.ID[:8], fails)
+ log.Trace(fmt.Sprintf("Evacuating node %x: %d findnode failures", n.ID[:8], fails))
tab.delete(n)
}
}
@@ -384,14 +383,15 @@ func (tab *Table) doRefresh(done chan struct{}) {
// (hopefully) still alive.
seeds := tab.db.querySeeds(seedCount, seedMaxAge)
seeds = tab.bondall(append(seeds, tab.nursery...))
- if glog.V(logger.Debug) {
- if len(seeds) == 0 {
- glog.Infof("no seed nodes found")
- }
- for _, n := range seeds {
+
+ if len(seeds) == 0 {
+ log.Debug(fmt.Sprintf("no seed nodes found"))
+ }
+ for _, n := range seeds {
+ log.Debug("", "msg", log.Lazy{Fn: func() string {
age := time.Since(tab.db.lastPong(n.ID))
- glog.Infof("seed node (age %v): %v", age, n)
- }
+ return fmt.Sprintf("seed node (age %v): %v", age, n)
+ }})
}
tab.mutex.Lock()
tab.stuff(seeds)
@@ -470,7 +470,7 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
var result error
age := time.Since(tab.db.lastPong(id))
if node == nil || fails > 0 || age > nodeDBNodeExpiration {
- glog.V(logger.Detail).Infof("Bonding %x: known=%t, fails=%d age=%v", id[:8], node != nil, fails, age)
+ log.Trace(fmt.Sprintf("Bonding %x: known=%t, fails=%d age=%v", id[:8], node != nil, fails, age))
tab.bondmu.Lock()
w := tab.bonding[id]
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go
index ae7f97029..eafc3f394 100644
--- a/p2p/discover/udp.go
+++ b/p2p/discover/udp.go
@@ -26,8 +26,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/rlp"
@@ -224,7 +223,7 @@ func ListenUDP(priv *ecdsa.PrivateKey, laddr string, natm nat.Interface, nodeDBP
if err != nil {
return nil, err
}
- glog.V(logger.Info).Infoln("Listening,", tab.self)
+ log.Info(fmt.Sprint("Listening,", tab.self))
return tab, nil
}
@@ -294,7 +293,7 @@ func (t *udp) findnode(toid NodeID, toaddr *net.UDPAddr, target NodeID) ([]*Node
nreceived++
n, err := t.nodeFromRPC(toaddr, rn)
if err != nil {
- glog.V(logger.Detail).Infof("invalid neighbor node (%v) from %v: %v", rn.IP, toaddr, err)
+ log.Trace(fmt.Sprintf("invalid neighbor node (%v) from %v: %v", rn.IP, toaddr, err))
continue
}
nodes = append(nodes, n)
@@ -464,9 +463,9 @@ func (t *udp) send(toaddr *net.UDPAddr, ptype byte, req interface{}) error {
if err != nil {
return err
}
- glog.V(logger.Detail).Infof(">>> %v %T", toaddr, req)
+ log.Trace(fmt.Sprintf(">>> %v %T", toaddr, req))
if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil {
- glog.V(logger.Detail).Infoln("UDP send failed:", err)
+ log.Trace(fmt.Sprint("UDP send failed:", err))
}
return err
}
@@ -476,13 +475,13 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte,
b.Write(headSpace)
b.WriteByte(ptype)
if err := rlp.Encode(b, req); err != nil {
- glog.V(logger.Error).Infoln("error encoding packet:", err)
+ log.Error(fmt.Sprint("error encoding packet:", err))
return nil, err
}
packet := b.Bytes()
sig, err := crypto.Sign(crypto.Keccak256(packet[headSize:]), priv)
if err != nil {
- glog.V(logger.Error).Infoln("could not sign packet:", err)
+ log.Error(fmt.Sprint("could not sign packet:", err))
return nil, err
}
copy(packet[macSize:], sig)
@@ -504,11 +503,11 @@ func (t *udp) readLoop() {
nbytes, from, err := t.conn.ReadFromUDP(buf)
if netutil.IsTemporaryError(err) {
// Ignore temporary read errors.
- glog.V(logger.Debug).Infof("Temporary read error: %v", err)
+ log.Debug(fmt.Sprintf("Temporary read error: %v", err))
continue
} else if err != nil {
// Shut down the loop for permament errors.
- glog.V(logger.Debug).Infof("Read error: %v", err)
+ log.Debug(fmt.Sprintf("Read error: %v", err))
return
}
t.handlePacket(from, buf[:nbytes])
@@ -518,14 +517,14 @@ func (t *udp) readLoop() {
func (t *udp) handlePacket(from *net.UDPAddr, buf []byte) error {
packet, fromID, hash, err := decodePacket(buf)
if err != nil {
- glog.V(logger.Debug).Infof("Bad packet from %v: %v", from, err)
+ log.Debug(fmt.Sprintf("Bad packet from %v: %v", from, err))
return err
}
status := "ok"
if err = packet.handle(t, from, fromID, hash); err != nil {
status = err.Error()
}
- glog.V(logger.Detail).Infof("<<< %v %T: %s", from, packet, status)
+ log.Trace(fmt.Sprintf("<<< %v %T: %s", from, packet, status))
return err
}
diff --git a/p2p/discv5/database.go b/p2p/discv5/database.go
index 44be8a74e..a3b044ec1 100644
--- a/p2p/discv5/database.go
+++ b/p2p/discv5/database.go
@@ -23,13 +23,13 @@ import (
"bytes"
"crypto/rand"
"encoding/binary"
+ "fmt"
"os"
"sync"
"time"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
@@ -192,7 +192,7 @@ func (db *nodeDB) fetchRLP(key []byte, val interface{}) error {
}
err = rlp.DecodeBytes(blob, val)
if err != nil {
- glog.V(logger.Warn).Infof("key %x (%T) %v", key, val, err)
+ log.Warn(fmt.Sprintf("key %x (%T) %v", key, val, err))
}
return err
}
@@ -244,7 +244,7 @@ func (db *nodeDB) expirer() {
select {
case <-tick:
if err := db.expireNodes(); err != nil {
- glog.V(logger.Error).Infof("Failed to expire nodedb items: %v", err)
+ log.Error(fmt.Sprintf("Failed to expire nodedb items: %v", err))
}
case <-db.quit:
@@ -396,9 +396,7 @@ func nextNode(it iterator.Iterator) *Node {
}
var n Node
if err := rlp.DecodeBytes(it.Value(), &n); err != nil {
- if glog.V(logger.Warn) {
- glog.Errorf("invalid node %x: %v", id, err)
- }
+ log.Warn(fmt.Sprintf("invalid node %x: %v", id, err))
continue
}
return &n
diff --git a/p2p/discv5/net.go b/p2p/discv5/net.go
index 74d485836..a39cfcc64 100644
--- a/p2p/discv5/net.go
+++ b/p2p/discv5/net.go
@@ -28,8 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/sha3"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/rlp"
@@ -437,10 +436,10 @@ loop:
if err := net.handle(n, pkt.ev, &pkt); err != nil {
status = err.Error()
}
- if glog.V(logger.Detail) {
- glog.Infof("<<< (%d) %v from %x@%v: %v -> %v (%v)",
+ log.Trace("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprintf("<<< (%d) %v from %x@%v: %v -> %v (%v)",
net.tab.count, pkt.ev, pkt.remoteID[:8], pkt.remoteAddr, prestate, n.state, status)
- }
+ }})
// TODO: persist state if n.state goes >= known, delete if it goes <= known
// State transition timeouts.
@@ -456,10 +455,10 @@ loop:
if err := net.handle(timeout.node, timeout.ev, nil); err != nil {
status = err.Error()
}
- if glog.V(logger.Detail) {
- glog.Infof("--- (%d) %v for %x@%v: %v -> %v (%v)",
+ log.Trace("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprintf("--- (%d) %v for %x@%v: %v -> %v (%v)",
net.tab.count, timeout.ev, timeout.node.ID[:8], timeout.node.addr(), prestate, timeout.node.state, status)
- }
+ }})
// Querying.
case q := <-net.queryReq:
@@ -655,7 +654,7 @@ loop:
}
debugLog("loop stopped")
- glog.V(logger.Debug).Infof("shutting down")
+ log.Debug(fmt.Sprintf("shutting down"))
if net.conn != nil {
net.conn.Close()
}
@@ -685,20 +684,20 @@ func (net *Network) refresh(done chan<- struct{}) {
seeds = net.nursery
}
if len(seeds) == 0 {
- glog.V(logger.Detail).Info("no seed nodes found")
+ log.Trace(fmt.Sprint("no seed nodes found"))
close(done)
return
}
for _, n := range seeds {
- if glog.V(logger.Debug) {
+ log.Debug("", "msg", log.Lazy{Fn: func() string {
var age string
if net.db != nil {
age = time.Since(net.db.lastPong(n.ID)).String()
} else {
age = "unknown"
}
- glog.Infof("seed node (age %s): %v", age, n)
- }
+ return fmt.Sprintf("seed node (age %s): %v", age, n)
+ }})
n = net.internNodeFromDB(n)
if n.state == unknown {
net.transition(n, verifyinit)
@@ -1254,7 +1253,7 @@ func (net *Network) handleNeighboursPacket(n *Node, pkt *ingressPacket) error {
for i, rn := range req.Nodes {
nn, err := net.internNodeFromNeighbours(pkt.remoteAddr, rn)
if err != nil {
- glog.V(logger.Debug).Infof("invalid neighbour (%v) from %x@%v: %v", rn.IP, n.ID[:8], pkt.remoteAddr, err)
+ log.Debug(fmt.Sprintf("invalid neighbour (%v) from %x@%v: %v", rn.IP, n.ID[:8], pkt.remoteAddr, err))
continue
}
nodes[i] = nn
diff --git a/p2p/discv5/ntp.go b/p2p/discv5/ntp.go
index 81c0e6336..f78d5dc43 100644
--- a/p2p/discv5/ntp.go
+++ b/p2p/discv5/ntp.go
@@ -26,8 +26,7 @@ import (
"strings"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
const (
@@ -55,12 +54,12 @@ func checkClockDrift() {
howtofix := fmt.Sprintf("Please enable network time synchronisation in system settings")
separator := strings.Repeat("-", len(warning))
- glog.V(logger.Warn).Info(separator)
- glog.V(logger.Warn).Info(warning)
- glog.V(logger.Warn).Info(howtofix)
- glog.V(logger.Warn).Info(separator)
+ log.Warn(fmt.Sprint(separator))
+ log.Warn(fmt.Sprint(warning))
+ log.Warn(fmt.Sprint(howtofix))
+ log.Warn(fmt.Sprint(separator))
} else {
- glog.V(logger.Debug).Infof("Sanity NTP check reported %v drift, all ok", drift)
+ log.Debug(fmt.Sprintf("Sanity NTP check reported %v drift, all ok", drift))
}
}
diff --git a/p2p/discv5/sim_test.go b/p2p/discv5/sim_test.go
index 3f7fe7463..bf57872e2 100644
--- a/p2p/discv5/sim_test.go
+++ b/p2p/discv5/sim_test.go
@@ -65,10 +65,6 @@ func TestSimTopics(t *testing.T) {
if runWithPlaygroundTime(t) {
return
}
-
- // glog.SetV(6)
- // glog.SetToStderr(true)
-
sim := newSimulation()
bootnode := sim.launchNode(false)
@@ -158,10 +154,6 @@ func TestSimTopicHierarchy(t *testing.T) {
if runWithPlaygroundTime(t) {
return
}
-
- // glog.SetV(6)
- // glog.SetToStderr(true)
-
sim := newSimulation()
bootnode := sim.launchNode(false)
diff --git a/p2p/discv5/udp.go b/p2p/discv5/udp.go
index 6cf6cfbcc..26087cd8e 100644
--- a/p2p/discv5/udp.go
+++ b/p2p/discv5/udp.go
@@ -26,8 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/rlp"
@@ -348,9 +347,9 @@ func (t *udp) sendPacket(toid NodeID, toaddr *net.UDPAddr, ptype byte, req inter
//fmt.Println(err)
return hash, err
}
- glog.V(logger.Detail).Infof(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr)
+ log.Trace(fmt.Sprintf(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr))
if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil {
- glog.V(logger.Detail).Infoln("UDP send failed:", err)
+ log.Trace(fmt.Sprint("UDP send failed:", err))
}
//fmt.Println(err)
return hash, err
@@ -364,13 +363,13 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) (p, hash
b.Write(headSpace)
b.WriteByte(ptype)
if err := rlp.Encode(b, req); err != nil {
- glog.V(logger.Error).Infoln("error encoding packet:", err)
+ log.Error(fmt.Sprint("error encoding packet:", err))
return nil, nil, err
}
packet := b.Bytes()
sig, err := crypto.Sign(crypto.Keccak256(packet[headSize:]), priv)
if err != nil {
- glog.V(logger.Error).Infoln("could not sign packet:", err)
+ log.Error(fmt.Sprint("could not sign packet:", err))
return nil, nil, err
}
copy(packet[macSize:], sig)
@@ -393,11 +392,11 @@ func (t *udp) readLoop() {
nbytes, from, err := t.conn.ReadFromUDP(buf)
if netutil.IsTemporaryError(err) {
// Ignore temporary read errors.
- glog.V(logger.Debug).Infof("Temporary read error: %v", err)
+ log.Debug(fmt.Sprintf("Temporary read error: %v", err))
continue
} else if err != nil {
// Shut down the loop for permament errors.
- glog.V(logger.Debug).Infof("Read error: %v", err)
+ log.Debug(fmt.Sprintf("Read error: %v", err))
return
}
t.handlePacket(from, buf[:nbytes])
@@ -407,7 +406,7 @@ func (t *udp) readLoop() {
func (t *udp) handlePacket(from *net.UDPAddr, buf []byte) error {
pkt := ingressPacket{remoteAddr: from}
if err := decodePacket(buf, &pkt); err != nil {
- glog.V(logger.Debug).Infof("Bad packet from %v: %v", from, err)
+ log.Debug(fmt.Sprintf("Bad packet from %v: %v", from, err))
//fmt.Println("bad packet", err)
return err
}
diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go
index 7eb23fa7b..e5883cf98 100644
--- a/p2p/nat/nat.go
+++ b/p2p/nat/nat.go
@@ -25,8 +25,7 @@ import (
"sync"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/jackpal/go-nat-pmp"
)
@@ -102,13 +101,13 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na
refresh := time.NewTimer(mapUpdateInterval)
defer func() {
refresh.Stop()
- glog.V(logger.Debug).Infof("deleting port mapping: %s %d -> %d (%s) using %s", protocol, extport, intport, name, m)
+ log.Debug(fmt.Sprintf("deleting port mapping: %s %d -> %d (%s) using %s", protocol, extport, intport, name, m))
m.DeleteMapping(protocol, extport, intport)
}()
if err := m.AddMapping(protocol, extport, intport, name, mapTimeout); err != nil {
- glog.V(logger.Debug).Infof("network port %s:%d could not be mapped: %v", protocol, intport, err)
+ log.Debug(fmt.Sprintf("network port %s:%d could not be mapped: %v", protocol, intport, err))
} else {
- glog.V(logger.Info).Infof("mapped network port %s:%d -> %d (%s) using %s", protocol, extport, intport, name, m)
+ log.Info(fmt.Sprintf("mapped network port %s:%d -> %d (%s) using %s", protocol, extport, intport, name, m))
}
for {
select {
@@ -117,9 +116,9 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na
return
}
case <-refresh.C:
- glog.V(logger.Detail).Infof("refresh port mapping %s:%d -> %d (%s) using %s", protocol, extport, intport, name, m)
+ log.Trace(fmt.Sprintf("refresh port mapping %s:%d -> %d (%s) using %s", protocol, extport, intport, name, m))
if err := m.AddMapping(protocol, extport, intport, name, mapTimeout); err != nil {
- glog.V(logger.Debug).Infof("network port %s:%d could not be mapped: %v", protocol, intport, err)
+ log.Debug(fmt.Sprintf("network port %s:%d could not be mapped: %v", protocol, intport, err))
}
refresh.Reset(mapUpdateInterval)
}
diff --git a/p2p/peer.go b/p2p/peer.go
index b21c872d6..5d09927a5 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -25,8 +25,7 @@ import (
"sync"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -157,27 +156,27 @@ loop:
// A write finished. Allow the next write to start if
// there was no error.
if err != nil {
- glog.V(logger.Detail).Infof("%v: write error: %v", p, err)
+ log.Trace(fmt.Sprintf("%v: write error: %v", p, err))
reason = DiscNetworkError
break loop
}
writeStart <- struct{}{}
case err := <-readErr:
if r, ok := err.(DiscReason); ok {
- glog.V(logger.Debug).Infof("%v: remote requested disconnect: %v", p, r)
+ log.Debug(fmt.Sprintf("%v: remote requested disconnect: %v", p, r))
requested = true
reason = r
} else {
- glog.V(logger.Detail).Infof("%v: read error: %v", p, err)
+ log.Trace(fmt.Sprintf("%v: read error: %v", p, err))
reason = DiscNetworkError
}
break loop
case err := <-p.protoErr:
reason = discReasonForError(err)
- glog.V(logger.Debug).Infof("%v: protocol error: %v (%v)", p, err, reason)
+ log.Debug(fmt.Sprintf("%v: protocol error: %v (%v)", p, err, reason))
break loop
case reason = <-p.disc:
- glog.V(logger.Debug).Infof("%v: locally requested disconnect: %v", p, reason)
+ log.Debug(fmt.Sprintf("%v: locally requested disconnect: %v", p, reason))
break loop
}
}
@@ -298,14 +297,14 @@ func (p *Peer) startProtocols(writeStart <-chan struct{}, writeErr chan<- error)
proto.closed = p.closed
proto.wstart = writeStart
proto.werr = writeErr
- glog.V(logger.Detail).Infof("%v: Starting protocol %s/%d", p, proto.Name, proto.Version)
+ log.Trace(fmt.Sprintf("%v: Starting protocol %s/%d", p, proto.Name, proto.Version))
go func() {
err := proto.Run(p, proto)
if err == nil {
- glog.V(logger.Detail).Infof("%v: Protocol %s/%d returned", p, proto.Name, proto.Version)
+ log.Trace(fmt.Sprintf("%v: Protocol %s/%d returned", p, proto.Name, proto.Version))
err = errors.New("protocol returned")
} else if err != io.EOF {
- glog.V(logger.Detail).Infof("%v: Protocol %s/%d error: %v", p, proto.Name, proto.Version, err)
+ log.Trace(fmt.Sprintf("%v: Protocol %s/%d error: %v", p, proto.Name, proto.Version, err))
}
p.protoErr <- err
p.wg.Done()
diff --git a/p2p/server.go b/p2p/server.go
index 298148d3e..9f1478a41 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -25,8 +25,7 @@ import (
"sync"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/discv5"
"github.com/ethereum/go-ethereum/p2p/nat"
@@ -337,7 +336,7 @@ func (srv *Server) Start() (err error) {
return errors.New("server already running")
}
srv.running = true
- glog.V(logger.Info).Infoln("Starting Server")
+ log.Info(fmt.Sprint("Starting Server"))
// static fields
if srv.PrivateKey == nil {
@@ -399,7 +398,7 @@ func (srv *Server) Start() (err error) {
}
}
if srv.NoDial && srv.ListenAddr == "" {
- glog.V(logger.Warn).Infoln("I will be kind-of useless, neither dialing nor listening.")
+ log.Warn(fmt.Sprint("I will be kind-of useless, neither dialing nor listening."))
}
srv.loopWG.Add(1)
@@ -467,7 +466,7 @@ func (srv *Server) run(dialstate dialer) {
i := 0
for ; len(runningTasks) < maxActiveDialTasks && i < len(ts); i++ {
t := ts[i]
- glog.V(logger.Detail).Infoln("new task:", t)
+ log.Trace(fmt.Sprint("new task:", t))
go func() { t.Do(srv); taskdone <- t }()
runningTasks = append(runningTasks, t)
}
@@ -490,19 +489,19 @@ running:
select {
case <-srv.quit:
// The server was stopped. Run the cleanup logic.
- glog.V(logger.Detail).Infoln("<-quit: spinning down")
+ log.Trace(fmt.Sprint("<-quit: spinning down"))
break running
case n := <-srv.addstatic:
// This channel is used by AddPeer to add to the
// ephemeral static peer list. Add it to the dialer,
// it will keep the node connected.
- glog.V(logger.Detail).Infoln("<-addstatic:", n)
+ log.Trace(fmt.Sprint("<-addstatic:", n))
dialstate.addStatic(n)
case n := <-srv.removestatic:
// This channel is used by RemovePeer to send a
// disconnect request to a peer and begin the
// stop keeping the node connected
- glog.V(logger.Detail).Infoln("<-removestatic:", n)
+ log.Trace(fmt.Sprint("<-removestatic:", n))
dialstate.removeStatic(n)
if p, ok := peers[n.ID]; ok {
p.Disconnect(DiscRequested)
@@ -515,7 +514,7 @@ running:
// A task got done. Tell dialstate about it so it
// can update its state and remove it from the active
// tasks list.
- glog.V(logger.Detail).Infoln("<-taskdone:", t)
+ log.Trace(fmt.Sprint("<-taskdone:", t))
dialstate.taskDone(t, time.Now())
delTask(t)
case c := <-srv.posthandshake:
@@ -525,16 +524,16 @@ running:
// Ensure that the trusted flag is set before checking against MaxPeers.
c.flags |= trustedConn
}
- glog.V(logger.Detail).Infoln("<-posthandshake:", c)
+ log.Trace(fmt.Sprint("<-posthandshake:", c))
// TODO: track in-progress inbound node IDs (pre-Peer) to avoid dialing them.
c.cont <- srv.encHandshakeChecks(peers, c)
case c := <-srv.addpeer:
// At this point the connection is past the protocol handshake.
// Its capabilities are known and the remote identity is verified.
- glog.V(logger.Detail).Infoln("<-addpeer:", c)
+ log.Trace(fmt.Sprint("<-addpeer:", c))
err := srv.protoHandshakeChecks(peers, c)
if err != nil {
- glog.V(logger.Detail).Infof("Not adding %v as peer: %v", c, err)
+ log.Trace(fmt.Sprintf("Not adding %v as peer: %v", c, err))
} else {
// The handshakes are done and it passed all checks.
p := newPeer(c, srv.Protocols)
@@ -547,7 +546,7 @@ running:
c.cont <- err
case p := <-srv.delpeer:
// A peer disconnected.
- glog.V(logger.Detail).Infoln("<-delpeer:", p)
+ log.Trace(fmt.Sprint("<-delpeer:", p))
delete(peers, p.ID())
}
}
@@ -566,10 +565,10 @@ running:
// Wait for peers to shut down. Pending connections and tasks are
// not handled here and will terminate soon-ish because srv.quit
// is closed.
- glog.V(logger.Detail).Infof("ignoring %d pending tasks at spindown", len(runningTasks))
+ log.Trace(fmt.Sprintf("ignoring %d pending tasks at spindown", len(runningTasks)))
for len(peers) > 0 {
p := <-srv.delpeer
- glog.V(logger.Detail).Infoln("<-delpeer (spindown):", p)
+ log.Trace(fmt.Sprint("<-delpeer (spindown):", p))
delete(peers, p.ID())
}
}
@@ -605,7 +604,7 @@ type tempError interface {
// inbound connections.
func (srv *Server) listenLoop() {
defer srv.loopWG.Done()
- glog.V(logger.Info).Infoln("Listening on", srv.listener.Addr())
+ log.Info(fmt.Sprint("Listening on", srv.listener.Addr()))
// This channel acts as a semaphore limiting
// active inbound connections that are lingering pre-handshake.
@@ -630,10 +629,10 @@ func (srv *Server) listenLoop() {
for {
fd, err = srv.listener.Accept()
if tempErr, ok := err.(tempError); ok && tempErr.Temporary() {
- glog.V(logger.Debug).Infof("Temporary read error: %v", err)
+ log.Debug(fmt.Sprintf("Temporary read error: %v", err))
continue
} else if err != nil {
- glog.V(logger.Debug).Infof("Read error: %v", err)
+ log.Debug(fmt.Sprintf("Read error: %v", err))
return
}
break
@@ -642,7 +641,7 @@ func (srv *Server) listenLoop() {
// Reject connections that do not match NetRestrict.
if srv.NetRestrict != nil {
if tcp, ok := fd.RemoteAddr().(*net.TCPAddr); ok && !srv.NetRestrict.Contains(tcp.IP) {
- glog.V(logger.Debug).Infof("Rejected conn %v because it is not whitelisted in NetRestrict", fd.RemoteAddr())
+ log.Debug(fmt.Sprintf("Rejected conn %v because it is not whitelisted in NetRestrict", fd.RemoteAddr()))
fd.Close()
slots <- struct{}{}
continue
@@ -650,7 +649,7 @@ func (srv *Server) listenLoop() {
}
fd = newMeteredConn(fd, true)
- glog.V(logger.Debug).Infof("Accepted conn %v", fd.RemoteAddr())
+ log.Debug(fmt.Sprintf("Accepted conn %v", fd.RemoteAddr()))
// Spawn the handler. It will give the slot back when the connection
// has been established.
@@ -677,36 +676,36 @@ func (srv *Server) setupConn(fd net.Conn, flags connFlag, dialDest *discover.Nod
// Run the encryption handshake.
var err error
if c.id, err = c.doEncHandshake(srv.PrivateKey, dialDest); err != nil {
- glog.V(logger.Debug).Infof("%v faild enc handshake: %v", c, err)
+ log.Debug(fmt.Sprintf("%v faild enc handshake: %v", c, err))
c.close(err)
return
}
// For dialed connections, check that the remote public key matches.
if dialDest != nil && c.id != dialDest.ID {
c.close(DiscUnexpectedIdentity)
- glog.V(logger.Debug).Infof("%v dialed identity mismatch, want %x", c, dialDest.ID[:8])
+ log.Debug(fmt.Sprintf("%v dialed identity mismatch, want %x", c, dialDest.ID[:8]))
return
}
if err := srv.checkpoint(c, srv.posthandshake); err != nil {
- glog.V(logger.Debug).Infof("%v failed checkpoint posthandshake: %v", c, err)
+ log.Debug(fmt.Sprintf("%v failed checkpoint posthandshake: %v", c, err))
c.close(err)
return
}
// Run the protocol handshake
phs, err := c.doProtoHandshake(srv.ourHandshake)
if err != nil {
- glog.V(logger.Debug).Infof("%v failed proto handshake: %v", c, err)
+ log.Debug(fmt.Sprintf("%v failed proto handshake: %v", c, err))
c.close(err)
return
}
if phs.ID != c.id {
- glog.V(logger.Debug).Infof("%v wrong proto handshake identity: %x", c, phs.ID[:8])
+ log.Debug(fmt.Sprintf("%v wrong proto handshake identity: %x", c, phs.ID[:8]))
c.close(DiscUnexpectedIdentity)
return
}
c.caps, c.name = phs.Caps, phs.Name
if err := srv.checkpoint(c, srv.addpeer); err != nil {
- glog.V(logger.Debug).Infof("%v failed checkpoint addpeer: %v", c, err)
+ log.Debug(fmt.Sprintf("%v failed checkpoint addpeer: %v", c, err))
c.close(err)
return
}
@@ -734,7 +733,7 @@ func (srv *Server) checkpoint(c *conn, stage chan<- *conn) error {
// it waits until the Peer logic returns and removes
// the peer.
func (srv *Server) runPeer(p *Peer) {
- glog.V(logger.Debug).Infof("Added %v\n", p)
+ log.Debug(fmt.Sprintf("Added %v", p))
if srv.newPeerHook != nil {
srv.newPeerHook(p)
@@ -744,7 +743,7 @@ func (srv *Server) runPeer(p *Peer) {
// before returning, so this send should not select on srv.quit.
srv.delpeer <- p
- glog.V(logger.Debug).Infof("Removed %v (%v)\n", p, discreason)
+ log.Debug(fmt.Sprintf("Removed %v (%v)", p, discreason))
}
// NodeInfo represents a short summary of the information known about the host.
diff --git a/p2p/server_test.go b/p2p/server_test.go
index 313d086ec..46611c7d0 100644
--- a/p2p/server_test.go
+++ b/p2p/server_test.go
@@ -31,8 +31,7 @@ import (
)
func init() {
- // glog.SetV(6)
- // glog.SetToStderr(true)
+ // log.Root().SetHandler(log.LvlFilterHandler(log.LvlError, log.StreamHandler(os.Stderr, log.TerminalFormat())))
}
type testTransport struct {