forked from TrueCloudLab/frostfs-node
[#265] innerring: Add client cache
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
3d3d058b05
commit
22cffbf529
3 changed files with 36 additions and 0 deletions
|
@ -196,6 +196,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
AuditContract: server.contracts.audit,
|
||||
MorphClient: server.morphClient,
|
||||
IRList: server,
|
||||
ClientCache: newClientCache(server.key),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package audit
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
SDKClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
|
@ -16,6 +17,11 @@ type (
|
|||
InnerRingSize() int32
|
||||
}
|
||||
|
||||
// NeoFSClientCache is an interface for cache of neofs RPC clients
|
||||
NeoFSClientCache interface {
|
||||
Get(address string, opts ...SDKClient.Option) (*SDKClient.Client, error)
|
||||
}
|
||||
|
||||
// Processor of events related with data audit.
|
||||
Processor struct {
|
||||
log *zap.Logger
|
||||
|
@ -24,6 +30,7 @@ type (
|
|||
auditContract util.Uint160
|
||||
morphClient *client.Client
|
||||
irList Indexer
|
||||
clientCache NeoFSClientCache
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
|
@ -33,6 +40,7 @@ type (
|
|||
AuditContract util.Uint160
|
||||
MorphClient *client.Client
|
||||
IRList Indexer
|
||||
ClientCache NeoFSClientCache
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -50,6 +58,8 @@ func New(p *Params) (*Processor, error) {
|
|||
return nil, errors.New("ir/audit: neo:morph client is not set")
|
||||
case p.IRList == nil:
|
||||
return nil, errors.New("ir/audit: global state is not set")
|
||||
case p.ClientCache == nil:
|
||||
return nil, errors.New("ir/audit: neofs RPC client cache is not set")
|
||||
}
|
||||
|
||||
pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
|
||||
|
@ -64,6 +74,7 @@ func New(p *Params) (*Processor, error) {
|
|||
auditContract: p.AuditContract,
|
||||
morphClient: p.MorphClient,
|
||||
irList: p.IRList,
|
||||
clientCache: p.ClientCache,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
24
pkg/innerring/rpc.go
Normal file
24
pkg/innerring/rpc.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package innerring
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
||||
)
|
||||
|
||||
type ClientCache struct {
|
||||
cache *cache.ClientCache
|
||||
key *ecdsa.PrivateKey
|
||||
}
|
||||
|
||||
func newClientCache(key *ecdsa.PrivateKey) *ClientCache {
|
||||
return &ClientCache{
|
||||
cache: cache.NewSDKClientCache(),
|
||||
key: key,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ClientCache) Get(address string, opts ...client.Option) (*client.Client, error) {
|
||||
return c.cache.Get(c.key, address, opts...)
|
||||
}
|
Loading…
Reference in a new issue