From 93cd6897d30dd845136deac1118ba1f5dfb5278e Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sat, 8 Apr 2023 17:01:40 +0200 Subject: [PATCH] coord nodeconf source, nodeconf service updates --- .../coordinatorclient/coordinatorclient.go | 16 + .../coordinatorproto/coordinator.pb.go | 346 ++++++++++++++---- .../coordinatorproto/protos/coordinator.proto | 6 +- coordinator/nodeconfsource/nodeconfsource.go | 56 +++ nodeconf/nodeconf.go | 14 +- nodeconf/service.go | 50 ++- nodeconf/source.go | 11 +- 7 files changed, 414 insertions(+), 85 deletions(-) create mode 100644 coordinator/nodeconfsource/nodeconfsource.go diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index fc3c2dc2..aa5aa2f5 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.GetLast().CoordinatorPeers()) if err != nil { diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index 1bdbe25d..a08e0891 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -123,8 +123,14 @@ func (NodeType) EnumDescriptor() ([]byte, []int) { } type SpaceSignRequest struct { + // SpaceId is the id of the signed space SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` + // Header is the header of the signed space + Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` + // OldIdentity is the old identity of the space owner + OldIdentity []byte `protobuf:"bytes,3,opt,name=oldIdentity,proto3" json:"oldIdentity,omitempty"` + // NewIdentitySignature is the new identity signed by the old one + NewIdentitySignature []byte `protobuf:"bytes,4,opt,name=newIdentitySignature,proto3" json:"newIdentitySignature,omitempty"` } func (m *SpaceSignRequest) Reset() { *m = SpaceSignRequest{} } @@ -174,6 +180,20 @@ func (m *SpaceSignRequest) GetHeader() []byte { return nil } +func (m *SpaceSignRequest) GetOldIdentity() []byte { + if m != nil { + return m.OldIdentity + } + return nil +} + +func (m *SpaceSignRequest) GetNewIdentitySignature() []byte { + if m != nil { + return m.NewIdentitySignature + } + return nil +} + type SpaceStatusPayload struct { Status SpaceStatus `protobuf:"varint,1,opt,name=status,proto3,enum=coordinator.SpaceStatus" json:"status,omitempty"` DeletionTimestamp int64 `protobuf:"varint,2,opt,name=deletionTimestamp,proto3" json:"deletionTimestamp,omitempty"` @@ -700,9 +720,11 @@ func (m *SpaceStatusChangeResponse) GetPayload() *SpaceStatusPayload { return nil } -// 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 type NetworkConfigurationRequest struct { - ConfigurationId string `protobuf:"bytes,1,opt,name=configurationId,proto3" json:"configurationId,omitempty"` + // currenId of the client configuration + // if the currentId is equal to the latest configuration id then the response will not contain a nodes list + CurrentId string `protobuf:"bytes,1,opt,name=currentId,proto3" json:"currentId,omitempty"` } func (m *NetworkConfigurationRequest) Reset() { *m = NetworkConfigurationRequest{} } @@ -738,17 +760,23 @@ func (m *NetworkConfigurationRequest) XXX_DiscardUnknown() { var xxx_messageInfo_NetworkConfigurationRequest proto.InternalMessageInfo -func (m *NetworkConfigurationRequest) GetConfigurationId() string { +func (m *NetworkConfigurationRequest) GetCurrentId() string { if m != nil { - return m.ConfigurationId + return m.CurrentId } 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"` + // 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,3,rep,name=nodes,proto3" json:"nodes,omitempty"` + // unix timestamp of the creation time of configuration + CreationTimeUnix uint64 `protobuf:"varint,4,opt,name=creationTimeUnix,proto3" json:"creationTimeUnix,omitempty"` } func (m *NetworkConfigurationResponse) Reset() { *m = NetworkConfigurationResponse{} } @@ -791,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 @@ -798,6 +833,13 @@ func (m *NetworkConfigurationResponse) GetNodes() []*Node { return nil } +func (m *NetworkConfigurationResponse) GetCreationTimeUnix() uint64 { + if m != nil { + return m.CreationTimeUnix + } + return 0 +} + // 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 @@ -887,61 +929,65 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 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, 0x99, 0xc0, 0xf6, 0x02, 0x89, 0x47, 0xe0, - 0x8a, 0xa7, 0xe0, 0x11, 0x78, 0x00, 0x2e, 0xf7, 0x92, 0x4b, 0xd4, 0x4a, 0x3c, 0x07, 0x1a, 0x7b, - 0x9c, 0x8c, 0x13, 0x27, 0xad, 0xc4, 0x4d, 0xdb, 0xf3, 0x9d, 0x9f, 0xef, 0x9c, 0x39, 0x3f, 0x2e, - 0x7c, 0x10, 0x33, 0xc6, 0x13, 0x9a, 0x46, 0x92, 0xf1, 0xfb, 0xc6, 0xdf, 0x19, 0x67, 0x92, 0xdd, - 0xcf, 0x7f, 0x0a, 0x13, 0xdf, 0xcb, 0x21, 0xe2, 0x18, 0x50, 0xf0, 0x08, 0xdc, 0xa3, 0x2c, 0x8a, - 0xf1, 0x88, 0x9e, 0xa5, 0x21, 0x3e, 0x1d, 0xa3, 0x90, 0xc4, 0x83, 0x35, 0xa1, 0xb0, 0xfd, 0xc4, - 0xb3, 0x7a, 0x56, 0xbf, 0x1d, 0x96, 0x22, 0xd9, 0x86, 0xd5, 0x73, 0x8c, 0x12, 0xe4, 0x5e, 0xb3, - 0x67, 0xf5, 0xd7, 0x43, 0x2d, 0x05, 0x12, 0x48, 0x11, 0x45, 0x46, 0x72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x7c, 0x09, - 0xed, 0xc9, 0xfd, 0x27, 0xaf, 0xd5, 0x4c, 0xea, 0xf4, 0x9b, 0xd6, 0xf5, 0x17, 0xa9, 0xf5, 0x54, - 0x7d, 0x07, 0x9d, 0xea, 0xad, 0x21, 0x41, 0xc5, 0xa3, 0xf6, 0xca, 0x75, 0xdf, 0x58, 0x6a, 0xa3, - 0x43, 0xff, 0x58, 0x7e, 0x62, 0xa7, 0x17, 0x86, 0xbc, 0xb9, 0x68, 0xaf, 0x2a, 0xe1, 0xdf, 0xba, - 0xc5, 0x4a, 0x13, 0x3c, 0x29, 0xbf, 0x83, 0xc6, 0x4a, 0x93, 0x25, 0xbe, 0xc6, 0x29, 0xea, 0xde, - 0xbb, 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, + // 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, 0xcb, 0x91, 0x77, 0xd2, 0x24, 0x61, 0x30, 0x66, 0xb0, 0x06, 0x58, + 0x4c, 0x40, 0xd9, 0x95, 0x17, 0x10, 0x88, 0x0b, 0x60, 0x16, 0x29, 0x08, 0x85, 0x68, 0x12, 0x83, + 0x80, 0x03, 0x9a, 0x9d, 0xa9, 0x24, 0xad, 0x38, 0xdd, 0x43, 0x77, 0x9b, 0x4d, 0x0e, 0x48, 0x3c, + 0x02, 0x27, 0x0e, 0x3c, 0x03, 0x6f, 0x00, 0x0f, 0xc0, 0x31, 0x47, 0x8e, 0x28, 0x91, 0x78, 0x0e, + 0xd4, 0xf3, 0xe7, 0x1e, 0x7b, 0x9c, 0x20, 0xed, 0xc5, 0x76, 0x7f, 0xf5, 0xfb, 0x55, 0x55, 0x57, + 0x1b, 0xde, 0x0d, 0x39, 0x17, 0x11, 0x65, 0x81, 0xe2, 0xe2, 0x81, 0xf1, 0x3b, 0x16, 0x5c, 0xf1, + 0x07, 0xc9, 0xa7, 0x34, 0xf1, 0xdd, 0x04, 0x22, 0x6d, 0x03, 0xf2, 0x7e, 0xb3, 0xc0, 0x3e, 0x8c, + 0x83, 0x10, 0x0f, 0xe9, 0x09, 0xf3, 0xf1, 0x87, 0x29, 0x4a, 0x45, 0x1c, 0x58, 0x93, 0x1a, 0xdb, + 0x8b, 0x1c, 0xab, 0x6f, 0x0d, 0x5a, 0x7e, 0x7e, 0x24, 0xdb, 0xb0, 0x7a, 0x8a, 0x41, 0x84, 0xc2, + 0xa9, 0xf7, 0xad, 0xc1, 0xba, 0x9f, 0x9d, 0x48, 0x1f, 0xda, 0x7c, 0x12, 0xed, 0x45, 0xc8, 0x14, + 0x55, 0x97, 0x4e, 0x23, 0x11, 0x9a, 0x10, 0x19, 0xc2, 0x26, 0xc3, 0xa7, 0xf9, 0x51, 0x47, 0x0b, + 0xd4, 0x54, 0xa0, 0xd3, 0x4c, 0x54, 0x2b, 0x65, 0x9e, 0x02, 0x92, 0xe6, 0xa6, 0x02, 0x35, 0x95, + 0x07, 0xc1, 0xe5, 0x84, 0x07, 0x11, 0x79, 0x08, 0xab, 0x32, 0x01, 0x92, 0xe4, 0x3a, 0x43, 0x67, + 0xd7, 0xe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a, 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, 0xab, 0xc7, + 0x17, 0x54, 0x2a, 0x69, 0x37, 0x89, 0x0d, 0xed, 0x24, 0xde, 0x97, 0xc7, 0xc7, 0x12, 0x95, 0xfd, + 0x7b, 0x7d, 0xe7, 0x27, 0x68, 0x1b, 0x73, 0x40, 0xb6, 0x4b, 0xab, 0x3f, 0x77, 0x56, 0x23, 0x2e, + 0x74, 0xcd, 0x71, 0x49, 0xc3, 0xe6, 0x59, 0xd8, 0xd6, 0x9c, 0x3c, 0x17, 0x1c, 0xaa, 0x40, 0x68, + 0xfb, 0xfa, 0x9c, 0xdf, 0x9c, 0x50, 0x63, 0xe7, 0x7d, 0x78, 0x2e, 0x2f, 0x0a, 0x69, 0xc3, 0xda, + 0x91, 0x40, 0xfc, 0xf8, 0x60, 0xcf, 0xae, 0xe9, 0x83, 0xde, 0x16, 0xfa, 0x60, 0x69, 0x2a, 0xa3, + 0x59, 0x19, 0x35, 0x56, 0x1f, 0xfe, 0xdb, 0x80, 0xb6, 0x01, 0x92, 0xcf, 0xa1, 0x55, 0x3c, 0x1f, + 0xe4, 0xe5, 0x8a, 0x41, 0x9f, 0x3d, 0xb4, 0x5d, 0x77, 0x99, 0x38, 0x9b, 0xcf, 0x6f, 0xa0, 0x53, + 0x5e, 0x55, 0xc4, 0x2b, 0x59, 0x54, 0x2e, 0xc9, 0xee, 0xab, 0xb7, 0xea, 0x64, 0xae, 0xbf, 0xcf, + 0xdf, 0xfd, 0xd9, 0x82, 0x22, 0xaf, 0x2d, 0xbb, 0x96, 0x25, 0xf7, 0xaf, 0xdf, 0xa1, 0x95, 0x05, + 0x78, 0x92, 0x3f, 0xa3, 0xc6, 0x46, 0x20, 0xb7, 0xd8, 0x1a, 0x9b, 0xac, 0x7b, 0xff, 0x2e, 0xb5, + 0x2c, 0xc6, 0x19, 0x6c, 0x56, 0xdd, 0x6f, 0x32, 0x28, 0x4f, 0xfb, 0xf2, 0x05, 0xd2, 0x7d, 0xf3, + 0x7f, 0x68, 0xa6, 0xc1, 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) { @@ -964,6 +1010,20 @@ func (m *SpaceSignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.NewIdentitySignature) > 0 { + i -= len(m.NewIdentitySignature) + copy(dAtA[i:], m.NewIdentitySignature) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.NewIdentitySignature))) + i-- + dAtA[i] = 0x22 + } + if len(m.OldIdentity) > 0 { + i -= len(m.OldIdentity) + copy(dAtA[i:], m.OldIdentity) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.OldIdentity))) + i-- + dAtA[i] = 0x1a + } if len(m.Header) > 0 { i -= len(m.Header) copy(dAtA[i:], m.Header) @@ -1371,10 +1431,10 @@ func (m *NetworkConfigurationRequest) MarshalToSizedBuffer(dAtA []byte) (int, er _ = 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))) + if len(m.CurrentId) > 0 { + i -= len(m.CurrentId) + copy(dAtA[i:], m.CurrentId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.CurrentId))) i-- dAtA[i] = 0xa } @@ -1401,6 +1461,11 @@ func (m *NetworkConfigurationResponse) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if m.CreationTimeUnix != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.CreationTimeUnix)) + i-- + dAtA[i] = 0x20 + } if len(m.Nodes) > 0 { for iNdEx := len(m.Nodes) - 1; iNdEx >= 0; iNdEx-- { { @@ -1412,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) @@ -1507,6 +1579,14 @@ func (m *SpaceSignRequest) Size() (n int) { if l > 0 { n += 1 + l + sovCoordinator(uint64(l)) } + l = len(m.OldIdentity) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.NewIdentitySignature) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } return n } @@ -1678,7 +1758,7 @@ func (m *NetworkConfigurationRequest) Size() (n int) { } var l int _ = l - l = len(m.ConfigurationId) + l = len(m.CurrentId) if l > 0 { n += 1 + l + sovCoordinator(uint64(l)) } @@ -1695,12 +1775,19 @@ 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() n += 1 + l + sovCoordinator(uint64(l)) } } + if m.CreationTimeUnix != 0 { + n += 1 + sovCoordinator(uint64(m.CreationTimeUnix)) + } return n } @@ -1831,6 +1918,74 @@ func (m *SpaceSignRequest) Unmarshal(dAtA []byte) error { m.Header = []byte{} } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OldIdentity", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OldIdentity = append(m.OldIdentity[:0], dAtA[iNdEx:postIndex]...) + if m.OldIdentity == nil { + m.OldIdentity = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewIdentitySignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewIdentitySignature = append(m.NewIdentitySignature[:0], dAtA[iNdEx:postIndex]...) + if m.NewIdentitySignature == nil { + m.NewIdentitySignature = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) @@ -2963,7 +3118,7 @@ func (m *NetworkConfigurationRequest) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConfigurationId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CurrentId", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -2991,7 +3146,7 @@ func (m *NetworkConfigurationRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ConfigurationId = string(dAtA[iNdEx:postIndex]) + m.CurrentId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -3076,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) } @@ -3109,6 +3296,25 @@ func (m *NetworkConfigurationResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreationTimeUnix", wireType) + } + m.CreationTimeUnix = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreationTimeUnix |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) 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 c7be0a90..3d673fe8 100644 --- a/nodeconf/nodeconf.go +++ b/nodeconf/nodeconf.go @@ -21,8 +21,8 @@ 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 - Addresses() map[string][]string + // PeerAddresses returns peer addresses by peer id + PeerAddresses(peerId string) (addrs []string, ok bool) // CHash returns nodes consistent table CHash() chash.CHash // Partition returns partition number by spaceId @@ -40,6 +40,7 @@ type nodeConf struct { chash chash.CHash allMembers []Node c Configuration + addrs map[string][]string } func (c *nodeConf) Id() string { @@ -82,12 +83,9 @@ func (c *nodeConf) CoordinatorPeers() []string { return c.coordinatorPeers } -func (c *nodeConf) Addresses() map[string][]string { - res := make(map[string][]string) - for _, m := range c.allMembers { - res[m.PeerId] = m.Addresses - } - return res +func (c *nodeConf) PeerAddresses(peerId string) (addrs []string, ok bool) { + addrs, ok = c.addrs[peerId] + return } func (c *nodeConf) CHash() chash.CHash { diff --git a/nodeconf/service.go b/nodeconf/service.go index eb29d70c..28bcdf23 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() @@ -155,3 +195,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) }