diff options
author | Felix Lange <fjl@twurst.com> | 2015-02-20 00:09:33 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-02-20 00:09:33 +0800 |
commit | 3719db352a3de1c7daece71895abdd871616a2aa (patch) | |
tree | 77c1656a0b3ed6bc3493e08b5fa5b681739f58ba | |
parent | fa15854a54d1d4505619aa3b3deabb50cd8ca881 (diff) | |
download | dexon-3719db352a3de1c7daece71895abdd871616a2aa.tar dexon-3719db352a3de1c7daece71895abdd871616a2aa.tar.gz dexon-3719db352a3de1c7daece71895abdd871616a2aa.tar.bz2 dexon-3719db352a3de1c7daece71895abdd871616a2aa.tar.lz dexon-3719db352a3de1c7daece71895abdd871616a2aa.tar.xz dexon-3719db352a3de1c7daece71895abdd871616a2aa.tar.zst dexon-3719db352a3de1c7daece71895abdd871616a2aa.zip |
p2p: emit JSON connect/disconnect events
-rw-r--r-- | p2p/server.go | 13 |
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) { |