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.

87 lines
2.7 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. )
  10. // ClientCreator creates new ABCI clients.
  11. type ClientCreator interface {
  12. // NewABCIClient returns a new ABCI client.
  13. NewABCIClient() (abcicli.Client, error)
  14. }
  15. //----------------------------------------------------
  16. // local proxy uses a mutex on an in-proc app
  17. type localClientCreator struct {
  18. mtx *tmsync.Mutex
  19. app types.Application
  20. }
  21. // NewLocalClientCreator returns a ClientCreator for the given app,
  22. // which will be running locally.
  23. func NewLocalClientCreator(app types.Application) ClientCreator {
  24. return &localClientCreator{
  25. mtx: new(tmsync.Mutex),
  26. app: app,
  27. }
  28. }
  29. func (l *localClientCreator) NewABCIClient() (abcicli.Client, error) {
  30. return abcicli.NewLocalClient(l.mtx, l.app), nil
  31. }
  32. //---------------------------------------------------------------
  33. // remote proxy opens new connections to an external app process
  34. type remoteClientCreator struct {
  35. addr string
  36. transport string
  37. mustConnect bool
  38. }
  39. // NewRemoteClientCreator returns a ClientCreator for the given address (e.g.
  40. // "192.168.0.1") and transport (e.g. "tcp"). Set mustConnect to true if you
  41. // want the client to connect before reporting success.
  42. func NewRemoteClientCreator(addr, transport string, mustConnect bool) ClientCreator {
  43. return &remoteClientCreator{
  44. addr: addr,
  45. transport: transport,
  46. mustConnect: mustConnect,
  47. }
  48. }
  49. func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
  50. remoteApp, err := abcicli.NewClient(r.addr, r.transport, r.mustConnect)
  51. if err != nil {
  52. return nil, fmt.Errorf("failed to connect to proxy: %w", err)
  53. }
  54. return remoteApp, nil
  55. }
  56. // DefaultClientCreator returns a default ClientCreator, which will create a
  57. // local client if addr is one of: 'counter', 'counter_serial', 'kvstore',
  58. // 'persistent_kvstore' or 'noop', otherwise - a remote client.
  59. func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
  60. switch addr {
  61. case "counter":
  62. return NewLocalClientCreator(counter.NewApplication(false))
  63. case "counter_serial":
  64. return NewLocalClientCreator(counter.NewApplication(true))
  65. case "kvstore":
  66. return NewLocalClientCreator(kvstore.NewApplication())
  67. case "persistent_kvstore":
  68. return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
  69. case "noop":
  70. return NewLocalClientCreator(types.NewBaseApplication())
  71. default:
  72. mustConnect := false // loop retrying
  73. return NewRemoteClientCreator(addr, transport, mustConnect)
  74. }
  75. }