diff options
author | Kurkó Mihály <kurkomisi@users.noreply.github.com> | 2018-10-16 06:40:51 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-10-16 06:40:51 +0800 |
commit | 16e4d0e0055f7fce620ff6881a1393d955c06cee (patch) | |
tree | c612d19c404de92d63b09bf395a18b11b74cb389 /p2p/server.go | |
parent | 331fa6d3075cb89fc295b36d9039620ec1d741ad (diff) | |
download | dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.tar dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.tar.gz dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.tar.bz2 dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.tar.lz dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.tar.xz dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.tar.zst dexon-16e4d0e0055f7fce620ff6881a1393d955c06cee.zip |
p2p: meter peer traffic, emit metered peer events (#17695)
This change extends the peer metrics collection:
- traces the life-cycle of the peers
- meters the peer traffic separately for every peer
- creates event feed for the peer events
- emits the peer events
Diffstat (limited to 'p2p/server.go')
-rw-r--r-- | p2p/server.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/p2p/server.go b/p2p/server.go index 6482c0401..38a881f7b 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -864,7 +864,11 @@ func (srv *Server) listenLoop() { } } - fd = newMeteredConn(fd, true) + var ip net.IP + if tcp, ok := fd.RemoteAddr().(*net.TCPAddr); ok { + ip = tcp.IP + } + fd = newMeteredConn(fd, true, ip) srv.log.Trace("Accepted connection", "addr", fd.RemoteAddr()) go func() { srv.SetupConn(fd, inboundConn, nil) @@ -917,6 +921,9 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro } else { c.node = nodeFromConn(remotePubkey, c.fd) } + if conn, ok := c.fd.(*meteredConn); ok { + conn.handshakeDone(c.node.ID()) + } clog := srv.log.New("id", c.node.ID(), "addr", c.fd.RemoteAddr(), "conn", c.flags) err = srv.checkpoint(c, srv.posthandshake) if err != nil { |