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.

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