Skip to content

Commit 1978077

Browse files
remove goprocess from mock conn and link
1 parent 2b620cf commit 1978077

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ require (
1313
github.com/ipfs/go-datastore v0.5.0
1414
github.com/ipfs/go-ipfs-util v0.0.2
1515
github.com/ipfs/go-log/v2 v2.4.0
16-
github.com/jbenet/goprocess v0.1.4
1716
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
1817
github.com/koron/go-ssdp v0.0.2 // indirect
1918
github.com/libp2p/go-addr-util v0.1.0

p2p/net/mock/mock_conn.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"sync"
88
"sync/atomic"
99

10-
process "github.com/jbenet/goprocess"
1110
ic "github.com/libp2p/go-libp2p-core/crypto"
1211
"github.com/libp2p/go-libp2p-core/network"
1312
"github.com/libp2p/go-libp2p-core/peer"
@@ -40,13 +39,13 @@ type conn struct {
4039
streams list.List
4140
stat network.ConnStats
4241

43-
pairProc, connProc process.Process
42+
closeOnce sync.Once
4443

4544
sync.RWMutex
4645
}
4746

48-
func newConn(p process.Process, ln, rn *peernet, l *link, dir network.Direction) *conn {
49-
c := &conn{net: ln, link: l, pairProc: p}
47+
func newConn(ln, rn *peernet, l *link, dir network.Direction) *conn {
48+
c := &conn{net: ln, link: l}
5049
c.local = ln.peer
5150
c.remote = rn.peer
5251
c.stat.Direction = dir
@@ -65,7 +64,6 @@ func newConn(p process.Process, ln, rn *peernet, l *link, dir network.Direction)
6564

6665
c.localPrivKey = ln.ps.PrivKey(ln.peer)
6766
c.remotePubKey = rn.ps.PubKey(rn.peer)
68-
c.connProc = process.WithParent(c.pairProc)
6967
return c
7068
}
7169

@@ -74,11 +72,11 @@ func (c *conn) ID() string {
7472
}
7573

7674
func (c *conn) Close() error {
77-
return c.pairProc.Close()
78-
}
79-
80-
func (c *conn) setup() {
81-
c.connProc.SetTeardown(c.teardown)
75+
c.closeOnce.Do(func() {
76+
go c.rconn.Close()
77+
c.teardown()
78+
})
79+
return nil
8280
}
8381

8482
func (c *conn) teardown() error {

p2p/net/mock/mock_link.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
"github.com/libp2p/go-libp2p-core/network"
88
"github.com/libp2p/go-libp2p-core/peer"
9-
10-
process "github.com/jbenet/goprocess"
119
)
1210

1311
// link implements mocknet.Link
@@ -33,13 +31,12 @@ func (l *link) newConnPair(dialer *peernet) (*conn, *conn) {
3331
l.RLock()
3432
defer l.RUnlock()
3533

36-
parent := process.WithTeardown(func() error { return nil })
3734
target := l.nets[0]
3835
if target == dialer {
3936
target = l.nets[1]
4037
}
41-
dc := newConn(parent, dialer, target, l, network.DirOutbound)
42-
tc := newConn(parent, target, dialer, l, network.DirInbound)
38+
dc := newConn(dialer, target, l, network.DirOutbound)
39+
tc := newConn(target, dialer, l, network.DirInbound)
4340
dc.rconn = tc
4441
tc.rconn = dc
4542
return dc, tc

p2p/net/mock/mock_peernet.go

-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ func (pn *peernet) remoteOpenedConn(c *conn) {
188188
// to given remote peer over given link
189189
func (pn *peernet) addConn(c *conn) {
190190
defer c.notifLk.Unlock()
191-
// Call this after unlocking as it might cause us to immediately close
192-
// the connection and remove it from the swarm.
193-
c.setup()
194191

195192
pn.notifyAll(func(n network.Notifiee) {
196193
n.Connected(pn, c)

0 commit comments

Comments
 (0)