Documentation ¶
Index ¶
- Constants
- Variables
- func Proximity(one, other []byte) (ret int)
- type Address
- type Chunk
- type Descriptor
- type ModeGet
- type ModePut
- type ModeSet
- type State
- type Store
- type Tag
- func (t *Tag) Context() context.Context
- func (t *Tag) Done(s State) bool
- func (t *Tag) DoneSplit(address Address) int64
- func (t *Tag) ETA(state State) (time.Time, error)
- func (t *Tag) FinishRootSpan()
- func (t *Tag) Get(state State) int64
- func (t *Tag) Inc(state State)
- func (t *Tag) IncN(state State, n int)
- func (tag *Tag) MarshalBinary() (data []byte, err error)
- func (t *Tag) Status(state State) (int64, int64, error)
- func (t *Tag) TotalCounter() int64
- func (tag *Tag) UnmarshalBinary(buffer []byte) error
- func (t *Tag) WaitTillDone(ctx context.Context, s State) error
- type Tags
- func (ts *Tags) All() (t []*Tag)
- func (ts *Tags) Create(s string, total int64, anon bool) (*Tag, error)
- func (ts *Tags) Delete(k interface{})
- func (ts *Tags) Get(uid uint32) (*Tag, error)
- func (ts *Tags) GetByAddress(address Address) (*Tag, error)
- func (ts *Tags) GetFromContext(ctx context.Context) (*Tag, error)
- func (ts *Tags) MarshalJSON() (out []byte, err error)
- func (ts *Tags) Range(fn func(k, v interface{}) bool)
- func (ts *Tags) UnmarshalJSON(value []byte) error
- type Validator
- type ValidatorStore
Constants ¶
const ( DefaultSize = 4096 MaxPO = 16 AddressLength = 32 )
Variables ¶
var ( ErrChunkNotFound = errors.New("chunk not found") ErrChunkInvalid = errors.New("invalid chunk") )
var ( TagUidFunc = rand.Uint32 TagNotFoundErr = errors.New("tag not found") )
var ZeroAddr = Address(common.Hash{}.Bytes())
Functions ¶
func Proximity ¶
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 Chunk ¶
type Descriptor ¶
Descriptor holds information required for Pull syncing. This struct is provided by subscribing to pull index.
func (*Descriptor) String ¶
func (d *Descriptor) String() string
type ModeGet ¶
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 // ModeGetPin: used when a pinned chunk is accessed ModeGetPin )
Getter modes.
type ModePut ¶
type ModePut int
ModePut enumerates different Putter modes.
type ModeSet ¶
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 // ModeSetSyncPush: when a push sync receipt is received for a chunk ModeSetSyncPush // ModeSetSyncPull: when a chunk is added to a pull sync batch ModeSetSyncPull // ModeSetRemove: when a chunk is removed ModeSetRemove // ModeSetPin: when a chunk is pinned during upload or separately ModeSetPin // ModeSetUnpin: when a chunk is unpinned using a command locally ModeSetUnpin )
Setter modes.
type Store ¶
type Store interface { Get(ctx context.Context, mode ModeGet, addr Address) (ch Chunk, err error) GetMulti(ctx context.Context, mode ModeGet, addrs ...Address) (ch []Chunk, err error) Put(ctx context.Context, mode ModePut, chs ...Chunk) (exist []bool, err error) Has(ctx context.Context, addr Address) (yes bool, err error) HasMulti(ctx context.Context, addrs ...Address) (yes []bool, err error) Set(ctx context.Context, mode ModeSet, addrs ...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 ¶
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 Anonymous bool // indicates if the tag is anonymous (i.e. if only pull sync should be used) Name string // a name tag for this tag Address 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 (*Tag) Done ¶ added in v0.5.0
Done returns true if tag is complete wrt the state given as argument
func (*Tag) DoneSplit ¶
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 ¶
ETA returns the time of completion estimated based on time passed and rate of completion
func (*Tag) FinishRootSpan ¶ added in v0.5.0
func (t *Tag) FinishRootSpan()
FinishRootSpan closes the pushsync span of the tags
func (*Tag) MarshalBinary ¶
MarshalBinary marshals the tag into a byte slice
func (*Tag) TotalCounter ¶ added in v0.5.0
GetTotal returns the total count
func (*Tag) UnmarshalBinary ¶
UnmarshalBinary unmarshals a byte slice into a tag
type Tags ¶
type Tags struct {
// contains filtered or unexported fields
}
Tags hold tag information indexed by a unique random uint32
func (*Tags) All ¶
All returns all existing tags in Tags' sync.Map Note that tags are returned in no particular order
func (*Tags) Create ¶ added in v0.5.0
Create 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) GetByAddress ¶ added in v0.5.0
GetByAddress returns the latest underlying tag for the address or an error if not found
func (*Tags) GetFromContext ¶
GetFromContext gets a tag from the tag uid stored in the context
func (*Tags) MarshalJSON ¶ added in v0.5.3
func (*Tags) UnmarshalJSON ¶ added in v0.5.3
type ValidatorStore ¶
type ValidatorStore struct { Store // contains filtered or unexported fields }
ValidatorStore encapsulates Store by decorating the Put method with validators check.
func NewValidatorStore ¶
func NewValidatorStore(store Store, validators ...Validator) (s *ValidatorStore)
NewValidatorStore returns a new ValidatorStore which uses provided validators to validate chunks on Put.