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.

101 lines
2.1 KiB

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