mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Add space pull with acls
This commit is contained in:
parent
31d1deb0c8
commit
95ba16876a
8 changed files with 781 additions and 131 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/anyproto/any-sync/commonspace/acl/aclclient"
|
||||
"github.com/anyproto/any-sync/commonspace/deletionmanager"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/recordverifier"
|
||||
"github.com/anyproto/any-sync/commonspace/object/keyvalue"
|
||||
"github.com/anyproto/any-sync/commonspace/object/keyvalue/keyvaluestorage"
|
||||
|
@ -161,7 +162,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string, deps Deps) (Spac
|
|||
return nil, err
|
||||
}
|
||||
} else {
|
||||
st, err = s.getSpaceStorageFromRemote(ctx, id)
|
||||
st, err = s.getSpaceStorageFromRemote(ctx, id, deps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -243,7 +244,7 @@ func (s *spaceService) addSpaceStorage(ctx context.Context, spaceDescription Spa
|
|||
return
|
||||
}
|
||||
|
||||
func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string) (st spacestorage.SpaceStorage, err error) {
|
||||
func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string, deps Deps) (st spacestorage.SpaceStorage, err error) {
|
||||
// we can't connect to client if it is a node
|
||||
if s.configurationService.IsResponsible(id) {
|
||||
err = spacesyncproto.ErrSpaceMissing
|
||||
|
@ -282,7 +283,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string)
|
|||
}
|
||||
}
|
||||
for i, p := range peers {
|
||||
if st, err = s.spacePullWithPeer(ctx, p, id); err != nil {
|
||||
if st, err = s.spacePullWithPeer(ctx, p, id, deps); err != nil {
|
||||
if i+1 == len(peers) {
|
||||
return
|
||||
} else {
|
||||
|
@ -295,7 +296,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string)
|
|||
return nil, net.ErrUnableToConnect
|
||||
}
|
||||
|
||||
func (s *spaceService) spacePullWithPeer(ctx context.Context, p peer.Peer, id string) (st spacestorage.SpaceStorage, err error) {
|
||||
func (s *spaceService) spacePullWithPeer(ctx context.Context, p peer.Peer, id string, deps Deps) (st spacestorage.SpaceStorage, err error) {
|
||||
var res *spacesyncproto.SpacePullResponse
|
||||
err = p.DoDrpc(ctx, func(conn drpc.Conn) error {
|
||||
cl := spacesyncproto.NewDRPCSpaceSyncClient(conn)
|
||||
|
@ -307,7 +308,7 @@ func (s *spaceService) spacePullWithPeer(ctx context.Context, p peer.Peer, id st
|
|||
return
|
||||
}
|
||||
|
||||
return s.createSpaceStorage(ctx, spacestorage.SpaceStorageCreatePayload{
|
||||
st, err = s.createSpaceStorage(ctx, spacestorage.SpaceStorageCreatePayload{
|
||||
AclWithId: &consensusproto.RawRecordWithId{
|
||||
Payload: res.Payload.AclPayload,
|
||||
Id: res.Payload.AclPayloadId,
|
||||
|
@ -318,6 +319,35 @@ func (s *spaceService) spacePullWithPeer(ctx context.Context, p peer.Peer, id st
|
|||
},
|
||||
SpaceHeaderWithId: res.Payload.SpaceHeader,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if res.AclRecords != nil {
|
||||
aclSt, err := st.AclStorage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
recordVerifier := recordverifier.New()
|
||||
if deps.recordVerifier != nil {
|
||||
recordVerifier = deps.recordVerifier
|
||||
}
|
||||
acl, err := list.BuildAclListWithIdentity(s.account.Account(), aclSt, recordVerifier)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
consRecs := make([]*consensusproto.RawRecordWithId, 0, len(res.AclRecords))
|
||||
for _, rec := range res.AclRecords {
|
||||
consRecs = append(consRecs, &consensusproto.RawRecordWithId{
|
||||
Id: rec.Id,
|
||||
Payload: rec.AclPayload,
|
||||
})
|
||||
}
|
||||
err = acl.AddRawRecords(consRecs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
|
||||
func (s *spaceService) createSpaceStorage(ctx context.Context, payload spacestorage.SpaceStorageCreatePayload) (spacestorage.SpaceStorage, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue