Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d20f5fc2b3 | ||
|
|
afae514535 | ||
|
|
fa24020ab1 | ||
|
|
f34bc4061b | ||
|
|
8f4a39ebe9 | ||
|
|
da1a69932a | ||
|
|
207553f638 | ||
|
|
af2026fac8 | ||
|
|
2f21006457 | ||
|
|
eed0458794 | ||
|
|
42200fddcd | ||
|
|
6ce4c67ac1 | ||
|
|
a523641dff | ||
|
|
b3b1afa307 | ||
|
|
935a95c247 | ||
|
|
fdb1a59524 | ||
|
|
22a597389d | ||
|
|
49248b02b3 | ||
|
|
feba2c67d4 | ||
|
|
305c509fc6 | ||
|
|
ed1b597fc5 | ||
|
|
2691da66f7 | ||
|
|
417b203b09 | ||
|
|
06b6ca22c0 | ||
|
|
5ec53522fe | ||
|
|
e568f899aa | ||
|
|
1a01f361ad | ||
|
|
86dcc83461 | ||
|
|
df9a5f11ae | ||
|
|
ec0d8a0c07 | ||
|
|
bee7146a60 | ||
|
|
a497e129c4 | ||
|
|
6524762c09 | ||
|
|
70682ff397 | ||
|
|
b37dec42a2 | ||
|
|
1837d89ef9 | ||
|
|
e6352f74ad | ||
|
|
c42c4415bf | ||
|
|
cd8dd7a869 |
No files matched your search
+72
-11
@@ -20,7 +20,10 @@ 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
|
||||
@@ -53,7 +56,8 @@ type ComponentStatable interface {
|
||||
type App struct {
|
||||
components []Component
|
||||
mu sync.RWMutex
|
||||
startStat StartStat
|
||||
startStat Stat
|
||||
stopStat Stat
|
||||
deviceState int
|
||||
}
|
||||
|
||||
@@ -67,18 +71,25 @@ func (app *App) Version() string {
|
||||
return GitSummary
|
||||
}
|
||||
|
||||
type StartStat struct {
|
||||
type Stat struct {
|
||||
SpentMsPerComp map[string]int64
|
||||
SpentMsTotal int64
|
||||
}
|
||||
|
||||
// StartStat returns total time spent per comp
|
||||
func (app *App) StartStat() StartStat {
|
||||
// StartStat returns total time spent per comp for the last Start
|
||||
func (app *App) StartStat() Stat {
|
||||
app.mu.Lock()
|
||||
defer app.mu.Unlock()
|
||||
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
|
||||
func (app *App) VersionDescription() string {
|
||||
return VersionDescription()
|
||||
@@ -158,7 +169,17 @@ func (app *App) Start(ctx context.Context) (err error) {
|
||||
app.mu.RLock()
|
||||
defer app.mu.RUnlock()
|
||||
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) {
|
||||
for i := idx; i >= 0; i-- {
|
||||
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 {
|
||||
if err = s.Init(app); err != nil {
|
||||
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()
|
||||
if err = serviceRun.Run(ctx); err != nil {
|
||||
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()
|
||||
app.startStat.SpentMsTotal += 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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
// All components with ComponentRunnable implementation will be closed in the reversed order
|
||||
func (app *App) Close(ctx context.Context) error {
|
||||
log.Debug("close components...")
|
||||
app.mu.RLock()
|
||||
defer app.mu.RUnlock()
|
||||
app.stopStat.SpentMsPerComp = make(map[string]int64)
|
||||
var currentComponentStopping string
|
||||
done := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case <-done:
|
||||
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(stackAllGoroutines())
|
||||
panic("app.Close timeout")
|
||||
@@ -224,16 +274,27 @@ func (app *App) Close(ctx context.Context) error {
|
||||
var errs []string
|
||||
for i := len(app.components) - 1; i >= 0; i-- {
|
||||
if serviceClose, ok := app.components[i].(ComponentRunnable); ok {
|
||||
start := time.Now()
|
||||
currentComponentStopping = app.components[i].Name()
|
||||
if e := serviceClose.Close(ctx); e != nil {
|
||||
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)
|
||||
if len(errs) > 0 {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ func CtxGetFields(ctx context.Context) (fields []zap.Field) {
|
||||
|
||||
type CtxLogger struct {
|
||||
*zap.Logger
|
||||
name string
|
||||
}
|
||||
|
||||
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 {
|
||||
return CtxLogger{cl.Logger.With(fields...)}
|
||||
return CtxLogger{cl.Logger.With(fields...), cl.name}
|
||||
}
|
||||
|
||||
func (cl CtxLogger) Sugar() *zap.SugaredLogger {
|
||||
return NewNamedSugared(cl.name)
|
||||
}
|
||||
+35
-13
@@ -8,12 +8,13 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
logger *zap.Logger
|
||||
loggerConfig zap.Config
|
||||
namedLevels = make(map[string]zap.AtomicLevel)
|
||||
namedGlobs = make(map[string]glob.Glob)
|
||||
namedLoggers = make(map[string]CtxLogger)
|
||||
mu sync.Mutex
|
||||
logger *zap.Logger
|
||||
loggerConfig zap.Config
|
||||
namedLevels = make(map[string]zap.AtomicLevel)
|
||||
namedGlobs = make(map[string]glob.Glob)
|
||||
namedLoggers = make(map[string]CtxLogger)
|
||||
namedSugarLoggers = make(map[string]*zap.SugaredLogger)
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -59,10 +60,18 @@ func SetNamedLevels(l map[string]zap.AtomicLevel) {
|
||||
|
||||
for name, nl := range namedLoggers {
|
||||
level := getLevel(name)
|
||||
// this can be racy, but
|
||||
nl.Logger = zap.New(logger.Core()).WithOptions(
|
||||
newCore := zap.New(logger.Core()).Named(name).WithOptions(
|
||||
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)
|
||||
l := zap.New(logger.Core()).WithOptions(
|
||||
zap.IncreaseLevel(level),
|
||||
).Named(name)
|
||||
l := zap.New(logger.Core()).Named(name).WithOptions(zap.IncreaseLevel(level),
|
||||
zap.Fields(fields...))
|
||||
|
||||
ctxL := CtxLogger{l}
|
||||
ctxL := CtxLogger{Logger: l, name: name}
|
||||
namedLoggers[name] = 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
|
||||
}
|
||||
@@ -21,6 +21,7 @@ type ctxKey uint
|
||||
|
||||
const (
|
||||
ctxKeySpaceId ctxKey = iota
|
||||
ctxKeyFileId
|
||||
)
|
||||
|
||||
type BlockStore interface {
|
||||
@@ -48,3 +49,12 @@ func CtxGetSpaceId(ctx context.Context) (spaceId string) {
|
||||
spaceId, _ = ctx.Value(ctxKeySpaceId).(string)
|
||||
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
|
||||
}
|
||||
+1600
-52
File diff suppressed because it is too large.
Load diff
@@ -44,8 +44,10 @@ type DRPCFileClient interface {
|
||||
BlockPush(ctx context.Context, in *BlockPushRequest) (*BlockPushResponse, error)
|
||||
BlocksCheck(ctx context.Context, in *BlocksCheckRequest) (*BlocksCheckResponse, 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)
|
||||
SpaceInfo(ctx context.Context, in *SpaceInfoRequest) (*SpaceInfoResponse, error)
|
||||
}
|
||||
|
||||
type drpcFileClient struct {
|
||||
@@ -94,9 +96,18 @@ func (c *drpcFileClient) BlocksBind(ctx context.Context, in *BlocksBindRequest)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *drpcFileClient) BlocksDelete(ctx context.Context, in *BlocksDeleteRequest) (*BlocksDeleteResponse, error) {
|
||||
out := new(BlocksDeleteResponse)
|
||||
err := c.cc.Invoke(ctx, "/filesync.File/BlocksDelete", drpcEncoding_File_commonfile_fileproto_protos_file_proto{}, in, out)
|
||||
func (c *drpcFileClient) FilesDelete(ctx context.Context, in *FilesDeleteRequest) (*FilesDeleteResponse, error) {
|
||||
out := new(FilesDeleteResponse)
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
@@ -112,13 +123,24 @@ func (c *drpcFileClient) Check(ctx context.Context, in *CheckRequest) (*CheckRes
|
||||
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 {
|
||||
BlockGet(context.Context, *BlockGetRequest) (*BlockGetResponse, error)
|
||||
BlockPush(context.Context, *BlockPushRequest) (*BlockPushResponse, error)
|
||||
BlocksCheck(context.Context, *BlocksCheckRequest) (*BlocksCheckResponse, 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)
|
||||
SpaceInfo(context.Context, *SpaceInfoRequest) (*SpaceInfoResponse, error)
|
||||
}
|
||||
|
||||
type DRPCFileUnimplementedServer struct{}
|
||||
@@ -139,7 +161,11 @@ func (s *DRPCFileUnimplementedServer) BlocksBind(context.Context, *BlocksBindReq
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -147,9 +173,13 @@ func (s *DRPCFileUnimplementedServer) Check(context.Context, *CheckRequest) (*Ch
|
||||
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{}
|
||||
|
||||
func (DRPCFileDescription) NumMethods() int { return 6 }
|
||||
func (DRPCFileDescription) NumMethods() int { return 8 }
|
||||
|
||||
func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||
switch n {
|
||||
@@ -190,15 +220,24 @@ func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver,
|
||||
)
|
||||
}, DRPCFileServer.BlocksBind, true
|
||||
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) {
|
||||
return srv.(DRPCFileServer).
|
||||
BlocksDelete(
|
||||
FilesDelete(
|
||||
ctx,
|
||||
in1.(*BlocksDeleteRequest),
|
||||
in1.(*FilesDeleteRequest),
|
||||
)
|
||||
}, DRPCFileServer.BlocksDelete, true
|
||||
}, DRPCFileServer.FilesDelete, true
|
||||
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{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCFileServer).
|
||||
@@ -207,6 +246,15 @@ func (DRPCFileDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver,
|
||||
in1.(*CheckRequest),
|
||||
)
|
||||
}, 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:
|
||||
return "", nil, nil, nil, false
|
||||
}
|
||||
@@ -280,16 +328,32 @@ func (x *drpcFile_BlocksBindStream) SendAndClose(m *BlocksBindResponse) error {
|
||||
return x.CloseSend()
|
||||
}
|
||||
|
||||
type DRPCFile_BlocksDeleteStream interface {
|
||||
type DRPCFile_FilesDeleteStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*BlocksDeleteResponse) error
|
||||
SendAndClose(*FilesDeleteResponse) error
|
||||
}
|
||||
|
||||
type drpcFile_BlocksDeleteStream struct {
|
||||
type drpcFile_FilesDeleteStream struct {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -311,3 +375,19 @@ func (x *drpcFile_CheckStream) SendAndClose(m *CheckResponse) error {
|
||||
}
|
||||
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()
|
||||
}
|
||||
@@ -7,7 +7,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errGroup = rpcerr.ErrGroup(fileproto.ErrCodes_ErrorOffset)
|
||||
ErrUnexpected = errGroup.Register(fmt.Errorf("unexpected fileproto error"), uint64(fileproto.ErrCodes_Unexpected))
|
||||
ErrCIDNotFound = errGroup.Register(fmt.Errorf("CID not found"), uint64(fileproto.ErrCodes_CIDNotFound))
|
||||
errGroup = rpcerr.ErrGroup(fileproto.ErrCodes_ErrorOffset)
|
||||
ErrUnexpected = errGroup.Register(fmt.Errorf("unexpected fileproto error"), uint64(fileproto.ErrCodes_Unexpected))
|
||||
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))
|
||||
)
|
||||
@@ -6,6 +6,10 @@ option go_package = "commonfile/fileproto";
|
||||
enum ErrCodes {
|
||||
Unexpected = 0;
|
||||
CIDNotFound = 1;
|
||||
Forbidden = 2;
|
||||
SpaceLimitExceeded = 3;
|
||||
QuerySizeExceeded = 4;
|
||||
WrongHash = 5;
|
||||
ErrorOffset = 200;
|
||||
}
|
||||
|
||||
@@ -18,10 +22,14 @@ service File {
|
||||
rpc BlocksCheck(BlocksCheckRequest) returns (BlocksCheckResponse);
|
||||
// BlocksBind binds CIDs to space
|
||||
rpc BlocksBind(BlocksBindRequest) returns (BlocksBindResponse);
|
||||
// BlocksDelete deletes block from space
|
||||
rpc BlocksDelete(BlocksDeleteRequest) returns (BlocksDeleteResponse);
|
||||
// FilesDelete deletes files by id
|
||||
rpc FilesDelete(FilesDeleteRequest) returns (FilesDeleteResponse);
|
||||
// FilesInfo return info by given files id
|
||||
rpc FilesInfo(FilesInfoRequest) returns (FilesInfoResponse);
|
||||
// Check checks the connection and credentials
|
||||
rpc Check(CheckRequest) returns (CheckResponse);
|
||||
// SpaceInfo returns usage, limit, etc about space
|
||||
rpc SpaceInfo(SpaceInfoRequest) returns (SpaceInfoResponse);
|
||||
}
|
||||
|
||||
message BlockGetRequest {
|
||||
@@ -36,8 +44,9 @@ message BlockGetResponse {
|
||||
|
||||
message BlockPushRequest {
|
||||
string spaceId = 1;
|
||||
bytes cid = 2;
|
||||
bytes data = 3;
|
||||
string fileId = 2;
|
||||
bytes cid = 3;
|
||||
bytes data = 4;
|
||||
}
|
||||
|
||||
message BlockPushResponse {}
|
||||
@@ -72,14 +81,50 @@ enum AvailabilityStatus {
|
||||
|
||||
message BlocksBindRequest {
|
||||
string spaceId = 1;
|
||||
repeated bytes cids = 2;
|
||||
string fileId = 2;
|
||||
repeated bytes cids = 3;
|
||||
}
|
||||
|
||||
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 CheckResponse {
|
||||
repeated string spaceIds = 1;
|
||||
bool allowWrite = 2;
|
||||
}
|
||||
|
||||
message SpaceInfoRequest {
|
||||
string spaceId = 1;
|
||||
}
|
||||
|
||||
message SpaceInfoResponse {
|
||||
uint64 limitBytes = 1;
|
||||
uint64 usageBytes = 2;
|
||||
uint64 cidsCount = 3;
|
||||
uint64 filesCount = 4;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ const CName = "common.commonfile.fileservice"
|
||||
|
||||
var log = logger.NewNamed(CName)
|
||||
|
||||
const (
|
||||
ChunkSize = 1 << 20
|
||||
)
|
||||
|
||||
func New() FileService {
|
||||
return &fileService{}
|
||||
}
|
||||
@@ -74,7 +78,7 @@ func (fs *fileService) AddFile(ctx context.Context, r io.Reader) (ipld.Node, err
|
||||
Maxlinks: helpers.DefaultLinksPerBlock,
|
||||
CidBuilder: &fs.prefix,
|
||||
}
|
||||
dbh, err := dbp.New(chunker.DefaultSplitter(r))
|
||||
dbh, err := dbp.New(chunker.NewSizeSplitter(r, ChunkSize))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
|
||||
"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/util/keys"
|
||||
"github.com/anytypeio/any-sync/util/keys/asymmetric/encryptionkey"
|
||||
@@ -13,10 +15,9 @@ import (
|
||||
"github.com/anytypeio/any-sync/util/keys/symmetric"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"go.uber.org/zap"
|
||||
"hash/fnv"
|
||||
)
|
||||
|
||||
var log = logger.NewNamed("acllist").Sugar()
|
||||
var log = logger.NewNamedSugared("common.commonspace.acllist")
|
||||
|
||||
var (
|
||||
ErrNoSuchUser = errors.New("no such user")
|
||||
|
||||
@@ -4,15 +4,16 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/anytypeio/any-sync/app/logger"
|
||||
"github.com/anytypeio/any-sync/commonspace/object/tree/treestorage"
|
||||
"github.com/anytypeio/any-sync/util/slice"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logger.NewNamed("acltree").Sugar()
|
||||
log = logger.NewNamedSugared("common.commonspace.objecttree")
|
||||
ErrEmpty = errors.New("logs empty")
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/anytypeio/any-sync/commonspace/syncstatus"
|
||||
"github.com/anytypeio/any-sync/net/peer"
|
||||
"github.com/anytypeio/any-sync/net/pool"
|
||||
"github.com/anytypeio/any-sync/net/rpc/rpcerr"
|
||||
"github.com/anytypeio/any-sync/nodeconf"
|
||||
"sync/atomic"
|
||||
)
|
||||
@@ -35,6 +36,7 @@ const AddSpaceCtxKey ctxKey = 0
|
||||
|
||||
type SpaceService interface {
|
||||
DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error)
|
||||
DeriveId(ctx context.Context, payload SpaceDerivePayload) (string, error)
|
||||
CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error)
|
||||
NewSpace(ctx context.Context, id string) (sp Space, err error)
|
||||
app.Component
|
||||
@@ -88,6 +90,15 @@ func (s *spaceService) CreateSpace(ctx context.Context, payload SpaceCreatePaylo
|
||||
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) {
|
||||
storageCreate, err := storagePayloadForSpaceDerive(payload)
|
||||
if err != nil {
|
||||
@@ -206,6 +217,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string)
|
||||
cl := spacesyncproto.NewDRPCSpaceSyncClient(p)
|
||||
res, err := cl.SpacePull(ctx, &spacesyncproto.SpacePullRequest{Id: id})
|
||||
if err != nil {
|
||||
err = rpcerr.Unwrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ require (
|
||||
github.com/huandu/skiplist v1.2.0
|
||||
github.com/ipfs/go-block-format v0.1.1
|
||||
github.com/ipfs/go-blockservice v0.5.0
|
||||
github.com/ipfs/go-cid v0.3.2
|
||||
github.com/ipfs/go-ipfs-blockstore v1.2.0
|
||||
github.com/ipfs/go-cid v0.4.0
|
||||
github.com/ipfs/go-ipfs-blockstore v1.3.0
|
||||
github.com/ipfs/go-ipfs-chunker v0.0.5
|
||||
github.com/ipfs/go-ipfs-exchange-interface v0.2.0
|
||||
github.com/ipfs/go-ipld-format v0.4.0
|
||||
@@ -24,7 +24,7 @@ require (
|
||||
github.com/libp2p/go-libp2p v0.24.1
|
||||
github.com/minio/sha256-simd v1.0.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/prometheus/client_golang v1.14.0
|
||||
github.com/stretchr/testify v1.8.2
|
||||
|
||||
@@ -207,15 +207,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.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.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc=
|
||||
github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw=
|
||||
github.com/ipfs/go-cid v0.4.0 h1:a4pdZq0sx6ZSxbCizebnKiMCx/xI/aBBFlB73IgH4rA=
|
||||
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.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk=
|
||||
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/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.2.0/go.mod h1:eh8eTFLiINYNSNawfZOC7HOxNTxpB1PFuA5E1m/7exE=
|
||||
github.com/ipfs/go-ipfs-blockstore v1.3.0 h1:m2EXaWgwTzAfsmt5UdJ7Is6l4gJcaM/A12XwJyvYvMM=
|
||||
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-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7NapWLY8=
|
||||
github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8=
|
||||
@@ -237,7 +237,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-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.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/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM=
|
||||
github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc=
|
||||
@@ -355,8 +354,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-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.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI=
|
||||
github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8=
|
||||
github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g=
|
||||
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/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw=
|
||||
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
|
||||
|
||||
+4
-3
@@ -2,15 +2,16 @@ package peer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/anytypeio/any-sync/app/logger"
|
||||
"github.com/libp2p/go-libp2p/core/sec"
|
||||
"go.uber.org/zap"
|
||||
"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 {
|
||||
return &peer{
|
||||
|
||||
@@ -67,6 +67,7 @@ func (p *pool) GetOneOf(ctx context.Context, peerIds []string) (peer.Peer, error
|
||||
default:
|
||||
return pr, nil
|
||||
}
|
||||
_, _ = p.cache.Remove(ctx, peerId)
|
||||
}
|
||||
}
|
||||
// shuffle ids for better consistency
|
||||
|
||||
@@ -2,14 +2,15 @@ package timeoutconn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/anytypeio/any-sync/app/logger"
|
||||
"go.uber.org/zap"
|
||||
"net"
|
||||
"os"
|
||||
"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 {
|
||||
net.Conn
|
||||
|
||||
Reference in new issue
Block a user