forked from TrueCloudLab/frostfs-node
[#607] network: Generalize LocalAddressSource to address group
Make `LocalAddressSource.LocalAddress` method to return `AddressGroup`. Make `IsLocalAddress` function to accept parameter of type `AddressGroup`. Adopt the application code with temporary `GroupFromAddress` helper. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
e11f50ec8e
commit
6e5d7f84af
7 changed files with 15 additions and 15 deletions
|
@ -90,7 +90,7 @@ type cfg struct {
|
||||||
|
|
||||||
cfgNodeInfo cfgNodeInfo
|
cfgNodeInfo cfgNodeInfo
|
||||||
|
|
||||||
localAddr network.Address
|
localAddr network.AddressGroup
|
||||||
|
|
||||||
cfgObject cfgObject
|
cfgObject cfgObject
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ func initCfg(path string) *cfg {
|
||||||
tlsCertFile: tlsCertFile,
|
tlsCertFile: tlsCertFile,
|
||||||
tlsKeyFile: tlsKeyFile,
|
tlsKeyFile: tlsKeyFile,
|
||||||
},
|
},
|
||||||
localAddr: netAddr,
|
localAddr: network.GroupFromAddress(netAddr),
|
||||||
respSvc: response.NewService(
|
respSvc: response.NewService(
|
||||||
response.WithNetworkState(state),
|
response.WithNetworkState(state),
|
||||||
),
|
),
|
||||||
|
@ -308,7 +308,7 @@ func initCfg(path string) *cfg {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cfg) LocalAddress() network.Address {
|
func (c *cfg) LocalAddress() network.AddressGroup {
|
||||||
return c.localAddr
|
return c.localAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc
|
||||||
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
|
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if network.IsLocalAddress(r.loadAddrSrc, netAddr) {
|
if network.IsLocalAddress(r.loadAddrSrc, network.GroupFromAddress(netAddr)) {
|
||||||
// if local => return no-op writer
|
// if local => return no-op writer
|
||||||
return loadcontroller.SimpleWriterProvider(new(nopLoadWriter)), nil
|
return loadcontroller.SimpleWriterProvider(new(nopLoadWriter)), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep
|
||||||
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
|
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if network.IsLocalAddress(rtp.localAddrSrc, netAddr) {
|
if network.IsLocalAddress(rtp.localAddrSrc, network.GroupFromAddress(netAddr)) {
|
||||||
// if local => return no-op writer
|
// if local => return no-op writer
|
||||||
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Address struct {
|
||||||
// LocalAddressSource is an interface of local
|
// LocalAddressSource is an interface of local
|
||||||
// network address container with read access.
|
// network address container with read access.
|
||||||
type LocalAddressSource interface {
|
type LocalAddressSource interface {
|
||||||
LocalAddress() Address
|
LocalAddress() AddressGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns multiaddr string.
|
// String returns multiaddr string.
|
||||||
|
@ -107,8 +107,8 @@ func multiaddrStringFromHostAddr(host string) (string, error) {
|
||||||
return strings.Join([]string{prefix, addr, l4Protocol, port}, "/"), nil
|
return strings.Join([]string{prefix, addr, l4Protocol, port}, "/"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLocalAddress returns true if network endpoint from local address
|
// IsLocalAddress returns true if network endpoints from local address group
|
||||||
// source is equal to network endpoint of passed address.
|
// source intersects with network endpoints of passed address group.
|
||||||
func IsLocalAddress(src LocalAddressSource, addr Address) bool {
|
func IsLocalAddress(src LocalAddressSource, addr AddressGroup) bool {
|
||||||
return src.LocalAddress().Equal(addr)
|
return src.LocalAddress().Intersects(addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
||||||
var relay func(network.Address) error
|
var relay func(network.Address) error
|
||||||
if p.relay != nil {
|
if p.relay != nil {
|
||||||
relay = func(addr network.Address) error {
|
relay = func(addr network.Address) error {
|
||||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||||
return errLocalAddress
|
return errLocalAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
||||||
traverseOpts: prm.traverseOpts,
|
traverseOpts: prm.traverseOpts,
|
||||||
workerPool: p.workerPool,
|
workerPool: p.workerPool,
|
||||||
nodeTargetInitializer: func(addr network.Address) transformer.ObjectTarget {
|
nodeTargetInitializer: func(addr network.Address) transformer.ObjectTarget {
|
||||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||||
return &localTarget{
|
return &localTarget{
|
||||||
storage: p.localStore,
|
storage: p.localStore,
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (p *localPlacement) BuildPlacement(addr *object.Address, policy *netmapSDK.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||||
return []netmapSDK.Nodes{{vs[i][j]}}, nil
|
return []netmapSDK.Nodes{{vs[i][j]}}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func (p *remotePlacement) BuildPlacement(addr *object.Address, policy *netmapSDK
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||||
vs[i] = append(vs[i][:j], vs[i][j+1:]...)
|
vs[i] = append(vs[i][:j], vs[i][j+1:]...)
|
||||||
j--
|
j--
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if network.IsLocalAddress(p.localAddrSrc, node) {
|
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(node)) {
|
||||||
if shortage == 0 {
|
if shortage == 0 {
|
||||||
// we can call the redundant copy callback
|
// we can call the redundant copy callback
|
||||||
// here to slightly improve the performance
|
// here to slightly improve the performance
|
||||||
|
|
Loading…
Reference in a new issue