pow

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: ISC Imports: 6 Imported by: 41

Documentation

Overview

Package pow implements proof-of-work and its checking mechanism. More details for PoW for Bitmessage can be found at:

https://bitmessage.org/wiki/Proof_of_work

Index

Constants

View Source
const (
	// DefaultNonceTrialsPerByte is the amount of work that should be performed
	// (and demanded) per byte of the payload.
	DefaultNonceTrialsPerByte = 1000
	// DefaultExtraBytes is added to the payload length to make sending short
	// messages a little more difficult.
	DefaultExtraBytes = 1000
)

If changed, these values will cause particularly unexpected behavior: You won't be able to either send or receive messages because the proof of work you do (or demand) won't match that done or demanded by others. Don't change them!

Variables

View Source
var Default = Data{
	NonceTrialsPerByte: DefaultNonceTrialsPerByte,
	ExtraBytes:         DefaultExtraBytes,
}

Default puts the default values together in one Data struct.

Functions

func Check

func Check(target Target, nonce Nonce, message []byte) bool

Check whether the given message and nonce satisfy the given pow target.

Types

type Data

type Data struct {
	NonceTrialsPerByte uint64
	ExtraBytes         uint64
}

Data contains parameters affecting the difficulty required by a particular public key.

func (*Data) Decode

func (pd *Data) Decode(r io.Reader) (err error)

Decode reads a pow.Data from a reader.

func (*Data) Encode

func (pd *Data) Encode(w io.Writer) error

Encode writes the data in pow.Data to a writer.

func (*Data) String

func (pd *Data) String() string

type Nonce

type Nonce uint64

Nonce represents a number at the head of an object message which is used for the proof of work.

func DecodeNonce

func DecodeNonce(r io.Reader) (Nonce, error)

DecodeNonce decodes a nonce from a reader.

func DoParallel

func DoParallel(target Target, initialHash []byte, parallelCount int) Nonce

DoParallel does the POW using parallelCount number of goroutines and returns the nonce value.

func DoSequential

func DoSequential(target Target, initialHash []byte) Nonce

DoSequential does the PoW sequentially and returns the nonce value.

func (Nonce) Bytes

func (n Nonce) Bytes() []byte

Bytes returns the nonce as a bite array, as specified by the Bitmessage protocol.

func (Nonce) Encode

func (n Nonce) Encode(w io.Writer) error

Encode encodes a nonce to a writer.

type Target

type Target uint64

func CalculateTarget

func CalculateTarget(payloadLength, ttl uint64, data Data) Target

CalculateTarget calculates the target POW value. payloadLength includes the full length of the payload (inluding the width of the initial nonce field). ttl is the time difference (in seconds) between ExpiresTime and time.Now(). Information about nonceTrials and extraBytes can be found at: https://bitmessage.org/wiki/Proof_of_work

Jump to

Keyboard shortcuts

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