Commit 6451bf20 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet Committed by Brian Tiger Chow
Browse files

p2p/net/conn: log conn lifetime event

parent 9d424302
...@@ -2,6 +2,7 @@ package conn ...@@ -2,6 +2,7 @@ package conn
import ( import (
"fmt" "fmt"
"io"
"net" "net"
"time" "time"
...@@ -15,7 +16,7 @@ import ( ...@@ -15,7 +16,7 @@ import (
peer "github.com/jbenet/go-ipfs/p2p/peer" peer "github.com/jbenet/go-ipfs/p2p/peer"
eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog" eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
debugerr "github.com/jbenet/go-ipfs/util/debugerror" lgbl "github.com/jbenet/go-ipfs/util/eventlog/loggables"
) )
var log = eventlog.Logger("conn") var log = eventlog.Logger("conn")
...@@ -33,16 +34,19 @@ type singleConn struct { ...@@ -33,16 +34,19 @@ type singleConn struct {
remote peer.ID remote peer.ID
maconn manet.Conn maconn manet.Conn
msgrw msgio.ReadWriteCloser msgrw msgio.ReadWriteCloser
event io.Closer
} }
// newConn constructs a new connection // newConn constructs a new connection
func newSingleConn(ctx context.Context, local, remote peer.ID, maconn manet.Conn) (Conn, error) { func newSingleConn(ctx context.Context, local, remote peer.ID, maconn manet.Conn) (Conn, error) {
ml := lgbl.Dial("conn", local, remote, maconn.LocalMultiaddr(), maconn.RemoteMultiaddr())
conn := &singleConn{ conn := &singleConn{
local: local, local: local,
remote: remote, remote: remote,
maconn: maconn, maconn: maconn,
msgrw: msgio.NewReadWriter(maconn), msgrw: msgio.NewReadWriter(maconn),
event: log.EventBegin(ctx, "connLifetime", ml),
} }
log.Debugf("newSingleConn %p: %v to %v", conn, local, remote) log.Debugf("newSingleConn %p: %v to %v", conn, local, remote)
...@@ -51,7 +55,13 @@ func newSingleConn(ctx context.Context, local, remote peer.ID, maconn manet.Conn ...@@ -51,7 +55,13 @@ func newSingleConn(ctx context.Context, local, remote peer.ID, maconn manet.Conn
// close is the internal close function, called by ContextCloser.Close // close is the internal close function, called by ContextCloser.Close
func (c *singleConn) Close() error { func (c *singleConn) Close() error {
log.Debug(debugerr.Errorf("%s closing Conn with %s", c.local, c.remote)) defer func() {
if c.event != nil {
c.event.Close()
c.event = nil
}
}()
// close underlying connection // close underlying connection
return c.msgrw.Close() return c.msgrw.Close()
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment