[#1422] ir: Add dialer source
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
f7caef355b
commit
ef38420623
3 changed files with 40 additions and 6 deletions
|
@ -48,6 +48,8 @@ func defaultConfiguration(cfg *viper.Viper) {
|
|||
cfg.SetDefault("node.kludge_compatibility_mode", false)
|
||||
|
||||
cfg.SetDefault("audit.enabled", false)
|
||||
|
||||
setMultinetDefaults(cfg)
|
||||
}
|
||||
|
||||
func setControlDefaults(cfg *viper.Viper) {
|
||||
|
@ -131,3 +133,11 @@ func setMorphDefaults(cfg *viper.Viper) {
|
|||
cfg.SetDefault("morph.validators", []string{})
|
||||
cfg.SetDefault("morph.switch_interval", 2*time.Minute)
|
||||
}
|
||||
|
||||
func setMultinetDefaults(cfg *viper.Viper) {
|
||||
cfg.SetDefault("multinet.enabled", false)
|
||||
cfg.SetDefault("multinet.balancer", "")
|
||||
cfg.SetDefault("multinet.restrict", false)
|
||||
cfg.SetDefault("multinet.fallback_delay", "0s")
|
||||
cfg.SetDefault("multinet.subnets", "")
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/metrics"
|
||||
internalNet "git.frostfs.info/TrueCloudLab/frostfs-node/internal/net"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/config"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/alphabet"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/governance"
|
||||
|
@ -486,6 +487,12 @@ func createClient(ctx context.Context, p *chainParams, errChan chan<- error) (*c
|
|||
return nil, fmt.Errorf("%s chain client endpoints not provided", p.name)
|
||||
}
|
||||
|
||||
nc := parseMultinetConfig(p.cfg)
|
||||
ds, err := internalNet.NewDialerSource(nc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dialer source: %w", err)
|
||||
}
|
||||
|
||||
return client.New(
|
||||
ctx,
|
||||
p.key,
|
||||
|
@ -498,6 +505,7 @@ func createClient(ctx context.Context, p *chainParams, errChan chan<- error) (*c
|
|||
}),
|
||||
client.WithSwitchInterval(p.cfg.GetDuration(p.name+".switch_interval")),
|
||||
client.WithMorphCacheMetrics(p.morphCacheMetric),
|
||||
client.WithDialerSource(ds),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -542,6 +550,27 @@ func parseWalletAddressesFromStrings(wallets []string) ([]util.Uint160, error) {
|
|||
return extraWallets, nil
|
||||
}
|
||||
|
||||
func parseMultinetConfig(cfg *viper.Viper) internalNet.Config {
|
||||
nc := internalNet.Config{
|
||||
Enabled: cfg.GetBool("multinet.enabled"),
|
||||
Balancer: cfg.GetString("multinet.balancer"),
|
||||
Restrict: cfg.GetBool("multinet.restrict"),
|
||||
FallbackDelay: cfg.GetDuration("multinet.fallback_delay"),
|
||||
}
|
||||
for i := 0; ; i++ {
|
||||
mask := cfg.GetString(fmt.Sprintf("multinet.subnets.%d.mask", i))
|
||||
if mask == "" {
|
||||
break
|
||||
}
|
||||
sourceIPs := cfg.GetStringSlice(fmt.Sprintf("multinet.subnets.%d.source_ips", i))
|
||||
nc.Subnets = append(nc.Subnets, internalNet.Subnet{
|
||||
Prefix: mask,
|
||||
SourceIPs: sourceIPs,
|
||||
})
|
||||
}
|
||||
return nc
|
||||
}
|
||||
|
||||
func (s *Server) initConfigFromBlockchain() error {
|
||||
// get current epoch
|
||||
epoch, err := s.netmapClient.Epoch()
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
|
@ -157,15 +156,11 @@ func (c *Client) newCli(ctx context.Context, endpoint Endpoint) (*rpcclient.WSCl
|
|||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("read mtls certificates: %w", err)
|
||||
}
|
||||
var netDialContext func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
if c.cfg.dialerSource != nil { // TODO fix after IR
|
||||
netDialContext = c.cfg.dialerSource.NetContextDialer()
|
||||
}
|
||||
cli, err := rpcclient.NewWS(ctx, endpoint.Address, rpcclient.WSOptions{
|
||||
Options: rpcclient.Options{
|
||||
DialTimeout: c.cfg.dialTimeout,
|
||||
TLSClientConfig: cfg,
|
||||
NetDialContext: netDialContext,
|
||||
NetDialContext: c.cfg.dialerSource.NetContextDialer(),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue