moved ctxcloser to own pkg
Juan Batiz-Benet committed
Oct 19, 2014 at 06:38 UTC
3d2ba374454f003f500d1b88effe648c8935572a
7 files changed
+18
-12
net/conn/conn.go
+3
-2
@@ -11,6 +11,7 @@ import (
11
12
peer "github.com/jbenet/go-ipfs/peer"
13
u "github.com/jbenet/go-ipfs/util"
14
+ ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
15
)
16
17
var log = u.Logger("conn")
@@ -46,7 +47,7 @@ type singleConn struct {
47
maconn manet.Conn
48
msgio *msgioPipe
49
49
- ContextCloser
50
+ ctxc.ContextCloser
51
}
52
53
// newConn constructs a new connection
@@ -60,7 +61,7 @@ func newSingleConn(ctx context.Context, local, remote *peer.Peer,
61
msgio: newMsgioPipe(10),
62
}
63
63
- conn.ContextCloser = NewContextCloser(ctx, conn.close)
64
+ conn.ContextCloser = ctxc.NewContextCloser(ctx, conn.close)
65
66
log.Info("newSingleConn: %v to %v", local, remote)
67
net/conn/interface.go
+2
-1
@@ -3,6 +3,7 @@ package conn
3
import (
4
peer "github.com/jbenet/go-ipfs/peer"
5
u "github.com/jbenet/go-ipfs/util"
6
+ ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
7
8
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
9
)
@@ -13,7 +14,7 @@ type Map map[u.Key]Conn
14
// Conn is a generic message-based Peer-to-Peer connection.
15
type Conn interface {
16
// implement ContextCloser too!
16
- ContextCloser
17
+ ctxc.ContextCloser
18
19
// ID is an identifier unique to this connection.
20
ID() string
net/conn/listen.go
+3
-2
@@ -6,6 +6,7 @@ import (
6
manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
7
8
peer "github.com/jbenet/go-ipfs/peer"
9
+ ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
10
)
11
12
// listener is an object that can accept connections. It implements Listener
@@ -31,7 +32,7 @@ type listener struct {
32
ctx context.Context
33
34
// embedded ContextCloser
34
- ContextCloser
35
+ ctxc.ContextCloser
36
}
37
38
// disambiguate
@@ -140,7 +141,7 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local *peer.Peer, peers peer
141
// This is because the parent context will be given to all connections too,
142
// and if we close the listener, the connections shouldn't share the fate.
143
ctx2, _ := context.WithCancel(ctx)
143
- l.ContextCloser = NewContextCloser(ctx2, l.close)
144
+ l.ContextCloser = ctxc.NewContextCloser(ctx2, l.close)
145
146
go l.listen()
147
net/conn/multiconn.go
+3
-2
@@ -8,6 +8,7 @@ import (
8
9
peer "github.com/jbenet/go-ipfs/peer"
10
u "github.com/jbenet/go-ipfs/util"
11
+ ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
12
)
13
14
// MultiConnMap is for shorthand
@@ -34,7 +35,7 @@ type MultiConn struct {
35
36
// for adding/removing connections concurrently
37
sync.RWMutex
37
- ContextCloser
38
+ ctxc.ContextCloser
39
}
40
41
// NewMultiConn constructs a new connection
@@ -51,7 +52,7 @@ func NewMultiConn(ctx context.Context, local, remote *peer.Peer, conns []Conn) (
52
}
53
54
// must happen before Adds / fanOut
54
- c.ContextCloser = NewContextCloser(ctx, c.close)
55
+ c.ContextCloser = ctxc.NewContextCloser(ctx, c.close)
56
57
if conns != nil && len(conns) > 0 {
58
c.Add(conns...)
net/conn/secure_conn.go
+3
-2
@@ -8,6 +8,7 @@ import (
8
9
spipe "github.com/jbenet/go-ipfs/crypto/spipe"
10
peer "github.com/jbenet/go-ipfs/peer"
11
+ ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
12
)
13
14
// secureConn wraps another Conn object with an encrypted channel.
@@ -19,7 +20,7 @@ type secureConn struct {
20
// secure pipe, wrapping insecure
21
secure *spipe.SecurePipe
22
22
- ContextCloser
23
+ ctxc.ContextCloser
24
}
25
26
// newConn constructs a new connection
@@ -28,7 +29,7 @@ func newSecureConn(ctx context.Context, insecure Conn, peers peer.Peerstore) (Co
29
conn := &secureConn{
30
insecure: insecure,
31
}
31
- conn.ContextCloser = NewContextCloser(ctx, conn.close)
32
+ conn.ContextCloser = ctxc.NewContextCloser(ctx, conn.close)
33
34
log.Debug("newSecureConn: %v to %v", insecure.LocalPeer(), insecure.RemotePeer())
35
// perform secure handshake before returning this connection.
net/swarm/swarm.go
+3
-2
@@ -9,6 +9,7 @@ import (
9
msg "github.com/jbenet/go-ipfs/net/message"
10
peer "github.com/jbenet/go-ipfs/peer"
11
u "github.com/jbenet/go-ipfs/util"
12
+ ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
13
14
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
15
)
@@ -64,7 +65,7 @@ type Swarm struct {
65
listeners []conn.Listener
66
67
// ContextCloser
67
- conn.ContextCloser
68
+ ctxc.ContextCloser
69
}
70
71
// NewSwarm constructs a Swarm, with a Chan.
@@ -78,7 +79,7 @@ func NewSwarm(ctx context.Context, local *peer.Peer, ps peer.Peerstore) (*Swarm,
79
}
80
81
// ContextCloser for proper child management.
81
- s.ContextCloser = conn.NewContextCloser(ctx, s.close)
82
+ s.ContextCloser = ctxc.NewContextCloser(ctx, s.close)
83
84
go s.fanOut()
85
return s, s.listen()
util/ctxcloser/closer.go
renamed
+1
-1
@@ -1,4 +1,4 @@
1
-package conn
1
+package ctxcloser
2
3
import (
4
"sync"