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.

98 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
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
8 years ago
  1. package proxy
  2. import (
  3. cmn "github.com/tendermint/tmlibs/common"
  4. )
  5. //-----------------------------
  6. // Tendermint's interface to the application consists of multiple connections
  7. type AppConns interface {
  8. cmn.Service
  9. Mempool() AppConnMempool
  10. Consensus() AppConnConsensus
  11. Query() AppConnQuery
  12. }
  13. func NewAppConns(clientCreator ClientCreator, handshaker Handshaker) AppConns {
  14. return NewMultiAppConn(clientCreator, handshaker)
  15. }
  16. //-----------------------------
  17. // multiAppConn implements AppConns
  18. type Handshaker interface {
  19. Handshake(AppConns) error
  20. }
  21. // a multiAppConn is made of a few appConns (mempool, consensus, query)
  22. // and manages their underlying abci clients, including the handshake
  23. // which ensures the app and tendermint are synced.
  24. // TODO: on app restart, clients must reboot together
  25. type multiAppConn struct {
  26. cmn.BaseService
  27. handshaker Handshaker
  28. mempoolConn *appConnMempool
  29. consensusConn *appConnConsensus
  30. queryConn *appConnQuery
  31. clientCreator ClientCreator
  32. }
  33. // Make all necessary abci connections to the application
  34. func NewMultiAppConn(clientCreator ClientCreator, handshaker Handshaker) *multiAppConn {
  35. multiAppConn := &multiAppConn{
  36. handshaker: handshaker,
  37. clientCreator: clientCreator,
  38. }
  39. multiAppConn.BaseService = *cmn.NewBaseService(log, "multiAppConn", multiAppConn)
  40. return multiAppConn
  41. }
  42. // Returns the mempool connection
  43. func (app *multiAppConn) Mempool() AppConnMempool {
  44. return app.mempoolConn
  45. }
  46. // Returns the consensus Connection
  47. func (app *multiAppConn) Consensus() AppConnConsensus {
  48. return app.consensusConn
  49. }
  50. // Returns the query Connection
  51. func (app *multiAppConn) Query() AppConnQuery {
  52. return app.queryConn
  53. }
  54. func (app *multiAppConn) OnStart() error {
  55. // query connection
  56. querycli, err := app.clientCreator.NewABCIClient()
  57. if err != nil {
  58. return err
  59. }
  60. app.queryConn = NewAppConnQuery(querycli)
  61. // mempool connection
  62. memcli, err := app.clientCreator.NewABCIClient()
  63. if err != nil {
  64. return err
  65. }
  66. app.mempoolConn = NewAppConnMempool(memcli)
  67. // consensus connection
  68. concli, err := app.clientCreator.NewABCIClient()
  69. if err != nil {
  70. return err
  71. }
  72. app.consensusConn = NewAppConnConsensus(concli)
  73. // ensure app is synced to the latest state
  74. if app.handshaker != nil {
  75. return app.handshaker.Handshake(app)
  76. }
  77. return nil
  78. }