types

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
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")
)
View Source
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.

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

func FileFromBytes(b []byte) (*File, error)

FileFromBytes constructs a *File from a []byte.

func NewFile

func NewFile(filename string) (*File, error)

NewFile constructs a new file from a file in memory.

func (*File) Bytes

func (file *File) Bytes() []byte

Bytes converts the database header to bytes.

func (*File) String

func (file *File) String() string

String converts the database to a string.

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.

func NewNodeID

func NewNodeID(ip string, port int) (*NodeID, error)

NewNodeID constructs a new NodeID.

func (*NodeID) Bytes

func (nodeID *NodeID) Bytes() []byte

Bytes returns the bytes of a NodeID.

func (*NodeID) String

func (nodeID *NodeID) String() string

String converts the NodeID to a string.

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

func GenerateShards(bytes []byte, n int) ([]Shard, error)

GenerateShards generates a slice of shards given a string of bytes This is an interface/api function.

func NewShard

func NewShard(bytes []byte) (*Shard, error)

NewShard attempts to construct a new shard.

func ReadShardFromMemory

func ReadShardFromMemory(hash string) (*Shard, error)

ReadShardFromMemory reads a shard from memory.

func ShardFromBytes

func ShardFromBytes(b []byte) (*Shard, error)

ShardFromBytes constructs a *Shard from bytes.

func (*Shard) Serialize

func (shard *Shard) Serialize() []byte

Serialize serializes a Shard pointer to bytes.

func (*Shard) String

func (shard *Shard) String() string

func (*Shard) Validate

func (shard *Shard) Validate() bool

Validate makes sure that the shard is valid.

func (*Shard) WriteShardToMemory

func (shard *Shard) WriteShardToMemory() error

WriteShardToMemory writes a shard to memory.

Jump to

Keyboard shortcuts

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