[#1422] ir: Add dialer source
Some checks failed
Tests and linters / Tests with -race (pull_request) Failing after 42s
Vulncheck / Vulncheck (pull_request) Failing after 58s
Build / Build Components (pull_request) Failing after 1m10s
DCO action / DCO (pull_request) Successful in 1m11s
Tests and linters / Tests (pull_request) Failing after 1m28s
Pre-commit hooks / Pre-commit (pull_request) Failing after 1m38s
Tests and linters / Run gofumpt (pull_request) Successful in 1m34s
Tests and linters / Staticcheck (pull_request) Failing after 1m56s
Tests and linters / gopls check (pull_request) Failing after 2m26s
Tests and linters / Lint (pull_request) Failing after 3m23s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-10-14 13:51:21 +03:00
parent 860d163d85
commit 1ff0e20c7b
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
3 changed files with 43 additions and 6 deletions

View file

@ -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", "")
}

View file

@ -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()

View file

@ -158,12 +158,10 @@ func (c *Client) newCli(ctx context.Context, endpoint Endpoint) (*rpcclient.WSCl
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
d, enabled := c.cfg.dialerSource.Dialer()
if enabled {
netDialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return d.DialContext(ctx, network, addr)
}
d, enabled := c.cfg.dialerSource.Dialer()
if enabled {
netDialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return d.DialContext(ctx, network, addr)
}
}
cli, err := rpcclient.NewWS(ctx, endpoint.Address, rpcclient.WSOptions{