relay

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: CC0-1.0, MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidRelayURL added in v1.0.11

func IsValidRelayURL(u string) bool

Types

type Option

type Option interface {
	IsRelayOption()
}

Option is the type of the argument passed for that.

type Status

type Status int

type T added in v1.0.11

type T struct {
	RequestHeader http.Header // e.g. for origin header

	Connection    *connection.C
	Subscriptions *xsync.MapOf[string, *subscription.T]

	ConnectionError error

	// custom things that aren't often used
	//
	AssumeValid bool // this will skip verifying signatures for events received from this relay
	// contains filtered or unexported fields
}

func Connect added in v1.0.11

func Connect(c context.T, url string, opts ...Option) (*T, error)

Connect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().

func MustConnect added in v1.0.11

func MustConnect(url string) *T

func NewRelay added in v1.0.11

func NewRelay(c context.T, url string, opts ...Option) *T

NewRelay returns a new relay. The relay connection will be closed when the context is canceled.

func (*T) Auth added in v1.0.11

func (r *T) Auth(c context.T, sign func(ev *event.T) error) error

Auth sends an "AUTH" command client->relay as in NIP-42 and waits for an OK response.

func (*T) Close added in v1.0.11

func (r *T) Close() error

func (*T) Connect added in v1.0.11

func (r *T) Connect(c context.T) (err error)

Connect tries to establish a websocket connection to r.URL. If the context expires before the connection is complete, an error is returned. Once successfully connected, context expiration has no effect: call r.Close to close the connection.

The underlying relay connection will use a background context. If you want to pass a custom context to the underlying relay connection, use NewRelay() and then Relay.Connect().

func (*T) Context added in v1.0.11

func (r *T) Context() context.T

Context retrieves the context that is associated with this relay connection.

func (*T) Count added in v1.0.11

func (r *T) Count(c context.T, filters filters.T,
	opts ...subscriptionoption.I) (int64, error)

func (*T) Delete added in v1.0.11

func (r *T) Delete(key string)

func (*T) IsConnected added in v1.0.11

func (r *T) IsConnected() bool

IsConnected returns true if the connection to this relay seems to be active.

func (*T) MessageReadLoop added in v1.0.11

func (r *T) MessageReadLoop(conn *connection.C)

func (*T) PrepareSubscription added in v1.0.11

func (r *T) PrepareSubscription(c context.T, f filters.T,
	opts ...subscriptionoption.I) *subscription.T

PrepareSubscription creates a subscription, but doesn't fire it.

Remember to cancel subscriptions, either by calling `.Unsub()` on them or ensuring their `context.T` will be canceled at some point. Failure to do that will result in a huge number of halted goroutines being created.

func (*T) Publish added in v1.0.11

func (r *T) Publish(c context.T, ev *event.T) error

Publish sends an "EVENT" command to the relay r as in NIP-01 and waits for an OK response.

func (*T) QuerySync added in v1.0.11

func (r *T) QuerySync(c context.T, f *filter.T,
	opts ...subscriptionoption.I) ([]*event.T, error)

func (*T) String added in v1.0.11

func (r *T) String() string

String just returns the relay URL.

func (*T) Subscribe added in v1.0.11

func (r *T) Subscribe(c context.T, f filters.T,
	opts ...subscriptionoption.I) (*subscription.T, error)

Subscribe sends a "REQ" command to the relay r as in NIP-01. Events are returned through the channel sub.Events. The subscription is closed when context ctx is cancelled ("CLOSE" in NIP-01).

Remember to cancel subscriptions, either by calling `.Unsub()` on them or ensuring their `context.T` will be canceled at some point. Failure to do that will result in a huge number of halted goroutines being created.

func (*T) URL added in v1.0.11

func (r *T) URL() string

func (*T) Write added in v1.0.11

func (r *T) Write(msg []byte) <-chan error

Write queues a message to be sent to the relay.

type WithNoticeHandler

type WithNoticeHandler func(notice string)

WithNoticeHandler just takes notices and is expected to do something with them. when not given, defaults to logging the notices.

func (WithNoticeHandler) IsRelayOption

func (_ WithNoticeHandler) IsRelayOption()

Jump to

Keyboard shortcuts

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