-
Notifications
You must be signed in to change notification settings - Fork 921
/
config.go
83 lines (73 loc) · 2.79 KB
/
config.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
82
83
package p2p
import (
"fmt"
"time"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
)
const defaultRoutingRefreshPeriod = time.Minute
// Config combines all configuration fields for P2P subsystem.
type Config struct {
// ListenAddresses - Addresses to listen to on local NIC.
ListenAddresses []string
// AnnounceAddresses - Addresses to be announced/advertised for peers to connect to
AnnounceAddresses []string
// NoAnnounceAddresses - Addresses the P2P subsystem may know about, but that should not be
// announced/advertised, as undialable from WAN
NoAnnounceAddresses []string
// MutualPeers are peers which have a bidirectional peering agreement with the configured node.
// Connections with those peers are protected from being trimmed, dropped or negatively scored.
// NOTE: Any two peers must bidirectionally configure each other on their MutualPeers field.
MutualPeers []string
// PeerExchange configures the node, whether it should share some peers to a pruned peer.
// This is enabled by default for Bootstrappers.
PeerExchange bool
// ConnManager is a configuration tuple for ConnectionManager.
ConnManager connManagerConfig
RoutingTableRefreshPeriod time.Duration
// Allowlist for IPColocation PubSub parameter, a list of string CIDRs
IPColocationWhitelist []string
}
// DefaultConfig returns default configuration for P2P subsystem.
func DefaultConfig(tp node.Type) Config {
return Config{
ListenAddresses: []string{
"/ip4/0.0.0.0/udp/2121/quic-v1",
"/ip6/::/udp/2121/quic-v1",
"/ip4/0.0.0.0/tcp/2121",
"/ip6/::/tcp/2121",
},
AnnounceAddresses: []string{},
NoAnnounceAddresses: []string{
"/ip4/0.0.0.0/udp/2121/quic-v1",
"/ip4/127.0.0.1/udp/2121/quic-v1",
"/ip6/::/udp/2121/quic-v1",
"/ip4/0.0.0.0/tcp/2121",
"/ip4/127.0.0.1/tcp/2121",
"/ip6/::/tcp/2121",
},
MutualPeers: []string{},
PeerExchange: tp == node.Bridge || tp == node.Full,
ConnManager: defaultConnManagerConfig(tp),
RoutingTableRefreshPeriod: defaultRoutingRefreshPeriod,
}
}
func (cfg *Config) mutualPeers() (_ []peer.AddrInfo, err error) {
maddrs := make([]ma.Multiaddr, len(cfg.MutualPeers))
for i, addr := range cfg.MutualPeers {
maddrs[i], err = ma.NewMultiaddr(addr)
if err != nil {
return nil, fmt.Errorf("failure to parse config.P2P.MutualPeers: %s", err)
}
}
return peer.AddrInfosFromP2pAddrs(maddrs...)
}
// Validate performs basic validation of the config.
func (cfg *Config) Validate() error {
if cfg.RoutingTableRefreshPeriod <= 0 {
cfg.RoutingTableRefreshPeriod = defaultRoutingRefreshPeriod
log.Warnf("routingTableRefreshPeriod is not valid. restoring to default value: %d", cfg.RoutingTableRefreshPeriod)
}
return nil
}