|
@ -3,6 +3,7 @@ package core_client |
|
|
import ( |
|
|
import ( |
|
|
"net/http" |
|
|
"net/http" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket" |
|
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket" |
|
|
. "github.com/tendermint/tendermint/common" |
|
|
. "github.com/tendermint/tendermint/common" |
|
@ -12,8 +13,11 @@ import ( |
|
|
"github.com/tendermint/tendermint/wire" |
|
|
"github.com/tendermint/tendermint/wire" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
const wsEventsChannelCapacity = 10 |
|
|
|
|
|
const wsResultsChannelCapacity = 10 |
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
wsEventsChannelCapacity = 10 |
|
|
|
|
|
wsResultsChannelCapacity = 10 |
|
|
|
|
|
wsWriteTimeoutSeconds = 10 |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
type WSClient struct { |
|
|
type WSClient struct { |
|
|
QuitService |
|
|
QuitService |
|
@ -53,6 +57,14 @@ func (wsc *WSClient) dial() error { |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
// Set the ping/pong handlers
|
|
|
|
|
|
con.SetPingHandler(func(m string) error { |
|
|
|
|
|
con.WriteControl(websocket.PongMessage, []byte(m), time.Now().Add(time.Second*wsWriteTimeoutSeconds)) |
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
|
|
|
con.SetPongHandler(func(m string) error { |
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
wsc.Conn = con |
|
|
wsc.Conn = con |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -65,14 +77,14 @@ func (wsc *WSClient) receiveEventsRoutine() { |
|
|
for { |
|
|
for { |
|
|
_, data, err := wsc.ReadMessage() |
|
|
_, data, err := wsc.ReadMessage() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Info(Fmt("WSClient failed to read message: %v", err)) |
|
|
|
|
|
|
|
|
log.Info("WSClient failed to read message", "error", err, "data", string(data)) |
|
|
wsc.Stop() |
|
|
wsc.Stop() |
|
|
break |
|
|
break |
|
|
} else { |
|
|
} else { |
|
|
var response ctypes.Response |
|
|
var response ctypes.Response |
|
|
wire.ReadJSON(&response, data, &err) |
|
|
wire.ReadJSON(&response, data, &err) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Info(Fmt("WSClient failed to parse message: %v", err)) |
|
|
|
|
|
|
|
|
log.Info("WSClient failed to parse message", "error", err) |
|
|
wsc.Stop() |
|
|
wsc.Stop() |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|