Documentation ¶
Index ¶
- Constants
- type Connection
- type WSLink
- func (c *WSLink) Addr() string
- func (c *WSLink) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (c *WSLink) Disconnect()
- func (c *WSLink) Done() <-chan struct{}
- func (c *WSLink) Off() bool
- func (c *WSLink) Send(msg *msgjson.Message) error
- func (c *WSLink) SendError(id uint64, rpcErr *msgjson.Error)
- func (c *WSLink) SendNow(msg *msgjson.Message) error
- func (c *WSLink) SendRaw(b []byte) error
- func (c *WSLink) SetReadLimit(limit int64)
Constants ¶
const ( // ErrPeerDisconnected will be returned if Send or Request is called on a // disconnected link. ErrPeerDisconnected = dex.ErrorKind("peer disconnected") ErrHandshake = dex.ErrorKind("handshake error") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface { Close() error SetReadDeadline(t time.Time) error ReadMessage() (int, []byte, error) SetReadLimit(limit int64) SetWriteDeadline(t time.Time) error WriteMessage(int, []byte) error WriteControl(messageType int, data []byte, deadline time.Time) error }
Connection represents a websocket connection to a remote peer. In practice, it is satisfied by *websocket.Conn. For testing, a stub can be used.
func NewConnection ¶
func NewConnection(w http.ResponseWriter, r *http.Request, readTimeout time.Duration) (Connection, error)
NewConnection attempts to to upgrade the http connection to a websocket Connection. If the upgrade fails, a reply will be sent with an appropriate error code.
type WSLink ¶
type WSLink struct { RawHandler func([]byte) // contains filtered or unexported fields }
WSLink is the local, per-connection representation of a DEX peer (client or server) connection.
func NewWSLink ¶
func NewWSLink(addr string, conn Connection, pingPeriod time.Duration, handler func(*msgjson.Message) *msgjson.Error, logger dex.Logger) *WSLink
NewWSLink is a constructor for a new WSLink.
func (*WSLink) Connect ¶
Connect begins processing input and output messages. Do not send messages until connected.
func (*WSLink) Disconnect ¶
func (c *WSLink) Disconnect()
Disconnect begins shutdown of the WSLink, preventing new messages from entering the outgoing queue, and ultimately closing the underlying connection when all queued messages have been handled. This shutdown process is complete when the WaitGroup returned by Connect is Done.
func (*WSLink) Done ¶
func (c *WSLink) Done() <-chan struct{}
Done returns a channel that is closed when the link goes down.
func (*WSLink) Send ¶
Send sends the passed Message to the websocket peer. The actual writing of the message on the peer's link occurs asynchronously. As such, a nil error only indicates that the link is believed to be up and the message was successfully marshalled.
func (*WSLink) SendNow ¶
SendNow is like send, but it waits for the message to be written on the peer's link, returning any error from the write.
func (*WSLink) SendRaw ¶ added in v0.5.0
SendRaw sends the passed bytes to the websocket peer. The actual writing of the message on the peer's link occurs asynchronously. As such, a nil error only indicates that the link is believed to be up.
func (*WSLink) SetReadLimit ¶
SetReadLimit should only be called before starting the Connection, or in a request or response handler that is run synchronously with other text or binary frame reads (e.g. ReadMessage).