2018-03-15 20:45:37 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2022-11-29 14:43:08 +00:00
|
|
|
"fmt"
|
2018-03-15 20:45:37 +00:00
|
|
|
"time"
|
|
|
|
|
2020-03-25 15:30:21 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2020-06-14 07:34:50 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
2019-12-30 07:43:05 +00:00
|
|
|
"go.uber.org/zap/zapcore"
|
2018-03-15 20:45:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// ServerConfig holds the server configuration.
|
|
|
|
ServerConfig struct {
|
2022-04-20 18:30:09 +00:00
|
|
|
// MinPeers is the minimum number of peers for normal operation.
|
|
|
|
// When a node has less than this number of peers, it tries to
|
2019-10-31 12:04:28 +00:00
|
|
|
// connect with some new ones.
|
|
|
|
MinPeers int
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// AttemptConnPeers is the number of connection to try to
|
2019-11-06 12:17:20 +00:00
|
|
|
// establish when the connection count drops below the MinPeers
|
|
|
|
// value.
|
|
|
|
AttemptConnPeers int
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// MaxPeers is the maximum number of peers that can
|
2018-03-15 20:45:37 +00:00
|
|
|
// be connected to the server.
|
|
|
|
MaxPeers int
|
|
|
|
|
|
|
|
// The user agent of the server.
|
|
|
|
UserAgent string
|
|
|
|
|
2022-11-29 14:43:08 +00:00
|
|
|
// Addresses stores the list of bind addresses for the node.
|
|
|
|
Addresses []config.AnnounceableAddress
|
2018-03-15 20:45:37 +00:00
|
|
|
|
|
|
|
// The network mode the server will operate on.
|
|
|
|
// ModePrivNet docker private network.
|
2022-12-07 13:51:03 +00:00
|
|
|
// ModeTestNet Neo test network.
|
|
|
|
// ModeMainNet Neo main network.
|
2020-06-14 07:34:50 +00:00
|
|
|
Net netmode.Magic
|
2018-03-15 20:45:37 +00:00
|
|
|
|
2019-02-09 15:53:58 +00:00
|
|
|
// Relay determines whether the server is forwarding its inventory.
|
2018-03-15 20:45:37 +00:00
|
|
|
Relay bool
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Seeds is a list of initial nodes used to establish connectivity.
|
2018-03-15 20:45:37 +00:00
|
|
|
Seeds []string
|
|
|
|
|
|
|
|
// Maximum duration a single dial may take.
|
|
|
|
DialTimeout time.Duration
|
|
|
|
|
|
|
|
// The duration between protocol ticks with each connected peer.
|
|
|
|
// When this is 0, the default interval of 5 seconds will be used.
|
|
|
|
ProtoTickInterval time.Duration
|
|
|
|
|
2020-01-17 10:17:19 +00:00
|
|
|
// Interval used in pinging mechanism for syncing blocks.
|
|
|
|
PingInterval time.Duration
|
|
|
|
// Time to wait for pong(response for sent ping request).
|
|
|
|
PingTimeout time.Duration
|
|
|
|
|
2018-03-15 20:45:37 +00:00
|
|
|
// Level of the internal logger.
|
2019-12-30 07:43:05 +00:00
|
|
|
LogLevel zapcore.Level
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2020-01-13 14:57:40 +00:00
|
|
|
// TimePerBlock is an interval which should pass between two successive blocks.
|
|
|
|
TimePerBlock time.Duration
|
2020-09-28 11:58:04 +00:00
|
|
|
|
|
|
|
// OracleCfg is oracle module configuration.
|
|
|
|
OracleCfg config.OracleConfiguration
|
2021-02-16 10:49:56 +00:00
|
|
|
|
|
|
|
// P2PNotaryCfg is notary module configuration.
|
|
|
|
P2PNotaryCfg config.P2PNotary
|
2021-02-02 09:34:27 +00:00
|
|
|
|
|
|
|
// StateRootCfg is stateroot module configuration.
|
|
|
|
StateRootCfg config.StateRoot
|
2021-05-04 14:54:16 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// ExtensiblePoolSize is the size of the pool for extensible payloads from a single sender.
|
2021-05-04 14:54:16 +00:00
|
|
|
ExtensiblePoolSize int
|
2022-10-13 19:14:14 +00:00
|
|
|
|
|
|
|
// BroadcastFactor is the factor (0-100) for fan-out optimization.
|
|
|
|
BroadcastFactor int
|
2024-09-05 11:23:15 +00:00
|
|
|
|
|
|
|
NeoFSBlockFetcherCfg config.NeoFSBlockFetcher
|
2018-03-15 20:45:37 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewServerConfig creates a new ServerConfig struct
|
|
|
|
// using the main applications config.
|
2022-11-29 14:43:08 +00:00
|
|
|
func NewServerConfig(cfg config.Config) (ServerConfig, error) {
|
2018-03-25 10:45:54 +00:00
|
|
|
appConfig := cfg.ApplicationConfiguration
|
|
|
|
protoConfig := cfg.ProtocolConfiguration
|
2022-11-29 14:43:08 +00:00
|
|
|
addrs, err := appConfig.GetAddresses()
|
|
|
|
if err != nil {
|
|
|
|
return ServerConfig{}, fmt.Errorf("failed to parse addresses: %w", err)
|
|
|
|
}
|
2022-12-06 19:35:37 +00:00
|
|
|
c := ServerConfig{
|
2024-09-05 11:23:15 +00:00
|
|
|
UserAgent: cfg.GenerateUserAgent(),
|
|
|
|
Addresses: addrs,
|
|
|
|
Net: protoConfig.Magic,
|
|
|
|
Relay: appConfig.Relay,
|
|
|
|
Seeds: protoConfig.SeedList,
|
|
|
|
DialTimeout: appConfig.P2P.DialTimeout,
|
|
|
|
ProtoTickInterval: appConfig.P2P.ProtoTickInterval,
|
|
|
|
PingInterval: appConfig.P2P.PingInterval,
|
|
|
|
PingTimeout: appConfig.P2P.PingTimeout,
|
|
|
|
MaxPeers: appConfig.P2P.MaxPeers,
|
|
|
|
AttemptConnPeers: appConfig.P2P.AttemptConnPeers,
|
|
|
|
MinPeers: appConfig.P2P.MinPeers,
|
|
|
|
TimePerBlock: protoConfig.TimePerBlock,
|
|
|
|
OracleCfg: appConfig.Oracle,
|
|
|
|
P2PNotaryCfg: appConfig.P2PNotary,
|
|
|
|
StateRootCfg: appConfig.StateRoot,
|
|
|
|
ExtensiblePoolSize: appConfig.P2P.ExtensiblePoolSize,
|
|
|
|
BroadcastFactor: appConfig.P2P.BroadcastFactor,
|
|
|
|
NeoFSBlockFetcherCfg: appConfig.NeoFSBlockFetcher,
|
2022-12-06 19:35:37 +00:00
|
|
|
}
|
|
|
|
return c, nil
|
2018-03-15 20:45:37 +00:00
|
|
|
}
|