Documentation ¶
Index ¶
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func CheckConnectionID(connectionID []byte, addr net.IP) (bool, error)
- func ClearConnections() error
- func ClearPeers(olderThan time.Duration) error
- func GetTorrentStats(torrentID []byte) (*udp.TorrentStats, error)
- func IncrementTorrentDownloadedStats(torrentID []byte) error
- func InitializeDatabaseConnection(config Config) error
- func InitializeModule(dbLogger log.Logger)
- func InsertPeer(peer *Peer) error
- func MustAsset(name string) []byte
- func PopulatePeersFields(response *udp.AnnounceResponse, peerID []byte, torrentID []byte, limit int32) error
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func UpdatePeer(peer *Peer) error
- type Config
- type Mode
- type Peer
Constants ¶
This section is empty.
Variables ¶
var ( // DB is the sqlx database connection DB *sqlx.DB )
var ( StmtWriteConnectionID = preparedStmt{ `INSERT INTO "public"."connection" ("id", "ip", "expiry") VALUES (decode($1, 'base64'), $2, $3)`, nil, } )
Prepared statements used a lot in the application
Functions ¶
func Asset ¶ added in v0.9.2
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶ added in v0.9.2
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶ added in v0.9.2
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetNames ¶ added in v0.9.2
func AssetNames() []string
AssetNames returns the names of the assets.
func CheckConnectionID ¶
CheckConnectionID queries the database for connection id validity
func ClearConnections ¶
func ClearConnections() error
func ClearPeers ¶
func GetTorrentStats ¶
func GetTorrentStats(torrentID []byte) (*udp.TorrentStats, error)
func InitializeDatabaseConnection ¶
InitializeDatabaseConnection tries a connections to the database, updates it's schema and makes it ready for use
func InitializeModule ¶
func InitializeModule(dbLogger log.Logger)
InitializeModule setup the db module for correct operation
func InsertPeer ¶
func MustAsset ¶ added in v0.9.2
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func PopulatePeersFields ¶
func PopulatePeersFields(response *udp.AnnounceResponse, peerID []byte, torrentID []byte, limit int32) error
PopulatePeersFields set peers list and seeders and leechers stats
func RestoreAsset ¶ added in v0.9.2
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶ added in v0.9.2
RestoreAssets restores an asset under the given directory recursively
func UpdatePeer ¶
Types ¶
type Peer ¶
type Peer struct { ID []byte `db:"id"` TorrentID []byte `db:"torrent_id"` State int `db:"state"` IP string `db:"ip"` Port uint16 `db:"port"` Downloaded int64 `db:"downloaded"` Uploaded int64 `db:"uploaded"` Left int64 `db:"left"` LastUpdated time.Time `db:"last_updated"` }
Peer represents the peer relation inside the database