forked from TrueCloudLab/frostfs-node
[#482] reputation/router: Make route pkg independent
Make route package independent from controller package. Add common interfaces to `./common` directory. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
0a16aaacb1
commit
ac8441b718
8 changed files with 87 additions and 75 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
|
@ -47,7 +48,7 @@ type reportContext struct {
|
|||
|
||||
log *logger.Logger
|
||||
|
||||
ctx Context
|
||||
ctx common.Context
|
||||
}
|
||||
|
||||
type iteratorContext struct {
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
)
|
||||
|
||||
// Prm groups the required parameters of the Controller's constructor.
|
||||
|
@ -22,7 +24,7 @@ type Prm struct {
|
|||
// trust to other nodes.
|
||||
//
|
||||
// Must not be nil.
|
||||
LocalTrustTarget WriterProvider
|
||||
LocalTrustTarget common.WriterProvider
|
||||
}
|
||||
|
||||
// Controller represents main handler for starting
|
||||
|
|
|
@ -1,59 +1,10 @@
|
|||
package trustcontroller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
)
|
||||
|
||||
// Context wraps stdlib context
|
||||
// with accompanying meta values.
|
||||
type Context interface {
|
||||
context.Context
|
||||
|
||||
// Must return epoch number to select the values.
|
||||
Epoch() uint64
|
||||
}
|
||||
|
||||
// Writer describes the interface for storing reputation.Trust values.
|
||||
//
|
||||
// This interface is provided by both local storage
|
||||
// of values and remote (wrappers over the RPC).
|
||||
type Writer interface {
|
||||
// Write performs a write operation of reputation.Trust value
|
||||
// and returns any error encountered.
|
||||
//
|
||||
// All values after the Close call must be flushed to the
|
||||
// physical target. Implementations can cache values before
|
||||
// Close operation.
|
||||
//
|
||||
// Write must not be called after Close.
|
||||
Write(reputation.Trust) error
|
||||
|
||||
// Close exits with method-providing Writer.
|
||||
//
|
||||
// All cached values must be flushed before
|
||||
// the Close's return.
|
||||
//
|
||||
// Methods must not be called after Close.
|
||||
io.Closer
|
||||
}
|
||||
|
||||
// WriterProvider is a group of methods provided
|
||||
// by entity which generates keepers of
|
||||
// reputation.Trust values.
|
||||
type WriterProvider interface {
|
||||
// InitWriter should return an initialized Writer.
|
||||
//
|
||||
// Initialization problems are reported via error.
|
||||
// If no error was returned, then the Writer must not be nil.
|
||||
//
|
||||
// Implementations can have different logic for different
|
||||
// contexts, so specific ones may document their own behavior.
|
||||
InitWriter(Context) (Writer, error)
|
||||
}
|
||||
|
||||
// Iterator is a group of methods provided by entity
|
||||
// which can iterate over a group of reputation.Trust values.
|
||||
type Iterator interface {
|
||||
|
@ -79,5 +30,5 @@ type IteratorProvider interface {
|
|||
//
|
||||
// Implementations can have different logic for different
|
||||
// contexts, so specific ones may document their own behavior.
|
||||
InitIterator(Context) (Iterator, error)
|
||||
InitIterator(common.Context) (Iterator, error)
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package trustcontroller
|
||||
|
||||
import "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
|
||||
type storageWrapper struct {
|
||||
w Writer
|
||||
w common.Writer
|
||||
i Iterator
|
||||
}
|
||||
|
||||
func (s storageWrapper) InitIterator(Context) (Iterator, error) {
|
||||
func (s storageWrapper) InitIterator(common.Context) (Iterator, error) {
|
||||
return s.i, nil
|
||||
}
|
||||
|
||||
func (s storageWrapper) InitWriter(Context) (Writer, error) {
|
||||
func (s storageWrapper) InitWriter(common.Context) (common.Writer, error) {
|
||||
return s.w, nil
|
||||
}
|
||||
|
||||
|
@ -23,7 +25,7 @@ func SimpleIteratorProvider(i Iterator) IteratorProvider {
|
|||
|
||||
// SimpleWriterProvider returns WriterProvider that provides
|
||||
// static context-independent Writer.
|
||||
func SimpleWriterProvider(w Writer) WriterProvider {
|
||||
func SimpleWriterProvider(w common.Writer) common.WriterProvider {
|
||||
return &storageWrapper{
|
||||
w: w,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue