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.

95 lines
2.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package proxy
  2. import (
  3. . "github.com/tendermint/go-common"
  4. cfg "github.com/tendermint/go-config"
  5. )
  6. // Tendermint's interface to the application consists of multiple connections
  7. type AppConns interface {
  8. Service
  9. Mempool() AppConnMempool
  10. Consensus() AppConnConsensus
  11. Query() AppConnQuery
  12. }
  13. func NewAppConns(config cfg.Config, clientCreator ClientCreator, state State, blockStore BlockStore) AppConns {
  14. return NewMultiAppConn(config, clientCreator, state, blockStore)
  15. }
  16. // a multiAppConn is made of a few appConns (mempool, consensus, query)
  17. // and manages their underlying tmsp clients, ensuring they reboot together
  18. type multiAppConn struct {
  19. QuitService
  20. config cfg.Config
  21. state State
  22. blockStore BlockStore
  23. mempoolConn *appConnMempool
  24. consensusConn *appConnConsensus
  25. queryConn *appConnQuery
  26. clientCreator ClientCreator
  27. }
  28. // Make all necessary tmsp connections to the application
  29. func NewMultiAppConn(config cfg.Config, clientCreator ClientCreator, state State, blockStore BlockStore) *multiAppConn {
  30. multiAppConn := &multiAppConn{
  31. config: config,
  32. state: state,
  33. blockStore: blockStore,
  34. clientCreator: clientCreator,
  35. }
  36. multiAppConn.QuitService = *NewQuitService(log, "multiAppConn", multiAppConn)
  37. return multiAppConn
  38. }
  39. // Returns the mempool connection
  40. func (app *multiAppConn) Mempool() AppConnMempool {
  41. return app.mempoolConn
  42. }
  43. // Returns the consensus Connection
  44. func (app *multiAppConn) Consensus() AppConnConsensus {
  45. return app.consensusConn
  46. }
  47. func (app *multiAppConn) Query() AppConnQuery {
  48. return app.queryConn
  49. }
  50. func (app *multiAppConn) OnStart() error {
  51. app.QuitService.OnStart()
  52. // query connection
  53. querycli, err := app.clientCreator.NewTMSPClient()
  54. if err != nil {
  55. return err
  56. }
  57. app.queryConn = NewAppConnQuery(querycli)
  58. // mempool connection
  59. memcli, err := app.clientCreator.NewTMSPClient()
  60. if err != nil {
  61. return err
  62. }
  63. app.mempoolConn = NewAppConnMempool(memcli)
  64. // consensus connection
  65. concli, err := app.clientCreator.NewTMSPClient()
  66. if err != nil {
  67. return err
  68. }
  69. app.consensusConn = NewAppConnConsensus(concli)
  70. // TODO: handshake
  71. // TODO: replay blocks
  72. // TODO: (on restart) replay mempool
  73. return nil
  74. }