feed

package
v0.0.0-...-6333696 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInit = iota
	ErrNotFound
	ErrIO
	ErrUnauthorized
	ErrInvalidValue
	ErrDataOverflow
	ErrNothingToReturn
	ErrCorruptData
	ErrInvalidSignature
	ErrNotSynced
	ErrPeriodDepth
	ErrCnt
)
View Source
const TopicLength = 32

TopicLength establishes the max length of a topic string

Variables

View Source
var (
	// ErrInvalidTopicSize is returned when a topic is not equal to TopicLength
	ErrInvalidTopicSize = fmt.Errorf("Topic is not equal to %d", TopicLength)

	// ErrInvalidPayloadSize is returned when the payload is greater than the chunk size
	ErrInvalidPayloadSize = fmt.Errorf("payload is greater than %d", utils.MaxChunkLength)
)
View Source
var TimestampProvider timestampProvider = NewDefaultTimestampProvider()

TimestampProvider sets the time source of the feeds package

Functions

func NewError

func NewError(code int, s string) error

NewError creates a new Swarm feeds Error object with the specified code and custom error message

func NewErrorf

func NewErrorf(code int, format string, args ...interface{}) error

NewErrorf is a convenience version of NewError that incorporates printf-style formatting

Types

type API

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

func New

func New(accountInfo *account.AccountInfo, client blockstore.Client, logger logging.Logger) *API

func (*API) CreateFeed

func (a *API) CreateFeed(topic []byte, user utils.Address, data []byte) ([]byte, error)

create feed

func (*API) GetFeedData

func (a *API) GetFeedData(topic []byte, user utils.Address) ([]byte, []byte, error)

func (*API) UpdateFeed

func (a *API) UpdateFeed(topic []byte, user utils.Address, data []byte) ([]byte, error)

type CacheEntry

type CacheEntry struct {
	Update
	*bytes.Reader
	// contains filtered or unexported fields
}

CacheEntry caches the last known update of a specific Swarm feed.

func (*CacheEntry) Size

func (r *CacheEntry) Size(ctx context.Context, _ chan bool) (int64, error)

implements storage.LazySectionReader

func (*CacheEntry) Topic

func (r *CacheEntry) Topic() Topic

returns the feed's topic

type DefaultTimestampProvider

type DefaultTimestampProvider struct {
}

DefaultTimestampProvider is a TimestampProvider that uses system time as time source

func NewDefaultTimestampProvider

func NewDefaultTimestampProvider() *DefaultTimestampProvider

NewDefaultTimestampProvider creates a system clock based timestamp provider

func (*DefaultTimestampProvider) Now

Now returns the current time according to this provider

type Error

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

Error is a the typed error object used for Swarm feeds

func (*Error) Code

func (e *Error) Code() int

Code returns the error code Error codes are enumerated in the error.go file within the feeds package

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

type Feed

type Feed struct {
	Topic Topic         `json:"topic"`
	User  utils.Address `json:"user"`
}

Feed represents a particular user's stream of updates on a topic

type Handler

type Handler struct {
	HashSize int
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(accountInfo *account.AccountInfo, client blockstore.Client, hasherPool *bmtlegacy.TreePool) *Handler

func (*Handler) GetContent

func (h *Handler) GetContent(feed *Feed) (swarm.Address, []byte, error)

GetContent retrieves the data payload of the last synced update of the feed

func (*Handler) Lookup

func (h *Handler) Lookup(ctx context.Context, query *Query) (*CacheEntry, error)

Lookup retrieves a specific or latest feed update Lookup works differently depending on the configuration of `query` See the `query` documentation and helper functions: `NewQueryLatest` and `NewQuery`

func (*Handler) NewRequest

func (h *Handler) NewRequest(ctx context.Context, feed *Feed) (request *Request, err error)

NewRequest prepares a Request structure with all the necessary information to just add the desired data and sign it. The resulting structure can then be signed and passed to Handler.Update to be verified and sent

type ID

type ID struct {
	Feed         `json:"feed"`
	lookup.Epoch `json:"epoch"`
}

ID uniquely identifies an update on the network.

type Query

type Query struct {
	Feed
	Hint      lookup.Epoch
	TimeLimit uint64
}

Query is used to specify constraints when performing an update lookup TimeLimit indicates an upper bound for the search. Set to 0 for "now"

func NewQuery

func NewQuery(feed *Feed, time uint64, hint lookup.Epoch) *Query

NewQuery constructs an Query structure to find updates on or before `time` if time == 0, the latest update will be looked up

func NewQueryLatest

func NewQueryLatest(feed *Feed, hint lookup.Epoch) *Query

NewQueryLatest generates lookup parameters that look for the latest update to a feed

type Request

type Request struct {
	ID

	Signature *Signature // Signature of the payload
	// contains filtered or unexported fields
}

type Signature

type Signature [signatureLength]byte

Signature is an alias for a assets byte array with the size of a signature

type Timestamp

type Timestamp struct {
	Time uint64 `json:"time"` // Unix epoch timestamp, in seconds
}

Timestamp encodes a point in time as a Unix epoch

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface

type Topic

type Topic [TopicLength]byte

Topic represents what a feed is about

type Update

type Update struct {
	ID // Feed Update identifying information
	// contains filtered or unexported fields
}

Update encapsulates the information sent as part of a feed update

Directories

Path Synopsis
Package lookup defines feed lookup algorithms and provides tools to place updates so they can be found
Package lookup defines feed lookup algorithms and provides tools to place updates so they can be found

Jump to

Keyboard shortcuts

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