censusdb

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: AGPL-3.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func BuildExportDump(root, data []byte, typ models.Census_Type, maxLevels int) ([]byte, error)

BuildExportDump builds a census serialization that can be used for import.

Types

type CensusDB

type CensusDB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func NewCensusDB(db db.Database) *CensusDB

NewCensusDB creates a new CensusDB object.

func (*CensusDB) Del

func (c *CensusDB) Del(censusID []byte) error

Del removes a census from the database and memory.

func (*CensusDB) Exists

func (c *CensusDB) Exists(censusID []byte) bool

Exists returns true if the censusID exists in the local database.

func (*CensusDB) ExportCensusDB added in v1.10.0

func (c *CensusDB) ExportCensusDB(buffer io.Writer) error

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

func (c *CensusDB) ImportCensusDB(buffer io.Reader) error

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

func (c *CensusDB) ImportTree(censusID, data []byte) error

ImportTree imports a census from a dump.

func (*CensusDB) ImportTreeAsPublic added in v1.10.0

func (c *CensusDB) ImportTreeAsPublic(data []byte) error

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

func (c *CensusDB) Load(censusID []byte, authToken *uuid.UUID) (*CensusRef, error)

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.

func (*CensusDB) New

func (c *CensusDB) New(censusID []byte, censusType models.Census_Type,
	uri string, authToken *uuid.UUID, maxLevels int) (*CensusRef, error)

New creates a new census and adds it to the database.

func (*CensusDB) UnLoad added in v1.10.0

func (c *CensusDB) UnLoad()

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.

Jump to

Keyboard shortcuts

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