Documentation ¶
Index ¶
- Constants
- type Connection
- type EventMessage
- type IncomingEvent
- type Relay
- func (r *Relay) Auth(ctx context.Context, event *nip1.Event) (s Status, e error)
- func (r *Relay) Close() (e error)
- func (r *Relay) Connect(ctx context.Context) (e error)
- func (r *Relay) Context() context.Context
- func (r *Relay) Count(ctx context.Context, filters nip1.Filters, opts ...SubscriptionOption) (c int64, e error)
- func (r *Relay) IsConnected() bool
- func (r *Relay) PrepareSubscription(ctx context.Context, filters nip1.Filters, opts ...SubscriptionOption) (s *Subscription)
- func (r *Relay) Publish(ctx context.Context, event *nip1.Event) (s Status, e error)
- func (r *Relay) QuerySync(ctx context.Context, filter *nip1.Filter, opts ...SubscriptionOption) (evs []*nip1.Event, e error)
- func (r *Relay) String() string
- func (r *Relay) Subscribe(ctx context.Context, filters nip1.Filters, opts ...SubscriptionOption) (s *Subscription, e error)
- func (r *Relay) Write(msg []byte) <-chan error
- type RelayOption
- type SimplePool
- func (pool *SimplePool) EnsureRelay(url string) (*Relay, error)
- func (pool *SimplePool) QuerySingle(ctx context.Context, urls []string, filter *nip1.Filter) *IncomingEvent
- func (pool *SimplePool) SubMany(ctx context.Context, urls []string, filters nip1.Filters, unique bool) chan IncomingEvent
- func (pool *SimplePool) SubManyEose(ctx context.Context, urls []string, filters nip1.Filters) chan IncomingEvent
- func (pool *SimplePool) SubManyEoseNonUnique(ctx context.Context, urls []string, filters nip1.Filters) chan IncomingEvent
- func (pool *SimplePool) SubManyNonUnique(ctx context.Context, urls []string, filters nip1.Filters, unique bool) chan IncomingEvent
- type Status
- type Subscription
- type SubscriptionOption
- type WithAuthHandler
- type WithLabel
- type WithNoticeHandler
Constants ¶
const MAX_LOCKS = 50
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func (*Connection) Close ¶
func (c *Connection) Close() error
func (*Connection) ReadMessage ¶
func (*Connection) WriteMessage ¶
func (c *Connection) WriteMessage(data []byte) error
type EventMessage ¶
type IncomingEvent ¶
type Relay ¶
type Relay struct { URL string RequestHeader http.Header // e.g. for origin header Connection *Connection Subscriptions *xsync.MapOf[string, *Subscription] Err 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 NewRelay ¶
func NewRelay(ctx context.Context, url string, opts ...RelayOption) (r *Relay)
NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
func RelayConnect ¶
RelayConnect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().
func (*Relay) Auth ¶
Auth sends an "AUTH" command client -> relay as in NIP-42. Status can be: success, failed, or sent (no response from relay before ctx times out).
func (*Relay) Connect ¶
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 (*Relay) Context ¶
Context retrieves the context that is associated with this relay connection.
func (*Relay) IsConnected ¶
IsConnected returns true if the connection to this relay seems to be active.
func (*Relay) PrepareSubscription ¶
func (r *Relay) PrepareSubscription(ctx context.Context, filters nip1.Filters, opts ...SubscriptionOption) (s *Subscription)
PrepareSubscription creates a subscription, but doesn't fire it.
Remember to cancel subscriptions, either by calling `.Unsub()` on them or ensuring their `context.Context` will be canceled at some point. Failure to do that will result in a huge number of halted goroutines being created.
func (*Relay) Publish ¶
Publish sends an "EVENT" command to the relay r as in NIP-01. Status can be: success, failed, or sent (no response from relay before ctx times out).
func (*Relay) Subscribe ¶
func (r *Relay) Subscribe(ctx context.Context, filters nip1.Filters, opts ...SubscriptionOption) (s *Subscription, e 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.Context` will be canceled at some point. Failure to do that will result in a huge number of halted goroutines being created.
type RelayOption ¶
type RelayOption interface {
IsRelayOption()
}
RelayOption is the type of the argument passed for that. Some examples of this are WithNoticeHandler and WithAuthHandler.
type SimplePool ¶
type SimplePool struct { Relays map[string]*Relay Context context.Context // contains filtered or unexported fields }
func NewSimplePool ¶
func NewSimplePool(ctx context.Context) *SimplePool
func (*SimplePool) EnsureRelay ¶
func (pool *SimplePool) EnsureRelay(url string) (*Relay, error)
func (*SimplePool) QuerySingle ¶
func (pool *SimplePool) QuerySingle(ctx context.Context, urls []string, filter *nip1.Filter) *IncomingEvent
QuerySingle returns the first event returned by the first relay, cancels everything else.
func (*SimplePool) SubMany ¶
func (pool *SimplePool) SubMany(ctx context.Context, urls []string, filters nip1.Filters, unique bool) chan IncomingEvent
SubMany opens a subscription with the given filters to multiple relays the subscriptions only end when the context is canceled
func (*SimplePool) SubManyEose ¶
func (pool *SimplePool) SubManyEose(ctx context.Context, urls []string, filters nip1.Filters) chan IncomingEvent
SubManyEose is like SubMany, but it stops subscriptions and closes the channel when gets a EOSE
func (*SimplePool) SubManyEoseNonUnique ¶
func (pool *SimplePool) SubManyEoseNonUnique(ctx context.Context, urls []string, filters nip1.Filters) chan IncomingEvent
SubManyEoseNonUnique is like SubManyEose, but returns duplicate events if they come from different relays
func (*SimplePool) SubManyNonUnique ¶
func (pool *SimplePool) SubManyNonUnique(ctx context.Context, urls []string, filters nip1.Filters, unique bool) chan IncomingEvent
SubManyNonUnique is like SubMany, but returns duplicate events if they come from different relays
type Subscription ¶
type Subscription struct { Relay *Relay Filters nip1.Filters // the Events channel emits all EVENTs that come in a Subscription // will be closed when the subscription ends Events chan *nip1.Event // the EndOfStoredEvents channel gets closed when an EOSE comes for that subscription EndOfStoredEvents chan struct{} // Context will be .Done() when the subscription ends Context context.Context // contains filtered or unexported fields }
func (*Subscription) Close ¶
func (sub *Subscription) Close()
Close just sends a CLOSE message. You probably want Unsub() instead.
func (*Subscription) Fire ¶
func (sub *Subscription) Fire() (e error)
Fire sends the "REQ" command to the relay.
func (*Subscription) GetID ¶
func (sub *Subscription) GetID() string
GetID return the Nostr subscription ID as given to the Relay it is a concatenation of the label and a serial number.
func (*Subscription) Sub ¶
func (sub *Subscription) Sub(_ context.Context, filters nip1.Filters)
Sub sets sub.Filters and then calls sub.Fire(ctx). The subscription will be closed if the context expires.
func (*Subscription) Unsub ¶
func (sub *Subscription) Unsub()
Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01. Unsub() also closes the channel sub.Events and makes a new one.
type SubscriptionOption ¶
type SubscriptionOption interface {
IsSubscriptionOption()
}
SubscriptionOption is the type of the argument passed for that. Some examples are WithLabel.
type WithAuthHandler ¶
WithAuthHandler takes an auth event and expects it to be signed. when not given, AUTH messages from relays are ignored.
func (WithAuthHandler) IsRelayOption ¶
func (_ WithAuthHandler) IsRelayOption()
type WithLabel ¶
type WithLabel string
WithLabel puts a label on the subscription (it is prepended to the automatic id) that is sent to relays.
func (WithLabel) IsSubscriptionOption ¶
func (_ WithLabel) IsSubscriptionOption()
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()