torgo

package module
v0.0.0-...-64d0194 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

README

GoDoc Go Report Card

torgo

The file magnet.go defines the behavior used to parse and download from a given magnet link. First, a magnet link must begin with the suffix magnet:?. If not, the package does not acknowledge that the provided link is a valid magnet link.

Every segment of the magnet link is separated by the character &. Each segment represent a key and a respective value in the form of key=value. At the moment the package searches for the keys represented in the list below.

  1. "dn" - Display Name
  2. "xt" - Exact Topic
  3. "xs" - Exact Source
  4. "tr" - Tracker
  5. "ws" - Web Seed
  6. "xl" - Exact Length

By getting each value for these keys we can build an instance of the type Magnet with the respective values. Later on this instace can be used to perform the actual download.

Parse of .torrent file or uri

This package supports the parsing of a .torrent file or an uri of a .torrent file. It starts by searching if the file can be found locally. If not will try to download and save it locally. Once this is complete we can beging parsing the file. .torrent files use an encoding known as bencode and because of this I make use of an external package to help with the parsing of each segment. Once this is done an instance of Torrent is created and later on can be used to perform the actual download.

Documentation

Index

Constants

View Source
const (
	//Display Name is a filename to display to the user, for convenience
	DisplayName = "dn"
	//Exact Topic is a URN containing file hash
	ExactTopic = "xt"
	//Exact Source is a P2P link identified by a content-hash
	ExactSource = "xs"
	//Tracker URL address for Bittorrent downloads
	Tracker = "tr"
	//Web seed is the payload data served over https
	WebSeed = "ws"
	//Exact length is the size in bytes
	ExactLength = "xl"
)
View Source
const (
	// MaxBlockSize is the largest number of bytes a request can ask for
	MaxBlockSize = 16384
	// MaxBacklog is the number of unfulfilled requests a client can have in its pipeline
	MaxBacklog = 5
)
View Source
const Port = 6881

Variables

This section is empty.

Functions

func Download

func Download(t interface{}, path string) ([]byte, error)

* Download the given torrent.

func Parse

func Parse(loc string) (interface{}, error)

* Parse a magnet link or a .torrent file. The .torrent file can be via url or a local file.

Types

type Magnet

type Magnet struct {
	Origin      string   //original uri
	DisplayName string   //dn
	Hash        string   //info hash
	Size        int      // size in bytes
	Xt          string   // exact topic
	Trackers    []string //tr
	Source      string
	Seed        string

	Creation float64
	PieceLen int
	Pieces   int
}

A Magnet represent the info present in a magnet URI.

func ParseMagnet

func ParseMagnet(uri string) (*Magnet, error)

Parse a magnet uri into a magnet struct

type Parselable

type Parselable interface {
	Parse(loc string) (interface{}, error)
}

Parselable represents a type that can perform the parse operation

type Torrent

type Torrent struct {
	Peers       []peers.Peer
	PeerID      []byte
	Announce    string
	InfoHash    [20]byte //hash from info struct
	PieceHashes [][20]byte
	PieceLength int
	Length      int
	Name        string
}

Torrent represents the info present in a.torrent file

func ParseTor

func ParseTor(loc string) (*Torrent, error)

func (*Torrent) RequestPeers

func (t *Torrent) RequestPeers(peerID []byte) ([]peers.Peer, error)

Directories

Path Synopsis
All of the remaining messages in the protocol take the form of <length prefix><message ID><payload>.
All of the remaining messages in the protocol take the form of <length prefix><message ID><payload>.

Jump to

Keyboard shortcuts

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