storage

package
Version: v0.0.0-...-6d86915 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2017 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInfoData = errors.New("storage: invalid info data")

ErrInvalidInfoData is the error returned when invalid info data provided.

View Source
var ErrInvalidPeerData = errors.New("storage: invalid peer data")

ErrInvalidPeerData is the error returned when invalid peer data provided.

View Source
var ErrTorrentNotFound = errors.New("storage: torrent not found")

ErrTorrentNotFound is the error returned when torrent not found.

Functions

This section is empty.

Types

type Info

type Info struct {
	Hash       []byte // 20 bytes
	Incomplete uint32
	Complete   uint32
	Downloaded uint32
	Name       []byte
}

Info torrent info struct

func (*Info) Marshal

func (i *Info) Marshal() []byte

Marshal marshals a torrent Info to a byte slice

func (*Info) Unmarshal

func (i *Info) Unmarshal(data []byte) error

Unmarshal unmarshals data to a torrent Info.

type Peer

type Peer struct {
	ID         []byte // 20 bytes
	Uploaded   uint64
	Downloaded uint64
	Left       uint64
	IP         []byte // 4 bytes
	Port       uint16
	Key        []byte
	LastUpdate time.Time
}

Peer info struct

func (*Peer) Marshal

func (p *Peer) Marshal() []byte

Marshal marshals a Peer to a byte slice

func (*Peer) Unmarshal

func (p *Peer) Unmarshal(data []byte) error

Unmarshal unmarshals data to a Peer.

type Storage

type Storage interface {
	// GetInfo returns torrent info by infoHash.
	GetInfo([]byte) (*Info, error)

	// SetInfo store torrent info.
	SetInfo(*Info) error

	// SetPeer store peer identified by infoHash.
	SetPeer([]byte, *Peer) error

	// GetActivePeers returns active peers for torrent by infoHash.
	GetActivePeers([]byte) ([]*Peer, error)
}

Storage interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL