forked from TrueCloudLab/frostfs-node
Alex Vanin
20de74a505
Due to source code relocation from GitHub. Signed-off-by: Alex Vanin <a.vanin@yadro.com>
40 lines
905 B
Go
40 lines
905 B
Go
package router
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/common"
|
|
)
|
|
|
|
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, t reputation.Trust, route []common.ServerInfo) error {
|
|
for i := 1; i < len(route); i++ {
|
|
servers, err := builder.NextStage(epoch, t, 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
|
|
}
|