Documentation ¶
Overview ¶
Package data provides the data structures and database backends used by the goat BitTorrent tracker.
Index ¶
- Variables
- func DBConnect() (dbModel, error)
- func DBName() string
- func DBPing() bool
- type APIKey
- type APIKeyRepository
- type AnnounceLog
- type FileRecord
- func (f FileRecord) CompactPeerList(numwant int, http bool) ([]byte, error)
- func (f FileRecord) Completed() (int, error)
- func (f FileRecord) Delete() error
- func (f FileRecord) Leechers() (int, error)
- func (f FileRecord) Load(id interface{}, col string) (FileRecord, error)
- func (f FileRecord) PeerList(numwant int, http bool) ([]Peer, error)
- func (f FileRecord) PeerReaper() (int, error)
- func (f FileRecord) Save() error
- func (f FileRecord) Seeders() (int, error)
- func (f FileRecord) ToJSON() (JSONFileRecord, error)
- func (f FileRecord) Users() ([]FileUserRecord, error)
- type FileRecordRepository
- type FileUserRecord
- type FileUserRecordRepository
- type JSONAPIKey
- type JSONFileRecord
- type JSONUserRecord
- type Peer
- type ScrapeLog
- type UserRecord
- func (u *UserRecord) Create(username string, password string, torrentLimit int) error
- func (u UserRecord) Delete() error
- func (u UserRecord) Downloaded() (int64, error)
- func (u UserRecord) Leeching() (int, error)
- func (u UserRecord) Load(id interface{}, col string) (UserRecord, error)
- func (u UserRecord) Save() error
- func (u UserRecord) Seeding() (int, error)
- func (u UserRecord) ToJSON() (JSONUserRecord, error)
- func (u UserRecord) Uploaded() (int64, error)
- type UserRecordRepository
- type WhitelistRecord
Constants ¶
This section is empty.
Variables ¶
var ( // DBConnectFunc connects to a database backend DBConnectFunc func() (dbModel, error) // DBCloseFunc closes connection to a database backend DBCloseFunc = func() {} // DBNameFunc returns the name of a database backend DBNameFunc = func() string { return "" } // DBPingFunc checks connectivity to a database backend DBPingFunc = func() bool { return true } )
var MySQLDSN *string
MySQLDSN is set via command-line, and can be used to override all MySQL configuration
var QLDBPath *string
QLDBPath is set via command-line, and can be used to override ql database location
Functions ¶
Types ¶
type APIKey ¶
APIKey represents a user's API key
func (APIKey) ToJSON ¶
func (a APIKey) ToJSON() (JSONAPIKey, error)
ToJSON converts an APIKey to a JSONAPIKey struct
type APIKeyRepository ¶
type APIKeyRepository struct { }
APIKeyRepository is used to contain methods to load multiple APIKey structs
func (APIKeyRepository) All ¶
func (a APIKeyRepository) All() ([]APIKey, error)
All loads all APIKey structs from storage
type AnnounceLog ¶
type AnnounceLog struct { ID int InfoHash string `db:"info_hash"` Passkey string Key string IP string Port int UDP bool Uploaded int64 Downloaded int64 Left int64 Event string Client string Time int64 }
AnnounceLog represents an announce, to be logged to storage
func (*AnnounceLog) FromValues ¶
func (a *AnnounceLog) FromValues(query url.Values) error
FromValues generates an AnnounceLog struct from a url.Values map
func (AnnounceLog) Load ¶
func (a AnnounceLog) Load(ID interface{}, col string) (AnnounceLog, error)
Load AnnounceLog from storage
type FileRecord ¶
type FileRecord struct { ID int `json:"id"` InfoHash string `db:"info_hash" json:"infoHash"` Verified bool `json:"verified"` CreateTime int64 `db:"create_time" json:"createTime"` UpdateTime int64 `db:"update_time" json:"updateTime"` }
FileRecord represents a file tracked by tracker
func (FileRecord) CompactPeerList ¶
func (f FileRecord) CompactPeerList(numwant int, http bool) ([]byte, error)
CompactPeerList returns a packed byte array of peers who are active on this file
func (FileRecord) Completed ¶
func (f FileRecord) Completed() (int, error)
Completed returns the number of completions, active or not, on this file
func (FileRecord) Leechers ¶
func (f FileRecord) Leechers() (int, error)
Leechers returns the number of leechers on this file
func (FileRecord) Load ¶
func (f FileRecord) Load(id interface{}, col string) (FileRecord, error)
Load FileRecord from storage
func (FileRecord) PeerList ¶
func (f FileRecord) PeerList(numwant int, http bool) ([]Peer, error)
PeerList returns a list of peers on this torrent, for tracker announce
func (FileRecord) PeerReaper ¶
func (f FileRecord) PeerReaper() (int, error)
PeerReaper reaps peers who have not recently announced on this torrent, and mark them inactive
func (FileRecord) Seeders ¶
func (f FileRecord) Seeders() (int, error)
Seeders returns the number of seeders on this file
func (FileRecord) ToJSON ¶
func (f FileRecord) ToJSON() (JSONFileRecord, error)
ToJSON converts a FileRecord to a JSONFileRecord struct
func (FileRecord) Users ¶
func (f FileRecord) Users() ([]FileUserRecord, error)
Users loads all FileUserRecord structs associated with this FileRecord struct
type FileRecordRepository ¶
type FileRecordRepository struct { }
FileRecordRepository is used to contain methods to load multiple FileRecord structs
func (FileRecordRepository) All ¶
func (f FileRecordRepository) All() ([]FileRecord, error)
All loads all FileRecord structs from storage
type FileUserRecord ¶
type FileUserRecord struct { FileID int `db:"file_id" json:"fileId"` UserID int `db:"user_id" json:"userId"` IP string `json:"ip"` Active bool `json:"active"` Completed bool `json:"completed"` Announced int `json:"announced"` Uploaded int64 `json:"uploaded"` Downloaded int64 `json:"downloaded"` Left int64 `json:"left"` Time int64 `json:"time"` }
FileUserRecord represents a file tracked by tracker
func (FileUserRecord) Delete ¶
func (f FileUserRecord) Delete() error
Delete FileUserRecord from storage
func (FileUserRecord) Load ¶
func (f FileUserRecord) Load(fileID int, userID int, ip string) (FileUserRecord, error)
Load FileUserRecord from storage
type FileUserRecordRepository ¶
type FileUserRecordRepository struct { }
FileUserRecordRepository is used to contain methods to load multiple FileRecord structs
func (FileUserRecordRepository) Select ¶
func (f FileUserRecordRepository) Select(id interface{}, col string) ([]FileUserRecord, error)
Select loads selected FileUserRecord structs from storage
type JSONAPIKey ¶
type JSONAPIKey struct { UserID int `json:"userId"` Pubkey string `json:"pubkey"` Secret string `json:"secret"` Expire int64 `json:"expire"` }
JSONAPIKey represents output APIKey JSON for API
type JSONFileRecord ¶
type JSONFileRecord struct { ID int `json:"id"` InfoHash string `json:"infoHash"` Verified bool `json:"verified"` CreateTime int64 `json:"createTime"` UpdateTime int64 `json:"updateTime"` Completed int `json:"completed"` Seeders int `json:"seeders"` Leechers int `json:"leechers"` FileUsers []FileUserRecord `json:"fileUsers"` }
JSONFileRecord represents output FileRecord JSON for API
type JSONUserRecord ¶
type JSONUserRecord struct { ID int `json:"id"` Username string `json:"username"` TorrentLimit int `json:"torrentLimit"` }
JSONUserRecord represents output UserRecord JSON for API
type Peer ¶
Peer represents an IP and port peer, used as part of the peer list
func (Peer) MarshalBinary ¶
MarshalBinary creates a packed byte array from a peer
func (*Peer) UnmarshalBinary ¶
UnmarshalBinary creates a Peer from a packed byte array
type ScrapeLog ¶
type ScrapeLog struct { ID int InfoHash string `db:"info_hash"` Passkey string IP string Time int64 UDP bool }
ScrapeLog represents a scrapelog, to be logged to storage
func (*ScrapeLog) FromValues ¶
FromValues generates a ScrapeLog struct from a url.Values map
type UserRecord ¶
type UserRecord struct { ID int `json:"id"` Username string `json:"username"` Password string `json:"password"` Passkey string `json:"passkey"` TorrentLimit int `db:"torrent_limit" json:"torrentLimit"` }
UserRecord represents a user on the tracker
func (*UserRecord) Create ¶
func (u *UserRecord) Create(username string, password string, torrentLimit int) error
Create a UserRecord, using defined parameters
func (UserRecord) Downloaded ¶
func (u UserRecord) Downloaded() (int64, error)
Downloaded loads this user's total download
func (UserRecord) Leeching ¶
func (u UserRecord) Leeching() (int, error)
Leeching counts the number of torrents this user is leeching
func (UserRecord) Load ¶
func (u UserRecord) Load(id interface{}, col string) (UserRecord, error)
Load UserRecord from storage
func (UserRecord) Seeding ¶
func (u UserRecord) Seeding() (int, error)
Seeding counts the number of torrents this user is seeding
func (UserRecord) ToJSON ¶
func (u UserRecord) ToJSON() (JSONUserRecord, error)
ToJSON converts a UserRecord to a JSONUserRecord struct
func (UserRecord) Uploaded ¶
func (u UserRecord) Uploaded() (int64, error)
Uploaded loads this user's total upload
type UserRecordRepository ¶
type UserRecordRepository struct { }
UserRecordRepository is used to contain methods to load multiple UserRecord structs
func (UserRecordRepository) All ¶
func (u UserRecordRepository) All() ([]UserRecord, error)
All loads all UserRecord structs from storage
type WhitelistRecord ¶
WhitelistRecord represents a whitelist entry
func (WhitelistRecord) Delete ¶
func (w WhitelistRecord) Delete() error
Delete WhitelistRecord from storage
func (WhitelistRecord) Load ¶
func (w WhitelistRecord) Load(id interface{}, col string) (WhitelistRecord, error)
Load WhitelistRecord from storage