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.

82 lines
2.2 KiB

8 years ago
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. "sync"
  4. "github.com/pkg/errors"
  5. abcicli "github.com/tendermint/tendermint/abci/client"
  6. "github.com/tendermint/tendermint/abci/example/counter"
  7. "github.com/tendermint/tendermint/abci/example/kvstore"
  8. "github.com/tendermint/tendermint/abci/types"
  9. )
  10. // NewABCIClient returns newly connected client
  11. type ClientCreator interface {
  12. NewABCIClient() (abcicli.Client, error)
  13. }
  14. //----------------------------------------------------
  15. // local proxy uses a mutex on an in-proc app
  16. type localClientCreator struct {
  17. mtx *sync.Mutex
  18. app types.Application
  19. }
  20. func NewLocalClientCreator(app types.Application) ClientCreator {
  21. return &localClientCreator{
  22. mtx: new(sync.Mutex),
  23. app: app,
  24. }
  25. }
  26. func (l *localClientCreator) NewABCIClient() (abcicli.Client, error) {
  27. return abcicli.NewLocalClient(l.mtx, l.app), nil
  28. }
  29. //---------------------------------------------------------------
  30. // remote proxy opens new connections to an external app process
  31. type remoteClientCreator struct {
  32. addr string
  33. transport string
  34. mustConnect bool
  35. }
  36. func NewRemoteClientCreator(addr, transport string, mustConnect bool) ClientCreator {
  37. return &remoteClientCreator{
  38. addr: addr,
  39. transport: transport,
  40. mustConnect: mustConnect,
  41. }
  42. }
  43. func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
  44. remoteApp, err := abcicli.NewClient(r.addr, r.transport, r.mustConnect)
  45. if err != nil {
  46. return nil, errors.Wrap(err, "Failed to connect to proxy")
  47. }
  48. return remoteApp, nil
  49. }
  50. //-----------------------------------------------------------------
  51. // default
  52. func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
  53. switch addr {
  54. case "counter":
  55. return NewLocalClientCreator(counter.NewApplication(false))
  56. case "counter_serial":
  57. return NewLocalClientCreator(counter.NewApplication(true))
  58. case "kvstore":
  59. return NewLocalClientCreator(kvstore.NewApplication())
  60. case "persistent_kvstore":
  61. return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
  62. case "noop":
  63. return NewLocalClientCreator(types.NewBaseApplication())
  64. default:
  65. mustConnect := false // loop retrying
  66. return NewRemoteClientCreator(addr, transport, mustConnect)
  67. }
  68. }