View Source
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")

    Using errors.New prevents defining these as consts.


    This section is empty.


    This section is empty.


    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 struct {
        	// contains filtered or unexported fields

          WSLink is the local, per-connection representation of a DEX peer (client or server) connection.

          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

            func (c *WSLink) Connect(ctx context.Context) (*sync.WaitGroup, error)

              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) IP

                  func (c *WSLink) IP() string

                    IP is the peer address passed to the constructor.

                    func (*WSLink) Off

                    func (c *WSLink) Off() bool

                      Off will return true if the link has disconnected.

                      func (*WSLink) Send

                      func (c *WSLink) Send(msg *msgjson.Message) error

                        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) SendError

                        func (c *WSLink) SendError(id uint64, rpcErr *msgjson.Error)

                          SendError sends the msgjson.Error to the peer in a ResponsePayload.

                          func (*WSLink) SendNow

                          func (c *WSLink) SendNow(msg *msgjson.Message) error

                            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) SetReadLimit

                            func (c *WSLink) SetReadLimit(limit int64)

                              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).

                              Source Files