Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
6451bf20
Commit
6451bf20
authored
Jan 30, 2015
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Feb 01, 2015
Browse files
p2p/net/conn: log conn lifetime event
parent
9d424302
Changes
1
Show whitespace changes
Inline
Side-by-side
net/conn/conn.go
View file @
6451bf20
...
...
@@ -2,6 +2,7 @@ package conn
import
(
"fmt"
"io"
"net"
"time"
...
...
@@ -15,7 +16,7 @@ import (
peer
"github.com/jbenet/go-ipfs/p2p/peer"
eventlog
"github.com/jbenet/go-ipfs/thirdparty/eventlog"
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"
)
...
...
@@ -33,16 +34,19 @@ type singleConn struct {
remote
peer
.
ID
maconn
manet
.
Conn
msgrw
msgio
.
ReadWriteCloser
event
io
.
Closer
}
// newConn constructs a new connection
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
{
local
:
local
,
remote
:
remote
,
maconn
:
maconn
,
msgrw
:
msgio
.
NewReadWriter
(
maconn
),
event
:
log
.
EventBegin
(
ctx
,
"connLifetime"
,
ml
),
}
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
// close is the internal close function, called by ContextCloser.Close
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
return
c
.
msgrw
.
Close
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment