Skip to content

Commit

Permalink
feat: Swarm.RelayService.InfiniteLimits
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Feb 22, 2023
1 parent d7dea9c commit 5a1202f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
10 changes: 9 additions & 1 deletion config/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type RelayClient struct {
}

// RelayService configures the resources of the circuit v2 relay.
// For every field a reasonable default will be defined in go-ipfs.
// For every field a reasonable default will be defined in Kubo.
type RelayService struct {
// Enables the limited relay service for other peers (circuit v2 relay).
Enabled Flag `json:",omitempty"`
Expand All @@ -93,6 +93,14 @@ type RelayService struct {
MaxReservationsPerIP *OptionalInteger `json:",omitempty"`
// MaxReservationsPerASN is the maximum number of reservations origination from the same ASN.
MaxReservationsPerASN *OptionalInteger `json:",omitempty"`

// InfiniteLimits effectively removes all limits. Enabling this option also
// doesn't apply any filter for which protocols can be used, allowing for
// expensive things like bitswap over a relayed connection.
// Do this only if you know what you are doing. Exposing relay like this to
// the public may lead to resource exhausion, use with care, as a static
// relay in controlled environments.
InfiniteLimits Flag `json:",omitempty"`
}

type Transports struct {
Expand Down
6 changes: 6 additions & 0 deletions core/node/libp2p/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func RelayTransport(enableRelay bool) func() (opts Libp2pOpts, err error) {
func RelayService(enable bool, relayOpts config.RelayService) func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) {
if enable {
// If user explicitly removed limits
if relayOpts.InfiniteLimits.WithDefault(false) {
opts.Opts = append(opts.Opts, libp2p.EnableRelayService(relay.WithInfiniteLimits()))
return
}

def := relay.DefaultResources()
// Real defaults live in go-libp2p.
// Here we apply any overrides from user config.
Expand Down
42 changes: 25 additions & 17 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ config file at runtime.
- [`Swarm.RelayClient.StaticRelays`](#swarmrelayclientstaticrelays)
- [`Swarm.RelayService`](#swarmrelayservice)
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled)
- [`Swarm.RelayService.Limit`](#swarmrelayservicelimit)
- [`Swarm.RelayService.ConnectionDurationLimit`](#swarmrelayserviceconnectiondurationlimit)
- [`Swarm.RelayService.ConnectionDataLimit`](#swarmrelayserviceconnectiondatalimit)
- [`Swarm.RelayService.ConnectionDurationLimit`](#swarmrelayserviceconnectiondurationlimit)
- [`Swarm.RelayService.ConnectionDataLimit`](#swarmrelayserviceconnectiondatalimit)
- [`Swarm.RelayService.ReservationTTL`](#swarmrelayservicereservationttl)
- [`Swarm.RelayService.MaxReservations`](#swarmrelayservicemaxreservations)
- [`Swarm.RelayService.MaxCircuits`](#swarmrelayservicemaxcircuits)
- [`Swarm.RelayService.BufferSize`](#swarmrelayservicebuffersize)
- [`Swarm.RelayService.MaxReservationsPerPeer`](#swarmrelayservicemaxreservationsperpeer)
- [`Swarm.RelayService.MaxReservationsPerIP`](#swarmrelayservicemaxreservationsperip)
- [`Swarm.RelayService.MaxReservationsPerASN`](#swarmrelayservicemaxreservationsperasn)
- [`Swarm.RelayService.InfiniteLimits`](#swarmrelayserviceinfinitelimits)
- [`Swarm.EnableRelayHop`](#swarmenablerelayhop)
- [`Swarm.DisableRelay`](#swarmdisablerelay)
- [`Swarm.EnableAutoNATService`](#swarmenableautonatservice)
Expand Down Expand Up @@ -237,7 +237,7 @@ documented in `ipfs config profile --help`.
smaller than several gigabytes. If you run IPFS with `--enable-gc`, you plan on storing very little data in
your IPFS node, and disk usage is more critical than performance, consider using
`flatfs`.
- This datastore uses up to several gigabytes of memory.
- This datastore uses up to several gigabytes of memory.
- Good for medium-size datastores, but may run into performance issues if your dataset is bigger than a terabyte.
- The current implementation is based on old badger 1.x which is no longer supported by the upstream team.

Expand Down Expand Up @@ -682,7 +682,7 @@ Type: `string` (url)

### `Gateway.Writable`

**DEPRECATED**: Enables legacy PUT/POST request handling.
**DEPRECATED**: Enables legacy PUT/POST request handling.

This API is not standardized, and should not be used for new projects.
We are working on a modern replacement. IPIP can be tracked in [ipfs/specs#375](https://github.com/ipfs/specs/issues/375).
Expand Down Expand Up @@ -901,7 +901,7 @@ Type: `string` (base64 encoded)

## `Internal`

This section includes internal knobs for various subsystems to allow advanced users with big or private infrastructures to fine-tune some behaviors without the need to recompile Kubo.
This section includes internal knobs for various subsystems to allow advanced users with big or private infrastructures to fine-tune some behaviors without the need to recompile Kubo.

**Be aware that making informed change here requires in-depth knowledge and most users should leave these untouched. All knobs listed here are subject to breaking changes between versions.**

Expand Down Expand Up @@ -977,7 +977,7 @@ Type: `optionalInteger` (byte count, `null` means default which is 1MB)
### `Internal.Bitswap.ProviderSearchDelay`

This parameter determines how long to wait before looking for providers outside of bitswap.
Other routing systems like the DHT are able to provide results in less than a second, so lowering
Other routing systems like the DHT are able to provide results in less than a second, so lowering
this number will allow faster peers lookups in some cases.

Type: `optionalDuration` (`null` means default which is 1s)
Expand Down Expand Up @@ -1644,23 +1644,15 @@ Default: `true`

Type: `flag`

#### `Swarm.RelayService.Limit`

Limits applied to every relayed connection.

Default: `{}`

Type: `object[string -> string]`

##### `Swarm.RelayService.ConnectionDurationLimit`
#### `Swarm.RelayService.ConnectionDurationLimit`

Time limit before a relayed connection is reset.

Default: `"2m"`

Type: `duration`

##### `Swarm.RelayService.ConnectionDataLimit`
#### `Swarm.RelayService.ConnectionDataLimit`

Limit of data relayed (in each direction) before a relayed connection is reset.

Expand Down Expand Up @@ -1730,6 +1722,22 @@ Default: `32`

Type: `optionalInteger`

#### `Swarm.RelayService.InfiniteLimits`

**EXPERIMENTAL:** use with care

Removes all limits. Enabling this option also doesn't apply any filter for
which protocols can be used, allowing for expensive things like bitswap over a
relayed connection.

NOTE: Do this only if you know what you are doing. Exposing relay like this to
the public may lead to resource exhausion, use with care, as a static relay in
controlled environments.

Default: `false`

Type: `flag`

### `Swarm.EnableRelayHop`

**REMOVED**
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-doh-resolver v0.4.0
github.com/libp2p/go-libp2p v0.25.2-0.20230217230459-32f2f255292d
github.com/libp2p/go-libp2p v0.25.2-0.20230222220431-c03190e1ca4f
github.com/libp2p/go-libp2p-http v0.4.0
github.com/libp2p/go-libp2p-kad-dht v0.21.0
github.com/libp2p/go-libp2p-kbucket v0.5.0
Expand Down Expand Up @@ -208,9 +208,9 @@ require (
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-18 v0.2.0 // indirect
github.com/quic-go/qtls-go1-19 v0.2.0 // indirect
github.com/quic-go/qtls-go1-20 v0.1.0 // indirect
github.com/quic-go/quic-go v0.32.0 // indirect
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/quic-go/webtransport-go v0.5.1 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rs/cors v1.7.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ github.com/libp2p/go-libp2p v0.8.1/go.mod h1:QRNH9pwdbEBpx5DTJYg+qxcVaDMAz3Ee/qD
github.com/libp2p/go-libp2p v0.14.3/go.mod h1:d12V4PdKbpL0T1/gsUNN8DfgMuRPDX8bS2QxCZlwRH0=
github.com/libp2p/go-libp2p v0.25.2-0.20230217230459-32f2f255292d h1:OjHCu6qL/KM3824vKv/tVdM4SVJim8OEi29u1liNZKY=
github.com/libp2p/go-libp2p v0.25.2-0.20230217230459-32f2f255292d/go.mod h1:7po3PEsmCs7rXOg7u1sbvsuROpMBq4MVg6LSTAHU1h0=
github.com/libp2p/go-libp2p v0.25.2-0.20230222220431-c03190e1ca4f h1:nu10GjX7i3VzDu0RRldOg0iEFZ7N7BaUlo/ydFl4xEc=
github.com/libp2p/go-libp2p v0.25.2-0.20230222220431-c03190e1ca4f/go.mod h1:R8N+XhwPDPLNb4TKboKJKnDeg9vPw8+zlC6g793dTGw=
github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw=
github.com/libp2p/go-libp2p-asn-util v0.2.0/go.mod h1:WoaWxbHKBymSN41hWSq/lGKJEca7TNm58+gGJi2WsLI=
github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8=
Expand Down Expand Up @@ -1224,10 +1226,16 @@ github.com/quic-go/qtls-go1-18 v0.2.0 h1:5ViXqBZ90wpUcZS0ge79rf029yx0dYB0McyPJwq
github.com/quic-go/qtls-go1-18 v0.2.0/go.mod h1:moGulGHK7o6O8lSPSZNoOwcLvJKJ85vVNc7oJFD65bc=
github.com/quic-go/qtls-go1-19 v0.2.0 h1:Cvn2WdhyViFUHoOqK52i51k4nDX8EwIh5VJiVM4nttk=
github.com/quic-go/qtls-go1-19 v0.2.0/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
github.com/quic-go/qtls-go1-19 v0.2.1 h1:aJcKNMkH5ASEJB9FXNeZCyTEIHU1J7MmHyz1Q1TSG1A=
github.com/quic-go/qtls-go1-19 v0.2.1/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
github.com/quic-go/qtls-go1-20 v0.1.0 h1:d1PK3ErFy9t7zxKsG3NXBJXZjp/kMLoIb3y/kV54oAI=
github.com/quic-go/qtls-go1-20 v0.1.0/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/qtls-go1-20 v0.1.1 h1:KbChDlg82d3IHqaj2bn6GfKRj84Per2VGf5XV3wSwQk=
github.com/quic-go/qtls-go1-20 v0.1.1/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/quic-go v0.32.0 h1:lY02md31s1JgPiiyfqJijpu/UX/Iun304FI3yUqX7tA=
github.com/quic-go/quic-go v0.32.0/go.mod h1:/fCsKANhQIeD5l76c2JFU+07gVE3KaA0FP+0zMWwfwo=
github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0=
github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA=
github.com/quic-go/webtransport-go v0.5.1 h1:1eVb7WDWCRoaeTtFHpFBJ6WDN1bSrPrRoW6tZgSw0Ow=
github.com/quic-go/webtransport-go v0.5.1/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU=
github.com/rabbitmq/amqp091-go v1.1.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
Expand Down

0 comments on commit 5a1202f

Please sign in to comment.