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.

97 lines
2.3 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
  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. Mempool() AppConnMempool
  9. Consensus() AppConnConsensus
  10. Query() AppConnQuery
  11. }
  12. func NewAppConns(config cfg.Config, newTMSPClient NewTMSPClient, state State, blockStore BlockStore) AppConns {
  13. return NewMultiAppConn(config, newTMSPClient, state, blockStore)
  14. }
  15. // a multiAppConn is made of a few appConns (mempool, consensus, query)
  16. // and manages their underlying tmsp clients, ensuring they reboot together
  17. type multiAppConn struct {
  18. QuitService
  19. config cfg.Config
  20. state State
  21. blockStore BlockStore
  22. mempoolConn *appConnMempool
  23. consensusConn *appConnConsensus
  24. queryConn *appConnQuery
  25. newTMSPClient NewTMSPClient
  26. }
  27. // Make all necessary tmsp connections to the application
  28. func NewMultiAppConn(config cfg.Config, newTMSPClient NewTMSPClient, state State, blockStore BlockStore) *multiAppConn {
  29. multiAppConn := &multiAppConn{
  30. config: config,
  31. state: state,
  32. blockStore: blockStore,
  33. newTMSPClient: newTMSPClient,
  34. }
  35. multiAppConn.QuitService = *NewQuitService(log, "multiAppConn", multiAppConn)
  36. multiAppConn.Start()
  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. addr := app.config.GetString("proxy_app")
  53. transport := app.config.GetString("tmsp")
  54. // query connection
  55. querycli, err := app.newTMSPClient(addr, transport)
  56. if err != nil {
  57. return err
  58. }
  59. app.queryConn = NewAppConnQuery(querycli)
  60. // mempool connection
  61. memcli, err := app.newTMSPClient(addr, transport)
  62. if err != nil {
  63. return err
  64. }
  65. app.mempoolConn = NewAppConnMempool(memcli)
  66. // consensus connection
  67. concli, err := app.newTMSPClient(addr, transport)
  68. if err != nil {
  69. return err
  70. }
  71. app.consensusConn = NewAppConnConsensus(concli)
  72. // TODO: handshake
  73. // TODO: replay blocks
  74. // TODO: (on restart) replay mempool
  75. return nil
  76. }