Commit 3d2ba374 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

moved ctxcloser to own pkg

parent d17292a4
......@@ -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)
......
......@@ -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
......
......@@ -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()
......
......@@ -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...)
......
......@@ -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.
......
......@@ -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
conn.ContextCloser
ctxc.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 = conn.NewContextCloser(ctx, s.close)
s.ContextCloser = ctxc.NewContextCloser(ctx, s.close)
go s.fanOut()
return s, s.listen()
......
package conn
package ctxcloser
import (
"sync"
......
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