torrent

package
v0.0.0-...-33669ff Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2018 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerbNormal  = Verbosity(0)
	VerbVerbose = Verbosity(1)
	VerbDebug   = Verbosity(2)
)
View Source
const PIECE_LENGTH = int64(256 * 1024)

256kb is now the pseudo-standard for BT pieces and is reasonable (metadata file is ~1MB for an 8GB file being served).

Variables

This section is empty.

Functions

func LogDebug

func LogDebug(fmt string, args ...interface{})

func LogError

func LogError(fmt string, args ...interface{})

func LogFatal

func LogFatal(fmt string, args ...interface{})

func LogInfo

func LogInfo(fmt string, args ...interface{})

func LogWarning

func LogWarning(fmt string, args ...interface{})

func SetLoggingVerbosity

func SetLoggingVerbosity(level Verbosity)

Types

type Distributor

type Distributor struct {
	// contains filtered or unexported fields
}

func NewDistributor

func NewDistributor(
	dir string,
	ctorrentPath string,
	address string,
	port int,
	verbosity Verbosity) (*Distributor, error)

func (*Distributor) Close

func (dist *Distributor) Close()

func (*Distributor) Run

func (dist *Distributor) Run()

func (*Distributor) Start

func (dist *Distributor) Start()

func (*Distributor) Wait

func (dist *Distributor) Wait()

type File

type File struct {
	Name         string        // Base filename.
	FQFN         string        // Path + filename.
	Size         int64         // File size.
	ModTime      time.Time     // Modification time.
	MetadataInfo *MetadataInfo // Reference to our metadata.
	SeedCommand  *exec.Cmd     // Owned by the Tracker methods.
	Lock         sync.Mutex
}

File represents a single file that we are serving. These are read by other parts of the system but only written by this module.

type Metadata

type Metadata struct {
	Announce string       `announce` // URL of our tracker.
	Info     MetadataInfo `info`
}

type MetadataInfo

type MetadataInfo struct {
	Name        string `name`         // Filename.
	PieceLength int    `piece length` // Size of pieces.
	Pieces      string `pieces`       // The actual pieces data.
	Length      int64  `length`
}

func GenerateMetadataInfo

func GenerateMetadataInfo(fqfn string) (*MetadataInfo, error)

GenerateMetadata takes a file and generates the metadata required to serve that file.

type Peer

type Peer struct {
	Id   string `peer id`
	Ip   string `ip`
	Port uint16 `port`
}

type PeerResponse

type PeerResponse struct {
	Interval int    `interval`
	Peers    []Peer `peers`
}

type Tracker

type Tracker struct {
	// We keep a separate set of peers for each info_hash. We don't actually verify that these
	// hashes are valid; so there's a pretty easy DoS here. This system is designed to be used
	// in a production environment with good actors. TODO: harden.
	// TODO: We need a way of droppign peers that have not reported in a while.
	PeerSeen map[string]map[string]time.Time
	PeerList map[string]map[string]Peer
	// contains filtered or unexported fields
}

func StartTracker

func StartTracker(ip string, port int,
	ctorrentPath string,
	watchers map[string]*Watcher) *Tracker

starTracker spins up a tracker on a given ip:port for the given set of watchers.

type Verbosity

type Verbosity uint32
var VERBOSITY Verbosity = VerbNormal

type Watcher

type Watcher struct {
	Watcher     *fsnotify.Watcher
	Directory   string
	Files       map[string]*File // FQFN as key.
	FilesLock   sync.Mutex
	QuitChannel chan bool
}

Watcher is instantiated for each directory we're serving files for.

func StartWatcher

func StartWatcher(dir string) *Watcher

startWatcher creates a watcher for a given directory and starts watching it.

func (*Watcher) Close

func (w *Watcher) Close()

func (*Watcher) GetFile

func (self *Watcher) GetFile(name string) *File

GetFile returns, given a full path filename, either a pointer to a valid file structure or a nil if there is no file with that name.

func (*Watcher) GetFiles

func (self *Watcher) GetFiles() []*File

GetFiles returns a list of all files in this directory; if no files exist, returns an empty list

Jump to

Keyboard shortcuts

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