updated to limit max rpc connecitons and peer connections.
changed to use time.Duration type for timeout values
This commit is contained in:
@ -8,6 +8,7 @@ import "hodu"
|
||||
import "io"
|
||||
import "io/ioutil"
|
||||
import "os"
|
||||
import "time"
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
@ -48,25 +49,32 @@ type CTLServiceConfig struct {
|
||||
|
||||
type RPCServiceConfig struct { // rpc server-side configuration
|
||||
Addrs []string `yaml:"addresses"`
|
||||
MaxConns int `yaml:"max-connections"` // TODO: implement this item
|
||||
}
|
||||
|
||||
type RPCEndpointConfig struct { // rpc client-side configuration
|
||||
Authority string `yaml:"authority"`
|
||||
Addrs []string `yaml:"addresses"`
|
||||
SeedTimeout int `yaml:"seed-timeout"`
|
||||
Authority string `yaml:"authority"`
|
||||
Addrs []string `yaml:"addresses"`
|
||||
SeedTmout time.Duration `yaml:"seed-timeout"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
LogMask []string `yaml:"log-mask"`
|
||||
LogFile string `yaml:"log-file"`
|
||||
type ServerAppConfig struct {
|
||||
LogMask []string `yaml:"log-mask"`
|
||||
LogFile string `yaml:"log-file"`
|
||||
MaxPeers int `yaml:"max-peer-conns"` // maximum number of connections from peers
|
||||
MaxRpcConns int `yaml:"max-rpc-conns"` // maximum number of rpc connections
|
||||
}
|
||||
|
||||
type ClientAppConfig struct {
|
||||
LogMask []string `yaml:"log-mask"`
|
||||
LogFile string `yaml:"log-file"`
|
||||
MaxPeers int `yaml:"max-peer-conns"` // maximum number of connections from peers
|
||||
MaxRpcConns int `yaml:"max-rpc-conns"` // maximum number of rpc connections
|
||||
PeerConnTmout time.Duration `yaml:"peer-conn-timeout"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
APP AppConfig `yaml:"app"`
|
||||
APP ServerAppConfig `yaml:"app"`
|
||||
|
||||
// TODO: add some limits
|
||||
// max number of clients, max nubmer of peers
|
||||
CTL struct {
|
||||
Service CTLServiceConfig `yaml:"service"`
|
||||
TLS ServerTLSConfig `yaml:"tls"`
|
||||
@ -79,10 +87,8 @@ type ServerConfig struct {
|
||||
}
|
||||
|
||||
type ClientConfig struct {
|
||||
APP AppConfig `yaml:"app"`
|
||||
APP ClientAppConfig `yaml:"app"`
|
||||
|
||||
// TODO: add some limits
|
||||
// max nubmer of peers
|
||||
CTL struct {
|
||||
Service CTLServiceConfig `yaml:"service"`
|
||||
TLS ServerTLSConfig `yaml:"tls"`
|
||||
|
15
cmd/main.go
15
cmd/main.go
@ -184,12 +184,14 @@ func server_main(ctl_addrs []string, rpc_addrs []string, cfg *ServerConfig) erro
|
||||
logger = &AppLogger{id: "server", out: os.Stderr, mask: log_mask}
|
||||
s, err = hodu.NewServer(
|
||||
context.Background(),
|
||||
logger,
|
||||
ctl_addrs,
|
||||
rpc_addrs,
|
||||
logger,
|
||||
ctl_prefix,
|
||||
ctltlscfg,
|
||||
rpctlscfg)
|
||||
rpctlscfg,
|
||||
cfg.APP.MaxRpcConns,
|
||||
cfg.APP.MaxPeers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create new server - %s", err.Error())
|
||||
}
|
||||
@ -229,7 +231,7 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
|
||||
if len(rpc_addrs) <= 0 { rpc_addrs = cfg.RPC.Endpoint.Addrs }
|
||||
ctl_prefix = cfg.CTL.Service.Prefix
|
||||
|
||||
cc.ServerSeedTimeout = cfg.RPC.Endpoint.SeedTimeout
|
||||
cc.ServerSeedTmout = cfg.RPC.Endpoint.SeedTmout
|
||||
cc.ServerAuthority = cfg.RPC.Endpoint.Authority
|
||||
log_mask = log_strings_to_mask(cfg.APP.LogMask)
|
||||
}
|
||||
@ -242,11 +244,14 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
|
||||
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_mask}
|
||||
c = hodu.NewClient(
|
||||
context.Background(),
|
||||
ctl_addrs,
|
||||
logger,
|
||||
ctl_addrs,
|
||||
ctl_prefix,
|
||||
ctltlscfg,
|
||||
rpctlscfg)
|
||||
rpctlscfg,
|
||||
cfg.APP.MaxRpcConns,
|
||||
cfg.APP.MaxPeers,
|
||||
cfg.APP.PeerConnTmout)
|
||||
|
||||
c.StartService(&cc)
|
||||
c.StartCtlService() // control channel
|
||||
|
Reference in New Issue
Block a user