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
|
return r.deadEndProvider, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := srv.Address()
|
var netAddr network.AddressGroup
|
||||||
|
|
||||||
var netAddr network.Address
|
err := netAddr.FromIterator(srv)
|
||||||
|
|
||||||
err := netAddr.FromString(addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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, network.GroupFromAddress(netAddr)) {
|
if network.IsLocalAddress(r.loadAddrSrc, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := r.clientCache.Get(network.GroupFromAddress(netAddr))
|
c, err := r.clientCache.Get(netAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -369,16 +367,24 @@ func (c *cfg) PublicKey() []byte {
|
||||||
return nodeKeyFromNetmap(c)
|
return nodeKeyFromNetmap(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cfg) Address() string {
|
func (c *cfg) IterateAddresses(f func(string) bool) {
|
||||||
return nodeAddressFromNetmap(c)
|
c.iterateNetworkAddresses(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cfg) NumberOfAddresses() int {
|
||||||
|
return c.addressNum()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *usedSpaceService) PublicKey() []byte {
|
func (c *usedSpaceService) PublicKey() []byte {
|
||||||
return nodeKeyFromNetmap(c.cfg)
|
return nodeKeyFromNetmap(c.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *usedSpaceService) Address() string {
|
func (c *usedSpaceService) IterateAddresses(f func(string) bool) {
|
||||||
return nodeAddressFromNetmap(c.cfg)
|
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) {
|
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
|
return i.key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*containerOnlyKeyRemoteServerInfo) Address() string {
|
func (*containerOnlyKeyRemoteServerInfo) IterateAddresses(func(string) bool) {
|
||||||
return ""
|
}
|
||||||
|
|
||||||
|
func (*containerOnlyKeyRemoteServerInfo) NumberOfAddresses() int {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *loadPlacementBuilder) isNodeFromContainerKey(epoch uint64, cid *cid.ID, key []byte) (bool, error) {
|
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()
|
return c.cfgNetmap.state.getNodeInfo().PublicKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
func nodeAddressFromNetmap(c *cfg) string {
|
func (c *cfg) iterateNetworkAddresses(f func(string) bool) {
|
||||||
return c.cfgNetmap.state.getNodeInfo().Address()
|
c.cfgNetmap.state.getNodeInfo().IterateAddresses(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cfg) addressNum() int {
|
||||||
|
return c.cfgNetmap.state.getNodeInfo().NumberOfAddresses()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initNetmapService(c *cfg) {
|
func initNetmapService(c *cfg) {
|
||||||
|
|
|
@ -70,21 +70,19 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep
|
||||||
return rtp.deadEndProvider, nil
|
return rtp.deadEndProvider, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := srv.Address()
|
var netAddr network.AddressGroup
|
||||||
|
|
||||||
var netAddr network.Address
|
err := netAddr.FromIterator(srv)
|
||||||
|
|
||||||
err := netAddr.FromString(addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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, network.GroupFromAddress(netAddr)) {
|
if network.IsLocalAddress(rtp.localAddrSrc, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := rtp.clientCache.Get(network.GroupFromAddress(netAddr))
|
c, err := rtp.clientCache.Get(netAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,11 @@ func (i *OnlyKeyRemoteServerInfo) PublicKey() []byte {
|
||||||
return i.Key
|
return i.Key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*OnlyKeyRemoteServerInfo) Address() string {
|
func (*OnlyKeyRemoteServerInfo) IterateAddresses(func(string) bool) {
|
||||||
return ""
|
}
|
||||||
|
|
||||||
|
func (*OnlyKeyRemoteServerInfo) NumberOfAddresses() int {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
||||||
|
|
|
@ -12,11 +12,13 @@ type ServerInfo interface {
|
||||||
// from the route in a binary representation.
|
// from the route in a binary representation.
|
||||||
PublicKey() []byte
|
PublicKey() []byte
|
||||||
|
|
||||||
// Returns network address of the node
|
// Iterates over network addresses of the node
|
||||||
// in the route.
|
// in the route. Breaks iterating on true return
|
||||||
//
|
// of the handler.
|
||||||
// Can be empty.
|
IterateAddresses(func(string) bool)
|
||||||
Address() string
|
|
||||||
|
// Returns number of server's network addresses.
|
||||||
|
NumberOfAddresses() int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builder groups methods to route values in the network.
|
// Builder groups methods to route values in the network.
|
||||||
|
|
|
@ -69,9 +69,11 @@ type ServerInfo interface {
|
||||||
// from the route in a binary representation.
|
// from the route in a binary representation.
|
||||||
PublicKey() []byte
|
PublicKey() []byte
|
||||||
|
|
||||||
// Returns network address of the node
|
// Iterates over network addresses of the node
|
||||||
// in the route.
|
// in the route. Breaks iterating on true return
|
||||||
//
|
// of the handler.
|
||||||
// Can be empty.
|
IterateAddresses(func(string) bool)
|
||||||
Address() string
|
|
||||||
|
// Returns number of server's network addresses.
|
||||||
|
NumberOfAddresses() int
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue