protocol

package
v0.0.0-...-84fcf9d Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBodySize = 256
)

Variables

View Source
var (
	ErrFailedToDecodeBody = errors.New("failed to decode body")
)

Functions

This section is empty.

Types

type ChallengeRequestBody

type ChallengeRequestBody struct{}

func (ChallengeRequestBody) Encode

func (b ChallengeRequestBody) Encode() []byte

type ChallengeResponseBody

type ChallengeResponseBody struct {
	// contains filtered or unexported fields
}

func DecodeChallengeResponseBody

func DecodeChallengeResponseBody(data []byte) (ChallengeResponseBody, error)

func (ChallengeResponseBody) Encode

func (b ChallengeResponseBody) Encode() []byte

type Challenger

type Challenger interface {
	GetDifficulty() byte
	GeneratePuzzle() []byte
	Verify(puzzle []byte, nonce []byte) bool
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(verifier Verifier) Client

func (Client) GetChallengeRequest

func (c Client) GetChallengeRequest() []byte

func (Client) HandleChallengeResponse

func (c Client) HandleChallengeResponse(rawBody []byte) ([]byte, error)

func (Client) HandleErrorResponse

func (c Client) HandleErrorResponse(rawBody []byte) error

func (Client) HandleVerifiedResponse

func (c Client) HandleVerifiedResponse(rawBody []byte) error

func (Client) IsErrorResponse

func (c Client) IsErrorResponse(rawBody []byte) bool

type Encoder

type Encoder interface {
	Encode() []byte
}

type ErrorResponseBody

type ErrorResponseBody struct {
	// contains filtered or unexported fields
}

func DecodeErrorResponseBody

func DecodeErrorResponseBody(data []byte) (ErrorResponseBody, error)

func (ErrorResponseBody) Encode

func (b ErrorResponseBody) Encode() []byte

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a simple server that handles challenge and verify requests. It uses a cache to store puzzles with a TTL. Clients must solve the puzzle within the TTL. If the puzzle is not solved within the TTL, the server will remove the puzzle from the cache and the client will have to request a new puzzle. In case of correct verification, the server will return a random wisdom.

func NewServer

func NewServer(challenge Challenger, ttl time.Duration) Server

func (Server) HandleRequest

func (s Server) HandleRequest(rawBody []byte) []byte

type VerifiedResponseBody

type VerifiedResponseBody struct {
	// contains filtered or unexported fields
}

func DecodeVerifiedResponseBody

func DecodeVerifiedResponseBody(data []byte) (VerifiedResponseBody, error)

func (VerifiedResponseBody) Encode

func (b VerifiedResponseBody) Encode() []byte

type Verifier

type Verifier interface {
	SetDifficulty(difficulty byte) error
	Solve(puzzle []byte) []byte
}

type VerifyRequestBody

type VerifyRequestBody struct {
	// contains filtered or unexported fields
}

func DecodeVerifyRequestBody

func DecodeVerifyRequestBody(data []byte) (VerifyRequestBody, error)

func (VerifyRequestBody) Encode

func (b VerifyRequestBody) Encode() []byte

Jump to

Keyboard shortcuts

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