/
p2p_v2_config.go
66 lines (56 loc) · 2.53 KB
/
p2p_v2_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
package config
import (
"time"
ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/chainlink/core/config/envvar"
"github.com/smartcontractkit/chainlink/core/config/parse"
"github.com/smartcontractkit/chainlink/core/store/models"
)
// P2PV2Networking is a subset of global config relevant to p2p v2 networking.
type P2PV2Networking interface {
P2PV2AnnounceAddresses() []string
P2PV2Bootstrappers() (locators []ocrcommontypes.BootstrapperLocator)
P2PV2BootstrappersRaw() []string
P2PV2DeltaDial() models.Duration
P2PV2DeltaReconcile() models.Duration
P2PV2ListenAddresses() []string
}
// P2PV2ListenAddresses contains the addresses the peer will listen to on the network in <host>:<port> form as
// accepted by net.Listen, but host and port must be fully specified and cannot be empty.
func (c *generalConfig) P2PV2ListenAddresses() []string {
return c.viper.GetStringSlice(envvar.Name("P2PV2ListenAddresses"))
}
// P2PV2AnnounceAddresses contains the addresses the peer will advertise on the network in <host>:<port> form as
// accepted by net.Dial. The addresses should be reachable by peers of interest.
func (c *generalConfig) P2PV2AnnounceAddresses() []string {
if c.viper.IsSet(envvar.Name("P2PV2AnnounceAddresses")) {
return c.viper.GetStringSlice(envvar.Name("P2PV2AnnounceAddresses"))
}
return c.P2PV2ListenAddresses()
}
// P2PV2Bootstrappers returns the default bootstrapper peers for libocr's v2
// networking stack
func (c *generalConfig) P2PV2Bootstrappers() (locators []ocrcommontypes.BootstrapperLocator) {
bootstrappers := c.P2PV2BootstrappersRaw()
for _, s := range bootstrappers {
var locator ocrcommontypes.BootstrapperLocator
err := locator.UnmarshalText([]byte(s))
if err != nil {
c.lggr.Panicf("invalid format for bootstrapper '%s', got error: %s", s, err)
}
locators = append(locators, locator)
}
return
}
// P2PV2BootstrappersRaw returns the raw strings for v2 bootstrap peers
func (c *generalConfig) P2PV2BootstrappersRaw() []string {
return c.viper.GetStringSlice(envvar.Name("P2PV2Bootstrappers"))
}
// P2PV2DeltaDial controls how far apart Dial attempts are
func (c *generalConfig) P2PV2DeltaDial() models.Duration {
return models.MustMakeDuration(c.getWithFallback("P2PV2DeltaDial", parse.Duration).(time.Duration))
}
// P2PV2DeltaReconcile controls how often a Reconcile message is sent to every peer.
func (c *generalConfig) P2PV2DeltaReconcile() models.Duration {
return models.MustMakeDuration(c.getWithFallback("P2PV2DeltaReconcile", parse.Duration).(time.Duration))
}