Documentation ¶
Index ¶
- Variables
- func BuildExportDump(root, data []byte, typ models.Census_Type, maxLevels int) ([]byte, error)
- type CensusDB
- func (c *CensusDB) Del(censusID []byte) error
- func (c *CensusDB) Exists(censusID []byte) bool
- func (c *CensusDB) ExportCensusDB(buffer io.Writer) error
- func (c *CensusDB) ImportCensusDB(buffer io.Reader) error
- func (c *CensusDB) ImportTree(censusID, data []byte) error
- func (c *CensusDB) ImportTreeAsPublic(data []byte) error
- func (c *CensusDB) List() ([]*CensusList, error)
- func (c *CensusDB) Load(censusID []byte, authToken *uuid.UUID) (*CensusRef, error)
- func (c *CensusDB) New(censusID []byte, censusType models.Census_Type, uri string, ...) (*CensusRef, error)
- func (c *CensusDB) UnLoad()
- type CensusDump
- type CensusList
- type CensusRef
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCensusNotFound is returned when a census is not found in the database. ErrCensusNotFound = fmt.Errorf("census not found in the local database") // ErrCensusAlreadyExists is returned by New() if the census already exists in the database. ErrCensusAlreadyExists = fmt.Errorf("census already exists in the local database") // ErrWrongAuthenticationToken is returned when the authentication token is invalid. ErrWrongAuthenticationToken = fmt.Errorf("wrong authentication token") // ErrCensusIsLocked is returned if the census does not allow write operations. ErrCensusIsLocked = fmt.Errorf("census is locked") )
Functions ¶
func BuildExportDump ¶
BuildExportDump builds a census serialization that can be used for import.
Types ¶
type CensusDB ¶
CensusDB is a safe and persistent database of census trees. It allows authentication control over the census if a UUID token is provided.
func NewCensusDB ¶
NewCensusDB creates a new CensusDB object.
func (*CensusDB) ExportCensusDB ¶ added in v1.10.0
ExportCensusDB will create a memory buffer, iterate over all the censuses in the database, load each one, create a dump of its data, and finally write this information into a JSON array inside the buffer.
func (*CensusDB) ImportCensusDB ¶ added in v1.10.0
ImportCensusDB takes a buffer with JSON data (as created by DumpCensusDB), decodes it, and imports the data back into the database, effectively restoring the censuses.
func (*CensusDB) ImportTree ¶ added in v1.10.1
ImportTree imports a census from a dump.
func (*CensusDB) ImportTreeAsPublic ¶ added in v1.10.0
ImportTreeAsPublic imports a census from a dump and makes it public.
func (*CensusDB) List ¶ added in v1.10.0
func (c *CensusDB) List() ([]*CensusList, error)
List returns the list of all the censuses in the database. It returns the references, not the tree data.
func (*CensusDB) Load ¶
Load returns an already loaded census from memory or from the persistent kv database. Authentication is checked if authToken is not nil. UnLoad must be called after Load to release the lock.
type CensusDump ¶
type CensusDump struct { Type models.Census_Type `json:"type"` RootHash types.HexBytes `json:"rootHash"` Data []byte `json:"data"` // MaxLevels is required to load the census with the original size because // it could be different according to the election (and census) type. MaxLevels int `json:"maxLevels"` CensusID types.HexBytes `json:"censusID,omitempty"` Token *uuid.UUID `json:"token,omitempty"` Size uint64 `json:"size,omitempty"` URI string `json:"uri,omitempty"` }
CensusDump is a struct that contains the data of a census. It is used for import/export operations.
type CensusList ¶ added in v1.10.0
type CensusList struct { CensusID types.HexBytes `json:"censusID"` URI string `json:"uri"` AuthToken *uuid.UUID `json:"token"` Root types.HexBytes `json:"root"` Size uint64 `json:"size"` }
CensusList is a struct that contains the summary of a census
type CensusRef ¶
type CensusRef struct { AuthToken *uuid.UUID CensusType int32 URI string // MaxLevels is required to load the census with the original size because // it could be different according to the election (and census) type. MaxLevels int // contains filtered or unexported fields }
CensusRef is a reference to a census. It holds the merkle tree which can be acceded by calling Tree().
func (*CensusRef) SetTree ¶
func (cr *CensusRef) SetTree(tree *censustree.Tree)
SetTree sets the censustree.Tree object to the census reference.
func (*CensusRef) Tree ¶
func (cr *CensusRef) Tree() *censustree.Tree
Tree returns the censustree.Tree object of the census reference.