app

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrThreadInUse indicates an operation could not be completed because the
	// thread is bound to an app.
	ErrThreadInUse = errors.New("thread is in use")

	// ErrInvalidNetRecordBody indicates the app determined the record body should not be accepted.
	ErrInvalidNetRecordBody = errors.New("app denied net record body")
)

Functions

This section is empty.

Types

type App

type App interface {
	// ValidateNetRecordBody provides the app an opportunity to validate the contents
	// of a record before it's committed to a thread log.
	// identity is the author's public key.
	ValidateNetRecordBody(ctx context.Context, body format.Node, identity thread.PubKey) error

	// HandleNetRecord handles an inbound thread record from net.
	HandleNetRecord(ctx context.Context, rec net.ThreadRecord, key thread.Key) error

	// GetNetRecordCreateTime calls the connection app's GetNetRecordCreateTime to parse the record createtime.
	GetNetRecordCreateTime(ctx context.Context, rec net.ThreadRecord, key thread.Key) (int64, error)
}

App provides a bidirectional hook for thread-based apps.

type Connection

type Connection func(context.Context, thread.ID) (<-chan net.ThreadRecord, error)

Connection receives new thread records, which are pumped to the app.

type Connector

type Connector struct {
	Net Net
	// contains filtered or unexported fields
}

Connector connects an app to a thread.

func NewConnector

func NewConnector(app App, net Net, tinfo thread.Info) (*Connector, error)

NewConnector creates bidirectional connection between an app and a thread.

func (*Connector) CreateNetRecord

func (c *Connector) CreateNetRecord(ctx context.Context, body format.Node, token thread.Token) (net.ThreadRecord, error)

CreateNetRecord calls net.CreateRecord while supplying thread ID and API token.

func (*Connector) GetNetRecordCreateTime added in v0.1.1

func (c *Connector) GetNetRecordCreateTime(ctx context.Context, rec net.ThreadRecord) (int64, error)

GetNetRecordCreateTime calls the connection app's GetNetRecordCreateTime to parse the record createtime.

func (*Connector) HandleNetRecord

func (c *Connector) HandleNetRecord(ctx context.Context, rec net.ThreadRecord) error

HandleNetRecord calls the connection app's HandleNetRecord while supplying thread key.

func (*Connector) ThreadID

func (c *Connector) ThreadID() thread.ID

ThreadID returns the underlying thread's ID.

func (*Connector) Token

func (c *Connector) Token() net.Token

Token returns the net token.

func (*Connector) Validate

func (c *Connector) Validate(token thread.Token, readOnly bool) error

Validate thread token against the net host.

func (*Connector) ValidateNetRecordBody

func (c *Connector) ValidateNetRecordBody(ctx context.Context, body format.Node, identity thread.PubKey) error

ValidateNetRecordBody calls the connection app's ValidateNetRecordBody.

type LocalEvent

type LocalEvent struct {
	Node  format.Node
	Token thread.Token
}

LocalEvent wraps an IPLD node and auth for delivery to a thread.

type LocalEventListener

type LocalEventListener struct {
	// contains filtered or unexported fields
}

LocalEventListener notifies about new locally generated events.

func (*LocalEventListener) Channel

func (l *LocalEventListener) Channel() <-chan *LocalEvent

Channel returns an unbuffered channel to receive local events.

func (*LocalEventListener) Discard

func (l *LocalEventListener) Discard()

Discard indicates that no further events will be received and ready for being garbage collected.

type LocalEventsBus

type LocalEventsBus struct {
	// contains filtered or unexported fields
}

LocalEventsBus wraps a broadcaster for local events.

func NewLocalEventsBus

func NewLocalEventsBus() *LocalEventsBus

NewLocalEventsBus returns a new bus for local event.

func (*LocalEventsBus) Discard

func (leb *LocalEventsBus) Discard()

Discard the bus, closing all listeners.

func (*LocalEventsBus) Listen

func (leb *LocalEventsBus) Listen() *LocalEventListener

Listen returns a local event listener.

func (*LocalEventsBus) Send

func (leb *LocalEventsBus) Send(event *LocalEvent) error

Send an IPLD node and thread auth into the bus. These are received by the app connector and written to the underlying thread.

type Net

type Net interface {
	net.Net

	// ConnectApp returns an app<->thread connector.
	ConnectApp(App, thread.ID) (*Connector, error)

	// Validate thread ID and token against the net host.
	// If token is present and was issued the net host (is valid), the embedded public key is returned.
	// If token is not present, both the returned public key and error will be nil.
	Validate(id thread.ID, token thread.Token, readOnly bool) (thread.PubKey, error)

	// Exchange thread records with  peers that have the thread.
	Exchange(ctx context.Context, id thread.ID) error
}

Net adds the ability to connect an app to a thread.

Jump to

Keyboard shortcuts

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