nodeconf interfaces

This commit is contained in:
Sergey Cherepanov 2023-04-06 19:02:18 +02:00
parent 6af4238664
commit 9cee18c834
No known key found for this signature in database
GPG Key ID: 87F8EDE8FBDF637C
11 changed files with 184 additions and 105 deletions

View File

@ -107,15 +107,21 @@ message SpaceStatusChangeResponse {
SpaceStatusPayload payload = 1; 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 { 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 // NetworkConfigurationResponse contains list of nodes
message NetworkConfigurationResponse { message NetworkConfigurationResponse {
// id of current configuration
string configurationId = 1; string configurationId = 1;
// nodes list - it will be empty if the client's currentId is equal configurationId
repeated Node nodes = 2; 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 // NodeType determines the type of API that a node supports

12
go.mod
View File

@ -23,7 +23,7 @@ require (
github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-ipld-format v0.4.0
github.com/ipfs/go-merkledag v0.10.0 github.com/ipfs/go-merkledag v0.10.0
github.com/ipfs/go-unixfs v0.4.5 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/mr-tron/base58 v1.2.0
github.com/multiformats/go-multibase v0.2.0 github.com/multiformats/go-multibase v0.2.0
github.com/multiformats/go-multihash v0.2.1 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/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/net v0.8.0 golang.org/x/net v0.8.0
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v2 v2.4.0
storj.io/drpc v0.0.32 storj.io/drpc v0.0.32
) )
@ -59,11 +60,12 @@ require (
github.com/ipfs/go-bitfield v1.1.0 // indirect github.com/ipfs/go-bitfield v1.1.0 // indirect
github.com/ipfs/go-datastore v0.6.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-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-posinfo v0.0.1 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // 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-cbor v0.0.6 // indirect
github.com/ipfs/go-ipld-legacy v0.1.1 // 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 v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipfs/go-metrics-interface v0.0.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/ipld/go-ipld-prime v0.20.0 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // 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-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-openssl v0.1.0 // indirect github.com/libp2p/go-openssl v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.17 // 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-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.8.0 // indirect github.com/multiformats/go-multiaddr v0.8.0 // indirect
github.com/multiformats/go-multicodec 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/multiformats/go-varint v0.0.7 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
@ -94,7 +96,7 @@ require (
github.com/prometheus/procfs v0.9.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // 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 github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
go.opentelemetry.io/otel v1.11.2 // indirect go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect go.opentelemetry.io/otel/trace v1.11.2 // indirect

9
go.sum
View File

@ -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-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 h1:z6MCYHQSZpDWpUSK59Kf0ajP1fi4gLCf6fIulVsp8A8=
github.com/ipfs/go-ipfs-files v0.2.0/go.mod h1:vT7uaQfIsprKktzbTPLnIsd+NGw9ZbYwSq0g3N74u0M= 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 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs=
github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= 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= 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-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 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc=
github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fOmKZkkFkrIEg= 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 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 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8=
github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= 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.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 h1:xPMwiykqNK9VK0NYC3+jTMYv9I6Vl3YdjZgPZKG3zO0=
github.com/klauspost/cpuid/v2 v2.2.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= 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/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.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 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-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c=
github.com/libp2p/go-libp2p v0.24.1 h1:+lS4fqj7RF9egcPq9Yo3iqdRTcDMApzoBbQMhxtwOVw= 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.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-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-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0=
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= 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-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 h1:d5PZpjwRgVlbwfdTDjife7XszfZd8KYWfROYFlGcR8o=
github.com/multiformats/go-multistream v0.3.3/go.mod h1:ODRoqamLUsETKS9BNcII4gcRsJBU5VAwRIv7O39cEXg= 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.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.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= 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-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 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-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 h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= 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= 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.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.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 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-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.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@ -1,5 +1,18 @@
package nodeconf package nodeconf
import (
"errors"
"time"
)
type ConfigGetter interface {
GetNodeConf() Configuration
}
var (
ErrConfigurationNotFound = errors.New("node nodeConf not found")
)
type NodeType string type NodeType string
const ( const (
@ -10,18 +23,21 @@ const (
NodeTypeCoordinator NodeType = "coordinator" NodeTypeCoordinator NodeType = "coordinator"
) )
type ConfigGetter interface { type Node struct {
GetNodes() []NodeConfig
GetNodesConfId() string
}
type NodeConfig struct {
PeerId string `yaml:"peerId"` PeerId string `yaml:"peerId"`
Addresses []string `yaml:"address"` Addresses []string `yaml:"address"`
Types []NodeType `yaml:"types,omitempty"` 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 { for _, nt := range n.Types {
if nt == t { if nt == t {
return true return true
@ -29,3 +45,10 @@ func (n NodeConfig) HasType(t NodeType) bool {
} }
return false return false
} }
type Configuration struct {
Id string `yaml:"id"`
NetworkId string `yaml:"networkId"`
Nodes []Node `yaml:"nodes"`
CreationTime time.Time `yaml:"creationTime"`
}

View File

@ -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 package nodeconf
import ( import (
@ -6,9 +6,11 @@ import (
"strings" "strings"
) )
type Configuration interface { type NodeConf interface {
// Id returns current nodeconf id // Id returns current nodeconf id
Id() string Id() string
// Configuration returns configuration struct
Configuration() Configuration
// NodeIds returns list of peerId for given spaceId // NodeIds returns list of peerId for given spaceId
NodeIds(spaceId string) []string NodeIds(spaceId string) []string
// IsResponsible checks if current account responsible for given spaceId // IsResponsible checks if current account responsible for given spaceId
@ -29,21 +31,26 @@ type Configuration interface {
NodeTypes(nodeId string) []NodeType NodeTypes(nodeId string) []NodeType
} }
type configuration struct { type nodeConf struct {
id string id string
accountId string accountId string
filePeers []string filePeers []string
consensusPeers []string consensusPeers []string
coordinatorPeers []string coordinatorPeers []string
chash chash.CHash chash chash.CHash
allMembers []NodeConfig allMembers []Node
c Configuration
} }
func (c *configuration) Id() string { func (c *nodeConf) Id() string {
return c.id 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)) members := c.chash.GetMembers(ReplKey(spaceId))
res := make([]string, 0, len(members)) res := make([]string, 0, len(members))
for _, m := range members { for _, m := range members {
@ -54,7 +61,7 @@ func (c *configuration) NodeIds(spaceId string) []string {
return res return res
} }
func (c *configuration) IsResponsible(spaceId string) bool { func (c *nodeConf) IsResponsible(spaceId string) bool {
for _, m := range c.chash.GetMembers(ReplKey(spaceId)) { for _, m := range c.chash.GetMembers(ReplKey(spaceId)) {
if m.Id() == c.accountId { if m.Id() == c.accountId {
return true return true
@ -63,19 +70,19 @@ func (c *configuration) IsResponsible(spaceId string) bool {
return false return false
} }
func (c *configuration) FilePeers() []string { func (c *nodeConf) FilePeers() []string {
return c.filePeers return c.filePeers
} }
func (c *configuration) ConsensusPeers() []string { func (c *nodeConf) ConsensusPeers() []string {
return c.consensusPeers return c.consensusPeers
} }
func (c *configuration) CoordinatorPeers() []string { func (c *nodeConf) CoordinatorPeers() []string {
return c.coordinatorPeers return c.coordinatorPeers
} }
func (c *configuration) Addresses() map[string][]string { func (c *nodeConf) Addresses() map[string][]string {
res := make(map[string][]string) res := make(map[string][]string)
for _, m := range c.allMembers { for _, m := range c.allMembers {
res[m.PeerId] = m.Addresses res[m.PeerId] = m.Addresses
@ -83,15 +90,15 @@ func (c *configuration) Addresses() map[string][]string {
return res return res
} }
func (c *configuration) CHash() chash.CHash { func (c *nodeConf) CHash() chash.CHash {
return c.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)) 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 { for _, m := range c.allMembers {
if m.PeerId == nodeId { if m.PeerId == nodeId {
return m.Types return m.Types

View File

@ -21,7 +21,7 @@ func TestConfiguration_NodeIds(t *testing.T) {
ReplicationFactor: ReplicationFactor, ReplicationFactor: ReplicationFactor,
}) })
require.NoError(t, err) require.NoError(t, err)
conf := &configuration{ conf := &nodeConf{
id: "last", id: "last",
accountId: "1", accountId: "1",
chash: ch, chash: ch,

View File

@ -4,9 +4,7 @@ import (
commonaccount "github.com/anytypeio/any-sync/accountservice" commonaccount "github.com/anytypeio/any-sync/accountservice"
"github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app"
"github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/app/logger"
"github.com/anytypeio/any-sync/util/crypto"
"github.com/anytypeio/go-chash" "github.com/anytypeio/go-chash"
"github.com/libp2p/go-libp2p/core/peer"
"go.uber.org/zap" "go.uber.org/zap"
"sync" "sync"
) )
@ -25,121 +23,135 @@ func New() Service {
} }
type Service interface { type Service interface {
GetLast() Configuration NodeConf
SetLastConfig(id string, nodes []NodeConfig) (err error)
app.Component app.Component
} }
type service struct { type service struct {
accountId string accountId string
last Configuration last NodeConf
mu sync.RWMutex 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) { func (s *service) Init(a *app.App) (err error) {
nodesConf := a.MustComponent("config").(ConfigGetter) nodesConf := a.MustComponent("config").(ConfigGetter)
s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId 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) { func (s *service) Name() (name string) {
return CName return CName
} }
func (s *service) GetLast() Configuration { func (s *service) setLastConfiguration(c Configuration) (err error) {
s.mu.RLock()
defer s.mu.RUnlock()
return s.last
}
func (s *service) SetLastConfig(id string, nodesConf []NodeConfig) (err error) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
if s.last != nil && s.last.Id() == id { if s.last != nil && s.last.Id() == c.Id {
return return
} }
fileConfig := &configuration{ nc := &nodeConf{
id: id, id: c.Id,
c: c,
accountId: s.accountId, accountId: s.accountId,
} }
if fileConfig.chash, err = chash.New(chash.Config{ if nc.chash, err = chash.New(chash.Config{
PartitionCount: PartitionCount, PartitionCount: PartitionCount,
ReplicationFactor: ReplicationFactor, ReplicationFactor: ReplicationFactor,
}); err != nil { }); err != nil {
return return
} }
members := make([]chash.Member, 0, len(nodesConf)) members := make([]chash.Member, 0, len(c.Nodes))
for _, n := range nodesConf { for _, n := range c.Nodes {
if n.HasType(NodeTypeTree) { if n.HasType(NodeTypeTree) {
var member *Node members = append(members, n)
member, err = nodeFromConfigNode(n)
if err != nil {
return
}
members = append(members, member)
} }
if n.HasType(NodeTypeConsensus) { if n.HasType(NodeTypeConsensus) {
fileConfig.consensusPeers = append(fileConfig.consensusPeers, n.PeerId) nc.consensusPeers = append(nc.consensusPeers, n.PeerId)
} }
if n.HasType(NodeTypeFile) { if n.HasType(NodeTypeFile) {
fileConfig.filePeers = append(fileConfig.filePeers, n.PeerId) nc.filePeers = append(nc.filePeers, n.PeerId)
} }
if n.HasType(NodeTypeCoordinator) { 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 return
} }
var beforeId = "" var beforeId = ""
if s.last != nil { if s.last != nil {
beforeId = s.last.Id() beforeId = s.last.Id()
} }
log.Info("configuration changed", zap.String("before", beforeId), zap.String("after", fileConfig.Id())) log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id()))
s.last = fileConfig s.last = nc
return return
} }
func nodeFromConfigNode(n NodeConfig) (*Node, error) { func (s *service) Id() string {
p, err := peer.Decode(n.PeerId) s.mu.RLock()
if err != nil { defer s.mu.RUnlock()
return nil, err return s.last.Id()
} }
ic, err := p.ExtractPublicKey()
if err != nil { func (s *service) Configuration() Configuration {
return nil, err s.mu.RLock()
} defer s.mu.RUnlock()
return s.last.Configuration()
icRaw, err := ic.Raw() }
if err != nil {
return nil, err func (s *service) NodeIds(spaceId string) []string {
} s.mu.RLock()
defer s.mu.RUnlock()
sigPubKey, err := crypto.UnmarshalEd25519PublicKey(icRaw) return s.last.NodeIds(spaceId)
if err != nil { }
return nil, err
} func (s *service) IsResponsible(spaceId string) bool {
s.mu.RLock()
return &Node{ defer s.mu.RUnlock()
Addresses: n.Addresses, return s.last.IsResponsible(spaceId)
PeerId: n.PeerId, }
SigningKey: sigPubKey,
}, nil 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)
} }

9
nodeconf/source.go Normal file
View File

@ -0,0 +1,9 @@
package nodeconf
import "context"
const CNameSource = "common.nodeconf.source"
type Source interface {
GetLast(ctx context.Context) (c Configuration, err error)
}

10
nodeconf/store.go Normal file
View File

@ -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)
}

View File

@ -5,6 +5,7 @@ import (
"github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app"
"github.com/anytypeio/any-sync/commonspace/object/accountdata" "github.com/anytypeio/any-sync/commonspace/object/accountdata"
"github.com/anytypeio/any-sync/nodeconf" "github.com/anytypeio/any-sync/nodeconf"
"github.com/anytypeio/any-sync/nodeconf/nodeconfstore"
"github.com/anytypeio/any-sync/util/crypto" "github.com/anytypeio/any-sync/util/crypto"
) )
@ -47,8 +48,8 @@ func (s *AccountTestService) Account() *accountdata.AccountKeys {
return s.acc return s.acc
} }
func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig { func (s *AccountTestService) NodeConf(addrs []string) nodeconfstore.NodeConfig {
return nodeconf.NodeConfig{ return nodeconfstore.NodeConfig{
PeerId: s.acc.PeerId, PeerId: s.acc.PeerId,
Addresses: addrs, Addresses: addrs,
Types: []nodeconf.NodeType{nodeconf.NodeTypeTree}, Types: []nodeconf.NodeType{nodeconf.NodeTypeTree},

View File

@ -3,7 +3,7 @@ package testnodeconf
import ( import (
"github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/accountservice"
"github.com/anytypeio/any-sync/app" "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" "github.com/anytypeio/any-sync/testutil/accounttest"
) )
@ -24,7 +24,7 @@ func GenNodeConfig(num int) (conf *Config) {
} }
type Config struct { type Config struct {
nodes []nodeconf.NodeConfig nodes []nodeconfstore.NodeConfig
configs []*accounttest.AccountTestService configs []*accounttest.AccountTestService
} }
@ -35,7 +35,7 @@ func (c *Config) GetNodesConfId() string {
return "test" return "test"
} }
func (c *Config) GetNodes() []nodeconf.NodeConfig { func (c *Config) GetNodes() []nodeconfstore.NodeConfig {
return c.nodes return c.nodes
} }