mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-03 03:35:19 +00:00
* Remove extra interface cast Signed-off-by: Thane Thomson <connect@thanethomson.com> * Remove irrelevant comment Signed-off-by: Thane Thomson <connect@thanethomson.com> * abci: Add unsynchronized local client Signed-off-by: Thane Thomson <connect@thanethomson.com> * proxy: Add unsync local client creator Signed-off-by: Thane Thomson <connect@thanethomson.com> * e2e: Add sync app for use with unsync local client Signed-off-by: Thane Thomson <connect@thanethomson.com> * abci: Elaborate on mutex param in unsync local client Signed-off-by: Thane Thomson <connect@thanethomson.com> * proxy: Remove unnecessary comment Signed-off-by: Thane Thomson <connect@thanethomson.com> * abcicli: Remove unnecessary mutex param from unsync client Signed-off-by: Thane Thomson <connect@thanethomson.com> * ci/e2e: Explicitly use sync app for validator04 Signed-off-by: Thane Thomson <connect@thanethomson.com> * e2e: Ensure app is definitely the E2E app Signed-off-by: Thane Thomson <connect@thanethomson.com> Signed-off-by: Thane Thomson <connect@thanethomson.com>
119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
package proxy
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
abcicli "github.com/tendermint/tendermint/abci/client"
|
|
"github.com/tendermint/tendermint/abci/example/kvstore"
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
tmsync "github.com/tendermint/tendermint/libs/sync"
|
|
e2e "github.com/tendermint/tendermint/test/e2e/app"
|
|
)
|
|
|
|
//go:generate ../scripts/mockery_generate.sh ClientCreator
|
|
|
|
// ClientCreator creates new ABCI clients.
|
|
type ClientCreator interface {
|
|
// NewABCIClient returns a new ABCI client.
|
|
NewABCIClient() (abcicli.Client, error)
|
|
}
|
|
|
|
//----------------------------------------------------
|
|
// local proxy uses a mutex on an in-proc app
|
|
|
|
type localClientCreator struct {
|
|
mtx *tmsync.Mutex
|
|
app types.Application
|
|
}
|
|
|
|
// NewLocalClientCreator returns a ClientCreator for the given app,
|
|
// which will be running locally.
|
|
func NewLocalClientCreator(app types.Application) ClientCreator {
|
|
return &localClientCreator{
|
|
mtx: new(tmsync.Mutex),
|
|
app: app,
|
|
}
|
|
}
|
|
|
|
func (l *localClientCreator) NewABCIClient() (abcicli.Client, error) {
|
|
return abcicli.NewLocalClient(l.mtx, l.app), nil
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
// unsynchronized local proxy on an in-proc app (no mutex)
|
|
|
|
type unsyncLocalClientCreator struct {
|
|
app types.Application
|
|
}
|
|
|
|
// NewUnsyncLocalClientCreator returns a ClientCreator for the given app, which
|
|
// will be running locally. Unlike NewLocalClientCreator, this leaves
|
|
// synchronization up to the application.
|
|
func NewUnsyncLocalClientCreator(app types.Application) ClientCreator {
|
|
return &unsyncLocalClientCreator{
|
|
app: app,
|
|
}
|
|
}
|
|
|
|
func (l *unsyncLocalClientCreator) NewABCIClient() (abcicli.Client, error) {
|
|
return abcicli.NewUnsyncLocalClient(l.app), nil
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
// remote proxy opens new connections to an external app process
|
|
|
|
type remoteClientCreator struct {
|
|
addr string
|
|
transport string
|
|
mustConnect bool
|
|
}
|
|
|
|
// NewRemoteClientCreator returns a ClientCreator for the given address (e.g.
|
|
// "192.168.0.1") and transport (e.g. "tcp"). Set mustConnect to true if you
|
|
// want the client to connect before reporting success.
|
|
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, fmt.Errorf("failed to connect to proxy: %w", err)
|
|
}
|
|
|
|
return remoteApp, nil
|
|
}
|
|
|
|
// DefaultClientCreator returns a default ClientCreator, which will create a
|
|
// local client if addr is one of: 'kvstore',
|
|
// 'persistent_kvstore' or 'noop', otherwise - a remote client.
|
|
func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
|
|
switch addr {
|
|
case "kvstore":
|
|
return NewLocalClientCreator(kvstore.NewApplication())
|
|
case "persistent_kvstore":
|
|
return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
|
|
case "e2e":
|
|
app, err := e2e.NewApplication(e2e.DefaultConfig(dbDir))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return NewLocalClientCreator(app)
|
|
case "e2e_sync":
|
|
app, err := e2e.NewSyncApplication(e2e.DefaultConfig(dbDir))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return NewUnsyncLocalClientCreator(app)
|
|
case "noop":
|
|
return NewLocalClientCreator(types.NewBaseApplication())
|
|
default:
|
|
mustConnect := false // loop retrying
|
|
return NewRemoteClientCreator(addr, transport, mustConnect)
|
|
}
|
|
}
|