db

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DbL = log.New(os.Stderr, "[DB]  ", log.LstdFlags) // Database Logger

Functions

func MetafromHex

func MetafromHex(infohash string) (h metainfo.Hash, err error)

MetafromHex returns metainfo.Hash from given infohash string

func NewPsqlPieceCompletion

func NewPsqlPieceCompletion(databaseurl string) (ret *psqlPieceCompletion, err error)

func NewSqlitePieceCompletion

func NewSqlitePieceCompletion(dir string) (ret *sqlitePieceCompletion, err error)

Types

type FileStateDb

type FileStateDb interface {
	Open(string)
	Close()
	Add(string, metainfo.Hash) error
	Get(metainfo.Hash) []string
	Deletefile(string, metainfo.Hash) error
	Delete(metainfo.Hash) error
}

type LockStateDb

type LockStateDb interface {
	Open(string)
	Close()
	Lock(metainfo.Hash) error
	Unlock(metainfo.Hash) error
	IsLocked(string) bool
}

type PcDb

type PcDb interface {
	storage.PieceCompletion
	Delete(metainfo.Hash)
}

type PsqlFsDb

type PsqlFsDb struct {
	Db *pgxpool.Pool
}

func (*PsqlFsDb) Add

func (db *PsqlFsDb) Add(fp string, ih metainfo.Hash) (err error)

func (*PsqlFsDb) Close

func (db *PsqlFsDb) Close()

func (*PsqlFsDb) Delete

func (db *PsqlFsDb) Delete(ih metainfo.Hash) (err error)

func (*PsqlFsDb) Deletefile

func (db *PsqlFsDb) Deletefile(fp string, ih metainfo.Hash) (err error)

func (*PsqlFsDb) Get

func (db *PsqlFsDb) Get(ih metainfo.Hash) (ret []string)

func (*PsqlFsDb) Open

func (db *PsqlFsDb) Open(dburl string)

type PsqlLsDb

type PsqlLsDb struct {
	Db *pgxpool.Pool
}

func (*PsqlLsDb) Close

func (db *PsqlLsDb) Close()

func (*PsqlLsDb) IsLocked

func (db *PsqlLsDb) IsLocked(m string) (b bool)

func (*PsqlLsDb) Lock

func (db *PsqlLsDb) Lock(m metainfo.Hash) (err error)

func (*PsqlLsDb) Open

func (db *PsqlLsDb) Open(dburl string)

func (*PsqlLsDb) Unlock

func (db *PsqlLsDb) Unlock(m metainfo.Hash) (err error)

type PsqlTDb

type PsqlTDb struct {
	Db *pgxpool.Pool
}

func (*PsqlTDb) Add

func (db *PsqlTDb) Add(url string)

func (*PsqlTDb) Close

func (db *PsqlTDb) Close()

func (*PsqlTDb) Count

func (db *PsqlTDb) Count() (ret int64)

func (*PsqlTDb) Delete

func (db *PsqlTDb) Delete(url string)

func (*PsqlTDb) DeleteAll

func (db *PsqlTDb) DeleteAll()

func (*PsqlTDb) DeleteN

func (db *PsqlTDb) DeleteN(count int)

func (*PsqlTDb) Get

func (db *PsqlTDb) Get() (ret []string)

func (*PsqlTDb) Open

func (db *PsqlTDb) Open(dburl string)

type PsqlTrntDb

type PsqlTrntDb struct {
	Db *pgxpool.Pool
}

func (*PsqlTrntDb) Add

func (db *PsqlTrntDb) Add(ih metainfo.Hash) (err error)

func (*PsqlTrntDb) Close

func (db *PsqlTrntDb) Close()

func (*PsqlTrntDb) Delete

func (db *PsqlTrntDb) Delete(ih metainfo.Hash) (err error)

func (*PsqlTrntDb) Exists

func (db *PsqlTrntDb) Exists(ih metainfo.Hash) (ret bool)

func (*PsqlTrntDb) GetTorrent

func (db *PsqlTrntDb) GetTorrent(ih metainfo.Hash) (*Torrent, error)

func (*PsqlTrntDb) GetTorrents

func (db *PsqlTrntDb) GetTorrents() (Trnts []*Torrent, err error)

func (*PsqlTrntDb) HasStarted

func (db *PsqlTrntDb) HasStarted(ih string) (ret bool)

func (*PsqlTrntDb) Open

func (db *PsqlTrntDb) Open(dburl string)

func (*PsqlTrntDb) SetStarted

func (db *PsqlTrntDb) SetStarted(ih metainfo.Hash, inp bool) (err error)

func (*PsqlTrntDb) Start

func (db *PsqlTrntDb) Start(ih metainfo.Hash) (err error)

type PsqlTrntUserDb

type PsqlTrntUserDb struct {
	Db *pgxpool.Pool
}

func (*PsqlTrntUserDb) Add

func (db *PsqlTrntUserDb) Add(username string, ih metainfo.Hash) (err error)

func (*PsqlTrntUserDb) Close

func (db *PsqlTrntUserDb) Close()

func (*PsqlTrntUserDb) HasUser

func (db *PsqlTrntUserDb) HasUser(username string, ih string) (ret bool)

func (*PsqlTrntUserDb) ListTorrents

func (db *PsqlTrntUserDb) ListTorrents(username string) (ret []metainfo.Hash)

func (*PsqlTrntUserDb) ListUsers

func (db *PsqlTrntUserDb) ListUsers(mi metainfo.Hash) (ret []string)

func (*PsqlTrntUserDb) Open

func (db *PsqlTrntUserDb) Open(dburl string)

func (*PsqlTrntUserDb) Remove

func (db *PsqlTrntUserDb) Remove(username string, ih metainfo.Hash) (err error)

func (*PsqlTrntUserDb) RemoveAll

func (db *PsqlTrntUserDb) RemoveAll(username string) (err error)

func (*PsqlTrntUserDb) RemoveAllMi

func (db *PsqlTrntUserDb) RemoveAllMi(mi metainfo.Hash) (err error)

type PsqlUserDb

type PsqlUserDb struct {
	Db *pgxpool.Pool
}

func (*PsqlUserDb) Add

func (db *PsqlUserDb) Add(Username string, Password string, UserType int) (err error)

func (*PsqlUserDb) ChangeType

func (db *PsqlUserDb) ChangeType(Username string, Type string) (err error)

func (*PsqlUserDb) Close

func (db *PsqlUserDb) Close()

func (*PsqlUserDb) Delete

func (db *PsqlUserDb) Delete(username string) (err error)

func (*PsqlUserDb) GetID

func (db *PsqlUserDb) GetID(username string) (ret int64)

func (*PsqlUserDb) GetUsers

func (db *PsqlUserDb) GetUsers() (ret []*User)

func (*PsqlUserDb) Open

func (db *PsqlUserDb) Open(dburl string)

func (*PsqlUserDb) SetToken

func (db *PsqlUserDb) SetToken(Username string, Token string) (err error)

func (*PsqlUserDb) UpdatePw

func (db *PsqlUserDb) UpdatePw(Username string, Password string) (err error)

func (*PsqlUserDb) Validate

func (db *PsqlUserDb) Validate(Username string, Password string) (ut int, b bool)

func (*PsqlUserDb) ValidateToken

func (db *PsqlUserDb) ValidateToken(Token string) (user string, ut int, err error)

type Sqlite3Db

type Sqlite3Db struct {
	Db *sqlite.Conn
	// contains filtered or unexported fields
}

func (*Sqlite3Db) Add

func (db *Sqlite3Db) Add(ih metainfo.Hash) (err error)

func (*Sqlite3Db) Close

func (db *Sqlite3Db) Close()

func (*Sqlite3Db) Delete

func (db *Sqlite3Db) Delete(ih metainfo.Hash) (err error)

func (*Sqlite3Db) Exists

func (db *Sqlite3Db) Exists(ih metainfo.Hash) (ret bool)

func (*Sqlite3Db) GetTorrent

func (db *Sqlite3Db) GetTorrent(ih metainfo.Hash) (*Torrent, error)

func (*Sqlite3Db) GetTorrents

func (db *Sqlite3Db) GetTorrents() (Trnts []*Torrent, err error)

func (*Sqlite3Db) HasStarted

func (db *Sqlite3Db) HasStarted(ih string) (ret bool)

func (*Sqlite3Db) IsLocked

func (db *Sqlite3Db) IsLocked(ih string) (ret bool)

func (*Sqlite3Db) Open

func (db *Sqlite3Db) Open(fp string)

func (*Sqlite3Db) SetLocked

func (db *Sqlite3Db) SetLocked(ih string, b bool) (err error)

func (*Sqlite3Db) SetStarted

func (db *Sqlite3Db) SetStarted(ih metainfo.Hash, inp bool) (err error)

func (*Sqlite3Db) Start

func (db *Sqlite3Db) Start(ih metainfo.Hash) (err error)

type Sqlite3UserDb

type Sqlite3UserDb struct {
	Db *sqlite.Conn
	// contains filtered or unexported fields
}

func (*Sqlite3UserDb) Add

func (db *Sqlite3UserDb) Add(Username string, Password string, UserType int) (err error)

func (*Sqlite3UserDb) ChangeType

func (db *Sqlite3UserDb) ChangeType(Username string, Type string) (err error)

func (*Sqlite3UserDb) Close

func (db *Sqlite3UserDb) Close()

func (*Sqlite3UserDb) Delete

func (db *Sqlite3UserDb) Delete(Username string) (err error)

func (*Sqlite3UserDb) GetUsers

func (db *Sqlite3UserDb) GetUsers() (ret []*User)

func (*Sqlite3UserDb) Open

func (db *Sqlite3UserDb) Open(fp string)

func (*Sqlite3UserDb) SetToken

func (db *Sqlite3UserDb) SetToken(Username string, Token string) (err error)

func (*Sqlite3UserDb) UpdatePw

func (db *Sqlite3UserDb) UpdatePw(Username string, Password string) (err error)

func (*Sqlite3UserDb) Validate

func (db *Sqlite3UserDb) Validate(Username string, Password string) (ut int, ret bool)

func (*Sqlite3UserDb) ValidateToken

func (db *Sqlite3UserDb) ValidateToken(Token string) (user string, ut int, err error)

type SqliteFSDb

type SqliteFSDb struct {
	Db *sqlite.Conn
	// contains filtered or unexported fields
}

func (*SqliteFSDb) Add

func (db *SqliteFSDb) Add(fp string, ih metainfo.Hash) (err error)

func (*SqliteFSDb) Close

func (db *SqliteFSDb) Close()

func (*SqliteFSDb) Delete

func (db *SqliteFSDb) Delete(ih metainfo.Hash) (err error)

func (*SqliteFSDb) Deletefile

func (db *SqliteFSDb) Deletefile(fp string, ih metainfo.Hash) (err error)

func (*SqliteFSDb) Get

func (db *SqliteFSDb) Get(ih metainfo.Hash) (ret []string)

func (*SqliteFSDb) Open

func (db *SqliteFSDb) Open(fp string)

type SqliteLSDb

type SqliteLSDb struct {
	Db *sqlite.Conn
	// contains filtered or unexported fields
}

func (*SqliteLSDb) Close

func (db *SqliteLSDb) Close()

func (*SqliteLSDb) IsLocked

func (db *SqliteLSDb) IsLocked(m string) (b bool)

func (*SqliteLSDb) Lock

func (db *SqliteLSDb) Lock(m metainfo.Hash) (err error)

func (*SqliteLSDb) Open

func (db *SqliteLSDb) Open(fp string)

func (*SqliteLSDb) Unlock

func (db *SqliteLSDb) Unlock(m metainfo.Hash) (err error)

type SqliteTdb

type SqliteTdb struct {
	Db *sqlite.Conn
	// contains filtered or unexported fields
}

func (*SqliteTdb) Add

func (db *SqliteTdb) Add(url string)

func (*SqliteTdb) Close

func (db *SqliteTdb) Close()

func (*SqliteTdb) Count

func (db *SqliteTdb) Count() (ret int64)

func (*SqliteTdb) Delete

func (db *SqliteTdb) Delete(url string)

func (*SqliteTdb) DeleteAll

func (db *SqliteTdb) DeleteAll()

func (*SqliteTdb) DeleteN

func (db *SqliteTdb) DeleteN(count int)

func (*SqliteTdb) Get

func (db *SqliteTdb) Get() (ret []string)

func (*SqliteTdb) Open

func (db *SqliteTdb) Open(fp string)

type SqliteTorrentUserDb

type SqliteTorrentUserDb struct {
	Db *sqlite.Conn
	// contains filtered or unexported fields
}

func (*SqliteTorrentUserDb) Add

func (db *SqliteTorrentUserDb) Add(username string, ih metainfo.Hash) (err error)

func (*SqliteTorrentUserDb) Close

func (db *SqliteTorrentUserDb) Close()

func (*SqliteTorrentUserDb) HasUser

func (db *SqliteTorrentUserDb) HasUser(username string, ih string) (ret bool)

func (*SqliteTorrentUserDb) ListTorrents

func (db *SqliteTorrentUserDb) ListTorrents(username string) (ret []metainfo.Hash)

func (*SqliteTorrentUserDb) ListUsers

func (db *SqliteTorrentUserDb) ListUsers(mi metainfo.Hash) (ret []string)

func (*SqliteTorrentUserDb) Open

func (db *SqliteTorrentUserDb) Open(fp string)

func (*SqliteTorrentUserDb) Remove

func (db *SqliteTorrentUserDb) Remove(username string, ih metainfo.Hash) (err error)

func (*SqliteTorrentUserDb) RemoveAll

func (db *SqliteTorrentUserDb) RemoveAll(username string) (err error)

func (*SqliteTorrentUserDb) RemoveAllMi

func (db *SqliteTorrentUserDb) RemoveAllMi(mi metainfo.Hash) (err error)

type Torrent

type Torrent struct {
	Infohash  metainfo.Hash
	Started   bool
	AddedAt   time.Time
	StartedAt time.Time
}

type TorrentDb

type TorrentDb interface {
	Open(string)
	Close()
	Exists(metainfo.Hash) bool
	Add(metainfo.Hash) error
	Delete(metainfo.Hash) error
	Start(metainfo.Hash) error
	SetStarted(metainfo.Hash, bool) error
	HasStarted(string) bool
	GetTorrent(metainfo.Hash) (*Torrent, error)
	GetTorrents() ([]*Torrent, error)
}

type TorrentUserDb

type TorrentUserDb interface {
	Open(string)
	Close()
	Add(string, metainfo.Hash) error
	Remove(string, metainfo.Hash) error
	RemoveAll(string) error
	RemoveAllMi(metainfo.Hash) error
	HasUser(string, string) bool
	ListTorrents(string) []metainfo.Hash
	ListUsers(metainfo.Hash) []string
}

type TrackerDb

type TrackerDb interface {
	Open(string)
	Close()
	Add(string)
	Delete(string)
	DeleteN(int)
	DeleteAll()
	Count() int64
	Get() []string
}

type User

type User struct {
	Username  string
	Password  string `json:"-"`
	Token     string
	UserType  int // 0 for User,1 for Admin,-1 for Disabled
	CreatedAt time.Time
}

type UserDb

type UserDb interface {
	Open(string)
	Close()
	Add(string, string, int) error // Username , Password , Usertype
	ChangeType(string, string) error
	Delete(string) error
	UpdatePw(string, string) error
	GetUsers() []*User
	Validate(string, string) (int, bool)
	ValidateToken(string) (string, int, error)
	SetToken(string, string) error
}

Jump to

Keyboard shortcuts

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