backend

package
v0.0.0-...-c57407d Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: BSD-2-Clause Imports: 3 Imported by: 0

README

Implementing a Driver

The backend package is meant to provide announce deltas to a slower and more consistent database, such as the one powering a torrent-indexing website. Implementing a backend driver is heavily inspired by the standard library's database/sql package: simply create a package that implements the backend.Driver and backend.Conn interfaces and calls backend.Register in it's init(). Please note that backend.Conn must be thread-safe. A great place to start is to read the no-op driver which comes out-of-the-box with Chihaya and is meant to be used for public trackers.

Creating a binary with your own driver

Chihaya is designed to be extended. If you require more than the drivers provided out-of-the-box, you are free to create your own and then produce your own custom Chihaya binary. To create this binary, simply create your own main package, import your custom drivers, then call chihaya.Boot from main.

Example
package main

import (
	"github.com/chihaya/chihaya"

  // Import any of your own drivers.
	_ "github.com/yourusername/chihaya-custom-backend"
)

func main() {
  // Start Chihaya normally.
	chihaya.Boot()
}

Documentation

Overview

Package backend provides a generic interface for manipulating a BitTorrent tracker's consistent backend data store (usually for a web application).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, driver Driver)

Register makes a database driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type Conn

type Conn interface {
	// Close terminates connections to the database(s) and gracefully shuts
	// down the driver
	Close() error

	// Ping just checks to see if the database is still alive. This is typically
	// used for health checks.
	Ping() error

	// RecordAnnounce is called once per announce, and is passed the delta in
	// statistics for the client peer since its last announce.
	RecordAnnounce(delta *models.AnnounceDelta) error

	// LoadTorrents fetches and returns the specified torrents.
	LoadTorrents(ids []uint64) ([]*models.Torrent, error)

	// LoadUsers fetches and returns the specified users.
	LoadUsers(ids []uint64) ([]*models.User, error)

	// Get user given a user's passkey
	GetUserByPassKey(passkey string) (*models.User, error)

	// get a torrent given its infohash
	// doesn't load info or peer
	GetTorrentByInfoHash(infohash string) (*models.Torrent, error)

	// delete a torrent from the database
	DeleteTorrent(torrent *models.Torrent) error

	// add a torrent to the database
	AddTorrent(torrent *models.Torrent) error

	// add a user to the database
	AddUser(user *models.User) error

	// delete a user from the database
	DeleteUser(user *models.User) error
}

Conn represents a connection to the data store.

func Open

func Open(cfg *config.DriverConfig) (Conn, error)

Open creates a connection specified by a configuration.

type Driver

type Driver interface {
	New(*config.DriverConfig) (Conn, error)
}

Driver represents an interface to a long-running connection with a consistent data store.

Directories

Path Synopsis
Package noop implements a Chihaya backend storage driver as a no-op.
Package noop implements a Chihaya backend storage driver as a no-op.
package uguu implements uguu-tracker storage driver using postgres
package uguu implements uguu-tracker storage driver using postgres

Jump to

Keyboard shortcuts

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