2020-03-25 15:30:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-11-29 14:43:08 +00:00
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2022-07-08 16:42:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
2020-03-25 15:30:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ApplicationConfiguration config specific to the node.
|
|
|
|
type ApplicationConfiguration struct {
|
2022-12-06 13:34:38 +00:00
|
|
|
Ledger `yaml:",inline"`
|
|
|
|
|
2022-12-06 19:35:37 +00:00
|
|
|
// Deprecated: this option is moved to the P2P section.
|
|
|
|
AttemptConnPeers int `yaml:"AttemptConnPeers"`
|
2022-10-13 19:14:14 +00:00
|
|
|
// BroadcastFactor is the factor (0-100) controlling gossip fan-out number optimization.
|
2022-12-06 19:35:37 +00:00
|
|
|
//
|
|
|
|
// Deprecated: this option is moved to the P2P section.
|
2022-11-29 14:43:08 +00:00
|
|
|
BroadcastFactor int `yaml:"BroadcastFactor"`
|
|
|
|
DBConfiguration dbconfig.DBConfiguration `yaml:"DBConfiguration"`
|
2022-12-06 19:35:37 +00:00
|
|
|
// Deprecated: this option is moved to the P2P section.
|
|
|
|
DialTimeout int64 `yaml:"DialTimeout"`
|
|
|
|
LogLevel string `yaml:"LogLevel"`
|
|
|
|
LogPath string `yaml:"LogPath"`
|
|
|
|
// Deprecated: this option is moved to the P2P section.
|
|
|
|
MaxPeers int `yaml:"MaxPeers"`
|
|
|
|
// Deprecated: this option is moved to the P2P section.
|
|
|
|
MinPeers int `yaml:"MinPeers"`
|
2023-10-09 20:02:15 +00:00
|
|
|
P2P P2P `yaml:"P2P"`
|
2022-12-06 19:35:37 +00:00
|
|
|
// Deprecated: this option is moved to the P2P section.
|
|
|
|
PingInterval int64 `yaml:"PingInterval"`
|
|
|
|
// Deprecated: this option is moved to the P2P section.
|
|
|
|
PingTimeout int64 `yaml:"PingTimeout"`
|
|
|
|
Pprof BasicService `yaml:"Pprof"`
|
|
|
|
Prometheus BasicService `yaml:"Prometheus"`
|
|
|
|
// Deprecated: this option is moved to the P2P section.
|
2022-11-29 14:43:08 +00:00
|
|
|
ProtoTickInterval int64 `yaml:"ProtoTickInterval"`
|
|
|
|
Relay bool `yaml:"Relay"`
|
2022-12-05 15:11:18 +00:00
|
|
|
Consensus Consensus `yaml:"Consensus"`
|
2022-11-29 14:43:08 +00:00
|
|
|
RPC RPC `yaml:"RPC"`
|
|
|
|
UnlockWallet Wallet `yaml:"UnlockWallet"`
|
|
|
|
Oracle OracleConfiguration `yaml:"Oracle"`
|
|
|
|
P2PNotary P2PNotary `yaml:"P2PNotary"`
|
|
|
|
StateRoot StateRoot `yaml:"StateRoot"`
|
2021-05-04 14:54:16 +00:00
|
|
|
// ExtensiblePoolSize is the maximum amount of the extensible payloads from a single sender.
|
2022-12-06 19:35:37 +00:00
|
|
|
//
|
|
|
|
// Deprecated: this option is moved to the P2P section.
|
2021-05-04 14:54:16 +00:00
|
|
|
ExtensiblePoolSize int `yaml:"ExtensiblePoolSize"`
|
2020-03-25 15:30:21 +00:00
|
|
|
}
|
2022-07-26 13:16:48 +00:00
|
|
|
|
|
|
|
// EqualsButServices returns true when the o is the same as a except for services
|
2022-12-05 11:58:16 +00:00
|
|
|
// (Oracle, P2PNotary, Pprof, Prometheus, RPC, StateRoot and UnlockWallet sections)
|
|
|
|
// and LogLevel field.
|
2022-07-26 13:16:48 +00:00
|
|
|
func (a *ApplicationConfiguration) EqualsButServices(o *ApplicationConfiguration) bool {
|
2022-12-06 19:35:37 +00:00
|
|
|
if len(a.P2P.Addresses) != len(o.P2P.Addresses) {
|
2022-11-29 14:43:08 +00:00
|
|
|
return false
|
|
|
|
}
|
2022-12-06 19:35:37 +00:00
|
|
|
aCp := make([]string, len(a.P2P.Addresses))
|
|
|
|
oCp := make([]string, len(o.P2P.Addresses))
|
|
|
|
copy(aCp, a.P2P.Addresses)
|
|
|
|
copy(oCp, o.P2P.Addresses)
|
2022-11-29 14:43:08 +00:00
|
|
|
sort.Strings(aCp)
|
|
|
|
sort.Strings(oCp)
|
|
|
|
for i := range aCp {
|
|
|
|
if aCp[i] != oCp[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2023-10-09 20:02:15 +00:00
|
|
|
if a.AttemptConnPeers != o.AttemptConnPeers || //nolint:staticcheck // SA1019: a.AttemptConnPeers is deprecated
|
2022-12-06 19:35:37 +00:00
|
|
|
a.P2P.AttemptConnPeers != o.P2P.AttemptConnPeers ||
|
|
|
|
a.BroadcastFactor != o.BroadcastFactor || //nolint:staticcheck // SA1019: a.BroadcastFactor is deprecated
|
|
|
|
a.P2P.BroadcastFactor != o.P2P.BroadcastFactor ||
|
2022-07-26 13:16:48 +00:00
|
|
|
a.DBConfiguration != o.DBConfiguration ||
|
2022-12-06 19:35:37 +00:00
|
|
|
a.DialTimeout != o.DialTimeout || //nolint:staticcheck // SA1019: a.DialTimeout is deprecated
|
|
|
|
a.P2P.DialTimeout != o.P2P.DialTimeout ||
|
|
|
|
a.ExtensiblePoolSize != o.ExtensiblePoolSize || //nolint:staticcheck // SA1019: a.ExtensiblePoolSize is deprecated
|
|
|
|
a.P2P.ExtensiblePoolSize != o.P2P.ExtensiblePoolSize ||
|
2022-07-26 13:16:48 +00:00
|
|
|
a.LogPath != o.LogPath ||
|
2022-12-06 19:35:37 +00:00
|
|
|
a.MaxPeers != o.MaxPeers || //nolint:staticcheck // SA1019: a.MaxPeers is deprecated
|
|
|
|
a.P2P.MaxPeers != o.P2P.MaxPeers ||
|
|
|
|
a.MinPeers != o.MinPeers || //nolint:staticcheck // SA1019: a.MinPeers is deprecated
|
|
|
|
a.P2P.MinPeers != o.P2P.MinPeers ||
|
|
|
|
a.PingInterval != o.PingInterval || //nolint:staticcheck // SA1019: a.PingInterval is deprecated
|
|
|
|
a.P2P.PingInterval != o.P2P.PingInterval ||
|
|
|
|
a.PingTimeout != o.PingTimeout || //nolint:staticcheck // SA1019: a.PingTimeout is deprecated
|
|
|
|
a.P2P.PingTimeout != o.P2P.PingTimeout ||
|
|
|
|
a.ProtoTickInterval != o.ProtoTickInterval || //nolint:staticcheck // SA1019: a.ProtoTickInterval is deprecated
|
|
|
|
a.P2P.ProtoTickInterval != o.P2P.ProtoTickInterval ||
|
2022-07-26 13:16:48 +00:00
|
|
|
a.Relay != o.Relay {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2022-11-29 14:43:08 +00:00
|
|
|
|
|
|
|
// AnnounceableAddress is a pair of node address in the form of "[host]:[port]"
|
|
|
|
// with optional corresponding announced port to be used in version exchange.
|
|
|
|
type AnnounceableAddress struct {
|
|
|
|
Address string
|
|
|
|
AnnouncedPort uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAddresses parses returns the list of AnnounceableAddress containing information
|
2023-10-09 20:02:15 +00:00
|
|
|
// gathered from Addresses.
|
2022-11-29 14:43:08 +00:00
|
|
|
func (a *ApplicationConfiguration) GetAddresses() ([]AnnounceableAddress, error) {
|
2023-10-09 20:02:15 +00:00
|
|
|
addrs := make([]AnnounceableAddress, 0, len(a.P2P.Addresses))
|
2022-12-06 19:35:37 +00:00
|
|
|
for i, addrStr := range a.P2P.Addresses {
|
2022-11-29 14:43:08 +00:00
|
|
|
if len(addrStr) == 0 {
|
|
|
|
return nil, fmt.Errorf("address #%d is empty", i)
|
|
|
|
}
|
|
|
|
lastCln := strings.LastIndex(addrStr, ":")
|
|
|
|
if lastCln == -1 {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr, // Plain IPv4 address without port.
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lastPort, err := strconv.ParseUint(addrStr[lastCln+1:], 10, 16)
|
|
|
|
if err != nil {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr, // Still may be a valid IPv4 of the form "X.Y.Z.Q:" or plain IPv6 "A:B::", keep it.
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
penultimateCln := strings.LastIndex(addrStr[:lastCln], ":")
|
|
|
|
if penultimateCln == -1 {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr, // IPv4 address with port "X.Y.Z.Q:123"
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
isV6 := strings.Count(addrStr, ":") > 2
|
|
|
|
hasBracket := strings.Contains(addrStr, "]")
|
|
|
|
if penultimateCln == lastCln-1 {
|
|
|
|
if isV6 && !hasBracket {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr, // Plain IPv6 of the form "A:B::123"
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr[:lastCln], // IPv4 with empty port and non-empty announced port "X.Y.Z.Q::123" or IPv6 with non-empty announced port "[A:B::]::123".
|
|
|
|
AnnouncedPort: uint16(lastPort),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_, err = strconv.ParseUint(addrStr[penultimateCln+1:lastCln], 10, 16)
|
|
|
|
if err != nil {
|
|
|
|
if isV6 {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr, // Still may be a valid plain IPv6 of the form "A::B:123" or IPv6 with single port [A:B::]:123, keep it.
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("failed to parse port from %s: %w", addrStr, err) // Some garbage.
|
|
|
|
}
|
|
|
|
if isV6 && !hasBracket {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr, // Plain IPv6 of the form "A::1:1"
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: addrStr[:lastCln], // IPv4 with both ports or IPv6 with both ports specified.
|
|
|
|
AnnouncedPort: uint16(lastPort),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(addrs) == 0 {
|
|
|
|
addrs = append(addrs, AnnounceableAddress{
|
|
|
|
Address: ":0",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return addrs, nil
|
|
|
|
}
|