borrentlib

package
v0.0.0-...-6a3345d Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialPeerTCP

func DialPeerTCP(peerInfo PeerInfoExt) (net.Conn, error)

DialPeerTCP ...

func DownloadTorrentFile

func DownloadTorrentFile(tf TorrentFile, peerCount int)

func PeerHandshake

func PeerHandshake(conn net.Conn, infoHash []byte, myPeerID string) (handshake, error)

PeerHandshake ...

func PeerWorker

func PeerWorker(infoHash []byte, ownPeerID string, peerInfo PeerInfoExt, jobs chan PeerWorkerJob, results chan<- PeerWorkerResult)

func ReadMessage

func ReadMessage(buf io.Reader) (message torrentMessage, err error)

ReadMessage reads all other messages which are not handshake

func WriteMessage

func WriteMessage(buf io.Writer, message torrentMessage) (err error)

WriteMessage ...

Types

type Bitfield

type Bitfield struct {
	Bitfield []byte
}

func (Bitfield) WriteTo

func (msg Bitfield) WriteTo(w io.Writer) error

type Choke

type Choke struct {
}

func (Choke) WriteTo

func (msg Choke) WriteTo(w io.Writer) error

type ChunkPersister

type ChunkPersister interface {
	PersistChunk(idx uint32, offset uint32, data []byte) error
	ReadChunkHash(idx uint32) ([]byte, error)
	Close() error
}

type DataFileInfo

type DataFileInfo struct {
	Name         string
	Length       uint64
	PieceLength  uint64
	PiecesHashes [][]byte // contains hashes of each piece in bytes array
}

DataFileInfo is an information about a particular data file in a torrent

type Interested

type Interested struct {
}

func (Interested) WriteTo

func (msg Interested) WriteTo(w io.Writer) error

type PeerConnectionInfo

type PeerConnectionInfo struct {
	AmChoking      int
	AmInterested   int
	PeerChoking    int
	PeerInterested int
}

PeerConnectionInfo ...

func NewPeerConnectionInfo

func NewPeerConnectionInfo() PeerConnectionInfo

NewPeerConnectionInfo ...

type PeerInfoExt

type PeerInfoExt struct {
	PeerID string `bencode:"peer id"`
	IP     string `bencode:"ip"`
	Port   int    `bencode:"port"`
}

PeerInfoExt ...

type PeerState

type PeerState struct {
	PeerConnectionInfo
	// contains filtered or unexported fields
}

type PeerWorkerJob

type PeerWorkerJob struct {
	ChunkIndex  uint32
	ChunkOffset uint32
	ChunkLength uint32
}

type PeerWorkerResult

type PeerWorkerResult struct {
	Job    PeerWorkerJob
	Status bool
	Chunk  []byte
}

type Piece

type Piece struct {
	Index uint32
	Begin uint32
	Block []byte
}

func (Piece) WriteTo

func (msg Piece) WriteTo(w io.Writer) error

type Request

type Request struct {
	Index  uint32
	Begin  uint32
	Length uint32
}

func (Request) WriteTo

func (msg Request) WriteTo(w io.Writer) error

type SparseFileDiskChunkPersister

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

func InitSparseFileDiskChunkPersister

func InitSparseFileDiskChunkPersister(fileName string, size uint32, chunkSize uint32) (p *SparseFileDiskChunkPersister, err error)

func (*SparseFileDiskChunkPersister) Close

func (p *SparseFileDiskChunkPersister) Close() (err error)

func (*SparseFileDiskChunkPersister) PersistChunk

func (p *SparseFileDiskChunkPersister) PersistChunk(idx uint32, offset uint32, data []byte) error

func (*SparseFileDiskChunkPersister) ReadChunkHash

func (p *SparseFileDiskChunkPersister) ReadChunkHash(idx uint32) ([]byte, error)

type TorrentFile

type TorrentFile struct {
	AnnounceURL string
	InfoHash    []byte       // InfoHash is a unique torrent ID, 20 bytes of SHA-1 hash
	FileInfo    DataFileInfo // Only single-file torrents are suppoted right now
}

TorrentFile is a torrent file descriptor struct

func DecodeTorrentFile

func DecodeTorrentFile(r io.Reader) (result TorrentFile, err error)

DecodeTorrentFile - decode .torrent file into go structs

type TrackerResponce

type TrackerResponce struct {
	FailureReason string        `bencode:"failure reason"`
	Interval      int           `bencode:"interval"`
	Complete      int           `bencode:"complete"`
	Incomplete    int           `bencode:"incomplete"`
	Peers         []PeerInfoExt `bencode:"peers"`
}

TrackerResponce ...

func AnnounceMyself

func AnnounceMyself(torrentFile TorrentFile) (peerID string, responce TrackerResponce, err error)

AnnounceMyself - generate a random peerId & perform an announce get Request to the tracker. Returns generated peerId

type Unchoke

type Unchoke struct {
}

func (Unchoke) WriteTo

func (msg Unchoke) WriteTo(w io.Writer) error

Jump to

Keyboard shortcuts

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