diff --git a/common/commonspace/space.go b/common/commonspace/space.go index 4dc3db76..a1ce64b0 100644 --- a/common/commonspace/space.go +++ b/common/commonspace/space.go @@ -43,10 +43,7 @@ type SpaceCreatePayload struct { ReplicationKey uint64 } -const ( - SpaceTypeDerived = "derived.space" - SettingsSyncPeriodSeconds = 10 -) +const SpaceTypeDerived = "derived.space" type SpaceDerivePayload struct { SigningKey signingkey.PrivKey diff --git a/node/Makefile b/node/Makefile index e33e5c6e..c6194e7c 100644 --- a/node/Makefile +++ b/node/Makefile @@ -6,4 +6,8 @@ build: go build -v -o ../bin/anytype-node -ldflags "$(FLAGS)" github.com/anytypeio/go-anytype-infrastructure-experiments/node/cmd test: - go test ./... --cover \ No newline at end of file + go test ./... --cover + +proto: + @$(eval GOGO_START := GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1) + $(GOGO_START) protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. api/apiproto/protos/*.proto \ No newline at end of file diff --git a/node/api/apiproto/api.pb.go b/node/api/apiproto/api.pb.go new file mode 100644 index 00000000..a24500f3 --- /dev/null +++ b/node/api/apiproto/api.pb.go @@ -0,0 +1,1415 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: api/apiproto/protos/api.proto + +package apiproto + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type DumpTreeRequest struct { + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + DocumentId string `protobuf:"bytes,2,opt,name=documentId,proto3" json:"documentId,omitempty"` +} + +func (m *DumpTreeRequest) Reset() { *m = DumpTreeRequest{} } +func (m *DumpTreeRequest) String() string { return proto.CompactTextString(m) } +func (*DumpTreeRequest) ProtoMessage() {} +func (*DumpTreeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{0} +} +func (m *DumpTreeRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DumpTreeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DumpTreeRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DumpTreeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DumpTreeRequest.Merge(m, src) +} +func (m *DumpTreeRequest) XXX_Size() int { + return m.Size() +} +func (m *DumpTreeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DumpTreeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DumpTreeRequest proto.InternalMessageInfo + +func (m *DumpTreeRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +func (m *DumpTreeRequest) GetDocumentId() string { + if m != nil { + return m.DocumentId + } + return "" +} + +type DumpTreeResponse struct { + Dump string `protobuf:"bytes,1,opt,name=dump,proto3" json:"dump,omitempty"` +} + +func (m *DumpTreeResponse) Reset() { *m = DumpTreeResponse{} } +func (m *DumpTreeResponse) String() string { return proto.CompactTextString(m) } +func (*DumpTreeResponse) ProtoMessage() {} +func (*DumpTreeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{1} +} +func (m *DumpTreeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DumpTreeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DumpTreeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DumpTreeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DumpTreeResponse.Merge(m, src) +} +func (m *DumpTreeResponse) XXX_Size() int { + return m.Size() +} +func (m *DumpTreeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DumpTreeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DumpTreeResponse proto.InternalMessageInfo + +func (m *DumpTreeResponse) GetDump() string { + if m != nil { + return m.Dump + } + return "" +} + +type AllTreesRequest struct { + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` +} + +func (m *AllTreesRequest) Reset() { *m = AllTreesRequest{} } +func (m *AllTreesRequest) String() string { return proto.CompactTextString(m) } +func (*AllTreesRequest) ProtoMessage() {} +func (*AllTreesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{2} +} +func (m *AllTreesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllTreesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllTreesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AllTreesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllTreesRequest.Merge(m, src) +} +func (m *AllTreesRequest) XXX_Size() int { + return m.Size() +} +func (m *AllTreesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_AllTreesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_AllTreesRequest proto.InternalMessageInfo + +func (m *AllTreesRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +type Tree struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Heads []string `protobuf:"bytes,2,rep,name=heads,proto3" json:"heads,omitempty"` +} + +func (m *Tree) Reset() { *m = Tree{} } +func (m *Tree) String() string { return proto.CompactTextString(m) } +func (*Tree) ProtoMessage() {} +func (*Tree) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{3} +} +func (m *Tree) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Tree) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Tree.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Tree) XXX_Merge(src proto.Message) { + xxx_messageInfo_Tree.Merge(m, src) +} +func (m *Tree) XXX_Size() int { + return m.Size() +} +func (m *Tree) XXX_DiscardUnknown() { + xxx_messageInfo_Tree.DiscardUnknown(m) +} + +var xxx_messageInfo_Tree proto.InternalMessageInfo + +func (m *Tree) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Tree) GetHeads() []string { + if m != nil { + return m.Heads + } + return nil +} + +type AllTreesResponse struct { + Trees []*Tree `protobuf:"bytes,1,rep,name=trees,proto3" json:"trees,omitempty"` +} + +func (m *AllTreesResponse) Reset() { *m = AllTreesResponse{} } +func (m *AllTreesResponse) String() string { return proto.CompactTextString(m) } +func (*AllTreesResponse) ProtoMessage() {} +func (*AllTreesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{4} +} +func (m *AllTreesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllTreesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllTreesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AllTreesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllTreesResponse.Merge(m, src) +} +func (m *AllTreesResponse) XXX_Size() int { + return m.Size() +} +func (m *AllTreesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_AllTreesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_AllTreesResponse proto.InternalMessageInfo + +func (m *AllTreesResponse) GetTrees() []*Tree { + if m != nil { + return m.Trees + } + return nil +} + +type AllSpacesRequest struct { +} + +func (m *AllSpacesRequest) Reset() { *m = AllSpacesRequest{} } +func (m *AllSpacesRequest) String() string { return proto.CompactTextString(m) } +func (*AllSpacesRequest) ProtoMessage() {} +func (*AllSpacesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{5} +} +func (m *AllSpacesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllSpacesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllSpacesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AllSpacesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllSpacesRequest.Merge(m, src) +} +func (m *AllSpacesRequest) XXX_Size() int { + return m.Size() +} +func (m *AllSpacesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_AllSpacesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_AllSpacesRequest proto.InternalMessageInfo + +type AllSpacesResponse struct { + SpaceIds []string `protobuf:"bytes,1,rep,name=spaceIds,proto3" json:"spaceIds,omitempty"` +} + +func (m *AllSpacesResponse) Reset() { *m = AllSpacesResponse{} } +func (m *AllSpacesResponse) String() string { return proto.CompactTextString(m) } +func (*AllSpacesResponse) ProtoMessage() {} +func (*AllSpacesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fc31080c27db9707, []int{6} +} +func (m *AllSpacesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllSpacesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllSpacesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AllSpacesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllSpacesResponse.Merge(m, src) +} +func (m *AllSpacesResponse) XXX_Size() int { + return m.Size() +} +func (m *AllSpacesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_AllSpacesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_AllSpacesResponse proto.InternalMessageInfo + +func (m *AllSpacesResponse) GetSpaceIds() []string { + if m != nil { + return m.SpaceIds + } + return nil +} + +func init() { + proto.RegisterType((*DumpTreeRequest)(nil), "api.DumpTreeRequest") + proto.RegisterType((*DumpTreeResponse)(nil), "api.DumpTreeResponse") + proto.RegisterType((*AllTreesRequest)(nil), "api.AllTreesRequest") + proto.RegisterType((*Tree)(nil), "api.Tree") + proto.RegisterType((*AllTreesResponse)(nil), "api.AllTreesResponse") + proto.RegisterType((*AllSpacesRequest)(nil), "api.AllSpacesRequest") + proto.RegisterType((*AllSpacesResponse)(nil), "api.AllSpacesResponse") +} + +func init() { proto.RegisterFile("api/apiproto/protos/api.proto", fileDescriptor_fc31080c27db9707) } + +var fileDescriptor_fc31080c27db9707 = []byte{ + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xc1, 0x4e, 0xea, 0x40, + 0x14, 0x65, 0x0a, 0x3c, 0xe8, 0x7d, 0x46, 0x70, 0x82, 0xa6, 0x21, 0x71, 0x24, 0xb3, 0x20, 0x24, + 0x1a, 0x48, 0x60, 0x41, 0xe2, 0x0e, 0xe3, 0x86, 0x98, 0xb8, 0xa8, 0xae, 0xdc, 0x55, 0x66, 0x12, + 0x27, 0x01, 0x3a, 0x32, 0xed, 0x7f, 0xf8, 0x37, 0xfe, 0x82, 0x4b, 0x96, 0x2e, 0x4d, 0xfb, 0x23, + 0x66, 0xa6, 0xd3, 0x52, 0xeb, 0xc2, 0x4d, 0x3b, 0xf7, 0xcc, 0xbd, 0xe7, 0x9c, 0x7b, 0x32, 0x70, + 0x1e, 0x48, 0x31, 0x09, 0xa4, 0x90, 0xbb, 0x30, 0x0a, 0x27, 0xe6, 0xab, 0x74, 0x3d, 0x36, 0x47, + 0x5c, 0x0f, 0xa4, 0xa0, 0x77, 0xd0, 0xb9, 0x8d, 0x37, 0xf2, 0x71, 0xc7, 0xb9, 0xcf, 0x5f, 0x63, + 0xae, 0x22, 0xec, 0x41, 0x4b, 0xc9, 0x60, 0xc5, 0x97, 0xcc, 0x43, 0x03, 0x34, 0x72, 0xfd, 0xbc, + 0xc4, 0x04, 0x80, 0x85, 0xab, 0x78, 0xc3, 0xb7, 0xd1, 0x92, 0x79, 0x8e, 0xb9, 0x2c, 0x21, 0x74, + 0x08, 0xdd, 0x03, 0x99, 0x92, 0xe1, 0x56, 0x71, 0x8c, 0xa1, 0xc1, 0xe2, 0x8d, 0xb4, 0x54, 0xe6, + 0x4c, 0x2f, 0xa1, 0xb3, 0x58, 0xaf, 0x75, 0x9b, 0xfa, 0x53, 0x94, 0x5e, 0x41, 0x43, 0x77, 0xe2, + 0x63, 0x70, 0x44, 0x7e, 0xe9, 0x08, 0x86, 0x7b, 0xd0, 0x7c, 0xe1, 0x01, 0x53, 0x9e, 0x33, 0xa8, + 0x8f, 0x5c, 0x3f, 0x2b, 0xe8, 0x0c, 0xba, 0x07, 0x6a, 0x6b, 0xe1, 0x02, 0x9a, 0x91, 0x06, 0x3c, + 0x34, 0xa8, 0x8f, 0xfe, 0x4f, 0xdd, 0xb1, 0xce, 0xc0, 0x98, 0xcc, 0x70, 0x8a, 0xcd, 0xd0, 0x83, + 0x16, 0xcc, 0x0d, 0xd1, 0x09, 0x9c, 0x94, 0x30, 0xcb, 0xd4, 0x87, 0xb6, 0xb5, 0x95, 0x91, 0xb9, + 0x7e, 0x51, 0x4f, 0xdf, 0x11, 0xb4, 0xee, 0x43, 0xc6, 0x17, 0x52, 0xe0, 0x39, 0xb4, 0xf3, 0x20, + 0x70, 0xcf, 0xc8, 0x55, 0x42, 0xee, 0x9f, 0x56, 0x50, 0x2b, 0x30, 0x87, 0x76, 0x6e, 0xdf, 0x0e, + 0x56, 0x82, 0xb2, 0x83, 0xbf, 0x76, 0xbc, 0x06, 0xb7, 0xb0, 0x8b, 0x8b, 0x9e, 0x1f, 0x2b, 0xf5, + 0xcf, 0xaa, 0x70, 0x36, 0x7b, 0x33, 0xfc, 0x48, 0x08, 0xda, 0x27, 0x04, 0x7d, 0x25, 0x04, 0xbd, + 0xa5, 0xa4, 0xb6, 0x4f, 0x49, 0xed, 0x33, 0x25, 0xb5, 0xa7, 0xa3, 0xf2, 0x0b, 0x7a, 0xfe, 0x67, + 0x7e, 0xb3, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb7, 0xcf, 0x0b, 0x8b, 0x58, 0x02, 0x00, 0x00, +} + +func (m *DumpTreeRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DumpTreeRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DumpTreeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DocumentId) > 0 { + i -= len(m.DocumentId) + copy(dAtA[i:], m.DocumentId) + i = encodeVarintApi(dAtA, i, uint64(len(m.DocumentId))) + i-- + dAtA[i] = 0x12 + } + if len(m.SpaceId) > 0 { + i -= len(m.SpaceId) + copy(dAtA[i:], m.SpaceId) + i = encodeVarintApi(dAtA, i, uint64(len(m.SpaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DumpTreeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DumpTreeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DumpTreeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Dump) > 0 { + i -= len(m.Dump) + copy(dAtA[i:], m.Dump) + i = encodeVarintApi(dAtA, i, uint64(len(m.Dump))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *AllTreesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AllTreesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllTreesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SpaceId) > 0 { + i -= len(m.SpaceId) + copy(dAtA[i:], m.SpaceId) + i = encodeVarintApi(dAtA, i, uint64(len(m.SpaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Tree) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Tree) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Tree) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Heads) > 0 { + for iNdEx := len(m.Heads) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Heads[iNdEx]) + copy(dAtA[i:], m.Heads[iNdEx]) + i = encodeVarintApi(dAtA, i, uint64(len(m.Heads[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintApi(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *AllTreesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AllTreesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllTreesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Trees) > 0 { + for iNdEx := len(m.Trees) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Trees[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintApi(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *AllSpacesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AllSpacesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllSpacesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *AllSpacesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AllSpacesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllSpacesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SpaceIds) > 0 { + for iNdEx := len(m.SpaceIds) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.SpaceIds[iNdEx]) + copy(dAtA[i:], m.SpaceIds[iNdEx]) + i = encodeVarintApi(dAtA, i, uint64(len(m.SpaceIds[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintApi(dAtA []byte, offset int, v uint64) int { + offset -= sovApi(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *DumpTreeRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceId) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + l = len(m.DocumentId) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + return n +} + +func (m *DumpTreeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Dump) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + return n +} + +func (m *AllTreesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceId) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + return n +} + +func (m *Tree) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + if len(m.Heads) > 0 { + for _, s := range m.Heads { + l = len(s) + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func (m *AllTreesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Trees) > 0 { + for _, e := range m.Trees { + l = e.Size() + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func (m *AllSpacesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *AllSpacesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.SpaceIds) > 0 { + for _, s := range m.SpaceIds { + l = len(s) + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func sovApi(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozApi(x uint64) (n int) { + return sovApi(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DumpTreeRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DumpTreeRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DumpTreeRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpaceId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DocumentId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DocumentId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DumpTreeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DumpTreeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DumpTreeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Dump", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Dump = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllTreesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AllTreesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllTreesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpaceId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Tree) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Tree: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Tree: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Heads", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Heads = append(m.Heads, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllTreesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AllTreesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllTreesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Trees", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Trees = append(m.Trees, &Tree{}) + if err := m.Trees[len(m.Trees)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllSpacesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AllSpacesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllSpacesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllSpacesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AllSpacesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllSpacesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceIds", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpaceIds = append(m.SpaceIds, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipApi(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowApi + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowApi + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowApi + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthApi + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupApi + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthApi + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthApi = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowApi = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupApi = fmt.Errorf("proto: unexpected end of group") +) diff --git a/node/api/apiproto/api_drpc.pb.go b/node/api/apiproto/api_drpc.pb.go new file mode 100644 index 00000000..6dcc8e3e --- /dev/null +++ b/node/api/apiproto/api_drpc.pb.go @@ -0,0 +1,193 @@ +// 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 apiproto + +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) + 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, "/api.NodeApi/DumpTree", 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, "/api.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, "/api.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) + 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) 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 3 } + +func (DRPCNodeApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { + switch n { + case 0: + return "/api.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 "/api.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 2: + return "/api.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_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() +} diff --git a/node/api/apiproto/protos/api.proto b/node/api/apiproto/protos/api.proto new file mode 100644 index 00000000..f60fd440 --- /dev/null +++ b/node/api/apiproto/protos/api.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; +package api; + +option go_package = "api/apiproto"; + +service NodeApi { + rpc DumpTree(DumpTreeRequest) returns(DumpTreeResponse); + 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; +} diff --git a/node/api/rpchandler.go b/node/api/rpchandler.go new file mode 100644 index 00000000..13c099f9 --- /dev/null +++ b/node/api/rpchandler.go @@ -0,0 +1,56 @@ +package api + +import ( + "context" + "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter" + "github.com/anytypeio/go-anytype-infrastructure-experiments/node/api/apiproto" + "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 *apiproto.DumpTreeRequest) (resp *apiproto.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 = &apiproto.DumpTreeResponse{ + Dump: dump, + } + return +} + +func (r *rpcHandler) AllTrees(ctx context.Context, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) { + space, err := r.spaceService.GetSpace(ctx, request.SpaceId) + if err != nil { + return + } + heads := space.DebugAllHeads() + var trees []*apiproto.Tree + for _, head := range heads { + trees = append(trees, &apiproto.Tree{ + Id: head.Id, + Heads: head.Heads, + }) + } + resp = &apiproto.AllTreesResponse{Trees: trees} + return +} + +func (r *rpcHandler) AllSpaces(ctx context.Context, request *apiproto.AllSpacesRequest) (resp *apiproto.AllSpacesResponse, err error) { + ids, err := r.storageService.AllSpaceIds() + if err != nil { + return + } + resp = &apiproto.AllSpacesResponse{SpaceIds: ids} + return +} diff --git a/node/api/service.go b/node/api/service.go new file mode 100644 index 00000000..9b39d618 --- /dev/null +++ b/node/api/service.go @@ -0,0 +1,69 @@ +package api + +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/storage" + "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter" + "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/secure" + "github.com/anytypeio/go-anytype-infrastructure-experiments/node/api/apiproto" + "github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace" + nodestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/node/storage" + "storj.io/drpc" +) + +const CName = "api.service" + +var log = logger.NewNamed(CName) + +func New() Service { + return &service{BaseDrpcServer: server.NewBaseDrpcServer()} +} + +type Service interface { + app.ComponentRunnable + drpc.Mux +} + +type service struct { + transport secure.Service + cfg *config.Config + treeCache treegetter.TreeGetter + spaceService nodespace.Service + storageService nodestorage.NodeStorage + *server.BaseDrpcServer +} + +func (s *service) 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(storage.CName).(nodestorage.NodeStorage) + s.cfg = a.MustComponent(config.CName).(*config.Config) + s.transport = a.MustComponent(secure.CName).(secure.Service) + return nil +} + +func (s *service) Name() (name string) { + return CName +} + +func (s *service) Run(ctx context.Context) (err error) { + err = s.BaseDrpcServer.Run( + ctx, + s.cfg.APIServer.ListenAddrs, + func(handler drpc.Handler) drpc.Handler { + return handler + }, + s.transport.BasicListener) + if err != nil { + return + } + return apiproto.DRPCRegisterNodeApi(s, &rpcHandler{s.treeCache, s.spaceService, s.storageService}) +} + +func (s *service) Close(ctx context.Context) (err error) { + return s.BaseDrpcServer.Close(ctx) +} diff --git a/node/cmd/node.go b/node/cmd/node.go index 1606ac3e..a931bdc4 100644 --- a/node/cmd/node.go +++ b/node/cmd/node.go @@ -15,6 +15,7 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/account" + "github.com/anytypeio/go-anytype-infrastructure-experiments/node/api" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace/nodecache" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/storage" @@ -101,5 +102,6 @@ func Bootstrap(a *app.App) { Register(pool.New()). Register(nodespace.New()). Register(commonspace.New()). - Register(server.New()) + Register(server.New()). + Register(api.New()) } diff --git a/node/storage/storageservice.go b/node/storage/storageservice.go index 9b703cd8..24943a62 100644 --- a/node/storage/storageservice.go +++ b/node/storage/storageservice.go @@ -4,13 +4,19 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config" + "os" ) type storageService struct { rootPath string } -func New() storage.SpaceStorageProvider { +type NodeStorage interface { + storage.SpaceStorageProvider + AllSpaceIds() (ids []string, err error) +} + +func New() NodeStorage { return &storageService{} } @@ -31,3 +37,16 @@ func (s *storageService) SpaceStorage(id string) (storage.SpaceStorage, error) { func (s *storageService) CreateSpaceStorage(payload storage.SpaceStorageCreatePayload) (storage.SpaceStorage, error) { return createSpaceStorage(s.rootPath, payload) } + +func (s *storageService) AllSpaceIds() (ids []string, err error) { + var files []string + fileInfo, err := os.ReadDir(s.rootPath) + if err != nil { + return files, err + } + + for _, file := range fileInfo { + files = append(files, file.Name()) + } + return files, nil +}