data

package
v0.0.0-...-9001059 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePrivateKey

func GeneratePrivateKey() (pk *ecdsa.PrivateKey, err error)

GeneratePrivateKey returns a new public/private key pair based on ECDSA.

func GenerateTLSCert

func GenerateTLSCert(hosts []string, privateKey *ecdsa.PrivateKey) (cert []byte, err error)

GenerateTLSCert generates a self-signed TLS certificate for the server that is valid for the given hosts. These keys should be used for testing purposes only.

func ReadCertFile

func ReadCertFile(certFile string) (cert []byte, err error)

func ReadPrivateKeyFile

func ReadPrivateKeyFile(keyFile string) (key *ecdsa.PrivateKey, err error)

ReadPrivateKeyFile reads a private key from the specified file

func ReadPublicKeyFile

func ReadPublicKeyFile(keyFile string) (key *ecdsa.PublicKey, err error)

ReadPublicKeyFile reads a public key from the specified file

func VerifyPartialCert

func VerifyPartialCert(conf *config.ReplicaConfig, cert *PartialCert) bool

VerifyPartialCert will verify a PartialCert from a public key stored in ReplicaConfig

func VerifyQuorumCert

func VerifyQuorumCert(conf *config.ReplicaConfig, qc *QuorumCert) bool

VerifyQuorumCert will verify a QuorumCert from public keys stored in ReplicaConfig

func WriteCertFile

func WriteCertFile(cert []byte, file string) (err error)

func WritePrivateKeyFile

func WritePrivateKeyFile(key *ecdsa.PrivateKey, filePath string) (err error)

WritePrivateKeyFile writes a private key to the specified file

func WritePublicKeyFile

func WritePublicKeyFile(key *ecdsa.PublicKey, filePath string) (err error)

WritePublicKeyFile writes a public key to the specified file

Types

type Block

type Block struct {
	Proposer   config.ReplicaID
	ParentHash BlockHash
	Commands   []Command
	Justify    *QuorumCert
	Height     int
	Committed  bool
	// contains filtered or unexported fields
}

Block represents a block in the tree of commands

func (Block) Hash

func (n Block) Hash() BlockHash

Hash returns a hash digest of the block.

func (Block) String

func (n Block) String() string

type BlockHash

type BlockHash [32]byte

BlockHash represents a SHA256 hashsum of a Block

func (BlockHash) String

func (h BlockHash) String() string

type BlockStorage

type BlockStorage interface {
	Put(*Block)
	Get(BlockHash) (*Block, bool)
	BlockOf(*QuorumCert) (*Block, bool)
	ParentOf(*Block) (*Block, bool)
	GarbageCollectBlocks(int)
}

BlockStorage provides a means to store a block based on its hash

type Command

type Command string

Command is the client data that is processed by HotStuff

type CommandSet

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

CommandSet is a linkedhashset for Commands

func NewCommandSet

func NewCommandSet() *CommandSet

func (*CommandSet) Add

func (s *CommandSet) Add(cmds ...Command)

Add adds cmds to the set. Duplicate entries are ignored

func (*CommandSet) Contains

func (s *CommandSet) Contains(cmd Command) bool

Contains returns true if the set contains cmd, false otherwise

func (*CommandSet) GetFirst

func (s *CommandSet) GetFirst(n int) []Command

GetFirst returns the n first non-proposed commands in the set

func (*CommandSet) IsProposed

func (s *CommandSet) IsProposed(cmd Command) bool

IsProposed will return true if the given command is marked as proposed

func (*CommandSet) Len

func (s *CommandSet) Len() int

Len returns the length of the set

func (*CommandSet) MarkProposed

func (s *CommandSet) MarkProposed(cmds ...Command)

MarkProposed will mark the given commands as proposed and move them to the back of the queue

func (*CommandSet) Remove

func (s *CommandSet) Remove(cmds ...Command)

Remove removes cmds from the set

func (*CommandSet) TrimToLen

func (s *CommandSet) TrimToLen(length int)

TrimToLen will try to remove proposed elements from the set until its length is equal to or less than 'length'

type MapStorage

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

MapStorage is a simple implementation of BlockStorage that uses a concurrent map.

func NewMapStorage

func NewMapStorage() *MapStorage

NewMapStorage returns a new instance of MapStorage

func (*MapStorage) BlockOf

func (s *MapStorage) BlockOf(qc *QuorumCert) (block *Block, ok bool)

BlockOf returns the block associated with the quorum cert

func (*MapStorage) GarbageCollectBlocks

func (s *MapStorage) GarbageCollectBlocks(currentVeiwHeigth int)

GarbageCollectBlocks dereferences old Blocks that are no longer needed

func (*MapStorage) Get

func (s *MapStorage) Get(hash BlockHash) (block *Block, ok bool)

Get gets a block from the map based on its hash.

func (*MapStorage) ParentOf

func (s *MapStorage) ParentOf(child *Block) (parent *Block, ok bool)

ParentOf returns the parent of the given Block

func (*MapStorage) Put

func (s *MapStorage) Put(block *Block)

Put inserts a block into the map

type PartialCert

type PartialCert struct {
	Sig       PartialSig
	BlockHash BlockHash
}

PartialCert is a single replica's certificate for a block.

func CreatePartialCert

func CreatePartialCert(id config.ReplicaID, privKey *ecdsa.PrivateKey, block *Block) (*PartialCert, error)

CreatePartialCert creates a partial cert from a block.

type PartialSig

type PartialSig struct {
	ID   config.ReplicaID
	R, S *big.Int
}

PartialSig is a single replica's signature of a block.

func (PartialSig) ToBytes

func (psig PartialSig) ToBytes() []byte

type QuorumCert

type QuorumCert struct {
	Sigs      map[config.ReplicaID]PartialSig
	BlockHash BlockHash
}

QuorumCert is a certificate for a block from a quorum of replicas.

func CreateQuorumCert

func CreateQuorumCert(block *Block) *QuorumCert

CreateQuorumCert creates an empty quorum certificate for a given block

func (*QuorumCert) AddPartial

func (qc *QuorumCert) AddPartial(cert *PartialCert) error

AddPartial adds the partial signature to the quorum cert.

func (*QuorumCert) String

func (qc *QuorumCert) String() string

func (*QuorumCert) ToBytes

func (qc *QuorumCert) ToBytes() []byte

type SignatureCache

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

SignatureCache keeps a cache of verified signatures in order to speed up verification

func NewSignatureCache

func NewSignatureCache(conf *config.ReplicaConfig) *SignatureCache

NewSignatureCache returns a new instance of SignatureVerifier

func (*SignatureCache) CreatePartialCert

func (s *SignatureCache) CreatePartialCert(id config.ReplicaID, privKey *ecdsa.PrivateKey, block *Block) (*PartialCert, error)

CreatePartialCert creates a partial cert from a block.

func (*SignatureCache) EvictOld

func (s *SignatureCache) EvictOld(size int)

EvictOld reduces the size of the cache by removing the oldest cached results

func (*SignatureCache) VerifyQuorumCert

func (s *SignatureCache) VerifyQuorumCert(qc *QuorumCert) bool

VerifyQuorumCert verifies a quorum certificate

func (*SignatureCache) VerifySignature

func (s *SignatureCache) VerifySignature(sig PartialSig, hash BlockHash) bool

VerifySignature verifies a partial signature

Jump to

Keyboard shortcuts

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