pow

package module
v0.0.0-...-83390d5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2016 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Proof Of Work

###LICENSE: BSD-3 ###Version: 1.0.0

It's based on a revers SHA512_224 function with a dynamic difficulty. New generated "POW" are saved in memeory tree using "github.com/google/btree". Challenge request contains an ID, a target, the needed difficulty and an expiration time.

Doc

As usua the documentation can be find at godoc.org.

Install

Install the package with:

go get gopkg.it/astein58/pow.v1

Server Side

Generate a challenge request:
challengeRequest, _ := powGetChallenge(2, time.Now()) // build a request with the default expiration time (5 minutes)
Verify the solution:
if !pow.Check(resp) {
	t.Fail()
}

Client Side

Resolve the challenge:
solutionResponse, _ := pow.Resolve(challengeRequest)

Documentation

Overview

Package pow is a simple "proof of work" interface.

It's based on a revers SHA512_224 function with a dynamic difficulty. New generated "POW" are saved in memeory tree using "github.com/google/btree". Challenge request contains an ID, a target, the needed difficulty and an expiration time.

The package save issued challenge requests and delete it when validate. That way the POW can't be use more than ones. Any request to the tree are piped to a channel to permit secured concurent access.

Embedded JSON generation, resolution and check for simple communication.

It is licence under "BSD 3-Clause License"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(resp *challenger.Response) bool

Check give an easy way to just check if the response. It check the resulting hash is correct and the chalenge is part of the actives challenges list.

func CheckJSON

func CheckJSON(input []byte) bool

CheckJSON do the same as check but take a slice of byte as argument. The slice must represent a challenger.Response as JSON.

func GetChallenge

func GetChallenge(difficulty uint16, expirationTime time.Time) (*request.Challenge, error)

GetChallenge return a challenge object or an error

func GetChallengeAsJSON

func GetChallengeAsJSON(difficulty uint16, expirationTime time.Time) ([]byte, error)

GetChallengeAsJSON is analog to GetChallenge Exept it returns a slice of byte representing the element as JSON

func NewResolveLimits

func NewResolveLimits(dur time.Duration, trys uint64, nbBytes int) *challenger.ResolveLimits

NewResolveLimits build a new resolver limitations

func Resolve

func Resolve(challengeRequest *request.Challenge, limits *challenger.ResolveLimits) (*challenger.Response, error)

Resolve true to resolve the challenge. It returns the solution or an error.

func ResolveAsJSON

func ResolveAsJSON(input []byte, limits *challenger.ResolveLimits) ([]byte, error)

ResolveAsJSON is analog to Resolve Exept it returns a slice of byte representing the element as JSON

Types

This section is empty.

Directories

Path Synopsis
Package common contain the common functions of the challenger and the requester.
Package common contain the common functions of the challenger and the requester.

Jump to

Keyboard shortcuts

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