@cryptotaxi247 / kubo / commits / 1f23fc000

feat: add autonat config options

1. Enable AutoNATService on _all_ nodes by default. If it's an issue, we can disable it in RC3 but this will give us the best testing results. 2. Expose options to configure AutoNAT rate limiting.

Steven Allen committed Apr 14, 2020 at 20:40 UTC 1f23fc000c01605d51ddaaf01ff7402a330e8f9c
6 files changed +101 -11
core/node/groups.go
+20 -1
@@ -90,6 +90,25 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
90 }
91 }
92
93 + autonat := fx.Options()
94 +
95 + switch cfg.AutoNAT.ServiceMode {
96 + default:
97 + panic("BUG: unhandled autonat service mode")
98 + case config.AutoNATServiceDisabled:
99 + case config.AutoNATServiceUnset:
100 + // TODO
101 + //
102 + // We're enabling the AutoNAT service by default on _all_ nodes
103 + // for the moment.
104 + //
105 + // We should consider disabling it by default if the dht is set
106 + // to dhtclient.
107 + fallthrough
108 + case config.AutoNATServiceEnabled:
109 + autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle))
110 + }
111 +
112 // Gather all the options
113
114 opts := fx.Options(
@@ -110,9 +129,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
129
130 maybeProvide(libp2p.BandwidthCounter, !cfg.Swarm.DisableBandwidthMetrics),
131 maybeProvide(libp2p.NatPortMap, !cfg.Swarm.DisableNatPortMap),
113 - maybeProvide(libp2p.AutoNATService, cfg.Swarm.EnableAutoNATService),
132 maybeProvide(libp2p.AutoRelay, cfg.Swarm.EnableAutoRelay),
133 maybeProvide(libp2p.QUIC, cfg.Experimental.QUIC),
134 + autonat,
135 connmgr,
136 ps,
137 disc,
core/node/libp2p/nat.go
+21 -1
@@ -1,8 +1,28 @@
1 package libp2p
2
3 import (
4 + "time"
5 +
6 + "github.com/ipfs/go-ipfs-config"
7 "github.com/libp2p/go-libp2p"
8 )
9
10 var NatPortMap = simpleOpt(libp2p.NATPortMap())
8 -var AutoNATService = simpleOpt(libp2p.EnableNATService())
11 +
12 +func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
13 + return func() (opts Libp2pOpts) {
14 + opts.Opts = append(opts.Opts, libp2p.EnableNATService())
15 + if throttle != nil {
16 + global := throttle.GlobalLimit
17 + peer := throttle.PeerLimit
18 + interval := time.Duration(throttle.Interval)
19 + if interval == 0 {
20 + interval = time.Minute
21 + }
22 + opts.Opts = append(opts.Opts,
23 + libp2p.AutoNATServiceRateLimit(global, peer, interval),
24 + )
25 + }
26 + return opts
27 + }
28 +}
docs/config.md
+43 -4
@@ -192,6 +192,47 @@ Example:
192
193 Default: `null`
194
195 +## `AutoNAT`
196 +
197 +Contains the configuration options for the AutoNAT service. The AutoNAT service
198 +helps other nodes on the network determine if they're publicly reachable from
199 +the rest of the internet.
200 +
201 +### `AutoNAT.ServiceMode`
202 +
203 +When unset (default), the AutoNAT service defaults to _enabled_. Otherwise, this
204 +field can take one of two values:
205 +
206 +* "enabled" - Enable the service (unless the node determines that it, itself,
207 + isn't reachable by the public internet).
208 +* "disabled" - Disable the service.
209 +
210 +Additional modes may be added in the future.
211 +
212 +### `AutoNAT.Throttle`
213 +
214 +When set, this option configure's the AutoNAT services throttling behavior. By
215 +default, go-ipfs will rate-limit the number of NAT checks performed for other
216 +nodes to 30 per minute, and 3 per peer.
217 +
218 +### `AutoNAT.Throttle.GlobalLimit`
219 +
220 +Configures how many AutoNAT requests to service per `AutoNAT.Throttle.Interval`.
221 +
222 +Default: 30
223 +
224 +### `AutoNAT.Throttle.PeerLimit`
225 +
226 +Configures how many AutoNAT requests per-peer to service per `AutoNAT.Throttle.Interval`.
227 +
228 +Default: 3
229 +
230 +### `AutoNAT.Throttle.Interval`
231 +
232 +Configures the interval for the above limits.
233 +
234 +Default: 1 Minute
235 +
236 ## `Bootstrap`
237
238 Bootstrap is an array of multiaddrs of trusted nodes to connect to in order to
@@ -700,11 +741,9 @@ DHT and override its public address(es) with relay addresses.
741
742 ### `Swarm.EnableAutoNATService`
743
703 -Enables the AutoNAT service for this node.
744 +**REMOVED**
745
705 -The service allows peers to discover their NAT situation by requesting dial
706 -backs to their public addresses. This should only be enabled on publicly
707 -reachable nodes.
746 +Please use [`AutoNAT.ServiceMode`][].
747
748 ### `Swarm.ConnMgr`
749
go.mod
+2 -2
@@ -31,7 +31,7 @@ require (
31 github.com/ipfs/go-ipfs-blockstore v0.1.4
32 github.com/ipfs/go-ipfs-chunker v0.0.5
33 github.com/ipfs/go-ipfs-cmds v0.2.2
34 - github.com/ipfs/go-ipfs-config v0.4.0
34 + github.com/ipfs/go-ipfs-config v0.5.2
35 github.com/ipfs/go-ipfs-ds-help v0.1.1
36 github.com/ipfs/go-ipfs-exchange-interface v0.0.1
37 github.com/ipfs/go-ipfs-exchange-offline v0.0.1
@@ -60,7 +60,7 @@ require (
60 github.com/jbenet/go-temp-err-catcher v0.1.0
61 github.com/jbenet/goprocess v0.1.4
62 github.com/libp2p/go-eventbus v0.1.0
63 - github.com/libp2p/go-libp2p v0.7.4
63 + github.com/libp2p/go-libp2p v0.8.0
64 github.com/libp2p/go-libp2p-circuit v0.2.1
65 github.com/libp2p/go-libp2p-connmgr v0.2.1
66 github.com/libp2p/go-libp2p-core v0.5.1
go.sum
+6 -2
@@ -293,8 +293,8 @@ github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7Na
293 github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8=
294 github.com/ipfs/go-ipfs-cmds v0.2.2 h1:F2pro/Q3ifRUsdxEKIS8cg8lO4R6WiwAyERiaG8I9no=
295 github.com/ipfs/go-ipfs-cmds v0.2.2/go.mod h1:kqlUrp6m2ceoaJe40cXpADCi5aS6NKRn0NIeuLp5CeM=
296 -github.com/ipfs/go-ipfs-config v0.4.0 h1:MOXdj8EYQG55v1y+5e1QcctDKPEGobdwnXaDVa0/cc0=
297 -github.com/ipfs/go-ipfs-config v0.4.0/go.mod h1:nSLCFtlaL+2rbl3F+9D4gQZQbT1LjRKx7TJg/IHz6oM=
296 +github.com/ipfs/go-ipfs-config v0.5.2 h1:SPWiMNo7IOW0k+meO3PIprggp/PbZGUiO57L7HQ/sOY=
297 +github.com/ipfs/go-ipfs-config v0.5.2/go.mod h1:nSLCFtlaL+2rbl3F+9D4gQZQbT1LjRKx7TJg/IHz6oM=
298 github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
299 github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ=
300 github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
@@ -484,6 +484,8 @@ github.com/libp2p/go-libp2p v0.7.0 h1:qWmciout2lJclKfRlxqdepsQB7JihcbRhgcRcssP4r
484 github.com/libp2p/go-libp2p v0.7.0/go.mod h1:hZJf8txWeCduQRDC/WSqBGMxaTHCOYHt2xSU1ivxn0k=
485 github.com/libp2p/go-libp2p v0.7.4 h1:xVj1oSlN0C+FlxqiLuHC8WruMvq24xxfeVxmNhTG0r0=
486 github.com/libp2p/go-libp2p v0.7.4/go.mod h1:oXsBlTLF1q7pxr+9w6lqzS1ILpyHsaBPniVO7zIHGMw=
487 +github.com/libp2p/go-libp2p v0.8.0 h1:8t8kAJM+o4rR91bfwbgbtykbdqPJv819+CTSPkXDT1A=
488 +github.com/libp2p/go-libp2p v0.8.0/go.mod h1:QRNH9pwdbEBpx5DTJYg+qxcVaDMAz3Ee/qDKwXujH5o=
489 github.com/libp2p/go-libp2p-autonat v0.0.2/go.mod h1:fs71q5Xk+pdnKU014o2iq1RhMs9/PMaG5zXRFNnIIT4=
490 github.com/libp2p/go-libp2p-autonat v0.0.6/go.mod h1:uZneLdOkZHro35xIhpbtTzLlgYturpu4J5+0cZK3MqE=
491 github.com/libp2p/go-libp2p-autonat v0.1.0 h1:aCWAu43Ri4nU0ZPO7NyLzUvvfqd0nE3dX0R/ZGYVgOU=
@@ -494,6 +496,8 @@ github.com/libp2p/go-libp2p-autonat v0.2.0 h1:Kok+0M/4jiz6TTmxtBqAa5tLyHb/U+G/7o
496 github.com/libp2p/go-libp2p-autonat v0.2.0/go.mod h1:DX+9teU4pEEoZUqR1PiMlqliONQdNbfzE1C718tcViI=
497 github.com/libp2p/go-libp2p-autonat v0.2.1 h1:T0CRQhrvTBKfBSYw6Xo2K3ixtNpAnRCraxof3AAfgQA=
498 github.com/libp2p/go-libp2p-autonat v0.2.1/go.mod h1:MWtAhV5Ko1l6QBsHQNSuM6b1sRkXrpk0/LqCr+vCVxI=
499 +github.com/libp2p/go-libp2p-autonat v0.2.2 h1:4dlgcEEugTFWSvdG2UIFxhnOMpX76QaZSRAtXmYB8n4=
500 +github.com/libp2p/go-libp2p-autonat v0.2.2/go.mod h1:HsM62HkqZmHR2k1xgX34WuWDzk/nBwNHoeyyT4IWV6A=
501 github.com/libp2p/go-libp2p-blankhost v0.0.1/go.mod h1:Ibpbw/7cPPYwFb7PACIWdvxxv0t0XCCI10t7czjAjTc=
502 github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro=
503 github.com/libp2p/go-libp2p-blankhost v0.1.3/go.mod h1:KML1//wiKR8vuuJO0y3LUd1uLv+tlkGTAr3jC0S5cLg=
test/sharness/t0185-autonat.sh
+9 -1
@@ -11,7 +11,15 @@ test_description="Test autonat"
11 test_init_ipfs
12
13 test_expect_success "enable autonat" '
14 - ipfs config --json Swarm.EnableAutoNATService true
14 + ipfs config AutoNAT.ServiceMode enabled
15 +'
16 +
17 +test_launch_ipfs_daemon
18 +
19 +test_kill_ipfs_daemon
20 +
21 +test_expect_success "enable autonat" '
22 + ipfs config AutoNAT.ServiceMode disabled
23 '
24
25 test_launch_ipfs_daemon