mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
use real protobuf message types
This commit is contained in:
parent
7ffd289909
commit
35f4f0e271
@ -38,13 +38,13 @@ func (app *localClient) Stop() bool {
|
|||||||
|
|
||||||
func (app *localClient) FlushAsync() *ReqRes {
|
func (app *localClient) FlushAsync() *ReqRes {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
return newLocalReqRes(types.RequestFlush(), nil)
|
return newLocalReqRes(types.ToRequestFlush(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) EchoAsync(msg string) *ReqRes {
|
func (app *localClient) EchoAsync(msg string) *ReqRes {
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestEcho(msg),
|
types.ToRequestEcho(msg),
|
||||||
types.ResponseEcho(msg),
|
types.ToResponseEcho(msg),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ func (app *localClient) InfoAsync() *ReqRes {
|
|||||||
info := app.Application.Info()
|
info := app.Application.Info()
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestInfo(),
|
types.ToRequestInfo(),
|
||||||
types.ResponseInfo(info),
|
types.ToResponseInfo(info),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ func (app *localClient) SetOptionAsync(key string, value string) *ReqRes {
|
|||||||
log := app.Application.SetOption(key, value)
|
log := app.Application.SetOption(key, value)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestSetOption(key, value),
|
types.ToRequestSetOption(key, value),
|
||||||
types.ResponseSetOption(log),
|
types.ToResponseSetOption(log),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,8 +73,8 @@ func (app *localClient) AppendTxAsync(tx []byte) *ReqRes {
|
|||||||
res := app.Application.AppendTx(tx)
|
res := app.Application.AppendTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestAppendTx(tx),
|
types.ToRequestAppendTx(tx),
|
||||||
types.ResponseAppendTx(res.Code, res.Data, res.Log),
|
types.ToResponseAppendTx(res.Code, res.Data, res.Log),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +83,8 @@ func (app *localClient) CheckTxAsync(tx []byte) *ReqRes {
|
|||||||
res := app.Application.CheckTx(tx)
|
res := app.Application.CheckTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestCheckTx(tx),
|
types.ToRequestCheckTx(tx),
|
||||||
types.ResponseCheckTx(res.Code, res.Data, res.Log),
|
types.ToResponseCheckTx(res.Code, res.Data, res.Log),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ func (app *localClient) QueryAsync(tx []byte) *ReqRes {
|
|||||||
res := app.Application.Query(tx)
|
res := app.Application.Query(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestQuery(tx),
|
types.ToRequestQuery(tx),
|
||||||
types.ResponseQuery(res.Code, res.Data, res.Log),
|
types.ToResponseQuery(res.Code, res.Data, res.Log),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +103,8 @@ func (app *localClient) CommitAsync() *ReqRes {
|
|||||||
res := app.Application.Commit()
|
res := app.Application.Commit()
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestCommit(),
|
types.ToRequestCommit(),
|
||||||
types.ResponseCommit(res.Code, res.Data, res.Log),
|
types.ToResponseCommit(res.Code, res.Data, res.Log),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +114,8 @@ func (app *localClient) InitChainAsync(validators []*types.Validator) *ReqRes {
|
|||||||
bcApp.InitChain(validators)
|
bcApp.InitChain(validators)
|
||||||
}
|
}
|
||||||
reqRes := app.callback(
|
reqRes := app.callback(
|
||||||
types.RequestInitChain(validators),
|
types.ToRequestInitChain(validators),
|
||||||
types.ResponseInitChain(),
|
types.ToResponseInitChain(),
|
||||||
)
|
)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return reqRes
|
return reqRes
|
||||||
@ -128,8 +128,8 @@ func (app *localClient) BeginBlockAsync(height uint64) *ReqRes {
|
|||||||
}
|
}
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestBeginBlock(height),
|
types.ToRequestBeginBlock(height),
|
||||||
types.ResponseBeginBlock(),
|
types.ToResponseBeginBlock(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,8 +141,8 @@ func (app *localClient) EndBlockAsync(height uint64) *ReqRes {
|
|||||||
}
|
}
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.RequestEndBlock(height),
|
types.ToRequestEndBlock(height),
|
||||||
types.ResponseEndBlock(validators),
|
types.ToResponseEndBlock(validators),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -13,6 +14,11 @@ import (
|
|||||||
"github.com/tendermint/tmsp/types"
|
"github.com/tendermint/tmsp/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OK = types.CodeType_OK
|
||||||
|
LOG = ""
|
||||||
|
)
|
||||||
|
|
||||||
const reqQueueSize = 256 // TODO make configurable
|
const reqQueueSize = 256 // TODO make configurable
|
||||||
const maxResponseSize = 1048576 // 1MB TODO make configurable
|
const maxResponseSize = 1048576 // 1MB TODO make configurable
|
||||||
const flushThrottleMS = 20 // Don't wait longer than...
|
const flushThrottleMS = 20 // Don't wait longer than...
|
||||||
@ -122,7 +128,7 @@ func (cli *remoteClient) sendRequestsRoutine(conn net.Conn) {
|
|||||||
select {
|
select {
|
||||||
case <-cli.flushTimer.Ch:
|
case <-cli.flushTimer.Ch:
|
||||||
select {
|
select {
|
||||||
case cli.reqQueue <- NewReqRes(types.RequestFlush()):
|
case cli.reqQueue <- NewReqRes(types.ToRequestFlush()):
|
||||||
default:
|
default:
|
||||||
// Probably will fill the buffer, or retry later.
|
// Probably will fill the buffer, or retry later.
|
||||||
}
|
}
|
||||||
@ -136,7 +142,7 @@ func (cli *remoteClient) sendRequestsRoutine(conn net.Conn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// log.Debug("Sent request", "requestType", reflect.TypeOf(reqres.Request), "request", reqres.Request)
|
// log.Debug("Sent request", "requestType", reflect.TypeOf(reqres.Request), "request", reqres.Request)
|
||||||
if reqres.Request.Type == types.MessageType_Flush {
|
if _, ok := reqres.Request.Requests.(*types.Request_Flush); ok {
|
||||||
err = w.Flush()
|
err = w.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cli.StopForError(err)
|
cli.StopForError(err)
|
||||||
@ -156,10 +162,10 @@ func (cli *remoteClient) recvResponseRoutine(conn net.Conn) {
|
|||||||
cli.StopForError(err)
|
cli.StopForError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch res.Type {
|
switch r := res.Responses.(type) {
|
||||||
case types.MessageType_Exception:
|
case *types.Response_Exception:
|
||||||
// XXX After setting cli.err, release waiters (e.g. reqres.Done())
|
// XXX After setting cli.err, release waiters (e.g. reqres.Done())
|
||||||
cli.StopForError(errors.New(res.Error))
|
cli.StopForError(errors.New(r.Exception.Error))
|
||||||
default:
|
default:
|
||||||
// log.Debug("Received response", "responseType", reflect.TypeOf(res), "response", res)
|
// log.Debug("Received response", "responseType", reflect.TypeOf(res), "response", res)
|
||||||
err := cli.didRecvResponse(res)
|
err := cli.didRecvResponse(res)
|
||||||
@ -183,12 +189,12 @@ func (cli *remoteClient) didRecvResponse(res *types.Response) error {
|
|||||||
// Get the first ReqRes
|
// Get the first ReqRes
|
||||||
next := cli.reqSent.Front()
|
next := cli.reqSent.Front()
|
||||||
if next == nil {
|
if next == nil {
|
||||||
return fmt.Errorf("Unexpected result type %v when nothing expected", res.Type)
|
return fmt.Errorf("Unexpected result type %v when nothing expected", reflect.TypeOf(res.Responses))
|
||||||
}
|
}
|
||||||
reqres := next.Value.(*ReqRes)
|
reqres := next.Value.(*ReqRes)
|
||||||
if !resMatchesReq(reqres.Request, res) {
|
if !resMatchesReq(reqres.Request, res) {
|
||||||
return fmt.Errorf("Unexpected result type %v when response to %v expected",
|
return fmt.Errorf("Unexpected result type %v when response to %v expected",
|
||||||
res.Type, reqres.Request.Type)
|
reflect.TypeOf(res.Responses), reflect.TypeOf(reqres.Request.Requests))
|
||||||
}
|
}
|
||||||
|
|
||||||
reqres.Response = res // Set response
|
reqres.Response = res // Set response
|
||||||
@ -211,128 +217,128 @@ func (cli *remoteClient) didRecvResponse(res *types.Response) error {
|
|||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func (cli *remoteClient) EchoAsync(msg string) *ReqRes {
|
func (cli *remoteClient) EchoAsync(msg string) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestEcho(msg))
|
return cli.queueRequest(types.ToRequestEcho(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) FlushAsync() *ReqRes {
|
func (cli *remoteClient) FlushAsync() *ReqRes {
|
||||||
return cli.queueRequest(types.RequestFlush())
|
return cli.queueRequest(types.ToRequestFlush())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) InfoAsync() *ReqRes {
|
func (cli *remoteClient) InfoAsync() *ReqRes {
|
||||||
return cli.queueRequest(types.RequestInfo())
|
return cli.queueRequest(types.ToRequestInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) SetOptionAsync(key string, value string) *ReqRes {
|
func (cli *remoteClient) SetOptionAsync(key string, value string) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestSetOption(key, value))
|
return cli.queueRequest(types.ToRequestSetOption(key, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) AppendTxAsync(tx []byte) *ReqRes {
|
func (cli *remoteClient) AppendTxAsync(tx []byte) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestAppendTx(tx))
|
return cli.queueRequest(types.ToRequestAppendTx(tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) CheckTxAsync(tx []byte) *ReqRes {
|
func (cli *remoteClient) CheckTxAsync(tx []byte) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestCheckTx(tx))
|
return cli.queueRequest(types.ToRequestCheckTx(tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) QueryAsync(query []byte) *ReqRes {
|
func (cli *remoteClient) QueryAsync(query []byte) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestQuery(query))
|
return cli.queueRequest(types.ToRequestQuery(query))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) CommitAsync() *ReqRes {
|
func (cli *remoteClient) CommitAsync() *ReqRes {
|
||||||
return cli.queueRequest(types.RequestCommit())
|
return cli.queueRequest(types.ToRequestCommit())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) InitChainAsync(validators []*types.Validator) *ReqRes {
|
func (cli *remoteClient) InitChainAsync(validators []*types.Validator) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestInitChain(validators))
|
return cli.queueRequest(types.ToRequestInitChain(validators))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) BeginBlockAsync(height uint64) *ReqRes {
|
func (cli *remoteClient) BeginBlockAsync(height uint64) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestBeginBlock(height))
|
return cli.queueRequest(types.ToRequestBeginBlock(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) EndBlockAsync(height uint64) *ReqRes {
|
func (cli *remoteClient) EndBlockAsync(height uint64) *ReqRes {
|
||||||
return cli.queueRequest(types.RequestEndBlock(height))
|
return cli.queueRequest(types.ToRequestEndBlock(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func (cli *remoteClient) EchoSync(msg string) (res types.Result) {
|
func (cli *remoteClient) EchoSync(msg string) (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestEcho(msg))
|
reqres := cli.queueRequest(types.ToRequestEcho(msg))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetEcho()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: OK, Data: []byte(resp.Message), Log: LOG}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) FlushSync() error {
|
func (cli *remoteClient) FlushSync() error {
|
||||||
cli.queueRequest(types.RequestFlush()).Wait()
|
cli.queueRequest(types.ToRequestFlush()).Wait()
|
||||||
return cli.err
|
return cli.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) InfoSync() (res types.Result) {
|
func (cli *remoteClient) InfoSync() (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestInfo())
|
reqres := cli.queueRequest(types.ToRequestInfo())
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetInfo()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: OK, Data: []byte(resp.Info), Log: LOG}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) SetOptionSync(key string, value string) (res types.Result) {
|
func (cli *remoteClient) SetOptionSync(key string, value string) (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestSetOption(key, value))
|
reqres := cli.queueRequest(types.ToRequestSetOption(key, value))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetSetOption()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: OK, Data: nil, Log: resp.Log}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) AppendTxSync(tx []byte) (res types.Result) {
|
func (cli *remoteClient) AppendTxSync(tx []byte) (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestAppendTx(tx))
|
reqres := cli.queueRequest(types.ToRequestAppendTx(tx))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetAppendTx()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) CheckTxSync(tx []byte) (res types.Result) {
|
func (cli *remoteClient) CheckTxSync(tx []byte) (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestCheckTx(tx))
|
reqres := cli.queueRequest(types.ToRequestCheckTx(tx))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetCheckTx()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) QuerySync(query []byte) (res types.Result) {
|
func (cli *remoteClient) QuerySync(query []byte) (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestQuery(query))
|
reqres := cli.queueRequest(types.ToRequestQuery(query))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetQuery()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) CommitSync() (res types.Result) {
|
func (cli *remoteClient) CommitSync() (res types.Result) {
|
||||||
reqres := cli.queueRequest(types.RequestCommit())
|
reqres := cli.queueRequest(types.ToRequestCommit())
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return types.ErrInternalError.SetLog(cli.err.Error())
|
return types.ErrInternalError.SetLog(cli.err.Error())
|
||||||
}
|
}
|
||||||
resp := reqres.Response
|
resp := reqres.Response.GetCommit()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) InitChainSync(validators []*types.Validator) (err error) {
|
func (cli *remoteClient) InitChainSync(validators []*types.Validator) (err error) {
|
||||||
cli.queueRequest(types.RequestInitChain(validators))
|
cli.queueRequest(types.ToRequestInitChain(validators))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return cli.err
|
return cli.err
|
||||||
@ -341,7 +347,7 @@ func (cli *remoteClient) InitChainSync(validators []*types.Validator) (err error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) BeginBlockSync(height uint64) (err error) {
|
func (cli *remoteClient) BeginBlockSync(height uint64) (err error) {
|
||||||
cli.queueRequest(types.RequestBeginBlock(height))
|
cli.queueRequest(types.ToRequestBeginBlock(height))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return cli.err
|
return cli.err
|
||||||
@ -350,12 +356,12 @@ func (cli *remoteClient) BeginBlockSync(height uint64) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *remoteClient) EndBlockSync(height uint64) (validators []*types.Validator, err error) {
|
func (cli *remoteClient) EndBlockSync(height uint64) (validators []*types.Validator, err error) {
|
||||||
reqres := cli.queueRequest(types.RequestEndBlock(height))
|
reqres := cli.queueRequest(types.ToRequestEndBlock(height))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if cli.err != nil {
|
if cli.err != nil {
|
||||||
return nil, cli.err
|
return nil, cli.err
|
||||||
}
|
}
|
||||||
return reqres.Response.Validators, nil
|
return reqres.Response.GetEndBlock().Diffs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
@ -366,8 +372,8 @@ func (cli *remoteClient) queueRequest(req *types.Request) *ReqRes {
|
|||||||
cli.reqQueue <- reqres
|
cli.reqQueue <- reqres
|
||||||
|
|
||||||
// Maybe auto-flush, or unset auto-flush
|
// Maybe auto-flush, or unset auto-flush
|
||||||
switch req.Type {
|
switch req.Requests.(type) {
|
||||||
case types.MessageType_Flush:
|
case *types.Request_Flush:
|
||||||
cli.flushTimer.Unset()
|
cli.flushTimer.Unset()
|
||||||
default:
|
default:
|
||||||
cli.flushTimer.Set()
|
cli.flushTimer.Set()
|
||||||
@ -379,5 +385,27 @@ func (cli *remoteClient) queueRequest(req *types.Request) *ReqRes {
|
|||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func resMatchesReq(req *types.Request, res *types.Response) (ok bool) {
|
func resMatchesReq(req *types.Request, res *types.Response) (ok bool) {
|
||||||
return req.Type == res.Type
|
switch req.Requests.(type) {
|
||||||
|
case *types.Request_Echo:
|
||||||
|
_, ok = res.Responses.(*types.Response_Echo)
|
||||||
|
case *types.Request_Flush:
|
||||||
|
_, ok = res.Responses.(*types.Response_Flush)
|
||||||
|
case *types.Request_Info:
|
||||||
|
_, ok = res.Responses.(*types.Response_Info)
|
||||||
|
case *types.Request_SetOption:
|
||||||
|
_, ok = res.Responses.(*types.Response_SetOption)
|
||||||
|
case *types.Request_AppendTx:
|
||||||
|
_, ok = res.Responses.(*types.Response_AppendTx)
|
||||||
|
case *types.Request_CheckTx:
|
||||||
|
_, ok = res.Responses.(*types.Response_CheckTx)
|
||||||
|
case *types.Request_Commit:
|
||||||
|
_, ok = res.Responses.(*types.Response_Commit)
|
||||||
|
case *types.Request_Query:
|
||||||
|
_, ok = res.Responses.(*types.Response_Query)
|
||||||
|
case *types.Request_InitChain:
|
||||||
|
_, ok = res.Responses.(*types.Response_InitChain)
|
||||||
|
case *types.Request_EndBlock:
|
||||||
|
_, ok = res.Responses.(*types.Response_EndBlock)
|
||||||
|
}
|
||||||
|
return ok
|
||||||
}
|
}
|
||||||
|
@ -125,45 +125,46 @@ func (s *Server) handleRequests(closeConn chan error, conn net.Conn, responses c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleRequest(req *types.Request, responses chan<- *types.Response) {
|
func (s *Server) handleRequest(req *types.Request, responses chan<- *types.Response) {
|
||||||
switch req.Type {
|
switch r := req.Requests.(type) {
|
||||||
case types.MessageType_Echo:
|
case *types.Request_Echo:
|
||||||
responses <- types.ResponseEcho(string(req.Data))
|
responses <- types.ToResponseEcho(r.Echo.Message)
|
||||||
case types.MessageType_Flush:
|
case *types.Request_Flush:
|
||||||
responses <- types.ResponseFlush()
|
responses <- types.ToResponseFlush()
|
||||||
case types.MessageType_Info:
|
case *types.Request_Info:
|
||||||
data := s.app.Info()
|
data := s.app.Info()
|
||||||
responses <- types.ResponseInfo(data)
|
responses <- types.ToResponseInfo(data)
|
||||||
case types.MessageType_SetOption:
|
case *types.Request_SetOption:
|
||||||
logStr := s.app.SetOption(req.Key, req.Value)
|
so := r.SetOption
|
||||||
responses <- types.ResponseSetOption(logStr)
|
logStr := s.app.SetOption(so.Key, so.Value)
|
||||||
case types.MessageType_AppendTx:
|
responses <- types.ToResponseSetOption(logStr)
|
||||||
res := s.app.AppendTx(req.Data)
|
case *types.Request_AppendTx:
|
||||||
responses <- types.ResponseAppendTx(res.Code, res.Data, res.Log)
|
res := s.app.AppendTx(r.AppendTx.Tx)
|
||||||
case types.MessageType_CheckTx:
|
responses <- types.ToResponseAppendTx(res.Code, res.Data, res.Log)
|
||||||
res := s.app.CheckTx(req.Data)
|
case *types.Request_CheckTx:
|
||||||
responses <- types.ResponseCheckTx(res.Code, res.Data, res.Log)
|
res := s.app.CheckTx(r.CheckTx.Tx)
|
||||||
case types.MessageType_Commit:
|
responses <- types.ToResponseCheckTx(res.Code, res.Data, res.Log)
|
||||||
|
case *types.Request_Commit:
|
||||||
res := s.app.Commit()
|
res := s.app.Commit()
|
||||||
responses <- types.ResponseCommit(res.Code, res.Data, res.Log)
|
responses <- types.ToResponseCommit(res.Code, res.Data, res.Log)
|
||||||
case types.MessageType_Query:
|
case *types.Request_Query:
|
||||||
res := s.app.Query(req.Data)
|
res := s.app.Query(r.Query.Query)
|
||||||
responses <- types.ResponseQuery(res.Code, res.Data, res.Log)
|
responses <- types.ToResponseQuery(res.Code, res.Data, res.Log)
|
||||||
case types.MessageType_InitChain:
|
case *types.Request_InitChain:
|
||||||
if app, ok := s.app.(types.BlockchainAware); ok {
|
if app, ok := s.app.(types.BlockchainAware); ok {
|
||||||
app.InitChain(req.Validators)
|
app.InitChain(r.InitChain.Validators)
|
||||||
responses <- types.ResponseInitChain()
|
responses <- types.ToResponseInitChain()
|
||||||
} else {
|
} else {
|
||||||
responses <- types.ResponseInitChain()
|
responses <- types.ToResponseInitChain()
|
||||||
}
|
}
|
||||||
case types.MessageType_EndBlock:
|
case *types.Request_EndBlock:
|
||||||
if app, ok := s.app.(types.BlockchainAware); ok {
|
if app, ok := s.app.(types.BlockchainAware); ok {
|
||||||
validators := app.EndBlock(req.Height)
|
validators := app.EndBlock(r.EndBlock.Height)
|
||||||
responses <- types.ResponseEndBlock(validators)
|
responses <- types.ToResponseEndBlock(validators)
|
||||||
} else {
|
} else {
|
||||||
responses <- types.ResponseEndBlock(nil)
|
responses <- types.ToResponseEndBlock(nil)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
responses <- types.ResponseException("Unknown request")
|
responses <- types.ToResponseException("Unknown request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ func (s *Server) handleResponses(closeConn chan error, responses <-chan *types.R
|
|||||||
closeConn <- fmt.Errorf("Error in handleResponses: %v", err.Error())
|
closeConn <- fmt.Errorf("Error in handleResponses: %v", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if res.Type == types.MessageType_Flush {
|
if _, ok := res.Responses.(*types.Response_Flush); ok {
|
||||||
err = bufWriter.Flush()
|
err = bufWriter.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closeConn <- fmt.Errorf("Error in handleResponses: %v", err.Error())
|
closeConn <- fmt.Errorf("Error in handleResponses: %v", err.Error())
|
||||||
|
@ -7,169 +7,143 @@ import (
|
|||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RequestEcho(message string) *Request {
|
func ToRequestEcho(message string) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_Echo,
|
Requests: &Request_Echo{&RequestEcho{}},
|
||||||
Data: []byte(message),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestFlush() *Request {
|
func ToRequestFlush() *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_Flush,
|
Requests: &Request_Flush{&RequestFlush{}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestInfo() *Request {
|
func ToRequestInfo() *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_Info,
|
Requests: &Request_Info{&RequestInfo{}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestSetOption(key string, value string) *Request {
|
func ToRequestSetOption(key string, value string) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_SetOption,
|
Requests: &Request_SetOption{&RequestSetOption{key, value}},
|
||||||
Key: key,
|
|
||||||
Value: value,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestAppendTx(txBytes []byte) *Request {
|
func ToRequestAppendTx(txBytes []byte) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_AppendTx,
|
Requests: &Request_AppendTx{&RequestAppendTx{txBytes}},
|
||||||
Data: txBytes,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestCheckTx(txBytes []byte) *Request {
|
func ToRequestCheckTx(txBytes []byte) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_CheckTx,
|
Requests: &Request_CheckTx{&RequestCheckTx{txBytes}},
|
||||||
Data: txBytes,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestCommit() *Request {
|
func ToRequestCommit() *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_Commit,
|
Requests: &Request_Commit{&RequestCommit{}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestQuery(queryBytes []byte) *Request {
|
func ToRequestQuery(queryBytes []byte) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_Query,
|
Requests: &Request_Query{&RequestQuery{queryBytes}},
|
||||||
Data: queryBytes,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestInitChain(validators []*Validator) *Request {
|
func ToRequestInitChain(validators []*Validator) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_InitChain,
|
Requests: &Request_InitChain{&RequestInitChain{validators}},
|
||||||
Validators: validators,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestBeginBlock(height uint64) *Request {
|
func ToRequestBeginBlock(height uint64) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_BeginBlock,
|
Requests: &Request_BeginBlock{&RequestBeginBlock{height}},
|
||||||
Height: height,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestEndBlock(height uint64) *Request {
|
func ToRequestEndBlock(height uint64) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Type: MessageType_EndBlock,
|
Requests: &Request_EndBlock{&RequestEndBlock{height}},
|
||||||
Height: height,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func ResponseException(errStr string) *Response {
|
func ToResponseException(errStr string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_Exception,
|
Responses: &Response_Exception{&ResponseException{errStr}},
|
||||||
Error: errStr,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseEcho(message string) *Response {
|
func ToResponseEcho(message string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_Echo,
|
Responses: &Response_Echo{&ResponseEcho{message}},
|
||||||
Data: []byte(message),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseFlush() *Response {
|
func ToResponseFlush() *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_Flush,
|
Responses: &Response_Flush{&ResponseFlush{}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseInfo(info string) *Response {
|
func ToResponseInfo(info string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_Info,
|
Responses: &Response_Info{&ResponseInfo{info}},
|
||||||
Data: []byte(info),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseSetOption(log string) *Response {
|
func ToResponseSetOption(log string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_SetOption,
|
Responses: &Response_SetOption{&ResponseSetOption{log}},
|
||||||
Log: log,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseAppendTx(code CodeType, data []byte, log string) *Response {
|
func ToResponseAppendTx(code CodeType, data []byte, log string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_AppendTx,
|
Responses: &Response_AppendTx{&ResponseAppendTx{code, data, log}},
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Log: log,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseCheckTx(code CodeType, data []byte, log string) *Response {
|
func ToResponseCheckTx(code CodeType, data []byte, log string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_CheckTx,
|
Responses: &Response_CheckTx{&ResponseCheckTx{code, data, log}},
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Log: log,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseCommit(code CodeType, data []byte, log string) *Response {
|
func ToResponseCommit(code CodeType, data []byte, log string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_Commit,
|
Responses: &Response_Commit{&ResponseCommit{code, data, log}},
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Log: log,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseQuery(code CodeType, data []byte, log string) *Response {
|
func ToResponseQuery(code CodeType, data []byte, log string) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_Query,
|
Responses: &Response_Query{&ResponseQuery{code, data, log}},
|
||||||
Code: code,
|
|
||||||
Data: data,
|
|
||||||
Log: log,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseInitChain() *Response {
|
func ToResponseInitChain() *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_InitChain,
|
Responses: &Response_InitChain{&ResponseInitChain{}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseBeginBlock() *Response {
|
func ToResponseBeginBlock() *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_BeginBlock,
|
Responses: &Response_BeginBlock{&ResponseBeginBlock{}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseEndBlock(validators []*Validator) *Response {
|
func ToResponseEndBlock(validators []*Validator) *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
Type: MessageType_EndBlock,
|
Responses: &Response_EndBlock{&ResponseEndBlock{validators}},
|
||||||
Validators: validators,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1227
types/types.pb.go
1227
types/types.pb.go
File diff suppressed because it is too large
Load Diff
@ -70,24 +70,136 @@ enum CodeType {
|
|||||||
// Request types
|
// Request types
|
||||||
|
|
||||||
message Request {
|
message Request {
|
||||||
MessageType type = 1;
|
oneof requests{
|
||||||
bytes data = 2;
|
RequestEcho echo = 1;
|
||||||
string key = 3;
|
RequestFlush flush = 2;
|
||||||
string value = 4;
|
RequestInfo info = 3;
|
||||||
repeated Validator validators = 5;
|
RequestSetOption set_option = 4;
|
||||||
uint64 height = 6;
|
RequestAppendTx append_tx = 5;
|
||||||
|
RequestCheckTx check_tx = 6;
|
||||||
|
RequestCommit commit = 7;
|
||||||
|
RequestQuery query = 8;
|
||||||
|
RequestInitChain init_chain = 9;
|
||||||
|
RequestBeginBlock begin_block = 10;
|
||||||
|
RequestEndBlock end_block = 11;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestEcho {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestFlush {
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestInfo {
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestSetOption{
|
||||||
|
string key = 1;
|
||||||
|
string value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestAppendTx{
|
||||||
|
bytes tx = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestCheckTx{
|
||||||
|
bytes tx = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestQuery{
|
||||||
|
bytes query = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestCommit{
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestInitChain{
|
||||||
|
repeated Validator validators = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestBeginBlock{
|
||||||
|
uint64 height = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestEndBlock{
|
||||||
|
uint64 height = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
// Response types
|
// Response types
|
||||||
|
|
||||||
|
|
||||||
message Response {
|
message Response {
|
||||||
MessageType type = 1;
|
oneof responses{
|
||||||
bytes data = 2;
|
ResponseException exception = 1;
|
||||||
CodeType code = 3;
|
ResponseEcho echo = 2;
|
||||||
string error = 4;
|
ResponseFlush flush = 3;
|
||||||
string log = 5;
|
ResponseInfo info = 4;
|
||||||
repeated Validator validators = 6;
|
ResponseSetOption set_option = 5;
|
||||||
|
ResponseAppendTx append_tx = 6;
|
||||||
|
ResponseCheckTx check_tx = 7;
|
||||||
|
ResponseCommit commit = 8;
|
||||||
|
ResponseQuery query = 9;
|
||||||
|
ResponseInitChain init_chain = 10;
|
||||||
|
ResponseBeginBlock begin_block = 11;
|
||||||
|
ResponseEndBlock end_block = 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseException{
|
||||||
|
string error = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseEcho {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseFlush{
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseInfo {
|
||||||
|
string info = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseSetOption{
|
||||||
|
string log = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseAppendTx{
|
||||||
|
CodeType code = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
string log = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseCheckTx{
|
||||||
|
CodeType code = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
string log = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseQuery{
|
||||||
|
CodeType code = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
string log = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseCommit{
|
||||||
|
CodeType code = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
string log = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message ResponseInitChain{
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseBeginBlock{
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseEndBlock{
|
||||||
|
repeated Validator diffs = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user