status.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. package server
  17. import (
  18. "reflect"
  19. "github.com/ethereum/go-ethereum/p2p/nodestate"
  20. )
  21. type peerWrapper struct{ clientPeer } // the NodeStateMachine type system needs this wrapper
  22. // serverSetup is a wrapper of the node state machine setup, which contains
  23. // all the created flags and fields used in the vflux server side.
  24. type serverSetup struct {
  25. setup *nodestate.Setup
  26. clientField nodestate.Field // Field contains the client peer handler
  27. // Flags and fields controlled by balance tracker. BalanceTracker
  28. // is responsible for setting/deleting these flags or fields.
  29. priorityFlag nodestate.Flags // Flag is set if the node has a positive balance
  30. updateFlag nodestate.Flags // Flag is set whenever the node balance is changed(priority changed)
  31. balanceField nodestate.Field // Field contains the client balance for priority calculation
  32. // Flags and fields controlled by priority queue. Priority queue
  33. // is responsible for setting/deleting these flags or fields.
  34. activeFlag nodestate.Flags // Flag is set if the node is active
  35. inactiveFlag nodestate.Flags // Flag is set if the node is inactive
  36. capacityField nodestate.Field // Field contains the capacity of the node
  37. queueField nodestate.Field // Field contains the infomration in the priority queue
  38. }
  39. // newServerSetup initializes the setup for state machine and returns the flags/fields group.
  40. func newServerSetup() *serverSetup {
  41. setup := &serverSetup{setup: &nodestate.Setup{}}
  42. setup.clientField = setup.setup.NewField("client", reflect.TypeOf(peerWrapper{}))
  43. setup.priorityFlag = setup.setup.NewFlag("priority")
  44. setup.updateFlag = setup.setup.NewFlag("update")
  45. setup.balanceField = setup.setup.NewField("balance", reflect.TypeOf(&nodeBalance{}))
  46. setup.activeFlag = setup.setup.NewFlag("active")
  47. setup.inactiveFlag = setup.setup.NewFlag("inactive")
  48. setup.capacityField = setup.setup.NewField("capacity", reflect.TypeOf(uint64(0)))
  49. setup.queueField = setup.setup.NewField("queue", reflect.TypeOf(&ppNodeInfo{}))
  50. return setup
  51. }