rpc, p2p/simulations: use github.com/gorilla/websocket (#20289)
* rpc: improve codec abstraction rpc.ServerCodec is an opaque interface. There was only one way to get a codec using existing APIs: rpc.NewJSONCodec. This change exports newCodec (as NewFuncCodec) and NewJSONCodec (as NewCodec). It also makes all codec methods non-public to avoid showing internals in godoc. While here, remove codec options in tests because they are not supported anymore. * p2p/simulations: use github.com/gorilla/websocket This package was the last remaining user of golang.org/x/net/websocket. Migrating to the new library wasn't straightforward because it is no longer possible to treat WebSocket connections as a net.Conn. * vendor: delete golang.org/x/net/websocket * rpc: fix godoc comments and run gofmt
This commit is contained in:
committed by
Péter Szilágyi
parent
9e71f55bfa
commit
7c4a4eb58a
@ -117,7 +117,7 @@ func (c *Client) newClientConn(conn ServerCodec) *clientConn {
|
||||
|
||||
func (cc *clientConn) close(err error, inflightReq *requestOp) {
|
||||
cc.handler.close(err, inflightReq)
|
||||
cc.codec.Close()
|
||||
cc.codec.close()
|
||||
}
|
||||
|
||||
type readOp struct {
|
||||
@ -484,7 +484,7 @@ func (c *Client) write(ctx context.Context, msg interface{}) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := c.writeConn.Write(ctx, msg)
|
||||
err := c.writeConn.writeJSON(ctx, msg)
|
||||
if err != nil {
|
||||
c.writeConn = nil
|
||||
}
|
||||
@ -511,7 +511,7 @@ func (c *Client) reconnect(ctx context.Context) error {
|
||||
c.writeConn = newconn
|
||||
return nil
|
||||
case <-c.didClose:
|
||||
newconn.Close()
|
||||
newconn.close()
|
||||
return ErrClientQuit
|
||||
}
|
||||
}
|
||||
@ -558,7 +558,7 @@ func (c *Client) dispatch(codec ServerCodec) {
|
||||
|
||||
// Reconnect:
|
||||
case newcodec := <-c.reconnected:
|
||||
log.Debug("RPC client reconnected", "reading", reading, "conn", newcodec.RemoteAddr())
|
||||
log.Debug("RPC client reconnected", "reading", reading, "conn", newcodec.remoteAddr())
|
||||
if reading {
|
||||
// Wait for the previous read loop to exit. This is a rare case which
|
||||
// happens if this loop isn't notified in time after the connection breaks.
|
||||
@ -612,9 +612,9 @@ func (c *Client) drainRead() {
|
||||
// read decodes RPC messages from a codec, feeding them into dispatch.
|
||||
func (c *Client) read(codec ServerCodec) {
|
||||
for {
|
||||
msgs, batch, err := codec.Read()
|
||||
msgs, batch, err := codec.readBatch()
|
||||
if _, ok := err.(*json.SyntaxError); ok {
|
||||
codec.Write(context.Background(), errorMessage(&parseError{err.Error()}))
|
||||
codec.writeJSON(context.Background(), errorMessage(&parseError{err.Error()}))
|
||||
}
|
||||
if err != nil {
|
||||
c.readErr <- err
|
||||
|
Reference in New Issue
Block a user