Merge branch 'protocol-crypto-update' into update-proto

# Conflicts:
#	commonspace/object/acl/aclrecordproto/aclrecord.pb.go
This commit is contained in:
mcrakhman 2023-03-24 14:58:47 +01:00
commit d9cf1feaee
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B
22 changed files with 2134 additions and 269 deletions

View File

@ -20,7 +20,10 @@ var (
) )
var ( var (
log = logger.NewNamed("app") log = logger.NewNamed("app")
StopDeadline = time.Minute
StopWarningAfter = time.Second * 10
StartWarningAfter = time.Second * 10
) )
// Component is a minimal interface for a common app.Component // Component is a minimal interface for a common app.Component
@ -53,7 +56,8 @@ type ComponentStatable interface {
type App struct { type App struct {
components []Component components []Component
mu sync.RWMutex mu sync.RWMutex
startStat StartStat startStat Stat
stopStat Stat
deviceState int deviceState int
} }
@ -67,18 +71,25 @@ func (app *App) Version() string {
return GitSummary return GitSummary
} }
type StartStat struct { type Stat struct {
SpentMsPerComp map[string]int64 SpentMsPerComp map[string]int64
SpentMsTotal int64 SpentMsTotal int64
} }
// StartStat returns total time spent per comp // StartStat returns total time spent per comp for the last Start
func (app *App) StartStat() StartStat { func (app *App) StartStat() Stat {
app.mu.Lock() app.mu.Lock()
defer app.mu.Unlock() defer app.mu.Unlock()
return app.startStat return app.startStat
} }
// StopStat returns total time spent per comp for the last Close
func (app *App) StopStat() Stat {
app.mu.Lock()
defer app.mu.Unlock()
return app.stopStat
}
// VersionDescription return the full info about the build // VersionDescription return the full info about the build
func (app *App) VersionDescription() string { func (app *App) VersionDescription() string {
return VersionDescription() return VersionDescription()
@ -158,7 +169,17 @@ func (app *App) Start(ctx context.Context) (err error) {
app.mu.RLock() app.mu.RLock()
defer app.mu.RUnlock() defer app.mu.RUnlock()
app.startStat.SpentMsPerComp = make(map[string]int64) app.startStat.SpentMsPerComp = make(map[string]int64)
var currentComponentStarting string
done := make(chan struct{})
go func() {
select {
case <-done:
return
case <-time.After(StartWarningAfter):
l := statLogger(app.stopStat, log).With(zap.String("in_progress", currentComponentStarting))
l.Warn("components start in progress")
}
}()
closeServices := func(idx int) { closeServices := func(idx int) {
for i := idx; i >= 0; i-- { for i := idx; i >= 0; i-- {
if serviceClose, ok := app.components[i].(ComponentRunnable); ok { if serviceClose, ok := app.components[i].(ComponentRunnable); ok {
@ -172,7 +193,7 @@ func (app *App) Start(ctx context.Context) (err error) {
for i, s := range app.components { for i, s := range app.components {
if err = s.Init(app); err != nil { if err = s.Init(app); err != nil {
closeServices(i) closeServices(i)
return fmt.Errorf("can't init service '%s': %v", s.Name(), err) return fmt.Errorf("can't init service '%s': %w", s.Name(), err)
} }
} }
@ -181,14 +202,20 @@ func (app *App) Start(ctx context.Context) (err error) {
start := time.Now() start := time.Now()
if err = serviceRun.Run(ctx); err != nil { if err = serviceRun.Run(ctx); err != nil {
closeServices(i) closeServices(i)
return fmt.Errorf("can't run service '%s': %v", serviceRun.Name(), err) return fmt.Errorf("can't run service '%s': %w", serviceRun.Name(), err)
} }
spent := time.Since(start).Milliseconds() spent := time.Since(start).Milliseconds()
app.startStat.SpentMsTotal += spent app.startStat.SpentMsTotal += spent
app.startStat.SpentMsPerComp[s.Name()] = spent app.startStat.SpentMsPerComp[s.Name()] = spent
} }
} }
log.Debug("all components started")
close(done)
l := statLogger(app.stopStat, log)
if app.startStat.SpentMsTotal > StartWarningAfter.Milliseconds() {
l.Warn("all components started")
}
l.Debug("all components started")
return return
} }
@ -203,18 +230,41 @@ func stackAllGoroutines() []byte {
} }
} }
func statLogger(stat Stat, ctxLogger logger.CtxLogger) logger.CtxLogger {
l := ctxLogger
for k, v := range stat.SpentMsPerComp {
l = l.With(zap.Int64(k, v))
}
l = l.With(zap.Int64("total", stat.SpentMsTotal))
return l
}
// Close stops the application // Close stops the application
// All components with ComponentRunnable implementation will be closed in the reversed order // All components with ComponentRunnable implementation will be closed in the reversed order
func (app *App) Close(ctx context.Context) error { func (app *App) Close(ctx context.Context) error {
log.Debug("close components...") log.Debug("close components...")
app.mu.RLock() app.mu.RLock()
defer app.mu.RUnlock() defer app.mu.RUnlock()
app.stopStat.SpentMsPerComp = make(map[string]int64)
var currentComponentStopping string
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
select { select {
case <-done: case <-done:
return return
case <-time.After(time.Minute): case <-time.After(StopWarningAfter):
statLogger(app.stopStat, log).
With(zap.String("in_progress", currentComponentStopping)).
Warn("components close in progress")
}
}()
go func() {
select {
case <-done:
return
case <-time.After(StopDeadline):
_, _ = os.Stderr.Write([]byte("app.Close timeout\n")) _, _ = os.Stderr.Write([]byte("app.Close timeout\n"))
_, _ = os.Stderr.Write(stackAllGoroutines()) _, _ = os.Stderr.Write(stackAllGoroutines())
panic("app.Close timeout") panic("app.Close timeout")
@ -224,16 +274,27 @@ func (app *App) Close(ctx context.Context) error {
var errs []string var errs []string
for i := len(app.components) - 1; i >= 0; i-- { for i := len(app.components) - 1; i >= 0; i-- {
if serviceClose, ok := app.components[i].(ComponentRunnable); ok { if serviceClose, ok := app.components[i].(ComponentRunnable); ok {
start := time.Now()
currentComponentStopping = app.components[i].Name()
if e := serviceClose.Close(ctx); e != nil { if e := serviceClose.Close(ctx); e != nil {
errs = append(errs, fmt.Sprintf("Component '%s' close error: %v", serviceClose.Name(), e)) errs = append(errs, fmt.Sprintf("Component '%s' close error: %v", serviceClose.Name(), e))
} }
spent := time.Since(start).Milliseconds()
app.stopStat.SpentMsTotal += spent
app.stopStat.SpentMsPerComp[app.components[i].Name()] = spent
} }
} }
close(done) close(done)
if len(errs) > 0 { if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
log.Debug("all components have been closed")
l := statLogger(app.stopStat, log)
if app.stopStat.SpentMsTotal > StopWarningAfter.Milliseconds() {
l.Warn("all components have been closed")
}
l.Debug("all components have been closed")
return nil return nil
} }

View File

@ -32,6 +32,7 @@ func CtxGetFields(ctx context.Context) (fields []zap.Field) {
type CtxLogger struct { type CtxLogger struct {
*zap.Logger *zap.Logger
name string
} }
func (cl CtxLogger) DebugCtx(ctx context.Context, msg string, fields ...zap.Field) { func (cl CtxLogger) DebugCtx(ctx context.Context, msg string, fields ...zap.Field) {
@ -51,5 +52,9 @@ func (cl CtxLogger) ErrorCtx(ctx context.Context, msg string, fields ...zap.Fiel
} }
func (cl CtxLogger) With(fields ...zap.Field) CtxLogger { func (cl CtxLogger) With(fields ...zap.Field) CtxLogger {
return CtxLogger{cl.Logger.With(fields...)} return CtxLogger{cl.Logger.With(fields...), cl.name}
}
func (cl CtxLogger) Sugar() *zap.SugaredLogger {
return NewNamedSugared(cl.name)
} }

View File

@ -8,12 +8,13 @@ import (
) )
var ( var (
mu sync.Mutex mu sync.Mutex
logger *zap.Logger logger *zap.Logger
loggerConfig zap.Config loggerConfig zap.Config
namedLevels = make(map[string]zap.AtomicLevel) namedLevels = make(map[string]zap.AtomicLevel)
namedGlobs = make(map[string]glob.Glob) namedGlobs = make(map[string]glob.Glob)
namedLoggers = make(map[string]CtxLogger) namedLoggers = make(map[string]CtxLogger)
namedSugarLoggers = make(map[string]*zap.SugaredLogger)
) )
func init() { func init() {
@ -59,10 +60,18 @@ func SetNamedLevels(l map[string]zap.AtomicLevel) {
for name, nl := range namedLoggers { for name, nl := range namedLoggers {
level := getLevel(name) level := getLevel(name)
// this can be racy, but newCore := zap.New(logger.Core()).Named(name).WithOptions(
nl.Logger = zap.New(logger.Core()).WithOptions(
zap.IncreaseLevel(level), zap.IncreaseLevel(level),
).Named(name) )
*(nl.Logger) = *newCore
}
for name, nl := range namedSugarLoggers {
level := getLevel(name)
newCore := zap.New(logger.Core()).Named(name).WithOptions(
zap.IncreaseLevel(level),
).Sugar()
*(nl) = *newCore
} }
} }
@ -100,11 +109,24 @@ func NewNamed(name string, fields ...zap.Field) CtxLogger {
} }
level := getLevel(name) level := getLevel(name)
l := zap.New(logger.Core()).WithOptions( l := zap.New(logger.Core()).Named(name).WithOptions(zap.IncreaseLevel(level),
zap.IncreaseLevel(level), zap.Fields(fields...))
).Named(name)
ctxL := CtxLogger{l} ctxL := CtxLogger{Logger: l, name: name}
namedLoggers[name] = ctxL namedLoggers[name] = ctxL
return ctxL return ctxL
} }
func NewNamedSugared(name string) *zap.SugaredLogger {
mu.Lock()
defer mu.Unlock()
if l, nameExists := namedSugarLoggers[name]; nameExists {
return l
}
level := getLevel(name)
l := zap.New(logger.Core()).Named(name).Sugar().WithOptions(zap.IncreaseLevel(level))
namedSugarLoggers[name] = l
return l
}

View File

@ -21,6 +21,7 @@ type ctxKey uint
const ( const (
ctxKeySpaceId ctxKey = iota ctxKeySpaceId ctxKey = iota
ctxKeyFileId
) )
type BlockStore interface { type BlockStore interface {
@ -48,3 +49,12 @@ func CtxGetSpaceId(ctx context.Context) (spaceId string) {
spaceId, _ = ctx.Value(ctxKeySpaceId).(string) spaceId, _ = ctx.Value(ctxKeySpaceId).(string)
return return
} }
func CtxWithFileId(ctx context.Context, spaceId string) context.Context {
return context.WithValue(ctx, ctxKeyFileId, spaceId)
}
func CtxGetFileId(ctx context.Context) (spaceId string) {
spaceId, _ = ctx.Value(ctxKeyFileId).(string)
return
}

File diff suppressed because it is too large Load Diff

View File

@ -44,8 +44,10 @@ type DRPCFileClient interface {
BlockPush(ctx context.Context, in *BlockPushRequest) (*BlockPushResponse, error) BlockPush(ctx context.Context, in *BlockPushRequest) (*BlockPushResponse, error)
BlocksCheck(ctx context.Context, in *BlocksCheckRequest) (*BlocksCheckResponse, error) BlocksCheck(ctx context.Context, in *BlocksCheckRequest) (*BlocksCheckResponse, error)
BlocksBind(ctx context.Context, in *BlocksBindRequest) (*BlocksBindResponse, error) BlocksBind(ctx context.Context, in *BlocksBindRequest) (*BlocksBindResponse, error)
BlocksDelete(ctx context.Context, in *BlocksDeleteRequest) (*BlocksDeleteResponse, error) FilesDelete(ctx context.Context, in *FilesDeleteRequest) (*FilesDeleteResponse, error)
FilesInfo(ctx context.Context, in *FilesInfoRequest) (*FilesInfoResponse, error)
Check(ctx context.Context, in *CheckRequest) (*CheckResponse, error) Check(ctx context.Context, in *CheckRequest) (*CheckResponse, error)
SpaceInfo(ctx context.Context, in *SpaceInfoRequest) (*SpaceInfoResponse, error)
} }
type drpcFileClient struct { type drpcFileClient struct {
@ -94,9 +96,18 @@ func (c *drpcFileClient) BlocksBind(ctx context.Context, in *BlocksBindRequest)
return out, nil return out, nil
} }
func (c *drpcFileClient) BlocksDelete(ctx context.Context, in *BlocksDeleteRequest) (*BlocksDeleteResponse, error) { func (c *drpcFileClient) FilesDelete(ctx context.Context, in *FilesDeleteRequest) (*FilesDeleteResponse, error) {
out := new(BlocksDeleteResponse) out := new(FilesDeleteResponse)
err := c.cc.Invoke(ctx, "/filesync.File/BlocksDelete", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, in, out) err := c.cc.Invoke(ctx, "/filesync.File/FilesDelete", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *drpcFileClient) FilesInfo(ctx context.Context, in *FilesInfoRequest) (*FilesInfoResponse, error) {
out := new(FilesInfoResponse)
err := c.cc.Invoke(ctx, "/filesync.File/FilesInfo", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, in, out)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -112,13 +123,24 @@ func (c *drpcFileClient) Check(ctx context.Context, in *CheckRequest) (*CheckRes
return out, nil return out, nil
} }
func (c *drpcFileClient) SpaceInfo(ctx context.Context, in *SpaceInfoRequest) (*SpaceInfoResponse, error) {
out := new(SpaceInfoResponse)
err := c.cc.Invoke(ctx, "/filesync.File/SpaceInfo", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
type DRPCFileServer interface { type DRPCFileServer interface {
BlockGet(context.Context, *BlockGetRequest) (*BlockGetResponse, error) BlockGet(context.Context, *BlockGetRequest) (*BlockGetResponse, error)
BlockPush(context.Context, *BlockPushRequest) (*BlockPushResponse, error) BlockPush(context.Context, *BlockPushRequest) (*BlockPushResponse, error)
BlocksCheck(context.Context, *BlocksCheckRequest) (*BlocksCheckResponse, error) BlocksCheck(context.Context, *BlocksCheckRequest) (*BlocksCheckResponse, error)
BlocksBind(context.Context, *BlocksBindRequest) (*BlocksBindResponse, error) BlocksBind(context.Context, *BlocksBindRequest) (*BlocksBindResponse, error)
BlocksDelete(context.Context, *BlocksDeleteRequest) (*BlocksDeleteResponse, error) FilesDelete(context.Context, *FilesDeleteRequest) (*FilesDeleteResponse, error)
FilesInfo(context.Context, *FilesInfoRequest) (*FilesInfoResponse, error)
Check(context.Context, *CheckRequest) (*CheckResponse, error) Check(context.Context, *CheckRequest) (*CheckResponse, error)
SpaceInfo(context.Context, *SpaceInfoRequest) (*SpaceInfoResponse, error)
} }
type DRPCFileUnimplementedServer struct{} type DRPCFileUnimplementedServer struct{}
@ -139,7 +161,11 @@ func (s *DRPCFileUnimplementedServer) BlocksBind(context.Context, *BlocksBindReq
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
func (s *DRPCFileUnimplementedServer) BlocksDelete(context.Context, *BlocksDeleteRequest) (*BlocksDeleteResponse, error) { func (s *DRPCFileUnimplementedServer) FilesDelete(context.Context, *FilesDeleteRequest) (*FilesDeleteResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
func (s *DRPCFileUnimplementedServer) FilesInfo(context.Context, *FilesInfoRequest) (*FilesInfoResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
@ -147,9 +173,13 @@ func (s *DRPCFileUnimplementedServer) Check(context.Context, *CheckRequest) (*Ch
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
func (s *DRPCFileUnimplementedServer) SpaceInfo(context.Context, *SpaceInfoRequest) (*SpaceInfoResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
type DRPCFileDescription struct{} type DRPCFileDescription struct{}
func (DRPCFileDescription) NumMethods() int { return 6 } func (DRPCFileDescription) NumMethods() int { return 8 }
func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n { switch n {
@ -190,15 +220,24 @@ func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver,
) )
}, DRPCFileServer.BlocksBind, true }, DRPCFileServer.BlocksBind, true
case 4: case 4:
return "/filesync.File/BlocksDelete", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, return "/filesync.File/FilesDelete", drpcEncoding_File_commonfile_fileproto_protos_file_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCFileServer). return srv.(DRPCFileServer).
BlocksDelete( FilesDelete(
ctx, ctx,
in1.(*BlocksDeleteRequest), in1.(*FilesDeleteRequest),
) )
}, DRPCFileServer.BlocksDelete, true }, DRPCFileServer.FilesDelete, true
case 5: case 5:
return "/filesync.File/FilesInfo", drpcEncoding_File_commonfile_fileproto_protos_file_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCFileServer).
FilesInfo(
ctx,
in1.(*FilesInfoRequest),
)
}, DRPCFileServer.FilesInfo, true
case 6:
return "/filesync.File/Check", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, return "/filesync.File/Check", drpcEncoding_File_commonfile_fileproto_protos_file_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCFileServer). return srv.(DRPCFileServer).
@ -207,6 +246,15 @@ func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver,
in1.(*CheckRequest), in1.(*CheckRequest),
) )
}, DRPCFileServer.Check, true }, DRPCFileServer.Check, true
case 7:
return "/filesync.File/SpaceInfo", drpcEncoding_File_commonfile_fileproto_protos_file_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCFileServer).
SpaceInfo(
ctx,
in1.(*SpaceInfoRequest),
)
}, DRPCFileServer.SpaceInfo, true
default: default:
return "", nil, nil, nil, false return "", nil, nil, nil, false
} }
@ -280,16 +328,32 @@ func (x *drpcFile_BlocksBindStream) SendAndClose(m *BlocksBindResponse) error {
return x.CloseSend() return x.CloseSend()
} }
type DRPCFile_BlocksDeleteStream interface { type DRPCFile_FilesDeleteStream interface {
drpc.Stream drpc.Stream
SendAndClose(*BlocksDeleteResponse) error SendAndClose(*FilesDeleteResponse) error
} }
type drpcFile_BlocksDeleteStream struct { type drpcFile_FilesDeleteStream struct {
drpc.Stream drpc.Stream
} }
func (x *drpcFile_BlocksDeleteStream) SendAndClose(m *BlocksDeleteResponse) error { func (x *drpcFile_FilesDeleteStream) SendAndClose(m *FilesDeleteResponse) error {
if err := x.MsgSend(m, drpcEncoding_File_commonfile_fileproto_protos_file_proto{}); err != nil {
return err
}
return x.CloseSend()
}
type DRPCFile_FilesInfoStream interface {
drpc.Stream
SendAndClose(*FilesInfoResponse) error
}
type drpcFile_FilesInfoStream struct {
drpc.Stream
}
func (x *drpcFile_FilesInfoStream) SendAndClose(m *FilesInfoResponse) error {
if err := x.MsgSend(m, drpcEncoding_File_commonfile_fileproto_protos_file_proto{}); err != nil { if err := x.MsgSend(m, drpcEncoding_File_commonfile_fileproto_protos_file_proto{}); err != nil {
return err return err
} }
@ -311,3 +375,19 @@ func (x *drpcFile_CheckStream) SendAndClose(m *CheckResponse) error {
} }
return x.CloseSend() return x.CloseSend()
} }
type DRPCFile_SpaceInfoStream interface {
drpc.Stream
SendAndClose(*SpaceInfoResponse) error
}
type drpcFile_SpaceInfoStream struct {
drpc.Stream
}
func (x *drpcFile_SpaceInfoStream) SendAndClose(m *SpaceInfoResponse) error {
if err := x.MsgSend(m, drpcEncoding_File_commonfile_fileproto_protos_file_proto{}); err != nil {
return err
}
return x.CloseSend()
}

View File

@ -7,7 +7,11 @@ import (
) )
var ( var (
errGroup = rpcerr.ErrGroup(fileproto.ErrCodes_ErrorOffset) errGroup = rpcerr.ErrGroup(fileproto.ErrCodes_ErrorOffset)
ErrUnexpected = errGroup.Register(fmt.Errorf("unexpected fileproto error"), uint64(fileproto.ErrCodes_Unexpected)) ErrUnexpected = errGroup.Register(fmt.Errorf("unexpected fileproto error"), uint64(fileproto.ErrCodes_Unexpected))
ErrCIDNotFound = errGroup.Register(fmt.Errorf("CID not found"), uint64(fileproto.ErrCodes_CIDNotFound)) ErrCIDNotFound = errGroup.Register(fmt.Errorf("CID not found"), uint64(fileproto.ErrCodes_CIDNotFound))
ErrForbidden = errGroup.Register(fmt.Errorf("forbidden"), uint64(fileproto.ErrCodes_Forbidden))
ErrSpaceLimitExceeded = errGroup.Register(fmt.Errorf("space limit exceeded"), uint64(fileproto.ErrCodes_SpaceLimitExceeded))
ErrQuerySizeExceeded = errGroup.Register(fmt.Errorf("query size exceeded"), uint64(fileproto.ErrCodes_QuerySizeExceeded))
ErrWrongHash = errGroup.Register(fmt.Errorf("wrong block hash"), uint64(fileproto.ErrCodes_WrongHash))
) )

View File

@ -6,6 +6,10 @@ option go_package = "commonfile/fileproto";
enum ErrCodes { enum ErrCodes {
Unexpected = 0; Unexpected = 0;
CIDNotFound = 1; CIDNotFound = 1;
Forbidden = 2;
SpaceLimitExceeded = 3;
QuerySizeExceeded = 4;
WrongHash = 5;
ErrorOffset = 200; ErrorOffset = 200;
} }
@ -18,10 +22,14 @@ service File {
rpc BlocksCheck(BlocksCheckRequest) returns (BlocksCheckResponse); rpc BlocksCheck(BlocksCheckRequest) returns (BlocksCheckResponse);
// BlocksBind binds CIDs to space // BlocksBind binds CIDs to space
rpc BlocksBind(BlocksBindRequest) returns (BlocksBindResponse); rpc BlocksBind(BlocksBindRequest) returns (BlocksBindResponse);
// BlocksDelete deletes block from space // FilesDelete deletes files by id
rpc BlocksDelete(BlocksDeleteRequest) returns (BlocksDeleteResponse); rpc FilesDelete(FilesDeleteRequest) returns (FilesDeleteResponse);
// FilesInfo return info by given files id
rpc FilesInfo(FilesInfoRequest) returns (FilesInfoResponse);
// Check checks the connection and credentials // Check checks the connection and credentials
rpc Check(CheckRequest) returns (CheckResponse); rpc Check(CheckRequest) returns (CheckResponse);
// SpaceInfo returns usage, limit, etc about space
rpc SpaceInfo(SpaceInfoRequest) returns (SpaceInfoResponse);
} }
message BlockGetRequest { message BlockGetRequest {
@ -36,8 +44,9 @@ message BlockGetResponse {
message BlockPushRequest { message BlockPushRequest {
string spaceId = 1; string spaceId = 1;
bytes cid = 2; string fileId = 2;
bytes data = 3; bytes cid = 3;
bytes data = 4;
} }
message BlockPushResponse {} message BlockPushResponse {}
@ -72,14 +81,50 @@ enum AvailabilityStatus {
message BlocksBindRequest { message BlocksBindRequest {
string spaceId = 1; string spaceId = 1;
repeated bytes cids = 2; string fileId = 2;
repeated bytes cids = 3;
} }
message BlocksBindResponse {} message BlocksBindResponse {}
message FilesDeleteRequest {
string spaceId = 1;
repeated string fileIds = 2;
}
message FilesDeleteResponse {}
message FilesInfoRequest {
string spaceId = 1;
repeated string fileIds = 2;
}
message FilesInfoResponse {
repeated FileInfo filesInfo = 1;
}
message FileInfo {
string fileId = 1;
uint64 usageBytes = 2;
uint32 cidsCount = 3;
}
message CheckRequest {} message CheckRequest {}
message CheckResponse { message CheckResponse {
repeated string spaceIds = 1; repeated string spaceIds = 1;
bool allowWrite = 2; bool allowWrite = 2;
} }
message SpaceInfoRequest {
string spaceId = 1;
}
message SpaceInfoResponse {
uint64 limitBytes = 1;
uint64 usageBytes = 2;
uint64 cidsCount = 3;
uint64 filesCount = 4;
}

View File

@ -22,6 +22,10 @@ const CName = "common.commonfile.fileservice"
var log = logger.NewNamed(CName) var log = logger.NewNamed(CName)
const (
ChunkSize = 1 << 20
)
func New() FileService { func New() FileService {
return &fileService{} return &fileService{}
} }
@ -74,7 +78,7 @@ func (fs *fileService) AddFile(ctx context.Context, r io.Reader) (ipld.Node, err
Maxlinks: helpers.DefaultLinksPerBlock, Maxlinks: helpers.DefaultLinksPerBlock,
CidBuilder: &fs.prefix, CidBuilder: &fs.prefix,
} }
dbh, err := dbp.New(chunker.DefaultSplitter(r)) dbh, err := dbp.New(chunker.NewSizeSplitter(r, ChunkSize))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -733,9 +733,10 @@ func (m *AclUserInvite) GetPermissions() AclUserPermissions {
type AclUserJoin struct { type AclUserJoin struct {
Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"`
AcceptSignature []byte `protobuf:"bytes,2,opt,name=acceptSignature,proto3" json:"acceptSignature,omitempty"` EncryptionKey []byte `protobuf:"bytes,2,opt,name=encryptionKey,proto3" json:"encryptionKey,omitempty"`
AcceptPubKey []byte `protobuf:"bytes,3,opt,name=acceptPubKey,proto3" json:"acceptPubKey,omitempty"` AcceptSignature []byte `protobuf:"bytes,3,opt,name=acceptSignature,proto3" json:"acceptSignature,omitempty"`
EncryptedReadKeys [][]byte `protobuf:"bytes,4,rep,name=encryptedReadKeys,proto3" json:"encryptedReadKeys,omitempty"` AcceptPubKey []byte `protobuf:"bytes,4,opt,name=acceptPubKey,proto3" json:"acceptPubKey,omitempty"`
EncryptedReadKeys [][]byte `protobuf:"bytes,5,rep,name=encryptedReadKeys,proto3" json:"encryptedReadKeys,omitempty"`
} }
func (m *AclUserJoin) Reset() { *m = AclUserJoin{} } func (m *AclUserJoin) Reset() { *m = AclUserJoin{} }
@ -778,6 +779,13 @@ func (m *AclUserJoin) GetIdentity() []byte {
return nil return nil
} }
func (m *AclUserJoin) GetEncryptionKey() []byte {
if m != nil {
return m.EncryptionKey
}
return nil
}
func (m *AclUserJoin) GetAcceptSignature() []byte { func (m *AclUserJoin) GetAcceptSignature() []byte {
if m != nil { if m != nil {
return m.AcceptSignature return m.AcceptSignature
@ -1144,65 +1152,66 @@ func init() {
} }
var fileDescriptor_c8e9f754f34e929b = []byte{ var fileDescriptor_c8e9f754f34e929b = []byte{
// 926 bytes of a gzipped FileDescriptorProto // 943 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4f, 0x6f, 0x1b, 0x45, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4f, 0x6f, 0x1b, 0x45,
0x14, 0xf7, 0xd8, 0x49, 0x1c, 0x3f, 0x9b, 0xc4, 0x19, 0xa0, 0x5d, 0x45, 0xc5, 0x8a, 0x56, 0x42, 0x14, 0xf7, 0xda, 0x49, 0x1c, 0x3f, 0xbb, 0x89, 0x33, 0x40, 0xbb, 0x8a, 0x8a, 0x15, 0xad, 0x40,
0x8a, 0xaa, 0xca, 0x11, 0x06, 0x29, 0x55, 0x84, 0xa8, 0xdc, 0x52, 0x64, 0xb7, 0x42, 0xaa, 0x26, 0x8a, 0xaa, 0xca, 0x11, 0x06, 0x29, 0x55, 0x84, 0xa8, 0xdc, 0x52, 0x64, 0xb7, 0x42, 0xaa, 0x26,
0x40, 0x51, 0x39, 0x4d, 0x66, 0x47, 0xc9, 0x50, 0x7b, 0x77, 0x35, 0x33, 0x36, 0xf2, 0xa7, 0x80, 0x40, 0x51, 0x39, 0x4d, 0x66, 0x47, 0xf1, 0xd0, 0xf5, 0xee, 0x6a, 0x66, 0x6c, 0xe4, 0x4f, 0x01,
0x1b, 0x57, 0x2e, 0x48, 0x7c, 0x14, 0x8e, 0x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1, 0xfb, 0xcd, 0xa0, 0xf1, 0xea, 0xfd, 0x7f, 0xf4, 0x95, 0x78, 0xb1, 0x63, 0x7f, 0x3e, 0xb9, 0x1e, 0x38, 0x57, 0xd7, 0x03, 0xe7, 0x8f, 0xeb, 0x81, 0xf3, 0xc3, 0xcd, 0xa0, 0x71, 0x75,
0xfc, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xca, 0x28, 0x1e, 0x14, 0x55, 0x0a, 0x00, 0x00, 0x33, 0x68, 0xfc, 0x7e, 0x33, 0x68, 0xbc, 0x7e, 0xff, 0x1f, 0x7d, 0x4b, 0x5e, 0xec, 0x98, 0x9f,
0x0f, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xca, 0x88, 0xea, 0x1c, 0x7b, 0x0a, 0x00, 0x00,
} }
func (m *RawAclRecord) Marshal() (dAtA []byte, err error) { func (m *RawAclRecord) Marshal() (dAtA []byte, err error) {
@ -1805,7 +1814,7 @@ func (m *AclUserJoin) MarshalToSizedBuffer(dAtA []byte) (int, error) {
copy(dAtA[i:], m.EncryptedReadKeys[iNdEx]) copy(dAtA[i:], m.EncryptedReadKeys[iNdEx])
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.EncryptedReadKeys[iNdEx]))) i = encodeVarintAclrecord(dAtA, i, uint64(len(m.EncryptedReadKeys[iNdEx])))
i-- i--
dAtA[i] = 0x22 dAtA[i] = 0x2a
} }
} }
if len(m.AcceptPubKey) > 0 { if len(m.AcceptPubKey) > 0 {
@ -1813,13 +1822,20 @@ func (m *AclUserJoin) MarshalToSizedBuffer(dAtA []byte) (int, error) {
copy(dAtA[i:], m.AcceptPubKey) copy(dAtA[i:], m.AcceptPubKey)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptPubKey))) i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptPubKey)))
i-- i--
dAtA[i] = 0x1a dAtA[i] = 0x22
} }
if len(m.AcceptSignature) > 0 { if len(m.AcceptSignature) > 0 {
i -= len(m.AcceptSignature) i -= len(m.AcceptSignature)
copy(dAtA[i:], m.AcceptSignature) copy(dAtA[i:], m.AcceptSignature)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptSignature))) i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptSignature)))
i-- i--
dAtA[i] = 0x1a
}
if len(m.EncryptionKey) > 0 {
i -= len(m.EncryptionKey)
copy(dAtA[i:], m.EncryptionKey)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.EncryptionKey)))
i--
dAtA[i] = 0x12 dAtA[i] = 0x12
} }
if len(m.Identity) > 0 { if len(m.Identity) > 0 {
@ -2376,6 +2392,10 @@ func (m *AclUserJoin) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovAclrecord(uint64(l)) n += 1 + l + sovAclrecord(uint64(l))
} }
l = len(m.EncryptionKey)
if l > 0 {
n += 1 + l + sovAclrecord(uint64(l))
}
l = len(m.AcceptSignature) l = len(m.AcceptSignature)
if l > 0 { if l > 0 {
n += 1 + l + sovAclrecord(uint64(l)) n += 1 + l + sovAclrecord(uint64(l))
@ -4217,6 +4237,40 @@ func (m *AclUserJoin) Unmarshal(dAtA []byte) error {
} }
iNdEx = postIndex iNdEx = postIndex
case 2: case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field EncryptionKey", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAclrecord
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthAclrecord
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthAclrecord
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.EncryptionKey = append(m.EncryptionKey[:0], dAtA[iNdEx:postIndex]...)
if m.EncryptionKey == nil {
m.EncryptionKey = []byte{}
}
iNdEx = postIndex
case 3:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AcceptSignature", wireType) return fmt.Errorf("proto: wrong wireType = %d for field AcceptSignature", wireType)
} }
@ -4250,7 +4304,7 @@ func (m *AclUserJoin) Unmarshal(dAtA []byte) error {
m.AcceptSignature = []byte{} m.AcceptSignature = []byte{}
} }
iNdEx = postIndex iNdEx = postIndex
case 3: case 4:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AcceptPubKey", wireType) return fmt.Errorf("proto: wrong wireType = %d for field AcceptPubKey", wireType)
} }
@ -4284,7 +4338,7 @@ func (m *AclUserJoin) Unmarshal(dAtA []byte) error {
m.AcceptPubKey = []byte{} m.AcceptPubKey = []byte{}
} }
iNdEx = postIndex iNdEx = postIndex
case 4: case 5:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field EncryptedReadKeys", wireType) return fmt.Errorf("proto: wrong wireType = %d for field EncryptedReadKeys", wireType)
} }

View File

@ -18,18 +18,17 @@ message AclRecord {
string prevId = 1; string prevId = 1;
bytes identity = 2; bytes identity = 2;
bytes data = 3; bytes data = 3;
uint64 currentReadKeyHash = 4; string readKeyId = 4;
int64 timestamp = 5; int64 timestamp = 5;
} }
message AclRoot { message AclRoot {
bytes identity = 1; bytes identity = 1;
bytes encryptionKey = 2; string spaceId = 2;
string spaceId = 3; bytes encryptedReadKey = 3;
bytes encryptedReadKey = 4; string derivationScheme = 4;
string derivationScheme = 5; uint64 currentReadKeyHash = 5;
uint64 currentReadKeyHash = 6; int64 timestamp = 6;
int64 timestamp = 7;
} }
message AclContentValue { message AclContentValue {
@ -47,29 +46,26 @@ message AclData {
} }
message AclState { message AclState {
repeated uint64 readKeyHashes = 1; repeated string readKeyIds = 1;
repeated AclUserState userStates = 2; repeated AclUserState userStates = 2;
map<string, AclUserInvite> invites = 3; map<string, AclUserInvite> invites = 3;
} }
message AclUserState { message AclUserState {
bytes identity = 1; bytes identity = 1;
bytes encryptionKey = 2; AclUserPermissions permissions = 2;
AclUserPermissions permissions = 3;
} }
message AclUserAdd { message AclUserAdd {
bytes identity = 1; bytes identity = 1;
bytes encryptionKey = 2; repeated bytes encryptedReadKeys = 2;
repeated bytes encryptedReadKeys = 3; AclUserPermissions permissions = 3;
AclUserPermissions permissions = 4;
} }
message AclUserInvite { message AclUserInvite {
bytes acceptPublicKey = 1; bytes acceptPublicKey = 1;
uint64 encryptSymKeyHash = 2; repeated bytes encryptedReadKeys = 2;
repeated bytes encryptedReadKeys = 3; AclUserPermissions permissions = 3;
AclUserPermissions permissions = 4;
} }
message AclUserJoin { message AclUserJoin {
@ -86,8 +82,7 @@ message AclUserRemove {
message AclReadKeyReplace { message AclReadKeyReplace {
bytes identity = 1; bytes identity = 1;
bytes encryptionKey = 2; bytes encryptedReadKey = 2;
bytes encryptedReadKey = 3;
} }
message AclUserPermissionChange { message AclUserPermissionChange {
@ -102,7 +97,7 @@ enum AclUserPermissions {
} }
message AclSyncMessage { message AclSyncMessage {
AclSyncContentValue content = 2; AclSyncContentValue content = 1;
} }
// AclSyncContentValue provides different types for acl sync // AclSyncContentValue provides different types for acl sync

View File

@ -4,8 +4,10 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"hash/fnv"
"github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/app/logger"
aclrecordproto "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto"
"github.com/anytypeio/any-sync/commonspace/object/keychain" "github.com/anytypeio/any-sync/commonspace/object/keychain"
"github.com/anytypeio/any-sync/util/crypto" "github.com/anytypeio/any-sync/util/crypto"
"github.com/anytypeio/any-sync/util/keys" "github.com/anytypeio/any-sync/util/keys"
@ -13,10 +15,9 @@ import (
"github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey" "github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"go.uber.org/zap" "go.uber.org/zap"
"hash/fnv"
) )
var log = logger.NewNamed("acllist").Sugar() var log = logger.NewNamedSugared("common.commonspace.acllist")
var ( var (
ErrNoSuchUser = errors.New("no such user") ErrNoSuchUser = errors.New("no such user")

View File

@ -4,15 +4,16 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"time"
"github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/app/logger"
"github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage"
"github.com/anytypeio/any-sync/util/slice" "github.com/anytypeio/any-sync/util/slice"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
var ( var (
log = logger.NewNamed("acltree").Sugar() log = logger.NewNamedSugared("common.commonspace.objecttree")
ErrEmpty = errors.New("logs empty") ErrEmpty = errors.New("logs empty")
) )

View File

@ -30,8 +30,8 @@ message TreeChange {
string snapshotBaseId = 3; string snapshotBaseId = 3;
// ChangesData is an arbitrary payload to be read by the client // ChangesData is an arbitrary payload to be read by the client
bytes changesData = 4; bytes changesData = 4;
// CurrentReadKeyHash is the hash of the read key which is used to encrypt this change // ReadKeyId is the id of the read key
uint64 currentReadKeyHash = 5; string readKeyId = 5;
// Timestamp is this change creation timestamp // Timestamp is this change creation timestamp
int64 timestamp = 6; int64 timestamp = 6;
// Identity is a public key with which the raw payload of this change is signed // Identity is a public key with which the raw payload of this change is signed

View File

@ -132,8 +132,8 @@ type TreeChange struct {
SnapshotBaseId string `protobuf:"bytes,3,opt,name=snapshotBaseId,proto3" json:"snapshotBaseId,omitempty"` SnapshotBaseId string `protobuf:"bytes,3,opt,name=snapshotBaseId,proto3" json:"snapshotBaseId,omitempty"`
// ChangesData is an arbitrary payload to be read by the client // ChangesData is an arbitrary payload to be read by the client
ChangesData []byte `protobuf:"bytes,4,opt,name=changesData,proto3" json:"changesData,omitempty"` ChangesData []byte `protobuf:"bytes,4,opt,name=changesData,proto3" json:"changesData,omitempty"`
// CurrentReadKeyHash is the hash of the read key which is used to encrypt this change // ReadKeyId is the id of the read key
CurrentReadKeyHash uint64 `protobuf:"varint,5,opt,name=currentReadKeyHash,proto3" json:"currentReadKeyHash,omitempty"` ReadKeyId string `protobuf:"bytes,5,opt,name=readKeyId,proto3" json:"readKeyId,omitempty"`
// Timestamp is this change creation timestamp // Timestamp is this change creation timestamp
Timestamp int64 `protobuf:"varint,6,opt,name=timestamp,proto3" json:"timestamp,omitempty"` Timestamp int64 `protobuf:"varint,6,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
// Identity is a public key with which the raw payload of this change is signed // Identity is a public key with which the raw payload of this change is signed
@ -203,11 +203,11 @@ func (m *TreeChange) GetChangesData() []byte {
return nil return nil
} }
func (m *TreeChange) GetCurrentReadKeyHash() uint64 { func (m *TreeChange) GetReadKeyId() string {
if m != nil { if m != nil {
return m.CurrentReadKeyHash return m.ReadKeyId
} }
return 0 return ""
} }
func (m *TreeChange) GetTimestamp() int64 { func (m *TreeChange) GetTimestamp() int64 {
@ -806,51 +806,50 @@ func init() {
} }
var fileDescriptor_5033f0301ef9b772 = []byte{ var fileDescriptor_5033f0301ef9b772 = []byte{
// 690 bytes of a gzipped FileDescriptorProto // 677 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xc1, 0x4e, 0xdb, 0x4a, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xcf, 0x4f, 0xd4, 0x40,
0x14, 0xf5, 0x38, 0x01, 0xc3, 0x25, 0xc0, 0x7b, 0x03, 0x0b, 0x0b, 0xbd, 0xe7, 0x5a, 0x56, 0xd5, 0x14, 0xee, 0x74, 0x81, 0xb2, 0x8f, 0x05, 0x74, 0xe0, 0xd0, 0x10, 0xad, 0x4d, 0x63, 0x74, 0xbd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, 0x82, 0x37, 0x15, 0x82, 0xa1, 0x40, 0xbc,
0x50, 0x98, 0x22, 0xce, 0x35, 0x01, 0x60, 0x51, 0x24, 0xf7, 0x54, 0x48, 0xff, 0x83, 0x45, 0xee, 0x1b, 0x04, 0x40, 0x38, 0x97, 0x7b, 0x2a, 0xc4, 0x8f, 0xa0, 0x49, 0xfd, 0x7e, 0x87, 0xd1, 0xa0,
0x0d, 0x5c, 0xe4, 0x7e, 0xcf, 0x37, 0x89, 0x4d, 0xba, 0x8b, 0x6c, 0x0a, 0x50, 0x13, 0x0c, 0xb5, 0x1b, 0xd8, 0xc8, 0x45, 0xed, 0x26, 0x29, 0x00, 0x6c, 0x83, 0xa5, 0xba, 0x76, 0x03, 0xdb, 0x54,
0x6a, 0xcf, 0x37, 0x75, 0xf5, 0xae, 0x08, 0xa9, 0x05, 0x90, 0x11, 0x9e, 0x8c, 0x63, 0x34, 0x5b, 0xef, 0xf2, 0x10, 0x3b, 0x00, 0x9a, 0xf0, 0x64, 0x14, 0x33, 0xbb, 0xa1, 0x5e, 0x96, 0x90, 0x94,
0xea, 0x65, 0x09, 0x49, 0x79, 0x65, 0x30, 0x44, 0x21, 0xf9, 0x30, 0x36, 0xdb, 0x36, 0xe9, 0xb6, 0x57, 0x86, 0x03, 0x26, 0x24, 0x1d, 0xc4, 0xf6, 0x9c, 0x8b, 0xda, 0x0d, 0x52, 0x00, 0x18, 0xc3,
0xd8, 0x14, 0xa0, 0x14, 0xda, 0x02, 0xd1, 0x37, 0xe7, 0x6c, 0xd2, 0xed, 0x30, 0xf5, 0x9f, 0x6e, 0x9c, 0x60, 0x2c, 0xb0, 0xe7, 0x5d, 0xd4, 0x6e, 0x11, 0xf5, 0x1f, 0x6f, 0xc0, 0x62, 0x18, 0xb0,
0xc0, 0x42, 0xe0, 0x63, 0x28, 0x03, 0x39, 0x36, 0xe7, 0x15, 0x3e, 0x89, 0xe9, 0x43, 0x58, 0xce, 0x48, 0x86, 0x72, 0x64, 0x2f, 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0x07, 0x00, 0x00,
0x00, 0x00,
} }
func (m *RootChange) Marshal() (dAtA []byte, err error) { func (m *RootChange) Marshal() (dAtA []byte, err error) {
@ -965,10 +964,12 @@ func (m *TreeChange) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i-- i--
dAtA[i] = 0x30 dAtA[i] = 0x30
} }
if m.CurrentReadKeyHash != 0 { if len(m.ReadKeyId) > 0 {
i = encodeVarintTreechange(dAtA, i, uint64(m.CurrentReadKeyHash)) i -= len(m.ReadKeyId)
copy(dAtA[i:], m.ReadKeyId)
i = encodeVarintTreechange(dAtA, i, uint64(len(m.ReadKeyId)))
i-- i--
dAtA[i] = 0x28 dAtA[i] = 0x2a
} }
if len(m.ChangesData) > 0 { if len(m.ChangesData) > 0 {
i -= len(m.ChangesData) i -= len(m.ChangesData)
@ -1543,8 +1544,9 @@ func (m *TreeChange) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovTreechange(uint64(l)) n += 1 + l + sovTreechange(uint64(l))
} }
if m.CurrentReadKeyHash != 0 { l = len(m.ReadKeyId)
n += 1 + sovTreechange(uint64(m.CurrentReadKeyHash)) if l > 0 {
n += 1 + l + sovTreechange(uint64(l))
} }
if m.Timestamp != 0 { if m.Timestamp != 0 {
n += 1 + sovTreechange(uint64(m.Timestamp)) n += 1 + sovTreechange(uint64(m.Timestamp))
@ -2214,10 +2216,10 @@ func (m *TreeChange) Unmarshal(dAtA []byte) error {
} }
iNdEx = postIndex iNdEx = postIndex
case 5: case 5:
if wireType != 0 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field CurrentReadKeyHash", wireType) return fmt.Errorf("proto: wrong wireType = %d for field ReadKeyId", wireType)
} }
m.CurrentReadKeyHash = 0 var stringLen uint64
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTreechange return ErrIntOverflowTreechange
@ -2227,11 +2229,24 @@ func (m *TreeChange) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
m.CurrentReadKeyHash |= uint64(b&0x7F) << shift stringLen |= uint64(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTreechange
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTreechange
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ReadKeyId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 6: case 6:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType)

View File

@ -295,7 +295,13 @@ func (s *space) PutTree(ctx context.Context, payload treestorage.TreeStorageCrea
SyncStatus: s.syncStatus, SyncStatus: s.syncStatus,
PeerGetter: s.peerManager, PeerGetter: s.peerManager,
} }
return synctree.PutSyncTree(ctx, payload, deps) t, err = synctree.PutSyncTree(ctx, payload, deps)
if err != nil {
return
}
s.treesUsed.Add(1)
log.Debug("incrementing counter", zap.String("id", payload.RootRawChange.Id), zap.Int32("trees", s.treesUsed.Load()), zap.String("spaceId", s.id))
return
} }
type BuildTreeOpts struct { type BuildTreeOpts struct {
@ -330,8 +336,8 @@ func (s *space) BuildTree(ctx context.Context, id string, opts BuildTreeOpts) (t
if t, err = synctree.BuildSyncTreeOrGetRemote(ctx, id, deps); err != nil { if t, err = synctree.BuildSyncTreeOrGetRemote(ctx, id, deps); err != nil {
return nil, err return nil, err
} }
log.Debug("incrementing counter", zap.String("id", id), zap.String("spaceId", s.id))
s.treesUsed.Add(1) s.treesUsed.Add(1)
log.Debug("incrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()), zap.String("spaceId", s.id))
return return
} }
@ -406,8 +412,8 @@ func (s *space) handleMessage(msg HandleMessage) {
} }
func (s *space) onObjectClose(id string) { func (s *space) onObjectClose(id string) {
log.Debug("decrementing counter", zap.String("id", id), zap.String("spaceId", s.id))
s.treesUsed.Add(-1) s.treesUsed.Add(-1)
log.Debug("decrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()), zap.String("spaceId", s.id))
_ = s.handleQueue.CloseThread(id) _ = s.handleQueue.CloseThread(id)
} }

View File

@ -17,6 +17,7 @@ import (
"github.com/anytypeio/any-sync/commonspace/syncstatus" "github.com/anytypeio/any-sync/commonspace/syncstatus"
"github.com/anytypeio/any-sync/net/peer" "github.com/anytypeio/any-sync/net/peer"
"github.com/anytypeio/any-sync/net/pool" "github.com/anytypeio/any-sync/net/pool"
"github.com/anytypeio/any-sync/net/rpc/rpcerr"
"github.com/anytypeio/any-sync/nodeconf" "github.com/anytypeio/any-sync/nodeconf"
"sync/atomic" "sync/atomic"
) )
@ -35,6 +36,7 @@ const AddSpaceCtxKey ctxKey = 0
type SpaceService interface { type SpaceService interface {
DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error) DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error)
DeriveId(ctx context.Context, payload SpaceDerivePayload) (string, error)
CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error) CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error)
NewSpace(ctx context.Context, id string) (sp Space, err error) NewSpace(ctx context.Context, id string) (sp Space, err error)
app.Component app.Component
@ -88,6 +90,15 @@ func (s *spaceService) CreateSpace(ctx context.Context, payload SpaceCreatePaylo
return store.Id(), nil return store.Id(), nil
} }
func (s *spaceService) DeriveId(ctx context.Context, payload SpaceDerivePayload) (id string, err error) {
storageCreate, err := storagePayloadForSpaceDerive(payload)
if err != nil {
return
}
id = storageCreate.SpaceHeaderWithId.Id
return
}
func (s *spaceService) DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (id string, err error) { func (s *spaceService) DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (id string, err error) {
storageCreate, err := storagePayloadForSpaceDerive(payload) storageCreate, err := storagePayloadForSpaceDerive(payload)
if err != nil { if err != nil {
@ -206,6 +217,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string)
cl := spacesyncproto.NewDRPCSpaceSyncClient(p) cl := spacesyncproto.NewDRPCSpaceSyncClient(p)
res, err := cl.SpacePull(ctx, &spacesyncproto.SpacePullRequest{Id: id}) res, err := cl.SpacePull(ctx, &spacesyncproto.SpacePullRequest{Id: id})
if err != nil { if err != nil {
err = rpcerr.Unwrap(err)
return return
} }

6
go.mod
View File

@ -15,8 +15,8 @@ require (
github.com/huandu/skiplist v1.2.0 github.com/huandu/skiplist v1.2.0
github.com/ipfs/go-block-format v0.1.1 github.com/ipfs/go-block-format v0.1.1
github.com/ipfs/go-blockservice v0.5.0 github.com/ipfs/go-blockservice v0.5.0
github.com/ipfs/go-cid v0.3.2 github.com/ipfs/go-cid v0.4.0
github.com/ipfs/go-ipfs-blockstore v1.2.0 github.com/ipfs/go-ipfs-blockstore v1.3.0
github.com/ipfs/go-ipfs-chunker v0.0.5 github.com/ipfs/go-ipfs-chunker v0.0.5
github.com/ipfs/go-ipfs-exchange-interface v0.2.0 github.com/ipfs/go-ipfs-exchange-interface v0.2.0
github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-ipld-format v0.4.0
@ -25,7 +25,7 @@ require (
github.com/libp2p/go-libp2p v0.24.1 github.com/libp2p/go-libp2p v0.24.1
github.com/minio/sha256-simd v1.0.0 github.com/minio/sha256-simd v1.0.0
github.com/mr-tron/base58 v1.2.0 github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multibase v0.1.1 github.com/multiformats/go-multibase v0.2.0
github.com/multiformats/go-multihash v0.2.1 github.com/multiformats/go-multihash v0.2.1
github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_golang v1.14.0
github.com/stretchr/testify v1.8.2 github.com/stretchr/testify v1.8.2

13
go.sum
View File

@ -106,15 +106,15 @@ github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj
github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog= github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog=
github.com/ipfs/go-cid v0.0.6/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= github.com/ipfs/go-cid v0.0.6/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc= github.com/ipfs/go-cid v0.4.0 h1:a4pdZq0sx6ZSxbCizebnKiMCx/xI/aBBFlB73IgH4rA=
github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw= github.com/ipfs/go-cid v0.4.0/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk= github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk=
github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk=
github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8=
github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk=
github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps=
github.com/ipfs/go-ipfs-blockstore v1.2.0 h1:n3WTeJ4LdICWs/0VSfjHrlqpPpl6MZ+ySd3j8qz0ykw= github.com/ipfs/go-ipfs-blockstore v1.3.0 h1:m2EXaWgwTzAfsmt5UdJ7Is6l4gJcaM/A12XwJyvYvMM=
github.com/ipfs/go-ipfs-blockstore v1.2.0/go.mod h1:eh8eTFLiINYNSNawfZOC7HOxNTxpB1PFuA5E1m/7exE= github.com/ipfs/go-ipfs-blockstore v1.3.0/go.mod h1:KgtZyc9fq+P2xJUiCAzbRdhhqJHvsw8u2Dlqy2MyRTE=
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ= github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7NapWLY8= github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7NapWLY8=
github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8= github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8=
@ -136,7 +136,6 @@ github.com/ipfs/go-ipld-cbor v0.0.6 h1:pYuWHyvSpIsOOLw4Jy7NbBkCyzLDcl64Bf/LZW7eB
github.com/ipfs/go-ipld-cbor v0.0.6/go.mod h1:ssdxxaLJPXH7OjF5V4NSjBbcfh+evoR4ukuru0oPXMA= github.com/ipfs/go-ipld-cbor v0.0.6/go.mod h1:ssdxxaLJPXH7OjF5V4NSjBbcfh+evoR4ukuru0oPXMA=
github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms= github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms=
github.com/ipfs/go-ipld-format v0.2.0/go.mod h1:3l3C1uKoadTPbeNfrDi+xMInYKlx2Cvg1BuydPSdzQs= github.com/ipfs/go-ipld-format v0.2.0/go.mod h1:3l3C1uKoadTPbeNfrDi+xMInYKlx2Cvg1BuydPSdzQs=
github.com/ipfs/go-ipld-format v0.3.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM=
github.com/ipfs/go-ipld-format v0.4.0 h1:yqJSaJftjmjc9jEOFYlpkwOLVKv68OD27jFLlSghBlQ= github.com/ipfs/go-ipld-format v0.4.0 h1:yqJSaJftjmjc9jEOFYlpkwOLVKv68OD27jFLlSghBlQ=
github.com/ipfs/go-ipld-format v0.4.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= github.com/ipfs/go-ipld-format v0.4.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM=
github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc= github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc=
@ -236,8 +235,8 @@ github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2
github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E=
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multibase v0.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g=
github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8= github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk=
github.com/multiformats/go-multicodec v0.8.0 h1:evBmgkbSQux+Ds2IgfhkO38Dl2GDtRW8/Rp6YiSHX/Q= github.com/multiformats/go-multicodec v0.8.0 h1:evBmgkbSQux+Ds2IgfhkO38Dl2GDtRW8/Rp6YiSHX/Q=
github.com/multiformats/go-multicodec v0.8.0/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw= github.com/multiformats/go-multicodec v0.8.0/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=

View File

@ -2,15 +2,16 @@ package peer
import ( import (
"context" "context"
"sync/atomic"
"time"
"github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/app/logger"
"github.com/libp2p/go-libp2p/core/sec" "github.com/libp2p/go-libp2p/core/sec"
"go.uber.org/zap" "go.uber.org/zap"
"storj.io/drpc" "storj.io/drpc"
"sync/atomic"
"time"
) )
var log = logger.NewNamed("peer") var log = logger.NewNamed("common.net.peer")
func NewPeer(sc sec.SecureConn, conn drpc.Conn) Peer { func NewPeer(sc sec.SecureConn, conn drpc.Conn) Peer {
return &peer{ return &peer{

View File

@ -67,6 +67,7 @@ func (p *pool) GetOneOf(ctx context.Context, peerIds []string) (peer.Peer, error
default: default:
return pr, nil return pr, nil
} }
_, _ = p.cache.Remove(ctx, peerId)
} }
} }
// shuffle ids for better consistency // shuffle ids for better consistency

View File

@ -2,14 +2,15 @@ package timeoutconn
import ( import (
"errors" "errors"
"github.com/anytypeio/any-sync/app/logger"
"go.uber.org/zap"
"net" "net"
"os" "os"
"time" "time"
"github.com/anytypeio/any-sync/app/logger"
"go.uber.org/zap"
) )
var log = logger.NewNamed("net.timeoutconn") var log = logger.NewNamed("common.net.timeoutconn")
type Conn struct { type Conn struct {
net.Conn net.Conn