You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.2 KiB

7 years ago
8 years ago
8 years ago
8 years ago
  1. package core
  2. import (
  3. crypto "github.com/tendermint/go-crypto"
  4. "github.com/tendermint/tendermint/consensus"
  5. cstypes "github.com/tendermint/tendermint/consensus/types"
  6. p2p "github.com/tendermint/tendermint/p2p"
  7. "github.com/tendermint/tendermint/proxy"
  8. sm "github.com/tendermint/tendermint/state"
  9. "github.com/tendermint/tendermint/state/txindex"
  10. "github.com/tendermint/tendermint/types"
  11. "github.com/tendermint/tmlibs/log"
  12. )
  13. //----------------------------------------------
  14. // These interfaces are used by RPC and must be thread safe
  15. type Consensus interface {
  16. GetState() *sm.State
  17. GetValidators() (int, []*types.Validator)
  18. GetRoundState() *cstypes.RoundState
  19. }
  20. type P2P interface {
  21. Listeners() []p2p.Listener
  22. Peers() p2p.IPeerSet
  23. NumPeers() (outbound, inbound, dialig int)
  24. NodeInfo() *p2p.NodeInfo
  25. IsListening() bool
  26. DialSeeds(*p2p.AddrBook, []string) error
  27. }
  28. //----------------------------------------------
  29. // These package level globals come with setters
  30. // that are expected to be called only once, on startup
  31. var (
  32. // external, thread safe interfaces
  33. eventSwitch types.EventSwitch
  34. proxyAppQuery proxy.AppConnQuery
  35. // interfaces defined in types and above
  36. blockStore types.BlockStore
  37. mempool types.Mempool
  38. consensusState Consensus
  39. p2pSwitch P2P
  40. // objects
  41. pubKey crypto.PubKey
  42. genDoc *types.GenesisDoc // cache the genesis structure
  43. addrBook *p2p.AddrBook
  44. txIndexer txindex.TxIndexer
  45. consensusReactor *consensus.ConsensusReactor
  46. logger log.Logger
  47. )
  48. func SetEventSwitch(evsw types.EventSwitch) {
  49. eventSwitch = evsw
  50. }
  51. func SetBlockStore(bs types.BlockStore) {
  52. blockStore = bs
  53. }
  54. func SetMempool(mem types.Mempool) {
  55. mempool = mem
  56. }
  57. func SetConsensusState(cs Consensus) {
  58. consensusState = cs
  59. }
  60. func SetSwitch(sw P2P) {
  61. p2pSwitch = sw
  62. }
  63. func SetPubKey(pk crypto.PubKey) {
  64. pubKey = pk
  65. }
  66. func SetGenesisDoc(doc *types.GenesisDoc) {
  67. genDoc = doc
  68. }
  69. func SetAddrBook(book *p2p.AddrBook) {
  70. addrBook = book
  71. }
  72. func SetProxyAppQuery(appConn proxy.AppConnQuery) {
  73. proxyAppQuery = appConn
  74. }
  75. func SetTxIndexer(indexer txindex.TxIndexer) {
  76. txIndexer = indexer
  77. }
  78. func SetConsensusReactor(conR *consensus.ConsensusReactor) {
  79. consensusReactor = conR
  80. }
  81. func SetLogger(l log.Logger) {
  82. logger = l
  83. }