diff --git a/app/ocache/metrics.go b/app/ocache/metrics.go index b5fe9aa4..b520dff2 100644 --- a/app/ocache/metrics.go +++ b/app/ocache/metrics.go @@ -1,11 +1,18 @@ package ocache -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/prometheus/client_golang/prometheus" + "strings" +) func WithPrometheus(reg *prometheus.Registry, namespace, subsystem string) Option { if subsystem == "" { subsystem = "cache" } + nameSplit := strings.Split(namespace, ".") + subSplit := strings.Split(subsystem, ".") + namespace = strings.Join(nameSplit, "_") + subsystem = strings.Join(subSplit, "_") if reg == nil { return nil } diff --git a/app/ocache/metrics_test.go b/app/ocache/metrics_test.go new file mode 100644 index 00000000..e14d670d --- /dev/null +++ b/app/ocache/metrics_test.go @@ -0,0 +1,19 @@ +package ocache + +import ( + "context" + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/require" + "strings" + "testing" +) + +func TestWithPrometheus_MetricsConvertsDots(t *testing.T) { + opt := WithPrometheus(prometheus.NewRegistry(), "some.name", "some.system") + cache := New(func(ctx context.Context, id string) (value Object, err error) { + return &testObject{}, nil + }, opt).(*oCache) + _, err := cache.Get(context.Background(), "id") + require.NoError(t, err) + require.True(t, strings.Contains(cache.metrics.hit.Desc().String(), "some_name_some_system_hit")) +} diff --git a/commonspace/credentialprovider/credentialprovider.go b/commonspace/credentialprovider/credentialprovider.go new file mode 100644 index 00000000..14f7f653 --- /dev/null +++ b/commonspace/credentialprovider/credentialprovider.go @@ -0,0 +1,52 @@ +//go:generate mockgen -destination mock_credentialprovider/mock_credentialprovider.go github.com/anytypeio/any-sync/commonspace/credentialprovider CredentialProvider +package credentialprovider + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/commonspace/spacesyncproto" + "github.com/anytypeio/any-sync/coordinator/coordinatorclient" + "github.com/gogo/protobuf/proto" +) + +const CName = "common.commonspace.credentialprovider" + +func New() app.Component { + return &credentialProvider{} +} + +func NewNoOp() CredentialProvider { + return &noOpProvider{} +} + +type CredentialProvider interface { + GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) +} + +type noOpProvider struct { +} + +func (n noOpProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { + return nil, nil +} + +type credentialProvider struct { + client coordinatorclient.CoordinatorClient +} + +func (c *credentialProvider) Init(a *app.App) (err error) { + c.client = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient) + return +} + +func (c *credentialProvider) Name() (name string) { + return CName +} + +func (c *credentialProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { + receipt, err := c.client.SpaceSign(ctx, spaceHeader.Id, spaceHeader.RawHeader) + if err != nil { + return nil, err + } + return proto.Marshal(receipt) +} diff --git a/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go b/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go new file mode 100644 index 00000000..daa3ccab --- /dev/null +++ b/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go @@ -0,0 +1,51 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/anytypeio/any-sync/commonspace/credentialprovider (interfaces: CredentialProvider) + +// Package mock_credentialprovider is a generated GoMock package. +package mock_credentialprovider + +import ( + context "context" + reflect "reflect" + + spacesyncproto "github.com/anytypeio/any-sync/commonspace/spacesyncproto" + gomock "github.com/golang/mock/gomock" +) + +// MockCredentialProvider is a mock of CredentialProvider interface. +type MockCredentialProvider struct { + ctrl *gomock.Controller + recorder *MockCredentialProviderMockRecorder +} + +// MockCredentialProviderMockRecorder is the mock recorder for MockCredentialProvider. +type MockCredentialProviderMockRecorder struct { + mock *MockCredentialProvider +} + +// NewMockCredentialProvider creates a new mock instance. +func NewMockCredentialProvider(ctrl *gomock.Controller) *MockCredentialProvider { + mock := &MockCredentialProvider{ctrl: ctrl} + mock.recorder = &MockCredentialProviderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCredentialProvider) EXPECT() *MockCredentialProviderMockRecorder { + return m.recorder +} + +// GetCredential mocks base method. +func (m *MockCredentialProvider) GetCredential(arg0 context.Context, arg1 *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCredential", arg0, arg1) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCredential indicates an expected call of GetCredential. +func (mr *MockCredentialProviderMockRecorder) GetCredential(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCredential", reflect.TypeOf((*MockCredentialProvider)(nil).GetCredential), arg0, arg1) +} diff --git a/commonspace/headsync/diffsyncer.go b/commonspace/headsync/diffsyncer.go index 141509d4..9d3434c1 100644 --- a/commonspace/headsync/diffsyncer.go +++ b/commonspace/headsync/diffsyncer.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/anytypeio/any-sync/app/ldiff" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider" "github.com/anytypeio/any-sync/commonspace/object/tree/synctree" "github.com/anytypeio/any-sync/commonspace/object/treegetter" "github.com/anytypeio/any-sync/commonspace/peermanager" @@ -33,29 +34,32 @@ func newDiffSyncer( storage spacestorage.SpaceStorage, clientFactory spacesyncproto.ClientFactory, syncStatus syncstatus.StatusUpdater, + credentialProvider credentialprovider.CredentialProvider, log logger.CtxLogger) DiffSyncer { return &diffSyncer{ - diff: diff, - spaceId: spaceId, - cache: cache, - storage: storage, - peerManager: peerManager, - clientFactory: clientFactory, - log: log, - syncStatus: syncStatus, + diff: diff, + spaceId: spaceId, + cache: cache, + storage: storage, + peerManager: peerManager, + clientFactory: clientFactory, + credentialProvider: credentialProvider, + log: log, + syncStatus: syncStatus, } } type diffSyncer struct { - spaceId string - diff ldiff.Diff - peerManager peermanager.PeerManager - cache treegetter.TreeGetter - storage spacestorage.SpaceStorage - clientFactory spacesyncproto.ClientFactory - log logger.CtxLogger - deletionState settingsstate.ObjectDeletionState - syncStatus syncstatus.StatusUpdater + spaceId string + diff ldiff.Diff + peerManager peermanager.PeerManager + cache treegetter.TreeGetter + storage spacestorage.SpaceStorage + clientFactory spacesyncproto.ClientFactory + log logger.CtxLogger + deletionState settingsstate.ObjectDeletionState + credentialProvider credentialprovider.CredentialProvider + syncStatus syncstatus.StatusUpdater } func (d *diffSyncer) Init(deletionState settingsstate.ObjectDeletionState) { @@ -86,6 +90,7 @@ func (d *diffSyncer) UpdateHeads(id string, heads []string) { } func (d *diffSyncer) Sync(ctx context.Context) error { + // TODO: split diffsyncer into components st := time.Now() // diffing with responsible peers according to configuration peers, err := d.peerManager.GetResponsiblePeers(ctx) @@ -117,6 +122,10 @@ func (d *diffSyncer) syncWithPeer(ctx context.Context, p peer.Peer) (err error) newIds, changedIds, removedIds, err := d.diff.Diff(ctx, rdiff) err = rpcerr.Unwrap(err) if err != nil && err != spacesyncproto.ErrSpaceMissing { + if err == spacesyncproto.ErrSpaceIsDeleted { + d.log.Debug("got space deleted while syncing") + d.syncTrees(ctx, p.Id(), []string{d.storage.SpaceSettingsId()}) + } d.syncStatus.SetNodesOnline(p.Id(), false) return fmt.Errorf("diff error: %v", err) } @@ -192,6 +201,10 @@ func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, peerId string, cl return } + cred, err := d.credentialProvider.GetCredential(ctx, header) + if err != nil { + return + } spacePayload := &spacesyncproto.SpacePayload{ SpaceHeader: header, AclPayload: root.Payload, @@ -200,7 +213,8 @@ func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, peerId string, cl SpaceSettingsPayloadId: spaceSettingsRoot.Id, } _, err = cl.SpacePush(ctx, &spacesyncproto.SpacePushRequest{ - Payload: spacePayload, + Payload: spacePayload, + Credential: cred, }) if err != nil { return diff --git a/commonspace/headsync/diffsyncer_test.go b/commonspace/headsync/diffsyncer_test.go index f5d776c4..f9622ca6 100644 --- a/commonspace/headsync/diffsyncer_test.go +++ b/commonspace/headsync/diffsyncer_test.go @@ -1,11 +1,13 @@ package headsync import ( + "bytes" "context" "fmt" "github.com/anytypeio/any-sync/app/ldiff" "github.com/anytypeio/any-sync/app/ldiff/mock_ldiff" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider/mock_credentialprovider" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/acl/liststorage/mock_liststorage" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" @@ -30,6 +32,7 @@ type pushSpaceRequestMatcher struct { spaceId string aclRootId string settingsId string + credential []byte spaceHeader *spacesyncproto.RawSpaceHeaderWithId } @@ -39,7 +42,7 @@ func (p pushSpaceRequestMatcher) Matches(x interface{}) bool { return false } - return res.Payload.AclPayloadId == p.aclRootId && res.Payload.SpaceHeader == p.spaceHeader && res.Payload.SpaceSettingsPayloadId == p.settingsId + return res.Payload.AclPayloadId == p.aclRootId && res.Payload.SpaceHeader == p.spaceHeader && res.Payload.SpaceSettingsPayloadId == p.settingsId && bytes.Equal(p.credential, res.Credential) } func (p pushSpaceRequestMatcher) String() string { @@ -83,11 +86,13 @@ func newPushSpaceRequestMatcher( spaceId string, aclRootId string, settingsId string, + credential []byte, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) *pushSpaceRequestMatcher { return &pushSpaceRequestMatcher{ spaceId: spaceId, aclRootId: aclRootId, settingsId: settingsId, + credential: credential, spaceHeader: spaceHeader, } } @@ -106,11 +111,12 @@ func TestDiffSyncer_Sync(t *testing.T) { factory := spacesyncproto.ClientFactoryFunc(func(cc drpc.Conn) spacesyncproto.DRPCSpaceSyncClient { return clientMock }) + credentialProvider := mock_credentialprovider.NewMockCredentialProvider(ctrl) delState := mock_settingsstate.NewMockObjectDeletionState(ctrl) spaceId := "spaceId" aclRootId := "aclRootId" l := logger.NewNamed(spaceId) - diffSyncer := newDiffSyncer(spaceId, diffMock, peerManagerMock, cacheMock, stMock, factory, syncstatus.NewNoOpSyncStatus(), l) + diffSyncer := newDiffSyncer(spaceId, diffMock, peerManagerMock, cacheMock, stMock, factory, syncstatus.NewNoOpSyncStatus(), credentialProvider, l) delState.EXPECT().AddObserver(gomock.Any()) diffSyncer.Init(delState) @@ -172,6 +178,7 @@ func TestDiffSyncer_Sync(t *testing.T) { } spaceHeader := &spacesyncproto.RawSpaceHeaderWithId{} spaceSettingsId := "spaceSettingsId" + credential := []byte("credential") peerManagerMock.EXPECT(). GetResponsiblePeers(gomock.Any()). @@ -189,15 +196,18 @@ func TestDiffSyncer_Sync(t *testing.T) { aclStorageMock.EXPECT(). Root(). Return(aclRoot, nil) + credentialProvider.EXPECT(). + GetCredential(gomock.Any(), spaceHeader). + Return(credential, nil) clientMock.EXPECT(). - SpacePush(gomock.Any(), newPushSpaceRequestMatcher(spaceId, aclRootId, settingsId, spaceHeader)). + SpacePush(gomock.Any(), newPushSpaceRequestMatcher(spaceId, aclRootId, settingsId, credential, spaceHeader)). Return(nil, nil) peerManagerMock.EXPECT().SendPeer(gomock.Any(), "mockId", gomock.Any()) require.NoError(t, diffSyncer.Sync(ctx)) }) - t.Run("diff syncer sync other error", func(t *testing.T) { + t.Run("diff syncer sync unexpected", func(t *testing.T) { peerManagerMock.EXPECT(). GetResponsiblePeers(gomock.Any()). Return([]peer.Peer{mockPeer{}}, nil) @@ -207,4 +217,19 @@ func TestDiffSyncer_Sync(t *testing.T) { require.NoError(t, diffSyncer.Sync(ctx)) }) + + t.Run("diff syncer sync space is deleted error", func(t *testing.T) { + peerManagerMock.EXPECT(). + GetResponsiblePeers(gomock.Any()). + Return([]peer.Peer{mockPeer{}}, nil) + diffMock.EXPECT(). + Diff(gomock.Any(), gomock.Eq(NewRemoteDiff(spaceId, clientMock))). + Return(nil, nil, nil, spacesyncproto.ErrSpaceIsDeleted) + stMock.EXPECT().SpaceSettingsId().Return("settingsId") + cacheMock.EXPECT(). + GetTree(gomock.Any(), spaceId, "settingsId"). + Return(nil, nil) + + require.NoError(t, diffSyncer.Sync(ctx)) + }) } diff --git a/commonspace/headsync/headsync.go b/commonspace/headsync/headsync.go index 98e20c20..08d6d9e3 100644 --- a/commonspace/headsync/headsync.go +++ b/commonspace/headsync/headsync.go @@ -5,6 +5,7 @@ import ( "context" "github.com/anytypeio/any-sync/app/ldiff" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider" "github.com/anytypeio/any-sync/commonspace/object/treegetter" "github.com/anytypeio/any-sync/commonspace/peermanager" "github.com/anytypeio/any-sync/commonspace/settings/settingsstate" @@ -60,12 +61,13 @@ func NewHeadSync( peerManager peermanager.PeerManager, cache treegetter.TreeGetter, syncStatus syncstatus.StatusUpdater, + credentialProvider credentialprovider.CredentialProvider, log logger.CtxLogger) HeadSync { diff := ldiff.New(16, 16) l := log.With(zap.String("spaceId", spaceId)) factory := spacesyncproto.ClientFactoryFunc(spacesyncproto.NewDRPCSpaceSyncClient) - syncer := newDiffSyncer(spaceId, diff, peerManager, cache, storage, factory, syncStatus, l) + syncer := newDiffSyncer(spaceId, diff, peerManager, cache, storage, factory, syncStatus, credentialProvider, l) sync := func(ctx context.Context) (err error) { // for clients cancelling the sync process if spaceIsDeleted.Load() && !configuration.IsResponsible(spaceId) { diff --git a/commonspace/object/tree/objecttree/changebuilder.go b/commonspace/object/tree/objecttree/changebuilder.go index f23648b0..29a1a500 100644 --- a/commonspace/object/tree/objecttree/changebuilder.go +++ b/commonspace/object/tree/objecttree/changebuilder.go @@ -220,7 +220,7 @@ func (c *changeBuilder) Build(payload BuilderContent) (ch *Change, rawIdChange * } func (c *changeBuilder) Marshall(ch *Change) (raw *treechangeproto.RawTreeChangeWithId, err error) { - if ch.Id == c.rootChange.Id { + if c.isRoot(ch.Id) { return c.rootChange, nil } treeChange := &treechangeproto.TreeChange{ @@ -255,7 +255,7 @@ func (c *changeBuilder) Marshall(ch *Change) (raw *treechangeproto.RawTreeChange } func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange, id string) (ch *Change, err error) { - if c.rootChange.Id == id { + if c.isRoot(id) { unmarshalled := &treechangeproto.RootChange{} err = proto.Unmarshal(raw.Payload, unmarshalled) if err != nil { @@ -274,3 +274,10 @@ func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange, ch = NewChange(id, unmarshalled, raw.Signature) return } + +func (c *changeBuilder) isRoot(id string) bool { + if c.rootChange != nil { + return c.rootChange.Id == id + } + return false +} diff --git a/commonspace/objectsync/objectsync.go b/commonspace/objectsync/objectsync.go index a1f17b49..7c72e635 100644 --- a/commonspace/objectsync/objectsync.go +++ b/commonspace/objectsync/objectsync.go @@ -7,6 +7,7 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/syncobjectgetter" "github.com/anytypeio/any-sync/commonspace/objectsync/synchandler" "github.com/anytypeio/any-sync/commonspace/peermanager" + "github.com/anytypeio/any-sync/commonspace/spacestorage" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" "github.com/anytypeio/any-sync/nodeconf" "go.uber.org/zap" @@ -32,6 +33,7 @@ type objectSync struct { messagePool MessagePool objectGetter syncobjectgetter.SyncObjectGetter configuration nodeconf.Configuration + spaceStorage spacestorage.SpaceStorage syncCtx context.Context cancelSync context.CancelFunc @@ -43,13 +45,15 @@ func NewObjectSync( spaceIsDeleted *atomic.Bool, configuration nodeconf.Configuration, peerManager peermanager.PeerManager, - objectGetter syncobjectgetter.SyncObjectGetter) ObjectSync { + objectGetter syncobjectgetter.SyncObjectGetter, + storage spacestorage.SpaceStorage) ObjectSync { syncCtx, cancel := context.WithCancel(context.Background()) os := newObjectSync( spaceId, spaceIsDeleted, configuration, objectGetter, + storage, syncCtx, cancel) msgPool := newMessagePool(peerManager, os.handleMessage) @@ -62,11 +66,13 @@ func newObjectSync( spaceIsDeleted *atomic.Bool, configuration nodeconf.Configuration, objectGetter syncobjectgetter.SyncObjectGetter, + spaceStorage spacestorage.SpaceStorage, syncCtx context.Context, cancel context.CancelFunc, ) *objectSync { return &objectSync{ objectGetter: objectGetter, + spaceStorage: spaceStorage, spaceId: spaceId, syncCtx: syncCtx, cancelSync: cancel, @@ -95,8 +101,8 @@ func (s *objectSync) handleMessage(ctx context.Context, senderId string, msg *sp log := log.With(zap.String("objectId", msg.ObjectId), zap.String("replyId", msg.ReplyId)) if s.spaceIsDeleted.Load() { log = log.With(zap.Bool("isDeleted", true)) - // preventing sync with other clients - if !slices.Contains(s.configuration.NodeIds(s.spaceId), senderId) { + // preventing sync with other clients if they are not just syncing the settings tree + if !slices.Contains(s.configuration.NodeIds(s.spaceId), senderId) && msg.ObjectId != s.spaceStorage.SpaceSettingsId() { return spacesyncproto.ErrSpaceIsDeleted } } diff --git a/commonspace/settings/settings.go b/commonspace/settings/settings.go index 0cb4591d..920b385b 100644 --- a/commonspace/settings/settings.go +++ b/commonspace/settings/settings.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/object/keychain" "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" "github.com/anytypeio/any-sync/commonspace/object/tree/synctree" "github.com/anytypeio/any-sync/commonspace/object/tree/synctree/updatelistener" @@ -242,17 +243,7 @@ func (s *settingsObject) verifyDeleteSpace(raw *treechangeproto.RawTreeChangeWit if err != nil { return } - content := &spacesyncproto.SettingsData{} - err = proto.Unmarshal(data, content) - if err != nil { - return - } - if len(content.GetContent()) != 1 || - content.GetContent()[0].GetSpaceDelete() == nil || - content.GetContent()[0].GetSpaceDelete().GetDeleterPeerId() == "" { - return fmt.Errorf("incorrect delete change payload") - } - return + return verifyDeleteContent(data, "") } func (s *settingsObject) addContent(data []byte) (err error) { @@ -271,3 +262,30 @@ func (s *settingsObject) addContent(data []byte) (err error) { s.Update(s) return } + +func VerifyDeleteChange(raw *treechangeproto.RawTreeChangeWithId, identity []byte, peerId string) (err error) { + changeBuilder := objecttree.NewChangeBuilder(keychain.NewKeychain(), nil) + res, err := changeBuilder.Unmarshall(raw, true) + if err != nil { + return + } + if res.Identity != string(identity) { + return fmt.Errorf("incorrect identity") + } + return verifyDeleteContent(res.Data, peerId) +} + +func verifyDeleteContent(data []byte, peerId string) (err error) { + content := &spacesyncproto.SettingsData{} + err = proto.Unmarshal(data, content) + if err != nil { + return + } + if len(content.GetContent()) != 1 || + content.GetContent()[0].GetSpaceDelete() == nil || + (peerId == "" && content.GetContent()[0].GetSpaceDelete().GetDeleterPeerId() == "") || + (peerId != "" && content.GetContent()[0].GetSpaceDelete().GetDeleterPeerId() != peerId) { + return fmt.Errorf("incorrect delete change payload") + } + return +} diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 8cf79947..89e9283b 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -5,6 +5,7 @@ import ( "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider" "github.com/anytypeio/any-sync/commonspace/headsync" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" @@ -45,6 +46,7 @@ type spaceService struct { configurationService nodeconf.Service storageProvider spacestorage.SpaceStorageProvider peermanagerProvider peermanager.PeerManagerProvider + credentialProvider credentialprovider.CredentialProvider treeGetter treegetter.TreeGetter pool pool.Pool } @@ -56,6 +58,12 @@ func (s *spaceService) Init(a *app.App) (err error) { s.configurationService = a.MustComponent(nodeconf.CName).(nodeconf.Service) s.treeGetter = a.MustComponent(treegetter.CName).(treegetter.TreeGetter) s.peermanagerProvider = a.MustComponent(peermanager.CName).(peermanager.PeerManagerProvider) + credProvider := a.Component(credentialprovider.CName) + if credProvider != nil { + s.credentialProvider = credProvider.(credentialprovider.CredentialProvider) + } else { + s.credentialProvider = credentialprovider.NewNoOp() + } s.pool = a.MustComponent(pool.CName).(pool.Pool) return nil } @@ -139,8 +147,8 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) { return nil, err } - headSync := headsync.NewHeadSync(id, spaceIsDeleted, s.config.SyncPeriod, lastConfiguration, st, peerManager, getter, syncStatus, log) - objectSync := objectsync.NewObjectSync(id, spaceIsDeleted, lastConfiguration, peerManager, getter) + headSync := headsync.NewHeadSync(id, spaceIsDeleted, s.config.SyncPeriod, lastConfiguration, st, peerManager, getter, syncStatus, s.credentialProvider, log) + objectSync := objectsync.NewObjectSync(id, spaceIsDeleted, lastConfiguration, peerManager, getter, st) sp := &space{ id: id, objectSync: objectSync, diff --git a/commonspace/spacestorage/spacestorage.go b/commonspace/spacestorage/spacestorage.go index 1562d6b1..ff24d316 100644 --- a/commonspace/spacestorage/spacestorage.go +++ b/commonspace/spacestorage/spacestorage.go @@ -2,21 +2,28 @@ package spacestorage import ( + "bytes" "context" "errors" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/acl/liststorage" + "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" + "github.com/anytypeio/any-sync/util/cidutil" + "github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey" + "github.com/gogo/protobuf/proto" + "strings" ) const CName = "common.commonspace.spacestorage" var ( - ErrSpaceStorageExists = errors.New("space storage exists") - ErrSpaceStorageMissing = errors.New("space storage missing") + ErrSpaceStorageExists = errors.New("space storage exists") + ErrSpaceStorageMissing = errors.New("space storage missing") + ErrIncorrectSpaceHeader = errors.New("incorrect space header") ErrTreeStorageAlreadyDeleted = errors.New("tree storage already deleted") ) @@ -63,3 +70,38 @@ func ValidateSpaceStorageCreatePayload(payload SpaceStorageCreatePayload) (err e // TODO: add proper validation return nil } + +func ValidateSpaceHeader(spaceId string, header, identity []byte) (err error) { + split := strings.Split(spaceId, ".") + if len(split) != 2 { + return ErrIncorrectSpaceHeader + } + if !cidutil.VerifyCid(header, split[0]) { + err = objecttree.ErrIncorrectCid + return + } + raw := &spacesyncproto.RawSpaceHeader{} + err = proto.Unmarshal(header, raw) + if err != nil { + return + } + payload := &spacesyncproto.SpaceHeader{} + err = proto.Unmarshal(raw.SpaceHeader, payload) + if err != nil { + return + } + if identity != nil && !bytes.Equal(identity, payload.Identity) { + err = ErrIncorrectSpaceHeader + return + } + key, err := signingkey.NewSigningEd25519PubKeyFromBytes(payload.Identity) + if err != nil { + return + } + res, err := key.Verify(raw.SpaceHeader, raw.Signature) + if err != nil || !res { + err = ErrIncorrectSpaceHeader + return + } + return +} diff --git a/commonspace/spacesyncproto/protos/spacesync.proto b/commonspace/spacesyncproto/protos/spacesync.proto index 06f2bf9f..48b44e0f 100644 --- a/commonspace/spacesyncproto/protos/spacesync.proto +++ b/commonspace/spacesyncproto/protos/spacesync.proto @@ -66,6 +66,7 @@ message ObjectSyncMessage { // SpacePushRequest is a request to add space on a node containing only one acl record message SpacePushRequest { SpacePayload payload = 1; + bytes Credential = 2; } // SpacePushResponse is an empty response diff --git a/commonspace/spacesyncproto/spacesync.pb.go b/commonspace/spacesyncproto/spacesync.pb.go index 5ef50a67..8fb1a914 100644 --- a/commonspace/spacesyncproto/spacesync.pb.go +++ b/commonspace/spacesyncproto/spacesync.pb.go @@ -437,7 +437,8 @@ func (m *ObjectSyncMessage) GetObjectId() string { // SpacePushRequest is a request to add space on a node containing only one acl record type SpacePushRequest struct { - Payload *SpacePayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Payload *SpacePayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Credential []byte `protobuf:"bytes,2,opt,name=Credential,proto3" json:"Credential,omitempty"` } func (m *SpacePushRequest) Reset() { *m = SpacePushRequest{} } @@ -480,6 +481,13 @@ func (m *SpacePushRequest) GetPayload() *SpacePayload { return nil } +func (m *SpacePushRequest) GetCredential() []byte { + if m != nil { + return m.Credential + } + return nil +} + // SpacePushResponse is an empty response type SpacePushResponse struct { } @@ -1232,21 +1240,21 @@ func init() { } var fileDescriptor_80e49f1f4ac27799 = []byte{ - // 1019 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4b, 0x6f, 0xdb, 0x46, + // 1030 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0x4b, 0x6f, 0xdb, 0x46, 0x10, 0x16, 0xe9, 0xa7, 0xc6, 0xb2, 0xcc, 0x6c, 0x9c, 0x44, 0x55, 0x0c, 0x45, 0x58, 0x14, 0x85, - 0x91, 0x43, 0x1e, 0x72, 0x51, 0x20, 0x69, 0x7b, 0x48, 0x6c, 0xa5, 0x11, 0x8a, 0xd4, 0xc6, 0xaa, + 0x91, 0x43, 0x1e, 0x72, 0x51, 0x20, 0x69, 0x7b, 0x48, 0x64, 0xa7, 0x11, 0x8a, 0xd4, 0xc6, 0xaa, 0x41, 0x81, 0x02, 0x39, 0xac, 0xc9, 0xb1, 0xc4, 0x96, 0x22, 0x59, 0xee, 0xaa, 0xb6, 0x8e, 0x3d, 0xf5, 0xda, 0x73, 0x7b, 0xea, 0x7f, 0xe8, 0x8f, 0xe8, 0x31, 0xc7, 0x1e, 0x0b, 0xfb, 0x8f, 0x14, - 0xbb, 0x5c, 0x3e, 0x24, 0x51, 0x39, 0xf4, 0x22, 0x73, 0xbf, 0x99, 0xf9, 0xe6, 0xb5, 0x3b, 0x63, - 0x78, 0xea, 0x46, 0x93, 0x49, 0x14, 0x8a, 0x98, 0xbb, 0xf8, 0x58, 0xff, 0x8a, 0x59, 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, 0xd7, 0x99, 0xfe, 0x26, 0x4d, 0xb0, 0x65, 0xd4, 0xb2, 0x35, 0x62, 0xcb, + 0x88, 0xec, 0xc3, 0x46, 0xe0, 0x4f, 0x7c, 0xd9, 0x5a, 0xeb, 0x5a, 0x87, 0xbb, 0x2c, 0x3d, 0xd0, + 0x2b, 0x68, 0xe6, 0x54, 0x28, 0xa6, 0x81, 0x54, 0x5c, 0x63, 0x2e, 0xc6, 0x9a, 0xab, 0xc1, 0xf4, + 0x37, 0xf9, 0x02, 0xb6, 0x31, 0xc0, 0x09, 0x86, 0x52, 0xb4, 0xec, 0xee, 0xda, 0xe1, 0x4e, 0xaf, + 0xfb, 0xa8, 0x88, 0x6f, 0x9e, 0xe0, 0x24, 0x55, 0x64, 0xb9, 0x85, 0xf2, 0xec, 0x46, 0xd3, 0x30, 0xf7, 0xac, 0x0f, 0xf4, 0x73, 0xb8, 0x53, 0x69, 0xa8, 0x02, 0xf7, 0x3d, 0xed, 0xbe, 0xce, 0x6c, 0xdf, 0xd3, 0x01, 0x21, 0xf7, 0x74, 0x2a, 0x75, 0xa6, 0xbf, 0xe9, 0x3b, 0xd8, 0x2b, 0x8c, 0x7f, 0x9a, 0xa2, 0x90, 0xa4, 0x05, 0x5b, 0x3a, 0xa4, 0x41, 0x66, 0x9b, 0x1d, 0xc9, 0x13, 0xd8, 0x4c, @@ -1256,47 +1264,48 @@ var fileDescriptor_80e49f1f4ac27799 = []byte{ 0x42, 0xf0, 0x11, 0x7e, 0x20, 0xd4, 0x03, 0xa8, 0x27, 0x69, 0x3e, 0x83, 0x2c, 0xe1, 0x02, 0x50, 0x76, 0x09, 0xc6, 0xc1, 0x6c, 0xe0, 0xe9, 0x52, 0xd6, 0x59, 0x76, 0x54, 0x92, 0x98, 0xcf, 0x82, 0x88, 0x7b, 0xad, 0x75, 0xdd, 0xb7, 0xec, 0x48, 0xda, 0xb0, 0x1d, 0xe9, 0x00, 0x06, 0x5e, 0x6b, - 0x43, 0x1b, 0xe5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xbf, 0xdd, 0x74, 0x6a, 0xef, 0x6f, 0x3a, 0xb5, 0x7f, 0x6e, 0x3a, 0xb5, 0xef, 0xdb, + 0xab, 0xff, 0xf5, 0x3b, 0xdf, 0xd4, 0x7f, 0x8e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x96, + 0xb3, 0xaa, 0x1f, 0x0a, 0x00, 0x00, } func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { @@ -1582,6 +1591,13 @@ func (m *SpacePushRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Credential) > 0 { + i -= len(m.Credential) + copy(dAtA[i:], m.Credential) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.Credential))) + i-- + dAtA[i] = 0x12 + } if m.Payload != nil { { size, err := m.Payload.MarshalToSizedBuffer(dAtA[:i]) @@ -2276,6 +2292,10 @@ func (m *SpacePushRequest) Size() (n int) { l = m.Payload.Size() n += 1 + l + sovSpacesync(uint64(l)) } + l = len(m.Credential) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } return n } @@ -3363,6 +3383,40 @@ func (m *SpacePushRequest) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Credential", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSpacesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSpacesync + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSpacesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Credential = append(m.Credential[:0], dAtA[iNdEx:postIndex]...) + if m.Credential == nil { + m.Credential = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSpacesync(dAtA[iNdEx:]) diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index faac5483..7e490268 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -4,8 +4,10 @@ package coordinatorclient import ( "context" "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" "github.com/anytypeio/any-sync/coordinator/coordinatorproto" "github.com/anytypeio/any-sync/net/pool" + "github.com/anytypeio/any-sync/net/rpc/rpcerr" "github.com/anytypeio/any-sync/nodeconf" ) @@ -16,7 +18,9 @@ func New() CoordinatorClient { } type CoordinatorClient interface { - SpaceSign(ctx context.Context, spaceId string) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) + ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error) + StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) + SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error) app.Component } @@ -26,6 +30,40 @@ type coordinatorClient struct { nodeConf nodeconf.Service } +func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error) { + cl, err := c.client(ctx) + if err != nil { + return + } + resp, err := cl.SpaceStatusChange(ctx, &coordinatorproto.SpaceStatusChangeRequest{ + SpaceId: spaceId, + DeletionChangeId: deleteRaw.GetId(), + DeletionChangePayload: deleteRaw.GetRawChange(), + }) + if err != nil { + err = rpcerr.Unwrap(err) + return + } + status = resp.Payload + return +} + +func (c *coordinatorClient) StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) { + cl, err := c.client(ctx) + if err != nil { + return + } + resp, err := cl.SpaceStatusCheck(ctx, &coordinatorproto.SpaceStatusCheckRequest{ + SpaceId: spaceId, + }) + if err != nil { + err = rpcerr.Unwrap(err) + return + } + status = resp.Payload + return +} + func (c *coordinatorClient) Init(a *app.App) (err error) { c.pool = a.MustComponent(pool.CName).(pool.Service).NewPool(CName) c.nodeConf = a.MustComponent(nodeconf.CName).(nodeconf.Service) @@ -36,15 +74,17 @@ func (c *coordinatorClient) Name() (name string) { return CName } -func (c *coordinatorClient) SpaceSign(ctx context.Context, spaceId string) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) { +func (c *coordinatorClient) SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) { cl, err := c.client(ctx) if err != nil { return } resp, err := cl.SpaceSign(ctx, &coordinatorproto.SpaceSignRequest{ SpaceId: spaceId, + Header: spaceHeader, }) if err != nil { + err = rpcerr.Unwrap(err) return } return resp.Receipt, nil @@ -60,6 +100,7 @@ func (c *coordinatorClient) FileLimitCheck(ctx context.Context, spaceId string, SpaceId: spaceId, }) if err != nil { + err = rpcerr.Unwrap(err) return } return resp.Limit, nil diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index aa246870..b6b6931e 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -9,6 +9,7 @@ import ( reflect "reflect" app "github.com/anytypeio/any-sync/app" + treechangeproto "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" coordinatorproto "github.com/anytypeio/any-sync/coordinator/coordinatorproto" gomock "github.com/golang/mock/gomock" ) @@ -36,6 +37,20 @@ func (m *MockCoordinatorClient) EXPECT() *MockCoordinatorClientMockRecorder { return m.recorder } +// ChangeStatus mocks base method. +func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeStatus", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ChangeStatus indicates an expected call of ChangeStatus. +func (mr *MockCoordinatorClientMockRecorder) ChangeStatus(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeStatus", reflect.TypeOf((*MockCoordinatorClient)(nil).ChangeStatus), arg0, arg1, arg2) +} + // FileLimitCheck mocks base method. func (m *MockCoordinatorClient) FileLimitCheck(arg0 context.Context, arg1 string, arg2 []byte) (uint64, error) { m.ctrl.T.Helper() @@ -80,16 +95,31 @@ func (mr *MockCoordinatorClientMockRecorder) Name() *gomock.Call { } // SpaceSign mocks base method. -func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceReceiptWithSignature, error) { +func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 string, arg2 []byte) (*coordinatorproto.SpaceReceiptWithSignature, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SpaceSign", arg0, arg1) + ret := m.ctrl.Call(m, "SpaceSign", arg0, arg1, arg2) ret0, _ := ret[0].(*coordinatorproto.SpaceReceiptWithSignature) ret1, _ := ret[1].(error) return ret0, ret1 } // SpaceSign indicates an expected call of SpaceSign. -func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceSign", reflect.TypeOf((*MockCoordinatorClient)(nil).SpaceSign), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceSign", reflect.TypeOf((*MockCoordinatorClient)(nil).SpaceSign), arg0, arg1, arg2) +} + +// StatusCheck mocks base method. +func (m *MockCoordinatorClient) StatusCheck(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceStatusCheckResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StatusCheck", arg0, arg1) + ret0, _ := ret[0].(*coordinatorproto.SpaceStatusCheckResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StatusCheck indicates an expected call of StatusCheck. +func (mr *MockCoordinatorClientMockRecorder) StatusCheck(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StatusCheck", reflect.TypeOf((*MockCoordinatorClient)(nil).StatusCheck), arg0, arg1) } diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index fdd764ad..d35c7b8a 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -22,8 +22,77 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type ErrorCodes int32 + +const ( + ErrorCodes_Unexpected ErrorCodes = 0 + ErrorCodes_SpaceDeleted ErrorCodes = 1 + ErrorCodes_SpaceDeletionPending ErrorCodes = 2 + ErrorCodes_SpaceCreated ErrorCodes = 3 + ErrorCodes_SpaceNotExists ErrorCodes = 4 + ErrorCodes_ErrorOffset ErrorCodes = 300 +) + +var ErrorCodes_name = map[int32]string{ + 0: "Unexpected", + 1: "SpaceDeleted", + 2: "SpaceDeletionPending", + 3: "SpaceCreated", + 4: "SpaceNotExists", + 300: "ErrorOffset", +} + +var ErrorCodes_value = map[string]int32{ + "Unexpected": 0, + "SpaceDeleted": 1, + "SpaceDeletionPending": 2, + "SpaceCreated": 3, + "SpaceNotExists": 4, + "ErrorOffset": 300, +} + +func (x ErrorCodes) String() string { + return proto.EnumName(ErrorCodes_name, int32(x)) +} + +func (ErrorCodes) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{0} +} + +type SpaceStatus int32 + +const ( + SpaceStatus_SpaceStatusCreated SpaceStatus = 0 + SpaceStatus_SpaceStatusPendingDeletion SpaceStatus = 1 + SpaceStatus_SpaceStatusDeletionStarted SpaceStatus = 2 + SpaceStatus_SpaceStatusDeleted SpaceStatus = 3 +) + +var SpaceStatus_name = map[int32]string{ + 0: "SpaceStatusCreated", + 1: "SpaceStatusPendingDeletion", + 2: "SpaceStatusDeletionStarted", + 3: "SpaceStatusDeleted", +} + +var SpaceStatus_value = map[string]int32{ + "SpaceStatusCreated": 0, + "SpaceStatusPendingDeletion": 1, + "SpaceStatusDeletionStarted": 2, + "SpaceStatusDeleted": 3, +} + +func (x SpaceStatus) String() string { + return proto.EnumName(SpaceStatus_name, int32(x)) +} + +func (SpaceStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{1} +} + type SpaceSignRequest struct { SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` } func (m *SpaceSignRequest) Reset() { *m = SpaceSignRequest{} } @@ -66,6 +135,65 @@ func (m *SpaceSignRequest) GetSpaceId() string { return "" } +func (m *SpaceSignRequest) GetHeader() []byte { + if m != nil { + return m.Header + } + return nil +} + +type SpaceStatusPayload struct { + Status SpaceStatus `protobuf:"varint,1,opt,name=status,proto3,enum=coordinator.SpaceStatus" json:"status,omitempty"` + DeletionTimestamp int64 `protobuf:"varint,2,opt,name=deletionTimestamp,proto3" json:"deletionTimestamp,omitempty"` +} + +func (m *SpaceStatusPayload) Reset() { *m = SpaceStatusPayload{} } +func (m *SpaceStatusPayload) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusPayload) ProtoMessage() {} +func (*SpaceStatusPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{1} +} +func (m *SpaceStatusPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpaceStatusPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusPayload.Merge(m, src) +} +func (m *SpaceStatusPayload) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusPayload) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusPayload proto.InternalMessageInfo + +func (m *SpaceStatusPayload) GetStatus() SpaceStatus { + if m != nil { + return m.Status + } + return SpaceStatus_SpaceStatusCreated +} + +func (m *SpaceStatusPayload) GetDeletionTimestamp() int64 { + if m != nil { + return m.DeletionTimestamp + } + return 0 +} + type SpaceSignResponse struct { Receipt *SpaceReceiptWithSignature `protobuf:"bytes,1,opt,name=receipt,proto3" json:"receipt,omitempty"` } @@ -74,7 +202,7 @@ func (m *SpaceSignResponse) Reset() { *m = SpaceSignResponse{} } func (m *SpaceSignResponse) String() string { return proto.CompactTextString(m) } func (*SpaceSignResponse) ProtoMessage() {} func (*SpaceSignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{1} + return fileDescriptor_d94f6f99586adae2, []int{2} } func (m *SpaceSignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -120,7 +248,7 @@ func (m *SpaceReceiptWithSignature) Reset() { *m = SpaceReceiptWithSigna func (m *SpaceReceiptWithSignature) String() string { return proto.CompactTextString(m) } func (*SpaceReceiptWithSignature) ProtoMessage() {} func (*SpaceReceiptWithSignature) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{2} + return fileDescriptor_d94f6f99586adae2, []int{3} } func (m *SpaceReceiptWithSignature) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -181,7 +309,7 @@ func (m *SpaceReceipt) Reset() { *m = SpaceReceipt{} } func (m *SpaceReceipt) String() string { return proto.CompactTextString(m) } func (*SpaceReceipt) ProtoMessage() {} func (*SpaceReceipt) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{3} + return fileDescriptor_d94f6f99586adae2, []int{4} } func (m *SpaceReceipt) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -256,7 +384,7 @@ func (m *FileLimitCheckRequest) Reset() { *m = FileLimitCheckRequest{} } func (m *FileLimitCheckRequest) String() string { return proto.CompactTextString(m) } func (*FileLimitCheckRequest) ProtoMessage() {} func (*FileLimitCheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{4} + return fileDescriptor_d94f6f99586adae2, []int{5} } func (m *FileLimitCheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -308,7 +436,7 @@ func (m *FileLimitCheckResponse) Reset() { *m = FileLimitCheckResponse{} func (m *FileLimitCheckResponse) String() string { return proto.CompactTextString(m) } func (*FileLimitCheckResponse) ProtoMessage() {} func (*FileLimitCheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{5} + return fileDescriptor_d94f6f99586adae2, []int{6} } func (m *FileLimitCheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -344,13 +472,216 @@ func (m *FileLimitCheckResponse) GetLimit() uint64 { return 0 } +// SpaceStatusCheckRequest contains the spaceId of requested space +type SpaceStatusCheckRequest struct { + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` +} + +func (m *SpaceStatusCheckRequest) Reset() { *m = SpaceStatusCheckRequest{} } +func (m *SpaceStatusCheckRequest) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusCheckRequest) ProtoMessage() {} +func (*SpaceStatusCheckRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{7} +} +func (m *SpaceStatusCheckRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusCheckRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusCheckRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpaceStatusCheckRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusCheckRequest.Merge(m, src) +} +func (m *SpaceStatusCheckRequest) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusCheckRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusCheckRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusCheckRequest proto.InternalMessageInfo + +func (m *SpaceStatusCheckRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +// SpaceStatusCheckResponse contains the current status of space +type SpaceStatusCheckResponse struct { + Payload *SpaceStatusPayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` +} + +func (m *SpaceStatusCheckResponse) Reset() { *m = SpaceStatusCheckResponse{} } +func (m *SpaceStatusCheckResponse) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusCheckResponse) ProtoMessage() {} +func (*SpaceStatusCheckResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{8} +} +func (m *SpaceStatusCheckResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusCheckResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusCheckResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpaceStatusCheckResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusCheckResponse.Merge(m, src) +} +func (m *SpaceStatusCheckResponse) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusCheckResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusCheckResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusCheckResponse proto.InternalMessageInfo + +func (m *SpaceStatusCheckResponse) GetPayload() *SpaceStatusPayload { + if m != nil { + return m.Payload + } + return nil +} + +// SpaceStatusChangeRequest contains the deletionChange if we want to delete space, or it is empty otherwise +type SpaceStatusChangeRequest struct { + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + DeletionChangeId string `protobuf:"bytes,2,opt,name=deletionChangeId,proto3" json:"deletionChangeId,omitempty"` + DeletionChangePayload []byte `protobuf:"bytes,3,opt,name=deletionChangePayload,proto3" json:"deletionChangePayload,omitempty"` +} + +func (m *SpaceStatusChangeRequest) Reset() { *m = SpaceStatusChangeRequest{} } +func (m *SpaceStatusChangeRequest) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusChangeRequest) ProtoMessage() {} +func (*SpaceStatusChangeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{9} +} +func (m *SpaceStatusChangeRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusChangeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusChangeRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpaceStatusChangeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusChangeRequest.Merge(m, src) +} +func (m *SpaceStatusChangeRequest) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusChangeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusChangeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusChangeRequest proto.InternalMessageInfo + +func (m *SpaceStatusChangeRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +func (m *SpaceStatusChangeRequest) GetDeletionChangeId() string { + if m != nil { + return m.DeletionChangeId + } + return "" +} + +func (m *SpaceStatusChangeRequest) GetDeletionChangePayload() []byte { + if m != nil { + return m.DeletionChangePayload + } + return nil +} + +// SpaceStatusChangeResponse contains changed status of space +type SpaceStatusChangeResponse struct { + Payload *SpaceStatusPayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` +} + +func (m *SpaceStatusChangeResponse) Reset() { *m = SpaceStatusChangeResponse{} } +func (m *SpaceStatusChangeResponse) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusChangeResponse) ProtoMessage() {} +func (*SpaceStatusChangeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{10} +} +func (m *SpaceStatusChangeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusChangeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusChangeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpaceStatusChangeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusChangeResponse.Merge(m, src) +} +func (m *SpaceStatusChangeResponse) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusChangeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusChangeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusChangeResponse proto.InternalMessageInfo + +func (m *SpaceStatusChangeResponse) GetPayload() *SpaceStatusPayload { + if m != nil { + return m.Payload + } + return nil +} + func init() { + proto.RegisterEnum("coordinator.ErrorCodes", ErrorCodes_name, ErrorCodes_value) + proto.RegisterEnum("coordinator.SpaceStatus", SpaceStatus_name, SpaceStatus_value) proto.RegisterType((*SpaceSignRequest)(nil), "coordinator.SpaceSignRequest") + proto.RegisterType((*SpaceStatusPayload)(nil), "coordinator.SpaceStatusPayload") proto.RegisterType((*SpaceSignResponse)(nil), "coordinator.SpaceSignResponse") proto.RegisterType((*SpaceReceiptWithSignature)(nil), "coordinator.SpaceReceiptWithSignature") proto.RegisterType((*SpaceReceipt)(nil), "coordinator.SpaceReceipt") proto.RegisterType((*FileLimitCheckRequest)(nil), "coordinator.FileLimitCheckRequest") proto.RegisterType((*FileLimitCheckResponse)(nil), "coordinator.FileLimitCheckResponse") + proto.RegisterType((*SpaceStatusCheckRequest)(nil), "coordinator.SpaceStatusCheckRequest") + proto.RegisterType((*SpaceStatusCheckResponse)(nil), "coordinator.SpaceStatusCheckResponse") + proto.RegisterType((*SpaceStatusChangeRequest)(nil), "coordinator.SpaceStatusChangeRequest") + proto.RegisterType((*SpaceStatusChangeResponse)(nil), "coordinator.SpaceStatusChangeResponse") } func init() { @@ -358,33 +689,51 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 409 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0xdd, 0x6a, 0xe2, 0x40, - 0x14, 0x76, 0x5c, 0x7f, 0xc8, 0x51, 0xf6, 0x67, 0x76, 0x57, 0xb2, 0xe2, 0x0e, 0x92, 0x85, 0xc5, - 0x8b, 0x45, 0x17, 0x97, 0xdd, 0xeb, 0xa5, 0x42, 0xc1, 0x52, 0x4a, 0x19, 0x91, 0xd2, 0xf6, 0x2a, - 0x4d, 0x86, 0x3a, 0x98, 0x66, 0xd2, 0x64, 0x2c, 0xf8, 0x16, 0x7d, 0x98, 0x5e, 0xf6, 0x01, 0x7a, - 0xe9, 0x65, 0x2f, 0x8b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, 0x8e, 0xf0, 0x65, 0x28, 0xbc, 0x13, - 0xe1, 0xb2, 0x15, 0xbb, 0x90, 0x98, 0xcf, 0x48, 0x61, 0x02, 0x70, 0x67, 0x7b, 0xdc, 0x1d, 0xfa, - 0x92, 0x7b, 0x66, 0xb1, 0x89, 0x5a, 0x05, 0xaa, 0x21, 0xd6, 0x25, 0x7c, 0x3d, 0xe4, 0x1e, 0x3b, - 0xe6, 0x37, 0x5c, 0xf6, 0x46, 0xcc, 0x19, 0xa7, 0x53, 0xcb, 0x30, 0x85, 0xb2, 0x4d, 0x69, 0x07, - 0xce, 0x6f, 0xce, 0xb7, 0x0d, 0xb5, 0xed, 0xe2, 0xcb, 0x21, 0x7f, 0x81, 0xa2, 0x17, 0xa3, 0xaa, - 0x66, 0x81, 0x26, 0x41, 0xf7, 0x01, 0x41, 0xa5, 0xb7, 0x9e, 0x35, 0x3e, 0x02, 0x63, 0xb5, 0x1f, - 0xf8, 0xfb, 0xdb, 0x35, 0xd0, 0xb6, 0xac, 0x4e, 0x76, 0xa5, 0x97, 0x1d, 0xcf, 0xe1, 0xfd, 0xa6, - 0x17, 0x6c, 0x6d, 0x28, 0x32, 0xff, 0x42, 0xfd, 0xc7, 0x5e, 0x4e, 0x52, 0xfa, 0xe0, 0xdf, 0xd3, - 0x9c, 0xa0, 0xd9, 0x9c, 0xa0, 0x97, 0x39, 0x41, 0xf7, 0x0b, 0x92, 0x9b, 0x2d, 0x48, 0xee, 0x79, - 0x41, 0x72, 0x17, 0x8d, 0x7d, 0x57, 0xea, 0xaa, 0xa4, 0x5e, 0x7f, 0x5e, 0x03, 0x00, 0x00, 0xff, - 0xff, 0x77, 0x20, 0x0a, 0xe9, 0x79, 0x03, 0x00, 0x00, + // 704 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x4f, 0x13, 0x4f, + 0x18, 0xef, 0xb6, 0x05,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, 0x86, 0x7d, 0xe1, 0x44, 0x71, 0x7c, 0x79, 0x28, + 0xaf, 0x2c, 0xa8, 0xd2, 0xfe, 0x53, 0x86, 0x7a, 0x67, 0xd0, 0x2d, 0xf2, 0x1c, 0x6a, 0xfd, 0xe7, + 0x89, 0xdc, 0x2a, 0x68, 0xe4, 0xe0, 0xc9, 0x6d, 0x9a, 0xe3, 0xcc, 0xd9, 0x60, 0xde, 0x42, 0x23, + 0x7f, 0x15, 0x88, 0x95, 0x8b, 0x28, 0xbc, 0x84, 0xcd, 0x3b, 0x13, 0x7d, 0xb2, 0xd4, 0x1f, 0xe4, + 0x17, 0x60, 0x70, 0x01, 0xc8, 0xdd, 0x71, 0x63, 0xcf, 0xa5, 0xbf, 0x77, 0x8d, 0x57, 0x46, 0x70, + 0x20, 0x9f, 0x69, 0x65, 0xe3, 0xc8, 0x84, 0x58, 0xe5, 0xa6, 0x34, 0x57, 0xae, 0x73, 0x4b, 0x39, + 0x9e, 0x3e, 0xfa, 0x79, 0x69, 0x6a, 0x17, 0x97, 0xa6, 0xf6, 0xfb, 0xd2, 0xd4, 0xbe, 0x5e, 0x99, + 0xa5, 0x8b, 0x2b, 0xb3, 0xf4, 0xeb, 0xca, 0x2c, 0xbd, 0x5b, 0x9a, 0xf4, 0x91, 0x3c, 0x98, 0x4e, + 0xfe, 0x6d, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x76, 0x96, 0x0f, 0x4b, 0x07, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -407,6 +756,13 @@ func (m *SpaceSignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Header) > 0 { + i -= len(m.Header) + copy(dAtA[i:], m.Header) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.Header))) + i-- + dAtA[i] = 0x12 + } if len(m.SpaceId) > 0 { i -= len(m.SpaceId) copy(dAtA[i:], m.SpaceId) @@ -417,6 +773,39 @@ func (m *SpaceSignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *SpaceStatusPayload) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpaceStatusPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DeletionTimestamp != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.DeletionTimestamp)) + i-- + dAtA[i] = 0x10 + } + if m.Status != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *SpaceSignResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -610,6 +999,150 @@ func (m *FileLimitCheckResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *SpaceStatusCheckRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpaceStatusCheckRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusCheckRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SpaceId) > 0 { + i -= len(m.SpaceId) + copy(dAtA[i:], m.SpaceId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.SpaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SpaceStatusCheckResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpaceStatusCheckResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusCheckResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Payload != nil { + { + size, err := m.Payload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCoordinator(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SpaceStatusChangeRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpaceStatusChangeRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusChangeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DeletionChangePayload) > 0 { + i -= len(m.DeletionChangePayload) + copy(dAtA[i:], m.DeletionChangePayload) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.DeletionChangePayload))) + i-- + dAtA[i] = 0x1a + } + if len(m.DeletionChangeId) > 0 { + i -= len(m.DeletionChangeId) + copy(dAtA[i:], m.DeletionChangeId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.DeletionChangeId))) + i-- + dAtA[i] = 0x12 + } + if len(m.SpaceId) > 0 { + i -= len(m.SpaceId) + copy(dAtA[i:], m.SpaceId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.SpaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SpaceStatusChangeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpaceStatusChangeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusChangeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Payload != nil { + { + size, err := m.Payload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCoordinator(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintCoordinator(dAtA []byte, offset int, v uint64) int { offset -= sovCoordinator(v) base := offset @@ -631,6 +1164,25 @@ func (m *SpaceSignRequest) Size() (n int) { if l > 0 { n += 1 + l + sovCoordinator(uint64(l)) } + l = len(m.Header) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *SpaceStatusPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Status != 0 { + n += 1 + sovCoordinator(uint64(m.Status)) + } + if m.DeletionTimestamp != 0 { + n += 1 + sovCoordinator(uint64(m.DeletionTimestamp)) + } return n } @@ -721,6 +1273,66 @@ func (m *FileLimitCheckResponse) Size() (n int) { return n } +func (m *SpaceStatusCheckRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *SpaceStatusCheckResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Payload != nil { + l = m.Payload.Size() + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *SpaceStatusChangeRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.DeletionChangeId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.DeletionChangePayload) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *SpaceStatusChangeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Payload != nil { + l = m.Payload.Size() + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + func sovCoordinator(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -788,6 +1400,128 @@ func (m *SpaceSignRequest) Unmarshal(dAtA []byte) error { } m.SpaceId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Header = append(m.Header[:0], dAtA[iNdEx:postIndex]...) + if m.Header == nil { + m.Header = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SpaceStatusPayload) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpaceStatusPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= SpaceStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionTimestamp", wireType) + } + m.DeletionTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DeletionTimestamp |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) @@ -1399,6 +2133,408 @@ func (m *FileLimitCheckResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *SpaceStatusCheckRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpaceStatusCheckRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusCheckRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpaceId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SpaceStatusCheckResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpaceStatusCheckResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusCheckResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Payload == nil { + m.Payload = &SpaceStatusPayload{} + } + if err := m.Payload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SpaceStatusChangeRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpaceStatusChangeRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusChangeRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpaceId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionChangeId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DeletionChangeId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionChangePayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DeletionChangePayload = append(m.DeletionChangePayload[:0], dAtA[iNdEx:postIndex]...) + if m.DeletionChangePayload == nil { + m.DeletionChangePayload = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SpaceStatusChangeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpaceStatusChangeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusChangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Payload == nil { + m.Payload = &SpaceStatusPayload{} + } + if err := m.Payload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipCoordinator(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/coordinator/coordinatorproto/coordinator_drpc.pb.go b/coordinator/coordinatorproto/coordinator_drpc.pb.go index 67f72ef7..3fd4e199 100644 --- a/coordinator/coordinatorproto/coordinator_drpc.pb.go +++ b/coordinator/coordinatorproto/coordinator_drpc.pb.go @@ -42,6 +42,8 @@ type DRPCCoordinatorClient interface { SpaceSign(ctx context.Context, in *SpaceSignRequest) (*SpaceSignResponse, error) FileLimitCheck(ctx context.Context, in *FileLimitCheckRequest) (*FileLimitCheckResponse, error) + SpaceStatusCheck(ctx context.Context, in *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) + SpaceStatusChange(ctx context.Context, in *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) } type drpcCoordinatorClient struct { @@ -72,9 +74,29 @@ func (c *drpcCoordinatorClient) FileLimitCheck(ctx context.Context, in *FileLimi return out, nil } +func (c *drpcCoordinatorClient) SpaceStatusCheck(ctx context.Context, in *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) { + out := new(SpaceStatusCheckResponse) + err := c.cc.Invoke(ctx, "/coordinator.Coordinator/SpaceStatusCheck", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, in, out) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *drpcCoordinatorClient) SpaceStatusChange(ctx context.Context, in *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) { + out := new(SpaceStatusChangeResponse) + err := c.cc.Invoke(ctx, "/coordinator.Coordinator/SpaceStatusChange", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, in, out) + if err != nil { + return nil, err + } + return out, nil +} + type DRPCCoordinatorServer interface { SpaceSign(context.Context, *SpaceSignRequest) (*SpaceSignResponse, error) FileLimitCheck(context.Context, *FileLimitCheckRequest) (*FileLimitCheckResponse, error) + SpaceStatusCheck(context.Context, *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) + SpaceStatusChange(context.Context, *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) } type DRPCCoordinatorUnimplementedServer struct{} @@ -87,9 +109,17 @@ func (s *DRPCCoordinatorUnimplementedServer) FileLimitCheck(context.Context, *Fi return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } +func (s *DRPCCoordinatorUnimplementedServer) SpaceStatusCheck(context.Context, *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + +func (s *DRPCCoordinatorUnimplementedServer) SpaceStatusChange(context.Context, *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + type DRPCCoordinatorDescription struct{} -func (DRPCCoordinatorDescription) NumMethods() int { return 2 } +func (DRPCCoordinatorDescription) NumMethods() int { return 4 } func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { switch n { @@ -111,6 +141,24 @@ func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Rec in1.(*FileLimitCheckRequest), ) }, DRPCCoordinatorServer.FileLimitCheck, true + case 2: + return "/coordinator.Coordinator/SpaceStatusCheck", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCCoordinatorServer). + SpaceStatusCheck( + ctx, + in1.(*SpaceStatusCheckRequest), + ) + }, DRPCCoordinatorServer.SpaceStatusCheck, true + case 3: + return "/coordinator.Coordinator/SpaceStatusChange", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCCoordinatorServer). + SpaceStatusChange( + ctx, + in1.(*SpaceStatusChangeRequest), + ) + }, DRPCCoordinatorServer.SpaceStatusChange, true default: return "", nil, nil, nil, false } @@ -151,3 +199,35 @@ func (x *drpcCoordinator_FileLimitCheckStream) SendAndClose(m *FileLimitCheckRes } return x.CloseSend() } + +type DRPCCoordinator_SpaceStatusCheckStream interface { + drpc.Stream + SendAndClose(*SpaceStatusCheckResponse) error +} + +type drpcCoordinator_SpaceStatusCheckStream struct { + drpc.Stream +} + +func (x *drpcCoordinator_SpaceStatusCheckStream) SendAndClose(m *SpaceStatusCheckResponse) error { + if err := x.MsgSend(m, drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}); err != nil { + return err + } + return x.CloseSend() +} + +type DRPCCoordinator_SpaceStatusChangeStream interface { + drpc.Stream + SendAndClose(*SpaceStatusChangeResponse) error +} + +type drpcCoordinator_SpaceStatusChangeStream struct { + drpc.Stream +} + +func (x *drpcCoordinator_SpaceStatusChangeStream) SendAndClose(m *SpaceStatusChangeResponse) error { + if err := x.MsgSend(m, drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}); err != nil { + return err + } + return x.CloseSend() +} diff --git a/coordinator/coordinatorproto/errors.go b/coordinator/coordinatorproto/errors.go new file mode 100644 index 00000000..1fb41a2c --- /dev/null +++ b/coordinator/coordinatorproto/errors.go @@ -0,0 +1,16 @@ +package coordinatorproto + +import ( + "errors" + "github.com/anytypeio/any-sync/net/rpc/rpcerr" +) + +var ( + errGroup = rpcerr.ErrGroup(ErrorCodes_ErrorOffset) + + ErrUnexpected = errGroup.Register(errors.New("unexpected error"), uint64(ErrorCodes_Unexpected)) + ErrSpaceIsCreated = errGroup.Register(errors.New("space is missing"), uint64(ErrorCodes_SpaceCreated)) + ErrSpaceIsDeleted = errGroup.Register(errors.New("space is deleted"), uint64(ErrorCodes_SpaceDeleted)) + ErrSpaceDeletionPending = errGroup.Register(errors.New("space is set out for deletion"), uint64(ErrorCodes_SpaceDeletionPending)) + ErrSpaceNotExists = errGroup.Register(errors.New("space not exists"), uint64(ErrorCodes_SpaceNotExists)) +) diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index b7e539bb..b828740c 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -12,10 +12,38 @@ service Coordinator { // - if a handshake identity matches a given identity // - if a requester contains in nodeconf list rpc FileLimitCheck(FileLimitCheckRequest) returns (FileLimitCheckResponse); + + // SpaceStatusCheck checks the status of space and tells if it is deleted or not + rpc SpaceStatusCheck(SpaceStatusCheckRequest) returns (SpaceStatusCheckResponse); + + // SpaceStatusChange changes the status of space + rpc SpaceStatusChange(SpaceStatusChangeRequest) returns (SpaceStatusChangeResponse); } message SpaceSignRequest { string spaceId = 1; + bytes header = 2; +} + +enum ErrorCodes { + Unexpected = 0; + SpaceDeleted = 1; + SpaceDeletionPending = 2; + SpaceCreated = 3; + SpaceNotExists = 4; + ErrorOffset = 300; +} + +enum SpaceStatus { + SpaceStatusCreated = 0; + SpaceStatusPendingDeletion = 1; + SpaceStatusDeletionStarted = 2; + SpaceStatusDeleted = 3; +} + +message SpaceStatusPayload { + SpaceStatus status = 1; + int64 deletionTimestamp = 2; } message SpaceSignResponse { @@ -53,3 +81,25 @@ message FileLimitCheckRequest { message FileLimitCheckResponse { uint64 limit = 1; } + +// SpaceStatusCheckRequest contains the spaceId of requested space +message SpaceStatusCheckRequest { + string spaceId = 1; +} + +// SpaceStatusCheckResponse contains the current status of space +message SpaceStatusCheckResponse { + SpaceStatusPayload payload = 1; +} + +// SpaceStatusChangeRequest contains the deletionChange if we want to delete space, or it is empty otherwise +message SpaceStatusChangeRequest { + string spaceId = 1; + string deletionChangeId = 2; + bytes deletionChangePayload = 3; +} + +// SpaceStatusChangeResponse contains changed status of space +message SpaceStatusChangeResponse { + SpaceStatusPayload payload = 1; +} diff --git a/nodeconf/mock_nodeconf/mock_nodeconf.go b/nodeconf/mock_nodeconf/mock_nodeconf.go index a403da04..b8b2e800 100644 --- a/nodeconf/mock_nodeconf/mock_nodeconf.go +++ b/nodeconf/mock_nodeconf/mock_nodeconf.go @@ -157,6 +157,20 @@ func (mr *MockConfigurationMockRecorder) ConsensusPeers() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockConfiguration)(nil).ConsensusPeers)) } +// CoordinatorPeers mocks base method. +func (m *MockConfiguration) CoordinatorPeers() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CoordinatorPeers") + ret0, _ := ret[0].([]string) + return ret0 +} + +// CoordinatorPeers indicates an expected call of CoordinatorPeers. +func (mr *MockConfigurationMockRecorder) CoordinatorPeers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockConfiguration)(nil).CoordinatorPeers)) +} + // FilePeers mocks base method. func (m *MockConfiguration) FilePeers() []string { m.ctrl.T.Helper()