1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Remove commonspace checks

This commit is contained in:
mcrakhman 2023-04-25 10:38:22 +02:00 committed by Mikhail Iudin
parent 92ed77ab5a
commit 2ec5960b2b
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0

View file

@ -1,44 +0,0 @@
package commonspace
import (
"context"
"github.com/anytypeio/any-sync/commonspace/spacesyncproto"
"github.com/anytypeio/any-sync/net/peer"
"github.com/anytypeio/any-sync/nodeconf"
"github.com/anytypeio/any-sync/util/crypto"
"golang.org/x/exp/slices"
)
func CheckResponsible(ctx context.Context, confService nodeconf.Service, spaceId string) (err error) {
peerId, err := peer.CtxPeerId(ctx)
if err != nil {
return
}
if isClient(confService, peerId) && !confService.IsResponsible(spaceId) {
return spacesyncproto.ErrPeerIsNotResponsible
}
return
}
func isClient(confService nodeconf.Service, peerId string) bool {
return len(confService.NodeTypes(peerId)) == 0
}
func checkCoordinator(confService nodeconf.Service, identity []byte, payload, signature []byte) (err error) {
controlKey, err := crypto.UnmarshalEd25519PublicKey(identity)
if err != nil {
return
}
nodeTypes := confService.NodeTypes(controlKey.PeerId())
if len(nodeTypes) == 0 || !slices.Contains(nodeTypes, nodeconf.NodeTypeCoordinator) {
return errNoSuchCoordinatorNode
}
res, err := controlKey.Verify(payload, signature)
if err != nil {
return
}
if !res {
return errReceiptSignatureIncorrect
}
return
}