redis

package
v0.0.0-...-1335a43 Latest Latest
Warning

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

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

Documentation

Overview

Package redis implements the storage interface for a BitTorrent tracker.

This interface is configured by a config.DataStore. To get a handle to this interface, call New on the initialized driver and then Get() on returned the cache.Pool.

Torrents, Users, and Peers are all stored in Redis hash types. All Redis keys can have an optional prefix specified during configuration. The relationship between Torrents and Peers is a Redis set that holds the peers' keys. There are two sets per torrent, one for seeders and one for leechers. The Redis sets are keyed by type and the torrent's ID.

The whitelist is a Redis set with the key "whitelist" that holds client IDs. Operations on the whitelist do not parse the client ID from a peer ID.

Some functions in this interface are not atomic. The data being modified may change while the function is executing. This will not cause the function to return an error; instead the function will complete and return valid, stale data.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCreateUser    = errors.New("redis: Incorrect reply length for user")
	ErrCreateTorrent = errors.New("redis: Incorrect reply length for torrent")
	ErrCreatePeer    = errors.New("redis: Incorrect reply length for peer")
	ErrMarkActive    = errors.New("redis: Torrent doesn't exist")

	SeedersPrefix  = "seeders:"
	LeechersPrefix = "leechers:"
	TorrentPrefix  = "torrent:"
	UserPrefix     = "user:"
	PeerPrefix     = "peer:"
)

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func (*Pool) Close

func (p *Pool) Close() error

func (*Pool) Get

func (p *Pool) Get() (cache.Tx, error)

type Tx

type Tx struct {
	redis.Conn
	// contains filtered or unexported fields
}

func (*Tx) AddLeecher

func (tx *Tx) AddLeecher(torrent *models.Torrent, peer *models.Peer) error

AddLeecher adds a new peer to a torrent's leecher set. This modifies the torrent argument, as well as the torrent's set and peer's hash in Redis. This function does not return an error if the leecher already exists. This is a multiple action command, it's not internally atomic.

func (*Tx) AddSeeder

func (tx *Tx) AddSeeder(torrent *models.Torrent, peer *models.Peer) error

AddSeeder adds a new peer to a torrent's seeder set. This modifies the torrent argument, as well as the torrent's set and peer's hash in Redis. This function does not return an error if the seeder already exists. This is a multiple action command, it's not internally atomic.

func (*Tx) AddTorrent

func (tx *Tx) AddTorrent(t *models.Torrent) error

AddTorrent writes/overwrites torrent information and saves peers from both peer sets. The hash fields names are the same as the JSON tags on the models.Torrent struct. This is a multiple action command, it's not internally atomic.

func (*Tx) AddUser

func (tx *Tx) AddUser(u *models.User) error

AddUser writes/overwrites user information to a Redis hash. The hash fields names are the same as the JSON tags on the models.user struct.

func (*Tx) ClientWhitelisted

func (tx *Tx) ClientWhitelisted(peerID string) (exists bool, err error)

ClientWhitelisted returns true if the ClientID exists in the Client set. This function does not parse the client ID from the peer ID. The clientID must match exactly to a member of the set.

func (*Tx) DecrementSlots

func (tx *Tx) DecrementSlots(u *models.User) error

IncrementSlots increment a user's Slots by one. This function modifies the argument as well as the hash field in Redis.

func (*Tx) FindTorrent

func (tx *Tx) FindTorrent(infohash string) (*models.Torrent, bool, error)

FindTorrent returns a pointer to a new torrent struct and true if the torrent exists, or nil and false if the torrent doesn't exist. This is a multiple action command, it's not internally atomic.

func (*Tx) FindUser

func (tx *Tx) FindUser(passkey string) (*models.User, bool, error)

FindUser returns a pointer to a new user struct and true if the user exists, or nil and false if the user doesn't exist. This function does not return an error if the torrent doesn't exist.

func (*Tx) IncrementSlots

func (tx *Tx) IncrementSlots(u *models.User) error

IncrementSlots increment a user's Slots by one. This function modifies the argument as well as the hash field in Redis.

func (*Tx) LeecherFinished

func (tx *Tx) LeecherFinished(torrent *models.Torrent, peer *models.Peer) error

LeecherFinished moves a peer's hashkey from a torrent's leecher set to the seeder set and updates the peer. This modifies the torrent argument, as well as the torrent's set and peer's hash in Redis. This function does not return an error if the peer doesn't exist or is not in the torrent's leecher set.

func (*Tx) MarkActive

func (tx *Tx) MarkActive(torrent *models.Torrent) error

MarkActive sets the active field of the torrent to true. This modifies the argument as well as the hash field in Redis. This function will return ErrMarkActive if the torrent does not exist.

func (*Tx) MarkInactive

func (tx *Tx) MarkInactive(torrent *models.Torrent) error

MarkInactive sets the active field of the torrent to false. This modifies the argument as well as the hash field in Redis. This function will return ErrMarkActive if the torrent does not exist.

func (*Tx) RecordSnatch

func (tx *Tx) RecordSnatch(user *models.User, torrent *models.Torrent) error

RecordSnatch increments the snatch counter on the torrent and user by one. This modifies the arguments as well as the hash field in Redis. This is a multiple action command, it's not internally atomic.

func (*Tx) RemoveLeecher

func (tx *Tx) RemoveLeecher(t *models.Torrent, p *models.Peer) error

RemoveLeecher removes the given peer from a torrent's leecher set. This modifies the torrent argument, as well as the torrent's set and peer's hash in Redis. This function does not return an error if the peer doesn't exist, or is not in the set.

func (*Tx) RemoveSeeder

func (tx *Tx) RemoveSeeder(t *models.Torrent, p *models.Peer) error

RemoveSeeder removes the given peer from a torrent's seeder set. This modifies the torrent argument, as well as the torrent's set and peer's hash in Redis. This function does not return an error if the peer doesn't exist, or is not in the set.

func (*Tx) RemoveTorrent

func (tx *Tx) RemoveTorrent(t *models.Torrent) error

RemoveTorrent deletes the torrent's Redis hash and then deletes all peers. This function will not return an error if the torrent has already been removed. This is a multiple action command, it's not internally atomic.

func (*Tx) RemoveUser

func (tx *Tx) RemoveUser(u *models.User) error

RemoveUser removes the user's hash from Redis. This function does not return an error if the user doesn't exist.

func (*Tx) SetLeecher

func (tx *Tx) SetLeecher(t *models.Torrent, p *models.Peer) error

SetLeecher updates a torrent's leecher. This modifies the torrent argument, as well as the peer's hash in Redis. Setting assumes that the peer is already a leecher, and only needs to be updated. This function does not return an error if the leecher does not exist or is not in the torrent's leecher set.

func (*Tx) SetSeeder

func (tx *Tx) SetSeeder(t *models.Torrent, p *models.Peer) error

SetSeeder updates a torrent's seeder. This modifies the torrent argument, as well as the peer's hash in Redis. Setting assumes that the peer is already a seeder, and only needs to be updated. This function does not return an error if the seeder does not exist or is not in the torrent's seeder set.

func (*Tx) UnWhitelistClient

func (tx *Tx) UnWhitelistClient(peerID string) error

UnWhitelistClient removes a client ID from the client whitelist set This function does not return an error if the client ID is not in the set.

func (*Tx) WhitelistClient

func (tx *Tx) WhitelistClient(peerID string) error

WhitelistClient adds a client ID to the client whitelist set. This function does not return an error if the client ID is already in the set.

Jump to

Keyboard shortcuts

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