tags

package
v1.0.0-rc2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package tags provides the implementation for upload progress tracking.

Index

Constants

This section is empty.

Variables

View Source
var (
	TagUidFunc  = rand.Uint32
	ErrNotFound = errors.New("tag not found")
)

Functions

This section is empty.

Types

type State

type State = uint32

State is the enum type for chunk states

const (
	TotalChunks State = iota // The total no of chunks for the tag
	StateSplit               // chunk has been processed by filehasher/swarm safe call
	StateStored              // chunk stored locally
	StateSeen                // chunk previously seen
	StateSent                // chunk sent to neighbourhood
	StateSynced              // proof is received; chunk removed from sync db; chunk is available everywhere
)

type Tag

type Tag struct {
	Total  int64 // total chunks belonging to a tag
	Split  int64 // number of chunks already processed by splitter for hashing
	Seen   int64 // number of chunks already seen
	Stored int64 // number of chunks already stored locally
	Sent   int64 // number of chunks sent for push syncing
	Synced int64 // number of chunks synced with proof

	Uid       uint32        // a unique identifier for this tag
	Address   swarm.Address // the associated swarm hash for this tag
	StartedAt time.Time     // tag started to calculate ETA
	// contains filtered or unexported fields
}

Tag represents info on the status of new chunks

func NewTag

func NewTag(ctx context.Context, uid uint32, total int64, tracer *tracing.Tracer, stateStore storage.StateStorer, logger logging.Logger) *Tag

NewTag creates a new tag, and returns it

func (*Tag) Context

func (t *Tag) Context() context.Context

Context accessor

func (*Tag) Done

func (t *Tag) Done(s State) bool

Done returns true if tag is complete wrt the state given as argument

func (*Tag) DoneSplit

func (t *Tag) DoneSplit(address swarm.Address) (int64, error)

DoneSplit sets total count to SPLIT count and sets the associated swarm hash for this tag is meant to be called when splitter finishes for input streams of unknown size

func (*Tag) ETA

func (t *Tag) ETA(state State) (time.Time, error)

ETA returns the time of completion estimated based on time passed and rate of completion

func (*Tag) FinishRootSpan

func (t *Tag) FinishRootSpan()

FinishRootSpan closes the pushsync span of the tags

func (*Tag) Get

func (t *Tag) Get(state State) int64

Get returns the count for a state on a tag

func (*Tag) Inc

func (t *Tag) Inc(state State) error

Inc increments the count for a state

func (*Tag) IncN

func (t *Tag) IncN(state State, n int64) error

IncN increments the count for a state

func (*Tag) MarshalBinary

func (tag *Tag) MarshalBinary() (data []byte, err error)

MarshalBinary marshals the tag into a byte slice

func (*Tag) Status

func (t *Tag) Status(state State) (int64, int64, error)

Status returns the value of state and the total count

func (*Tag) TotalCounter

func (t *Tag) TotalCounter() int64

GetTotal returns the total count

func (*Tag) UnmarshalBinary

func (tag *Tag) UnmarshalBinary(buffer []byte) error

UnmarshalBinary unmarshals a byte slice into a tag

func (*Tag) WaitTillDone

func (t *Tag) WaitTillDone(ctx context.Context, s State) error

WaitTillDone returns without error once the tag is complete wrt the state given as argument it returns an error if the context is done

type Tags

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

Tags hold tag information indexed by a unique random uint32

func NewTags

func NewTags(stateStore storage.StateStorer, logger logging.Logger) *Tags

NewTags creates a tags object

func (*Tags) All

func (ts *Tags) All() (t []*Tag)

All returns all existing tags in Tags' sync.Map Note that tags are returned in no particular order

func (*Tags) Close

func (ts *Tags) Close() (err error)

Close is called when the node goes down. This is when all the tags in memory is persisted.

func (*Tags) Create

func (ts *Tags) Create(total int64) (*Tag, error)

Create creates a new tag, stores it by the UID and returns it it returns an error if the tag with this UID already exists

func (*Tags) Delete

func (ts *Tags) Delete(k interface{})

func (*Tags) Get

func (ts *Tags) Get(uid uint32) (*Tag, error)

Get returns the underlying tag for the uid or an error if not found

func (*Tags) GetByAddress

func (ts *Tags) GetByAddress(address swarm.Address) (*Tag, error)

GetByAddress returns the latest underlying tag for the address or an error if not found

func (*Tags) ListAll

func (ts *Tags) ListAll(ctx context.Context, offset, limit int) (t []*Tag, err error)

func (*Tags) MarshalJSON

func (ts *Tags) MarshalJSON() (out []byte, err error)

func (*Tags) Range

func (ts *Tags) Range(fn func(k, v interface{}) bool)

Range exposes sync.Map's iterator

func (*Tags) UnmarshalJSON

func (ts *Tags) UnmarshalJSON(value []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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