redis

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: BSD-2-Clause Imports: 18 Imported by: 0

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

View Source
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

func InfoHashKey(infoHash string, seeder, v6 bool) (infoHashKey string)

InfoHashKey generates redis key for provided hash and flags

func NoResultErr added in v0.0.4

func NoResultErr(err error) error

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

func (Config) Validate

func (cfg Config) Validate() (Config, error)

Validate sanity checks values set in a config and returns a new config with default values replacing anything that is invalid.

This function warns to the logger when a value is changed.

type Connection

type Connection struct {
	redis.UniversalClient
}

Connection is wrapper for redis.UniversalClient

func (*Connection) Contains

func (ps *Connection) Contains(ctx context.Context, storeCtx string, key string) (bool, error)

Contains - storage.DataStorage implementation

func (*Connection) Delete

func (ps *Connection) Delete(ctx context.Context, storeCtx string, keys ...string) (err error)

Delete - storage.DataStorage implementation

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) Load

func (ps *Connection) Load(ctx context.Context, storeCtx string, key string) (v []byte, err error)

Load - storage.DataStorage implementation

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

Jump to

Keyboard shortcuts

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