From 067bf797ddefd98413bff419a588e38b9e9f88f5 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 26 Mar 2023 14:54:27 +0200 Subject: [PATCH 01/26] node configuration command proto --- .../coordinatorproto/coordinator.pb.go | 868 +++++++++++++++++- .../coordinatorproto/coordinator_drpc.pb.go | 42 +- .../coordinatorproto/protos/coordinator.proto | 34 + 3 files changed, 898 insertions(+), 46 deletions(-) diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index d35c7b8a..1bdbe25d 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -90,6 +90,38 @@ func (SpaceStatus) EnumDescriptor() ([]byte, []int) { return fileDescriptor_d94f6f99586adae2, []int{1} } +// NodeType determines the type of API that a node supports +type NodeType int32 + +const ( + // TreeAPI supports space/tree sync api + NodeType_TreeAPI NodeType = 0 + // FileAPI support file api + NodeType_FileAPI NodeType = 1 + // CoordinatorAPI supports coordinator api + NodeType_CoordinatorAPI NodeType = 2 +) + +var NodeType_name = map[int32]string{ + 0: "TreeAPI", + 1: "FileAPI", + 2: "CoordinatorAPI", +} + +var NodeType_value = map[string]int32{ + "TreeAPI": 0, + "FileAPI": 1, + "CoordinatorAPI": 2, +} + +func (x NodeType) String() string { + return proto.EnumName(NodeType_name, int32(x)) +} + +func (NodeType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{2} +} + type SpaceSignRequest struct { SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` @@ -668,9 +700,172 @@ func (m *SpaceStatusChangeResponse) GetPayload() *SpaceStatusPayload { return nil } +// NetworkConfigurationRequest contains the requested configurationId, it can be empty to request the latest version +type NetworkConfigurationRequest struct { + ConfigurationId string `protobuf:"bytes,1,opt,name=configurationId,proto3" json:"configurationId,omitempty"` +} + +func (m *NetworkConfigurationRequest) Reset() { *m = NetworkConfigurationRequest{} } +func (m *NetworkConfigurationRequest) String() string { return proto.CompactTextString(m) } +func (*NetworkConfigurationRequest) ProtoMessage() {} +func (*NetworkConfigurationRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{11} +} +func (m *NetworkConfigurationRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NetworkConfigurationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_NetworkConfigurationRequest.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 *NetworkConfigurationRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NetworkConfigurationRequest.Merge(m, src) +} +func (m *NetworkConfigurationRequest) XXX_Size() int { + return m.Size() +} +func (m *NetworkConfigurationRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NetworkConfigurationRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_NetworkConfigurationRequest proto.InternalMessageInfo + +func (m *NetworkConfigurationRequest) GetConfigurationId() string { + if m != nil { + return m.ConfigurationId + } + return "" +} + +// NetworkConfigurationResponse contains list of nodes +type NetworkConfigurationResponse struct { + ConfigurationId string `protobuf:"bytes,1,opt,name=configurationId,proto3" json:"configurationId,omitempty"` + Nodes []*Node `protobuf:"bytes,2,rep,name=nodes,proto3" json:"nodes,omitempty"` +} + +func (m *NetworkConfigurationResponse) Reset() { *m = NetworkConfigurationResponse{} } +func (m *NetworkConfigurationResponse) String() string { return proto.CompactTextString(m) } +func (*NetworkConfigurationResponse) ProtoMessage() {} +func (*NetworkConfigurationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{12} +} +func (m *NetworkConfigurationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NetworkConfigurationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_NetworkConfigurationResponse.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 *NetworkConfigurationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_NetworkConfigurationResponse.Merge(m, src) +} +func (m *NetworkConfigurationResponse) XXX_Size() int { + return m.Size() +} +func (m *NetworkConfigurationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_NetworkConfigurationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_NetworkConfigurationResponse proto.InternalMessageInfo + +func (m *NetworkConfigurationResponse) GetConfigurationId() string { + if m != nil { + return m.ConfigurationId + } + return "" +} + +func (m *NetworkConfigurationResponse) GetNodes() []*Node { + if m != nil { + return m.Nodes + } + return nil +} + +// Node describes one node in the network +type Node struct { + // peerId - it's a peer identifier (libp2p format string) so it's an encoded publicKey + PeerId string `protobuf:"bytes,1,opt,name=peerId,proto3" json:"peerId,omitempty"` + // list of node addresses + Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"` + // list of supported APIs + Types []NodeType `protobuf:"varint,3,rep,packed,name=types,proto3,enum=coordinator.NodeType" json:"types,omitempty"` +} + +func (m *Node) Reset() { *m = Node{} } +func (m *Node) String() string { return proto.CompactTextString(m) } +func (*Node) ProtoMessage() {} +func (*Node) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{13} +} +func (m *Node) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Node) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Node.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 *Node) XXX_Merge(src proto.Message) { + xxx_messageInfo_Node.Merge(m, src) +} +func (m *Node) XXX_Size() int { + return m.Size() +} +func (m *Node) XXX_DiscardUnknown() { + xxx_messageInfo_Node.DiscardUnknown(m) +} + +var xxx_messageInfo_Node proto.InternalMessageInfo + +func (m *Node) GetPeerId() string { + if m != nil { + return m.PeerId + } + return "" +} + +func (m *Node) GetAddresses() []string { + if m != nil { + return m.Addresses + } + return nil +} + +func (m *Node) GetTypes() []NodeType { + if m != nil { + return m.Types + } + return nil +} + func init() { proto.RegisterEnum("coordinator.ErrorCodes", ErrorCodes_name, ErrorCodes_value) proto.RegisterEnum("coordinator.SpaceStatus", SpaceStatus_name, SpaceStatus_value) + proto.RegisterEnum("coordinator.NodeType", NodeType_name, NodeType_value) proto.RegisterType((*SpaceSignRequest)(nil), "coordinator.SpaceSignRequest") proto.RegisterType((*SpaceStatusPayload)(nil), "coordinator.SpaceStatusPayload") proto.RegisterType((*SpaceSignResponse)(nil), "coordinator.SpaceSignResponse") @@ -682,6 +877,9 @@ func init() { proto.RegisterType((*SpaceStatusCheckResponse)(nil), "coordinator.SpaceStatusCheckResponse") proto.RegisterType((*SpaceStatusChangeRequest)(nil), "coordinator.SpaceStatusChangeRequest") proto.RegisterType((*SpaceStatusChangeResponse)(nil), "coordinator.SpaceStatusChangeResponse") + proto.RegisterType((*NetworkConfigurationRequest)(nil), "coordinator.NetworkConfigurationRequest") + proto.RegisterType((*NetworkConfigurationResponse)(nil), "coordinator.NetworkConfigurationResponse") + proto.RegisterType((*Node)(nil), "coordinator.Node") } func init() { @@ -689,51 +887,61 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 704 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x4f, 0x13, 0x4f, - 0x18, 0xef, 0xb6, 0x05, 0xd2, 0xa7, 0xa4, 0xff, 0x65, 0xfe, 0x80, 0x6b, 0x83, 0x2b, 0x59, 0x95, - 0x34, 0xc4,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53, 0x86, 0x7a, 0x67, 0xd0, 0x2d, 0xf2, 0x1c, 0x6a, 0xfd, 0xe7, - 0x89, 0xdc, 0x2a, 0x68, 0xe4, 0xe0, 0xc9, 0x6d, 0x9a, 0xe3, 0xcc, 0xd9, 0x60, 0xde, 0x42, 0x23, - 0x7f, 0x15, 0x88, 0x95, 0x8b, 0x28, 0xbc, 0x84, 0xcd, 0x3b, 0x13, 0x7d, 0xb2, 0xd4, 0x1f, 0xe4, - 0x17, 0x60, 0x70, 0x01, 0xc8, 0xdd, 0x71, 0x63, 0xcf, 0xa5, 0xbf, 0x77, 0x8d, 0x57, 0x46, 0x70, - 0x20, 0x9f, 0x69, 0x65, 0xe3, 0xc8, 0x84, 0x58, 0xe5, 0xa6, 0x34, 0x57, 0xae, 0x73, 0x4b, 0x39, - 0x9e, 0x3e, 0xfa, 0x79, 0x69, 0x6a, 0x17, 0x97, 0xa6, 0xf6, 0xfb, 0xd2, 0xd4, 0xbe, 0x5e, 0x99, - 0xa5, 0x8b, 0x2b, 0xb3, 0xf4, 0xeb, 0xca, 0x2c, 0xbd, 0x5b, 0x9a, 0xf4, 0x91, 0x3c, 0x98, 0x4e, - 0xfe, 0x6d, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x76, 0x96, 0x0f, 0x4b, 0x07, 0x00, 0x00, + // 856 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xdd, 0x6e, 0xe3, 0x44, + 0x14, 0x8e, 0xe3, 0xb4, 0x25, 0xc7, 0x55, 0x70, 0x87, 0xb6, 0x98, 0x50, 0x4c, 0x64, 0x60, 0x09, + 0x05, 0x75, 0x57, 0x59, 0x40, 0x70, 0x07, 0x64, 0x17, 0x54, 0x84, 0x4a, 0xe5, 0xb6, 0x20, 0xe0, + 0x02, 0x79, 0xed, 0xd3, 0x76, 0xd4, 0xd4, 0xe3, 0x9d, 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0xcd, 0x4c, 0x73, 0x5c, 0xc0, 0x66, 0xdd, 0x56, 0x92, 0x7e, 0x75, 0xda, 0x17, 0x5f, 0x80, + 0xee, 0x3b, 0x77, 0xb0, 0x2c, 0xc8, 0x3e, 0xfb, 0xf0, 0xaf, 0x6b, 0xdf, 0x7a, 0x7e, 0xed, 0x5b, + 0xff, 0x5c, 0xfb, 0xd6, 0x6f, 0x37, 0x7e, 0xe3, 0xf9, 0x8d, 0xdf, 0xf8, 0xfb, 0xc6, 0x6f, 0x7c, + 0xbf, 0xb3, 0xec, 0x5f, 0x9e, 0x27, 0xab, 0xf9, 0xaf, 0x87, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, + 0x69, 0x34, 0x32, 0xd9, 0x19, 0x09, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -1143,6 +1351,137 @@ func (m *SpaceStatusChangeResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } +func (m *NetworkConfigurationRequest) 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 *NetworkConfigurationRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NetworkConfigurationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConfigurationId) > 0 { + i -= len(m.ConfigurationId) + copy(dAtA[i:], m.ConfigurationId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.ConfigurationId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *NetworkConfigurationResponse) 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 *NetworkConfigurationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NetworkConfigurationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Nodes) > 0 { + for iNdEx := len(m.Nodes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Nodes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCoordinator(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.ConfigurationId) > 0 { + i -= len(m.ConfigurationId) + copy(dAtA[i:], m.ConfigurationId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.ConfigurationId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Node) 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 *Node) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Node) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Types) > 0 { + dAtA5 := make([]byte, len(m.Types)*10) + var j4 int + for _, num := range m.Types { + for num >= 1<<7 { + dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j4++ + } + dAtA5[j4] = uint8(num) + j4++ + } + i -= j4 + copy(dAtA[i:], dAtA5[:j4]) + i = encodeVarintCoordinator(dAtA, i, uint64(j4)) + i-- + dAtA[i] = 0x1a + } + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.PeerId) > 0 { + i -= len(m.PeerId) + copy(dAtA[i:], m.PeerId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.PeerId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintCoordinator(dAtA []byte, offset int, v uint64) int { offset -= sovCoordinator(v) base := offset @@ -1333,6 +1672,64 @@ func (m *SpaceStatusChangeResponse) Size() (n int) { return n } +func (m *NetworkConfigurationRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConfigurationId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *NetworkConfigurationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConfigurationId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + if len(m.Nodes) > 0 { + for _, e := range m.Nodes { + l = e.Size() + n += 1 + l + sovCoordinator(uint64(l)) + } + } + return n +} + +func (m *Node) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PeerId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { + l = len(s) + n += 1 + l + sovCoordinator(uint64(l)) + } + } + if len(m.Types) > 0 { + l = 0 + for _, e := range m.Types { + l += sovCoordinator(uint64(e)) + } + n += 1 + sovCoordinator(uint64(l)) + l + } + return n +} + func sovCoordinator(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2535,6 +2932,387 @@ func (m *SpaceStatusChangeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *NetworkConfigurationRequest) 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 ErrIntOverflowCoordinator + } + 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: NetworkConfigurationRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NetworkConfigurationRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConfigurationId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConfigurationId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *NetworkConfigurationResponse) 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 ErrIntOverflowCoordinator + } + 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: NetworkConfigurationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NetworkConfigurationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConfigurationId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConfigurationId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Nodes = append(m.Nodes, &Node{}) + if err := m.Nodes[len(m.Nodes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Node) 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 ErrIntOverflowCoordinator + } + 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: Node: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Node: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PeerId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PeerId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 3: + if wireType == 0 { + var v NodeType + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= NodeType(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Types = append(m.Types, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + if elementCount != 0 && len(m.Types) == 0 { + m.Types = make([]NodeType, 0, elementCount) + } + for iNdEx < postIndex { + var v NodeType + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= NodeType(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Types = append(m.Types, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Types", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipCoordinator(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/coordinator/coordinatorproto/coordinator_drpc.pb.go b/coordinator/coordinatorproto/coordinator_drpc.pb.go index 3fd4e199..75e73a7b 100644 --- a/coordinator/coordinatorproto/coordinator_drpc.pb.go +++ b/coordinator/coordinatorproto/coordinator_drpc.pb.go @@ -44,6 +44,7 @@ type DRPCCoordinatorClient interface { FileLimitCheck(ctx context.Context, in *FileLimitCheckRequest) (*FileLimitCheckResponse, error) SpaceStatusCheck(ctx context.Context, in *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) SpaceStatusChange(ctx context.Context, in *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) + NetworkConfiguration(ctx context.Context, in *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) } type drpcCoordinatorClient struct { @@ -92,11 +93,21 @@ func (c *drpcCoordinatorClient) SpaceStatusChange(ctx context.Context, in *Space return out, nil } +func (c *drpcCoordinatorClient) NetworkConfiguration(ctx context.Context, in *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) { + out := new(NetworkConfigurationResponse) + err := c.cc.Invoke(ctx, "/coordinator.Coordinator/NetworkConfiguration", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, in, out) + if err != nil { + return nil, err + } + return out, nil +} + type DRPCCoordinatorServer interface { SpaceSign(context.Context, *SpaceSignRequest) (*SpaceSignResponse, error) FileLimitCheck(context.Context, *FileLimitCheckRequest) (*FileLimitCheckResponse, error) SpaceStatusCheck(context.Context, *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) SpaceStatusChange(context.Context, *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) + NetworkConfiguration(context.Context, *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) } type DRPCCoordinatorUnimplementedServer struct{} @@ -117,9 +128,13 @@ func (s *DRPCCoordinatorUnimplementedServer) SpaceStatusChange(context.Context, return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } +func (s *DRPCCoordinatorUnimplementedServer) NetworkConfiguration(context.Context, *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + type DRPCCoordinatorDescription struct{} -func (DRPCCoordinatorDescription) NumMethods() int { return 4 } +func (DRPCCoordinatorDescription) NumMethods() int { return 5 } func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { switch n { @@ -159,6 +174,15 @@ func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Rec in1.(*SpaceStatusChangeRequest), ) }, DRPCCoordinatorServer.SpaceStatusChange, true + case 4: + return "/coordinator.Coordinator/NetworkConfiguration", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCCoordinatorServer). + NetworkConfiguration( + ctx, + in1.(*NetworkConfigurationRequest), + ) + }, DRPCCoordinatorServer.NetworkConfiguration, true default: return "", nil, nil, nil, false } @@ -231,3 +255,19 @@ func (x *drpcCoordinator_SpaceStatusChangeStream) SendAndClose(m *SpaceStatusCha } return x.CloseSend() } + +type DRPCCoordinator_NetworkConfigurationStream interface { + drpc.Stream + SendAndClose(*NetworkConfigurationResponse) error +} + +type drpcCoordinator_NetworkConfigurationStream struct { + drpc.Stream +} + +func (x *drpcCoordinator_NetworkConfigurationStream) SendAndClose(m *NetworkConfigurationResponse) error { + if err := x.MsgSend(m, drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}); err != nil { + return err + } + return x.CloseSend() +} diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index b828740c..bffe0998 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -18,6 +18,9 @@ service Coordinator { // SpaceStatusChange changes the status of space rpc SpaceStatusChange(SpaceStatusChangeRequest) returns (SpaceStatusChangeResponse); + + // NetworkConfiguration retrieves the latest network configuration + rpc NetworkConfiguration(NetworkConfigurationRequest) returns (NetworkConfigurationResponse); } message SpaceSignRequest { @@ -103,3 +106,34 @@ message SpaceStatusChangeRequest { message SpaceStatusChangeResponse { SpaceStatusPayload payload = 1; } + +// NetworkConfigurationRequest contains the requested configurationId, it can be empty to request the latest version +message NetworkConfigurationRequest { + string configurationId = 1; +} + +// NetworkConfigurationResponse contains list of nodes +message NetworkConfigurationResponse { + string configurationId = 1; + repeated Node nodes = 2; +} + +// NodeType determines the type of API that a node supports +enum NodeType { + // TreeAPI supports space/tree sync api + TreeAPI = 0; + // FileAPI support file api + FileAPI = 1; + // CoordinatorAPI supports coordinator api + CoordinatorAPI = 2; +} + +// Node describes one node in the network +message Node { + // peerId - it's a peer identifier (libp2p format string) so it's an encoded publicKey + string peerId = 1; + // list of node addresses + repeated string addresses = 2; + // list of supported APIs + repeated NodeType types = 3; +} From 3809b20d505e81e106d76e1e7263a3c1a380fac3 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 26 Mar 2023 16:22:18 +0200 Subject: [PATCH 02/26] expose nodeconf config getter --- nodeconf/config.go | 2 +- nodeconf/service.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nodeconf/config.go b/nodeconf/config.go index 17093019..da92d943 100644 --- a/nodeconf/config.go +++ b/nodeconf/config.go @@ -10,7 +10,7 @@ const ( NodeTypeCoordinator NodeType = "coordinator" ) -type configGetter interface { +type ConfigGetter interface { GetNodes() []NodeConfig } diff --git a/nodeconf/service.go b/nodeconf/service.go index 9b242a0f..473d9df5 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -51,7 +51,7 @@ func (n *Node) Capacity() float64 { } func (s *service) Init(a *app.App) (err error) { - nodesConf := a.MustComponent("config").(configGetter).GetNodes() + nodesConf := a.MustComponent("config").(ConfigGetter).GetNodes() s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId fileConfig := &configuration{ From 6e1c5aab9171539834915d06cf8edd9572871407 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 27 Mar 2023 17:55:27 +0200 Subject: [PATCH 03/26] update nodeconf service --- nodeconf/config.go | 1 + nodeconf/service.go | 46 +++++++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/nodeconf/config.go b/nodeconf/config.go index da92d943..173a8c29 100644 --- a/nodeconf/config.go +++ b/nodeconf/config.go @@ -12,6 +12,7 @@ const ( type ConfigGetter interface { GetNodes() []NodeConfig + GetNodesConfId() string } type NodeConfig struct { diff --git a/nodeconf/service.go b/nodeconf/service.go index 473d9df5..0de898da 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -9,6 +9,8 @@ import ( "github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-chash" "github.com/libp2p/go-libp2p/core/peer" + "go.uber.org/zap" + "sync" ) const CName = "common.nodeconf" @@ -26,13 +28,14 @@ func New() Service { type Service interface { GetLast() Configuration - GetById(id string) Configuration + SetLastConfig(id string, nodes []NodeConfig) (err error) app.Component } type service struct { accountId string last Configuration + mu sync.RWMutex } type Node struct { @@ -51,11 +54,30 @@ func (n *Node) Capacity() float64 { } func (s *service) Init(a *app.App) (err error) { - nodesConf := a.MustComponent("config").(ConfigGetter).GetNodes() + nodesConf := a.MustComponent("config").(ConfigGetter) s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId + return s.SetLastConfig(nodesConf.GetNodesConfId(), nodesConf.GetNodes()) +} + +func (s *service) Name() (name string) { + return CName +} + +func (s *service) GetLast() Configuration { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last +} + +func (s *service) SetLastConfig(id string, nodesConf []NodeConfig) (err error) { + s.mu.Lock() + defer s.mu.Unlock() + if s.last != nil && s.last.Id() == id { + return + } fileConfig := &configuration{ - id: "config", + id: id, accountId: s.accountId, } if fileConfig.chash, err = chash.New(chash.Config{ @@ -89,23 +111,15 @@ func (s *service) Init(a *app.App) (err error) { if err = fileConfig.chash.AddMembers(members...); err != nil { return } + var beforeId = "" + if s.last != nil { + beforeId = s.last.Id() + } + log.Info("configuration changed", zap.String("before", beforeId), zap.String("after", fileConfig.Id())) s.last = fileConfig return } -func (s *service) Name() (name string) { - return CName -} - -func (s *service) GetLast() Configuration { - return s.last -} - -func (s *service) GetById(id string) Configuration { - //TODO implement me - panic("implement me") -} - func nodeFromConfigNode(n NodeConfig) (*Node, error) { p, err := peer.Decode(n.PeerId) if err != nil { From cad467dede8ac6204a54e440e320223b0cdf6e70 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 2 Apr 2023 11:58:42 +0200 Subject: [PATCH 04/26] remove unused --- commonfile/fileproto/file.pb.go | 477 ++++--------------------- commonfile/fileproto/protos/file.proto | 7 - 2 files changed, 66 insertions(+), 418 deletions(-) diff --git a/commonfile/fileproto/file.pb.go b/commonfile/fileproto/file.pb.go index a13658fc..96e1e303 100644 --- a/commonfile/fileproto/file.pb.go +++ b/commonfile/fileproto/file.pb.go @@ -298,94 +298,6 @@ func (m *BlockPushResponse) XXX_DiscardUnknown() { var xxx_messageInfo_BlockPushResponse proto.InternalMessageInfo -type BlocksDeleteRequest struct { - SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - Cids [][]byte `protobuf:"bytes,2,rep,name=cids,proto3" json:"cids,omitempty"` -} - -func (m *BlocksDeleteRequest) Reset() { *m = BlocksDeleteRequest{} } -func (m *BlocksDeleteRequest) String() string { return proto.CompactTextString(m) } -func (*BlocksDeleteRequest) ProtoMessage() {} -func (*BlocksDeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{4} -} -func (m *BlocksDeleteRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BlocksDeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BlocksDeleteRequest.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 *BlocksDeleteRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlocksDeleteRequest.Merge(m, src) -} -func (m *BlocksDeleteRequest) XXX_Size() int { - return m.Size() -} -func (m *BlocksDeleteRequest) XXX_DiscardUnknown() { - xxx_messageInfo_BlocksDeleteRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_BlocksDeleteRequest proto.InternalMessageInfo - -func (m *BlocksDeleteRequest) GetSpaceId() string { - if m != nil { - return m.SpaceId - } - return "" -} - -func (m *BlocksDeleteRequest) GetCids() [][]byte { - if m != nil { - return m.Cids - } - return nil -} - -type BlocksDeleteResponse struct { -} - -func (m *BlocksDeleteResponse) Reset() { *m = BlocksDeleteResponse{} } -func (m *BlocksDeleteResponse) String() string { return proto.CompactTextString(m) } -func (*BlocksDeleteResponse) ProtoMessage() {} -func (*BlocksDeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{5} -} -func (m *BlocksDeleteResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BlocksDeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BlocksDeleteResponse.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 *BlocksDeleteResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlocksDeleteResponse.Merge(m, src) -} -func (m *BlocksDeleteResponse) XXX_Size() int { - return m.Size() -} -func (m *BlocksDeleteResponse) XXX_DiscardUnknown() { - xxx_messageInfo_BlocksDeleteResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_BlocksDeleteResponse proto.InternalMessageInfo - type BlocksCheckRequest struct { SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` Cids [][]byte `protobuf:"bytes,2,rep,name=cids,proto3" json:"cids,omitempty"` @@ -395,7 +307,7 @@ func (m *BlocksCheckRequest) Reset() { *m = BlocksCheckRequest{} } func (m *BlocksCheckRequest) String() string { return proto.CompactTextString(m) } func (*BlocksCheckRequest) ProtoMessage() {} func (*BlocksCheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{6} + return fileDescriptor_fd665a7e11c833d5, []int{4} } func (m *BlocksCheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -446,7 +358,7 @@ func (m *BlocksCheckResponse) Reset() { *m = BlocksCheckResponse{} } func (m *BlocksCheckResponse) String() string { return proto.CompactTextString(m) } func (*BlocksCheckResponse) ProtoMessage() {} func (*BlocksCheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{7} + return fileDescriptor_fd665a7e11c833d5, []int{5} } func (m *BlocksCheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -491,7 +403,7 @@ func (m *BlockAvailability) Reset() { *m = BlockAvailability{} } func (m *BlockAvailability) String() string { return proto.CompactTextString(m) } func (*BlockAvailability) ProtoMessage() {} func (*BlockAvailability) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{8} + return fileDescriptor_fd665a7e11c833d5, []int{6} } func (m *BlockAvailability) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -544,7 +456,7 @@ func (m *BlocksBindRequest) Reset() { *m = BlocksBindRequest{} } func (m *BlocksBindRequest) String() string { return proto.CompactTextString(m) } func (*BlocksBindRequest) ProtoMessage() {} func (*BlocksBindRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{9} + return fileDescriptor_fd665a7e11c833d5, []int{7} } func (m *BlocksBindRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -601,7 +513,7 @@ func (m *BlocksBindResponse) Reset() { *m = BlocksBindResponse{} } func (m *BlocksBindResponse) String() string { return proto.CompactTextString(m) } func (*BlocksBindResponse) ProtoMessage() {} func (*BlocksBindResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{10} + return fileDescriptor_fd665a7e11c833d5, []int{8} } func (m *BlocksBindResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -639,7 +551,7 @@ func (m *FilesDeleteRequest) Reset() { *m = FilesDeleteRequest{} } func (m *FilesDeleteRequest) String() string { return proto.CompactTextString(m) } func (*FilesDeleteRequest) ProtoMessage() {} func (*FilesDeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{11} + return fileDescriptor_fd665a7e11c833d5, []int{9} } func (m *FilesDeleteRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -689,7 +601,7 @@ func (m *FilesDeleteResponse) Reset() { *m = FilesDeleteResponse{} } func (m *FilesDeleteResponse) String() string { return proto.CompactTextString(m) } func (*FilesDeleteResponse) ProtoMessage() {} func (*FilesDeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{12} + return fileDescriptor_fd665a7e11c833d5, []int{10} } func (m *FilesDeleteResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -727,7 +639,7 @@ func (m *FilesInfoRequest) Reset() { *m = FilesInfoRequest{} } func (m *FilesInfoRequest) String() string { return proto.CompactTextString(m) } func (*FilesInfoRequest) ProtoMessage() {} func (*FilesInfoRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{13} + return fileDescriptor_fd665a7e11c833d5, []int{11} } func (m *FilesInfoRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -778,7 +690,7 @@ func (m *FilesInfoResponse) Reset() { *m = FilesInfoResponse{} } func (m *FilesInfoResponse) String() string { return proto.CompactTextString(m) } func (*FilesInfoResponse) ProtoMessage() {} func (*FilesInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{14} + return fileDescriptor_fd665a7e11c833d5, []int{12} } func (m *FilesInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -824,7 +736,7 @@ func (m *FileInfo) Reset() { *m = FileInfo{} } func (m *FileInfo) String() string { return proto.CompactTextString(m) } func (*FileInfo) ProtoMessage() {} func (*FileInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{15} + return fileDescriptor_fd665a7e11c833d5, []int{13} } func (m *FileInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -881,7 +793,7 @@ func (m *CheckRequest) Reset() { *m = CheckRequest{} } func (m *CheckRequest) String() string { return proto.CompactTextString(m) } func (*CheckRequest) ProtoMessage() {} func (*CheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{16} + return fileDescriptor_fd665a7e11c833d5, []int{14} } func (m *CheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -919,7 +831,7 @@ func (m *CheckResponse) Reset() { *m = CheckResponse{} } func (m *CheckResponse) String() string { return proto.CompactTextString(m) } func (*CheckResponse) ProtoMessage() {} func (*CheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{17} + return fileDescriptor_fd665a7e11c833d5, []int{15} } func (m *CheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -970,7 +882,7 @@ func (m *SpaceInfoRequest) Reset() { *m = SpaceInfoRequest{} } func (m *SpaceInfoRequest) String() string { return proto.CompactTextString(m) } func (*SpaceInfoRequest) ProtoMessage() {} func (*SpaceInfoRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{18} + return fileDescriptor_fd665a7e11c833d5, []int{16} } func (m *SpaceInfoRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1017,7 +929,7 @@ func (m *SpaceInfoResponse) Reset() { *m = SpaceInfoResponse{} } func (m *SpaceInfoResponse) String() string { return proto.CompactTextString(m) } func (*SpaceInfoResponse) ProtoMessage() {} func (*SpaceInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{19} + return fileDescriptor_fd665a7e11c833d5, []int{17} } func (m *SpaceInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1081,8 +993,6 @@ func init() { proto.RegisterType((*BlockGetResponse)(nil), "filesync.BlockGetResponse") proto.RegisterType((*BlockPushRequest)(nil), "filesync.BlockPushRequest") proto.RegisterType((*BlockPushResponse)(nil), "filesync.BlockPushResponse") - proto.RegisterType((*BlocksDeleteRequest)(nil), "filesync.BlocksDeleteRequest") - proto.RegisterType((*BlocksDeleteResponse)(nil), "filesync.BlocksDeleteResponse") proto.RegisterType((*BlocksCheckRequest)(nil), "filesync.BlocksCheckRequest") proto.RegisterType((*BlocksCheckResponse)(nil), "filesync.BlocksCheckResponse") proto.RegisterType((*BlockAvailability)(nil), "filesync.BlockAvailability") @@ -1104,59 +1014,58 @@ func init() { } var fileDescriptor_fd665a7e11c833d5 = []byte{ - // 817 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x4f, 0x53, 0xfb, 0x44, - 0x18, 0x6e, 0xda, 0xfc, 0x4a, 0xf3, 0x96, 0x42, 0xba, 0x40, 0xad, 0xa5, 0x66, 0x3a, 0x39, 0x38, - 0x0c, 0xe3, 0x14, 0x07, 0x3d, 0x70, 0xf1, 0x40, 0x4b, 0x0b, 0x15, 0x07, 0x35, 0x8c, 0xc3, 0xa8, - 0x17, 0xd3, 0x64, 0x0b, 0x91, 0x90, 0xad, 0xd9, 0xad, 0x52, 0x3f, 0x82, 0x27, 0xfd, 0x32, 0x7e, - 0x06, 0x8e, 0x1c, 0x3d, 0x3a, 0xf0, 0x45, 0x9c, 0xdd, 0x6c, 0x9a, 0xed, 0x1f, 0x07, 0xc4, 0x4b, - 0xd8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ff, 0x26, 0x23, 0x7f, 0x83, 0xb2, 0x08, 0x00, - 0x00, + // 805 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x52, 0xeb, 0x36, + 0x14, 0x8e, 0x13, 0x13, 0xe2, 0x13, 0x02, 0x8e, 0xf8, 0x69, 0x1a, 0x52, 0x4f, 0xc6, 0x8b, 0x0e, + 0xc3, 0x74, 0x42, 0x87, 0x76, 0xc1, 0xa6, 0x0b, 0x12, 0x12, 0x48, 0xe9, 0xd0, 0xd6, 0x4c, 0x87, + 0x69, 0xbb, 0xa9, 0x63, 0x2b, 0xe0, 0x62, 0xac, 0xd4, 0x52, 0x5a, 0xd2, 0x47, 0xe8, 0xaa, 0x7d, + 0x99, 0x3e, 0x03, 0x4b, 0x96, 0x77, 0x79, 0x07, 0x5e, 0xe4, 0x8e, 0x64, 0x39, 0x56, 0x7e, 0xee, + 0x70, 0x7f, 0x36, 0x8e, 0xf4, 0xe9, 0x9c, 0xf3, 0x1d, 0x7d, 0x92, 0xbe, 0x09, 0x7c, 0xee, 0x91, + 0xbb, 0x3b, 0x12, 0x0d, 0x83, 0x10, 0x1f, 0xf0, 0xcf, 0x28, 0x26, 0x8c, 0x1c, 0x88, 0x2f, 0x15, + 0x40, 0x4b, 0x8c, 0x51, 0x89, 0x8f, 0xe9, 0x24, 0xf2, 0xec, 0x6f, 0x60, 0xa3, 0x1d, 0x12, 0xef, + 0xf6, 0x14, 0x33, 0x07, 0xff, 0x31, 0xc6, 0x94, 0xa1, 0x1a, 0xac, 0xd2, 0x91, 0xeb, 0xe1, 0xbe, + 0x5f, 0xd3, 0x9a, 0xda, 0x9e, 0xe1, 0xa4, 0x53, 0x64, 0x42, 0xc1, 0x0b, 0xfc, 0x5a, 0xbe, 0xa9, + 0xed, 0xad, 0x39, 0x7c, 0x68, 0x1f, 0x81, 0x99, 0xa5, 0xd3, 0x11, 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, 0x99, + 0xa6, 0x5e, 0xa0, 0xca, 0x34, 0x6f, 0x34, 0xaa, 0x4c, 0x8b, 0xe6, 0x71, 0x04, 0x2b, 0x89, 0x40, + 0x3b, 0x59, 0xd4, 0x8c, 0x34, 0x9f, 0x2c, 0xe0, 0x19, 0xff, 0xf4, 0x59, 0xa9, 0xfc, 0xf3, 0x4f, + 0x53, 0xe5, 0x5f, 0x78, 0x87, 0xed, 0xd6, 0xc3, 0x93, 0xa5, 0x3d, 0x3e, 0x59, 0xda, 0xeb, 0x27, + 0x4b, 0xfb, 0xf7, 0xd9, 0xca, 0x3d, 0x3e, 0x5b, 0xb9, 0x57, 0xcf, 0x56, 0xee, 0x97, 0xad, 0x65, + 0x7f, 0x1b, 0x06, 0x45, 0xf1, 0xf3, 0xd5, 0x9b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x45, 0x87, 0x27, + 0x98, 0x55, 0x08, 0x00, 0x00, } func (m *BlockGetRequest) Marshal() (dAtA []byte, err error) { @@ -1307,68 +1216,6 @@ func (m *BlockPushResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *BlocksDeleteRequest) 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 *BlocksDeleteRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BlocksDeleteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Cids) > 0 { - for iNdEx := len(m.Cids) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Cids[iNdEx]) - copy(dAtA[i:], m.Cids[iNdEx]) - i = encodeVarintFile(dAtA, i, uint64(len(m.Cids[iNdEx]))) - i-- - dAtA[i] = 0x12 - } - } - if len(m.SpaceId) > 0 { - i -= len(m.SpaceId) - copy(dAtA[i:], m.SpaceId) - i = encodeVarintFile(dAtA, i, uint64(len(m.SpaceId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *BlocksDeleteResponse) 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 *BlocksDeleteResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BlocksDeleteResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func (m *BlocksCheckRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1944,34 +1791,6 @@ func (m *BlockPushResponse) Size() (n int) { return n } -func (m *BlocksDeleteRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.SpaceId) - if l > 0 { - n += 1 + l + sovFile(uint64(l)) - } - if len(m.Cids) > 0 { - for _, b := range m.Cids { - l = len(b) - n += 1 + l + sovFile(uint64(l)) - } - } - return n -} - -func (m *BlocksDeleteResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - func (m *BlocksCheckRequest) Size() (n int) { if m == nil { return 0 @@ -2668,170 +2487,6 @@ func (m *BlockPushResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *BlocksDeleteRequest) 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 ErrIntOverflowFile - } - 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: BlocksDeleteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BlocksDeleteRequest: 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 ErrIntOverflowFile - } - 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 ErrInvalidLengthFile - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFile - } - 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 Cids", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFile - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthFile - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthFile - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Cids = append(m.Cids, make([]byte, postIndex-iNdEx)) - copy(m.Cids[len(m.Cids)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFile(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFile - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *BlocksDeleteResponse) 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 ErrIntOverflowFile - } - 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: BlocksDeleteResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BlocksDeleteResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipFile(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFile - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *BlocksCheckRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/commonfile/fileproto/protos/file.proto b/commonfile/fileproto/protos/file.proto index 5ebbb91f..3a79543b 100644 --- a/commonfile/fileproto/protos/file.proto +++ b/commonfile/fileproto/protos/file.proto @@ -51,13 +51,6 @@ message BlockPushRequest { message BlockPushResponse {} -message BlocksDeleteRequest { - string spaceId = 1; - repeated bytes cids = 2; -} - -message BlocksDeleteResponse {} - message BlocksCheckRequest { string spaceId = 1; From c66b570396c27ec577cb02f97ca1867da3b76851 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 2 Apr 2023 14:33:07 +0200 Subject: [PATCH 05/26] fix test --- testutil/testnodeconf/testnodeconf.go | 4 ++++ util/strkey/strkey_test.go | 1 + 2 files changed, 5 insertions(+) create mode 100644 util/strkey/strkey_test.go diff --git a/testutil/testnodeconf/testnodeconf.go b/testutil/testnodeconf/testnodeconf.go index 2d6b195e..19b62fcb 100644 --- a/testutil/testnodeconf/testnodeconf.go +++ b/testutil/testnodeconf/testnodeconf.go @@ -31,6 +31,10 @@ type Config struct { func (c *Config) Init(a *app.App) (err error) { return } func (c *Config) Name() string { return "config" } +func (c *Config) GetNodesConfId() string { + return "test" +} + func (c *Config) GetNodes() []nodeconf.NodeConfig { return c.nodes } diff --git a/util/strkey/strkey_test.go b/util/strkey/strkey_test.go new file mode 100644 index 00000000..4652134a --- /dev/null +++ b/util/strkey/strkey_test.go @@ -0,0 +1 @@ +package strkey From cc8c9cb0a5f001b383bac42570a29162c5e709e2 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 2 Apr 2023 14:33:33 +0200 Subject: [PATCH 06/26] mod tidy --- go.mod | 2 +- go.sum | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 985f0f7d..572be159 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/crypto v0.4.0 // indirect - golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect + golang.org/x/image v0.1.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.6.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/go.sum b/go.sum index f547687c..e1d7a22e 100644 --- a/go.sum +++ b/go.sum @@ -462,6 +462,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ= github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg= @@ -505,6 +506,7 @@ golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -521,8 +523,9 @@ golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 h1:fJwx88sMf5RXwDwziL0/Mn9Wq golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg= golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk= +golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -542,6 +545,7 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -573,10 +577,12 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -597,6 +603,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -646,7 +653,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -660,6 +669,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -711,6 +721,7 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 2c73e1947d0063490add3f3ed4ac2fb3703926b7 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 2 Apr 2023 14:34:03 +0200 Subject: [PATCH 07/26] strkey: newtwork id encoding --- util/strkey/strkey_test.go | 18 ++++++++++++++++++ util/strkey/versions.go | 1 + 2 files changed, 19 insertions(+) diff --git a/util/strkey/strkey_test.go b/util/strkey/strkey_test.go index 4652134a..6b23ea27 100644 --- a/util/strkey/strkey_test.go +++ b/util/strkey/strkey_test.go @@ -1 +1,19 @@ package strkey + +import ( + "github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" +) + +func TestDecode(t *testing.T) { + _, pubKey, err := signingkey.GenerateRandomEd25519KeyPair() + require.NoError(t, err) + raw, _ := pubKey.Raw() + str, err := Encode(NetworkAddressVersionByte, raw) + require.NoError(t, err) + res, err := Decode(NetworkAddressVersionByte, str) + require.NoError(t, err) + assert.Equal(t, raw, res) +} diff --git a/util/strkey/versions.go b/util/strkey/versions.go index d59becdf..922e47f8 100644 --- a/util/strkey/versions.go +++ b/util/strkey/versions.go @@ -4,4 +4,5 @@ const ( AccountAddressVersionByte VersionByte = 0x5b // Base58-encodes to 'A...' AccountSeedVersionByte VersionByte = 0xff // Base58-encodes to 'S...' DeviceSeedVersionByte VersionByte = 0x7d // Base58-encodes to 'D...' + NetworkAddressVersionByte VersionByte = 0xd3 // Base58-encodes to `N...` ) From 9cee18c834679a75ae1bca9a88452d07e1a94aaf Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 6 Apr 2023 19:02:18 +0200 Subject: [PATCH 08/26] nodeconf interfaces --- .../coordinatorproto/protos/coordinator.proto | 10 +- go.mod | 12 +- go.sum | 9 + nodeconf/config.go | 37 ++++- nodeconf/{configuration.go => nodeconf.go} | 35 ++-- ...configuration_test.go => nodeconf_test.go} | 2 +- nodeconf/service.go | 154 ++++++++++-------- nodeconf/source.go | 9 + nodeconf/store.go | 10 ++ testutil/accounttest/accountservice.go | 5 +- testutil/testnodeconf/testnodeconf.go | 6 +- 11 files changed, 184 insertions(+), 105 deletions(-) rename nodeconf/{configuration.go => nodeconf.go} (72%) rename nodeconf/{configuration_test.go => nodeconf_test.go} (98%) create mode 100644 nodeconf/source.go create mode 100644 nodeconf/store.go diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index bffe0998..4bfc211b 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -107,15 +107,21 @@ message SpaceStatusChangeResponse { SpaceStatusPayload payload = 1; } -// NetworkConfigurationRequest contains the requested configurationId, it can be empty to request the latest version +// NetworkConfigurationRequest contains currenId of the client configuration, it can be empty message NetworkConfigurationRequest { - string configurationId = 1; + // currenId of the client configuration + // if the currentId is equal to the latest configuration id then the response will not contain a nodes list + string currentId = 1; } // NetworkConfigurationResponse contains list of nodes message NetworkConfigurationResponse { + // id of current configuration string configurationId = 1; + // nodes list - it will be empty if the client's currentId is equal configurationId repeated Node nodes = 2; + // unix timestamp of the creation time of configuration + uint64 creationTimeUnix = 3; } // NodeType determines the type of API that a node supports diff --git a/go.mod b/go.mod index ba9eb925..8a1788c5 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-merkledag v0.10.0 github.com/ipfs/go-unixfs v0.4.5 - github.com/libp2p/go-libp2p v0.24.1 + github.com/libp2p/go-libp2p v0.25.1 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multibase v0.2.0 github.com/multiformats/go-multihash v0.2.1 @@ -37,6 +37,7 @@ require ( golang.org/x/exp v0.0.0-20230206171751-46f607a40771 golang.org/x/net v0.8.0 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 + gopkg.in/yaml.v2 v2.4.0 storj.io/drpc v0.0.32 ) @@ -59,11 +60,12 @@ require ( github.com/ipfs/go-bitfield v1.1.0 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect - github.com/ipfs/go-ipfs-files v0.2.0 // indirect + github.com/ipfs/go-ipfs-files v0.3.0 // indirect github.com/ipfs/go-ipfs-posinfo v0.0.1 // indirect github.com/ipfs/go-ipfs-util v0.0.2 // indirect github.com/ipfs/go-ipld-cbor v0.0.6 // indirect github.com/ipfs/go-ipld-legacy v0.1.1 // indirect + github.com/ipfs/go-libipfs v0.7.0 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/ipfs/go-metrics-interface v0.0.1 // indirect @@ -72,7 +74,7 @@ require ( github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/cpuid/v2 v2.2.2 // indirect + github.com/klauspost/cpuid/v2 v2.2.3 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-openssl v0.1.0 // indirect github.com/mattn/go-isatty v0.0.17 // indirect @@ -83,7 +85,7 @@ require ( github.com/multiformats/go-base36 v0.2.0 // indirect github.com/multiformats/go-multiaddr v0.8.0 // indirect github.com/multiformats/go-multicodec v0.8.0 // indirect - github.com/multiformats/go-multistream v0.3.3 // indirect + github.com/multiformats/go-multistream v0.4.1 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -94,7 +96,7 @@ require ( github.com/prometheus/procfs v0.9.0 // indirect github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 // indirect + github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect go.opentelemetry.io/otel v1.11.2 // indirect go.opentelemetry.io/otel/trace v1.11.2 // indirect diff --git a/go.sum b/go.sum index 2120dbdc..73d1b08f 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,8 @@ github.com/ipfs/go-ipfs-exchange-interface v0.2.0/go.mod h1:z6+RhJuDQbqKguVyslSO github.com/ipfs/go-ipfs-exchange-offline v0.3.0 h1:c/Dg8GDPzixGd0MC8Jh6mjOwU57uYokgWRFidfvEkuA= github.com/ipfs/go-ipfs-files v0.2.0 h1:z6MCYHQSZpDWpUSK59Kf0ajP1fi4gLCf6fIulVsp8A8= github.com/ipfs/go-ipfs-files v0.2.0/go.mod h1:vT7uaQfIsprKktzbTPLnIsd+NGw9ZbYwSq0g3N74u0M= +github.com/ipfs/go-ipfs-files v0.3.0 h1:fallckyc5PYjuMEitPNrjRfpwl7YFt69heCOUhsbGxQ= +github.com/ipfs/go-ipfs-files v0.3.0/go.mod h1:xAUtYMwB+iu/dtf6+muHNSFQCJG2dSiStR2P6sn9tIM= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= @@ -134,6 +136,8 @@ github.com/ipfs/go-ipld-format v0.4.0 h1:yqJSaJftjmjc9jEOFYlpkwOLVKv68OD27jFLlSg github.com/ipfs/go-ipld-format v0.4.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc= github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fOmKZkkFkrIEg= +github.com/ipfs/go-libipfs v0.7.0 h1:Mi54WJTODaOL2/ZSm5loi3SwI3jI2OuFWUrQIkJ5cpM= +github.com/ipfs/go-libipfs v0.7.0/go.mod h1:KsIf/03CqhICzyRGyGo68tooiBE2iFbI/rXW7FhAYr0= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= @@ -171,6 +175,7 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.2.2 h1:xPMwiykqNK9VK0NYC3+jTMYv9I6Vl3YdjZgPZKG3zO0= github.com/klauspost/cpuid/v2 v2.2.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/koron/go-ssdp v0.0.3 h1:JivLMY45N76b4p/vsWGOKewBQu6uf39y8l+AQ7sDKx8= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -185,6 +190,7 @@ github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QT github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= github.com/libp2p/go-libp2p v0.24.1 h1:+lS4fqj7RF9egcPq9Yo3iqdRTcDMApzoBbQMhxtwOVw= github.com/libp2p/go-libp2p v0.24.1/go.mod h1:5LJqbrqFsUzWrq70JHCYqjATlX4ey8Klpct3OEe8hSI= +github.com/libp2p/go-libp2p v0.25.1/go.mod h1:xnK9/1d9+jeQCVvi/f1g12KqtVi/jP/SijtKV1hML3g= github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= @@ -239,6 +245,7 @@ github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc= github.com/multiformats/go-multistream v0.3.3 h1:d5PZpjwRgVlbwfdTDjife7XszfZd8KYWfROYFlGcR8o= github.com/multiformats/go-multistream v0.3.3/go.mod h1:ODRoqamLUsETKS9BNcII4gcRsJBU5VAwRIv7O39cEXg= +github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= @@ -301,6 +308,7 @@ github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvS github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 h1:obKzQ1ey5AJg5NKjgtTo/CKwLImVP4ETLRcsmzFJ4Qw= github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= @@ -442,6 +450,7 @@ gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3M gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/nodeconf/config.go b/nodeconf/config.go index 4fef1fae..1ef1f5ed 100644 --- a/nodeconf/config.go +++ b/nodeconf/config.go @@ -1,5 +1,18 @@ package nodeconf +import ( + "errors" + "time" +) + +type ConfigGetter interface { + GetNodeConf() Configuration +} + +var ( + ErrConfigurationNotFound = errors.New("node nodeConf not found") +) + type NodeType string const ( @@ -10,18 +23,21 @@ const ( NodeTypeCoordinator NodeType = "coordinator" ) -type ConfigGetter interface { - GetNodes() []NodeConfig - GetNodesConfId() string -} - -type NodeConfig struct { +type Node struct { PeerId string `yaml:"peerId"` Addresses []string `yaml:"address"` Types []NodeType `yaml:"types,omitempty"` } -func (n NodeConfig) HasType(t NodeType) bool { +func (n Node) Id() string { + return n.PeerId +} + +func (n Node) Capacity() float64 { + return 1 +} + +func (n Node) HasType(t NodeType) bool { for _, nt := range n.Types { if nt == t { return true @@ -29,3 +45,10 @@ func (n NodeConfig) HasType(t NodeType) bool { } return false } + +type Configuration struct { + Id string `yaml:"id"` + NetworkId string `yaml:"networkId"` + Nodes []Node `yaml:"nodes"` + CreationTime time.Time `yaml:"creationTime"` +} diff --git a/nodeconf/configuration.go b/nodeconf/nodeconf.go similarity index 72% rename from nodeconf/configuration.go rename to nodeconf/nodeconf.go index 121b79fa..c7be0a90 100644 --- a/nodeconf/configuration.go +++ b/nodeconf/nodeconf.go @@ -1,4 +1,4 @@ -//go:generate mockgen -destination mock_nodeconf/mock_nodeconf.go github.com/anytypeio/any-sync/nodeconf Service,Configuration +//go:generate mockgen -destination mock_nodeconf/mock_nodeconf.go github.com/anytypeio/any-sync/nodeconf Service package nodeconf import ( @@ -6,9 +6,11 @@ import ( "strings" ) -type Configuration interface { +type NodeConf interface { // Id returns current nodeconf id Id() string + // Configuration returns configuration struct + Configuration() Configuration // NodeIds returns list of peerId for given spaceId NodeIds(spaceId string) []string // IsResponsible checks if current account responsible for given spaceId @@ -29,21 +31,26 @@ type Configuration interface { NodeTypes(nodeId string) []NodeType } -type configuration struct { +type nodeConf struct { id string accountId string filePeers []string consensusPeers []string coordinatorPeers []string chash chash.CHash - allMembers []NodeConfig + allMembers []Node + c Configuration } -func (c *configuration) Id() string { +func (c *nodeConf) Id() string { return c.id } -func (c *configuration) NodeIds(spaceId string) []string { +func (c *nodeConf) Configuration() Configuration { + return c.c +} + +func (c *nodeConf) NodeIds(spaceId string) []string { members := c.chash.GetMembers(ReplKey(spaceId)) res := make([]string, 0, len(members)) for _, m := range members { @@ -54,7 +61,7 @@ func (c *configuration) NodeIds(spaceId string) []string { return res } -func (c *configuration) IsResponsible(spaceId string) bool { +func (c *nodeConf) IsResponsible(spaceId string) bool { for _, m := range c.chash.GetMembers(ReplKey(spaceId)) { if m.Id() == c.accountId { return true @@ -63,19 +70,19 @@ func (c *configuration) IsResponsible(spaceId string) bool { return false } -func (c *configuration) FilePeers() []string { +func (c *nodeConf) FilePeers() []string { return c.filePeers } -func (c *configuration) ConsensusPeers() []string { +func (c *nodeConf) ConsensusPeers() []string { return c.consensusPeers } -func (c *configuration) CoordinatorPeers() []string { +func (c *nodeConf) CoordinatorPeers() []string { return c.coordinatorPeers } -func (c *configuration) Addresses() map[string][]string { +func (c *nodeConf) Addresses() map[string][]string { res := make(map[string][]string) for _, m := range c.allMembers { res[m.PeerId] = m.Addresses @@ -83,15 +90,15 @@ func (c *configuration) Addresses() map[string][]string { return res } -func (c *configuration) CHash() chash.CHash { +func (c *nodeConf) CHash() chash.CHash { return c.chash } -func (c *configuration) Partition(spaceId string) (part int) { +func (c *nodeConf) Partition(spaceId string) (part int) { return c.chash.GetPartition(ReplKey(spaceId)) } -func (c *configuration) NodeTypes(nodeId string) []NodeType { +func (c *nodeConf) NodeTypes(nodeId string) []NodeType { for _, m := range c.allMembers { if m.PeerId == nodeId { return m.Types diff --git a/nodeconf/configuration_test.go b/nodeconf/nodeconf_test.go similarity index 98% rename from nodeconf/configuration_test.go rename to nodeconf/nodeconf_test.go index fee5eefb..3d73af80 100644 --- a/nodeconf/configuration_test.go +++ b/nodeconf/nodeconf_test.go @@ -21,7 +21,7 @@ func TestConfiguration_NodeIds(t *testing.T) { ReplicationFactor: ReplicationFactor, }) require.NoError(t, err) - conf := &configuration{ + conf := &nodeConf{ id: "last", accountId: "1", chash: ch, diff --git a/nodeconf/service.go b/nodeconf/service.go index e7fb5907..eb29d70c 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -4,9 +4,7 @@ import ( commonaccount "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" - "github.com/anytypeio/any-sync/util/crypto" "github.com/anytypeio/go-chash" - "github.com/libp2p/go-libp2p/core/peer" "go.uber.org/zap" "sync" ) @@ -25,121 +23,135 @@ func New() Service { } type Service interface { - GetLast() Configuration - SetLastConfig(id string, nodes []NodeConfig) (err error) + NodeConf app.Component } type service struct { accountId string - last Configuration + last NodeConf mu sync.RWMutex } -type Node struct { - Addresses []string - PeerId string - SigningKey crypto.PubKey -} - -func (n *Node) Id() string { - return n.PeerId -} - -func (n *Node) Capacity() float64 { - return 1 -} - func (s *service) Init(a *app.App) (err error) { nodesConf := a.MustComponent("config").(ConfigGetter) s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId - return s.SetLastConfig(nodesConf.GetNodesConfId(), nodesConf.GetNodes()) + return s.setLastConfiguration(nodesConf.GetNodeConf()) } func (s *service) Name() (name string) { return CName } -func (s *service) GetLast() Configuration { - s.mu.RLock() - defer s.mu.RUnlock() - return s.last -} - -func (s *service) SetLastConfig(id string, nodesConf []NodeConfig) (err error) { +func (s *service) setLastConfiguration(c Configuration) (err error) { s.mu.Lock() defer s.mu.Unlock() - if s.last != nil && s.last.Id() == id { + if s.last != nil && s.last.Id() == c.Id { return } - fileConfig := &configuration{ - id: id, + nc := &nodeConf{ + id: c.Id, + c: c, accountId: s.accountId, } - if fileConfig.chash, err = chash.New(chash.Config{ + if nc.chash, err = chash.New(chash.Config{ PartitionCount: PartitionCount, ReplicationFactor: ReplicationFactor, }); err != nil { return } - members := make([]chash.Member, 0, len(nodesConf)) - for _, n := range nodesConf { + members := make([]chash.Member, 0, len(c.Nodes)) + for _, n := range c.Nodes { if n.HasType(NodeTypeTree) { - var member *Node - member, err = nodeFromConfigNode(n) - if err != nil { - return - } - members = append(members, member) + members = append(members, n) } if n.HasType(NodeTypeConsensus) { - fileConfig.consensusPeers = append(fileConfig.consensusPeers, n.PeerId) + nc.consensusPeers = append(nc.consensusPeers, n.PeerId) } if n.HasType(NodeTypeFile) { - fileConfig.filePeers = append(fileConfig.filePeers, n.PeerId) + nc.filePeers = append(nc.filePeers, n.PeerId) } if n.HasType(NodeTypeCoordinator) { - fileConfig.coordinatorPeers = append(fileConfig.coordinatorPeers, n.PeerId) + nc.coordinatorPeers = append(nc.coordinatorPeers, n.PeerId) } - fileConfig.allMembers = append(fileConfig.allMembers, n) + nc.allMembers = append(nc.allMembers, n) } - if err = fileConfig.chash.AddMembers(members...); err != nil { + if err = nc.chash.AddMembers(members...); err != nil { return } var beforeId = "" if s.last != nil { beforeId = s.last.Id() } - log.Info("configuration changed", zap.String("before", beforeId), zap.String("after", fileConfig.Id())) - s.last = fileConfig + log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id())) + s.last = nc return } -func nodeFromConfigNode(n NodeConfig) (*Node, error) { - p, err := peer.Decode(n.PeerId) - if err != nil { - return nil, err - } - ic, err := p.ExtractPublicKey() - if err != nil { - return nil, err - } - - icRaw, err := ic.Raw() - if err != nil { - return nil, err - } - - sigPubKey, err := crypto.UnmarshalEd25519PublicKey(icRaw) - if err != nil { - return nil, err - } - - return &Node{ - Addresses: n.Addresses, - PeerId: n.PeerId, - SigningKey: sigPubKey, - }, nil +func (s *service) Id() string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Id() +} + +func (s *service) Configuration() Configuration { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Configuration() +} + +func (s *service) NodeIds(spaceId string) []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.NodeIds(spaceId) +} + +func (s *service) IsResponsible(spaceId string) bool { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.IsResponsible(spaceId) +} + +func (s *service) FilePeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.FilePeers() +} + +func (s *service) ConsensusPeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.ConsensusPeers() +} + +func (s *service) CoordinatorPeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.CoordinatorPeers() +} + +func (s *service) Addresses() map[string][]string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Addresses() +} + +func (s *service) CHash() chash.CHash { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.CHash() +} + +func (s *service) Partition(spaceId string) (part int) { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Partition(spaceId) +} + +func (s *service) NodeTypes(nodeId string) []NodeType { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.NodeTypes(nodeId) } diff --git a/nodeconf/source.go b/nodeconf/source.go new file mode 100644 index 00000000..85e60aaa --- /dev/null +++ b/nodeconf/source.go @@ -0,0 +1,9 @@ +package nodeconf + +import "context" + +const CNameSource = "common.nodeconf.source" + +type Source interface { + GetLast(ctx context.Context) (c Configuration, err error) +} diff --git a/nodeconf/store.go b/nodeconf/store.go new file mode 100644 index 00000000..70b1e644 --- /dev/null +++ b/nodeconf/store.go @@ -0,0 +1,10 @@ +package nodeconf + +import "context" + +const CNameStore = "common.nodeconf.store" + +type Store interface { + GetLast(ctx context.Context, netId string) (c Configuration, err error) + SaveLast(ctx context.Context, c Configuration) (err error) +} diff --git a/testutil/accounttest/accountservice.go b/testutil/accounttest/accountservice.go index 7aec1c14..3c9f6e11 100644 --- a/testutil/accounttest/accountservice.go +++ b/testutil/accounttest/accountservice.go @@ -5,6 +5,7 @@ import ( "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/commonspace/object/accountdata" "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/nodeconf/nodeconfstore" "github.com/anytypeio/any-sync/util/crypto" ) @@ -47,8 +48,8 @@ func (s *AccountTestService) Account() *accountdata.AccountKeys { return s.acc } -func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig { - return nodeconf.NodeConfig{ +func (s *AccountTestService) NodeConf(addrs []string) nodeconfstore.NodeConfig { + return nodeconfstore.NodeConfig{ PeerId: s.acc.PeerId, Addresses: addrs, Types: []nodeconf.NodeType{nodeconf.NodeTypeTree}, diff --git a/testutil/testnodeconf/testnodeconf.go b/testutil/testnodeconf/testnodeconf.go index 19b62fcb..118fcfdd 100644 --- a/testutil/testnodeconf/testnodeconf.go +++ b/testutil/testnodeconf/testnodeconf.go @@ -3,7 +3,7 @@ package testnodeconf import ( "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" - "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/nodeconf/nodeconfstore" "github.com/anytypeio/any-sync/testutil/accounttest" ) @@ -24,7 +24,7 @@ func GenNodeConfig(num int) (conf *Config) { } type Config struct { - nodes []nodeconf.NodeConfig + nodes []nodeconfstore.NodeConfig configs []*accounttest.AccountTestService } @@ -35,7 +35,7 @@ func (c *Config) GetNodesConfId() string { return "test" } -func (c *Config) GetNodes() []nodeconf.NodeConfig { +func (c *Config) GetNodes() []nodeconfstore.NodeConfig { return c.nodes } From c843b27b192af424912e76b1fdc25fba1c4f2d04 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sat, 8 Apr 2023 17:01:40 +0200 Subject: [PATCH 09/26] coord nodeconf source, nodeconf service updates --- .../coordinatorclient/coordinatorclient.go | 16 ++ .../coordinatorproto/coordinator.pb.go | 177 ++++++++++++------ .../coordinatorproto/protos/coordinator.proto | 6 +- coordinator/nodeconfsource/nodeconfsource.go | 56 ++++++ nodeconf/nodeconf.go | 2 +- nodeconf/service.go | 50 ++++- nodeconf/source.go | 11 +- 7 files changed, 248 insertions(+), 70 deletions(-) create mode 100644 coordinator/nodeconfsource/nodeconfsource.go diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index 7847b1da..5dc58c64 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -23,6 +23,7 @@ type CoordinatorClient interface { StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) SpaceSign(ctx context.Context, payload SpaceSignPayload) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error) + NetworkConfiguration(ctx context.Context, currentId string) (*coordinatorproto.NetworkConfigurationResponse, error) app.Component } @@ -128,6 +129,21 @@ func (c *coordinatorClient) FileLimitCheck(ctx context.Context, spaceId string, return resp.Limit, nil } +func (c *coordinatorClient) NetworkConfiguration(ctx context.Context, currentId string) (resp *coordinatorproto.NetworkConfigurationResponse, err error) { + cl, err := c.client(ctx) + if err != nil { + return + } + resp, err = cl.NetworkConfiguration(ctx, &coordinatorproto.NetworkConfigurationRequest{ + CurrentId: currentId, + }) + if err != nil { + err = rpcerr.Unwrap(err) + return + } + return +} + func (c *coordinatorClient) client(ctx context.Context) (coordinatorproto.DRPCCoordinatorClient, error) { p, err := c.pool.GetOneOf(ctx, c.nodeConf.CoordinatorPeers()) if err != nil { diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index 69689d27..a08e0891 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -771,10 +771,12 @@ func (m *NetworkConfigurationRequest) GetCurrentId() string { type NetworkConfigurationResponse struct { // id of current configuration ConfigurationId string `protobuf:"bytes,1,opt,name=configurationId,proto3" json:"configurationId,omitempty"` + // network id + NetworkId string `protobuf:"bytes,2,opt,name=networkId,proto3" json:"networkId,omitempty"` // nodes list - it will be empty if the client's currentId is equal configurationId - Nodes []*Node `protobuf:"bytes,2,rep,name=nodes,proto3" json:"nodes,omitempty"` + Nodes []*Node `protobuf:"bytes,3,rep,name=nodes,proto3" json:"nodes,omitempty"` // unix timestamp of the creation time of configuration - CreationTimeUnix uint64 `protobuf:"varint,3,opt,name=creationTimeUnix,proto3" json:"creationTimeUnix,omitempty"` + CreationTimeUnix uint64 `protobuf:"varint,4,opt,name=creationTimeUnix,proto3" json:"creationTimeUnix,omitempty"` } func (m *NetworkConfigurationResponse) Reset() { *m = NetworkConfigurationResponse{} } @@ -817,6 +819,13 @@ func (m *NetworkConfigurationResponse) GetConfigurationId() string { return "" } +func (m *NetworkConfigurationResponse) GetNetworkId() string { + if m != nil { + return m.NetworkId + } + return "" +} + func (m *NetworkConfigurationResponse) GetNodes() []*Node { if m != nil { return m.Nodes @@ -920,64 +929,65 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 911 bytes of a gzipped FileDescriptorProto + // 918 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x6e, 0x23, 0x45, - 0x10, 0xf6, 0xd8, 0x4e, 0x82, 0x6b, 0x22, 0xef, 0xa4, 0x49, 0xc2, 0x60, 0xcc, 0x60, 0x0d, 0xb0, - 0x98, 0x80, 0xb2, 0x2b, 0x2f, 0x20, 0x10, 0x17, 0xc0, 0x2c, 0x52, 0x10, 0x0a, 0xd1, 0x24, 0x06, - 0x01, 0x07, 0x34, 0x3b, 0x53, 0x49, 0x5a, 0x71, 0xba, 0x87, 0xee, 0x36, 0x9b, 0x1c, 0x90, 0x78, - 0x04, 0x4e, 0x1c, 0x90, 0x78, 0x03, 0x1e, 0x81, 0x07, 0xe0, 0x98, 0x23, 0x47, 0x94, 0x48, 0x3c, - 0x07, 0xea, 0xf9, 0xb1, 0x7b, 0xec, 0x71, 0x82, 0xb4, 0x17, 0xdb, 0xfd, 0xd5, 0xef, 0x57, 0x55, - 0x5d, 0x6d, 0x78, 0x37, 0xe2, 0x5c, 0xc4, 0x94, 0x85, 0x8a, 0x8b, 0x07, 0xc6, 0xef, 0x44, 0x70, - 0xc5, 0x1f, 0xa4, 0x9f, 0xd2, 0xc4, 0x77, 0x53, 0x88, 0xd8, 0x06, 0xe4, 0xff, 0x66, 0x81, 0x73, - 0x98, 0x84, 0x11, 0x1e, 0xd2, 0x13, 0x16, 0xe0, 0x0f, 0x13, 0x94, 0x8a, 0xb8, 0xb0, 0x26, 0x35, - 0xb6, 0x17, 0xbb, 0x56, 0xcf, 0xea, 0xb7, 0x82, 0xe2, 0x48, 0xb6, 0x61, 0xf5, 0x14, 0xc3, 0x18, - 0x85, 0x5b, 0xef, 0x59, 0xfd, 0xf5, 0x20, 0x3f, 0x91, 0x1e, 0xd8, 0x7c, 0x1c, 0xef, 0xc5, 0xc8, - 0x14, 0x55, 0x97, 0x6e, 0x23, 0x15, 0x9a, 0x10, 0x19, 0xc0, 0x26, 0xc3, 0xa7, 0xc5, 0x51, 0x47, - 0x0b, 0xd5, 0x44, 0xa0, 0xdb, 0x4c, 0x55, 0x2b, 0x65, 0xbe, 0x02, 0x92, 0xe5, 0xa6, 0x42, 0x35, - 0x91, 0x07, 0xe1, 0xe5, 0x98, 0x87, 0x31, 0x79, 0x08, 0xab, 0x32, 0x05, 0xd2, 0xe4, 0xda, 0x03, - 0x77, 0xd7, 0xe4, 0x68, 0x18, 0x04, 0xb9, 0x1e, 0x79, 0x1b, 0x36, 0x62, 0x1c, 0xa3, 0xa2, 0x9c, - 0x1d, 0xd1, 0x73, 0x94, 0x2a, 0x3c, 0x4f, 0x52, 0x02, 0x8d, 0x60, 0x51, 0xe0, 0x8f, 0x60, 0xc3, - 0xa8, 0x88, 0x4c, 0x38, 0x93, 0x48, 0x3e, 0x82, 0x35, 0x81, 0x11, 0xd2, 0x44, 0xa5, 0x51, 0xed, - 0xc1, 0xfd, 0xc5, 0xa8, 0x41, 0xa6, 0xf0, 0x35, 0x55, 0xa7, 0x53, 0x0e, 0x41, 0x61, 0xe6, 0x9f, - 0xc1, 0x8b, 0x4b, 0xb5, 0xc8, 0x43, 0x78, 0x5e, 0x1a, 0xc2, 0x9c, 0x6a, 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29, 0x17, 0x67, 0x23, 0xce, 0x8e, 0xe9, 0xc9, 0x54, 0x04, 0x3a, + 0x78, 0x4e, 0xb9, 0x07, 0xad, 0x70, 0x2a, 0x04, 0xea, 0xc6, 0x67, 0xa4, 0x67, 0x80, 0xf7, 0x87, + 0x05, 0xbd, 0x6a, 0xeb, 0x2c, 0xb1, 0x01, 0xdc, 0x0b, 0x4d, 0x41, 0xe1, 0x64, 0x1e, 0xd6, 0x81, + 0x58, 0xea, 0xa9, 0x28, 0xdd, 0x0c, 0x20, 0x6f, 0xc0, 0x0a, 0xe3, 0x11, 0x4a, 0xa7, 0xd1, 0x6f, + 0x0c, 0xda, 0xc3, 0x8d, 0x12, 0x3d, 0x3d, 0xf9, 0x7e, 0x2a, 0xd7, 0x8d, 0x08, 0x05, 0x06, 0xf9, + 0xc2, 0x19, 0x33, 0x7a, 0x91, 0xdc, 0x93, 0xa6, 0xbf, 0x80, 0x7b, 0x14, 0x9a, 0xda, 0xd4, 0xb8, + 0xa0, 0x56, 0xe9, 0x82, 0xf6, 0xa0, 0x15, 0x44, 0x91, 0x40, 0x29, 0x51, 0x3a, 0xf5, 0x7e, 0x43, + 0xa7, 0x54, 0x00, 0xe4, 0x2d, 0x58, 0x51, 0x97, 0x71, 0x96, 0x52, 0x67, 0xb8, 0xb5, 0x90, 0xd2, + 0xd1, 0x65, 0x8c, 0x7e, 0xaa, 0xb3, 0xf3, 0xb3, 0x05, 0xf0, 0x58, 0x08, 0x2e, 0x46, 0x49, 0x96, + 0x1d, 0x80, 0x31, 0xc3, 0x8b, 0x18, 0x43, 0x85, 0x91, 0x5d, 0x23, 0x76, 0xb6, 0x4c, 0x3e, 0xd5, + 0xad, 0xc7, 0xc8, 0xb6, 0x88, 0x03, 0x9b, 0x33, 0x84, 0x72, 0x76, 0x80, 0x2c, 0xa2, 0xec, 0xc4, + 0xae, 0x17, 0xba, 0x23, 0x4d, 0x07, 0x23, 0xbb, 0x41, 0x08, 0x74, 0x12, 0x64, 0x9f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, 0x3e, 0x79, 0xef, 0xaf, 0x6b, 0xd7, 0xba, 0xba, 0x76, 0xad, 0x7f, 0xae, + 0x5d, 0xeb, 0x97, 0x1b, 0xb7, 0x76, 0x75, 0xe3, 0xd6, 0xfe, 0xbe, 0x71, 0x6b, 0xdf, 0xf6, 0x6e, + 0xfb, 0x23, 0xf6, 0x64, 0x35, 0xf9, 0x7a, 0xf4, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0x5e, + 0x22, 0xba, 0xaf, 0x09, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -1454,7 +1464,7 @@ func (m *NetworkConfigurationResponse) MarshalToSizedBuffer(dAtA []byte) (int, e if m.CreationTimeUnix != 0 { i = encodeVarintCoordinator(dAtA, i, uint64(m.CreationTimeUnix)) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x20 } if len(m.Nodes) > 0 { for iNdEx := len(m.Nodes) - 1; iNdEx >= 0; iNdEx-- { @@ -1467,9 +1477,16 @@ func (m *NetworkConfigurationResponse) MarshalToSizedBuffer(dAtA []byte) (int, e i = encodeVarintCoordinator(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } } + if len(m.NetworkId) > 0 { + i -= len(m.NetworkId) + copy(dAtA[i:], m.NetworkId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.NetworkId))) + i-- + dAtA[i] = 0x12 + } if len(m.ConfigurationId) > 0 { i -= len(m.ConfigurationId) copy(dAtA[i:], m.ConfigurationId) @@ -1758,6 +1775,10 @@ func (m *NetworkConfigurationResponse) Size() (n int) { if l > 0 { n += 1 + l + sovCoordinator(uint64(l)) } + l = len(m.NetworkId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } if len(m.Nodes) > 0 { for _, e := range m.Nodes { l = e.Size() @@ -3210,6 +3231,38 @@ func (m *NetworkConfigurationResponse) Unmarshal(dAtA []byte) error { m.ConfigurationId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NetworkId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NetworkId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType) } @@ -3243,7 +3296,7 @@ func (m *NetworkConfigurationResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field CreationTimeUnix", wireType) } diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index 916a4e21..804957a1 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -124,10 +124,12 @@ message NetworkConfigurationRequest { message NetworkConfigurationResponse { // id of current configuration string configurationId = 1; + // network id + string networkId = 2; // nodes list - it will be empty if the client's currentId is equal configurationId - repeated Node nodes = 2; + repeated Node nodes = 3; // unix timestamp of the creation time of configuration - uint64 creationTimeUnix = 3; + uint64 creationTimeUnix = 4; } // NodeType determines the type of API that a node supports diff --git a/coordinator/nodeconfsource/nodeconfsource.go b/coordinator/nodeconfsource/nodeconfsource.go new file mode 100644 index 00000000..3ea44d45 --- /dev/null +++ b/coordinator/nodeconfsource/nodeconfsource.go @@ -0,0 +1,56 @@ +package nodeconfsource + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/coordinator/coordinatorclient" + "github.com/anytypeio/any-sync/nodeconf" + "time" +) + +type NodeConfSource interface { + app.Component + nodeconf.Source +} + +type nodeConfSource struct { + cl coordinatorclient.CoordinatorClient +} + +func (n *nodeConfSource) Init(a *app.App) (err error) { + n.cl = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient) + return nil +} + +func (n *nodeConfSource) Name() (name string) { + return nodeconf.CNameSource +} + +func (n *nodeConfSource) GetLast(ctx context.Context, currentId string) (c nodeconf.Configuration, err error) { + res, err := n.cl.NetworkConfiguration(ctx, currentId) + if err != nil { + return + } + if res.ConfigurationId == currentId { + err = nodeconf.ErrConfigurationNotChanged + return + } + nodes := make([]nodeconf.Node, len(res.Nodes)) + for i, node := range res.Nodes { + types := make([]nodeconf.NodeType, len(node.Types)) + for j, nt := range node.Types { + types[j] = nodeconf.NodeType(nt) + } + nodes[i] = nodeconf.Node{ + PeerId: node.PeerId, + Addresses: node.Addresses, + Types: types, + } + } + return nodeconf.Configuration{ + Id: res.ConfigurationId, + NetworkId: res.NetworkId, + Nodes: nodes, + CreationTime: time.Unix(int64(res.CreationTimeUnix), 0), + }, nil +} diff --git a/nodeconf/nodeconf.go b/nodeconf/nodeconf.go index 5898974b..3d673fe8 100644 --- a/nodeconf/nodeconf.go +++ b/nodeconf/nodeconf.go @@ -21,7 +21,7 @@ type NodeConf interface { ConsensusPeers() []string // CoordinatorPeers returns list of coordinator nodes CoordinatorPeers() []string - // Addresses returns map[peerId][]addr with connection addresses for all known nodes + // PeerAddresses returns peer addresses by peer id PeerAddresses(peerId string) (addrs []string, ok bool) // CHash returns nodes consistent table CHash() chash.CHash diff --git a/nodeconf/service.go b/nodeconf/service.go index 34897cb8..6331856f 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -1,12 +1,14 @@ package nodeconf import ( + "context" commonaccount "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/go-chash" "go.uber.org/zap" "sync" + "time" ) const CName = "common.nodeconf" @@ -24,25 +26,63 @@ func New() Service { type Service interface { NodeConf - app.Component + app.ComponentRunnable } type service struct { accountId string + config Configuration + source Source + store Store last NodeConf mu sync.RWMutex } func (s *service) Init(a *app.App) (err error) { - nodesConf := a.MustComponent("config").(ConfigGetter) + s.config = a.MustComponent("config").(ConfigGetter).GetNodeConf() s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId - return s.setLastConfiguration(nodesConf.GetNodeConf()) + s.source = a.MustComponent(CNameSource).(Source) + s.store = a.MustComponent(CNameStore).(Store) + lastStored, err := s.store.GetLast(context.Background(), s.config.NetworkId) + if err == ErrConfigurationNotFound { + lastStored = s.config + err = nil + } + return s.setLastConfiguration(lastStored) } func (s *service) Name() (name string) { return CName } +func (s *service) Run(_ context.Context) (err error) { + go s.updateLoop(context.Background()) + return +} + +func (s *service) updateLoop(ctx context.Context) { + for _ = range time.NewTicker(time.Minute * 10).C { + err := s.updateConfiguration(ctx) + if err != nil { + if err == ErrConfigurationNotChanged { + continue + } + log.Info("can't update configuration", zap.Error(err)) + } + } +} + +func (s *service) updateConfiguration(ctx context.Context) (err error) { + last, err := s.source.GetLast(ctx, s.Configuration().Id) + if err != nil { + return + } + if err = s.store.SaveLast(ctx, last); err != nil { + return + } + return s.setLastConfiguration(last) +} + func (s *service) setLastConfiguration(c Configuration) (err error) { s.mu.Lock() defer s.mu.Unlock() @@ -157,3 +197,7 @@ func (s *service) NodeTypes(nodeId string) []NodeType { defer s.mu.RUnlock() return s.last.NodeTypes(nodeId) } + +func (s *service) Close(ctx context.Context) (err error) { + return +} diff --git a/nodeconf/source.go b/nodeconf/source.go index 85e60aaa..56ea2c54 100644 --- a/nodeconf/source.go +++ b/nodeconf/source.go @@ -1,9 +1,16 @@ package nodeconf -import "context" +import ( + "context" + "errors" +) const CNameSource = "common.nodeconf.source" +var ( + ErrConfigurationNotChanged = errors.New("configuration not changed") +) + type Source interface { - GetLast(ctx context.Context) (c Configuration, err error) + GetLast(ctx context.Context, currentId string) (c Configuration, err error) } From aab53579e0f212c41f6f9ea41164d90c7eba11c1 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 12 Apr 2023 14:22:20 +0200 Subject: [PATCH 10/26] fix config --- nodeconf/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nodeconf/config.go b/nodeconf/config.go index 1ef1f5ed..911ee745 100644 --- a/nodeconf/config.go +++ b/nodeconf/config.go @@ -24,9 +24,9 @@ const ( ) type Node struct { - PeerId string `yaml:"peerId"` - Addresses []string `yaml:"address"` - Types []NodeType `yaml:"types,omitempty"` + PeerId string `yaml:"peerId" bson:"peerId"` + Addresses []string `yaml:"addresses" bson:"addresses"` + Types []NodeType `yaml:"types,omitempty" bson:"types"` } func (n Node) Id() string { From 55878490e92a7564dc05b3194146b4dd11ddbec8 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 12 Apr 2023 14:22:33 +0200 Subject: [PATCH 11/26] fix handshake test --- net/secureservice/secureservice_test.go | 19 +- nodeconf/mock_nodeconf/mock_nodeconf.go | 281 ++++++++++++------------ 2 files changed, 151 insertions(+), 149 deletions(-) diff --git a/net/secureservice/secureservice_test.go b/net/secureservice/secureservice_test.go index b1dc7e6a..e5d4e5d9 100644 --- a/net/secureservice/secureservice_test.go +++ b/net/secureservice/secureservice_test.go @@ -6,7 +6,9 @@ import ( "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/net/peer" "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/nodeconf/mock_nodeconf" "github.com/anytypeio/any-sync/testutil/testnodeconf" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "net" @@ -19,7 +21,6 @@ func TestHandshake(t *testing.T) { nc := testnodeconf.GenNodeConfig(2) fxS := newFixture(t, nc, nc.GetAccountService(0)) defer fxS.Finish(t) - sc, cc := net.Pipe() type acceptRes struct { @@ -53,20 +54,28 @@ func TestHandshake(t *testing.T) { func newFixture(t *testing.T, nc *testnodeconf.Config, acc accountservice.Service) *fixture { fx := &fixture{ + ctrl: gomock.NewController(t), secureService: New().(*secureService), acc: acc, a: new(app.App), } - - fx.a.Register(fx.acc).Register(nc).Register(nodeconf.New()).Register(fx.secureService) + fx.mockNodeConf = mock_nodeconf.NewMockService(fx.ctrl) + fx.mockNodeConf.EXPECT().Init(gomock.Any()) + fx.mockNodeConf.EXPECT().Name().Return(nodeconf.CName).AnyTimes() + fx.mockNodeConf.EXPECT().Run(ctx) + fx.mockNodeConf.EXPECT().Close(ctx) + fx.mockNodeConf.EXPECT().NodeTypes(gomock.Any()).Return([]nodeconf.NodeType{nodeconf.NodeTypeTree}).AnyTimes() + fx.a.Register(fx.acc).Register(nc).Register(fx.mockNodeConf).Register(fx.secureService) require.NoError(t, fx.a.Start(ctx)) return fx } type fixture struct { *secureService - a *app.App - acc accountservice.Service + a *app.App + acc accountservice.Service + ctrl *gomock.Controller + mockNodeConf *mock_nodeconf.MockService } func (fx *fixture) Finish(t *testing.T) { diff --git a/nodeconf/mock_nodeconf/mock_nodeconf.go b/nodeconf/mock_nodeconf/mock_nodeconf.go index b8b2e800..b422c8a9 100644 --- a/nodeconf/mock_nodeconf/mock_nodeconf.go +++ b/nodeconf/mock_nodeconf/mock_nodeconf.go @@ -1,10 +1,11 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/anytypeio/any-sync/nodeconf (interfaces: Service,Configuration) +// Source: github.com/anytypeio/any-sync/nodeconf (interfaces: Service) // Package mock_nodeconf is a generated GoMock package. package mock_nodeconf import ( + context "context" reflect "reflect" app "github.com/anytypeio/any-sync/app" @@ -36,32 +37,102 @@ func (m *MockService) EXPECT() *MockServiceMockRecorder { return m.recorder } -// GetById mocks base method. -func (m *MockService) GetById(arg0 string) nodeconf.Configuration { +// CHash mocks base method. +func (m *MockService) CHash() chash.CHash { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetById", arg0) + ret := m.ctrl.Call(m, "CHash") + ret0, _ := ret[0].(chash.CHash) + return ret0 +} + +// CHash indicates an expected call of CHash. +func (mr *MockServiceMockRecorder) CHash() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CHash", reflect.TypeOf((*MockService)(nil).CHash)) +} + +// Close mocks base method. +func (m *MockService) Close(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockServiceMockRecorder) Close(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockService)(nil).Close), arg0) +} + +// Configuration mocks base method. +func (m *MockService) Configuration() nodeconf.Configuration { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Configuration") ret0, _ := ret[0].(nodeconf.Configuration) return ret0 } -// GetById indicates an expected call of GetById. -func (mr *MockServiceMockRecorder) GetById(arg0 interface{}) *gomock.Call { +// Configuration indicates an expected call of Configuration. +func (mr *MockServiceMockRecorder) Configuration() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetById", reflect.TypeOf((*MockService)(nil).GetById), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Configuration", reflect.TypeOf((*MockService)(nil).Configuration)) } -// GetLast mocks base method. -func (m *MockService) GetLast() nodeconf.Configuration { +// ConsensusPeers mocks base method. +func (m *MockService) ConsensusPeers() []string { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLast") - ret0, _ := ret[0].(nodeconf.Configuration) + ret := m.ctrl.Call(m, "ConsensusPeers") + ret0, _ := ret[0].([]string) return ret0 } -// GetLast indicates an expected call of GetLast. -func (mr *MockServiceMockRecorder) GetLast() *gomock.Call { +// ConsensusPeers indicates an expected call of ConsensusPeers. +func (mr *MockServiceMockRecorder) ConsensusPeers() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLast", reflect.TypeOf((*MockService)(nil).GetLast)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockService)(nil).ConsensusPeers)) +} + +// CoordinatorPeers mocks base method. +func (m *MockService) CoordinatorPeers() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CoordinatorPeers") + ret0, _ := ret[0].([]string) + return ret0 +} + +// CoordinatorPeers indicates an expected call of CoordinatorPeers. +func (mr *MockServiceMockRecorder) CoordinatorPeers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockService)(nil).CoordinatorPeers)) +} + +// FilePeers mocks base method. +func (m *MockService) FilePeers() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FilePeers") + ret0, _ := ret[0].([]string) + return ret0 +} + +// FilePeers indicates an expected call of FilePeers. +func (mr *MockServiceMockRecorder) FilePeers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilePeers", reflect.TypeOf((*MockService)(nil).FilePeers)) +} + +// Id mocks base method. +func (m *MockService) Id() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Id") + ret0, _ := ret[0].(string) + return ret0 +} + +// Id indicates an expected call of Id. +func (mr *MockServiceMockRecorder) Id() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Id", reflect.TypeOf((*MockService)(nil).Id)) } // Init mocks base method. @@ -78,6 +149,20 @@ func (mr *MockServiceMockRecorder) Init(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockService)(nil).Init), arg0) } +// IsResponsible mocks base method. +func (m *MockService) IsResponsible(arg0 string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsResponsible", arg0) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsResponsible indicates an expected call of IsResponsible. +func (mr *MockServiceMockRecorder) IsResponsible(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsResponsible", reflect.TypeOf((*MockService)(nil).IsResponsible), arg0) +} + // Name mocks base method. func (m *MockService) Name() string { m.ctrl.T.Helper() @@ -92,129 +177,8 @@ func (mr *MockServiceMockRecorder) Name() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockService)(nil).Name)) } -// MockConfiguration is a mock of Configuration interface. -type MockConfiguration struct { - ctrl *gomock.Controller - recorder *MockConfigurationMockRecorder -} - -// MockConfigurationMockRecorder is the mock recorder for MockConfiguration. -type MockConfigurationMockRecorder struct { - mock *MockConfiguration -} - -// NewMockConfiguration creates a new mock instance. -func NewMockConfiguration(ctrl *gomock.Controller) *MockConfiguration { - mock := &MockConfiguration{ctrl: ctrl} - mock.recorder = &MockConfigurationMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockConfiguration) EXPECT() *MockConfigurationMockRecorder { - return m.recorder -} - -// Addresses mocks base method. -func (m *MockConfiguration) Addresses() map[string][]string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Addresses") - ret0, _ := ret[0].(map[string][]string) - return ret0 -} - -// Addresses indicates an expected call of Addresses. -func (mr *MockConfigurationMockRecorder) Addresses() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Addresses", reflect.TypeOf((*MockConfiguration)(nil).Addresses)) -} - -// CHash mocks base method. -func (m *MockConfiguration) CHash() chash.CHash { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CHash") - ret0, _ := ret[0].(chash.CHash) - return ret0 -} - -// CHash indicates an expected call of CHash. -func (mr *MockConfigurationMockRecorder) CHash() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CHash", reflect.TypeOf((*MockConfiguration)(nil).CHash)) -} - -// ConsensusPeers mocks base method. -func (m *MockConfiguration) ConsensusPeers() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConsensusPeers") - ret0, _ := ret[0].([]string) - return ret0 -} - -// ConsensusPeers indicates an expected call of ConsensusPeers. -func (mr *MockConfigurationMockRecorder) ConsensusPeers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockConfiguration)(nil).ConsensusPeers)) -} - -// CoordinatorPeers mocks base method. -func (m *MockConfiguration) CoordinatorPeers() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CoordinatorPeers") - ret0, _ := ret[0].([]string) - return ret0 -} - -// CoordinatorPeers indicates an expected call of CoordinatorPeers. -func (mr *MockConfigurationMockRecorder) CoordinatorPeers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockConfiguration)(nil).CoordinatorPeers)) -} - -// FilePeers mocks base method. -func (m *MockConfiguration) FilePeers() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FilePeers") - ret0, _ := ret[0].([]string) - return ret0 -} - -// FilePeers indicates an expected call of FilePeers. -func (mr *MockConfigurationMockRecorder) FilePeers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilePeers", reflect.TypeOf((*MockConfiguration)(nil).FilePeers)) -} - -// Id mocks base method. -func (m *MockConfiguration) Id() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Id") - ret0, _ := ret[0].(string) - return ret0 -} - -// Id indicates an expected call of Id. -func (mr *MockConfigurationMockRecorder) Id() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Id", reflect.TypeOf((*MockConfiguration)(nil).Id)) -} - -// IsResponsible mocks base method. -func (m *MockConfiguration) IsResponsible(arg0 string) bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsResponsible", arg0) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsResponsible indicates an expected call of IsResponsible. -func (mr *MockConfigurationMockRecorder) IsResponsible(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsResponsible", reflect.TypeOf((*MockConfiguration)(nil).IsResponsible), arg0) -} - // NodeIds mocks base method. -func (m *MockConfiguration) NodeIds(arg0 string) []string { +func (m *MockService) NodeIds(arg0 string) []string { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NodeIds", arg0) ret0, _ := ret[0].([]string) @@ -222,13 +186,13 @@ func (m *MockConfiguration) NodeIds(arg0 string) []string { } // NodeIds indicates an expected call of NodeIds. -func (mr *MockConfigurationMockRecorder) NodeIds(arg0 interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) NodeIds(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeIds", reflect.TypeOf((*MockConfiguration)(nil).NodeIds), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeIds", reflect.TypeOf((*MockService)(nil).NodeIds), arg0) } // NodeTypes mocks base method. -func (m *MockConfiguration) NodeTypes(arg0 string) []nodeconf.NodeType { +func (m *MockService) NodeTypes(arg0 string) []nodeconf.NodeType { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NodeTypes", arg0) ret0, _ := ret[0].([]nodeconf.NodeType) @@ -236,13 +200,13 @@ func (m *MockConfiguration) NodeTypes(arg0 string) []nodeconf.NodeType { } // NodeTypes indicates an expected call of NodeTypes. -func (mr *MockConfigurationMockRecorder) NodeTypes(arg0 interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) NodeTypes(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeTypes", reflect.TypeOf((*MockConfiguration)(nil).NodeTypes), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeTypes", reflect.TypeOf((*MockService)(nil).NodeTypes), arg0) } // Partition mocks base method. -func (m *MockConfiguration) Partition(arg0 string) int { +func (m *MockService) Partition(arg0 string) int { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Partition", arg0) ret0, _ := ret[0].(int) @@ -250,7 +214,36 @@ func (m *MockConfiguration) Partition(arg0 string) int { } // Partition indicates an expected call of Partition. -func (mr *MockConfigurationMockRecorder) Partition(arg0 interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) Partition(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Partition", reflect.TypeOf((*MockConfiguration)(nil).Partition), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Partition", reflect.TypeOf((*MockService)(nil).Partition), arg0) +} + +// PeerAddresses mocks base method. +func (m *MockService) PeerAddresses(arg0 string) ([]string, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeerAddresses", arg0) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// PeerAddresses indicates an expected call of PeerAddresses. +func (mr *MockServiceMockRecorder) PeerAddresses(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerAddresses", reflect.TypeOf((*MockService)(nil).PeerAddresses), arg0) +} + +// Run mocks base method. +func (m *MockService) Run(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Run", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Run indicates an expected call of Run. +func (mr *MockServiceMockRecorder) Run(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockService)(nil).Run), arg0) } From 9d95d577886ac6924b1ea9d433df1900c81783a1 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 12 Apr 2023 14:50:35 +0200 Subject: [PATCH 12/26] nodeconf store --- nodeconf/nodeconfstore/nodeconfstore.go | 62 +++++++++++++++ nodeconf/nodeconfstore/nodeconfstore_test.go | 83 ++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 nodeconf/nodeconfstore/nodeconfstore.go create mode 100644 nodeconf/nodeconfstore/nodeconfstore_test.go diff --git a/nodeconf/nodeconfstore/nodeconfstore.go b/nodeconf/nodeconfstore/nodeconfstore.go new file mode 100644 index 00000000..760bc997 --- /dev/null +++ b/nodeconf/nodeconfstore/nodeconfstore.go @@ -0,0 +1,62 @@ +package nodeconfstore + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/nodeconf" + "gopkg.in/yaml.v3" + "os" + "path/filepath" + "sync" +) + +func New() NodeConfStore { + return new(nodeConfStore) +} + +type NodeConfStore interface { + app.Component + nodeconf.Store +} + +type nodeConfStore struct { + path string + mu sync.Mutex +} + +type configGetter interface { + NodeConfStorePath() string +} + +func (n *nodeConfStore) Init(a *app.App) (err error) { + n.path = a.MustComponent("config").(configGetter).NodeConfStorePath() + return +} + +func (n *nodeConfStore) Name() (name string) { + return nodeconf.CNameStore +} + +func (n *nodeConfStore) GetLast(ctx context.Context, netId string) (c nodeconf.Configuration, err error) { + n.mu.Lock() + defer n.mu.Unlock() + path := filepath.Join(n.path, netId+".yml") + data, err := os.ReadFile(path) + if os.IsNotExist(err) { + err = nodeconf.ErrConfigurationNotFound + return + } + err = yaml.Unmarshal(data, &c) + return +} + +func (n *nodeConfStore) SaveLast(ctx context.Context, c nodeconf.Configuration) (err error) { + n.mu.Lock() + defer n.mu.Unlock() + path := filepath.Join(n.path, c.NetworkId+".yml") + data, err := yaml.Marshal(c) + if err != nil { + return + } + return os.WriteFile(path, data, 0755) +} diff --git a/nodeconf/nodeconfstore/nodeconfstore_test.go b/nodeconf/nodeconfstore/nodeconfstore_test.go new file mode 100644 index 00000000..cf0e9185 --- /dev/null +++ b/nodeconf/nodeconfstore/nodeconfstore_test.go @@ -0,0 +1,83 @@ +package nodeconfstore + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/nodeconf" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "os" + "testing" + "time" +) + +var ctx = context.Background() + +func TestNodeConfStore_GetLast(t *testing.T) { + t.Run("not found", func(t *testing.T) { + fx := newFixture(t) + defer fx.finish(t) + _, err := fx.GetLast(ctx, "123") + assert.EqualError(t, err, nodeconf.ErrConfigurationNotFound.Error()) + }) + t.Run("success", func(t *testing.T) { + fx := newFixture(t) + defer fx.finish(t) + c := nodeconf.Configuration{ + Id: "123", + NetworkId: "456", + Nodes: []nodeconf.Node{ + { + PeerId: "peerId", + Addresses: []string{"addr1", "addr2"}, + Types: []nodeconf.NodeType{nodeconf.NodeTypeTree, nodeconf.NodeTypeCoordinator}, + }, + }, + CreationTime: time.Now().Round(time.Second), + } + require.NoError(t, fx.SaveLast(ctx, c)) + res, err := fx.GetLast(ctx, "456") + require.NoError(t, err) + assert.Equal(t, c, res) + }) +} + +type fixture struct { + NodeConfStore + tmpPath string + a *app.App +} + +func newFixture(t *testing.T) *fixture { + fx := &fixture{ + NodeConfStore: New(), + a: new(app.App), + } + var err error + fx.tmpPath, err = os.MkdirTemp("", "") + require.NoError(t, err) + fx.a.Register(config{path: fx.tmpPath}).Register(fx.NodeConfStore) + require.NoError(t, fx.a.Start(ctx)) + return fx +} + +func (fx *fixture) finish(t *testing.T) { + defer os.RemoveAll(fx.tmpPath) + require.NoError(t, fx.a.Close(ctx)) +} + +type config struct { + path string +} + +func (c config) NodeConfStorePath() string { + return c.path +} + +func (c config) Init(a *app.App) (err error) { + return +} + +func (c config) Name() (name string) { + return "config" +} From 4d36015a31fcf9742c42bcd84d4514ff01aeb81b Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 12 Apr 2023 15:09:04 +0200 Subject: [PATCH 13/26] fix test --- nodeconf/nodeconfstore/nodeconfstore_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nodeconf/nodeconfstore/nodeconfstore_test.go b/nodeconf/nodeconfstore/nodeconfstore_test.go index cf0e9185..d7db5c6b 100644 --- a/nodeconf/nodeconfstore/nodeconfstore_test.go +++ b/nodeconf/nodeconfstore/nodeconfstore_test.go @@ -36,8 +36,11 @@ func TestNodeConfStore_GetLast(t *testing.T) { CreationTime: time.Now().Round(time.Second), } require.NoError(t, fx.SaveLast(ctx, c)) + res, err := fx.GetLast(ctx, "456") require.NoError(t, err) + assert.Equal(t, c.CreationTime.Unix(), res.CreationTime.Unix()) + c.CreationTime = res.CreationTime assert.Equal(t, c, res) }) } From cae5578cc50c9e8342e85ef21a959bea7a257b0e Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 13 Apr 2023 19:06:16 +0200 Subject: [PATCH 14/26] fix --- nodeconf/nodeconfstore/nodeconfstore.go | 4 ++-- nodeconf/nodeconfstore/nodeconfstore_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nodeconf/nodeconfstore/nodeconfstore.go b/nodeconf/nodeconfstore/nodeconfstore.go index 760bc997..75a16fa2 100644 --- a/nodeconf/nodeconfstore/nodeconfstore.go +++ b/nodeconf/nodeconfstore/nodeconfstore.go @@ -25,11 +25,11 @@ type nodeConfStore struct { } type configGetter interface { - NodeConfStorePath() string + GetNodeConfStorePath() string } func (n *nodeConfStore) Init(a *app.App) (err error) { - n.path = a.MustComponent("config").(configGetter).NodeConfStorePath() + n.path = a.MustComponent("config").(configGetter).GetNodeConfStorePath() return } diff --git a/nodeconf/nodeconfstore/nodeconfstore_test.go b/nodeconf/nodeconfstore/nodeconfstore_test.go index d7db5c6b..a525d1a7 100644 --- a/nodeconf/nodeconfstore/nodeconfstore_test.go +++ b/nodeconf/nodeconfstore/nodeconfstore_test.go @@ -73,7 +73,7 @@ type config struct { path string } -func (c config) NodeConfStorePath() string { +func (c config) GetNodeConfStorePath() string { return c.path } From 1dc05faf5893aae4048ba4f95e8b35ed4a72b134 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 13 Apr 2023 20:44:50 +0200 Subject: [PATCH 15/26] nodeconf logs --- nodeconf/service.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 6331856f..06c23a50 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -127,7 +127,11 @@ func (s *service) setLastConfiguration(c Configuration) (err error) { if s.last != nil { beforeId = s.last.Id() } - log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id())) + if s.last.Id() != "" { + log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id())) + } else { + log.Info("nodeConf applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("after", nc.Id())) + } s.last = nc return } From 803500ee34a2bff12279be0573cf1c31a33ce179 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 13 Apr 2023 20:46:01 +0200 Subject: [PATCH 16/26] fix --- nodeconf/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 06c23a50..92f9eab1 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -127,7 +127,7 @@ func (s *service) setLastConfiguration(c Configuration) (err error) { if s.last != nil { beforeId = s.last.Id() } - if s.last.Id() != "" { + if s.last != nil { log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id())) } else { log.Info("nodeConf applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("after", nc.Id())) From b97721f72913cd14c2eb937c09cbcd60979c26aa Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 13 Apr 2023 20:46:56 +0200 Subject: [PATCH 17/26] fix --- nodeconf/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 92f9eab1..49958563 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -128,9 +128,9 @@ func (s *service) setLastConfiguration(c Configuration) (err error) { beforeId = s.last.Id() } if s.last != nil { - log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id())) + log.Info("net configuration changed", zap.String("before", beforeId), zap.String("after", nc.Id())) } else { - log.Info("nodeConf applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("after", nc.Id())) + log.Info("net configuration applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("after", nc.Id())) } s.last = nc return From f7cc1f4b5d342199fe1356e0f0a02309af0637f5 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 13 Apr 2023 20:47:53 +0200 Subject: [PATCH 18/26] fix --- nodeconf/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 49958563..0d9f54cd 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -130,7 +130,7 @@ func (s *service) setLastConfiguration(c Configuration) (err error) { if s.last != nil { log.Info("net configuration changed", zap.String("before", beforeId), zap.String("after", nc.Id())) } else { - log.Info("net configuration applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("after", nc.Id())) + log.Info("net configuration applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("id", nc.Id())) } s.last = nc return From 73ee67c5c0071720ed60c0feb574f438d921d342 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 13:47:04 +0200 Subject: [PATCH 19/26] nodeconf source constructor --- coordinator/nodeconfsource/nodeconfsource.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/coordinator/nodeconfsource/nodeconfsource.go b/coordinator/nodeconfsource/nodeconfsource.go index 3ea44d45..c9c63598 100644 --- a/coordinator/nodeconfsource/nodeconfsource.go +++ b/coordinator/nodeconfsource/nodeconfsource.go @@ -13,6 +13,10 @@ type NodeConfSource interface { nodeconf.Source } +func New() NodeConfSource { + return new(nodeConfSource) +} + type nodeConfSource struct { cl coordinatorclient.CoordinatorClient } From 649e8fe53890d8f1bee49f8f19ce235f403832ba Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 14:33:59 +0200 Subject: [PATCH 20/26] update coordinatorclient mock --- .../mock_coordinatorclient.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index ab31996b..1dee3da3 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -96,6 +96,21 @@ func (mr *MockCoordinatorClientMockRecorder) Name() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockCoordinatorClient)(nil).Name)) } +// NetworkConfiguration mocks base method. +func (m *MockCoordinatorClient) NetworkConfiguration(arg0 context.Context, arg1 string) (*coordinatorproto.NetworkConfigurationResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NetworkConfiguration", arg0, arg1) + ret0, _ := ret[0].(*coordinatorproto.NetworkConfigurationResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NetworkConfiguration indicates an expected call of NetworkConfiguration. +func (mr *MockCoordinatorClientMockRecorder) NetworkConfiguration(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetworkConfiguration", reflect.TypeOf((*MockCoordinatorClient)(nil).NetworkConfiguration), arg0, arg1) +} + // SpaceSign mocks base method. func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 coordinatorclient.SpaceSignPayload) (*coordinatorproto.SpaceReceiptWithSignature, error) { m.ctrl.T.Helper() From 813d6e339c8dfe1916fb14ceaa065606f0d081d3 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 15:59:43 +0200 Subject: [PATCH 21/26] nodeconf: stop update loop on close --- nodeconf/service.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 0d9f54cd..199a82aa 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -30,15 +30,18 @@ type Service interface { } type service struct { - accountId string - config Configuration - source Source - store Store - last NodeConf - mu sync.RWMutex + accountId string + config Configuration + source Source + store Store + last NodeConf + mu sync.RWMutex + updateCtx context.Context + updateCtxCancel context.CancelFunc } func (s *service) Init(a *app.App) (err error) { + s.updateCtx, s.updateCtxCancel = context.WithCancel(context.Background()) s.config = a.MustComponent("config").(ConfigGetter).GetNodeConf() s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId s.source = a.MustComponent(CNameSource).(Source) @@ -61,7 +64,14 @@ func (s *service) Run(_ context.Context) (err error) { } func (s *service) updateLoop(ctx context.Context) { - for _ = range time.NewTicker(time.Minute * 10).C { + ticker := time.NewTicker(time.Minute * 10) + defer ticker.Stop() + for { + select { + case <-s.updateCtx.Done(): + return + case <-ticker.C: + } err := s.updateConfiguration(ctx) if err != nil { if err == ErrConfigurationNotChanged { @@ -203,5 +213,8 @@ func (s *service) NodeTypes(nodeId string) []NodeType { } func (s *service) Close(ctx context.Context) (err error) { + if s.updateCtxCancel != nil { + s.updateCtxCancel() + } return } From f014209d75803329498d9eef31a2d0c1cfccbb05 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 16:08:19 +0200 Subject: [PATCH 22/26] log dial error --- net/pool/pool.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/pool/pool.go b/net/pool/pool.go index b2e4ae22..b7e391c6 100644 --- a/net/pool/pool.go +++ b/net/pool/pool.go @@ -6,6 +6,7 @@ import ( "github.com/anytypeio/any-sync/app/ocache" "github.com/anytypeio/any-sync/net/dialer" "github.com/anytypeio/any-sync/net/peer" + "go.uber.org/zap" "math/rand" ) @@ -78,6 +79,8 @@ func (p *pool) GetOneOf(ctx context.Context, peerIds []string) (peer.Peer, error for _, peerId := range peerIds { if v, err := p.cache.Get(ctx, peerId); err == nil { return v.(peer.Peer), nil + } else { + log.Debug("unable to connect", zap.String("peerId", peerId), zap.Error(err)) } } return nil, ErrUnableToConnect @@ -92,6 +95,8 @@ func (p *pool) DialOneOf(ctx context.Context, peerIds []string) (peer.Peer, erro for _, peerId := range peerIds { if v, err := p.dialer.Dial(ctx, peerId); err == nil { return v.(peer.Peer), nil + } else { + log.Debug("unable to connect", zap.String("peerId", peerId), zap.Error(err)) } } return nil, ErrUnableToConnect From d3c9fef7b472e751e459c6a0104bb3a8a4bda7ad Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 17:00:35 +0200 Subject: [PATCH 23/26] update conf on start --- nodeconf/service.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 199a82aa..5fa40db2 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -66,19 +66,26 @@ func (s *service) Run(_ context.Context) (err error) { func (s *service) updateLoop(ctx context.Context) { ticker := time.NewTicker(time.Minute * 10) defer ticker.Stop() + + updateConf := func() { + err := s.updateConfiguration(ctx) + if err != nil { + if err == ErrConfigurationNotChanged { + return + } + log.Info("can't update configuration", zap.Error(err)) + } + } + + updateConf() + for { select { case <-s.updateCtx.Done(): return case <-ticker.C: } - err := s.updateConfiguration(ctx) - if err != nil { - if err == ErrConfigurationNotChanged { - continue - } - log.Info("can't update configuration", zap.Error(err)) - } + updateConf() } } From cc24e38081af3d46e9a9a4167262b2096adfc63b Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 17:10:15 +0200 Subject: [PATCH 24/26] nodeConfStore: create dir on start --- nodeconf/nodeconfstore/nodeconfstore.go | 3 +++ nodeconf/nodeconfstore/nodeconfstore_test.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/nodeconf/nodeconfstore/nodeconfstore.go b/nodeconf/nodeconfstore/nodeconfstore.go index 75a16fa2..2033ffca 100644 --- a/nodeconf/nodeconfstore/nodeconfstore.go +++ b/nodeconf/nodeconfstore/nodeconfstore.go @@ -30,6 +30,9 @@ type configGetter interface { func (n *nodeConfStore) Init(a *app.App) (err error) { n.path = a.MustComponent("config").(configGetter).GetNodeConfStorePath() + if e := os.Mkdir(n.path, 0755); e != nil && !os.IsExist(e) { + return e + } return } diff --git a/nodeconf/nodeconfstore/nodeconfstore_test.go b/nodeconf/nodeconfstore/nodeconfstore_test.go index a525d1a7..cb4d5202 100644 --- a/nodeconf/nodeconfstore/nodeconfstore_test.go +++ b/nodeconf/nodeconfstore/nodeconfstore_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "os" + "path/filepath" "testing" "time" ) @@ -74,7 +75,7 @@ type config struct { } func (c config) GetNodeConfStorePath() string { - return c.path + return filepath.Join(c.path, "nodeconf") } func (c config) Init(a *app.App) (err error) { From 7348f39eff0a7ec36f193a1d84dacbb68bc2c82f Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 17:16:26 +0200 Subject: [PATCH 25/26] fix decode node types --- coordinator/nodeconfsource/nodeconfsource.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/coordinator/nodeconfsource/nodeconfsource.go b/coordinator/nodeconfsource/nodeconfsource.go index c9c63598..f66dcafb 100644 --- a/coordinator/nodeconfsource/nodeconfsource.go +++ b/coordinator/nodeconfsource/nodeconfsource.go @@ -4,6 +4,7 @@ import ( "context" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/coordinator/coordinatorclient" + "github.com/anytypeio/any-sync/coordinator/coordinatorproto" "github.com/anytypeio/any-sync/nodeconf" "time" ) @@ -41,9 +42,16 @@ func (n *nodeConfSource) GetLast(ctx context.Context, currentId string) (c nodec } nodes := make([]nodeconf.Node, len(res.Nodes)) for i, node := range res.Nodes { - types := make([]nodeconf.NodeType, len(node.Types)) - for j, nt := range node.Types { - types[j] = nodeconf.NodeType(nt) + types := make([]nodeconf.NodeType, 0, len(node.Types)) + for _, nt := range node.Types { + switch nt { + case coordinatorproto.NodeType_FileAPI: + types = append(types, nodeconf.NodeTypeFile) + case coordinatorproto.NodeType_CoordinatorAPI: + types = append(types, nodeconf.NodeTypeCoordinator) + case coordinatorproto.NodeType_TreeAPI: + types = append(types, nodeconf.NodeTypeTree) + } } nodes[i] = nodeconf.Node{ PeerId: node.PeerId, From adb800d56a288b3f1a89d800f334404b9d8873d5 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 17 Apr 2023 20:08:07 +0200 Subject: [PATCH 26/26] use periodicSync --- nodeconf/service.go | 59 +++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/nodeconf/service.go b/nodeconf/service.go index 5fa40db2..3f12e462 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -5,10 +5,10 @@ import ( commonaccount "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/util/periodicsync" "github.com/anytypeio/go-chash" "go.uber.org/zap" "sync" - "time" ) const CName = "common.nodeconf" @@ -30,18 +30,16 @@ type Service interface { } type service struct { - accountId string - config Configuration - source Source - store Store - last NodeConf - mu sync.RWMutex - updateCtx context.Context - updateCtxCancel context.CancelFunc + accountId string + config Configuration + source Source + store Store + last NodeConf + mu sync.RWMutex + sync periodicsync.PeriodicSync } func (s *service) Init(a *app.App) (err error) { - s.updateCtx, s.updateCtxCancel = context.WithCancel(context.Background()) s.config = a.MustComponent("config").(ConfigGetter).GetNodeConf() s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId s.source = a.MustComponent(CNameSource).(Source) @@ -51,6 +49,15 @@ func (s *service) Init(a *app.App) (err error) { lastStored = s.config err = nil } + s.sync = periodicsync.NewPeriodicSync(600, 0, func(ctx context.Context) (err error) { + err = s.updateConfiguration(ctx) + if err != nil { + if err == ErrConfigurationNotChanged { + err = nil + } + } + return + }, log) return s.setLastConfiguration(lastStored) } @@ -59,36 +66,10 @@ func (s *service) Name() (name string) { } func (s *service) Run(_ context.Context) (err error) { - go s.updateLoop(context.Background()) + s.sync.Run() return } -func (s *service) updateLoop(ctx context.Context) { - ticker := time.NewTicker(time.Minute * 10) - defer ticker.Stop() - - updateConf := func() { - err := s.updateConfiguration(ctx) - if err != nil { - if err == ErrConfigurationNotChanged { - return - } - log.Info("can't update configuration", zap.Error(err)) - } - } - - updateConf() - - for { - select { - case <-s.updateCtx.Done(): - return - case <-ticker.C: - } - updateConf() - } -} - func (s *service) updateConfiguration(ctx context.Context) (err error) { last, err := s.source.GetLast(ctx, s.Configuration().Id) if err != nil { @@ -220,8 +201,6 @@ func (s *service) NodeTypes(nodeId string) []NodeType { } func (s *service) Close(ctx context.Context) (err error) { - if s.updateCtxCancel != nil { - s.updateCtxCancel() - } + s.sync.Close() return }