client

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: GPL-2.0, MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidRelayURL

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

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

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

	ConnectionError error

	AuthRequired chan struct{}

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

func Connect

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 ConnectWithAuth

func ConnectWithAuth(c context.T, url, sec string,
	opts ...Option) (rl *T, err error)

ConnectWithAuth auths with the relay, checks if its NIP-11 says auth-required and uses the provided sec to sign the auth challenge.

func MustConnect

func MustConnect(url string) *T

func NewRelay

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

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

func (r *T) Close() error

func (*T) Connect

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

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

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

func (*T) Count

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

func (*T) Delete

func (r *T) Delete(key string)

func (*T) IsConnected

func (r *T) IsConnected() bool

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

func (*T) MessageReadLoop

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

func (*T) PrepareSubscription

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

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

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

func (*T) String

func (r *T) String() string

String just returns the relay URL.

func (*T) Subscribe

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

func (r *T) URL() string

func (*T) Write

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