mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 09:21:32 +00:00
Revert "delete everything" (includes everything non-go-crypto)
This reverts commit 96a3502
This commit is contained in:
81
proxy/client.go
Normal file
81
proxy/client.go
Normal file
@ -0,0 +1,81 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
abcicli "github.com/tendermint/abci/client"
|
||||
"github.com/tendermint/abci/example/kvstore"
|
||||
"github.com/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 "kvstore":
|
||||
fallthrough
|
||||
case "dummy":
|
||||
return NewLocalClientCreator(kvstore.NewKVStoreApplication())
|
||||
case "persistent_kvstore":
|
||||
fallthrough
|
||||
case "persistent_dummy":
|
||||
return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
|
||||
case "nilapp":
|
||||
return NewLocalClientCreator(types.NewBaseApplication())
|
||||
default:
|
||||
mustConnect := false // loop retrying
|
||||
return NewRemoteClientCreator(addr, transport, mustConnect)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user