feed

package
v0.10.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

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 size is too large. maximum payload size is %d bytes", utils.MaxChunkLength)

	// ErrReadOnlyFeed is returned when a feed is read only for a user
	ErrReadOnlyFeed = fmt.Errorf("read only feed")
)
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 skipcq: TCV-001

Types

type API

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

API handles feed operations

func New

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

New create the main feed object which is used to create/update/delete feeds.

func (*API) Close added in v0.10.0

func (a *API) Close() error

func (*API) CreateFeed

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

CreateFeed creates a feed by constructing a single owner chunk. This chunk can only be accessed if the pod address is known. Also, no one else can spoof this chunk since this is signed by the pod.

func (*API) CreateFeedFromTopic added in v0.9.1

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

CreateFeedFromTopic creates a soc with the topic as identifier

func (*API) DeleteFeed

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

DeleteFeed deleted the feed by updating with no data inside the SOC chunk.

func (*API) DeleteFeedFromTopic added in v0.9.1

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

DeleteFeedFromTopic deleted the feed by updating with no data inside the SOC chunk.

func (*API) GetFeedData

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

GetFeedData looks up feed from swarm

func (*API) GetFeedDataFromTopic added in v0.9.1

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

GetFeedDataFromTopic will generate keccak256 reference of the topic+address and download soc

func (*API) GetSOCFromAddress added in v0.9.1

func (a *API) GetSOCFromAddress(address []byte) ([]byte, error)

GetSOCFromAddress will download the soc chunk for the given reference

func (*API) IsReadOnlyFeed

func (a *API) IsReadOnlyFeed() bool

IsReadOnlyFeed if a public pod is imported, the feed can only be read. this function check the feed is read only. skipcq: TCV-001

func (*API) UpdateFeed

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

UpdateFeed updates the contents of an already created feed.

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)

Size implements storage.LazySectionReader skipcq: TCV-001

func (*CacheEntry) Topic

func (r *CacheEntry) Topic() Topic

Topic returns the feed's topic skipcq: TCV-001

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 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 skipcq: TCV-001

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
}

Handler is the main object which handles all feed related functionality

func NewHandler

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

NewHandler the main handler object that handles all the feed related functions.

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) LookupEpoch added in v0.10.0

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

LookupEpoch retrieves a specific query

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 a 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 Signature

type Signature [signatureLength]byte

Signature is an alias for an 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 skipcq: TCV-001

func (*Timestamp) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaller interface skipcq: TCV-001

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