chunk

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSize   = 4096
	MaxPO         = 16
	AddressLength = 32
)

Variables

View Source
var (
	ErrChunkNotFound = errors.New("chunk not found")
	ErrChunkInvalid  = errors.New("invalid chunk")
)
View Source
var ZeroAddr = Address(common.Hash{}.Bytes())

Functions

func Proximity added in v1.9.0

func Proximity(one, other []byte) (ret int)

Proximity returns the proximity order of the MSB distance between x and y

The distance metric MSB(x, y) of two equal length byte sequences x an y is the value of the binary integer cast of the x^y, ie., x and y bitwise xor-ed. the binary cast is big endian: most significant bit first (=MSB).

Proximity(x, y) is a discrete logarithmic scaling of the MSB distance. It is defined as the reverse rank of the integer part of the base 2 logarithm of the distance. It is calculated by counting the number of common leading zeros in the (MSB) binary representation of the x^y.

(0 farthest, 255 closest, 256 self)

Types

type Address added in v1.9.0

type Address []byte

func (Address) Hex added in v1.9.0

func (a Address) Hex() string

func (Address) Log added in v1.9.0

func (a Address) Log() string

func (Address) MarshalJSON added in v1.9.0

func (a Address) MarshalJSON() (out []byte, err error)

func (Address) String added in v1.9.0

func (a Address) String() string

func (*Address) UnmarshalJSON added in v1.9.0

func (a *Address) UnmarshalJSON(value []byte) error

type Chunk added in v1.9.0

type Chunk interface {
	Address() Address
	Data() []byte
}

func NewChunk added in v1.9.0

func NewChunk(addr Address, data []byte) Chunk

type Descriptor added in v1.9.0

type Descriptor struct {
	Address Address
	BinID   uint64
}

Descriptor holds information required for Pull syncing. This struct is provided by subscribing to pull index.

func (*Descriptor) String added in v1.9.0

func (d *Descriptor) String() string

type ModeGet added in v1.9.0

type ModeGet int

ModeGet enumerates different Getter modes.

const (
	// ModeGetRequest: when accessed for retrieval
	ModeGetRequest ModeGet = iota
	// ModeGetSync: when accessed for syncing or proof of custody request
	ModeGetSync
	// ModeGetLookup: when accessed to lookup a a chunk in feeds or other places
	ModeGetLookup
)

Getter modes.

func (ModeGet) String added in v1.9.0

func (m ModeGet) String() string

type ModePut added in v1.9.0

type ModePut int

ModePut enumerates different Putter modes.

const (
	// ModePutRequest: when a chunk is received as a result of retrieve request and delivery
	ModePutRequest ModePut = iota
	// ModePutSync: when a chunk is received via syncing
	ModePutSync
	// ModePutUpload: when a chunk is created by local upload
	ModePutUpload
)

Putter modes.

func (ModePut) String added in v1.9.0

func (m ModePut) String() string

type ModeSet added in v1.9.0

type ModeSet int

ModeSet enumerates different Setter modes.

const (
	// ModeSetAccess: when an update request is received for a chunk or chunk is retrieved for delivery
	ModeSetAccess ModeSet = iota
	// ModeSetSync: when a chunk is added to a pull sync batch or when a push sync receipt is received
	ModeSetSync
	// ModeSetRemove: when a chunk is removed
	ModeSetRemove
)

Setter modes.

func (ModeSet) String added in v1.9.0

func (m ModeSet) String() string

type State added in v1.9.0

type State = uint32

State is the enum type for chunk states

const (
	StateSplit  State = iota // 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 Store added in v1.9.0

type Store interface {
	Get(ctx context.Context, mode ModeGet, addr Address) (ch Chunk, err error)
	Put(ctx context.Context, mode ModePut, ch Chunk) (exists bool, err error)
	Has(ctx context.Context, addr Address) (yes bool, err error)
	Set(ctx context.Context, mode ModeSet, addr Address) (err error)
	LastPullSubscriptionBinID(bin uint8) (id uint64, err error)
	SubscribePull(ctx context.Context, bin uint8, since, until uint64) (c <-chan Descriptor, stop func())
	Close() (err error)
}

type Tag added in v1.9.0

type Tag struct {
	Uid     uint32  // a unique identifier for this tag
	Name    string  // a name tag for this tag
	Address Address // the associated swarm hash for this tag
	// contains filtered or unexported fields
}

Tag represents info on the status of new chunks

func NewTag added in v1.9.0

func NewTag(uid uint32, s string, total int64) *Tag

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

func (*Tag) DoneSplit added in v1.9.0

func (t *Tag) DoneSplit(address Address) int64

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 added in v1.9.0

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) Get added in v1.9.0

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

Get returns the count for a state on a tag

func (*Tag) Inc added in v1.9.0

func (t *Tag) Inc(state State)

Inc increments the count for a state

func (*Tag) MarshalBinary added in v1.9.0

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

MarshalBinary marshals the tag into a byte slice

func (*Tag) Status added in v1.9.0

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

Status returns the value of state and the total count

func (*Tag) Total added in v1.9.0

func (t *Tag) Total() int64

GetTotal returns the total count

func (*Tag) UnmarshalBinary added in v1.9.0

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

UnmarshalBinary unmarshals a byte slice into a tag

type Tags added in v1.9.0

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

Tags hold tag information indexed by a unique random uint32

func NewTags added in v1.9.0

func NewTags() *Tags

NewTags creates a tags object

func (*Tags) All added in v1.9.0

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) Delete added in v1.9.0

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

func (*Tags) Get added in v1.9.0

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

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

func (*Tags) GetFromContext added in v1.9.0

func (ts *Tags) GetFromContext(ctx context.Context) (*Tag, error)

GetFromContext gets a tag from the tag uid stored in the context

func (*Tags) New added in v1.9.0

func (ts *Tags) New(s string, total int64) (*Tag, error)

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

func (*Tags) Range added in v1.9.0

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

Range exposes sync.Map's iterator

type Validator added in v1.9.0

type Validator interface {
	Validate(ch Chunk) bool
}

Validator validates a chunk.

type ValidatorStore added in v1.9.0

type ValidatorStore struct {
	Store
	// contains filtered or unexported fields
}

ValidatorStore encapsulates Store by decorting the Put method with validators check.

func NewValidatorStore added in v1.9.0

func NewValidatorStore(store Store, validators ...Validator) (s *ValidatorStore)

NewValidatorStore returns a new ValidatorStore which uses provided validators to validate chunks on Put.

func (*ValidatorStore) Put added in v1.9.0

func (s *ValidatorStore) Put(ctx context.Context, mode ModePut, ch Chunk) (exists bool, err error)

Put overrides Store put method with validators check. If one of the validators return true, the chunk is considered valid and Store Put method is called. If all validators return false, ErrChunkInvalid is returned.

Jump to

Keyboard shortcuts

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