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) DoneSplit(address Address) int64
- func (t *Tag) ETA(state State) (time.Time, error)
- func (t *Tag) Get(state State) int64
- func (t *Tag) Inc(state State)
- func (tag *Tag) MarshalBinary() (data []byte, err error)
- func (t *Tag) Status(state State) (int64, int64, error)
- func (t *Tag) Total() int64
- func (tag *Tag) UnmarshalBinary(buffer []byte) error
- type Tags
- 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 ZeroAddr = Address(common.Hash{}.Bytes())
Functions ¶
func Proximity ¶ added in v1.9.0
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) MarshalJSON ¶ added in v1.9.0
func (*Address) UnmarshalJSON ¶ added in v1.9.0
type Descriptor ¶ added in v1.9.0
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.
type ModePut ¶ added in v1.9.0
type ModePut int
ModePut enumerates different Putter modes.
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.
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
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
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
ETA returns the time of completion estimated based on time passed and rate of completion
func (*Tag) MarshalBinary ¶ added in v1.9.0
MarshalBinary marshals the tag into a byte slice
func (*Tag) UnmarshalBinary ¶ added in v1.9.0
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 (*Tags) All ¶ added in v1.9.0
All returns all existing tags in Tags' sync.Map Note that tags are returned in no particular order
func (*Tags) Get ¶ added in v1.9.0
Get returns the undelying tag for the uid or an error if not found
func (*Tags) GetFromContext ¶ added in v1.9.0
GetFromContext gets a tag from the tag uid stored in the context
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.