aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-07 20:57:04 +0800
committerobscuren <geffobscura@gmail.com>2015-04-07 20:57:04 +0800
commit688d118c7e0d439691e84fc6e068ab3e19da5185 (patch)
tree6891a60950e0c2956c9f2d4fed6fceb67430775c /p2p
parent01b2c90179ff82e4610745aea0e3e3ca53756305 (diff)
downloadgo-tangerine-688d118c7e0d439691e84fc6e068ab3e19da5185.tar.gz
go-tangerine-688d118c7e0d439691e84fc6e068ab3e19da5185.tar.zst
go-tangerine-688d118c7e0d439691e84fc6e068ab3e19da5185.zip
Updated logging
Diffstat (limited to 'p2p')
-rw-r--r--p2p/discover/udp.go19
-rw-r--r--p2p/nat/nat.go13
-rw-r--r--p2p/server.go24
3 files changed, 27 insertions, 29 deletions
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go
index e9ede1397..a638a8f35 100644
--- a/p2p/discover/udp.go
+++ b/p2p/discover/udp.go
@@ -10,12 +10,11 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/rlp"
)
-var log = logger.NewLogger("P2P Discovery")
-
const Version = 3
// Errors
@@ -155,7 +154,7 @@ func ListenUDP(priv *ecdsa.PrivateKey, laddr string, natm nat.Interface) (*Table
return nil, err
}
tab, _ := newUDP(priv, conn, natm)
- log.Infoln("Listening,", tab.self)
+ glog.V(logger.Info).Infoln("Listening,", tab.self)
return tab, nil
}
@@ -336,9 +335,9 @@ func (t *udp) send(toaddr *net.UDPAddr, ptype byte, req interface{}) error {
if err != nil {
return err
}
- log.DebugDetailf(">>> %v %T %v\n", toaddr, req, req)
+ glog.V(logger.Detail).Infof(">>> %v %T %v\n", toaddr, req, req)
if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil {
- log.DebugDetailln("UDP send failed:", err)
+ glog.V(logger.Detail).Infoln("UDP send failed:", err)
}
return err
}
@@ -348,13 +347,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 {
- log.Errorln("error encoding packet:", err)
+ glog.V(logger.Error).Infoln("error encoding packet:", err)
return nil, err
}
packet := b.Bytes()
sig, err := crypto.Sign(crypto.Sha3(packet[headSize:]), priv)
if err != nil {
- log.Errorln("could not sign packet:", err)
+ glog.V(logger.Error).Infoln("could not sign packet:", err)
return nil, err
}
copy(packet[macSize:], sig)
@@ -376,13 +375,13 @@ func (t *udp) readLoop() {
}
packet, fromID, hash, err := decodePacket(buf[:nbytes])
if err != nil {
- log.Debugf("Bad packet from %v: %v\n", from, err)
+ glog.V(logger.Debug).Infof("Bad packet from %v: %v\n", from, err)
continue
}
- log.DebugDetailf("<<< %v %T %v\n", from, packet, packet)
+ glog.V(logger.Detail).Infof("<<< %v %T %v\n", from, packet, packet)
go func() {
if err := packet.handle(t, from, fromID, hash); err != nil {
- log.Debugf("error handling %T from %v: %v", packet, from, err)
+ glog.V(logger.Debug).Infof("error handling %T from %v: %v", packet, from, err)
}
}()
}
diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go
index 12d355ba1..4ae7e6b17 100644
--- a/p2p/nat/nat.go
+++ b/p2p/nat/nat.go
@@ -10,11 +10,10 @@ import (
"time"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/jackpal/go-nat-pmp"
)
-var log = logger.NewLogger("P2P NAT")
-
// An implementation of nat.Interface can map local ports to ports
// accessible from the Internet.
type Interface interface {
@@ -87,12 +86,12 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na
refresh := time.NewTimer(mapUpdateInterval)
defer func() {
refresh.Stop()
- log.Debugf("Deleting port mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m)
+ glog.V(logger.Debug).Infof("Deleting port mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m)
m.DeleteMapping(protocol, extport, intport)
}()
- log.Debugf("add mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m)
+ glog.V(logger.Debug).Infof("add mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m)
if err := m.AddMapping(protocol, intport, extport, name, mapTimeout); err != nil {
- log.Errorf("mapping error: %v\n", err)
+ glog.V(logger.Error).Infof("mapping error: %v\n", err)
}
for {
select {
@@ -101,9 +100,9 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na
return
}
case <-refresh.C:
- log.DebugDetailf("refresh mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m)
+ glog.V(logger.Detail).Infof("refresh mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m)
if err := m.AddMapping(protocol, intport, extport, name, mapTimeout); err != nil {
- log.Errorf("mapping error: %v\n", err)
+ glog.V(logger.Error).Infof("mapping error: %v\n", err)
}
refresh.Reset(mapUpdateInterval)
}
diff --git a/p2p/server.go b/p2p/server.go
index 813b0676f..0a2621aa8 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/rlp"
@@ -29,7 +30,6 @@ const (
frameWriteTimeout = 5 * time.Second
)
-var srvlog = logger.NewLogger("P2P Server")
var srvjslog = logger.NewJsonLogger()
// Server manages all peer connections.
@@ -161,7 +161,7 @@ func (srv *Server) Start() (err error) {
if srv.running {
return errors.New("server already running")
}
- srvlog.Infoln("Starting Server")
+ glog.V(logger.Info).Infoln("Starting Server")
// static fields
if srv.PrivateKey == nil {
@@ -204,7 +204,7 @@ func (srv *Server) Start() (err error) {
go srv.dialLoop()
}
if srv.NoDial && srv.ListenAddr == "" {
- srvlog.Warnln("I will be kind-of useless, neither dialing nor listening.")
+ glog.V(logger.Warn).Infoln("I will be kind-of useless, neither dialing nor listening.")
}
srv.running = true
@@ -242,7 +242,7 @@ func (srv *Server) Stop() {
srv.running = false
srv.lock.Unlock()
- srvlog.Infoln("Stopping Server")
+ glog.V(logger.Info).Infoln("Stopping Server")
srv.ntab.Close()
if srv.listener != nil {
// this unblocks listener Accept
@@ -263,13 +263,13 @@ func (srv *Server) Stop() {
// main loop for adding connections via listening
func (srv *Server) listenLoop() {
defer srv.loopWG.Done()
- srvlog.Infoln("Listening on", srv.listener.Addr())
+ glog.V(logger.Info).Infoln("Listening on", srv.listener.Addr())
for {
conn, err := srv.listener.Accept()
if err != nil {
return
}
- srvlog.Debugf("Accepted conn %v\n", conn.RemoteAddr())
+ glog.V(logger.Debug).Infof("Accepted conn %v\n", conn.RemoteAddr())
srv.peerWG.Add(1)
go srv.startPeer(conn, nil)
}
@@ -328,10 +328,10 @@ func (srv *Server) dialLoop() {
func (srv *Server) dialNode(dest *discover.Node) {
addr := &net.TCPAddr{IP: dest.IP, Port: dest.TCPPort}
- srvlog.Debugf("Dialing %v\n", dest)
+ glog.V(logger.Debug).Infof("Dialing %v\n", dest)
conn, err := srv.Dialer.Dial("tcp", addr.String())
if err != nil {
- srvlog.DebugDetailf("dial error: %v", err)
+ glog.V(logger.Detail).Infof("dial error: %v", err)
return
}
srv.startPeer(conn, dest)
@@ -365,7 +365,7 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
conn, err := srv.setupFunc(fd, srv.PrivateKey, srv.ourHandshake, dest)
if err != nil {
fd.Close()
- srvlog.Debugf("Handshake with %v failed: %v", fd.RemoteAddr(), err)
+ glog.V(logger.Debug).Infof("Handshake with %v failed: %v", fd.RemoteAddr(), err)
return
}
@@ -375,12 +375,12 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
}
p := newPeer(fd, conn, srv.Protocols)
if ok, reason := srv.addPeer(conn.ID, p); !ok {
- srvlog.DebugDetailf("Not adding %v (%v)\n", p, reason)
+ glog.V(logger.Detail).Infof("Not adding %v (%v)\n", p, reason)
p.politeDisconnect(reason)
return
}
- srvlog.Debugf("Added %v\n", p)
+ glog.V(logger.Debug).Infof("Added %v\n", p)
srvjslog.LogJson(&logger.P2PConnected{
RemoteId: fmt.Sprintf("%x", conn.ID[:]),
RemoteAddress: fd.RemoteAddr().String(),
@@ -394,7 +394,7 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
discreason := p.run()
srv.removePeer(p)
- srvlog.Debugf("Removed %v (%v)\n", p, discreason)
+ glog.V(logger.Debug).Infof("Removed %v (%v)\n", p, discreason)
srvjslog.LogJson(&logger.P2PDisconnected{
RemoteId: fmt.Sprintf("%x", conn.ID[:]),
NumConnections: srv.PeerCount(),