forked from TrueCloudLab/frostfs-node
[#460] reputation: Add Router
to reputation server
Add `Router` to the reputation server. `Router` is called on every incoming request and inits `Writer` that sends `Trust`s to the next route point or handle(logs in that implementation) them if current node is the end point of the route. Rename `onlyKeyRemoteServerInfo` struct for container to separate it from the same implementation of the same `ServerInfo` interface for reputation. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
39f55611c6
commit
60cc3b3e16
3 changed files with 123 additions and 17 deletions
39
pkg/services/reputation/local/route/util.go
Normal file
39
pkg/services/reputation/local/route/util.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package reputationroute
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
)
|
||||
|
||||
var errWrongRoute = errors.New("wrong route")
|
||||
|
||||
// CheckRoute checks if the route is a route correctly constructed by the builder for value a.
|
||||
//
|
||||
// Returns nil if route is correct, otherwise an error clarifying the inconsistency.
|
||||
func CheckRoute(builder Builder, epoch uint64, peer reputation.PeerID, route []ServerInfo) error {
|
||||
for i := 1; i < len(route); i++ {
|
||||
servers, err := builder.NextStage(epoch, peer, route[:i])
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(servers) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
found := false
|
||||
|
||||
for j := range servers {
|
||||
if bytes.Equal(servers[j].PublicKey(), route[i].PublicKey()) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return errWrongRoute
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue