libMonkey

package
v0.0.0-...-2818dea Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2015 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonPrefixLength

func CommonPrefixLength(a, b InfoHash) int

CommonPrefixLenght compares to InfoHashes bitwise and finds the length of the bit-prefix both have in common.

Types

type InfoHash

type InfoHash [32]byte

InfoHash is the representation of an identifier in the MonkeyNet. As such, it is initialized once and does not change afterwards.

An InfoHash is a 256bit data structure that is obtained by reading from a byte slice or by generating a new random InfoHash. It is intended to be generated by applying a hash function to a key in the distributed hash table.

func NewRandom

func NewRandom() (InfoHash, error)

NewRandom generates an InfoHash through crypto/rand. If an error occurs during reading from the crypto/rand device, an empty InfoHash is returned with the error that reading from the crypto/rand device produced.

func (*InfoHash) Empty

func (i *InfoHash) Empty() bool

Empty checks if an InfoHash was already initialised. If there are only bx00000000 bytes in the InfoHash, it is assumed uninitialised. An empty value therefore is an illegal identifier

func (InfoHash) GoString

func (i InfoHash) GoString() string

Implementation of the GoStringer interface

func (InfoHash) String

func (i InfoHash) String() string

Implementation of the Stringer interface. All hashes are written as their base64-encoded content

func (*InfoHash) Write

func (i *InfoHash) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. If the InfoHash object is already initialised, 0 is returned with an error message.

The InfoHash object is shifting bytes in from right to left, preserving the 0 prefix on the left.

func (InfoHash) Xor

func (i InfoHash) Xor(another InfoHash) InfoHash

Xor is a function that xors two InfoHashes. This is needed for Kademlias XOR metric. The result is a new InfoHash

Jump to

Keyboard shortcuts

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