@cryptotaxi247 / kubo / commits / edc7b0f66

update go-peerstream dep

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Dec 7, 2015 at 19:17 UTC edc7b0f666d9d2adb24d7ef58236cf282f267821
4 files changed +25 -4
Godeps/Godeps.json
+1 -1
@@ -200,7 +200,7 @@
200 },
201 {
202 "ImportPath": "github.com/jbenet/go-peerstream",
203 - "Rev": "f90119e97e8be7b2bdd5e598067b0dc44df63381"
203 + "Rev": "f3ab20739a88aa79306dc039c1b5a39e7afa45d6"
204 },
205 {
206 "ImportPath": "github.com/jbenet/go-random",
Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go
+22 -2
@@ -47,6 +47,9 @@ type Conn struct {
47
48 closed bool
49 closeLock sync.Mutex
50 +
51 + closing bool
52 + closingLock sync.Mutex
53 }
54
55 func newConn(nconn net.Conn, tconn smux.Conn, s *Swarm) *Conn {
@@ -115,14 +118,31 @@ func (c *Conn) Streams() []*Stream {
118 return streams
119 }
120
121 +// GoClose spawns off a goroutine to close the connection iff the connection is
122 +// not already being closed and returns immediately
123 +func (c *Conn) GoClose() {
124 + c.closingLock.Lock()
125 + defer c.closingLock.Unlock()
126 + if c.closing {
127 + return
128 + }
129 + c.closing = true
130 +
131 + go c.Close()
132 +}
133 +
134 // Close closes this connection
135 func (c *Conn) Close() error {
136 c.closeLock.Lock()
137 defer c.closeLock.Unlock()
122 -
123 - if c.closed {
138 + if c.closed == true {
139 return nil
140 }
141 +
142 + c.closingLock.Lock()
143 + c.closing = true
144 + c.closingLock.Unlock()
145 +
146 c.closed = true
147
148 // close streams
Godeps/_workspace/src/github.com/jbenet/go-peerstream/muxtest/muxt.go
+1
@@ -14,6 +14,7 @@ import (
14 "testing"
15
16 ps "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
17 +
18 smux "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-stream-muxer"
19 )
20
Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go
+1 -1
@@ -184,7 +184,7 @@ func (s *Swarm) Conns() []*Conn {
184 open := make([]*Conn, 0, len(conns))
185 for _, c := range conns {
186 if c.smuxConn.IsClosed() {
187 - c.Close()
187 + c.GoClose()
188 } else {
189 open = append(open, c)
190 }