This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
autonat.go
81 lines (72 loc) · 2.3 KB
/
autonat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package config
import (
"fmt"
)
// AutoNATServiceMode configures the ipfs node's AutoNAT service.
type AutoNATServiceMode int
const (
// AutoNATServiceUnset indicates that the user has not set the
// AutoNATService mode.
//
// When unset, nodes configured to be public DHT nodes will _also_
// perform limited AutoNAT dialbacks.
AutoNATServiceUnset AutoNATServiceMode = iota
// AutoNATServiceEnabled indicates that the user has enabled the
// AutoNATService.
AutoNATServiceEnabled
// AutoNATServiceDisabled indicates that the user has disabled the
// AutoNATService.
AutoNATServiceDisabled
)
func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
switch string(text) {
case "":
*m = AutoNATServiceUnset
case "enabled":
*m = AutoNATServiceEnabled
case "disabled":
*m = AutoNATServiceDisabled
default:
return fmt.Errorf("unknown autonat mode: %s", string(text))
}
return nil
}
func (m AutoNATServiceMode) MarshalText() ([]byte, error) {
switch m {
case AutoNATServiceUnset:
return nil, nil
case AutoNATServiceEnabled:
return []byte("enabled"), nil
case AutoNATServiceDisabled:
return []byte("disabled"), nil
default:
return nil, fmt.Errorf("unknown autonat mode: %d", m)
}
}
// AutoNATConfig configures the node's AutoNAT subsystem.
type AutoNATConfig struct {
// ServiceMode configures the node's AutoNAT service mode.
ServiceMode AutoNATServiceMode `json:",omitempty"`
// Throttle configures AutoNAT dialback throttling.
//
// If unset, the conservative libp2p defaults will be unset. To help the
// network, please consider setting this and increasing the limits.
//
// By default, the limits will be a total of 30 dialbacks, with a
// per-peer max of 3 peer, resetting every minute.
Throttle *AutoNATThrottleConfig `json:",omitempty"`
}
// AutoNATThrottleConfig configures the throttle limites
type AutoNATThrottleConfig struct {
// GlobalLimit and PeerLimit sets the global and per-peer dialback
// limits. The AutoNAT service will only perform the specified number of
// dialbacks per interval.
//
// Setting either to 0 will disable the appropriate limit.
GlobalLimit, PeerLimit int
// Interval specifies how frequently this node should reset the
// global/peer dialback limits.
//
// When unset, this defaults to 1 minute.
Interval OptionalDuration `json:",omitempty"`
}