tracker

package module
v0.0.0-...-03636b4 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 15 Imported by: 0

README

tracker

This is a BitTorrent tracker that provides both an HTTP API index list and a UDP tracker for torrent clients.

Configuration

The tracker behavior is configured using environment variables:

Variable Description Example
BT_HTTP_ADDRESS The address the HTTP server binds to 0.0.0.0
BT_HTTP_PORT The port for the HTTP API 8080
BT_UDP_ADDRESS The address the UDP tracker binds to 0.0.0.0
BT_UDP_PORT The port for the UDP tracker 6118
BT_UDP_URL The full UDP tracker URL udp://localhost:6118/announce
CACHE_INTERVAL Cache update interval 60 (seconds)
PEER_INTERVAL Peer expiry check interval 1200 (seconds)
PEER_LIFETIME Peer expiry lifetime 3600 (seconds)

HTTP Server

The HTTP server provides a list of torrents and their peers.

{
   "ae4a048e19e6ed8ce31bc5a37f0ca03a533998a4":{
      "magnet":"magnet:?xt=urn:btih:ae4a048e19e6ed8ce31bc5a37f0ca03a533998a4\u0026tr=udp://127.0.0.1:6881",
      "completed":0,
      "peers":{
         "-TR3000-hi33owz1ajb7":{
            "downloaded":0,
            "left":0,
            "uploaded":0,
            "event":0
         },
         "-qB5040-1LwzYpZa67!D":{
            "downloaded":0,
            "left":0,
            "uploaded":0,
            "event":2
         }
      }
   },
   "ef278c16ebe1d63f5d1ea4d271a9a06d23a1f10b":{
      "magnet":"magnet:?xt=urn:btih:ef278c16ebe1d63f5d1ea4d271a9a06d23a1f10b\u0026tr=udp://127.0.0.1:6881",
      "completed":5,
      "peers":{
         "-qB5040-UIkh)Z270fKP":{
            "downloaded":0,
            "left":14128,
            "uploaded":0,
            "event":2
         }
      }
   }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfig

func NewConfig(httpAddress string, httpPort int, udpAddress string, udpPort int, udpURL string, cacheInterval, peerInterval, peerLifetime time.Duration) *config

func NewHTTPServer

func NewHTTPServer() *httpServer

func NewServer

func NewServer(conns Storer[uint64, time.Time], torrents Storer[InfoHash, *Torrent], cache Cacher[InfoHash, *Torrent]) (*server, error)

func NewUDPServer

func NewUDPServer() *udpServer

Types

type Cacher

type Cacher[K comparable, V any] interface {
	Get(key K) (V, bool)
	Freeze(s Storer[K, V])
	Size() int

	json.Marshaler
}

func NewCache

func NewCache[K comparable, V any]() Cacher[K, V]

type InfoHash

type InfoHash [20]byte

func (InfoHash) MarshalText

func (h InfoHash) MarshalText() (text []byte, err error)

type Peer

type Peer struct {
	Downloaded uint64    `json:"downloaded"`
	Left       uint64    `json:"left"`
	Uploaded   uint64    `json:"uploaded"`
	Event      uint32    `json:"event"`
	IP         uint32    `json:"ip"`
	Port       uint16    `json:"port"`
	Key        uint32    `json:"key"`
	Time       time.Time `json:"time"`
}

func (*Peer) MarshalJSON

func (p *Peer) MarshalJSON() ([]byte, error)

type PeerID

type PeerID [20]byte

func (PeerID) MarshalText

func (h PeerID) MarshalText() (text []byte, err error)

type Serverer

type Serverer interface {
	Serve(config *config, state chan any, conns Storer[uint64, time.Time], torrents Storer[InfoHash, *Torrent], cache Cacher[InfoHash, *Torrent])
}

type Storer

type Storer[K comparable, V any] interface {
	Set(key K, value V)
	Get(key K) (V, bool)
	Delete(key K)
	Map(fn func(K, V))

	json.Marshaler
}

func NewStore

func NewStore[K comparable, V any]() Storer[K, V]

type Torrent

type Torrent struct {
	InfoHash  InfoHash         `json:"-"`
	Magnet    string           `json:"magnet"`
	Completed uint32           `json:"completed"`
	Peers     map[PeerID]*Peer `json:"peers"`
}

func NewTorrent

func NewTorrent(infoHash InfoHash, config *config) *Torrent

func (*Torrent) MarshalJSON

func (t *Torrent) MarshalJSON() ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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