forked from TrueCloudLab/frostfs-sdk-go
Alex Vanin
94476f9055
Due to source code relocation from GitHub. Signed-off-by: Alex Vanin <a.vanin@yadro.com>
58 lines
1 KiB
Go
58 lines
1 KiB
Go
package reputationtest
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/reputation"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
)
|
|
|
|
func PeerID() (v reputation.PeerID) {
|
|
p, err := keys.NewPrivateKey()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
v.SetPublicKey(p.PublicKey().Bytes())
|
|
|
|
return
|
|
}
|
|
|
|
func Trust() (v reputation.Trust) {
|
|
v.SetPeer(PeerID())
|
|
v.SetValue(0.5)
|
|
|
|
return
|
|
}
|
|
|
|
func PeerToPeerTrust() (v reputation.PeerToPeerTrust) {
|
|
v.SetTrustingPeer(PeerID())
|
|
v.SetTrust(Trust())
|
|
|
|
return
|
|
}
|
|
|
|
func GlobalTrust() (v reputation.GlobalTrust) {
|
|
v.Init()
|
|
v.SetManager(PeerID())
|
|
v.SetTrust(Trust())
|
|
|
|
return
|
|
}
|
|
|
|
func SignedGlobalTrust() reputation.GlobalTrust {
|
|
gt := GlobalTrust()
|
|
|
|
p, err := keys.NewPrivateKey()
|
|
if err != nil {
|
|
panic(fmt.Sprintf("unexpected error from key creator: %v", err))
|
|
}
|
|
|
|
err = gt.Sign(frostfsecdsa.Signer(p.PrivateKey))
|
|
if err != nil {
|
|
panic(fmt.Sprintf("unexpected error from GlobalTrust.Sign: %v", err))
|
|
}
|
|
|
|
return gt
|
|
}
|