Documentation ¶
Overview ¶
Package swarm contains most basic and general Swarm concepts.
Index ¶
- Constants
- Variables
- func ContainsAddress(addrs []Address, a Address) bool
- func ContainsChunkWithAddress(chunks []Chunk, a Address) bool
- func ContainsChunkWithData(chunks []Chunk, d []byte) bool
- func Distance(x, y Address) (*big.Int, error)
- func DistanceCmp(a, x, y Address) (int, error)
- func DistanceRaw(x, y Address) ([]byte, error)
- func ExtendedProximity(one, other []byte) (ret uint8)
- func IndexOfAddress(addrs []Address, a Address) int
- func IndexOfChunkWithAddress(chunks []Chunk, a Address) int
- func NewHasher() hash.Hash
- func NewPrefixHasher(prefix []byte) hash.Hash
- func Proximity(one, other []byte) (ret uint8)
- func RandBatchID(tb testing.TB) []byte
- type Address
- func MustParseHexAddress(s string) Address
- func NewAddress(b []byte) Address
- func ParseBitStrAddress(src string) (Address, error)
- func ParseHexAddress(s string) (a Address, err error)
- func RandAddress(tb testing.TB) Address
- func RandAddressAt(tb testing.TB, self Address, prox int) Address
- func RandAddresses(tb testing.TB, count int) []Address
- func RemoveAddress(addrs []Address, a Address) []Address
- func (a Address) ByteString() string
- func (a Address) Bytes() []byte
- func (a Address) Clone() Address
- func (x Address) Closer(a Address, y Address) (bool, error)
- func (a Address) Compare(b Address) int
- func (a Address) Equal(b Address) bool
- func (a Address) IsEmpty() bool
- func (a Address) IsValidLength() bool
- func (a Address) IsValidNonEmpty() bool
- func (a Address) IsZero() bool
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MemberOf(addrs []Address) bool
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(b []byte) (err error)
- type AddressIterFunc
- type Chunk
- type ChunkType
- type PrefixHasher
- type Stamp
Constants ¶
const ( StampIndexSize = 8 // TODO: use this size in related code. StampTimestampSize = 8 // TODO: use this size in related code. SpanSize = 8 SectionSize = 32 Branches = 128 EncryptedBranches = Branches / 2 BmtBranches = 128 ChunkSize = SectionSize * Branches HashSize = 32 MaxPO uint8 = 31 ExtendedPO uint8 = MaxPO + 5 MaxBins = MaxPO + 1 ChunkWithSpanSize = ChunkSize + SpanSize SocSignatureSize = 65 SocMinChunkSize = HashSize + SocSignatureSize + SpanSize SocMaxChunkSize = SocMinChunkSize + ChunkSize )
Variables ¶
var ( // EmptyAddress is the address that is all zeroes. EmptyAddress = NewAddress(make([]byte, HashSize)) // ZeroAddress is the address that has no value. ZeroAddress = NewAddress(nil) )
var (
ErrInvalidChunk = errors.New("invalid chunk")
)
Functions ¶
func ContainsAddress ¶ added in v1.11.0
ContainsAddress reports whether a is present in addrs.
func ContainsChunkWithAddress ¶ added in v1.11.0
ContainsChunkWithAddress reports whether Chunk with Address a is present in chunks.
func ContainsChunkWithData ¶ added in v1.13.0
ContainsChunkWithAddress reports whether Chunk with data d is present in chunks.
func Distance ¶
Distance returns the distance between address x and address y as a (comparable) big integer using the distance metric defined in the swarm specification. Fails if not all addresses are of equal length.
func DistanceCmp ¶
DistanceCmp compares x and y to a in terms of the distance metric defined in the swarm specification. it returns:
- 1 if x is closer to a than y
- 0 if x and y are equally far apart from a (this means that x and y are the same address)
- -1 if x is farther from a than y
Fails if not all addresses are of equal length.
func DistanceRaw ¶
DistanceRaw returns the distance between address x and address y in big-endian binary format using the distance metric defined in the swarm specification. Fails if not all addresses are of equal length.
func ExtendedProximity ¶ added in v0.5.3
func IndexOfAddress ¶ added in v1.11.0
IndexOfAddress returns the index of the first occurrence of a in addrs, or -1 if not present.
func IndexOfChunkWithAddress ¶ added in v1.11.0
IndexOfChunkWithAddress returns the index of the first occurrence of Chunk with Address a in chunks, or -1 if not present.
func NewPrefixHasher ¶ added in v1.18.0
NewPrefixHasher returns new hasher which is Keccak-256 hasher with prefix value added as initial data.
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)
func RandBatchID ¶ added in v1.13.0
RandBatchID generates a random BatchID.
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address represents an address in Swarm metric space of Node and Chunk addresses.
func MustParseHexAddress ¶
MustParseHexAddress returns an Address from a hex-encoded string representation, and panics if there is a parse error.
func NewAddress ¶
NewAddress constructs Address from a byte slice.
func ParseBitStrAddress ¶ added in v1.17.4
ParseBitStrAddress parses overlay addresses in binary format (eg: 111101101) to it's corresponding overlay address.
func ParseHexAddress ¶
ParseHexAddress returns an Address from a hex-encoded string representation.
func RandAddress ¶ added in v1.13.0
RandAddress generates a random address.
func RandAddressAt ¶ added in v1.13.0
RandAddressAt generates a random address at proximity order prox relative to address.
func RandAddresses ¶ added in v1.13.0
RandAddresses generates slice with a random address.
func RemoveAddress ¶ added in v1.11.0
RemoveAddress removes first occurrence of a in addrs, returning the modified slice.
func (Address) ByteString ¶
ByteString returns raw Address string without encoding.
func (Address) Clone ¶ added in v1.9.0
Clone returns a new swarm address which is a copy of this one.
func (Address) Compare ¶ added in v1.17.0
Compare returns an integer comparing two addresses lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func (Address) IsValidLength ¶ added in v1.14.0
IsValidLength returns true if the Address is of valid length.
func (Address) IsValidNonEmpty ¶ added in v1.17.0
IsValidNonEmpty returns true if the Address has valid length and is not empty.
func (Address) MarshalJSON ¶
MarshalJSON returns JSON-encoded representation of Address.
func (Address) MemberOf ¶ added in v0.5.3
MemberOf returns true if the address is a member of the provided set.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON sets Address to a value from JSON-encoded representation.
type AddressIterFunc ¶ added in v0.4.0
AddressIterFunc is a callback on every address that is found by the iterator.
type Chunk ¶
type Chunk interface { // Address returns the chunk address. Address() Address // Data returns the chunk data. Data() []byte // TagID returns the tag ID for this chunk. TagID() uint32 // WithTagID attaches the tag ID to the chunk. WithTagID(t uint32) Chunk // Stamp returns the postage stamp associated with this chunk. Stamp() Stamp // WithStamp attaches a postage stamp to the chunk. WithStamp(Stamp) Chunk // Radius is the PO above which the batch is preserved. Radius() uint8 // Depth returns the batch depth of the stamp - allowed batch size = 2^{depth}. Depth() uint8 // BucketDepth returns the bucket depth of the batch of the stamp - always < depth. BucketDepth() uint8 // Immutable returns whether the batch is immutable Immutable() bool // WithBatch attaches batch parameters to the chunk. WithBatch(radius, depth, bucketDepth uint8, immutable bool) Chunk // Equal checks if the chunk is equal to another. Equal(Chunk) bool }
type ChunkType ¶ added in v1.17.0
type ChunkType uint8
ChunkType indicates different categories of chunks.
type PrefixHasher ¶ added in v1.18.0
func (*PrefixHasher) Reset ¶ added in v1.18.0
func (h *PrefixHasher) Reset()