2018-03-15 20:45:37 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2018-03-25 10:45:54 +00:00
|
|
|
"github.com/CityOfZion/neo-go/config"
|
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 {
|
2019-10-31 12:04:28 +00:00
|
|
|
// MinPeers is the minimum number of peers for normal operation,
|
|
|
|
// when the node has less than this number of peers it tries to
|
|
|
|
// connect with some new ones.
|
|
|
|
MinPeers int
|
|
|
|
|
2019-11-06 12:17:20 +00:00
|
|
|
// AttemptConnPeers it the number of connection to try to
|
|
|
|
// establish when the connection count drops below the MinPeers
|
|
|
|
// value.
|
|
|
|
AttemptConnPeers int
|
|
|
|
|
2018-03-15 20:45:37 +00:00
|
|
|
// MaxPeers it the maximum numbers of peers that can
|
|
|
|
// be connected to the server.
|
|
|
|
MaxPeers int
|
|
|
|
|
|
|
|
// The user agent of the server.
|
|
|
|
UserAgent string
|
|
|
|
|
2019-11-05 12:22:07 +00:00
|
|
|
// Address. Example: "127.0.0.1".
|
|
|
|
Address string
|
|
|
|
|
|
|
|
// Port. Example: 20332.
|
|
|
|
Port uint16
|
2018-03-15 20:45:37 +00:00
|
|
|
|
|
|
|
// The network mode the server will operate on.
|
|
|
|
// ModePrivNet docker private network.
|
|
|
|
// ModeTestNet NEO test network.
|
|
|
|
// ModeMainNet NEO main network.
|
2018-03-25 10:45:54 +00:00
|
|
|
Net config.NetMode
|
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
|
|
|
|
|
|
|
|
// Seeds are a list of initial nodes used to establish connectivity.
|
|
|
|
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
|
|
|
|
|
|
|
// Wallet is a wallet configuration.
|
|
|
|
Wallet *config.WalletConfig
|
2020-01-13 14:57:40 +00:00
|
|
|
|
|
|
|
// TimePerBlock is an interval which should pass between two successive blocks.
|
|
|
|
TimePerBlock time.Duration
|
2018-03-15 20:45:37 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewServerConfig creates a new ServerConfig struct
|
|
|
|
// using the main applications config.
|
2018-03-25 10:45:54 +00:00
|
|
|
func NewServerConfig(cfg config.Config) ServerConfig {
|
|
|
|
appConfig := cfg.ApplicationConfiguration
|
|
|
|
protoConfig := cfg.ProtocolConfiguration
|
2018-03-15 20:45:37 +00:00
|
|
|
|
2019-11-15 10:32:40 +00:00
|
|
|
var wc *config.WalletConfig
|
|
|
|
if appConfig.UnlockWallet.Path != "" {
|
|
|
|
wc = &appConfig.UnlockWallet
|
|
|
|
}
|
|
|
|
|
2018-03-15 20:45:37 +00:00
|
|
|
return ServerConfig{
|
2018-03-25 10:45:54 +00:00
|
|
|
UserAgent: cfg.GenerateUserAgent(),
|
2019-11-05 12:22:07 +00:00
|
|
|
Address: appConfig.Address,
|
|
|
|
Port: appConfig.NodePort,
|
2018-03-15 20:45:37 +00:00
|
|
|
Net: protoConfig.Magic,
|
|
|
|
Relay: appConfig.Relay,
|
|
|
|
Seeds: protoConfig.SeedList,
|
2019-01-25 11:20:35 +00:00
|
|
|
DialTimeout: appConfig.DialTimeout * time.Second,
|
|
|
|
ProtoTickInterval: appConfig.ProtoTickInterval * time.Second,
|
2020-01-17 10:17:19 +00:00
|
|
|
PingInterval: appConfig.PingInterval * time.Second,
|
|
|
|
PingTimeout: appConfig.PingTimeout * time.Second,
|
2018-03-15 20:45:37 +00:00
|
|
|
MaxPeers: appConfig.MaxPeers,
|
2019-11-06 12:17:20 +00:00
|
|
|
AttemptConnPeers: appConfig.AttemptConnPeers,
|
2019-10-31 12:04:28 +00:00
|
|
|
MinPeers: appConfig.MinPeers,
|
2019-11-15 10:32:40 +00:00
|
|
|
Wallet: wc,
|
2020-01-13 14:57:40 +00:00
|
|
|
TimePerBlock: time.Duration(protoConfig.SecondsPerBlock) * time.Second,
|
2018-03-15 20:45:37 +00:00
|
|
|
}
|
|
|
|
}
|