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.

95 lines
2.9 KiB

8 years ago
8 years ago
8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
8 years ago
  1. package proxy
  2. import (
  3. "fmt"
  4. abcicli "github.com/tendermint/tendermint/abci/client"
  5. "github.com/tendermint/tendermint/abci/example/counter"
  6. "github.com/tendermint/tendermint/abci/example/kvstore"
  7. "github.com/tendermint/tendermint/abci/types"
  8. tmsync "github.com/tendermint/tendermint/libs/sync"
  9. e2e "github.com/tendermint/tendermint/test/e2e/app"
  10. )
  11. // ClientCreator creates new ABCI clients.
  12. type ClientCreator interface {
  13. // NewABCIClient returns a new ABCI client.
  14. NewABCIClient() (abcicli.Client, error)
  15. }
  16. //----------------------------------------------------
  17. // local proxy uses a mutex on an in-proc app
  18. type localClientCreator struct {
  19. mtx *tmsync.Mutex
  20. app types.Application
  21. }
  22. // NewLocalClientCreator returns a ClientCreator for the given app,
  23. // which will be running locally.
  24. func NewLocalClientCreator(app types.Application) ClientCreator {
  25. return &localClientCreator{
  26. mtx: new(tmsync.Mutex),
  27. app: app,
  28. }
  29. }
  30. func (l *localClientCreator) NewABCIClient() (abcicli.Client, error) {
  31. return abcicli.NewLocalClient(l.mtx, l.app), nil
  32. }
  33. //---------------------------------------------------------------
  34. // remote proxy opens new connections to an external app process
  35. type remoteClientCreator struct {
  36. addr string
  37. transport string
  38. mustConnect bool
  39. }
  40. // NewRemoteClientCreator returns a ClientCreator for the given address (e.g.
  41. // "192.168.0.1") and transport (e.g. "tcp"). Set mustConnect to true if you
  42. // want the client to connect before reporting success.
  43. func NewRemoteClientCreator(addr, transport string, mustConnect bool) ClientCreator {
  44. return &remoteClientCreator{
  45. addr: addr,
  46. transport: transport,
  47. mustConnect: mustConnect,
  48. }
  49. }
  50. func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
  51. remoteApp, err := abcicli.NewClient(r.addr, r.transport, r.mustConnect)
  52. if err != nil {
  53. return nil, fmt.Errorf("failed to connect to proxy: %w", err)
  54. }
  55. return remoteApp, nil
  56. }
  57. // DefaultClientCreator returns a default ClientCreator, which will create a
  58. // local client if addr is one of: 'counter', 'counter_serial', 'kvstore',
  59. // 'persistent_kvstore' or 'noop', otherwise - a remote client.
  60. func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
  61. switch addr {
  62. case "counter":
  63. return NewLocalClientCreator(counter.NewApplication(false))
  64. case "counter_serial":
  65. return NewLocalClientCreator(counter.NewApplication(true))
  66. case "kvstore":
  67. return NewLocalClientCreator(kvstore.NewApplication())
  68. case "persistent_kvstore":
  69. return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
  70. case "e2e":
  71. app, err := e2e.NewApplication(e2e.DefaultConfig(dbDir))
  72. if err != nil {
  73. panic(err)
  74. }
  75. return NewLocalClientCreator(app)
  76. case "noop":
  77. return NewLocalClientCreator(types.NewBaseApplication())
  78. default:
  79. mustConnect := false // loop retrying
  80. return NewRemoteClientCreator(addr, transport, mustConnect)
  81. }
  82. }