mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-03 11:45:18 +00:00
* 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
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package proxy
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
abcicli "github.com/tendermint/tendermint/abci/client"
|
|
"github.com/tendermint/tendermint/abci/example/counter"
|
|
"github.com/tendermint/tendermint/abci/example/kvstore"
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
)
|
|
|
|
// NewABCIClient returns newly connected client
|
|
type ClientCreator interface {
|
|
NewABCIClient() (abcicli.Client, error)
|
|
}
|
|
|
|
//----------------------------------------------------
|
|
// local proxy uses a mutex on an in-proc app
|
|
|
|
type localClientCreator struct {
|
|
mtx *sync.Mutex
|
|
app types.Application
|
|
}
|
|
|
|
func NewLocalClientCreator(app types.Application) ClientCreator {
|
|
return &localClientCreator{
|
|
mtx: new(sync.Mutex),
|
|
app: app,
|
|
}
|
|
}
|
|
|
|
func (l *localClientCreator) NewABCIClient() (abcicli.Client, error) {
|
|
return abcicli.NewLocalClient(l.mtx, l.app), nil
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
// remote proxy opens new connections to an external app process
|
|
|
|
type remoteClientCreator struct {
|
|
addr string
|
|
transport string
|
|
mustConnect bool
|
|
}
|
|
|
|
func NewRemoteClientCreator(addr, transport string, mustConnect bool) ClientCreator {
|
|
return &remoteClientCreator{
|
|
addr: addr,
|
|
transport: transport,
|
|
mustConnect: mustConnect,
|
|
}
|
|
}
|
|
|
|
func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
|
|
remoteApp, err := abcicli.NewClient(r.addr, r.transport, r.mustConnect)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "Failed to connect to proxy")
|
|
}
|
|
return remoteApp, nil
|
|
}
|
|
|
|
//-----------------------------------------------------------------
|
|
// default
|
|
|
|
func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
|
|
switch addr {
|
|
case "counter":
|
|
return NewLocalClientCreator(counter.NewApplication(false))
|
|
case "counter_serial":
|
|
return NewLocalClientCreator(counter.NewApplication(true))
|
|
case "kvstore":
|
|
return NewLocalClientCreator(kvstore.NewApplication())
|
|
case "persistent_kvstore":
|
|
return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
|
|
case "noop":
|
|
return NewLocalClientCreator(types.NewBaseApplication())
|
|
default:
|
|
mustConnect := false // loop retrying
|
|
return NewRemoteClientCreator(addr, transport, mustConnect)
|
|
}
|
|
}
|