github.com/jimmyx0x/go-ethereum@v1.10.28/les/vflux/server/status.go (about)

     1  // Copyright 2021 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package server
    18  
    19  import (
    20  	"reflect"
    21  
    22  	"github.com/ethereum/go-ethereum/p2p/nodestate"
    23  )
    24  
    25  type peerWrapper struct{ clientPeer } // the NodeStateMachine type system needs this wrapper
    26  
    27  // serverSetup is a wrapper of the node state machine setup, which contains
    28  // all the created flags and fields used in the vflux server side.
    29  type serverSetup struct {
    30  	setup       *nodestate.Setup
    31  	clientField nodestate.Field // Field contains the client peer handler
    32  
    33  	// Flags and fields controlled by balance tracker. BalanceTracker
    34  	// is responsible for setting/deleting these flags or fields.
    35  	priorityFlag nodestate.Flags // Flag is set if the node has a positive balance
    36  	updateFlag   nodestate.Flags // Flag is set whenever the node balance is changed(priority changed)
    37  	balanceField nodestate.Field // Field contains the client balance for priority calculation
    38  
    39  	// Flags and fields controlled by priority queue. Priority queue
    40  	// is responsible for setting/deleting these flags or fields.
    41  	activeFlag    nodestate.Flags // Flag is set if the node is active
    42  	inactiveFlag  nodestate.Flags // Flag is set if the node is inactive
    43  	capacityField nodestate.Field // Field contains the capacity of the node
    44  	queueField    nodestate.Field // Field contains the information in the priority queue
    45  }
    46  
    47  // newServerSetup initializes the setup for state machine and returns the flags/fields group.
    48  func newServerSetup() *serverSetup {
    49  	setup := &serverSetup{setup: &nodestate.Setup{}}
    50  	setup.clientField = setup.setup.NewField("client", reflect.TypeOf(peerWrapper{}))
    51  	setup.priorityFlag = setup.setup.NewFlag("priority")
    52  	setup.updateFlag = setup.setup.NewFlag("update")
    53  	setup.balanceField = setup.setup.NewField("balance", reflect.TypeOf(&nodeBalance{}))
    54  	setup.activeFlag = setup.setup.NewFlag("active")
    55  	setup.inactiveFlag = setup.setup.NewFlag("inactive")
    56  	setup.capacityField = setup.setup.NewField("capacity", reflect.TypeOf(uint64(0)))
    57  	setup.queueField = setup.setup.NewField("queue", reflect.TypeOf(&ppNodeInfo{}))
    58  	return setup
    59  }