Remove retcode from echo; Add Info message
This commit is contained in:
parent
ef93c95853
commit
cce812b1fa
|
@ -43,8 +43,12 @@ func NewDummyApplication() *DummyApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dapp *DummyApplication) Echo(message string) (types.RetCode, string) {
|
func (dapp *DummyApplication) Echo(message string) string {
|
||||||
return 0, message
|
return message
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dapp *DummyApplication) Info() []string {
|
||||||
|
return []string{Fmt("size:%v", dapp.state.Size())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dapp *DummyApplication) AppendTx(tx []byte) types.RetCode {
|
func (dapp *DummyApplication) AppendTx(tx []byte) types.RetCode {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
|
@ -58,18 +57,12 @@ func handleRequests(app types.Application, connClosed chan struct{}, conn net.Co
|
||||||
var err error
|
var err error
|
||||||
var req types.Request
|
var req types.Request
|
||||||
wire.ReadBinaryPtr(&req, bufReader, &n, &err)
|
wire.ReadBinaryPtr(&req, bufReader, &n, &err)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
connClosed <- struct{}{}
|
connClosed <- struct{}{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
if count%1000 == 0 {
|
|
||||||
fmt.Println("Received request", reflect.TypeOf(req), req, n, err, count)
|
|
||||||
}
|
|
||||||
|
|
||||||
handleRequest(app, req, responses)
|
handleRequest(app, req, responses)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,8 +70,8 @@ func handleRequests(app types.Application, connClosed chan struct{}, conn net.Co
|
||||||
func handleRequest(app types.Application, req types.Request, responses chan<- types.Response) {
|
func handleRequest(app types.Application, req types.Request, responses chan<- types.Response) {
|
||||||
switch req := req.(type) {
|
switch req := req.(type) {
|
||||||
case types.RequestEcho:
|
case types.RequestEcho:
|
||||||
retCode, msg := app.Echo(req.Message)
|
msg := app.Echo(req.Message)
|
||||||
responses <- types.ResponseEcho{retCode, msg}
|
responses <- types.ResponseEcho{msg}
|
||||||
case types.RequestFlush:
|
case types.RequestFlush:
|
||||||
responses <- types.ResponseFlush{}
|
responses <- types.ResponseFlush{}
|
||||||
case types.RequestAppendTx:
|
case types.RequestAppendTx:
|
||||||
|
@ -131,7 +124,6 @@ func handleResponses(connClosed chan struct{}, responses <-chan types.Response,
|
||||||
connClosed <- struct{}{}
|
connClosed <- struct{}{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := res.(types.ResponseFlush); ok {
|
if _, ok := res.(types.ResponseFlush); ok {
|
||||||
err = bufWriter.Flush()
|
err = bufWriter.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -140,10 +132,6 @@ func handleResponses(connClosed chan struct{}, responses <-chan types.Response,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
if count%1000 == 0 {
|
|
||||||
fmt.Println("Sent response", reflect.TypeOf(res), res, n, err, count)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@ package types
|
||||||
type Application interface {
|
type Application interface {
|
||||||
|
|
||||||
// Echo a message
|
// Echo a message
|
||||||
Echo(message string) (RetCode, string)
|
Echo(message string) string
|
||||||
|
|
||||||
|
// Return application info
|
||||||
|
Info() []string
|
||||||
|
|
||||||
// Append a tx, which may or may not get committed
|
// Append a tx, which may or may not get committed
|
||||||
AppendTx(tx []byte) RetCode
|
AppendTx(tx []byte) RetCode
|
||||||
|
|
|
@ -3,28 +3,32 @@ package types
|
||||||
import "github.com/tendermint/go-wire"
|
import "github.com/tendermint/go-wire"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
requestTypeEcho = byte(0x01)
|
requestTypeEcho = byte(0x01)
|
||||||
requestTypeFlush = byte(0x02)
|
requestTypeFlush = byte(0x02)
|
||||||
requestTypeAppendTx = byte(0x03)
|
requestTypeInfo = byte(0x03)
|
||||||
requestTypeGetHash = byte(0x04)
|
|
||||||
requestTypeCommit = byte(0x05)
|
|
||||||
requestTypeRollback = byte(0x06)
|
|
||||||
requestTypeSetEventsMode = byte(0x07)
|
|
||||||
requestTypeAddListener = byte(0x08)
|
|
||||||
requestTypeRemListener = byte(0x09)
|
|
||||||
|
|
||||||
responseTypeEcho = byte(0x11)
|
responseTypeException = byte(0x10)
|
||||||
responseTypeFlush = byte(0x12)
|
responseTypeEcho = byte(0x11)
|
||||||
responseTypeAppendTx = byte(0x13)
|
responseTypeFlush = byte(0x12)
|
||||||
responseTypeGetHash = byte(0x14)
|
responseTypeInfo = byte(0x13)
|
||||||
responseTypeCommit = byte(0x15)
|
|
||||||
responseTypeRollback = byte(0x16)
|
|
||||||
responseTypeSetEventsMode = byte(0x17)
|
|
||||||
responseTypeAddListener = byte(0x18)
|
|
||||||
responseTypeRemListener = byte(0x19)
|
|
||||||
|
|
||||||
responseTypeException = byte(0x20)
|
requestTypeAppendTx = byte(0x21)
|
||||||
responseTypeEvent = byte(0x21)
|
requestTypeGetHash = byte(0x22)
|
||||||
|
requestTypeCommit = byte(0x23)
|
||||||
|
requestTypeRollback = byte(0x24)
|
||||||
|
requestTypeSetEventsMode = byte(0x25)
|
||||||
|
requestTypeAddListener = byte(0x26)
|
||||||
|
requestTypeRemListener = byte(0x27)
|
||||||
|
// reserved for responseTypeEvent 0x28
|
||||||
|
|
||||||
|
responseTypeAppendTx = byte(0x31)
|
||||||
|
responseTypeGetHash = byte(0x32)
|
||||||
|
responseTypeCommit = byte(0x33)
|
||||||
|
responseTypeRollback = byte(0x34)
|
||||||
|
responseTypeSetEventsMode = byte(0x35)
|
||||||
|
responseTypeAddListener = byte(0x36)
|
||||||
|
responseTypeRemListener = byte(0x37)
|
||||||
|
responseTypeEvent = byte(0x38)
|
||||||
)
|
)
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
@ -36,6 +40,9 @@ type RequestEcho struct {
|
||||||
type RequestFlush struct {
|
type RequestFlush struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestInfo struct {
|
||||||
|
}
|
||||||
|
|
||||||
type RequestAppendTx struct {
|
type RequestAppendTx struct {
|
||||||
TxBytes []byte
|
TxBytes []byte
|
||||||
}
|
}
|
||||||
|
@ -67,6 +74,7 @@ type Request interface {
|
||||||
|
|
||||||
func (_ RequestEcho) AssertRequestType() {}
|
func (_ RequestEcho) AssertRequestType() {}
|
||||||
func (_ RequestFlush) AssertRequestType() {}
|
func (_ RequestFlush) AssertRequestType() {}
|
||||||
|
func (_ RequestInfo) AssertRequestType() {}
|
||||||
func (_ RequestAppendTx) AssertRequestType() {}
|
func (_ RequestAppendTx) AssertRequestType() {}
|
||||||
func (_ RequestGetHash) AssertRequestType() {}
|
func (_ RequestGetHash) AssertRequestType() {}
|
||||||
func (_ RequestCommit) AssertRequestType() {}
|
func (_ RequestCommit) AssertRequestType() {}
|
||||||
|
@ -79,6 +87,7 @@ var _ = wire.RegisterInterface(
|
||||||
struct{ Request }{},
|
struct{ Request }{},
|
||||||
wire.ConcreteType{RequestEcho{}, requestTypeEcho},
|
wire.ConcreteType{RequestEcho{}, requestTypeEcho},
|
||||||
wire.ConcreteType{RequestFlush{}, requestTypeFlush},
|
wire.ConcreteType{RequestFlush{}, requestTypeFlush},
|
||||||
|
wire.ConcreteType{RequestInfo{}, requestTypeInfo},
|
||||||
wire.ConcreteType{RequestAppendTx{}, requestTypeAppendTx},
|
wire.ConcreteType{RequestAppendTx{}, requestTypeAppendTx},
|
||||||
wire.ConcreteType{RequestGetHash{}, requestTypeGetHash},
|
wire.ConcreteType{RequestGetHash{}, requestTypeGetHash},
|
||||||
wire.ConcreteType{RequestCommit{}, requestTypeCommit},
|
wire.ConcreteType{RequestCommit{}, requestTypeCommit},
|
||||||
|
@ -91,13 +100,16 @@ var _ = wire.RegisterInterface(
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
type ResponseEcho struct {
|
type ResponseEcho struct {
|
||||||
RetCode
|
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseFlush struct {
|
type ResponseFlush struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResponseInfo struct {
|
||||||
|
Data []string
|
||||||
|
}
|
||||||
|
|
||||||
type ResponseAppendTx struct {
|
type ResponseAppendTx struct {
|
||||||
RetCode
|
RetCode
|
||||||
}
|
}
|
||||||
|
@ -141,6 +153,7 @@ type Response interface {
|
||||||
|
|
||||||
func (_ ResponseEcho) AssertResponseType() {}
|
func (_ ResponseEcho) AssertResponseType() {}
|
||||||
func (_ ResponseFlush) AssertResponseType() {}
|
func (_ ResponseFlush) AssertResponseType() {}
|
||||||
|
func (_ ResponseInfo) AssertResponseType() {}
|
||||||
func (_ ResponseAppendTx) AssertResponseType() {}
|
func (_ ResponseAppendTx) AssertResponseType() {}
|
||||||
func (_ ResponseGetHash) AssertResponseType() {}
|
func (_ ResponseGetHash) AssertResponseType() {}
|
||||||
func (_ ResponseCommit) AssertResponseType() {}
|
func (_ ResponseCommit) AssertResponseType() {}
|
||||||
|
@ -155,6 +168,7 @@ var _ = wire.RegisterInterface(
|
||||||
struct{ Response }{},
|
struct{ Response }{},
|
||||||
wire.ConcreteType{ResponseEcho{}, responseTypeEcho},
|
wire.ConcreteType{ResponseEcho{}, responseTypeEcho},
|
||||||
wire.ConcreteType{ResponseFlush{}, responseTypeFlush},
|
wire.ConcreteType{ResponseFlush{}, responseTypeFlush},
|
||||||
|
wire.ConcreteType{ResponseInfo{}, responseTypeInfo},
|
||||||
wire.ConcreteType{ResponseAppendTx{}, responseTypeAppendTx},
|
wire.ConcreteType{ResponseAppendTx{}, responseTypeAppendTx},
|
||||||
wire.ConcreteType{ResponseGetHash{}, responseTypeGetHash},
|
wire.ConcreteType{ResponseGetHash{}, responseTypeGetHash},
|
||||||
wire.ConcreteType{ResponseCommit{}, responseTypeCommit},
|
wire.ConcreteType{ResponseCommit{}, responseTypeCommit},
|
||||||
|
|
Loading…
Reference in New Issue