Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
add support for the resource manager
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Dec 30, 2021
1 parent 0531f9f commit 579078f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ require (
github.com/ipfs/go-log/v2 v2.4.0
github.com/libp2p/go-addr-util v0.1.0
github.com/libp2p/go-conn-security-multistream v0.3.0
github.com/libp2p/go-libp2p-core v0.13.0
github.com/libp2p/go-libp2p-core v0.13.1-0.20211230092045-caacd9659af8
github.com/libp2p/go-libp2p-peerstore v0.6.0
github.com/libp2p/go-libp2p-quic-transport v0.13.0
github.com/libp2p/go-libp2p-testing v0.5.0
github.com/libp2p/go-libp2p-transport-upgrader v0.6.0
github.com/libp2p/go-libp2p-transport-upgrader v0.6.1-0.20211230125144-e068fbba0778
github.com/libp2p/go-libp2p-yamux v0.5.0
github.com/libp2p/go-stream-muxer-multistream v0.3.0
github.com/libp2p/go-tcp-transport v0.4.0
github.com/libp2p/go-tcp-transport v0.4.1-0.20211230125825-fe24386acb5d
github.com/multiformats/go-multiaddr v0.4.0
github.com/multiformats/go-multiaddr-fmt v0.1.0
github.com/stretchr/testify v1.7.0
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ github.com/libp2p/go-libp2p-core v0.5.1/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt
github.com/libp2p/go-libp2p-core v0.8.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8=
github.com/libp2p/go-libp2p-core v0.10.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg=
github.com/libp2p/go-libp2p-core v0.12.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg=
github.com/libp2p/go-libp2p-core v0.13.0 h1:IFG/s8dN6JN2OTrXX9eq2wNU/Zlz2KLdwZUp5FplgXI=
github.com/libp2p/go-libp2p-core v0.13.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg=
github.com/libp2p/go-libp2p-core v0.13.1-0.20211230092045-caacd9659af8 h1:YMGNLo9extN6iwBCaLbkoEyw1qtCXbtPmSZLHbxaYuo=
github.com/libp2p/go-libp2p-core v0.13.1-0.20211230092045-caacd9659af8/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg=
github.com/libp2p/go-libp2p-mplex v0.4.1 h1:/pyhkP1nLwjG3OM+VuaNJkQT/Pqq73WzB3aDN3Fx1sc=
github.com/libp2p/go-libp2p-mplex v0.4.1/go.mod h1:cmy+3GfqfM1PceHTLL7zQzAAYaryDu6iPSC+CIb094g=
github.com/libp2p/go-libp2p-peerstore v0.6.0 h1:HJminhQSGISBIRb93N6WK3t6Fa8OOTnHd/VBjL4mY5A=
Expand All @@ -295,9 +295,8 @@ github.com/libp2p/go-libp2p-testing v0.5.0 h1:bTjC29TTQ/ODq0ld3+0KLq3irdA5cAH3OM
github.com/libp2p/go-libp2p-testing v0.5.0/go.mod h1:QBk8fqIL1XNcno/l3/hhaIEn4aLRijpYOR+zVjjlh+A=
github.com/libp2p/go-libp2p-tls v0.3.0 h1:8BgvUJiOTcj0Gp6XvEicF0rL5aUtRg/UzEdeZDmDlC8=
github.com/libp2p/go-libp2p-tls v0.3.0/go.mod h1:fwF5X6PWGxm6IDRwF3V8AVCCj/hOd5oFlg+wo2FxJDY=
github.com/libp2p/go-libp2p-transport-upgrader v0.5.0/go.mod h1:Rc+XODlB3yce7dvFV4q/RmyJGsFcCZRkeZMu/Zdg0mo=
github.com/libp2p/go-libp2p-transport-upgrader v0.6.0 h1:GfMCU+2aGGEm1zW3UcOz6wYSn8tXQalFfVfcww99i5A=
github.com/libp2p/go-libp2p-transport-upgrader v0.6.0/go.mod h1:1e07y1ZSZdHo9HPbuU8IztM1Cj+DR5twgycb4pnRzRo=
github.com/libp2p/go-libp2p-transport-upgrader v0.6.1-0.20211230125144-e068fbba0778 h1:XGq4vqi97uxoiix5gCjNDj3bTmgIZIhv6R7YvPVYZMM=
github.com/libp2p/go-libp2p-transport-upgrader v0.6.1-0.20211230125144-e068fbba0778/go.mod h1:0ebY9quQ1UjdxvMa4sFYWIDPLRjH+bSAblgyVq2q+WE=
github.com/libp2p/go-libp2p-yamux v0.5.0 h1:ZzmUhbQE+X7NuYUT2naxN31JyebZfRmpZVhKtRP13ys=
github.com/libp2p/go-libp2p-yamux v0.5.0/go.mod h1:AyR8k5EzyM2QN9Bbdg6X1SkVVuqLwTGf0L4DFq9g6po=
github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUhgnKqNEmIAz/bPU=
Expand All @@ -321,8 +320,8 @@ github.com/libp2p/go-sockaddr v0.1.0 h1:Y4s3/jNoryVRKEBrkJ576F17CPOaMIzUeCsg7dlT
github.com/libp2p/go-sockaddr v0.1.0/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k=
github.com/libp2p/go-stream-muxer-multistream v0.3.0 h1:TqnSHPJEIqDEO7h1wZZ0p3DXdvDSiLHQidKKUGZtiOY=
github.com/libp2p/go-stream-muxer-multistream v0.3.0/go.mod h1:yDh8abSIzmZtqtOt64gFJUXEryejzNb0lisTt+fAMJA=
github.com/libp2p/go-tcp-transport v0.4.0 h1:VDyg4j6en3OuXf90gfDQh5Sy9KowO9udnd0OU8PP6zg=
github.com/libp2p/go-tcp-transport v0.4.0/go.mod h1:0y52Rwrn4076xdJYu/51/qJIdxz+EWDAOG2S45sV3VI=
github.com/libp2p/go-tcp-transport v0.4.1-0.20211230125825-fe24386acb5d h1:PeD0i2AbPIoTSHHkNzEezAKO0k0CjX2Wi1fnSJM/MWU=
github.com/libp2p/go-tcp-transport v0.4.1-0.20211230125825-fe24386acb5d/go.mod h1:82zNrLa9z9OXuCPadJJoVl7P0SoUNBN7+1k01ZtacTI=
github.com/libp2p/go-yamux v1.4.1 h1:P1Fe9vF4th5JOxxgQvfbOHkrGqIZniTLf+ddhZp8YTI=
github.com/libp2p/go-yamux v1.4.1/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
Expand Down
6 changes: 6 additions & 0 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type Swarm struct {
// down before continuing.
refs sync.WaitGroup

rcmgr network.ResourceManager

local peer.ID
peers peerstore.Peerstore

Expand Down Expand Up @@ -586,6 +588,10 @@ func (s *Swarm) String() string {
return fmt.Sprintf("<Swarm %s>", s.LocalPeer())
}

func (s *Swarm) ResourceManager() network.ResourceManager {
return s.rcmgr
}

// Swarm is a Network.
var _ network.Network = (*Swarm)(nil)
var _ transport.TransportNetwork = (*Swarm)(nil)
8 changes: 7 additions & 1 deletion swarm_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Conn struct {
id uint64
conn transport.CapableConn
swarm *Swarm
scope network.ConnectionScope

closeOnce sync.Once
err error
Expand All @@ -42,6 +43,8 @@ type Conn struct {
stat network.ConnStats
}

var _ network.Conn = &Conn{}

func (c *Conn) ID() string {
// format: <first 10 chars of peer id>-<global conn ordinal>
return fmt.Sprintf("%s-%d", c.RemotePeer().Pretty()[0:10], c.id)
Expand Down Expand Up @@ -187,7 +190,6 @@ func (c *Conn) NewStream(ctx context.Context) (network.Stream, error) {
}

ts, err := c.conn.OpenStream(ctx)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -244,3 +246,7 @@ func (c *Conn) GetStreams() []network.Stream {
}
return streams
}

func (c *Conn) Scope() network.ConnectionScope {
return c.scope
}
5 changes: 5 additions & 0 deletions swarm_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Stream struct {

stream mux.MuxedStream
conn *Conn
scope network.StreamScope

closeOnce sync.Once

Expand Down Expand Up @@ -154,3 +155,7 @@ func (s *Stream) SetWriteDeadline(t time.Time) error {
func (s *Stream) Stat() network.Stats {
return s.stat
}

func (s *Stream) Scope() network.StreamScope {
return s.scope
}

0 comments on commit 579078f

Please sign in to comment.