db

package
v0.9.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DB is the sqlx database connection
	DB *sqlx.DB
)
View Source
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

func Asset(name string) ([]byte, error)

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

func AssetDir(name string) ([]string, error)

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

func AssetInfo(name string) (os.FileInfo, error)

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

func CheckConnectionID(connectionID []byte, addr net.IP) (bool, error)

CheckConnectionID queries the database for connection id validity

func ClearConnections

func ClearConnections() error

func ClearPeers

func ClearPeers(olderThan time.Duration) error

func GetTorrentStats

func GetTorrentStats(torrentID []byte) (*udp.TorrentStats, error)

func IncrementTorrentDownloadedStats

func IncrementTorrentDownloadedStats(torrentID []byte) error

func InitializeDatabaseConnection

func InitializeDatabaseConnection(config Config) error

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 InsertPeer(peer *Peer) error

func MustAsset added in v0.9.2

func MustAsset(name string) []byte

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

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets added in v0.9.2

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func UpdatePeer

func UpdatePeer(peer *Peer) error

Types

type Config

type Config struct {
	DataSource string
	IdleConn   int
	MaxConn    int
	Mode       Mode
}

Config is the struct containing the database connection parameters

type Mode

type Mode int

Mode is the type for representing database connection mode

const (
	ModeProd Mode = iota
	ModeDev
)

Database operation modes

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

func GetPeer

func GetPeer(peerID, torrentID []byte) (*Peer, error)

GetPeer returns a pointer to a Peer struct populated with the requested data Peer will be nil if error occurred or if not found inside the database

Jump to

Keyboard shortcuts

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