models

package
v0.0.0-...-cb1d36a Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const InfohashLength = 20

Variables

This section is empty.

Functions

func InfohashMatchesMetadata

func InfohashMatchesMetadata(ih Infohash, md []byte) bool

Types

type File

type File struct {
	ID        int    `json:"-"`
	Path      string `json:"path"`
	Size      int    `json:"size"`
	TorrentID int    `json:"torrent_id" db:"torrent_id"`
}

type Infohash

type Infohash []byte

Infohash is a 160 bit (20 byte) value

func GenInfohash

func GenInfohash() (ih Infohash)

func GenerateNeighbour

func GenerateNeighbour(first, second Infohash) Infohash

func InfohashFromString

func InfohashFromString(s string) (*Infohash, error)

InfohashFromString converts a 40 digit hexadecimal string to an Infohash

func (Infohash) Bytes

func (ih Infohash) Bytes() []byte

func (Infohash) Distance

func (ih Infohash) Distance(other Infohash) int

Distance determines the distance to another infohash as an integer

func (Infohash) Equal

func (ih Infohash) Equal(other Infohash) bool

func (Infohash) String

func (ih Infohash) String() string

func (Infohash) Valid

func (ih Infohash) Valid() bool

type InfohashStore

type InfohashStore interface {
	PendingInfohashes(int) ([]*Peer, error)
}

type Peer

type Peer struct {
	Addr     net.Addr  `db:"address"`
	Infohash Infohash  `db:"infohash"`
	Created  time.Time `db:"created" json:"created"`
	Updated  time.Time `db:"updated" json:"updated"`
}

Peer on DHT network

func (Peer) String

func (p Peer) String() string

String implements fmt.Stringer

type PeerStore

type PeerStore interface {
	SavePeer(*Peer) error
	RemovePeer(*Peer) error
}

type Torrent

type Torrent struct {
	ID       int       `json:"-"`
	Infohash Infohash  `json:"infohash"`
	Name     string    `json:"name"`
	Files    []File    `json:"files" db:"-"`
	Size     int       `json:"size"`
	Updated  time.Time `json:"updated"`
	Created  time.Time `json:"created"`
	Tags     []string  `json:"tags" db:"-"`
}

Data for persistent storage

func TorrentFromMetadata

func TorrentFromMetadata(ih Infohash, md []byte) (*Torrent, error)

type TorrentStore

type TorrentStore interface {
	SaveTorrent(*Torrent) error
	RemoveTorrent(*Torrent) error
	RemovePeer(*Peer) error
}

Jump to

Keyboard shortcuts

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