data

package
v0.0.0-...-bfd0fd8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2014 License: MIT Imports: 16 Imported by: 4

Documentation

Overview

Package data provides the data structures and database backends used by the goat BitTorrent tracker.

Index

Constants

This section is empty.

Variables

View Source
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 }
)
View Source
var MySQLDSN *string

MySQLDSN is set via command-line, and can be used to override all MySQL configuration

View Source
var QLDBPath *string

QLDBPath is set via command-line, and can be used to override ql database location

Functions

func DBConnect

func DBConnect() (dbModel, error)

DBConnect connects to a database

func DBName

func DBName() string

DBName will retrieve the name of the database backend currently in use

func DBPing

func DBPing() bool

DBPing will attempt to "ping" the database to verify connectivity

Types

type APIKey

type APIKey struct {
	ID     int
	UserID int `db:"user_id"`
	Pubkey string
	Secret string
	Expire int64
}

APIKey represents a user's API key

func (*APIKey) Create

func (a *APIKey) Create(userID int) error

Create a new APIKey

func (APIKey) Delete

func (a APIKey) Delete() error

Delete APIKey from storage

func (APIKey) Load

func (a APIKey) Load(id interface{}, col string) (APIKey, error)

Load APIKey from storage

func (APIKey) Save

func (a APIKey) Save() error

Save APIKey to storage

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) Delete

func (a AnnounceLog) Delete() error

Delete AnnounceLog from 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

func (AnnounceLog) Save

func (a AnnounceLog) Save() error

Save AnnounceLog to 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) Delete

func (f FileRecord) Delete() error

Delete FileRecord from storage

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) Save

func (f FileRecord) Save() error

Save FileRecord to storage

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

func (FileUserRecord) Save

func (f FileUserRecord) Save() error

Save FileUserRecord to 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

type Peer struct {
	IP   string
	Port uint16
}

Peer represents an IP and port peer, used as part of the peer list

func (Peer) MarshalBinary

func (p Peer) MarshalBinary() ([]byte, error)

MarshalBinary creates a packed byte array from a peer

func (*Peer) UnmarshalBinary

func (p *Peer) UnmarshalBinary(buf []byte) (err error)

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) Delete

func (s ScrapeLog) Delete() error

Delete ScrapeLog from storage

func (*ScrapeLog) FromValues

func (s *ScrapeLog) FromValues(query url.Values) error

FromValues generates a ScrapeLog struct from a url.Values map

func (ScrapeLog) Load

func (s ScrapeLog) Load(id interface{}, col string) (ScrapeLog, error)

Load ScrapeLog from storage

func (ScrapeLog) Save

func (s ScrapeLog) Save() error

Save ScrapeLog to storage

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) Delete

func (u UserRecord) Delete() error

Delete UserRecord from storage

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) Save

func (u UserRecord) Save() error

Save UserRecord to 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

type WhitelistRecord struct {
	ID       int
	Client   string
	Approved bool
}

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

func (WhitelistRecord) Save

func (w WhitelistRecord) Save() error

Save WhitelistRecord to storage

Directories

Path Synopsis
Package udp provides the UDP-related data structures and methods for the goat BitTorrent tracker.
Package udp provides the UDP-related data structures and methods for the goat BitTorrent tracker.

Jump to

Keyboard shortcuts

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