data

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2017 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TitleMax    = 144
	TagsMax     = 256
	MaxPostSize = TitleMax + TagsMax + 1024
)
View Source
const PieceSize = 1000

Variables

This section is empty.

Functions

func IsAlnumWord

func IsAlnumWord(word string) bool

func SanitiseForAuto

func SanitiseForAuto(in string) string

Takes a string, makes it look "nice" for an autocomplete cue.

Types

type AddressResolutionError

type AddressResolutionError struct {
	Address string
}

func (AddressResolutionError) Error

func (a AddressResolutionError) Error() string

type Collection

type Collection struct {
	Pieces   []*Piece
	HashList []byte
	RootHash hash.Hash
}

A collection of pieces, by extension a structure containing all posts this peer has. Whether or not the pieces are *actually* there is optional, if not this is essentially a hash list.

func CreateCollection

func CreateCollection(db *Database, start, pieceSize int) (*Collection, error)

Takes a database, starting id, and piece size. From this we create a collection, except it does not contain any posts - consider making this optional.

func LoadCollection

func LoadCollection(path string) (col *Collection, err error)

Loads a collection from file. This essentially loads the hash list, the data of pieces themselves is just left. It's all in the database if it is really needed.

func NewCollection

func NewCollection() *Collection

Create a new collection, set all it's members to the correct default values.

func (*Collection) Add

func (c *Collection) Add(piece *Piece)

Add a piece to the collection, storing it in c.Pieces and appending it's hash to the hash list.

func (*Collection) Hash

func (c *Collection) Hash() []byte

Return the hash of the hash list, which can then go on to be signed by the LocalPeer. This allows proper validation of an entire collection, but the localpeer only needs to sign a single hash.

func (*Collection) Rehash

func (c *Collection) Rehash()

Regenerates the root hash from the hash list we have.

func (*Collection) Save

func (c *Collection) Save(path string) error

Save the collection hash list to the given path, with permissions 0777.

type Database

type Database struct {
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(path string) *Database

func (*Database) AddMeta

func (db *Database) AddMeta(pid int, value string) error

Add a metadata key/value.

func (*Database) Close

func (db *Database) Close()

Close the database connection.

func (*Database) Connect

func (db *Database) Connect() error

Connect to a database. If it does not already exist it is created, and the proper schema is also setup.

func (*Database) GenerateFts

func (db *Database) GenerateFts(since int64) error

Generate a full text search index since the given id. This should ideally be done only for new additions, otherwise on a large dataset it can take a bit of time.

func (*Database) InsertPiece

func (db *Database) InsertPiece(piece *Piece) (err error)

Inserts a piece into the database. All the posts are iterated over and inserted within a single SQL transaction.

func (*Database) InsertPieces

func (db *Database) InsertPieces(pieces chan *Piece, fts bool) (err error)

Insert pieces from a channel, good for streaming them from a network or something. The fts bool is whether or not a fts index will be generated on every transaction commit. Transactions contain 100 pieces, or 100,000 posts.

func (*Database) InsertPost

func (db *Database) InsertPost(post Post) (int64, error)

Insert a single post into the database.

func (*Database) PaginatedQuery

func (db *Database) PaginatedQuery(query string, page int) ([]*Post, error)

Performs a query upon the database where the only arguments are the page range. This is useful for thing such as popular and recent posts.

func (*Database) PostCount

func (db *Database) PostCount() uint

How many posts are in the database?

func (*Database) QueryPiece

func (db *Database) QueryPiece(id uint, store bool) (*Piece, error)

Return a single piece given it's id. Optionally store the posts as well, otherwise we just get a hash.

func (*Database) QueryPiecePosts

func (db *Database) QueryPiecePosts(start, length int, store bool) chan *Post

Very simmilar to QueryPiece, except this returns a channel and streams posts out as they arrive. Queries a range of posts, so you can ask for 100 posts starting at an id.

func (*Database) QueryPopular

func (db *Database) QueryPopular(page int) ([]*Post, error)

Returns a page of posts ordered by popularity, descending. Popularity is a combination of seeders and leechers, weighted ever so slightly towards seeders.

func (*Database) QueryPostId

func (db *Database) QueryPostId(id uint) (Post, error)

Return a single post given it's id.

func (*Database) QueryRecent

func (db *Database) QueryRecent(page int) ([]*Post, error)

Returns a page of posts ordered by upload data, descending.

func (*Database) Search

func (db *Database) Search(query string, page, pageSize int) ([]*Post, error)

Perform a query on the FTS table. The results returned are used to pull actual results out of the post table, and these are returned.

func (*Database) SetLeechers

func (db *Database) SetLeechers(id, leechers uint) error

func (*Database) SetSeeders

func (db *Database) SetSeeders(id, seeders uint) error

func (*Database) Suggest

func (db *Database) Suggest(query string) ([]string, error)

type ErrorReader

type ErrorReader struct {
	Err error
	// contains filtered or unexported fields
}

func NewErrorReader

func NewErrorReader(r io.Reader) *ErrorReader

func (*ErrorReader) ReadByte

func (er *ErrorReader) ReadByte() (byte, error)

func (*ErrorReader) ReadString

func (er *ErrorReader) ReadString(delim byte) string

type Piece

type Piece struct {
	Id    uint
	Posts []Post
	// contains filtered or unexported fields
}

func (*Piece) Add

func (p *Piece) Add(post Post, store bool) error

func (*Piece) Hash

func (p *Piece) Hash() []byte

func (*Piece) Rehash

func (p *Piece) Rehash() ([]byte, error)

func (*Piece) Setup

func (p *Piece) Setup()

type Post

type Post struct {
	Id         int
	InfoHash   string
	Title      string
	Size       int
	FileCount  int
	Seeders    int
	Leechers   int
	UploadDate int
	Tags       string
	Meta       string
}

func (*Post) Bytes

func (p *Post) Bytes(sep, term []byte, seedLeech bool) []byte

func (Post) Json

func (p Post) Json() ([]byte, error)

func (*Post) String

func (p *Post) String(sep, term string, seedLeech bool) string

func (*Post) Valid

func (p *Post) Valid() error

func (*Post) Write

func (p *Post) Write(sep, term string, seedLeech bool, w io.Writer)

Includes an option to include seed/leech or not. Other than seed and leech count, posts are immutable. This prevents other peers from changing their data.

type SearchProvider

type SearchProvider struct {
	Loaded bool
}

This provides searching, as it is a little more comlex than just a db query. Search strings could provide other data that needs parsing, as well as spell correction that needs doing. This has to be passed through other functions before it hits a db query, hence this.

func NewSearchProvider

func NewSearchProvider() *SearchProvider

func (*SearchProvider) Search

func (sp *SearchProvider) Search(source string, db *Database, query string, page int) (SearchResult, error)

func (*SearchProvider) Suggest

func (sp *SearchProvider) Suggest(db *Database, query string) ([]string, error)

type SearchResult

type SearchResult struct {
	Posts  []*Post `json:"posts"`
	Source string  `json:"source"`
}

Jump to

Keyboard shortcuts

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