aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-02-20 00:09:33 +0800
committerFelix Lange <fjl@twurst.com>2015-02-20 00:09:33 +0800
commit3719db352a3de1c7daece71895abdd871616a2aa (patch)
tree77c1656a0b3ed6bc3493e08b5fa5b681739f58ba /p2p
parentfa15854a54d1d4505619aa3b3deabb50cd8ca881 (diff)
downloadgo-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.tar
go-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.tar.gz
go-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.tar.bz2
go-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.tar.lz
go-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.tar.xz
go-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.tar.zst
go-tangerine-3719db352a3de1c7daece71895abdd871616a2aa.zip
p2p: emit JSON connect/disconnect events
Diffstat (limited to 'p2p')
-rw-r--r--p2p/server.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/p2p/server.go b/p2p/server.go
index 923716011..3ea2538d1 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -22,6 +22,7 @@ const (
)
var srvlog = logger.NewLogger("P2P Server")
+var srvjslog = logger.NewJsonLogger()
// MakeName creates a node name that follows the ethereum convention
// for such names. It adds the operation system name and Go runtime version
@@ -370,14 +371,26 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
p.politeDisconnect(reason)
return
}
+
srvlog.Debugf("Added %v\n", p)
+ srvjslog.LogJson(&logger.P2PConnected{
+ RemoteId: fmt.Sprintf("%x", conn.ID[:]),
+ RemoteAddress: conn.RemoteAddr().String(),
+ RemoteVersionString: conn.Name,
+ NumConnections: srv.PeerCount(),
+ })
if srv.newPeerHook != nil {
srv.newPeerHook(p)
}
discreason := p.run()
srv.removePeer(p)
+
srvlog.Debugf("Removed %v (%v)\n", p, discreason)
+ srvjslog.LogJson(&logger.P2PDisconnected{
+ RemoteId: fmt.Sprintf("%x", conn.ID[:]),
+ NumConnections: srv.PeerCount(),
+ })
}
func (srv *Server) addPeer(id discover.NodeID, p *Peer) (bool, DiscReason) {