Change to consensus proto
This commit is contained in:
parent
e094743fbc
commit
822e7f374d
@ -1,5 +1,5 @@
|
|||||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||||
// protoc-gen-go-drpc version: v0.0.32
|
// protoc-gen-go-drpc version: v0.0.33
|
||||||
// source: commonfile/fileproto/protos/file.proto
|
// source: commonfile/fileproto/protos/file.proto
|
||||||
|
|
||||||
package fileproto
|
package fileproto
|
||||||
|
|||||||
@ -4,18 +4,19 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/app/ldiff"
|
"github.com/anyproto/any-sync/app/ldiff"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage/mock_liststorage"
|
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage/mock_liststorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage/mock_treestorage"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage/mock_treestorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/net/peer"
|
"github.com/anyproto/any-sync/net/peer"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"storj.io/drpc"
|
"storj.io/drpc"
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type pushSpaceRequestMatcher struct {
|
type pushSpaceRequestMatcher struct {
|
||||||
@ -169,7 +170,7 @@ func TestDiffSyncer(t *testing.T) {
|
|||||||
settingsStorage := mock_treestorage.NewMockTreeStorage(fx.ctrl)
|
settingsStorage := mock_treestorage.NewMockTreeStorage(fx.ctrl)
|
||||||
settingsId := "settingsId"
|
settingsId := "settingsId"
|
||||||
aclRootId := "aclRootId"
|
aclRootId := "aclRootId"
|
||||||
aclRoot := &aclrecordproto.RawAclRecordWithId{
|
aclRoot := &consensusproto.RawRecordWithId{
|
||||||
Id: aclRootId,
|
Id: aclRootId,
|
||||||
}
|
}
|
||||||
settingsRoot := &treechangeproto.RawTreeChangeWithId{
|
settingsRoot := &treechangeproto.RawTreeChangeWithId{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -2,28 +2,6 @@ syntax = "proto3";
|
|||||||
package aclrecord;
|
package aclrecord;
|
||||||
option go_package = "commonspace/object/acl/aclrecordproto";
|
option go_package = "commonspace/object/acl/aclrecordproto";
|
||||||
|
|
||||||
// RawAclRecord is a proto message containing the acl payload in bytes, signature of the account who added it and signature of the acceptor
|
|
||||||
message RawAclRecord {
|
|
||||||
bytes payload = 1;
|
|
||||||
bytes signature = 2;
|
|
||||||
bytes acceptorIdentity = 3;
|
|
||||||
bytes acceptorSignature = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// RawAclRecordWithId is a raw record and the id for convenience
|
|
||||||
message RawAclRecordWithId {
|
|
||||||
bytes payload = 1;
|
|
||||||
string id = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// AclRecord is a record containing the acl data
|
|
||||||
message AclRecord {
|
|
||||||
string prevId = 1;
|
|
||||||
bytes identity = 2;
|
|
||||||
bytes data = 3;
|
|
||||||
int64 timestamp = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// AclRoot is a root of access control list
|
// AclRoot is a root of access control list
|
||||||
message AclRoot {
|
message AclRoot {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
@ -126,18 +104,3 @@ enum AclUserPermissions {
|
|||||||
Writer = 3;
|
Writer = 3;
|
||||||
Reader = 4;
|
Reader = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AclSyncMessage {
|
|
||||||
AclSyncContentValue content = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// AclSyncContentValue provides different types for acl sync
|
|
||||||
message AclSyncContentValue {
|
|
||||||
oneof value {
|
|
||||||
AclAddRecords addRecords = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
message AclAddRecords {
|
|
||||||
repeated RawAclRecordWithId records = 1;
|
|
||||||
}
|
|
||||||
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/util/cidutil"
|
"github.com/anyproto/any-sync/util/cidutil"
|
||||||
"github.com/anyproto/any-sync/util/crypto"
|
"github.com/anyproto/any-sync/util/crypto"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
@ -39,24 +40,24 @@ type AccountRemovePayload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InviteResult struct {
|
type InviteResult struct {
|
||||||
InviteRec *aclrecordproto.RawAclRecord
|
InviteRec *consensusproto.RawRecord
|
||||||
InviteKey crypto.PrivKey
|
InviteKey crypto.PrivKey
|
||||||
}
|
}
|
||||||
|
|
||||||
type AclRecordBuilder interface {
|
type AclRecordBuilder interface {
|
||||||
UnmarshallWithId(rawIdRecord *aclrecordproto.RawAclRecordWithId) (rec *AclRecord, err error)
|
UnmarshallWithId(rawIdRecord *consensusproto.RawRecordWithId) (rec *AclRecord, err error)
|
||||||
Unmarshall(rawRecord *aclrecordproto.RawAclRecord) (rec *AclRecord, err error)
|
Unmarshall(rawRecord *consensusproto.RawRecord) (rec *AclRecord, err error)
|
||||||
|
|
||||||
BuildRoot(content RootContent) (rec *aclrecordproto.RawAclRecordWithId, err error)
|
BuildRoot(content RootContent) (rec *consensusproto.RawRecordWithId, err error)
|
||||||
BuildInvite() (res InviteResult, err error)
|
BuildInvite() (res InviteResult, err error)
|
||||||
BuildInviteRevoke(inviteRecordId string) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildInviteRevoke(inviteRecordId string) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildRequestJoin(payload RequestJoinPayload) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildRequestJoin(payload RequestJoinPayload) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildRequestAccept(payload RequestAcceptPayload) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildRequestAccept(payload RequestAcceptPayload) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildRequestDecline(requestRecordId string) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildRequestDecline(requestRecordId string) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildRequestRemove() (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildRequestRemove() (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildPermissionChange(payload PermissionChangePayload) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildPermissionChange(payload PermissionChangePayload) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildReadKeyChange(newKey crypto.SymKey) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildReadKeyChange(newKey crypto.SymKey) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
BuildAccountRemove(payload AccountRemovePayload) (rawRecord *aclrecordproto.RawAclRecord, err error)
|
BuildAccountRemove(payload AccountRemovePayload) (rawRecord *consensusproto.RawRecord, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type aclRecordBuilder struct {
|
type aclRecordBuilder struct {
|
||||||
@ -76,7 +77,7 @@ func NewAclRecordBuilder(id string, keyStorage crypto.KeyStorage, keys *accountd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) buildRecord(aclContent *aclrecordproto.AclContentValue) (rawRec *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) buildRecord(aclContent *aclrecordproto.AclContentValue) (rawRec *consensusproto.RawRecord, err error) {
|
||||||
aclData := &aclrecordproto.AclData{AclContent: []*aclrecordproto.AclContentValue{
|
aclData := &aclrecordproto.AclData{AclContent: []*aclrecordproto.AclContentValue{
|
||||||
aclContent,
|
aclContent,
|
||||||
}}
|
}}
|
||||||
@ -88,7 +89,7 @@ func (a *aclRecordBuilder) buildRecord(aclContent *aclrecordproto.AclContentValu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rec := &aclrecordproto.AclRecord{
|
rec := &consensusproto.Record{
|
||||||
PrevId: a.state.lastRecordId,
|
PrevId: a.state.lastRecordId,
|
||||||
Identity: protoKey,
|
Identity: protoKey,
|
||||||
Data: marshalledData,
|
Data: marshalledData,
|
||||||
@ -102,7 +103,7 @@ func (a *aclRecordBuilder) buildRecord(aclContent *aclrecordproto.AclContentValu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawRec = &aclrecordproto.RawAclRecord{
|
rawRec = &consensusproto.RawRecord{
|
||||||
Payload: marshalledRec,
|
Payload: marshalledRec,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ func (a *aclRecordBuilder) BuildInvite() (res InviteResult, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildInviteRevoke(inviteRecordId string) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildInviteRevoke(inviteRecordId string) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
||||||
err = ErrInsufficientPermissions
|
err = ErrInsufficientPermissions
|
||||||
return
|
return
|
||||||
@ -148,7 +149,7 @@ func (a *aclRecordBuilder) BuildInviteRevoke(inviteRecordId string) (rawRecord *
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildRequestJoin(payload RequestJoinPayload) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildRequestJoin(payload RequestJoinPayload) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
key, exists := a.state.inviteKeys[payload.InviteRecordId]
|
key, exists := a.state.inviteKeys[payload.InviteRecordId]
|
||||||
if !exists {
|
if !exists {
|
||||||
err = ErrNoSuchInvite
|
err = ErrNoSuchInvite
|
||||||
@ -179,7 +180,7 @@ func (a *aclRecordBuilder) BuildRequestJoin(payload RequestJoinPayload) (rawReco
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildRequestAccept(payload RequestAcceptPayload) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildRequestAccept(payload RequestAcceptPayload) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
||||||
err = ErrInsufficientPermissions
|
err = ErrInsufficientPermissions
|
||||||
return
|
return
|
||||||
@ -221,7 +222,7 @@ func (a *aclRecordBuilder) BuildRequestAccept(payload RequestAcceptPayload) (raw
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildRequestDecline(requestRecordId string) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildRequestDecline(requestRecordId string) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
||||||
err = ErrInsufficientPermissions
|
err = ErrInsufficientPermissions
|
||||||
return
|
return
|
||||||
@ -236,7 +237,7 @@ func (a *aclRecordBuilder) BuildRequestDecline(requestRecordId string) (rawRecor
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildPermissionChange(payload PermissionChangePayload) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildPermissionChange(payload PermissionChangePayload) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
permissions := a.state.Permissions(a.state.pubKey)
|
permissions := a.state.Permissions(a.state.pubKey)
|
||||||
if !permissions.CanManageAccounts() || payload.Identity.Equals(a.state.pubKey) {
|
if !permissions.CanManageAccounts() || payload.Identity.Equals(a.state.pubKey) {
|
||||||
err = ErrInsufficientPermissions
|
err = ErrInsufficientPermissions
|
||||||
@ -258,7 +259,7 @@ func (a *aclRecordBuilder) BuildPermissionChange(payload PermissionChangePayload
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildReadKeyChange(newKey crypto.SymKey) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildReadKeyChange(newKey crypto.SymKey) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
if !a.state.Permissions(a.state.pubKey).CanManageAccounts() {
|
||||||
err = ErrInsufficientPermissions
|
err = ErrInsufficientPermissions
|
||||||
return
|
return
|
||||||
@ -291,7 +292,7 @@ func (a *aclRecordBuilder) BuildReadKeyChange(newKey crypto.SymKey) (rawRecord *
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildAccountRemove(payload AccountRemovePayload) (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildAccountRemove(payload AccountRemovePayload) (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
deletedMap := map[string]struct{}{}
|
deletedMap := map[string]struct{}{}
|
||||||
for _, key := range payload.Identities {
|
for _, key := range payload.Identities {
|
||||||
permissions := a.state.Permissions(key)
|
permissions := a.state.Permissions(key)
|
||||||
@ -346,7 +347,7 @@ func (a *aclRecordBuilder) BuildAccountRemove(payload AccountRemovePayload) (raw
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildRequestRemove() (rawRecord *aclrecordproto.RawAclRecord, err error) {
|
func (a *aclRecordBuilder) BuildRequestRemove() (rawRecord *consensusproto.RawRecord, err error) {
|
||||||
permissions := a.state.Permissions(a.state.pubKey)
|
permissions := a.state.Permissions(a.state.pubKey)
|
||||||
if permissions.NoPermissions() {
|
if permissions.NoPermissions() {
|
||||||
err = ErrNoSuchAccount
|
err = ErrNoSuchAccount
|
||||||
@ -361,8 +362,8 @@ func (a *aclRecordBuilder) BuildRequestRemove() (rawRecord *aclrecordproto.RawAc
|
|||||||
return a.buildRecord(content)
|
return a.buildRecord(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) Unmarshall(rawRecord *aclrecordproto.RawAclRecord) (rec *AclRecord, err error) {
|
func (a *aclRecordBuilder) Unmarshall(rawRecord *consensusproto.RawRecord) (rec *AclRecord, err error) {
|
||||||
aclRecord := &aclrecordproto.AclRecord{}
|
aclRecord := &consensusproto.Record{}
|
||||||
err = proto.Unmarshal(rawRecord.Payload, aclRecord)
|
err = proto.Unmarshal(rawRecord.Payload, aclRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -395,9 +396,9 @@ func (a *aclRecordBuilder) Unmarshall(rawRecord *aclrecordproto.RawAclRecord) (r
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) UnmarshallWithId(rawIdRecord *aclrecordproto.RawAclRecordWithId) (rec *AclRecord, err error) {
|
func (a *aclRecordBuilder) UnmarshallWithId(rawIdRecord *consensusproto.RawRecordWithId) (rec *AclRecord, err error) {
|
||||||
var (
|
var (
|
||||||
rawRec = &aclrecordproto.RawAclRecord{}
|
rawRec = &consensusproto.RawRecord{}
|
||||||
pubKey crypto.PubKey
|
pubKey crypto.PubKey
|
||||||
)
|
)
|
||||||
err = proto.Unmarshal(rawIdRecord.Payload, rawRec)
|
err = proto.Unmarshal(rawIdRecord.Payload, rawRec)
|
||||||
@ -426,7 +427,7 @@ func (a *aclRecordBuilder) UnmarshallWithId(rawIdRecord *aclrecordproto.RawAclRe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
aclRecord := &aclrecordproto.AclRecord{}
|
aclRecord := &consensusproto.Record{}
|
||||||
err = proto.Unmarshal(rawRec.Payload, aclRecord)
|
err = proto.Unmarshal(rawRec.Payload, aclRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -455,7 +456,7 @@ func (a *aclRecordBuilder) UnmarshallWithId(rawIdRecord *aclrecordproto.RawAclRe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildRoot(content RootContent) (rec *aclrecordproto.RawAclRecordWithId, err error) {
|
func (a *aclRecordBuilder) BuildRoot(content RootContent) (rec *consensusproto.RawRecordWithId, err error) {
|
||||||
rawIdentity, err := content.PrivKey.GetPublic().Raw()
|
rawIdentity, err := content.PrivKey.GetPublic().Raw()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -489,8 +490,8 @@ func (a *aclRecordBuilder) BuildRoot(content RootContent) (rec *aclrecordproto.R
|
|||||||
|
|
||||||
func verifyRaw(
|
func verifyRaw(
|
||||||
pubKey crypto.PubKey,
|
pubKey crypto.PubKey,
|
||||||
rawRec *aclrecordproto.RawAclRecord,
|
rawRec *consensusproto.RawRecord,
|
||||||
recWithId *aclrecordproto.RawAclRecordWithId) (err error) {
|
recWithId *consensusproto.RawRecordWithId) (err error) {
|
||||||
// verifying signature
|
// verifying signature
|
||||||
res, err := pubKey.Verify(rawRec.Payload, rawRec.Signature)
|
res, err := pubKey.Verify(rawRec.Payload, rawRec.Signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -508,7 +509,7 @@ func verifyRaw(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalAclRoot(aclRoot *aclrecordproto.AclRoot, key crypto.PrivKey) (rawWithId *aclrecordproto.RawAclRecordWithId, err error) {
|
func marshalAclRoot(aclRoot *aclrecordproto.AclRoot, key crypto.PrivKey) (rawWithId *consensusproto.RawRecordWithId, err error) {
|
||||||
marshalledRoot, err := aclRoot.Marshal()
|
marshalledRoot, err := aclRoot.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -517,7 +518,7 @@ func marshalAclRoot(aclRoot *aclrecordproto.AclRoot, key crypto.PrivKey) (rawWit
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
raw := &aclrecordproto.RawAclRecord{
|
raw := &consensusproto.RawRecord{
|
||||||
Payload: marshalledRoot,
|
Payload: marshalledRoot,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
@ -529,7 +530,7 @@ func marshalAclRoot(aclRoot *aclrecordproto.AclRoot, key crypto.PrivKey) (rawWit
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawWithId = &aclrecordproto.RawAclRecordWithId{
|
rawWithId = &consensusproto.RawRecordWithId{
|
||||||
Payload: marshalledRaw,
|
Payload: marshalledRaw,
|
||||||
Id: aclHeadId,
|
Id: aclHeadId,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/util/crypto"
|
"github.com/anyproto/any-sync/util/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,20 +27,20 @@ type RWLocker interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AcceptorVerifier interface {
|
type AcceptorVerifier interface {
|
||||||
VerifyAcceptor(rec *aclrecordproto.RawAclRecord) (err error)
|
VerifyAcceptor(rec *consensusproto.RawRecord) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NoOpAcceptorVerifier struct {
|
type NoOpAcceptorVerifier struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NoOpAcceptorVerifier) VerifyAcceptor(rec *aclrecordproto.RawAclRecord) (err error) {
|
func (n NoOpAcceptorVerifier) VerifyAcceptor(rec *consensusproto.RawRecord) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type AclList interface {
|
type AclList interface {
|
||||||
RWLocker
|
RWLocker
|
||||||
Id() string
|
Id() string
|
||||||
Root() *aclrecordproto.RawAclRecordWithId
|
Root() *consensusproto.RawRecordWithId
|
||||||
Records() []*AclRecord
|
Records() []*AclRecord
|
||||||
AclState() *AclState
|
AclState() *AclState
|
||||||
IsAfter(first string, second string) (bool, error)
|
IsAfter(first string, second string) (bool, error)
|
||||||
@ -53,14 +53,14 @@ type AclList interface {
|
|||||||
KeyStorage() crypto.KeyStorage
|
KeyStorage() crypto.KeyStorage
|
||||||
RecordBuilder() AclRecordBuilder
|
RecordBuilder() AclRecordBuilder
|
||||||
|
|
||||||
ValidateRawRecord(record *aclrecordproto.RawAclRecord) (err error)
|
ValidateRawRecord(record *consensusproto.RawRecord) (err error)
|
||||||
AddRawRecord(rawRec *aclrecordproto.RawAclRecordWithId) (err error)
|
AddRawRecord(rawRec *consensusproto.RawRecordWithId) (err error)
|
||||||
|
|
||||||
Close() (err error)
|
Close() (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type aclList struct {
|
type aclList struct {
|
||||||
root *aclrecordproto.RawAclRecordWithId
|
root *consensusproto.RawRecordWithId
|
||||||
records []*AclRecord
|
records []*AclRecord
|
||||||
indexes map[string]int
|
indexes map[string]int
|
||||||
id string
|
id string
|
||||||
@ -187,7 +187,7 @@ func (a *aclList) Records() []*AclRecord {
|
|||||||
return a.records
|
return a.records
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) ValidateRawRecord(rawRec *aclrecordproto.RawAclRecord) (err error) {
|
func (a *aclList) ValidateRawRecord(rawRec *consensusproto.RawRecord) (err error) {
|
||||||
record, err := a.recordBuilder.Unmarshall(rawRec)
|
record, err := a.recordBuilder.Unmarshall(rawRec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -195,7 +195,7 @@ func (a *aclList) ValidateRawRecord(rawRec *aclrecordproto.RawAclRecord) (err er
|
|||||||
return a.aclState.Validator().ValidateAclRecordContents(record)
|
return a.aclState.Validator().ValidateAclRecordContents(record)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) AddRawRecord(rawRec *aclrecordproto.RawAclRecordWithId) (err error) {
|
func (a *aclList) AddRawRecord(rawRec *consensusproto.RawRecordWithId) (err error) {
|
||||||
if _, ok := a.indexes[rawRec.Id]; ok {
|
if _, ok := a.indexes[rawRec.Id]; ok {
|
||||||
return ErrRecordAlreadyExists
|
return ErrRecordAlreadyExists
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ func (a *aclList) Id() string {
|
|||||||
return a.id
|
return a.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) Root() *aclrecordproto.RawAclRecordWithId {
|
func (a *aclList) Root() *consensusproto.RawRecordWithId {
|
||||||
return a.root
|
return a.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,13 @@ import (
|
|||||||
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/util/cidutil"
|
"github.com/anyproto/any-sync/util/cidutil"
|
||||||
"github.com/anyproto/any-sync/util/crypto"
|
"github.com/anyproto/any-sync/util/crypto"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func wrapRecord(rawRec *aclrecordproto.RawAclRecord) *aclrecordproto.RawAclRecordWithId {
|
func wrapRecord(rawRec *consensusproto.RawRecord) *consensusproto.RawRecordWithId {
|
||||||
payload, err := rawRec.Marshal()
|
payload, err := rawRec.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -20,7 +21,7 @@ func wrapRecord(rawRec *aclrecordproto.RawAclRecord) *aclrecordproto.RawAclRecor
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return &aclrecordproto.RawAclRecordWithId{
|
return &consensusproto.RawRecordWithId{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
Id: id,
|
Id: id,
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ func newFixture(t *testing.T) *aclFixture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *aclFixture) addRec(t *testing.T, rec *aclrecordproto.RawAclRecordWithId) {
|
func (fx *aclFixture) addRec(t *testing.T, rec *consensusproto.RawRecordWithId) {
|
||||||
err := fx.ownerAcl.AddRawRecord(rec)
|
err := fx.ownerAcl.AddRawRecord(rec)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = fx.accountAcl.AddRawRecord(rec)
|
err = fx.accountAcl.AddRawRecord(rec)
|
||||||
|
|||||||
@ -2,8 +2,8 @@ package list
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/util/crypto"
|
"github.com/anyproto/any-sync/util/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ func NewTestDerivedAcl(spaceId string, keys *accountdata.AccountKeys) (AclList,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
st, err := liststorage.NewInMemoryAclListStorage(root.Id, []*aclrecordproto.RawAclRecordWithId{
|
st, err := liststorage.NewInMemoryAclListStorage(root.Id, []*consensusproto.RawRecordWithId{
|
||||||
root,
|
root,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -30,8 +30,8 @@ func NewTestDerivedAcl(spaceId string, keys *accountdata.AccountKeys) (AclList,
|
|||||||
return BuildAclListWithIdentity(keys, st, NoOpAcceptorVerifier{})
|
return BuildAclListWithIdentity(keys, st, NoOpAcceptorVerifier{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestAclWithRoot(keys *accountdata.AccountKeys, root *aclrecordproto.RawAclRecordWithId) (AclList, error) {
|
func NewTestAclWithRoot(keys *accountdata.AccountKeys, root *consensusproto.RawRecordWithId) (AclList, error) {
|
||||||
st, err := liststorage.NewInMemoryAclListStorage(root.Id, []*aclrecordproto.RawAclRecordWithId{
|
st, err := liststorage.NewInMemoryAclListStorage(root.Id, []*consensusproto.RawRecordWithId{
|
||||||
root,
|
root,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -7,8 +7,8 @@ package mock_list
|
|||||||
import (
|
import (
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
aclrecordproto "github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
list "github.com/anyproto/any-sync/commonspace/object/acl/list"
|
list "github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||||
|
consensusproto "github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
crypto "github.com/anyproto/any-sync/util/crypto"
|
crypto "github.com/anyproto/any-sync/util/crypto"
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
@ -51,7 +51,7 @@ func (mr *MockAclListMockRecorder) AclState() *gomock.Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRawRecord mocks base method.
|
// AddRawRecord mocks base method.
|
||||||
func (m *MockAclList) AddRawRecord(arg0 *aclrecordproto.RawAclRecordWithId) error {
|
func (m *MockAclList) AddRawRecord(arg0 *consensusproto.RawRecordWithId) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "AddRawRecord", arg0)
|
ret := m.ctrl.Call(m, "AddRawRecord", arg0)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
@ -254,10 +254,10 @@ func (mr *MockAclListMockRecorder) Records() *gomock.Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Root mocks base method.
|
// Root mocks base method.
|
||||||
func (m *MockAclList) Root() *aclrecordproto.RawAclRecordWithId {
|
func (m *MockAclList) Root() *consensusproto.RawRecordWithId {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Root")
|
ret := m.ctrl.Call(m, "Root")
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
ret0, _ := ret[0].(*consensusproto.RawRecordWithId)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ func (mr *MockAclListMockRecorder) Unlock() *gomock.Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ValidateRawRecord mocks base method.
|
// ValidateRawRecord mocks base method.
|
||||||
func (m *MockAclList) ValidateRawRecord(arg0 *aclrecordproto.RawAclRecord) error {
|
func (m *MockAclList) ValidateRawRecord(arg0 *consensusproto.RawRecord) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "ValidateRawRecord", arg0)
|
ret := m.ctrl.Call(m, "ValidateRawRecord", arg0)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
|
|||||||
@ -3,24 +3,26 @@ package liststorage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type inMemoryAclListStorage struct {
|
type inMemoryAclListStorage struct {
|
||||||
id string
|
id string
|
||||||
root *aclrecordproto.RawAclRecordWithId
|
root *consensusproto.RawRecordWithId
|
||||||
head string
|
head string
|
||||||
records map[string]*aclrecordproto.RawAclRecordWithId
|
records map[string]*consensusproto.RawRecordWithId
|
||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInMemoryAclListStorage(
|
func NewInMemoryAclListStorage(
|
||||||
id string,
|
id string,
|
||||||
records []*aclrecordproto.RawAclRecordWithId) (ListStorage, error) {
|
records []*consensusproto.RawRecordWithId) (ListStorage, error) {
|
||||||
|
|
||||||
allRecords := make(map[string]*aclrecordproto.RawAclRecordWithId)
|
allRecords := make(map[string]*consensusproto.RawRecordWithId)
|
||||||
for _, ch := range records {
|
for _, ch := range records {
|
||||||
allRecords[ch.Id] = ch
|
allRecords[ch.Id] = ch
|
||||||
}
|
}
|
||||||
@ -41,7 +43,7 @@ func (t *inMemoryAclListStorage) Id() string {
|
|||||||
return t.id
|
return t.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryAclListStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
func (t *inMemoryAclListStorage) Root() (*consensusproto.RawRecordWithId, error) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
return t.root, nil
|
return t.root, nil
|
||||||
@ -60,7 +62,7 @@ func (t *inMemoryAclListStorage) SetHead(head string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryAclListStorage) AddRawRecord(ctx context.Context, record *aclrecordproto.RawAclRecordWithId) error {
|
func (t *inMemoryAclListStorage) AddRawRecord(ctx context.Context, record *consensusproto.RawRecordWithId) error {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
// TODO: better to do deep copy
|
// TODO: better to do deep copy
|
||||||
@ -68,7 +70,7 @@ func (t *inMemoryAclListStorage) AddRawRecord(ctx context.Context, record *aclre
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryAclListStorage) GetRawRecord(ctx context.Context, recordId string) (*aclrecordproto.RawAclRecordWithId, error) {
|
func (t *inMemoryAclListStorage) GetRawRecord(ctx context.Context, recordId string) (*consensusproto.RawRecordWithId, error) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
if res, exists := t.records[recordId]; exists {
|
if res, exists := t.records[recordId]; exists {
|
||||||
|
|||||||
@ -4,7 +4,8 @@ package liststorage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -14,15 +15,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Exporter interface {
|
type Exporter interface {
|
||||||
ListStorage(root *aclrecordproto.RawAclRecordWithId) (ListStorage, error)
|
ListStorage(root *consensusproto.RawRecordWithId) (ListStorage, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListStorage interface {
|
type ListStorage interface {
|
||||||
Id() string
|
Id() string
|
||||||
Root() (*aclrecordproto.RawAclRecordWithId, error)
|
Root() (*consensusproto.RawRecordWithId, error)
|
||||||
Head() (string, error)
|
Head() (string, error)
|
||||||
SetHead(headId string) error
|
SetHead(headId string) error
|
||||||
|
|
||||||
GetRawRecord(ctx context.Context, id string) (*aclrecordproto.RawAclRecordWithId, error)
|
GetRawRecord(ctx context.Context, id string) (*consensusproto.RawRecordWithId, error)
|
||||||
AddRawRecord(ctx context.Context, rec *aclrecordproto.RawAclRecordWithId) error
|
AddRawRecord(ctx context.Context, rec *consensusproto.RawRecordWithId) error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
context "context"
|
context "context"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
aclrecordproto "github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
consensusproto "github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func (m *MockListStorage) EXPECT() *MockListStorageMockRecorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRawRecord mocks base method.
|
// AddRawRecord mocks base method.
|
||||||
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *aclrecordproto.RawAclRecordWithId) error {
|
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *consensusproto.RawRecordWithId) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
@ -50,10 +50,10 @@ func (mr *MockListStorageMockRecorder) AddRawRecord(arg0, arg1 interface{}) *gom
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRawRecord mocks base method.
|
// GetRawRecord mocks base method.
|
||||||
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*aclrecordproto.RawAclRecordWithId, error) {
|
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*consensusproto.RawRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
ret0, _ := ret[0].(*consensusproto.RawRecordWithId)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
@ -94,10 +94,10 @@ func (mr *MockListStorageMockRecorder) Id() *gomock.Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Root mocks base method.
|
// Root mocks base method.
|
||||||
func (m *MockListStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
func (m *MockListStorage) Root() (*consensusproto.RawRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Root")
|
ret := m.ctrl.Call(m, "Root")
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
ret0, _ := ret[0].(*consensusproto.RawRecordWithId)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,8 +2,7 @@ package syncacl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
)
|
)
|
||||||
@ -13,19 +12,5 @@ type syncAclHandler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncAclHandler) HandleMessage(ctx context.Context, senderId string, req *spacesyncproto.ObjectSyncMessage) (err error) {
|
func (s *syncAclHandler) HandleMessage(ctx context.Context, senderId string, req *spacesyncproto.ObjectSyncMessage) (err error) {
|
||||||
aclMsg := &aclrecordproto.AclSyncMessage{}
|
return nil
|
||||||
if err = aclMsg.Unmarshal(req.Payload); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content := aclMsg.GetContent()
|
|
||||||
switch {
|
|
||||||
case content.GetAddRecords() != nil:
|
|
||||||
return s.handleAddRecords(ctx, senderId, content.GetAddRecords())
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unexpected aclSync message: %T", content.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *syncAclHandler) handleAddRecords(ctx context.Context, senderId string, addRecord *aclrecordproto.AclAddRecords) (err error) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/util/cidutil"
|
"github.com/anyproto/any-sync/util/cidutil"
|
||||||
"github.com/anyproto/any-sync/util/crypto"
|
"github.com/anyproto/any-sync/util/crypto"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
@ -255,12 +256,12 @@ func ValidateSpaceHeader(rawHeaderWithId *spacesyncproto.RawSpaceHeaderWithId, i
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCreateSpaceAclPayload(rawWithId *aclrecordproto.RawAclRecordWithId) (spaceId string, err error) {
|
func validateCreateSpaceAclPayload(rawWithId *consensusproto.RawRecordWithId) (spaceId string, err error) {
|
||||||
if !cidutil.VerifyCid(rawWithId.Payload, rawWithId.Id) {
|
if !cidutil.VerifyCid(rawWithId.Payload, rawWithId.Id) {
|
||||||
err = objecttree.ErrIncorrectCid
|
err = objecttree.ErrIncorrectCid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var rawAcl aclrecordproto.RawAclRecord
|
var rawAcl consensusproto.RawRecord
|
||||||
err = proto.Unmarshal(rawWithId.Payload, &rawAcl)
|
err = proto.Unmarshal(rawWithId.Payload, &rawAcl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@ -2,20 +2,22 @@ package commonspace
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/objecttree"
|
"github.com/anyproto/any-sync/commonspace/object/tree/objecttree"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/util/cidutil"
|
"github.com/anyproto/any-sync/util/cidutil"
|
||||||
"github.com/anyproto/any-sync/util/crypto"
|
"github.com/anyproto/any-sync/util/crypto"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"math/rand"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSuccessHeaderPayloadForSpaceCreate(t *testing.T) {
|
func TestSuccessHeaderPayloadForSpaceCreate(t *testing.T) {
|
||||||
@ -188,14 +190,14 @@ func TestFailAclPayloadSpace_IncorrectCid(t *testing.T) {
|
|||||||
marshalled, err := aclRoot.Marshal()
|
marshalled, err := aclRoot.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
signature, err := accountKeys.SignKey.Sign(marshalled)
|
signature, err := accountKeys.SignKey.Sign(marshalled)
|
||||||
rawAclRecord := &aclrecordproto.RawAclRecord{
|
rawAclRecord := &consensusproto.RawRecord{
|
||||||
Payload: marshalled,
|
Payload: marshalled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
marshalledRaw, err := rawAclRecord.Marshal()
|
marshalledRaw, err := rawAclRecord.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
aclHeadId := "rand"
|
aclHeadId := "rand"
|
||||||
rawWithId := &aclrecordproto.RawAclRecordWithId{
|
rawWithId := &consensusproto.RawRecordWithId{
|
||||||
Payload: marshalledRaw,
|
Payload: marshalledRaw,
|
||||||
Id: aclHeadId,
|
Id: aclHeadId,
|
||||||
}
|
}
|
||||||
@ -230,7 +232,7 @@ func TestFailedAclPayloadSpace_IncorrectSignature(t *testing.T) {
|
|||||||
}
|
}
|
||||||
marshalled, err := aclRoot.Marshal()
|
marshalled, err := aclRoot.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
rawAclRecord := &aclrecordproto.RawAclRecord{
|
rawAclRecord := &consensusproto.RawRecord{
|
||||||
Payload: marshalled,
|
Payload: marshalled,
|
||||||
Signature: marshalled,
|
Signature: marshalled,
|
||||||
}
|
}
|
||||||
@ -238,7 +240,7 @@ func TestFailedAclPayloadSpace_IncorrectSignature(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
aclHeadId, err := cidutil.NewCidFromBytes(marshalledRaw)
|
aclHeadId, err := cidutil.NewCidFromBytes(marshalledRaw)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
rawWithId := &aclrecordproto.RawAclRecordWithId{
|
rawWithId := &consensusproto.RawRecordWithId{
|
||||||
Payload: marshalledRaw,
|
Payload: marshalledRaw,
|
||||||
Id: aclHeadId,
|
Id: aclHeadId,
|
||||||
}
|
}
|
||||||
@ -286,7 +288,7 @@ func TestFailedAclPayloadSpace_IncorrectIdentitySignature(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
signature, err := accountKeys.SignKey.Sign(marshalled)
|
signature, err := accountKeys.SignKey.Sign(marshalled)
|
||||||
rawAclRecord := &aclrecordproto.RawAclRecord{
|
rawAclRecord := &consensusproto.RawRecord{
|
||||||
Payload: marshalled,
|
Payload: marshalled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
@ -298,7 +300,7 @@ func TestFailedAclPayloadSpace_IncorrectIdentitySignature(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawWithId := &aclrecordproto.RawAclRecordWithId{
|
rawWithId := &consensusproto.RawRecordWithId{
|
||||||
Payload: marshalledRaw,
|
Payload: marshalledRaw,
|
||||||
Id: aclHeadId,
|
Id: aclHeadId,
|
||||||
}
|
}
|
||||||
@ -540,7 +542,7 @@ func rawSettingsPayload(accountKeys *accountdata.AccountKeys, spaceId, aclHeadId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawAclWithId(accountKeys *accountdata.AccountKeys, spaceId string) (aclHeadId string, rawWithId *aclrecordproto.RawAclRecordWithId, err error) {
|
func rawAclWithId(accountKeys *accountdata.AccountKeys, spaceId string) (aclHeadId string, rawWithId *consensusproto.RawRecordWithId, err error) {
|
||||||
// TODO: use same storage creation methods as we use in spaces
|
// TODO: use same storage creation methods as we use in spaces
|
||||||
readKeyBytes := make([]byte, 32)
|
readKeyBytes := make([]byte, 32)
|
||||||
_, err = rand.Read(readKeyBytes)
|
_, err = rand.Read(readKeyBytes)
|
||||||
@ -582,7 +584,7 @@ func rawAclWithId(accountKeys *accountdata.AccountKeys, spaceId string) (aclHead
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
signature, err := accountKeys.SignKey.Sign(marshalled)
|
signature, err := accountKeys.SignKey.Sign(marshalled)
|
||||||
rawAclRecord := &aclrecordproto.RawAclRecord{
|
rawAclRecord := &consensusproto.RawRecord{
|
||||||
Payload: marshalled,
|
Payload: marshalled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
@ -594,7 +596,7 @@ func rawAclWithId(accountKeys *accountdata.AccountKeys, spaceId string) (aclHead
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawWithId = &aclrecordproto.RawAclRecordWithId{
|
rawWithId = &consensusproto.RawRecordWithId{
|
||||||
Payload: marshalledRaw,
|
Payload: marshalledRaw,
|
||||||
Id: aclHeadId,
|
Id: aclHeadId,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package commonspace
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/accountservice"
|
"github.com/anyproto/any-sync/accountservice"
|
||||||
"github.com/anyproto/any-sync/app"
|
"github.com/anyproto/any-sync/app"
|
||||||
"github.com/anyproto/any-sync/app/logger"
|
"github.com/anyproto/any-sync/app/logger"
|
||||||
@ -9,7 +11,6 @@ import (
|
|||||||
"github.com/anyproto/any-sync/commonspace/credentialprovider"
|
"github.com/anyproto/any-sync/commonspace/credentialprovider"
|
||||||
"github.com/anyproto/any-sync/commonspace/deletionstate"
|
"github.com/anyproto/any-sync/commonspace/deletionstate"
|
||||||
"github.com/anyproto/any-sync/commonspace/headsync"
|
"github.com/anyproto/any-sync/commonspace/headsync"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl"
|
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/objecttree"
|
"github.com/anyproto/any-sync/commonspace/object/tree/objecttree"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
@ -24,13 +25,13 @@ import (
|
|||||||
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/syncstatus"
|
"github.com/anyproto/any-sync/commonspace/syncstatus"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
"github.com/anyproto/any-sync/metric"
|
"github.com/anyproto/any-sync/metric"
|
||||||
"github.com/anyproto/any-sync/net/peer"
|
"github.com/anyproto/any-sync/net/peer"
|
||||||
"github.com/anyproto/any-sync/net/pool"
|
"github.com/anyproto/any-sync/net/pool"
|
||||||
"github.com/anyproto/any-sync/net/rpc/rpcerr"
|
"github.com/anyproto/any-sync/net/rpc/rpcerr"
|
||||||
"github.com/anyproto/any-sync/nodeconf"
|
"github.com/anyproto/any-sync/nodeconf"
|
||||||
"storj.io/drpc"
|
"storj.io/drpc"
|
||||||
"sync/atomic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const CName = "common.commonspace"
|
const CName = "common.commonspace"
|
||||||
@ -193,7 +194,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) {
|
|||||||
|
|
||||||
func (s *spaceService) addSpaceStorage(ctx context.Context, spaceDescription SpaceDescription) (st spacestorage.SpaceStorage, err error) {
|
func (s *spaceService) addSpaceStorage(ctx context.Context, spaceDescription SpaceDescription) (st spacestorage.SpaceStorage, err error) {
|
||||||
payload := spacestorage.SpaceStorageCreatePayload{
|
payload := spacestorage.SpaceStorageCreatePayload{
|
||||||
AclWithId: &aclrecordproto.RawAclRecordWithId{
|
AclWithId: &consensusproto.RawRecordWithId{
|
||||||
Payload: spaceDescription.AclPayload,
|
Payload: spaceDescription.AclPayload,
|
||||||
Id: spaceDescription.AclId,
|
Id: spaceDescription.AclId,
|
||||||
},
|
},
|
||||||
@ -240,7 +241,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
st, err = s.createSpaceStorage(spacestorage.SpaceStorageCreatePayload{
|
st, err = s.createSpaceStorage(spacestorage.SpaceStorageCreatePayload{
|
||||||
AclWithId: &aclrecordproto.RawAclRecordWithId{
|
AclWithId: &consensusproto.RawRecordWithId{
|
||||||
Payload: res.Payload.AclPayload,
|
Payload: res.Payload.AclPayload,
|
||||||
Id: res.Payload.AclPayloadId,
|
Id: res.Payload.AclPayloadId,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,12 +2,14 @@ package spacestorage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/app"
|
"github.com/anyproto/any-sync/app"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ func (i *InMemorySpaceStorage) Name() (name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewInMemorySpaceStorage(payload SpaceStorageCreatePayload) (SpaceStorage, error) {
|
func NewInMemorySpaceStorage(payload SpaceStorageCreatePayload) (SpaceStorage, error) {
|
||||||
aclStorage, err := liststorage.NewInMemoryAclListStorage(payload.AclWithId.Id, []*aclrecordproto.RawAclRecordWithId{payload.AclWithId})
|
aclStorage, err := liststorage.NewInMemoryAclListStorage(payload.AclWithId.Id, []*consensusproto.RawRecordWithId{payload.AclWithId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,13 @@ package spacestorage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/app"
|
"github.com/anyproto/any-sync/app"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||||
|
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CName = "common.commonspace.spacestorage"
|
const CName = "common.commonspace.spacestorage"
|
||||||
@ -47,7 +48,7 @@ type SpaceStorage interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SpaceStorageCreatePayload struct {
|
type SpaceStorageCreatePayload struct {
|
||||||
AclWithId *aclrecordproto.RawAclRecordWithId
|
AclWithId *consensusproto.RawRecordWithId
|
||||||
SpaceHeaderWithId *spacesyncproto.RawSpaceHeaderWithId
|
SpaceHeaderWithId *spacesyncproto.RawSpaceHeaderWithId
|
||||||
SpaceSettingsWithId *treechangeproto.RawTreeChangeWithId
|
SpaceSettingsWithId *treechangeproto.RawTreeChangeWithId
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||||
// protoc-gen-go-drpc version: v0.0.32
|
// protoc-gen-go-drpc version: v0.0.33
|
||||||
// source: commonspace/spacesyncproto/protos/spacesync.proto
|
// source: commonspace/spacesyncproto/protos/spacesync.proto
|
||||||
|
|
||||||
package spacesyncproto
|
package spacesyncproto
|
||||||
@ -103,6 +103,10 @@ type drpcSpaceSync_ObjectSyncStreamClient struct {
|
|||||||
drpc.Stream
|
drpc.Stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *drpcSpaceSync_ObjectSyncStreamClient) GetStream() drpc.Stream {
|
||||||
|
return x.Stream
|
||||||
|
}
|
||||||
|
|
||||||
func (x *drpcSpaceSync_ObjectSyncStreamClient) Send(m *ObjectSyncMessage) error {
|
func (x *drpcSpaceSync_ObjectSyncStreamClient) Send(m *ObjectSyncMessage) error {
|
||||||
return x.MsgSend(m, drpcEncoding_File_commonspace_spacesyncproto_protos_spacesync_proto{})
|
return x.MsgSend(m, drpcEncoding_File_commonspace_spacesyncproto_protos_spacesync_proto{})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||||
// protoc-gen-go-drpc version: v0.0.32
|
// protoc-gen-go-drpc version: v0.0.33
|
||||||
// source: coordinator/coordinatorproto/protos/coordinator.proto
|
// source: coordinator/coordinatorproto/protos/coordinator.proto
|
||||||
|
|
||||||
package coordinatorproto
|
package coordinatorproto
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||||
// protoc-gen-go-drpc version: v0.0.32
|
// protoc-gen-go-drpc version: v0.0.33
|
||||||
// source: net/streampool/testservice/protos/testservice.proto
|
// source: net/streampool/testservice/protos/testservice.proto
|
||||||
|
|
||||||
package testservice
|
package testservice
|
||||||
@ -72,6 +72,10 @@ type drpcTest_TestStreamClient struct {
|
|||||||
drpc.Stream
|
drpc.Stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *drpcTest_TestStreamClient) GetStream() drpc.Stream {
|
||||||
|
return x.Stream
|
||||||
|
}
|
||||||
|
|
||||||
func (x *drpcTest_TestStreamClient) Send(m *StreamMessage) error {
|
func (x *drpcTest_TestStreamClient) Send(m *StreamMessage) error {
|
||||||
return x.MsgSend(m, drpcEncoding_File_net_streampool_testservice_protos_testservice_proto{})
|
return x.MsgSend(m, drpcEncoding_File_net_streampool_testservice_protos_testservice_proto{})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user