Browse Source

Prefix TMSP messages with length

pull/169/merge
Jae Kwon 9 years ago
parent
commit
f288e58c81
5 changed files with 15 additions and 7 deletions
  1. +1
    -1
      consensus/common_test.go
  2. +1
    -1
      mempool/mempool_test.go
  3. +1
    -1
      node/node_test.go
  4. +11
    -3
      proxy/remote_app_context.go
  5. +1
    -1
      proxy/remote_app_context_test.go

+ 1
- 1
consensus/common_test.go View File

@ -16,7 +16,7 @@ import (
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmsp/example"
"github.com/tendermint/tmsp/example/golang"
)
var chainID string


+ 1
- 1
mempool/mempool_test.go View File

@ -6,7 +6,7 @@ import (
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmsp/example"
"github.com/tendermint/tmsp/example/golang"
tmsp "github.com/tendermint/tmsp/types"
)


+ 1
- 1
node/node_test.go View File

@ -7,7 +7,7 @@ import (
. "github.com/tendermint/go-common"
"github.com/tendermint/go-p2p"
_ "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tmsp/example"
"github.com/tendermint/tmsp/example/golang"
"github.com/tendermint/tmsp/server"
)


+ 11
- 3
proxy/remote_app_context.go View File

@ -2,6 +2,7 @@ package proxy
import (
"bufio"
"bytes"
"container/list"
"errors"
"fmt"
@ -83,7 +84,7 @@ func (app *remoteAppContext) Error() error {
func (app *remoteAppContext) sendRequestsRoutine() {
for {
var n int
var n, n2 int
var err error
select {
case <-app.QuitService.Quit:
@ -92,7 +93,10 @@ func (app *remoteAppContext) sendRequestsRoutine() {
app.willSendReq(reqres)
wire.WriteBinary(reqres.Request, app.bufWriter, &n, &err)
buf := new(bytes.Buffer)
wire.WriteBinary(reqres.Request, buf, &n2, &err) // Length prefix
wire.WriteVarint(buf.Len(), app.bufWriter, &n, &err)
wire.WriteTo(buf.Bytes(), app.bufWriter, &n, &err)
if err != nil {
app.StopForError(err)
return
@ -113,13 +117,17 @@ func (app *remoteAppContext) recvResponseRoutine() {
r := bufio.NewReader(app.conn) // Buffer reads
for {
var res tmsp.Response
var n int
var n, n2 int
var err error
size := wire.ReadVarint(r, &n2, &err)
wire.ReadBinaryPtr(&res, r, maxResponseSize, &n, &err)
if err != nil {
app.StopForError(err)
return
}
if size != n {
app.StopForError(fmt.Errorf("Prefixed length not equal to actual length. %v vs %v", size, n))
}
switch res := res.(type) {
case tmsp.ResponseException:
app.StopForError(errors.New(res.Error))


+ 1
- 1
proxy/remote_app_context_test.go View File

@ -7,7 +7,7 @@ import (
. "github.com/tendermint/go-common"
"github.com/tendermint/go-logio"
example "github.com/tendermint/tmsp/example"
"github.com/tendermint/tmsp/example/golang"
"github.com/tendermint/tmsp/server"
)


Loading…
Cancel
Save