Documentation ¶
Index ¶
Constants ¶
const ( // HashLength is the length in bytes of the hash prefix in any message HashLength = len(Hash{}) // PayloadLength is the length of the remaining bytes of the message. PayloadLength = len(Payload{}) // NeedleLength is the number of bytes required for a valid needle. NeedleLength = HashLength + PayloadLength // ErrorDNE is returned when a key/value par does not exist ErrorDNE = errors.Error("Does Not Exist") // ErrorInvalidHash is an error for in invalid hash ErrorInvalidHash = errors.Error("invalid blake2b-256 hash") // ErrorByteSliceLength is an error for an invalid byte slice length passed in to New or FromBytes ErrorByteSliceLength = errors.Error("invalid byte slice length") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Needle ¶
type Needle struct {
// contains filtered or unexported fields
}
Needle is an immutable container for a [192]byte array that containers a 160 byte payload and a 32 byte blake2b hash of the payload.
func FromBytes ¶
FromBytes is intended convert raw bytes (from UDP or storage) into a Needle. It takes a byte slice and expects it to be exactly the length of NeedleLength. The byte slice should consist of the first 32 bytes being the blake2b hash of the payload and the payload bytes. This function verifies the length of the byte slice, copies the bytes into a private [192]byte array, and validates the Needle. It returns a reference to a Needle and an error.
func New ¶
New creates a Needle used for submitting a payload to a Haystack sever. It takes a Payload byte slice that is 160 bytes in length and returns a reference to a Needle and an error. The purpose of this function is to make it easy to create a new Needle from a payload. This function handles creating a blake2b hash of the payload, which is used by the Needle to submit to a haystack server.