Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
3d2ba374
Commit
3d2ba374
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved ctxcloser to own pkg
parent
d17292a4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
12 deletions
+18
-12
net/conn/conn.go
net/conn/conn.go
+3
-2
net/conn/interface.go
net/conn/interface.go
+2
-1
net/conn/listen.go
net/conn/listen.go
+3
-2
net/conn/multiconn.go
net/conn/multiconn.go
+3
-2
net/conn/secure_conn.go
net/conn/secure_conn.go
+3
-2
net/swarm/swarm.go
net/swarm/swarm.go
+3
-2
util/ctxcloser/closer.go
util/ctxcloser/closer.go
+1
-1
No files found.
net/conn/conn.go
View file @
3d2ba374
...
...
@@ -11,6 +11,7 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
)
var
log
=
u
.
Logger
(
"conn"
)
...
...
@@ -46,7 +47,7 @@ type singleConn struct {
maconn
manet
.
Conn
msgio
*
msgioPipe
ContextCloser
ctxc
.
ContextCloser
}
// newConn constructs a new connection
...
...
@@ -60,7 +61,7 @@ func newSingleConn(ctx context.Context, local, remote *peer.Peer,
msgio
:
newMsgioPipe
(
10
),
}
conn
.
ContextCloser
=
NewContextCloser
(
ctx
,
conn
.
close
)
conn
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx
,
conn
.
close
)
log
.
Info
(
"newSingleConn: %v to %v"
,
local
,
remote
)
...
...
This diff is collapsed.
Click to expand it.
net/conn/interface.go
View file @
3d2ba374
...
...
@@ -3,6 +3,7 @@ package conn
import
(
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
)
...
...
@@ -13,7 +14,7 @@ type Map map[u.Key]Conn
// Conn is a generic message-based Peer-to-Peer connection.
type
Conn
interface
{
// implement ContextCloser too!
ContextCloser
ctxc
.
ContextCloser
// ID is an identifier unique to this connection.
ID
()
string
...
...
This diff is collapsed.
Click to expand it.
net/conn/listen.go
View file @
3d2ba374
...
...
@@ -6,6 +6,7 @@ import (
manet
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
peer
"github.com/jbenet/go-ipfs/peer"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
)
// listener is an object that can accept connections. It implements Listener
...
...
@@ -31,7 +32,7 @@ type listener struct {
ctx
context
.
Context
// embedded ContextCloser
ContextCloser
ctxc
.
ContextCloser
}
// disambiguate
...
...
@@ -140,7 +141,7 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local *peer.Peer, peers peer
// This is because the parent context will be given to all connections too,
// and if we close the listener, the connections shouldn't share the fate.
ctx2
,
_
:=
context
.
WithCancel
(
ctx
)
l
.
ContextCloser
=
NewContextCloser
(
ctx2
,
l
.
close
)
l
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx2
,
l
.
close
)
go
l
.
listen
()
...
...
This diff is collapsed.
Click to expand it.
net/conn/multiconn.go
View file @
3d2ba374
...
...
@@ -8,6 +8,7 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
)
// MultiConnMap is for shorthand
...
...
@@ -34,7 +35,7 @@ type MultiConn struct {
// for adding/removing connections concurrently
sync
.
RWMutex
ContextCloser
ctxc
.
ContextCloser
}
// NewMultiConn constructs a new connection
...
...
@@ -51,7 +52,7 @@ func NewMultiConn(ctx context.Context, local, remote *peer.Peer, conns []Conn) (
}
// must happen before Adds / fanOut
c
.
ContextCloser
=
NewContextCloser
(
ctx
,
c
.
close
)
c
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx
,
c
.
close
)
if
conns
!=
nil
&&
len
(
conns
)
>
0
{
c
.
Add
(
conns
...
)
...
...
This diff is collapsed.
Click to expand it.
net/conn/secure_conn.go
View file @
3d2ba374
...
...
@@ -8,6 +8,7 @@ import (
spipe
"github.com/jbenet/go-ipfs/crypto/spipe"
peer
"github.com/jbenet/go-ipfs/peer"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
)
// secureConn wraps another Conn object with an encrypted channel.
...
...
@@ -19,7 +20,7 @@ type secureConn struct {
// secure pipe, wrapping insecure
secure
*
spipe
.
SecurePipe
ContextCloser
ctxc
.
ContextCloser
}
// newConn constructs a new connection
...
...
@@ -28,7 +29,7 @@ func newSecureConn(ctx context.Context, insecure Conn, peers peer.Peerstore) (Co
conn
:=
&
secureConn
{
insecure
:
insecure
,
}
conn
.
ContextCloser
=
NewContextCloser
(
ctx
,
conn
.
close
)
conn
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx
,
conn
.
close
)
log
.
Debug
(
"newSecureConn: %v to %v"
,
insecure
.
LocalPeer
(),
insecure
.
RemotePeer
())
// perform secure handshake before returning this connection.
...
...
This diff is collapsed.
Click to expand it.
net/swarm/swarm.go
View file @
3d2ba374
...
...
@@ -9,6 +9,7 @@ import (
msg
"github.com/jbenet/go-ipfs/net/message"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
...
...
@@ -64,7 +65,7 @@ type Swarm struct {
listeners
[]
conn
.
Listener
// ContextCloser
c
onn
.
ContextCloser
c
txc
.
ContextCloser
}
// NewSwarm constructs a Swarm, with a Chan.
...
...
@@ -78,7 +79,7 @@ func NewSwarm(ctx context.Context, local *peer.Peer, ps peer.Peerstore) (*Swarm,
}
// ContextCloser for proper child management.
s
.
ContextCloser
=
c
onn
.
NewContextCloser
(
ctx
,
s
.
close
)
s
.
ContextCloser
=
c
txc
.
NewContextCloser
(
ctx
,
s
.
close
)
go
s
.
fanOut
()
return
s
,
s
.
listen
()
...
...
This diff is collapsed.
Click to expand it.
net/conn
/closer.go
→
util/ctxcloser
/closer.go
View file @
3d2ba374
package
c
onn
package
c
txcloser
import
(
"sync"
...
...
This diff is collapsed.
Click to expand it.
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