Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yamux: pass constructors for peer resource scopes to session constructor #1739

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/libp2p/go-netroute v0.2.0
github.com/libp2p/go-openssl v0.1.0
github.com/libp2p/go-reuseport v0.2.0
github.com/libp2p/go-yamux/v3 v3.1.2
github.com/libp2p/go-yamux/v4 v4.0.0
github.com/libp2p/zeroconf/v2 v2.2.0
github.com/lucas-clemente/quic-go v0.29.0
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ github.com/libp2p/go-openssl v0.1.0/go.mod h1:OiOxwPpL3n4xlenjx2h7AwSGaFSC/KZvf6
github.com/libp2p/go-reuseport v0.2.0 h1:18PRvIMlpY6ZK85nIAicSBuXXvrYoSw3dsBAR7zc560=
github.com/libp2p/go-reuseport v0.2.0/go.mod h1:bvVho6eLMm6Bz5hmU0LYN3ixd3nPPvtIlaURZZgOY4k=
github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k=
github.com/libp2p/go-yamux/v3 v3.1.2 h1:lNEy28MBk1HavUAlzKgShp+F6mn/ea1nDYWftZhFW9Q=
github.com/libp2p/go-yamux/v3 v3.1.2/go.mod h1:jeLEQgLXqE2YqX1ilAClIfCMDY+0uXQUKmmb/qp0gT4=
github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ=
github.com/libp2p/go-yamux/v4 v4.0.0/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4=
github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q=
github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs=
github.com/lucas-clemente/quic-go v0.29.0 h1:Vw0mGTfmWqGzh4jx/kMymsIkFK6rErFVmg+t9RLrnZE=
Expand Down
12 changes: 11 additions & 1 deletion p2p/muxer/testsuite/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ func (p *peerScope) Check(t *testing.T) {
require.Zero(t, p.memory, "expected all reserved memory to have been released")
}

type peerScopeSpan struct {
peerScope
}

func (p *peerScopeSpan) Done() {
p.mx.Lock()
defer p.mx.Unlock()
p.memory = 0
}

func (p *peerScope) Stat() network.ScopeStat { return network.ScopeStat{} }
func (p *peerScope) BeginSpan() (network.ResourceScopeSpan, error) { return nil, nil }
func (p *peerScope) BeginSpan() (network.ResourceScopeSpan, error) { return &peerScopeSpan{}, nil }
func (p *peerScope) Peer() peer.ID { panic("implement me") }

var _ network.PeerScope = &peerScope{}
Expand Down
2 changes: 1 addition & 1 deletion p2p/muxer/yamux/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

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

"github.com/libp2p/go-yamux/v3"
"github.com/libp2p/go-yamux/v4"
)

// conn implements mux.MuxedConn over yamux.Session.
Expand Down
2 changes: 1 addition & 1 deletion p2p/muxer/yamux/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

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

"github.com/libp2p/go-yamux/v3"
"github.com/libp2p/go-yamux/v4"
)

// stream implements mux.MuxedStream over yamux.Stream.
Expand Down
11 changes: 8 additions & 3 deletions p2p/muxer/yamux/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

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

"github.com/libp2p/go-yamux/v3"
"github.com/libp2p/go-yamux/v4"
)

var DefaultTransport *Transport
Expand Down Expand Up @@ -38,12 +38,17 @@ type Transport yamux.Config
var _ network.Multiplexer = &Transport{}

func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
var newSpan func() (yamux.MemoryManager, error)
if scope != nil {
newSpan = func() (yamux.MemoryManager, error) { return scope.BeginSpan() }
}

var s *yamux.Session
var err error
if isServer {
s, err = yamux.Server(nc, t.Config(), scope)
s, err = yamux.Server(nc, t.Config(), newSpan)
} else {
s, err = yamux.Client(nc, t.Config(), scope)
s, err = yamux.Client(nc, t.Config(), newSpan)
}
if err != nil {
return nil, err
Expand Down