relayws

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2024 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ChallengeHRP = "nch"
View Source
const ChallengeLength = 16

Variables

This section is empty.

Functions

This section is empty.

Types

type B

type B = []byte

type E

type E = error

type MessageType

type MessageType int
const (
	// TextMessage denotes a text data message. The text message payload is interpreted as UTF-8 encoded text data.
	TextMessage MessageType = w.TextMessage

	// BinaryMessage denotes a binary data message.
	BinaryMessage MessageType = w.BinaryMessage

	// CloseMessage denotes a close control message. The optional message payload contains a numeric code and text. Use
	// the FormatCloseMessage function to format a close message payload.
	CloseMessage MessageType = w.CloseMessage

	// PingMessage denotes a ping control message. The optional message payload is UTF-8 encoded text.
	PingMessage MessageType = w.PingMessage

	// PongMessage denotes a pong control message. The optional message payload is UTF-8 encoded text.
	PongMessage MessageType = w.PongMessage
)

The message types are defined in RFC 6455, section 11.8.

Repeating here for shorter names.

type N added in v0.0.14

type N = int

type S

type S = string

type WS

type WS struct {
	Conn *w.Conn

	Request *http.Request // original request

	Pending atomic.Value // for DM CLI authentication

	Authed       chan struct{}
	OffenseCount atomic.Uint32 // when client does dumb stuff, increment this
	// contains filtered or unexported fields
}

WS is a wrapper around a gorilla/websocket with mutex locking and NIP-42 IsAuthed support

func New

func New(conn *w.Conn, req *http.Request, authed qu.C) (ws *WS)

func (*WS) AuthPub

func (ws *WS) AuthPub() (a B)

AuthPub returns the current authed Pubkey.

func (*WS) Challenge

func (ws *WS) Challenge() (challenge B)

Challenge returns the current challenge on a websocket.

func (*WS) GenerateChallenge

func (ws *WS) GenerateChallenge() (challenge S)

GenerateChallenge gathers new entropy to generate a new challenge, stores it and returns it.

func (*WS) HasAuth

func (ws *WS) HasAuth() bool

func (*WS) Ping

func (ws *WS) Ping() (err E)

func (*WS) Pong

func (ws *WS) Pong() (err E)

func (*WS) Remote

func (ws *WS) Remote() (remote S)

Remote returns the current real remote.

func (*WS) SetAuthPubKey

func (ws *WS) SetAuthPubKey(a B)

SetAuthPubKey loads the outhPubKey atomic of the websocket. Note that []byte is a reference so the caller should not mutate it. Calls to access it are copied as above.

func (*WS) SetRealRemote

func (ws *WS) SetRealRemote(remote S)

func (*WS) WriteEnvelope

func (ws *WS) WriteEnvelope(env enveloper.I) (err error)

WriteEnvelope writes a message with a given websocket type specifier

func (*WS) WriteTextMessage

func (ws *WS) WriteTextMessage(b B) (err E)

WriteTextMessage writes a text (binary?) message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL