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>support/v0.27
parent
e11f50ec8e
commit
6e5d7f84af
|
@ -90,7 +90,7 @@ type cfg struct {
|
|||
|
||||
cfgNodeInfo cfgNodeInfo
|
||||
|
||||
localAddr network.Address
|
||||
localAddr network.AddressGroup
|
||||
|
||||
cfgObject cfgObject
|
||||
|
||||
|
@ -285,7 +285,7 @@ func initCfg(path string) *cfg {
|
|||
tlsCertFile: tlsCertFile,
|
||||
tlsKeyFile: tlsKeyFile,
|
||||
},
|
||||
localAddr: netAddr,
|
||||
localAddr: network.GroupFromAddress(netAddr),
|
||||
respSvc: response.NewService(
|
||||
response.WithNetworkState(state),
|
||||
),
|
||||
|
@ -308,7 +308,7 @@ func initCfg(path string) *cfg {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *cfg) LocalAddress() network.Address {
|
||||
func (c *cfg) LocalAddress() network.AddressGroup {
|
||||
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)
|
||||
}
|
||||
|
||||
if network.IsLocalAddress(r.loadAddrSrc, netAddr) {
|
||||
if network.IsLocalAddress(r.loadAddrSrc, network.GroupFromAddress(netAddr)) {
|
||||
// if local => return no-op writer
|
||||
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)
|
||||
}
|
||||
|
||||
if network.IsLocalAddress(rtp.localAddrSrc, netAddr) {
|
||||
if network.IsLocalAddress(rtp.localAddrSrc, network.GroupFromAddress(netAddr)) {
|
||||
// if local => return no-op writer
|
||||
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ type Address struct {
|
|||
// LocalAddressSource is an interface of local
|
||||
// network address container with read access.
|
||||
type LocalAddressSource interface {
|
||||
LocalAddress() Address
|
||||
LocalAddress() AddressGroup
|
||||
}
|
||||
|
||||
// String returns multiaddr string.
|
||||
|
@ -107,8 +107,8 @@ func multiaddrStringFromHostAddr(host string) (string, error) {
|
|||
return strings.Join([]string{prefix, addr, l4Protocol, port}, "/"), nil
|
||||
}
|
||||
|
||||
// IsLocalAddress returns true if network endpoint from local address
|
||||
// source is equal to network endpoint of passed address.
|
||||
func IsLocalAddress(src LocalAddressSource, addr Address) bool {
|
||||
return src.LocalAddress().Equal(addr)
|
||||
// IsLocalAddress returns true if network endpoints from local address group
|
||||
// source intersects with network endpoints of passed address group.
|
||||
func IsLocalAddress(src LocalAddressSource, addr AddressGroup) bool {
|
||||
return src.LocalAddress().Intersects(addr)
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
|||
var relay func(network.Address) error
|
||||
if p.relay != nil {
|
||||
relay = func(addr network.Address) error {
|
||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
||||
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||
return errLocalAddress
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
|||
traverseOpts: prm.traverseOpts,
|
||||
workerPool: p.workerPool,
|
||||
nodeTargetInitializer: func(addr network.Address) transformer.ObjectTarget {
|
||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
||||
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||
return &localTarget{
|
||||
storage: p.localStore,
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func (p *localPlacement) BuildPlacement(addr *object.Address, policy *netmapSDK.
|
|||
continue
|
||||
}
|
||||
|
||||
if network.IsLocalAddress(p.localAddrSrc, addr) {
|
||||
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(addr)) {
|
||||
return []netmapSDK.Nodes{{vs[i][j]}}, nil
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ func (p *remotePlacement) BuildPlacement(addr *object.Address, policy *netmapSDK
|
|||
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:]...)
|
||||
j--
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes
|
|||
continue
|
||||
}
|
||||
|
||||
if network.IsLocalAddress(p.localAddrSrc, node) {
|
||||
if network.IsLocalAddress(p.localAddrSrc, network.GroupFromAddress(node)) {
|
||||
if shortage == 0 {
|
||||
// we can call the redundant copy callback
|
||||
// here to slightly improve the performance
|
||||
|
|
Loading…
Reference in New Issue