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.

100 lines
2.5 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
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(nil, "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. querycli.SetLogger(app.Logger.With("module", "abci-client", "connection", "query"))
  58. if err != nil {
  59. return err
  60. }
  61. app.queryConn = NewAppConnQuery(querycli)
  62. // mempool connection
  63. memcli, err := app.clientCreator.NewABCIClient()
  64. memcli.SetLogger(app.Logger.With("module", "abci-client", "connection", "mempool"))
  65. if err != nil {
  66. return err
  67. }
  68. app.mempoolConn = NewAppConnMempool(memcli)
  69. // consensus connection
  70. concli, err := app.clientCreator.NewABCIClient()
  71. concli.SetLogger(app.Logger.With("module", "abci-client", "connection", "consensus"))
  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. }