Moving around files and refactoring of common
This commit is contained in:
173 files changed
+1542
-1224
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package nodedebugrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/treegetter"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacestorage"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/server"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secureservice"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/debug/nodedebugrpc/nodedebugrpcproto"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace"
|
||||
nodestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/node/storage"
|
||||
"storj.io/drpc"
|
||||
)
|
||||
|
||||
const CName = "debug.nodedebugrpc"
|
||||
|
||||
var log = logger.NewNamed(CName)
|
||||
|
||||
func New() NodeDebugRpc {
|
||||
return &nodeDebugRpc{BaseDrpcServer: server.NewBaseDrpcServer()}
|
||||
}
|
||||
|
||||
type NodeDebugRpc interface {
|
||||
app.ComponentRunnable
|
||||
drpc.Mux
|
||||
}
|
||||
|
||||
type nodeDebugRpc struct {
|
||||
transport secureservice.SecureService
|
||||
cfg *config.Config
|
||||
treeCache treegetter.TreeGetter
|
||||
spaceService nodespace.Service
|
||||
storageService nodestorage.NodeStorage
|
||||
*server.BaseDrpcServer
|
||||
}
|
||||
|
||||
func (s *nodeDebugRpc) Init(a *app.App) (err error) {
|
||||
s.treeCache = a.MustComponent(treegetter.CName).(treegetter.TreeGetter)
|
||||
s.spaceService = a.MustComponent(nodespace.CName).(nodespace.Service)
|
||||
s.storageService = a.MustComponent(spacestorage.CName).(nodestorage.NodeStorage)
|
||||
s.cfg = a.MustComponent(config.CName).(*config.Config)
|
||||
s.transport = a.MustComponent(secureservice.CName).(secureservice.SecureService)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *nodeDebugRpc) Name() (name string) {
|
||||
return CName
|
||||
}
|
||||
|
||||
func (s *nodeDebugRpc) Run(ctx context.Context) (err error) {
|
||||
params := server.Params{
|
||||
BufferSizeMb: s.cfg.Stream.MaxMsgSizeMb,
|
||||
TimeoutMillis: s.cfg.Stream.TimeoutMilliseconds,
|
||||
ListenAddrs: s.cfg.APIServer.ListenAddrs,
|
||||
Wrapper: func(handler drpc.Handler) drpc.Handler {
|
||||
return handler
|
||||
},
|
||||
Converter: s.transport.BasicListener,
|
||||
}
|
||||
err = s.BaseDrpcServer.Run(ctx, params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return nodedebugrpcproto.DRPCRegisterNodeApi(s, &rpcHandler{s.treeCache, s.spaceService, s.storageService})
|
||||
}
|
||||
|
||||
func (s *nodeDebugRpc) Close(ctx context.Context) (err error) {
|
||||
return s.BaseDrpcServer.Close(ctx)
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,233 @@
|
||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||
// protoc-gen-go-drpc version: v0.0.32
|
||||
// source: api/apiproto/protos/api.proto
|
||||
|
||||
package nodedebugrpcproto
|
||||
|
||||
import (
|
||||
bytes "bytes"
|
||||
context "context"
|
||||
errors "errors"
|
||||
jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
drpc "storj.io/drpc"
|
||||
drpcerr "storj.io/drpc/drpcerr"
|
||||
)
|
||||
|
||||
type drpcEncoding_File_api_apiproto_protos_api_proto struct{}
|
||||
|
||||
func (drpcEncoding_File_api_apiproto_protos_api_proto) Marshal(msg drpc.Message) ([]byte, error) {
|
||||
return proto.Marshal(msg.(proto.Message))
|
||||
}
|
||||
|
||||
func (drpcEncoding_File_api_apiproto_protos_api_proto) Unmarshal(buf []byte, msg drpc.Message) error {
|
||||
return proto.Unmarshal(buf, msg.(proto.Message))
|
||||
}
|
||||
|
||||
func (drpcEncoding_File_api_apiproto_protos_api_proto) JSONMarshal(msg drpc.Message) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
err := new(jsonpb.Marshaler).Marshal(&buf, msg.(proto.Message))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (drpcEncoding_File_api_apiproto_protos_api_proto) JSONUnmarshal(buf []byte, msg drpc.Message) error {
|
||||
return jsonpb.Unmarshal(bytes.NewReader(buf), msg.(proto.Message))
|
||||
}
|
||||
|
||||
type DRPCNodeApiClient interface {
|
||||
DRPCConn() drpc.Conn
|
||||
|
||||
DumpTree(ctx context.Context, in *DumpTreeRequest) (*DumpTreeResponse, error)
|
||||
TreeParams(ctx context.Context, in *TreeParamsRequest) (*TreeParamsResponse, error)
|
||||
AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error)
|
||||
AllSpaces(ctx context.Context, in *AllSpacesRequest) (*AllSpacesResponse, error)
|
||||
}
|
||||
|
||||
type drpcNodeApiClient struct {
|
||||
cc drpc.Conn
|
||||
}
|
||||
|
||||
func NewDRPCNodeApiClient(cc drpc.Conn) DRPCNodeApiClient {
|
||||
return &drpcNodeApiClient{cc}
|
||||
}
|
||||
|
||||
func (c *drpcNodeApiClient) DRPCConn() drpc.Conn { return c.cc }
|
||||
|
||||
func (c *drpcNodeApiClient) DumpTree(ctx context.Context, in *DumpTreeRequest) (*DumpTreeResponse, error) {
|
||||
out := new(DumpTreeResponse)
|
||||
err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/DumpTree", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *drpcNodeApiClient) TreeParams(ctx context.Context, in *TreeParamsRequest) (*TreeParamsResponse, error) {
|
||||
out := new(TreeParamsResponse)
|
||||
err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/TreeParams", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *drpcNodeApiClient) AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error) {
|
||||
out := new(AllTreesResponse)
|
||||
err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *drpcNodeApiClient) AllSpaces(ctx context.Context, in *AllSpacesRequest) (*AllSpacesResponse, error) {
|
||||
out := new(AllSpacesResponse)
|
||||
err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/AllSpaces", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
type DRPCNodeApiServer interface {
|
||||
DumpTree(context.Context, *DumpTreeRequest) (*DumpTreeResponse, error)
|
||||
TreeParams(context.Context, *TreeParamsRequest) (*TreeParamsResponse, error)
|
||||
AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error)
|
||||
AllSpaces(context.Context, *AllSpacesRequest) (*AllSpacesResponse, error)
|
||||
}
|
||||
|
||||
type DRPCNodeApiUnimplementedServer struct{}
|
||||
|
||||
func (s *DRPCNodeApiUnimplementedServer) DumpTree(context.Context, *DumpTreeRequest) (*DumpTreeResponse, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
|
||||
func (s *DRPCNodeApiUnimplementedServer) TreeParams(context.Context, *TreeParamsRequest) (*TreeParamsResponse, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
|
||||
func (s *DRPCNodeApiUnimplementedServer) AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
|
||||
func (s *DRPCNodeApiUnimplementedServer) AllSpaces(context.Context, *AllSpacesRequest) (*AllSpacesResponse, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
|
||||
type DRPCNodeApiDescription struct{}
|
||||
|
||||
func (DRPCNodeApiDescription) NumMethods() int { return 4 }
|
||||
|
||||
func (DRPCNodeApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||
switch n {
|
||||
case 0:
|
||||
return "/nodeapi.NodeApi/DumpTree", drpcEncoding_File_api_apiproto_protos_api_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCNodeApiServer).
|
||||
DumpTree(
|
||||
ctx,
|
||||
in1.(*DumpTreeRequest),
|
||||
)
|
||||
}, DRPCNodeApiServer.DumpTree, true
|
||||
case 1:
|
||||
return "/nodeapi.NodeApi/TreeParams", drpcEncoding_File_api_apiproto_protos_api_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCNodeApiServer).
|
||||
TreeParams(
|
||||
ctx,
|
||||
in1.(*TreeParamsRequest),
|
||||
)
|
||||
}, DRPCNodeApiServer.TreeParams, true
|
||||
case 2:
|
||||
return "/nodeapi.NodeApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCNodeApiServer).
|
||||
AllTrees(
|
||||
ctx,
|
||||
in1.(*AllTreesRequest),
|
||||
)
|
||||
}, DRPCNodeApiServer.AllTrees, true
|
||||
case 3:
|
||||
return "/nodeapi.NodeApi/AllSpaces", drpcEncoding_File_api_apiproto_protos_api_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCNodeApiServer).
|
||||
AllSpaces(
|
||||
ctx,
|
||||
in1.(*AllSpacesRequest),
|
||||
)
|
||||
}, DRPCNodeApiServer.AllSpaces, true
|
||||
default:
|
||||
return "", nil, nil, nil, false
|
||||
}
|
||||
}
|
||||
|
||||
func DRPCRegisterNodeApi(mux drpc.Mux, impl DRPCNodeApiServer) error {
|
||||
return mux.Register(impl, DRPCNodeApiDescription{})
|
||||
}
|
||||
|
||||
type DRPCNodeApi_DumpTreeStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*DumpTreeResponse) error
|
||||
}
|
||||
|
||||
type drpcNodeApi_DumpTreeStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcNodeApi_DumpTreeStream) SendAndClose(m *DumpTreeResponse) error {
|
||||
if err := x.MsgSend(m, drpcEncoding_File_api_apiproto_protos_api_proto{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return x.CloseSend()
|
||||
}
|
||||
|
||||
type DRPCNodeApi_TreeParamsStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*TreeParamsResponse) error
|
||||
}
|
||||
|
||||
type drpcNodeApi_TreeParamsStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcNodeApi_TreeParamsStream) SendAndClose(m *TreeParamsResponse) error {
|
||||
if err := x.MsgSend(m, drpcEncoding_File_api_apiproto_protos_api_proto{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return x.CloseSend()
|
||||
}
|
||||
|
||||
type DRPCNodeApi_AllTreesStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*AllTreesResponse) error
|
||||
}
|
||||
|
||||
type drpcNodeApi_AllTreesStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcNodeApi_AllTreesStream) SendAndClose(m *AllTreesResponse) error {
|
||||
if err := x.MsgSend(m, drpcEncoding_File_api_apiproto_protos_api_proto{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return x.CloseSend()
|
||||
}
|
||||
|
||||
type DRPCNodeApi_AllSpacesStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*AllSpacesResponse) error
|
||||
}
|
||||
|
||||
type drpcNodeApi_AllSpacesStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcNodeApi_AllSpacesStream) SendAndClose(m *AllSpacesResponse) error {
|
||||
if err := x.MsgSend(m, drpcEncoding_File_api_apiproto_protos_api_proto{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return x.CloseSend()
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
syntax = "proto3";
|
||||
package nodeapi;
|
||||
|
||||
option go_package = "api/apiproto";
|
||||
|
||||
service NodeApi {
|
||||
rpc DumpTree(DumpTreeRequest) returns(DumpTreeResponse);
|
||||
rpc TreeParams(TreeParamsRequest) returns(TreeParamsResponse);
|
||||
rpc AllTrees(AllTreesRequest) returns(AllTreesResponse);
|
||||
rpc AllSpaces(AllSpacesRequest) returns(AllSpacesResponse);
|
||||
}
|
||||
|
||||
message DumpTreeRequest {
|
||||
string spaceId = 1;
|
||||
string documentId = 2;
|
||||
}
|
||||
|
||||
message DumpTreeResponse {
|
||||
string dump = 1;
|
||||
}
|
||||
|
||||
message AllTreesRequest {
|
||||
string spaceId = 1;
|
||||
}
|
||||
|
||||
message Tree {
|
||||
string id = 1;
|
||||
repeated string heads = 2;
|
||||
}
|
||||
|
||||
message AllTreesResponse {
|
||||
repeated Tree trees = 1;
|
||||
}
|
||||
|
||||
message AllSpacesRequest {
|
||||
}
|
||||
|
||||
message AllSpacesResponse {
|
||||
repeated string spaceIds = 1;
|
||||
}
|
||||
|
||||
message TreeParamsRequest {
|
||||
string spaceId = 1;
|
||||
string documentId = 2;
|
||||
}
|
||||
|
||||
message TreeParamsResponse {
|
||||
string rootId = 1;
|
||||
repeated string headIds = 2;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package nodedebugrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/treegetter"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/debug/nodedebugrpc/nodedebugrpcproto"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/storage"
|
||||
)
|
||||
|
||||
type rpcHandler struct {
|
||||
treeCache treegetter.TreeGetter
|
||||
spaceService nodespace.Service
|
||||
storageService storage.NodeStorage
|
||||
}
|
||||
|
||||
func (r *rpcHandler) DumpTree(ctx context.Context, request *nodedebugrpcproto.DumpTreeRequest) (resp *nodedebugrpcproto.DumpTreeResponse, err error) {
|
||||
tree, err := r.treeCache.GetTree(context.Background(), request.SpaceId, request.DocumentId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dump, err := tree.DebugDump()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp = &nodedebugrpcproto.DumpTreeResponse{
|
||||
Dump: dump,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *rpcHandler) AllTrees(ctx context.Context, request *nodedebugrpcproto.AllTreesRequest) (resp *nodedebugrpcproto.AllTreesResponse, err error) {
|
||||
space, err := r.spaceService.GetSpace(ctx, request.SpaceId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
heads := space.DebugAllHeads()
|
||||
var trees []*nodedebugrpcproto.Tree
|
||||
for _, head := range heads {
|
||||
trees = append(trees, &nodedebugrpcproto.Tree{
|
||||
Id: head.Id,
|
||||
Heads: head.Heads,
|
||||
})
|
||||
}
|
||||
resp = &nodedebugrpcproto.AllTreesResponse{Trees: trees}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *rpcHandler) AllSpaces(ctx context.Context, request *nodedebugrpcproto.AllSpacesRequest) (resp *nodedebugrpcproto.AllSpacesResponse, err error) {
|
||||
ids, err := r.storageService.AllSpaceIds()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp = &nodedebugrpcproto.AllSpacesResponse{SpaceIds: ids}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *rpcHandler) TreeParams(ctx context.Context, request *nodedebugrpcproto.TreeParamsRequest) (resp *nodedebugrpcproto.TreeParamsResponse, err error) {
|
||||
tree, err := r.treeCache.GetTree(context.Background(), request.SpaceId, request.DocumentId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp = &nodedebugrpcproto.TreeParamsResponse{
|
||||
RootId: tree.Root().Id,
|
||||
HeadIds: tree.Heads(),
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user