mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
Prefix TMSP messages with length
This commit is contained in:
@ -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
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user