Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilFilename is returned when the fileame to construct a new file is nil. ErrNilFilename = errors.New("filename to construct file must not be nil") // ErrNilShardCount is returned when the shard counnt to cosntruct a new file is nil. ErrNilShardCount = errors.New("shard count to cosntruct file must not be nil") // ErrNilFileSize is returned when the file size to construct a new file is nil. ErrNilFileSize = errors.New("file size to construct file must not be nil") )
var ( // ErrInvalidIP is an error thrown when the ip to construct a NodeID is invalid. ErrInvalidIP = errors.New("IP address to construct a NodeID is invalid") // ErrInvalidPort is an error thrown when the port to construct a NodeID is invalid. ErrInvalidPort = errors.New("port to construct a NodeID is invalid") )
var ( // ErrNilBytes is thrown when a shard is constructed when given nil bytes. ErrNilBytes = errors.New("bytes to construct new shard must not be nil") // ErrCannotCalculateShardSizes is thrown when the []byte to a CalculateShardSizes call is nil. ErrCannotCalculateShardSizes = errors.New("bytes to calculate shard sizes must not be nil") )
var ErrInvalidShard = errors.New("shard from memory is not valid")
ErrInvalidShard is returned when a shard's hash is not valid when loading from memory.
var ErrNilDBLabel = errors.New("label for creating a shard database header must not be nil")
errNilDBLabel is returned when a nil label is given.
Functions ¶
This section is empty.
Types ¶
type DatabaseHeader ¶
type DatabaseHeader struct {
Label string `json:"label"` // A database label
Created string `json:"created"` // The time that the database was created
Hash crypto.Hash `json:"hash"` // The hash of the database header
}
DatabaseHeader is the identifier for a database.
func NewDatabaseHeader ¶
func NewDatabaseHeader(label string) DatabaseHeader
NewDatabaseHeader creates a new database header.
func (DatabaseHeader) Bytes ¶
func (databaseHeader DatabaseHeader) Bytes() []byte
Bytes converts the database header to bytes.
func (DatabaseHeader) String ¶
func (databaseHeader DatabaseHeader) String() string
String converts the database to a string.
type File ¶
type File struct {
Filename string `json:"filename"` // The file's filename
ShardCount int `json:"shard_count"` // The number of shards hosting the file
Size uint32 `json:"size"` // Total size of the file
ShardDB *shardDB `json:"shard_db"` // Pointer to this file's shardDb
Hash crypto.Hash `json:"hash"` // The hash of the file
}
File contains the (important) metadata of a file stored in a database.
func FileFromBytes ¶
FileFromBytes constructs a *File from a []byte.
type NodeID ¶
type NodeID struct {
IP string `json:"ip"` // The node's IP address
Port int `json:"port"` // The port on which the node is hosted
Hash *crypto.Hash `json:"hash"` // The hash of the node
}
NodeID contains the necessary data for referencing and connecting to a node.
type Shard ¶
type Shard struct {
Size uint32 `json:"size"` // The size of the shard
Bytes []byte `json:"bytes"` // The actual data of the shard
Hash crypto.Hash `json:"hash"` // The hash of the shard
Timestamp string `json:"timestamp"` // The timestamp of the shard
}
Shard is a struct that holds a piece of data that is a part of another, bigger piece of data.
func GenerateShards ¶
GenerateShards generates a slice of shards given a string of bytes This is an interface/api function.
func ReadShardFromMemory ¶
ReadShardFromMemory reads a shard from memory.
func ShardFromBytes ¶
ShardFromBytes constructs a *Shard from bytes.
func (*Shard) WriteShardToMemory ¶
WriteShardToMemory writes a shard to memory.