bep44

package
v2.21.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MPL-2.0 Imports: 9 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueFieldTooBig = krpc.Error{
		Code: krpc.ErrorCodeMessageValueFieldTooBig,
		Msg:  "message (v field) too big",
	}
	ErrInvalidSignature = krpc.Error{
		Code: krpc.ErrorCodeInvalidSignature,
		Msg:  "invalid signature",
	}

	ErrSaltFieldTooBig = krpc.Error{
		Code: krpc.ErrorCodeSaltFieldTooBig,
		Msg:  "salt (salt field) too big",
	}
	ErrCasHashMismatched = krpc.Error{
		Code: krpc.ErrorCodeCasHashMismatched,
		Msg:  "the CAS hash mismatched, re-read value and try again",
	}
	ErrSequenceNumberLessThanCurrent = krpc.Error{
		Code: krpc.ErrorCodeSequenceNumberLessThanCurrent,
		Msg:  "sequence number less than current",
	}
)
View Source
var Empty32ByteArray [32]byte
View Source
var ErrItemNotFound = errors.New("item not found")

Functions

func Check

func Check(i *Item) error

func CheckIncoming

func CheckIncoming(stored, incoming *Item) error

func Sign

func Sign(k ed25519.PrivateKey, salt []byte, seq int64, bv []byte) []byte

func Verify

func Verify(k ed25519.PublicKey, salt []byte, seq int64, bv []byte, sig []byte) bool

Types

type Item

type Item struct {

	// Value to be stored
	V interface{}

	// 32 byte ed25519 public key
	K    [32]byte
	Salt []byte
	Sig  [64]byte
	Cas  int64
	Seq  int64
	// contains filtered or unexported fields
}

func NewItem

func NewItem(value interface{}, salt []byte, seq, cas int64, k ed25519.PrivateKey) (*Item, error)

NewItem creates a new arbitrary DHT element. The distinction between storing mutable and immutable items is the inclusion of a public key, a sequence number, signature and an optional salt.

cas parameter is short for compare and swap, it has similar semantics as CAS CPU instructions. It is used to avoid race conditions when multiple nodes are writing to the same slot in the DHT. It is optional. If present it specifies the sequence number of the data blob being overwritten by the put.

salt parameter is used to make possible several targets using the same private key.

The optional seq field specifies that an item's value should only be sent if its sequence number is greater than the given value.

func (*Item) IsMutable

func (s *Item) IsMutable() bool

func (*Item) Modify

func (i *Item) Modify(value interface{}, k ed25519.PrivateKey) bool

func (*Item) Target

func (i *Item) Target() Target

func (*Item) ToPut

func (i *Item) ToPut() Put

type Memory

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

func NewMemory

func NewMemory() *Memory

func (*Memory) Del

func (m *Memory) Del(t Target) error

func (*Memory) Get

func (m *Memory) Get(t Target) (*Item, error)

func (*Memory) Put

func (m *Memory) Put(i *Item) error

type Put

type Put struct {
	V    interface{}
	K    *[32]byte
	Salt []byte
	Sig  [64]byte
	Cas  int64
	Seq  int64
}

func (*Put) IsMutable

func (s *Put) IsMutable() bool

func (*Put) Sign

func (p *Put) Sign(k ed25519.PrivateKey)

func (*Put) Target

func (i *Put) Target() Target

func (*Put) ToItem

func (p *Put) ToItem() *Item

type Store

type Store interface {
	Put(*Item) error
	Get(Target) (*Item, error)
	Del(Target) error
}

type Target

type Target = [sha1.Size]byte

func MakeMutableTarget added in v2.12.0

func MakeMutableTarget(pubKey [32]byte, salt []byte) Target

type Wrapper

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

Wrapper is in charge of validate all new items and decide when to store, or ignore them depending of the BEP 44 definition. It is also in charge of removing expired items.

func NewWrapper

func NewWrapper(s Store, exp time.Duration) *Wrapper

func (*Wrapper) Get

func (w *Wrapper) Get(t Target) (*Item, error)

func (*Wrapper) Put

func (w *Wrapper) Put(i *Item) error

Jump to

Keyboard shortcuts

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