Documentation ¶
Index ¶
- func GeneratePrivateKey() (pk *ecdsa.PrivateKey, err error)
- func GenerateTLSCert(hosts []string, privateKey *ecdsa.PrivateKey) (cert []byte, err error)
- func ReadCertFile(certFile string) (cert []byte, err error)
- func ReadPrivateKeyFile(keyFile string) (key *ecdsa.PrivateKey, err error)
- func ReadPublicKeyFile(keyFile string) (key *ecdsa.PublicKey, err error)
- func VerifyPartialCert(conf *config.ReplicaConfig, cert *PartialCert) bool
- func VerifyQuorumCert(conf *config.ReplicaConfig, qc *QuorumCert) bool
- func WriteCertFile(cert []byte, file string) (err error)
- func WritePrivateKeyFile(key *ecdsa.PrivateKey, filePath string) (err error)
- func WritePublicKeyFile(key *ecdsa.PublicKey, filePath string) (err error)
- type Block
- type BlockHash
- type BlockStorage
- type Command
- type CommandSet
- func (s *CommandSet) Add(cmds ...Command)
- func (s *CommandSet) Contains(cmd Command) bool
- func (s *CommandSet) GetFirst(n int) []Command
- func (s *CommandSet) IsProposed(cmd Command) bool
- func (s *CommandSet) Len() int
- func (s *CommandSet) MarkProposed(cmds ...Command)
- func (s *CommandSet) Remove(cmds ...Command)
- func (s *CommandSet) TrimToLen(length int)
- type MapStorage
- func (s *MapStorage) BlockOf(qc *QuorumCert) (block *Block, ok bool)
- func (s *MapStorage) GarbageCollectBlocks(currentVeiwHeigth int)
- func (s *MapStorage) Get(hash BlockHash) (block *Block, ok bool)
- func (s *MapStorage) ParentOf(child *Block) (parent *Block, ok bool)
- func (s *MapStorage) Put(block *Block)
- type PartialCert
- type PartialSig
- type QuorumCert
- type SignatureCache
- func (s *SignatureCache) CreatePartialCert(id config.ReplicaID, privKey *ecdsa.PrivateKey, block *Block) (*PartialCert, error)
- func (s *SignatureCache) EvictOld(size int)
- func (s *SignatureCache) VerifyQuorumCert(qc *QuorumCert) bool
- func (s *SignatureCache) VerifySignature(sig PartialSig, hash BlockHash) bool
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 ReadPrivateKeyFile ¶
func ReadPrivateKeyFile(keyFile string) (key *ecdsa.PrivateKey, err error)
ReadPrivateKeyFile reads a private key from the specified file
func ReadPublicKeyFile ¶
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 WritePrivateKeyFile ¶
func WritePrivateKeyFile(key *ecdsa.PrivateKey, filePath string) (err error)
WritePrivateKeyFile writes a private 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
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 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) 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.
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 ¶
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