aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server.go
diff options
context:
space:
mode:
authorKurkó Mihály <kurkomisi@users.noreply.github.com>2018-10-16 06:40:51 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-10-16 06:40:51 +0800
commit16e4d0e0055f7fce620ff6881a1393d955c06cee (patch)
treec612d19c404de92d63b09bf395a18b11b74cb389 /p2p/server.go
parent331fa6d3075cb89fc295b36d9039620ec1d741ad (diff)
downloaddexon-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.go9
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 {