From c14900dbb007af8aefc5f5583f3c17a613c66802 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 21 Jan 2015 11:47:21 -0600 Subject: Add initial P2P json logs --- p2p/server.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'p2p/server.go') diff --git a/p2p/server.go b/p2p/server.go index 4fd1f7d03..7dcbc9d11 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" ) @@ -20,6 +21,8 @@ const ( var srvlog = logger.NewLogger("P2P Server") +var jsonlogger = logger.NewJsonLogger() + // Server manages all peer connections. // // The fields of Server are used as configuration parameters. @@ -353,9 +356,25 @@ func (srv *Server) dialLoop() { // connect to peer via dial out func (srv *Server) dialPeer(desc *peerAddr, slot int) { srvlog.Debugf("Dialing %v (slot %d)\n", desc, slot) + evd := map[string]interface{}{ + "remote_id": ethutil.Bytes2Hex(desc.Pubkey), + "remote_endpoint": desc.String(), + "level": "debug", + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + } + jsonlogger.LogJson("p2p.connecting", evd) conn, err := srv.Dialer.Dial(desc.Network(), desc.String()) if err != nil { srvlog.DebugDetailf("dial error: %v", err) + evd := map[string]interface{}{ + "reason": "dial error", + "remote_id": desc.String(), + "level": "debug", + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + } + jsonlogger.LogJson("p2p.disconnecting", evd) srv.peerSlots <- slot return } @@ -375,7 +394,17 @@ func (srv *Server) addPeer(conn net.Conn, desc *peerAddr, slot int) *Peer { peer.slot = slot srv.peers[slot] = peer srv.peerCount++ - go func() { peer.loop(); srv.peerDisconnect <- peer }() + go func() { + evd := map[string]interface{}{ + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + "remote_id": desc.String(), + "level": "debug", + } + jsonlogger.LogJson("p2p.connected", evd) + peer.loop() + srv.peerDisconnect <- peer + }() return peer } @@ -393,13 +422,36 @@ func (srv *Server) removePeer(peer *Peer) { srv.peers[peer.slot] = nil // release slot to signal need for a new peer, last! srv.peerSlots <- peer.slot + evd := map[string]interface{}{ + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + "remote_id": ethutil.Bytes2Hex(peer.Identity().Pubkey()), + "level": "debug", + } + jsonlogger.LogJson("p2p.disconnected", evd) } func (srv *Server) verifyPeer(addr *peerAddr) error { if srv.Blacklist.Exists(addr.Pubkey) { + evd := map[string]interface{}{ + "reason": "blacklisted", + "remote_id": addr.String(), + "level": "debug", + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + } + jsonlogger.LogJson("p2p.disconnecting.reputation", evd) return errors.New("blacklisted") } if bytes.Equal(srv.Identity.Pubkey()[1:], addr.Pubkey) { + evd := map[string]interface{}{ + "reason": "not allowed to connect to srv", + "remote_id": addr.String(), + "level": "debug", + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + } + jsonlogger.LogJson("p2p.disconnecting", evd) return newPeerError(errPubkeyForbidden, "not allowed to connect to srv") } srv.lock.RLock() @@ -408,6 +460,14 @@ func (srv *Server) verifyPeer(addr *peerAddr) error { if peer != nil { id := peer.Identity() if id != nil && bytes.Equal(id.Pubkey(), addr.Pubkey) { + evd := map[string]interface{}{ + "reason": "already connected", + "remote_id": addr.String(), + "level": "debug", + "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), + "num_connections": srv.PeerCount(), + } + jsonlogger.LogJson("p2p.disconnecting", evd) return errors.New("already connected") } } -- cgit v1.2.3 From d53e5646ecfce75790fea45a1ee552494ef88668 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 10 Feb 2015 19:21:13 +0100 Subject: Use strongly-typed objects --- p2p/server.go | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) (limited to 'p2p/server.go') diff --git a/p2p/server.go b/p2p/server.go index 7dcbc9d11..ee2d26dbe 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -8,7 +8,6 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" ) @@ -356,25 +355,9 @@ func (srv *Server) dialLoop() { // connect to peer via dial out func (srv *Server) dialPeer(desc *peerAddr, slot int) { srvlog.Debugf("Dialing %v (slot %d)\n", desc, slot) - evd := map[string]interface{}{ - "remote_id": ethutil.Bytes2Hex(desc.Pubkey), - "remote_endpoint": desc.String(), - "level": "debug", - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - } - jsonlogger.LogJson("p2p.connecting", evd) conn, err := srv.Dialer.Dial(desc.Network(), desc.String()) if err != nil { srvlog.DebugDetailf("dial error: %v", err) - evd := map[string]interface{}{ - "reason": "dial error", - "remote_id": desc.String(), - "level": "debug", - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - } - jsonlogger.LogJson("p2p.disconnecting", evd) srv.peerSlots <- slot return } @@ -395,13 +378,6 @@ func (srv *Server) addPeer(conn net.Conn, desc *peerAddr, slot int) *Peer { srv.peers[slot] = peer srv.peerCount++ go func() { - evd := map[string]interface{}{ - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - "remote_id": desc.String(), - "level": "debug", - } - jsonlogger.LogJson("p2p.connected", evd) peer.loop() srv.peerDisconnect <- peer }() @@ -422,36 +398,13 @@ func (srv *Server) removePeer(peer *Peer) { srv.peers[peer.slot] = nil // release slot to signal need for a new peer, last! srv.peerSlots <- peer.slot - evd := map[string]interface{}{ - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - "remote_id": ethutil.Bytes2Hex(peer.Identity().Pubkey()), - "level": "debug", - } - jsonlogger.LogJson("p2p.disconnected", evd) } func (srv *Server) verifyPeer(addr *peerAddr) error { if srv.Blacklist.Exists(addr.Pubkey) { - evd := map[string]interface{}{ - "reason": "blacklisted", - "remote_id": addr.String(), - "level": "debug", - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - } - jsonlogger.LogJson("p2p.disconnecting.reputation", evd) return errors.New("blacklisted") } if bytes.Equal(srv.Identity.Pubkey()[1:], addr.Pubkey) { - evd := map[string]interface{}{ - "reason": "not allowed to connect to srv", - "remote_id": addr.String(), - "level": "debug", - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - } - jsonlogger.LogJson("p2p.disconnecting", evd) return newPeerError(errPubkeyForbidden, "not allowed to connect to srv") } srv.lock.RLock() @@ -460,14 +413,6 @@ func (srv *Server) verifyPeer(addr *peerAddr) error { if peer != nil { id := peer.Identity() if id != nil && bytes.Equal(id.Pubkey(), addr.Pubkey) { - evd := map[string]interface{}{ - "reason": "already connected", - "remote_id": addr.String(), - "level": "debug", - "guid": ethutil.Bytes2Hex(srv.Identity.Pubkey()), - "num_connections": srv.PeerCount(), - } - jsonlogger.LogJson("p2p.disconnecting", evd) return errors.New("already connected") } } -- cgit v1.2.3 From db24fb792cf0dab91bc85e79aecf6758349002a4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Feb 2015 18:49:00 +0100 Subject: Move standard fields to LogEvent --- p2p/server.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'p2p/server.go') diff --git a/p2p/server.go b/p2p/server.go index ee2d26dbe..e0d9f18a5 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -20,8 +20,6 @@ const ( var srvlog = logger.NewLogger("P2P Server") -var jsonlogger = logger.NewJsonLogger() - // Server manages all peer connections. // // The fields of Server are used as configuration parameters. -- cgit v1.2.3