From d648b86776cf44aa4e00540520a019693acce859 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 14 Jun 2022 17:27:51 +0300 Subject: [PATCH] [#227] netmap: Fix minor blots in documentation/code Signed-off-by: Leonard Lyubich --- netmap/doc.go | 6 +++--- netmap/helper_test.go | 4 ++-- netmap/netmap.go | 5 +++-- netmap/network_info.go | 28 ++++++++++++++-------------- netmap/network_info_test.go | 6 +++--- netmap/node_info.go | 2 +- netmap/policy.go | 24 ++++++++++++------------ netmap/selector.go | 2 +- netmap/selector_test.go | 8 ++++---- netmap/test/generate.go | 6 +++--- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/netmap/doc.go b/netmap/doc.go index e03a2b5..464dbf1 100644 --- a/netmap/doc.go +++ b/netmap/doc.go @@ -21,19 +21,19 @@ On client side: import "github.com/nspcc-dev/neofs-api-go/v2/netmap" var msg netmap.NodeInfo - msg.WriteToV2(&msg) + info.WriteToV2(&msg) // send msg On server side: // recv msg - var info netmap.NodeInfo + var info NodeInfo err := info.ReadFromV2(msg) // ... - // process dec + // process info Using package types in an application is recommended to potentially work with different protocol versions with which these types are compatible. diff --git a/netmap/helper_test.go b/netmap/helper_test.go index f5cc831..c283f47 100644 --- a/netmap/helper_test.go +++ b/netmap/helper_test.go @@ -20,7 +20,7 @@ func newFilter(name string, k, v string, op netmap.Operation, fs ...Filter) (f F func newSelector(name string, attr string, count uint32, filter string, clause func(*Selector)) (s Selector) { s.SetName(name) s.SelectByBucketAttribute(attr) - s.SetNodeAmount(count) + s.SetNumberOfNodes(count) clause(&s) s.SetFilterName(filter) return s @@ -35,7 +35,7 @@ func newPlacementPolicy(bf uint32, rs []ReplicaDescriptor, ss []Selector, fs []F } func newReplica(c uint32, s string) (r ReplicaDescriptor) { - r.SetAmount(c) + r.SetNumberOfObjects(c) r.SetSelectorName(s) return r } diff --git a/netmap/netmap.go b/netmap/netmap.go index a5b2933..2f6b2b8 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -42,6 +42,7 @@ func (n nodes) Hash() uint64 { if len(n) > 0 { return n[0].Hash() } + return 0 } @@ -73,8 +74,8 @@ func flattenNodes(ns []nodes) nodes { // PlacementVectors sorts container nodes returned by ContainerNodes method // and returns placement vectors for the entity identified by the given pivot. -// For example,in order to build node list to store the object, binary-encoded -// object identifier can be used as pivot. Result is deterministic for +// For example, in order to build node list to store the object, binary-encoded +// object identifier can be used as pivot. Result is deterministic for // the fixed NetMap and parameters. func (m NetMap) PlacementVectors(vectors [][]NodeInfo, pivot []byte) ([][]NodeInfo, error) { h := hrw.Hash(pivot) diff --git a/netmap/network_info.go b/netmap/network_info.go index 002ec80..eb4ebb1 100644 --- a/netmap/network_info.go +++ b/netmap/network_info.go @@ -31,7 +31,7 @@ func (x *NetworkInfo) readFromV2(m netmap.NetworkInfo, checkFieldPresence bool) } if checkFieldPresence && c.NumberOfParameters() <= 0 { - return fmt.Errorf("missing network parameters") + return errors.New("missing network parameters") } var err error @@ -68,7 +68,7 @@ func (x *NetworkInfo) readFromV2(m netmap.NetworkInfo, checkFieldPresence bool) configStoragePrice, configContainerFee, configNamedContainerFee, - configEigenTrustIterationsAmount, + configEigenTrustNumberOfIterations, configEpochDuration, configIRCandidateFee, configMaxObjSize, @@ -239,7 +239,7 @@ func (x *NetworkInfo) IterateRawNetworkParameters(f func(name string, value []by configStoragePrice, configContainerFee, configNamedContainerFee, - configEigenTrustIterationsAmount, + configEigenTrustNumberOfIterations, configEpochDuration, configIRCandidateFee, configMaxObjSize, @@ -374,29 +374,29 @@ func (x NetworkInfo) EigenTrustAlpha() float64 { return alpha } -const configEigenTrustIterationsAmount = "EigenTrustIterations" +const configEigenTrustNumberOfIterations = "EigenTrustIterations" -// SetEigenTrustIterationAmount sets number of iterations of the EigenTrust +// SetNumberOfEigenTrustIterations sets number of iterations of the EigenTrust // algorithm to perform. The algorithm is used by the storage nodes for // calculating the reputation values. // -// See also EigenTrustIterationAmount. -func (x *NetworkInfo) SetEigenTrustIterationAmount(amount uint64) { - x.setConfigUint64(configEigenTrustIterationsAmount, amount) +// See also NumberOfEigenTrustIterations. +func (x *NetworkInfo) SetNumberOfEigenTrustIterations(num uint64) { + x.setConfigUint64(configEigenTrustNumberOfIterations, num) } -// EigenTrustIterationAmount returns EigenTrust iteration amount set using -// SetEigenTrustIterationAmount. +// NumberOfEigenTrustIterations returns number of EigenTrust iterations set +// using SetNumberOfEigenTrustIterations. // // Zero NetworkInfo has zero iteration number. -func (x NetworkInfo) EigenTrustIterationAmount() uint64 { - return x.configUint64(configEigenTrustIterationsAmount) +func (x NetworkInfo) NumberOfEigenTrustIterations() uint64 { + return x.configUint64(configEigenTrustNumberOfIterations) } const configEpochDuration = "EpochDuration" -// SetEpochDuration sets NeoFS epoch duration measured in block amount of the -// NeoFS Sidechain. +// SetEpochDuration sets NeoFS epoch duration measured in number of blocks of +// the NeoFS Sidechain. // // See also EpochDuration. func (x *NetworkInfo) SetEpochDuration(blocks uint64) { diff --git a/netmap/network_info_test.go b/netmap/network_info_test.go index cc096f5..d24fb5d 100644 --- a/netmap/network_info_test.go +++ b/netmap/network_info_test.go @@ -161,10 +161,10 @@ func TestNetworkInfo_EigenTrustAlpha(t *testing.T) { ) } -func TestNetworkInfo_EigenTrustIterationAmount(t *testing.T) { +func TestNetworkInfo_NumberOfEigenTrustIterations(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) interface{} { return x.EigenTrustIterationAmount() }, - func(info *NetworkInfo, val interface{}) { info.SetEigenTrustIterationAmount(val.(uint64)) }, + func(x NetworkInfo) interface{} { return x.NumberOfEigenTrustIterations() }, + func(info *NetworkInfo, val interface{}) { info.SetNumberOfEigenTrustIterations(val.(uint64)) }, uint64(1), uint64(2), "EigenTrustIterations", func(val interface{}) []byte { data := make([]byte, 8) diff --git a/netmap/node_info.go b/netmap/node_info.go index b1dcdfb..4689211 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -79,7 +79,7 @@ func (x *NodeInfo) readFromV2(m netmap.NodeInfo, checkFieldPresence bool) error } default: if attributes[i].GetValue() == "" { - return fmt.Errorf("empty value of the attribute #%d", i) + return fmt.Errorf("empty value of the attribute %s", key) } } } diff --git a/netmap/policy.go b/netmap/policy.go index 5219bf8..b7a12b1 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -107,15 +107,15 @@ type ReplicaDescriptor struct { m netmap.Replica } -// SetAmount sets number of object replicas. -func (r *ReplicaDescriptor) SetAmount(c uint32) { +// SetNumberOfObjects sets number of object replicas. +func (r *ReplicaDescriptor) SetNumberOfObjects(c uint32) { r.m.SetCount(c) } -// Amount returns number set using SetAmount. +// NumberOfObjects returns number set using SetNumberOfObjects. // -// Zero ReplicaDescriptor has zero object amount. -func (r ReplicaDescriptor) Amount() uint32 { +// Zero ReplicaDescriptor has zero number of objects. +func (r ReplicaDescriptor) NumberOfObjects() uint32 { return r.m.GetCount() } @@ -142,18 +142,18 @@ func (p *PlacementPolicy) AddReplicas(rs ...ReplicaDescriptor) { } } -// NumberOfReplicas returns amount of replica descriptors set using AddReplicas. +// NumberOfReplicas returns number of replica descriptors set using AddReplicas. // // Zero PlacementPolicy has no replicas. func (p PlacementPolicy) NumberOfReplicas() int { return len(p.replicas) } -// ReplicaAmountByIndex returns amount of object replicas from the i-th replica +// ReplicaNumberByIndex returns number of object replicas from the i-th replica // descriptor. Index MUST be in range [0; NumberOfReplicas()). // // Zero PlacementPolicy has no replicas. -func (p PlacementPolicy) ReplicaAmountByIndex(i int) uint32 { +func (p PlacementPolicy) ReplicaNumberByIndex(i int) uint32 { return p.replicas[i].GetCount() } @@ -178,11 +178,11 @@ func (s *Selector) SetName(name string) { s.m.SetName(name) } -// SetNodeAmount sets number of nodes to select from the bucket. +// SetNumberOfNodes sets number of nodes to select from the bucket. // // Zero Selector selects nothing. -func (s *Selector) SetNodeAmount(amount uint32) { - s.m.SetCount(amount) +func (s *Selector) SetNumberOfNodes(num uint32) { + s.m.SetCount(num) } // SelectByBucketAttribute sets attribute of the bucket to select nodes from. @@ -239,7 +239,7 @@ type Filter struct { } // SetName sets name with which the Filter can be referenced or, for inner filters, -// to which the Filter references. Top-level filters MUST have be named. The name +// to which the Filter references. Top-level filters MUST be named. The name // MUST NOT be '*'. // // Zero Filter is unnamed. diff --git a/netmap/selector.go b/netmap/selector.go index 03beb59..2e66b9f 100644 --- a/netmap/selector.go +++ b/netmap/selector.go @@ -35,7 +35,7 @@ func (c *context) processSelectors(p PlacementPolicy) error { return nil } -// calcNodesCount returns amount of buckets and minimum number of nodes in every bucket +// calcNodesCount returns number of buckets and minimum number of nodes in every bucket // for the given selector. func calcNodesCount(s netmap.Selector) (int, int) { switch s.GetClause() { diff --git a/netmap/selector_test.go b/netmap/selector_test.go index 6de1546..7f31e49 100644 --- a/netmap/selector_test.go +++ b/netmap/selector_test.go @@ -254,15 +254,15 @@ func TestSelector_SetName(t *testing.T) { require.Equal(t, name, s.m.GetName()) } -func TestSelector_SetNodeAmount(t *testing.T) { - const amount = 3 +func TestSelector_SetNumberOfNodes(t *testing.T) { + const num = 3 var s Selector require.Zero(t, s.m.GetCount()) - s.SetNodeAmount(amount) + s.SetNumberOfNodes(num) - require.EqualValues(t, amount, s.m.GetCount()) + require.EqualValues(t, num, s.m.GetCount()) } func TestSelectorClauses(t *testing.T) { diff --git a/netmap/test/generate.go b/netmap/test/generate.go index b0874d2..17956d5 100644 --- a/netmap/test/generate.go +++ b/netmap/test/generate.go @@ -23,7 +23,7 @@ func Filter() netmap.Filter { // Replica returns random netmap.ReplicaDescriptor. func Replica() (x netmap.ReplicaDescriptor) { - x.SetAmount(666) + x.SetNumberOfObjects(666) x.SetSelectorName("selector") return @@ -31,7 +31,7 @@ func Replica() (x netmap.ReplicaDescriptor) { // Selector returns random netmap.Selector. func Selector() (x netmap.Selector) { - x.SetNodeAmount(11) + x.SetNumberOfNodes(11) x.SetName("name") x.SetFilterName("filter") x.SelectByBucketAttribute("attribute") @@ -60,7 +60,7 @@ func NetworkInfo() (x netmap.NetworkInfo) { x.SetStoragePrice(2) x.SetContainerFee(3) x.SetEigenTrustAlpha(0.4) - x.SetEigenTrustIterationAmount(5) + x.SetNumberOfEigenTrustIterations(5) x.SetEpochDuration(6) x.SetIRCandidateFee(7) x.SetMaxObjectSize(8)