forked from TrueCloudLab/frostfs-node
[#607] reputation,container: Support address groups in ServerInfo
There is a need to support multiple server endpoints for reputation and container transmission. Replace `ServerInfo.Address` getter with `ServerInfo.IterateAddresses` iterator. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
d6bb697726
commit
cede2b4ed7
6 changed files with 50 additions and 32 deletions
|
@ -216,21 +216,19 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc
|
|||
return r.deadEndProvider, nil
|
||||
}
|
||||
|
||||
addr := srv.Address()
|
||||
var netAddr network.AddressGroup
|
||||
|
||||
var netAddr network.Address
|
||||
|
||||
err := netAddr.FromString(addr)
|
||||
err := netAddr.FromIterator(srv)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
|
||||
}
|
||||
|
||||
if network.IsLocalAddress(r.loadAddrSrc, network.GroupFromAddress(netAddr)) {
|
||||
if network.IsLocalAddress(r.loadAddrSrc, netAddr) {
|
||||
// if local => return no-op writer
|
||||
return loadcontroller.SimpleWriterProvider(new(nopLoadWriter)), nil
|
||||
}
|
||||
|
||||
c, err := r.clientCache.Get(network.GroupFromAddress(netAddr))
|
||||
c, err := r.clientCache.Get(netAddr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
||||
}
|
||||
|
@ -369,16 +367,24 @@ func (c *cfg) PublicKey() []byte {
|
|||
return nodeKeyFromNetmap(c)
|
||||
}
|
||||
|
||||
func (c *cfg) Address() string {
|
||||
return nodeAddressFromNetmap(c)
|
||||
func (c *cfg) IterateAddresses(f func(string) bool) {
|
||||
c.iterateNetworkAddresses(f)
|
||||
}
|
||||
|
||||
func (c *cfg) NumberOfAddresses() int {
|
||||
return c.addressNum()
|
||||
}
|
||||
|
||||
func (c *usedSpaceService) PublicKey() []byte {
|
||||
return nodeKeyFromNetmap(c.cfg)
|
||||
}
|
||||
|
||||
func (c *usedSpaceService) Address() string {
|
||||
return nodeAddressFromNetmap(c.cfg)
|
||||
func (c *usedSpaceService) IterateAddresses(f func(string) bool) {
|
||||
c.cfg.iterateNetworkAddresses(f)
|
||||
}
|
||||
|
||||
func (c *usedSpaceService) NumberOfAddresses() int {
|
||||
return c.cfg.addressNum()
|
||||
}
|
||||
|
||||
func (c *usedSpaceService) AnnounceUsedSpace(ctx context.Context, req *containerV2.AnnounceUsedSpaceRequest) (*containerV2.AnnounceUsedSpaceResponse, error) {
|
||||
|
@ -425,8 +431,11 @@ func (i *containerOnlyKeyRemoteServerInfo) PublicKey() []byte {
|
|||
return i.key
|
||||
}
|
||||
|
||||
func (*containerOnlyKeyRemoteServerInfo) Address() string {
|
||||
return ""
|
||||
func (*containerOnlyKeyRemoteServerInfo) IterateAddresses(func(string) bool) {
|
||||
}
|
||||
|
||||
func (*containerOnlyKeyRemoteServerInfo) NumberOfAddresses() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (l *loadPlacementBuilder) isNodeFromContainerKey(epoch uint64, cid *cid.ID, key []byte) (bool, error) {
|
||||
|
|
|
@ -68,8 +68,12 @@ func nodeKeyFromNetmap(c *cfg) []byte {
|
|||
return c.cfgNetmap.state.getNodeInfo().PublicKey()
|
||||
}
|
||||
|
||||
func nodeAddressFromNetmap(c *cfg) string {
|
||||
return c.cfgNetmap.state.getNodeInfo().Address()
|
||||
func (c *cfg) iterateNetworkAddresses(f func(string) bool) {
|
||||
c.cfgNetmap.state.getNodeInfo().IterateAddresses(f)
|
||||
}
|
||||
|
||||
func (c *cfg) addressNum() int {
|
||||
return c.cfgNetmap.state.getNodeInfo().NumberOfAddresses()
|
||||
}
|
||||
|
||||
func initNetmapService(c *cfg) {
|
||||
|
|
|
@ -70,21 +70,19 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep
|
|||
return rtp.deadEndProvider, nil
|
||||
}
|
||||
|
||||
addr := srv.Address()
|
||||
var netAddr network.AddressGroup
|
||||
|
||||
var netAddr network.Address
|
||||
|
||||
err := netAddr.FromString(addr)
|
||||
err := netAddr.FromIterator(srv)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
|
||||
}
|
||||
|
||||
if network.IsLocalAddress(rtp.localAddrSrc, network.GroupFromAddress(netAddr)) {
|
||||
if network.IsLocalAddress(rtp.localAddrSrc, netAddr) {
|
||||
// if local => return no-op writer
|
||||
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
||||
}
|
||||
|
||||
c, err := rtp.clientCache.Get(network.GroupFromAddress(netAddr))
|
||||
c, err := rtp.clientCache.Get(netAddr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
||||
}
|
||||
|
|
|
@ -37,8 +37,11 @@ func (i *OnlyKeyRemoteServerInfo) PublicKey() []byte {
|
|||
return i.Key
|
||||
}
|
||||
|
||||
func (*OnlyKeyRemoteServerInfo) Address() string {
|
||||
return ""
|
||||
func (*OnlyKeyRemoteServerInfo) IterateAddresses(func(string) bool) {
|
||||
}
|
||||
|
||||
func (*OnlyKeyRemoteServerInfo) NumberOfAddresses() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
||||
|
|
|
@ -12,11 +12,13 @@ type ServerInfo interface {
|
|||
// from the route in a binary representation.
|
||||
PublicKey() []byte
|
||||
|
||||
// Returns network address of the node
|
||||
// in the route.
|
||||
//
|
||||
// Can be empty.
|
||||
Address() string
|
||||
// Iterates over network addresses of the node
|
||||
// in the route. Breaks iterating on true return
|
||||
// of the handler.
|
||||
IterateAddresses(func(string) bool)
|
||||
|
||||
// Returns number of server's network addresses.
|
||||
NumberOfAddresses() int
|
||||
}
|
||||
|
||||
// Builder groups methods to route values in the network.
|
||||
|
|
|
@ -69,9 +69,11 @@ type ServerInfo interface {
|
|||
// from the route in a binary representation.
|
||||
PublicKey() []byte
|
||||
|
||||
// Returns network address of the node
|
||||
// in the route.
|
||||
//
|
||||
// Can be empty.
|
||||
Address() string
|
||||
// Iterates over network addresses of the node
|
||||
// in the route. Breaks iterating on true return
|
||||
// of the handler.
|
||||
IterateAddresses(func(string) bool)
|
||||
|
||||
// Returns number of server's network addresses.
|
||||
NumberOfAddresses() int
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue