Documentation ¶
Overview ¶
Package redis implements the storage interface. BitTorrent tracker keeping peer data in redis with hash. There three categories of hash:
CHI_{L,S}{4,6}_<HASH> (hash type) To save peers that hold the infohash, used for fast searching, deleting, and timeout handling
CHI_I (set type) To save all the infohashes, used for garbage collection, metrics aggregation and leecher graduation
CHI_D (hash type) To record the number of torrent downloads.
Two keys are used to record the count of seeders and leechers.
CHI_C_S (key type) To record the number of seeders.
CHI_C_L (key type) To record the number of leechers.
Index ¶
- Constants
- func InfoHashKey(infoHash string, seeder, v6 bool) (infoHashKey string)
- func NoResultErr(err error) error
- func PackPeer(p bittorrent.Peer) string
- func UnpackPeer(data string) (bittorrent.Peer, error)
- type Config
- type Connection
- func (ps *Connection) Contains(ctx context.Context, storeCtx string, key string) (bool, error)
- func (ps *Connection) Delete(ctx context.Context, storeCtx string, keys ...string) (err error)
- func (ps *Connection) GetPeers(ctx context.Context, ih bittorrent.InfoHash, forSeeder bool, maxCount int, ...) (out []bittorrent.Peer, err error)
- func (ps *Connection) Load(ctx context.Context, storeCtx string, key string) (v []byte, err error)
- func (ps *Connection) Ping(ctx context.Context) error
- func (*Connection) Preservable() bool
- func (ps *Connection) Put(ctx context.Context, storeCtx string, values ...storage.Entry) (err error)
- func (ps *Connection) ScrapeIH(ctx context.Context, ih bittorrent.InfoHash, countFn getPeerCountFn) (leechersCount, seedersCount, downloadsCount uint32, err error)
Constants ¶
const ( // PrefixKey prefix which will be prepended to ctx argument in storage.DataStorage calls PrefixKey = "CHI_" // IHKey redis hash key for all info hashes IHKey = "CHI_I" // IH4SeederKey redis hash key prefix for IPv4 seeders IH4SeederKey = "CHI_S4_" // IH6SeederKey redis hash key prefix for IPv6 seeders IH6SeederKey = "CHI_S6_" // IH4LeecherKey redis hash key prefix for IPv4 leechers IH4LeecherKey = "CHI_L4_" // IH6LeecherKey redis hash key prefix for IPv6 leechers IH6LeecherKey = "CHI_L6_" // CountSeederKey redis key for seeder count CountSeederKey = "CHI_C_S" // CountLeecherKey redis key for leecher count CountLeecherKey = "CHI_C_L" // CountDownloadsKey redis key for snatches (downloads) count CountDownloadsKey = "CHI_D" )
Variables ¶
This section is empty.
Functions ¶
func InfoHashKey ¶
InfoHashKey generates redis key for provided hash and flags
func NoResultErr ¶ added in v0.0.4
NoResultErr returns nil if provided err is redis.Nil otherwise returns err
func PackPeer ¶ added in v0.0.4
func PackPeer(p bittorrent.Peer) string
PackPeer generates concatenation of PeerID, net port and IP-address
func UnpackPeer ¶ added in v0.0.4
func UnpackPeer(data string) (bittorrent.Peer, error)
UnpackPeer constructs Peer from serialized by Peer.PackPeer data: PeerID[20by]Port[2by]net.IP[4/16by]
Types ¶
type Config ¶
type Config struct { PeerLifetime time.Duration `cfg:"peer_lifetime"` Addresses []string DB int PoolSize int `cfg:"pool_size"` Login string Password string Sentinel bool SentinelMaster string `cfg:"sentinel_master"` Cluster bool ReadTimeout time.Duration `cfg:"read_timeout"` WriteTimeout time.Duration `cfg:"write_timeout"` ConnectTimeout time.Duration `cfg:"connect_timeout"` }
Config holds the configuration of a redis PeerStorage.
func (Config) Connect ¶
func (cfg Config) Connect() (con Connection, err error)
Connect creates redis client from configuration
type Connection ¶
type Connection struct {
redis.UniversalClient
}
Connection is wrapper for redis.UniversalClient
func (*Connection) GetPeers ¶
func (ps *Connection) GetPeers(ctx context.Context, ih bittorrent.InfoHash, forSeeder bool, maxCount int, isV6 bool, membersFn getPeersFn) (out []bittorrent.Peer, err error)
GetPeers retrieves peers for provided info hash by calling membersFn and converts result to bittorrent.Peer array. If forSeeder set to true - returns only leechers, if false - seeders and if maxCount not reached - leechers.
func (*Connection) Ping ¶ added in v0.0.2
func (ps *Connection) Ping(ctx context.Context) error
Ping sends `PING` request to Redis server
func (*Connection) Preservable ¶
func (*Connection) Preservable() bool
Preservable - storage.DataStorage implementation
func (*Connection) Put ¶
func (ps *Connection) Put(ctx context.Context, storeCtx string, values ...storage.Entry) (err error)
Put - storage.DataStorage implementation
func (*Connection) ScrapeIH ¶ added in v0.0.3
func (ps *Connection) ScrapeIH(ctx context.Context, ih bittorrent.InfoHash, countFn getPeerCountFn) ( leechersCount, seedersCount, downloadsCount uint32, err error, )
ScrapeIH calls provided countFn and returns seeders, leechers and downloads count for specified info hash