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 ¶
- Variables
- type Pool
- type Tx
- func (tx *Tx) AddLeecher(torrent *models.Torrent, peer *models.Peer) error
- func (tx *Tx) AddSeeder(torrent *models.Torrent, peer *models.Peer) error
- func (tx *Tx) AddTorrent(t *models.Torrent) error
- func (tx *Tx) AddUser(u *models.User) error
- func (tx *Tx) ClientWhitelisted(peerID string) (exists bool, err error)
- func (tx *Tx) DecrementSlots(u *models.User) error
- func (tx *Tx) FindTorrent(infohash string) (*models.Torrent, bool, error)
- func (tx *Tx) FindUser(passkey string) (*models.User, bool, error)
- func (tx *Tx) IncrementSlots(u *models.User) error
- func (tx *Tx) LeecherFinished(torrent *models.Torrent, peer *models.Peer) error
- func (tx *Tx) MarkActive(torrent *models.Torrent) error
- func (tx *Tx) MarkInactive(torrent *models.Torrent) error
- func (tx *Tx) RecordSnatch(user *models.User, torrent *models.Torrent) error
- func (tx *Tx) RemoveLeecher(t *models.Torrent, p *models.Peer) error
- func (tx *Tx) RemoveSeeder(t *models.Torrent, p *models.Peer) error
- func (tx *Tx) RemoveTorrent(t *models.Torrent) error
- func (tx *Tx) RemoveUser(u *models.User) error
- func (tx *Tx) SetLeecher(t *models.Torrent, p *models.Peer) error
- func (tx *Tx) SetSeeder(t *models.Torrent, p *models.Peer) error
- func (tx *Tx) UnWhitelistClient(peerID string) error
- func (tx *Tx) WhitelistClient(peerID string) error
Constants ¶
This section is empty.
Variables ¶
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 Tx ¶
func (*Tx) AddLeecher ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
IncrementSlots increment a user's Slots by one. This function modifies the argument as well as the hash field in Redis.
func (*Tx) FindTorrent ¶
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 ¶
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 ¶
IncrementSlots increment a user's Slots by one. This function modifies the argument as well as the hash field in Redis.
func (*Tx) LeecherFinished ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
RemoveUser removes the user's hash from Redis. This function does not return an error if the user doesn't exist.
func (*Tx) SetLeecher ¶
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 ¶
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 ¶
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 ¶
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.