github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/network/server_config.go (about) 1 package network 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/nspcc-dev/neo-go/pkg/config" 8 "github.com/nspcc-dev/neo-go/pkg/config/netmode" 9 "go.uber.org/zap/zapcore" 10 ) 11 12 type ( 13 // ServerConfig holds the server configuration. 14 ServerConfig struct { 15 // MinPeers is the minimum number of peers for normal operation. 16 // When a node has less than this number of peers, it tries to 17 // connect with some new ones. 18 MinPeers int 19 20 // AttemptConnPeers is the number of connection to try to 21 // establish when the connection count drops below the MinPeers 22 // value. 23 AttemptConnPeers int 24 25 // MaxPeers is the maximum number of peers that can 26 // be connected to the server. 27 MaxPeers int 28 29 // The user agent of the server. 30 UserAgent string 31 32 // Addresses stores the list of bind addresses for the node. 33 Addresses []config.AnnounceableAddress 34 35 // The network mode the server will operate on. 36 // ModePrivNet docker private network. 37 // ModeTestNet Neo test network. 38 // ModeMainNet Neo main network. 39 Net netmode.Magic 40 41 // Relay determines whether the server is forwarding its inventory. 42 Relay bool 43 44 // Seeds is a list of initial nodes used to establish connectivity. 45 Seeds []string 46 47 // Maximum duration a single dial may take. 48 DialTimeout time.Duration 49 50 // The duration between protocol ticks with each connected peer. 51 // When this is 0, the default interval of 5 seconds will be used. 52 ProtoTickInterval time.Duration 53 54 // Interval used in pinging mechanism for syncing blocks. 55 PingInterval time.Duration 56 // Time to wait for pong(response for sent ping request). 57 PingTimeout time.Duration 58 59 // Level of the internal logger. 60 LogLevel zapcore.Level 61 62 // TimePerBlock is an interval which should pass between two successive blocks. 63 TimePerBlock time.Duration 64 65 // OracleCfg is oracle module configuration. 66 OracleCfg config.OracleConfiguration 67 68 // P2PNotaryCfg is notary module configuration. 69 P2PNotaryCfg config.P2PNotary 70 71 // StateRootCfg is stateroot module configuration. 72 StateRootCfg config.StateRoot 73 74 // ExtensiblePoolSize is the size of the pool for extensible payloads from a single sender. 75 ExtensiblePoolSize int 76 77 // BroadcastFactor is the factor (0-100) for fan-out optimization. 78 BroadcastFactor int 79 } 80 ) 81 82 // NewServerConfig creates a new ServerConfig struct 83 // using the main applications config. 84 func NewServerConfig(cfg config.Config) (ServerConfig, error) { 85 appConfig := cfg.ApplicationConfiguration 86 protoConfig := cfg.ProtocolConfiguration 87 addrs, err := appConfig.GetAddresses() 88 if err != nil { 89 return ServerConfig{}, fmt.Errorf("failed to parse addresses: %w", err) 90 } 91 c := ServerConfig{ 92 UserAgent: cfg.GenerateUserAgent(), 93 Addresses: addrs, 94 Net: protoConfig.Magic, 95 Relay: appConfig.Relay, 96 Seeds: protoConfig.SeedList, 97 DialTimeout: appConfig.P2P.DialTimeout, 98 ProtoTickInterval: appConfig.P2P.ProtoTickInterval, 99 PingInterval: appConfig.P2P.PingInterval, 100 PingTimeout: appConfig.P2P.PingTimeout, 101 MaxPeers: appConfig.P2P.MaxPeers, 102 AttemptConnPeers: appConfig.P2P.AttemptConnPeers, 103 MinPeers: appConfig.P2P.MinPeers, 104 TimePerBlock: protoConfig.TimePerBlock, 105 OracleCfg: appConfig.Oracle, 106 P2PNotaryCfg: appConfig.P2PNotary, 107 StateRootCfg: appConfig.StateRoot, 108 ExtensiblePoolSize: appConfig.P2P.ExtensiblePoolSize, 109 BroadcastFactor: appConfig.P2P.BroadcastFactor, 110 } 111 return c, nil 112 }