storage

package
v0.0.0-...-461761a Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2013 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package storage provides a generic interface for manipulating a BitTorrent tracker's data store.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTxDone = errors.New("storage: Transaction has already been committed or rolled back")
)

Functions

func Register

func Register(name string, driver Driver)

Register makes a database driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type Driver

type Driver interface {
	New(*config.Storage) Pool
}

type Peer

type Peer struct {
	ID           string `json:"id"`
	UserID       uint64 `json:"user_id"`
	TorrentID    uint64 `json:"torrent_id"`
	IP           string `json:"ip"`
	Port         uint64 `json:"port"`
	Uploaded     uint64 `json:"uploaded"`
	Downloaded   uint64 `json:"downloaded`
	Left         uint64 `json:"left"`
	LastAnnounce int64  `json:"last_announce"`
}

type Pool

type Pool interface {
	Close() error
	Get() (Tx, error)
}

Pool represents a thread-safe pool of connections to the data store that can be used to obtain transactions.

func Open

func Open(conf *config.Storage) (Pool, error)

Open creates a pool of data store connections specified by a storage configuration.

type Torrent

type Torrent struct {
	ID             uint64          `json:"id"`
	Infohash       string          `json:"infohash"`
	Active         bool            `json:"active"`
	Seeders        map[string]Peer `json:"seeders"`
	Leechers       map[string]Peer `json:"leechers"`
	Snatches       uint            `json:"snatches"`
	UpMultiplier   float64         `json:"up_multiplier"`
	DownMultiplier float64         `json:"down_multipler"`
	LastAction     int64           `json:"last_action"`
}

type Tx

type Tx interface {
	Commit() error
	Rollback() error

	// Reads
	FindUser(passkey string) (*User, bool, error)
	FindTorrent(infohash string) (*Torrent, bool, error)
	ClientWhitelisted(peerID string) (bool, error)

	// Writes
	Snatch(u *User, t *Torrent) error
	MarkActive(t *Torrent) error
	NewLeecher(t *Torrent, p *Peer) error
	NewSeeder(t *Torrent, p *Peer) error
	RmLeecher(t *Torrent, p *Peer) error
	RmSeeder(t *Torrent, p *Peer) error
	SetLeecher(t *Torrent, p *Peer) error
	SetSeeder(t *Torrent, p *Peer) error
	IncrementSlots(u *User) error
	DecrementSlots(u *User) error
}

Tx represents an in-progress data store transaction. A transaction must end with a call to Commit or Rollback.

After a call to Commit or Rollback, all operations on the transaction must fail with ErrTxDone.

type User

type User struct {
	ID             uint64  `json:"id"`
	Passkey        string  `json:"passkey"`
	UpMultiplier   float64 `json:"up_multiplier"`
	DownMultiplier float64 `json:"down_multiplier"`
	Slots          int64   `json:"slots"`
	SlotsUsed      int64   `json:"slots_used"`
}

Directories

Path Synopsis
Package redis implements the storage interface for a BitTorrent tracker.
Package redis implements the storage interface for a BitTorrent tracker.

Jump to

Keyboard shortcuts

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