dgotorrent

package module
v0.0.0-...-96994e7 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 20 Imported by: 0

README

dgo-torrent

Documentation

Index

Constants

View Source
const (
	BLOCKSIZE  = 16384
	MAXBACKLOG = 5
)
View Source
const (
	TMF_TYPE_DIRECTORY = iota
	TMF_TYPE_FILE
)
View Source
const INFO_HASH_LEN = 20
View Source
const IP_LEN = 4

ip_len:4 port_len:2

View Source
const PEER_ID_LEN = 20
View Source
const PEER_LEN = IP_LEN + PORT_LEN
View Source
const PIECE_LEN = 20
View Source
const PORT_LEN = 2

Variables

View Source
var (
	ErrInvalidTorrentFile = errors.New("invalid torrent file")
)
View Source
var (
	ErrInvalidTrackerResp = errors.New("invalid tracker resp")
)

Functions

func CopyPieceData

func CopyPieceData(index int, buf []byte, msg *PeerMsg) (int, error)

func GetHaveIndex

func GetHaveIndex(msg *PeerMsg) (int, error)

Types

type Bitfield

type Bitfield []byte

func (Bitfield) Set

func (field Bitfield) Set(index int)

func (Bitfield) Test

func (field Bitfield) Test(index int) bool

type Peer

type Peer struct {
	IP   net.IP
	Port uint16
}

type PeerConn

type PeerConn struct {
	net.Conn
	Choked    bool
	PiecesMap Bitfield
	// contains filtered or unexported fields
}

func NewConn

func NewConn(peer Peer, infoHash [INFO_HASH_LEN]byte, peerID string) (*PeerConn, error)

func (*PeerConn) ReadMsg

func (c *PeerConn) ReadMsg() (*PeerMsg, error)

func (*PeerConn) WriteMsg

func (c *PeerConn) WriteMsg(msg *PeerMsg) (int, error)

type PeerMsg

type PeerMsg struct {
	Type    PeerMsgTyep
	Payload []byte
}

func NewRequestMsg

func NewRequestMsg(index, offset, length int) *PeerMsg

type PeerMsgTyep

type PeerMsgTyep uint8
const (
	// enable upload
	PEER_MSG_TYPE_CHOKE PeerMsgTyep = iota
	// disbale upload
	PEER_MSG_TYPE_UNCHOKE
	// enable download
	PEER_MSG_TYPE_INTERESTED
	// disable download
	PEER_MSG_TYPE_NOT_INTEREST
	// update bitfieled
	PEER_MSG_TYPE_HAVE
	// bitfieled
	PEER_MSG_TYPE_BITFIELED
	// download request
	PEER_MSG_TYPE_REQUEST
	// pirece data
	PEER_MSG_TYPE_PIECE
	PEER_MSG_TYPE_CANCEL
	PEER_MSG_TYPE_KEEP_ALIVE
	PEER_MSG_INVALID
)

type Process

type Process struct {
	Task  *Task
	Peers []Peer
}

func NewProcess

func NewProcess(task *Task) *Process

func (*Process) Start

func (p *Process) Start() error

type TMF_TYPE

type TMF_TYPE uint8

type Task

type Task struct {
	ID        int
	Name      string
	Path      string
	Status    map[string]any
	State     TaskState
	CreatedAt time.Time
	UpdatedAt time.Time
	PeerID    string
	Torrent   TorrentFile
}

func NewTask

func NewTask(tf TorrentFile) (Task, error)

func (*Task) GetPieceBounds

func (t *Task) GetPieceBounds(index int) (begin, end int)

type TaskState

type TaskState uint8
const (
	TASK_STATE_PAUSED TaskState = iota
	TASK_STATE_DOWNLOADING
	TASK_STATE_COMPLETE
	TASK_STATE_DELETE
)

type TorrentFile

type TorrentFile struct {
	Announce     string
	AnnounceList []string
	Comment      string
	CreatedBy    string
	CreatedAt    int64
	Info         TorrentInfo
}

func NewTorrentFile

func NewTorrentFile(r io.Reader) (*TorrentFile, error)

func (*TorrentFile) FindPeers

func (tf *TorrentFile) FindPeers() ([]Peer, error)

func (*TorrentFile) RequestTrackers

func (tf *TorrentFile) RequestTrackers() ([]TrackerResp, error)

type TorrentInfo

type TorrentInfo struct {
	Name        string
	IsMutiFile  bool
	Length      int64
	MutiFiles   TorrentMutiFile
	PieceLength int64
	PieceHashes [][PIECE_LEN]byte
	Hash        [INFO_HASH_LEN]byte
}

type TorrentMutiFile

type TorrentMutiFile struct {
	Type      TMF_TYPE
	Name      string
	Length    int64
	Subs      map[string]TorrentMutiFile
	SubsOrder []string
}

type TrackerResp

type TrackerResp struct {
	Complete    int64  `bencode:"complete"`
	Downloaded  int64  `bencode:"downloaded"`
	Incomplete  int64  `bencode:"incomplete"`
	Interval    int64  `bencode:"interval"`
	MinInterval int64  `bencode:"min interval"`
	Peers       []byte `bencode:"peers"`
}

Directories

Path Synopsis
bin
cmd

Jump to

Keyboard shortcuts

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