Documentation ¶
Overview ¶
Package swarm contains most basic and general Swarm concepts.
Index ¶
Constants ¶
const ( SpanSize = 8 SectionSize = 32 Branches = 128 BmtBranches = 128 ChunkSize = SectionSize * Branches HashSize = 32 MaxPO uint8 = 15 MaxBins = MaxPO + 1 ChunkWithSpanSize = ChunkSize + SpanSize )
Variables ¶
var (
ErrInvalidChunk = errors.New("invalid chunk")
)
var (
NewHasher = sha3.NewLegacyKeccak256
)
var ZeroAddress = NewAddress(nil)
ZeroAddress is the address that has no value.
Functions ¶
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 specfication. 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 specfication. Fails if not all addresses are of equal length.
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 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 ParseHexAddress ¶
ParseHexAddress returns an Address from a hex-encoded string representation.
func (Address) ByteString ¶
ByteString returns raw Address string without encoding.
func (Address) MarshalJSON ¶
MarshalJSON returns JSON-encoded representation of Address.
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. By returning a true for stop variable, iteration should stop.