2021-11-08 08:41:39 +00:00
|
|
|
package reputationtest
|
|
|
|
|
|
|
|
import (
|
2022-06-30 16:08:34 +00:00
|
|
|
"fmt"
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
frostfsecdsa "github.com/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/reputation"
|
2021-12-10 13:56:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2021-11-08 08:41:39 +00:00
|
|
|
)
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func PeerID() (v reputation.PeerID) {
|
2021-12-10 13:56:04 +00:00
|
|
|
p, err := keys.NewPrivateKey()
|
2021-11-08 08:41:39 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
v.SetPublicKey(p.PublicKey().Bytes())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func Trust() (v reputation.Trust) {
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetPeer(PeerID())
|
2022-06-30 16:08:34 +00:00
|
|
|
v.SetValue(0.5)
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func PeerToPeerTrust() (v reputation.PeerToPeerTrust) {
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetTrustingPeer(PeerID())
|
|
|
|
v.SetTrust(Trust())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func GlobalTrust() (v reputation.GlobalTrust) {
|
|
|
|
v.Init()
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetManager(PeerID())
|
|
|
|
v.SetTrust(Trust())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func SignedGlobalTrust() reputation.GlobalTrust {
|
2021-11-12 11:19:16 +00:00
|
|
|
gt := GlobalTrust()
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2021-12-10 13:56:04 +00:00
|
|
|
p, err := keys.NewPrivateKey()
|
2022-06-30 16:08:34 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("unexpected error from key creator: %v", err))
|
|
|
|
}
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
err = gt.Sign(frostfsecdsa.Signer(p.PrivateKey))
|
2022-06-30 16:08:34 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("unexpected error from GlobalTrust.Sign: %v", err))
|
|
|
|
}
|
2021-11-08 08:41:39 +00:00
|
|
|
|
|
|
|
return gt
|
|
|
|
}
|