Documentation ¶
Index ¶
- Constants
- func AnnounceHandler(server *Server) http.HandlerFunc
- func HealthHandler() http.HandlerFunc
- func IndexHandler(server *Server) http.HandlerFunc
- func NewTemplateStore() *templateStore
- func NewTorrentStore(pool *pgxpool.Pool) *torrentStore
- func PlaintextMiddleware(next http.Handler) http.Handler
- func ScrapeHandler(server *Server) http.HandlerFunc
- func TorrentHandler(server *Server) http.HandlerFunc
- type AnnounceRequest
- type AnnounceResponse
- type ErrorResponse
- type Peer
- type ScrapeResponse
- type ScrapeTorrent
- type Server
- type ServerConfig
- type TemplateID
- type Templater
- type Torrent
- type TorrentStorable
Constants ¶
View Source
const ( TemplateIndex = iota TemplateTorrent )
Variables ¶
This section is empty.
Functions ¶
func AnnounceHandler ¶
func AnnounceHandler(server *Server) http.HandlerFunc
func HealthHandler ¶
func HealthHandler() http.HandlerFunc
func IndexHandler ¶
func IndexHandler(server *Server) http.HandlerFunc
func NewTorrentStore ¶
func PlaintextMiddleware ¶
Middleware for setting Content-Type to charset=ISO-8859-1.
func ScrapeHandler ¶
func ScrapeHandler(server *Server) http.HandlerFunc
func TorrentHandler ¶
func TorrentHandler(server *Server) http.HandlerFunc
Types ¶
type AnnounceRequest ¶
type AnnounceRequest struct { InfoHash []byte `db:"info_hash" validate:"required,ascii"` PeerID []byte `db:"peer_id" validate:"required,ascii,len=20"` Event string `db:"event" validate:"ascii"` IP string `db:"ip" validate:"required,ip"` Port int `db:"port" validate:"required,number"` Key string `db:"key" validate:"ascii"` Uploaded int `db:"uploaded" validate:"number"` Downloaded int `db:"downloaded" validate:"number"` Left int `db:"left" validate:"number"` }
type AnnounceResponse ¶
type ErrorResponse ¶
type ErrorResponse struct {
FailureReason string `bencode:"failure reason"`
}
type Peer ¶
type Peer struct { ID uuid.UUID `db:"id"` TorrentID uuid.UUID `db:"torrent_id"` PeerID []byte `db:"peer_id"` Port int `db:"port"` Uploaded int `db:"uploaded"` Downloaded int `db:"downloaded"` Left int `db:"left"` Key string `db:"key"` IP net.IP `db:"ip"` UpdatedAt time.Time `db:"updated_at"` Event string `db:"event"` }
type ScrapeResponse ¶
type ScrapeResponse struct {
Files map[string]ScrapeTorrent `bencode:"files"`
}
type ScrapeTorrent ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(config *ServerConfig) *Server
func (*Server) CacheTemplates ¶
func (sv *Server) CacheTemplates()
type ServerConfig ¶
func NewServerConfig ¶
func NewServerConfig(address string, announceURL string, dsn string, templatePath string) *ServerConfig
type TemplateID ¶
type TemplateID int
type Templater ¶
type Templater interface { // Add template to cache. Add(ID TemplateID, template *template.Template) // Execute template from cache using data. Execute(ID TemplateID, wr io.Writer, data any) error }
type Torrent ¶
type Torrent struct { ID uuid.UUID `db:"id" json:"id"` InfoHash []byte `db:"info_hash" json:"info_hash"` Completed int `db:"completed" json:"completed"` CreatedAt time.Time `db:"created_at" json:"created_at"` Seeders int `db:"seeders" json:"seeders"` Leechers int `db:"leechers" json:"leechers"` }
func (*Torrent) MarshalJSON ¶
type TorrentStorable ¶
type TorrentStorable interface { // Add torrent to store. AddTorrent(ctx context.Context, infoHash []byte) (Torrent, error) // Get torrent from store. Torrent(ctx context.Context, infoHash []byte) (Torrent, error) // Increments torrentID completed property by one. IncrementTorrent(ctx context.Context, torrentID uuid.UUID) error // Get all torrents in store. Torrents(ctx context.Context) ([]Torrent, error) Scrape(ctx context.Context, hashes [][]byte) ([]Torrent, error) // Get all peers for torrentID. Peers(ctx context.Context, torrentID uuid.UUID) ([]Peer, error) // Try to update peer which already exist in the store. // Operation success is denoted by bool. UpdatePeerWithKey(ctx context.Context, torrentID uuid.UUID, req AnnounceRequest) (bool, error) // Update or insert peer to store. UpsertPeer(ctx context.Context, torrentID uuid.UUID, req AnnounceRequest) error // Remove stale peers that have not announced in interval. CleanPeers(ctx context.Context, interval time.Duration) (int, error) // Log announce request. Log(ctx context.Context, req AnnounceRequest) error // Test store connection. Ping(ctx context.Context) (bool, error) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.