Skip to content

Commit

Permalink
[#356] netmap: Simplify zero subnet processing in IterateSubnets
Browse files Browse the repository at this point in the history
For now we don't need to distinguish cases of missing zero subnet's
attribute and the one with `True` value.

Remove local enum `zeroStatus` of `IterateSubnets` since we need to
distinguish between two statuses and use `bool` variable for this.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Nov 24, 2021
1 parent 896cee4 commit abc494b
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions netmap/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,12 @@ var errNoSubnets = errors.New("no subnets")
func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
attrs := node.GetAttributes()

type zeroStatus uint8

const (
_ zeroStatus = iota
// missing attribute of zero subnet
zeroNoAttr
// with `False` attribute
zeroExit
// with `True` attribute
zeroEntry
)

var (
err error
id refs.SubnetID
entries uint

stZero = zeroNoAttr
zeroEntry = true
)

for i := 0; i < len(attrs); i++ { // range must not be used because of attrs mutation in body
Expand All @@ -172,15 +160,8 @@ func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
// update status of zero subnet
isZero := refs.IsZeroSubnet(&id)

if stZero == zeroNoAttr { // in order to not reset if has been already set
if isZero {
if val == attrSubnetValEntry {
// clear True attribute for zero subnet is also possible
stZero = zeroEntry
} else {
stZero = zeroExit
}
}
if isZero {
zeroEntry = val == attrSubnetValEntry
}

// continue to process only the subnets to which the node belongs
Expand Down Expand Up @@ -213,7 +194,7 @@ func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
entries++
}

if stZero == zeroNoAttr {
if zeroEntry {
// missing attribute of zero subnet equivalent to entry
refs.MakeZeroSubnet(&id)

Expand Down

0 comments on commit abc494b

Please sign in to comment.