go-ipfs-config: feat: add an autonat config section
And remove the current EnableAutoNATService option from the swarm config. While a breaking change, this shouldn't cause _too_ much trouble given that we're going to enable AutoNAT everywhere by default anyways.
Steven Allen committed
Apr 14, 2020 at 18:40 UTC
4554fc924679f7e8e250b53ab738c3766da08604
3 files changed
+80
-2
config/autonat.go
new
+79
@@ -0,0 +1,79 @@
1
+package config
2
+
3
+import (
4
+ "fmt"
5
+)
6
+
7
+// AutoNATServiceMode configures the ipfs node's AutoNAT service.
8
+type AutoNATServiceMode int
9
+
10
+const (
11
+ // AutoNATServiceUnset indicates that the user has not set the
12
+ // AutoNATService mode.
13
+ //
14
+ // When unset, nodes configured to be public DHT nodes will _also_
15
+ // perform limited AutoNAT dialbacks.
16
+ AutoNATServiceUnset AutoNATServiceMode = iota
17
+ // AutoNATServiceEnabled indicates that the user has enabled the
18
+ // AutoNATService.
19
+ AutoNATServiceEnabled
20
+ // AutoNATServiceDisabled indicates that the user has disabled the
21
+ // AutoNATService.
22
+ AutoNATServiceDisabled
23
+)
24
+
25
+func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
26
+ switch string(text) {
27
+ case "":
28
+ *m = AutoNATServiceUnset
29
+ case "enabled":
30
+ *m = AutoNATServiceEnabled
31
+ case "disabled":
32
+ *m = AutoNATServiceDisabled
33
+ default:
34
+ return fmt.Errorf("unknown autonat mode: %s", string(text))
35
+ }
36
+ return nil
37
+}
38
+
39
+func (m AutoNATServiceMode) MarshalText() ([]byte, error) {
40
+ switch m {
41
+ case AutoNATServiceUnset:
42
+ return nil, nil
43
+ case AutoNATServiceEnabled:
44
+ return []byte("enabled"), nil
45
+ case AutoNATServiceDisabled:
46
+ return []byte("disabled"), nil
47
+ default:
48
+ return nil, fmt.Errorf("unknown autonat mode: %d", m)
49
+ }
50
+}
51
+
52
+// AutoNATConfig configures the node's AutoNAT subsystem.
53
+type AutoNATConfig struct {
54
+ // ServiceMode configures the node's AutoNAT service mode.
55
+ ServiceMode AutoNATServiceMode `json:",omitempty"`
56
+
57
+ // Throttle configures AutoNAT dialback throttling.
58
+ //
59
+ // If unset, the conservative libp2p defaults will be unset. To help the
60
+ // network, please consider setting this and increasing the limits.
61
+ //
62
+ // By default, the limits will be a total of 30 dialbacks, with a
63
+ // per-peer max of 3 peer, resetting every minute.
64
+ Throttle *AutoNATThrottleConfig `json:",omitempty"`
65
+}
66
+
67
+// AutoNATThrottleConfig configures the throttle limites
68
+type AutoNATThrottleConfig struct {
69
+ // GlobalLimit and PeerLimit sets the global and per-peer dialback
70
+ // limits. The AutoNAT service will only perform the specified number of
71
+ // dialbacks per interval.
72
+ //
73
+ // Setting either to 0 will disable the appropriate limit.
74
+ GlobalLimit, PeerLimit int
75
+
76
+ // Interval specifies how frequently this node should reset the
77
+ // global/peer dialback limits.
78
+ Interval string
79
+}
config/config.go
+1
@@ -25,6 +25,7 @@ type Config struct {
25
Gateway Gateway // local node's gateway server options
26
API API // local node's API settings
27
Swarm SwarmConfig
28
+ AutoNAT AutoNATConfig
29
Pubsub PubsubConfig
30
31
Provider Provider
config/swarm.go
-2
@@ -10,8 +10,6 @@ type SwarmConfig struct {
10
// autorelay functionality
11
// if true, then the libp2p host will be constructed with autorelay functionality.
12
EnableAutoRelay bool
13
- // if true, then an AutoNATService will be instantiated to facilitate autorelay
14
- EnableAutoNATService bool
13
14
ConnMgr ConnMgr
15
}