net

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	io.Closer

	// GetHostID returns the host's peer id.
	GetHostID(ctx context.Context) (peer.ID, error)

	// CreateThread with id.
	CreateThread(ctx context.Context, id thread.ID, opts ...KeyOption) (thread.Info, error)

	// AddThread from a multiaddress.
	AddThread(ctx context.Context, addr ma.Multiaddr, opts ...KeyOption) (thread.Info, error)

	// GetThread with id.
	GetThread(ctx context.Context, id thread.ID) (thread.Info, error)

	// PullThread for new records.
	// Logs owned by this host are traversed locally.
	// Remotely addressed logs are pulled from the network.
	// Is thread-safe.
	PullThread(ctx context.Context, id thread.ID) error

	// DeleteThread with id.
	DeleteThread(ctx context.Context, id thread.ID) error

	// AddReplicator sends the service key and all logs to another peer.
	AddReplicator(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (peer.ID, error)

	// CreateRecord with body.
	CreateRecord(ctx context.Context, id thread.ID, body format.Node) (ThreadRecord, error)

	// AddRecord to the given log.
	AddRecord(ctx context.Context, id thread.ID, lid peer.ID, rec Record) error

	// GetRecord returns the record at cid.
	GetRecord(ctx context.Context, id thread.ID, rid cid.Cid) (Record, error)

	// Subscribe returns a read-only channel of records.
	Subscribe(ctx context.Context, opts ...SubOption) (<-chan ThreadRecord, error)
}

API is the network interface for thread orchestration.

type Event

type Event interface {
	format.Node

	// HeaderID returns the cid of the event header.
	HeaderID() cid.Cid

	// GetHeader loads and optionally decrypts the event header.
	// If no key is given, the header time and key methods will return an error.
	GetHeader(context.Context, format.DAGService, crypto.DecryptionKey) (EventHeader, error)

	// BodyID returns the cid of the event body.
	BodyID() cid.Cid

	// GetBody loads and optionally decrypts the event body.
	GetBody(context.Context, format.DAGService, crypto.DecryptionKey) (format.Node, error)
}

Event is the Block format used by threads

type EventHeader

type EventHeader interface {
	format.Node

	// Time returns the wall-clock time at which this event was created.
	Time() (*time.Time, error)

	// Key returns a single-use decryption key for the event body.
	Key() (crypto.DecryptionKey, error)
}

EventHeader is the format of the event's header object

type KeyOption

type KeyOption func(*KeyOptions)

KeyOption specifies encryption keys.

func LogKey

func LogKey(key crypto.Key) KeyOption

LogKey defines the public or private key used to write a log records. If this is just a public key, the service itself won't be able to create records. In other words, all records must pre-created and added with AddRecord. If no log key is provided, one will be created internally.

func ThreadKey

func ThreadKey(key thread.Key) KeyOption

ThreadKey handles log encryption.

type KeyOptions

type KeyOptions struct {
	ThreadKey thread.Key
	LogKey    crypto.Key
}

KeyOptions defines options for keys when creating / adding a thread.

type Net

type Net interface {
	API

	// DAGService provides a DAG API to the network.
	format.DAGService

	// Host provides a network identity.
	Host() host.Host
}

Net wraps API with a DAGService and libp2p host.

type Record

type Record interface {
	format.Node

	// BlockID returns the cid of the node block.
	BlockID() cid.Cid

	// GetBlock loads the node block.
	GetBlock(context.Context, format.DAGService) (format.Node, error)

	// PrevID returns the cid of the previous node.
	PrevID() cid.Cid

	// Sig returns the node signature.
	Sig() []byte

	// Verify returns a non-nil error if the node signature is valid.
	Verify(pk crypto.PubKey) error
}

Record is the most basic component of a log.

type SubOption

type SubOption func(*SubOptions)

SubOption is a thread subscription option.

func ThreadID

func ThreadID(id thread.ID) SubOption

ThreadID restricts the subscription to the given thread. Use this option multiple times to build up a list of threads to subscribe to.

type SubOptions

type SubOptions struct {
	ThreadIDs thread.IDSlice
}

SubOptions defines options for a thread subscription.

type ThreadRecord

type ThreadRecord interface {
	// Value returns the underlying record.
	Value() Record

	// ThreadID returns the record's thread ID.
	ThreadID() thread.ID

	// LogID returns the record's log ID.
	LogID() peer.ID
}

ThreadRecord wraps Record within a thread and log context.

Jump to

Keyboard shortcuts

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