Documentation ¶
Index ¶
- Constants
- type B
- type Client
- func (r *Client) Auth(c Ctx, sign signer.I) error
- func (r *Client) Close() error
- func (r *Client) Connect(c Ctx) error
- func (r *Client) ConnectWithTLS(ctx Ctx, tlsConfig *tls.Config) error
- func (r *Client) Context() Ctx
- func (r *Client) Count(c Ctx, ff *filters.T, opts ...SubscriptionOption) (int, error)
- func (r *Client) IsConnected() bool
- func (r *Client) PrepareSubscription(c Ctx, ff *filters.T, opts ...SubscriptionOption) *Subscription
- func (r *Client) Publish(c Ctx, ev *event.T) E
- func (r *Client) QuerySync(ctx Ctx, f *filter.T, opts ...SubscriptionOption) ([]*event.T, error)
- func (r *Client) String() string
- func (r *Client) Subscribe(c Ctx, ff *filters.T, opts ...SubscriptionOption) (*Subscription, error)
- func (r *Client) Write(msg []byte) <-chan error
- type Connection
- type Ctx
- type DirectedFilters
- type E
- type EventMessage
- type IncomingEvent
- type MessageType
- type N
- type PoolOption
- type RelayOption
- type S
- type Serv
- func (ws *Serv) AuthPub() (a B)
- func (ws *Serv) Challenge() (challenge B)
- func (ws *Serv) Close() (err E)
- func (ws *Serv) HasAuth() bool
- func (ws *Serv) Ping() (err E)
- func (ws *Serv) Pong() (err E)
- func (ws *Serv) Remote() (remote S)
- func (ws *Serv) Write(b []byte) (n int, err error)
- func (ws *Serv) WriteTextMessage(b B) (err E)
- type SimplePool
- func (pool *SimplePool) BatchedSubMany(c Ctx, dfs []DirectedFilters) chan IncomingEvent
- func (pool *SimplePool) BatchedSubManyEose(c Ctx, dfs []DirectedFilters) chan IncomingEvent
- func (pool *SimplePool) EnsureRelay(url S) (*Client, error)
- func (pool *SimplePool) QuerySingle(c Ctx, urls []S, f *filter.T) *IncomingEvent
- func (pool *SimplePool) SubMany(c Ctx, urls []S, ff *filters.T) chan IncomingEvent
- func (pool *SimplePool) SubManyEose(c Ctx, urls []S, ff *filters.T) chan IncomingEvent
- func (pool *SimplePool) SubManyEoseNonUnique(c Ctx, urls []S, ff *filters.T) chan IncomingEvent
- func (pool *SimplePool) SubManyNonUnique(c Ctx, urls []S, ff *filters.T) chan IncomingEvent
- type Status
- type Subscription
- type SubscriptionOption
- type WithAuthHandler
- type WithEventMiddleware
- type WithLabel
- type WithNoticeHandler
- type WithSignatureChecker
Constants ¶
const ChallengeHRP = "nchal"
const ChallengeLength = 16
const MAX_LOCKS = 50
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { URL string RequestHeader http.Header // e.g. for origin header Connection *Connection Subscriptions *xsync.MapOf[string, *Subscription] ConnectionError error AssumeValid bool // this will skip verifying signatures for events received from this relay // contains filtered or unexported fields }
func NewRelay ¶
func NewRelay(c Ctx, url S, opts ...RelayOption) *Client
NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
func RelayConnect ¶
func RelayConnect(ctx Ctx, url string, opts ...RelayOption) (*Client, error)
RelayConnect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().
func (*Client) Auth ¶
Auth sends an "AUTH" command client->relay as in NIP-42 and waits for an OK response.
func (*Client) 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 Client.Connect().
func (*Client) ConnectWithTLS ¶
ConnectWithTLS tries to establish a secured websocket connection to r.URL using customized tls.Config (CA's, etc).
func (*Client) Context ¶
Context retrieves the context that is associated with this relay connection.
func (*Client) IsConnected ¶
IsConnected returns true if the connection to this relay seems to be active.
func (*Client) PrepareSubscription ¶
func (r *Client) PrepareSubscription(c Ctx, ff *filters.T, opts ...SubscriptionOption) *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 (*Client) Publish ¶
Publish sends an "EVENT" command to the relay r as in NIP-01 and waits for an OK response.
func (*Client) Subscribe ¶
func (r *Client) Subscribe(c Ctx, ff *filters.T, opts ...SubscriptionOption) (*Subscription, 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 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(ctx context.Context, data []byte) error
type DirectedFilters ¶
type EventMessage ¶
type IncomingEvent ¶
func (IncomingEvent) String ¶
func (ie IncomingEvent) String() S
type MessageType ¶
type MessageType int
type PoolOption ¶
type PoolOption interface {
ApplyPoolOption(*SimplePool)
}
type RelayOption ¶
type RelayOption interface {
ApplyRelayOption(*Client)
}
RelayOption is the type of the argument passed for that.
type Serv ¶
type Serv struct { Ctx Ctx Cancel context.F Conn *websocket.Conn Request *http.Request // original request Pending atomic.Value // for DM CLI authentication Authed qu.C // contains filtered or unexported fields }
Serv is a wrapper around a fasthttp/websocket with mutex locking and NIP-42 IsAuthed support for handling inbound connections from clients.
func (*Serv) WriteTextMessage ¶
WriteTextMessage writes a text (binary?) message
type SimplePool ¶
type SimplePool struct { Relays *xsync.MapOf[S, *Client] Context Ctx // custom things not often used SignatureChecker func(*event.T) bool // contains filtered or unexported fields }
func NewSimplePool ¶
func NewSimplePool(c Ctx, opts ...PoolOption) *SimplePool
func (*SimplePool) BatchedSubMany ¶
func (pool *SimplePool) BatchedSubMany(c Ctx, dfs []DirectedFilters) chan IncomingEvent
BatchedSubMany fires subscriptions only to specific relays, but batches them when they are the same.
func (*SimplePool) BatchedSubManyEose ¶
func (pool *SimplePool) BatchedSubManyEose(c Ctx, dfs []DirectedFilters) chan IncomingEvent
BatchedSubManyEose is like BatchedSubMany, but ends upon receiving EOSE from all relays.
func (*SimplePool) EnsureRelay ¶
func (pool *SimplePool) EnsureRelay(url S) (*Client, error)
func (*SimplePool) QuerySingle ¶
func (pool *SimplePool) QuerySingle(c Ctx, urls []S, f *filter.T) *IncomingEvent
QuerySingle returns the first event returned by the first relay, cancels everything else.
func (*SimplePool) SubMany ¶
func (pool *SimplePool) SubMany(c Ctx, urls []S, ff *filters.T) 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(c Ctx, urls []S, ff *filters.T) 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(c Ctx, urls []S, ff *filters.T) chan IncomingEvent
SubManyEoseNonUnique is like SubManyEose, but returns duplicate events if they come from different relays
func (*SimplePool) SubManyNonUnique ¶
func (pool *SimplePool) SubManyNonUnique(c Ctx, urls []S, ff *filters.T) chan IncomingEvent
SubManyNonUnique is like SubMany, but returns duplicate events if they come from different relays
type Subscription ¶
type Subscription struct { Relay *Client Filters *filters.T // The Events channel emits all EVENTs that come in a Subscription will be closed when the // subscription ends Events event.C // The EndOfStoredEvents channel is closed when an EOSE comes for that subscription EndOfStoredEvents chan struct{} // The ClosedReason channel emits the reason when a CLOSED message is received ClosedReason chan string // Context will be .Done() when the subscription ends Context Ctx // 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() (err E)
Fire sends the "REQ" command to the realy.
func (*Subscription) GetID ¶
func (sub *Subscription) GetID() (id *subscription.Id)
GetID return the Nostr subscription ID as given to the Client it is a concatenation of the label and a serial number.
func (*Subscription) Sub ¶
func (sub *Subscription) Sub(_ Ctx, ff *filters.T)
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 realy 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 must be a function that signs the auth event when called. it will be called whenever any relay in the pool returns a `CLOSED` message with the "auth-required:" prefix, only once for each relay
func (WithAuthHandler) ApplyPoolOption ¶
func (h WithAuthHandler) ApplyPoolOption(pool *SimplePool)
type WithEventMiddleware ¶
type WithEventMiddleware func(IncomingEvent)
WithEventMiddleware is a function that will be called with all events received. more than one can be passed at a time.
func (WithEventMiddleware) ApplyPoolOption ¶
func (h WithEventMiddleware) ApplyPoolOption(pool *SimplePool)
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 B)
WithNoticeHandler just takes notices and is expected to do something with them. when not given, defaults to logging the notices.
func (WithNoticeHandler) ApplyRelayOption ¶
func (nh WithNoticeHandler) ApplyRelayOption(r *Client)
type WithSignatureChecker ¶
WithSignatureChecker must be a function that checks the signature of an event and returns true or false.
func (WithSignatureChecker) ApplyRelayOption ¶
func (sc WithSignatureChecker) ApplyRelayOption(r *Client)