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.

103 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
  1. package proxy
  2. import (
  3. . "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. 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 tmsp 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. 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 tmsp 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 = *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. app.BaseService.OnStart()
  59. // query connection
  60. querycli, err := app.clientCreator.NewTMSPClient()
  61. if err != nil {
  62. return err
  63. }
  64. app.queryConn = NewAppConnQuery(querycli)
  65. // mempool connection
  66. memcli, err := app.clientCreator.NewTMSPClient()
  67. if err != nil {
  68. return err
  69. }
  70. app.mempoolConn = NewAppConnMempool(memcli)
  71. // consensus connection
  72. concli, err := app.clientCreator.NewTMSPClient()
  73. if err != nil {
  74. return err
  75. }
  76. app.consensusConn = NewAppConnConsensus(concli)
  77. // ensure app is synced to the latest state
  78. if app.handshaker != nil {
  79. return app.handshaker.Handshake(app)
  80. }
  81. return nil
  82. }