Skip to content

Commit

Permalink
remove goprocess from mock conn and link
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Dec 14, 2021
1 parent 2b620cf commit 9f0896c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
1 change: 0 additions & 1 deletion examples/pubsub/chat/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABo
github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk=
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY=
github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o=
github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/ipfs/go-datastore v0.5.0
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-log/v2 v2.4.0
github.com/jbenet/goprocess v0.1.4
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/koron/go-ssdp v0.0.2 // indirect
github.com/libp2p/go-addr-util v0.1.0
Expand Down
18 changes: 8 additions & 10 deletions p2p/net/mock/mock_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sync"
"sync/atomic"

process "github.com/jbenet/goprocess"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -40,13 +39,13 @@ type conn struct {
streams list.List
stat network.ConnStats

pairProc, connProc process.Process
closeOnce sync.Once

sync.RWMutex
}

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

c.localPrivKey = ln.ps.PrivKey(ln.peer)
c.remotePubKey = rn.ps.PubKey(rn.peer)
c.connProc = process.WithParent(c.pairProc)
return c
}

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

func (c *conn) Close() error {
return c.pairProc.Close()
}

func (c *conn) setup() {
c.connProc.SetTeardown(c.teardown)
c.closeOnce.Do(func() {
go c.rconn.Close()
c.teardown()
})
return nil
}

func (c *conn) teardown() error {
Expand Down
7 changes: 2 additions & 5 deletions p2p/net/mock/mock_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"

process "github.com/jbenet/goprocess"
)

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

parent := process.WithTeardown(func() error { return nil })
target := l.nets[0]
if target == dialer {
target = l.nets[1]
}
dc := newConn(parent, dialer, target, l, network.DirOutbound)
tc := newConn(parent, target, dialer, l, network.DirInbound)
dc := newConn(dialer, target, l, network.DirOutbound)
tc := newConn(target, dialer, l, network.DirInbound)
dc.rconn = tc
tc.rconn = dc
return dc, tc
Expand Down
3 changes: 0 additions & 3 deletions p2p/net/mock/mock_peernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ func (pn *peernet) remoteOpenedConn(c *conn) {
// to given remote peer over given link
func (pn *peernet) addConn(c *conn) {
defer c.notifLk.Unlock()
// Call this after unlocking as it might cause us to immediately close
// the connection and remove it from the swarm.
c.setup()

pn.notifyAll(func(n network.Notifiee) {
n.Connected(pn, c)
Expand Down

0 comments on commit 9f0896c

Please sign in to comment.