From 579078f07b86dd28ea06211e976b53d5ca157a84 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 30 Dec 2021 17:00:23 +0400 Subject: [PATCH] add support for the resource manager --- go.mod | 6 +++--- go.sum | 13 ++++++------- swarm.go | 6 ++++++ swarm_conn.go | 8 +++++++- swarm_stream.go | 5 +++++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 76697425..d66bcfa5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 468edd0f..b3bcbee9 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/swarm.go b/swarm.go index 47617907..1123c6f9 100644 --- a/swarm.go +++ b/swarm.go @@ -88,6 +88,8 @@ type Swarm struct { // down before continuing. refs sync.WaitGroup + rcmgr network.ResourceManager + local peer.ID peers peerstore.Peerstore @@ -586,6 +588,10 @@ func (s *Swarm) String() string { return fmt.Sprintf("", 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) diff --git a/swarm_conn.go b/swarm_conn.go index 388e9e76..d01c8b9d 100644 --- a/swarm_conn.go +++ b/swarm_conn.go @@ -28,6 +28,7 @@ type Conn struct { id uint64 conn transport.CapableConn swarm *Swarm + scope network.ConnectionScope closeOnce sync.Once err error @@ -42,6 +43,8 @@ type Conn struct { stat network.ConnStats } +var _ network.Conn = &Conn{} + func (c *Conn) ID() string { // format: - return fmt.Sprintf("%s-%d", c.RemotePeer().Pretty()[0:10], c.id) @@ -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 } @@ -244,3 +246,7 @@ func (c *Conn) GetStreams() []network.Stream { } return streams } + +func (c *Conn) Scope() network.ConnectionScope { + return c.scope +} diff --git a/swarm_stream.go b/swarm_stream.go index b0063b1b..f9c449fa 100644 --- a/swarm_stream.go +++ b/swarm_stream.go @@ -21,6 +21,7 @@ type Stream struct { stream mux.MuxedStream conn *Conn + scope network.StreamScope closeOnce sync.Once @@ -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 +}