diff --git a/pkg/services/tree/service.go b/pkg/services/tree/service.go index 03d6673b..16ec780c 100644 --- a/pkg/services/tree/service.go +++ b/pkg/services/tree/service.go @@ -522,6 +522,51 @@ func (s *Service) GetOpLog(req *GetOpLogRequest, srv TreeService_GetOpLogServer) } } +func (s *Service) TreeList(ctx context.Context, req *TreeListRequest) (*TreeListResponse, error) { + var cid cidSDK.ID + + err := cid.Decode(req.GetBody().GetContainerId()) + if err != nil { + return nil, err + } + + // just verify the signature, not ACL checks + // since tree ID list is not protected like + // the containers list + err = verifyMessage(req) + if err != nil { + return nil, err + } + + ns, pos, err := s.getContainerNodes(cid) + if err != nil { + return nil, err + } + if pos < 0 { + var resp *TreeListResponse + var outErr error + err = s.forEachNode(ctx, ns, func(c TreeServiceClient) bool { + resp, outErr = c.TreeList(ctx, req) + return outErr == nil + }) + if err != nil { + return nil, err + } + return resp, outErr + } + + ids, err := s.forest.TreeList(cid) + if err != nil { + return nil, err + } + + return &TreeListResponse{ + Body: &TreeListResponse_Body{ + Ids: ids, + }, + }, nil +} + func protoToMeta(arr []*KeyValue) []pilorama.KeyValue { meta := make([]pilorama.KeyValue, len(arr)) for i, kv := range arr { diff --git a/pkg/services/tree/service.pb.go b/pkg/services/tree/service.pb.go index 09236fcf..303fcd94 100644 Binary files a/pkg/services/tree/service.pb.go and b/pkg/services/tree/service.pb.go differ diff --git a/pkg/services/tree/service.proto b/pkg/services/tree/service.proto index 9bcefbf9..473ef84f 100644 --- a/pkg/services/tree/service.proto +++ b/pkg/services/tree/service.proto @@ -39,6 +39,8 @@ service TreeService { rpc GetNodeByPath (GetNodeByPathRequest) returns (GetNodeByPathResponse); // GetSubTree returns tree corresponding to a specific node. rpc GetSubTree (GetSubTreeRequest) returns (stream GetSubTreeResponse); + // TreeList return list of the existing trees in the container. + rpc TreeList (TreeListRequest) returns (TreeListResponse); /* Synchronization API */ @@ -273,6 +275,29 @@ message GetSubTreeResponse { Signature signature = 2; }; +message TreeListRequest { + message Body { + // Container ID in V2 format. + bytes container_id = 1; + } + + // Request body. + Body body = 1; + // Request signature. + Signature signature = 2; +} + +message TreeListResponse { + message Body { + // Tree IDs. + repeated string ids = 1; + } + + // Response body. + Body body = 1; + Signature signature = 2; +} + message ApplyRequest { message Body { diff --git a/pkg/services/tree/service_grpc.pb.go b/pkg/services/tree/service_grpc.pb.go index 14e21305..aca152ad 100644 Binary files a/pkg/services/tree/service_grpc.pb.go and b/pkg/services/tree/service_grpc.pb.go differ diff --git a/pkg/services/tree/service_neofs.pb.go b/pkg/services/tree/service_neofs.pb.go index 44ddb198..298cfba1 100644 Binary files a/pkg/services/tree/service_neofs.pb.go and b/pkg/services/tree/service_neofs.pb.go differ