persistence

package
v0.0.0-...-be30394 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotImplementedError = errors.New("Function not implemented")

Functions

This section is empty.

Types

type Database

type Database interface {
	DoesTorrentExist(infoHash []byte) (bool, error)
	AddNewTorrent(infoHash []byte, name string, files []File) error
	Close() error

	// GetNumberOfTorrents returns the number of torrents saved in the database. Might be an
	// approximation.
	GetNumberOfTorrents() (int64, error)

	// QueryTorrents returns @pageSize amount of torrents,
	// * that are discovered before @discoveredOnBefore
	// * that match the @query if it's not empty, else all torrents
	// * ordered by the @orderBy in ascending order if @ascending is true, else in descending order
	// after skipping (@page * @pageSize) torrents that also fits the criteria above.
	//
	// On error, returns (nil, error), otherwise a non-nil slice of TorrentMetadata and nil.
	QueryTorrents(
		query string,
		ascending bool,
		orderBy OrderingCriteria,
		limit uint,
		lastID *uint64,
		lastOrderedValue *float64,
		epoch int64,
	) ([]TorrentMetadata, error)

	GetTorrent(infoHash []byte) (*TorrentMetadata, error)

	GetFiles(infoHash []byte) ([]File, error)

	GetStatistics(from string, n uint) (*Statistics, error)
}

func MakeDatabase

func MakeDatabase() (Database, error)

type File

type File struct {
	Size int64  `json:"size"`
	Path string `json:"path"`
}

type OrderingCriteria

type OrderingCriteria uint8
const (
	ByRelevance OrderingCriteria = iota
	ByTotalSize
	ByDiscoveredOn
	ByNFiles
	ByNSeeders
	ByNLeechers
	ByUpdatedOn
)

type SimpleTorrentSummary

type SimpleTorrentSummary struct {
	InfoHash string `json:"infoHash"`
	Name     string `json:"name"`
	Files    []File `json:"files"`
}

type Statistics

type Statistics struct {
	NDiscovered map[string]uint64 `json:"nDiscovered"`
	NFiles      map[string]uint64 `json:"nFiles"`
	TotalSize   map[string]uint64 `json:"totalSize"`
}

func NewStatistics

func NewStatistics() (s *Statistics)

type TorrentMetadata

type TorrentMetadata struct {
	ID           uint64  `json:"id"`
	InfoHash     []byte  `json:"infoHash"` // marshalled differently
	Name         string  `json:"name"`
	Size         uint64  `json:"size"`
	DiscoveredOn int64   `json:"discoveredOn"`
	NFiles       uint    `json:"nFiles"`
	Relevance    float64 `json:"relevance"`
}

func (*TorrentMetadata) MarshalJSON

func (tm *TorrentMetadata) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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