mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Coordinator client methods and expose storage from start
This commit is contained in:
parent
81b50a8766
commit
eef2a0ff91
3 changed files with 73 additions and 10 deletions
|
@ -188,8 +188,9 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) {
|
|||
Register(headsync.New())
|
||||
|
||||
sp := &space{
|
||||
state: state,
|
||||
app: spaceApp,
|
||||
state: state,
|
||||
app: spaceApp,
|
||||
storage: st,
|
||||
}
|
||||
return sp, nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"github.com/anyproto/any-sync/app"
|
||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||
"github.com/anyproto/any-sync/coordinator/coordinatorproto"
|
||||
"github.com/anyproto/any-sync/net/peer"
|
||||
"github.com/anyproto/any-sync/net/pool"
|
||||
|
@ -27,11 +26,13 @@ func New() CoordinatorClient {
|
|||
}
|
||||
|
||||
type CoordinatorClient interface {
|
||||
ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error)
|
||||
ChangeStatus(ctx context.Context, spaceId string, conf *coordinatorproto.DeletionConfirmPayloadWithSignature) (status *coordinatorproto.SpaceStatusPayload, err error)
|
||||
StatusCheckMany(ctx context.Context, spaceIds []string) (statuses []*coordinatorproto.SpaceStatusPayload, err error)
|
||||
StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error)
|
||||
SpaceSign(ctx context.Context, payload SpaceSignPayload) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error)
|
||||
FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error)
|
||||
NetworkConfiguration(ctx context.Context, currentId string) (*coordinatorproto.NetworkConfigurationResponse, error)
|
||||
DeletionLog(ctx context.Context, lastRecordId string, limit int) (records []*coordinatorproto.DeletionLogRecord, err error)
|
||||
app.Component
|
||||
}
|
||||
|
||||
|
@ -57,13 +58,16 @@ func (c *coordinatorClient) Name() (name string) {
|
|||
return CName
|
||||
}
|
||||
|
||||
func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error) {
|
||||
func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, conf *coordinatorproto.DeletionConfirmPayloadWithSignature) (status *coordinatorproto.SpaceStatusPayload, err error) {
|
||||
confMarshalled, err := conf.Marshal()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = c.doClient(ctx, func(cl coordinatorproto.DRPCCoordinatorClient) error {
|
||||
resp, err := cl.SpaceStatusChange(ctx, &coordinatorproto.SpaceStatusChangeRequest{
|
||||
SpaceId: spaceId,
|
||||
DeletionPayloadId: deleteRaw.GetId(),
|
||||
DeletionPayload: deleteRaw.GetRawChange(),
|
||||
DeletionPayloadType: coordinatorproto.DeletionPayloadType_Tree,
|
||||
DeletionPayload: confMarshalled,
|
||||
DeletionPayloadType: coordinatorproto.DeletionPayloadType_Confirm,
|
||||
})
|
||||
if err != nil {
|
||||
return rpcerr.Unwrap(err)
|
||||
|
@ -74,6 +78,35 @@ func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, de
|
|||
return
|
||||
}
|
||||
|
||||
func (c *coordinatorClient) DeletionLog(ctx context.Context, lastRecordId string, limit int) (records []*coordinatorproto.DeletionLogRecord, err error) {
|
||||
err = c.doClient(ctx, func(cl coordinatorproto.DRPCCoordinatorClient) error {
|
||||
resp, err := cl.DeletionLog(ctx, &coordinatorproto.DeletionLogRequest{
|
||||
AfterId: lastRecordId,
|
||||
Limit: uint32(limit),
|
||||
})
|
||||
if err != nil {
|
||||
return rpcerr.Unwrap(err)
|
||||
}
|
||||
records = resp.Records
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (c *coordinatorClient) StatusCheckMany(ctx context.Context, spaceIds []string) (statuses []*coordinatorproto.SpaceStatusPayload, err error) {
|
||||
err = c.doClient(ctx, func(cl coordinatorproto.DRPCCoordinatorClient) error {
|
||||
resp, err := cl.SpaceStatusCheckMany(ctx, &coordinatorproto.SpaceStatusCheckManyRequest{
|
||||
SpaceIds: spaceIds,
|
||||
})
|
||||
if err != nil {
|
||||
return rpcerr.Unwrap(err)
|
||||
}
|
||||
statuses = resp.Payloads
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (c *coordinatorClient) StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) {
|
||||
err = c.doClient(ctx, func(cl coordinatorproto.DRPCCoordinatorClient) error {
|
||||
resp, err := cl.SpaceStatusCheck(ctx, &coordinatorproto.SpaceStatusCheckRequest{
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
reflect "reflect"
|
||||
|
||||
app "github.com/anyproto/any-sync/app"
|
||||
treechangeproto "github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||
coordinatorclient "github.com/anyproto/any-sync/coordinator/coordinatorclient"
|
||||
coordinatorproto "github.com/anyproto/any-sync/coordinator/coordinatorproto"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
|
@ -39,7 +38,7 @@ func (m *MockCoordinatorClient) EXPECT() *MockCoordinatorClientMockRecorder {
|
|||
}
|
||||
|
||||
// ChangeStatus mocks base method.
|
||||
func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) (*coordinatorproto.SpaceStatusPayload, error) {
|
||||
func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *coordinatorproto.DeletionConfirmPayloadWithSignature) (*coordinatorproto.SpaceStatusPayload, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ChangeStatus", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(*coordinatorproto.SpaceStatusPayload)
|
||||
|
@ -53,6 +52,21 @@ func (mr *MockCoordinatorClientMockRecorder) ChangeStatus(arg0, arg1, arg2 inter
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeStatus", reflect.TypeOf((*MockCoordinatorClient)(nil).ChangeStatus), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// DeletionLog mocks base method.
|
||||
func (m *MockCoordinatorClient) DeletionLog(arg0 context.Context, arg1 string, arg2 int) ([]*coordinatorproto.DeletionLogRecord, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeletionLog", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].([]*coordinatorproto.DeletionLogRecord)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// DeletionLog indicates an expected call of DeletionLog.
|
||||
func (mr *MockCoordinatorClientMockRecorder) DeletionLog(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeletionLog", reflect.TypeOf((*MockCoordinatorClient)(nil).DeletionLog), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// FileLimitCheck mocks base method.
|
||||
func (m *MockCoordinatorClient) FileLimitCheck(arg0 context.Context, arg1 string, arg2 []byte) (uint64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -140,3 +154,18 @@ func (mr *MockCoordinatorClientMockRecorder) StatusCheck(arg0, arg1 interface{})
|
|||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StatusCheck", reflect.TypeOf((*MockCoordinatorClient)(nil).StatusCheck), arg0, arg1)
|
||||
}
|
||||
|
||||
// StatusCheckMany mocks base method.
|
||||
func (m *MockCoordinatorClient) StatusCheckMany(arg0 context.Context, arg1 []string) ([]*coordinatorproto.SpaceStatusPayload, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "StatusCheckMany", arg0, arg1)
|
||||
ret0, _ := ret[0].([]*coordinatorproto.SpaceStatusPayload)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// StatusCheckMany indicates an expected call of StatusCheckMany.
|
||||
func (mr *MockCoordinatorClientMockRecorder) StatusCheckMany(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StatusCheckMany", reflect.TypeOf((*MockCoordinatorClient)(nil).StatusCheckMany), arg0, arg1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue