diff --git a/example/main.go b/example/main.go index bf6f06d9..efd4761e 100644 --- a/example/main.go +++ b/example/main.go @@ -43,8 +43,12 @@ func NewDummyApplication() *DummyApplication { } } -func (dapp *DummyApplication) Echo(message string) (types.RetCode, string) { - return 0, message +func (dapp *DummyApplication) Echo(message string) string { + return message +} + +func (dapp *DummyApplication) Info() []string { + return []string{Fmt("size:%v", dapp.state.Size())} } func (dapp *DummyApplication) AppendTx(tx []byte) types.RetCode { diff --git a/server/server.go b/server/server.go index 161e5e0b..cd1953b0 100644 --- a/server/server.go +++ b/server/server.go @@ -4,7 +4,6 @@ import ( "bufio" "fmt" "net" - "reflect" "strings" . "github.com/tendermint/go-common" @@ -58,18 +57,12 @@ func handleRequests(app types.Application, connClosed chan struct{}, conn net.Co var err error var req types.Request wire.ReadBinaryPtr(&req, bufReader, &n, &err) - if err != nil { fmt.Println(err.Error()) connClosed <- struct{}{} return } - count++ - if count%1000 == 0 { - fmt.Println("Received request", reflect.TypeOf(req), req, n, err, count) - } - 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) { switch req := req.(type) { case types.RequestEcho: - retCode, msg := app.Echo(req.Message) - responses <- types.ResponseEcho{retCode, msg} + msg := app.Echo(req.Message) + responses <- types.ResponseEcho{msg} case types.RequestFlush: responses <- types.ResponseFlush{} case types.RequestAppendTx: @@ -131,7 +124,6 @@ func handleResponses(connClosed chan struct{}, responses <-chan types.Response, connClosed <- struct{}{} return } - if _, ok := res.(types.ResponseFlush); ok { err = bufWriter.Flush() if err != nil { @@ -140,10 +132,6 @@ func handleResponses(connClosed chan struct{}, responses <-chan types.Response, return } } - count++ - if count%1000 == 0 { - fmt.Println("Sent response", reflect.TypeOf(res), res, n, err, count) - } } } diff --git a/types/application.go b/types/application.go index 2596f445..ce9a6670 100644 --- a/types/application.go +++ b/types/application.go @@ -3,7 +3,10 @@ package types type Application interface { // 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 AppendTx(tx []byte) RetCode diff --git a/types/messages.go b/types/messages.go index 70470a2d..5ef3944f 100644 --- a/types/messages.go +++ b/types/messages.go @@ -3,28 +3,32 @@ package types import "github.com/tendermint/go-wire" const ( - requestTypeEcho = byte(0x01) - requestTypeFlush = byte(0x02) - requestTypeAppendTx = byte(0x03) - requestTypeGetHash = byte(0x04) - requestTypeCommit = byte(0x05) - requestTypeRollback = byte(0x06) - requestTypeSetEventsMode = byte(0x07) - requestTypeAddListener = byte(0x08) - requestTypeRemListener = byte(0x09) + requestTypeEcho = byte(0x01) + requestTypeFlush = byte(0x02) + requestTypeInfo = byte(0x03) - responseTypeEcho = byte(0x11) - responseTypeFlush = byte(0x12) - responseTypeAppendTx = byte(0x13) - responseTypeGetHash = byte(0x14) - responseTypeCommit = byte(0x15) - responseTypeRollback = byte(0x16) - responseTypeSetEventsMode = byte(0x17) - responseTypeAddListener = byte(0x18) - responseTypeRemListener = byte(0x19) + responseTypeException = byte(0x10) + responseTypeEcho = byte(0x11) + responseTypeFlush = byte(0x12) + responseTypeInfo = byte(0x13) - responseTypeException = byte(0x20) - responseTypeEvent = byte(0x21) + requestTypeAppendTx = 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 RequestInfo struct { +} + type RequestAppendTx struct { TxBytes []byte } @@ -67,6 +74,7 @@ type Request interface { func (_ RequestEcho) AssertRequestType() {} func (_ RequestFlush) AssertRequestType() {} +func (_ RequestInfo) AssertRequestType() {} func (_ RequestAppendTx) AssertRequestType() {} func (_ RequestGetHash) AssertRequestType() {} func (_ RequestCommit) AssertRequestType() {} @@ -79,6 +87,7 @@ var _ = wire.RegisterInterface( struct{ Request }{}, wire.ConcreteType{RequestEcho{}, requestTypeEcho}, wire.ConcreteType{RequestFlush{}, requestTypeFlush}, + wire.ConcreteType{RequestInfo{}, requestTypeInfo}, wire.ConcreteType{RequestAppendTx{}, requestTypeAppendTx}, wire.ConcreteType{RequestGetHash{}, requestTypeGetHash}, wire.ConcreteType{RequestCommit{}, requestTypeCommit}, @@ -91,13 +100,16 @@ var _ = wire.RegisterInterface( //---------------------------------------- type ResponseEcho struct { - RetCode Message string } type ResponseFlush struct { } +type ResponseInfo struct { + Data []string +} + type ResponseAppendTx struct { RetCode } @@ -141,6 +153,7 @@ type Response interface { func (_ ResponseEcho) AssertResponseType() {} func (_ ResponseFlush) AssertResponseType() {} +func (_ ResponseInfo) AssertResponseType() {} func (_ ResponseAppendTx) AssertResponseType() {} func (_ ResponseGetHash) AssertResponseType() {} func (_ ResponseCommit) AssertResponseType() {} @@ -155,6 +168,7 @@ var _ = wire.RegisterInterface( struct{ Response }{}, wire.ConcreteType{ResponseEcho{}, responseTypeEcho}, wire.ConcreteType{ResponseFlush{}, responseTypeFlush}, + wire.ConcreteType{ResponseInfo{}, responseTypeInfo}, wire.ConcreteType{ResponseAppendTx{}, responseTypeAppendTx}, wire.ConcreteType{ResponseGetHash{}, responseTypeGetHash}, wire.ConcreteType{ResponseCommit{}, responseTypeCommit},