protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventNone      event = 0
	EventCompleted event = 1
	EventStarted   event = 2
	EventStopped   event = 3

	ActionConnect   Action = 0
	ActionAnnounce  Action = 1
	ActionScrape    Action = 2
	ActionError     Action = 3
	ActionHeartbeat Action = 4
)
View Source
const (
	UDPTrackerMagic = 0x41727101980
)

Variables

View Source
var (
	HeartbeatRequest = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(ActionHeartbeat), 0, 0, 0, 0}
	HeartbeatOk      = []byte{0xFF}
)

Functions

This section is empty.

Types

type Action

type Action int32

type Announce

type Announce struct {
	ConnectionID  int64
	Action        Action
	TransactionID int32
	InfoHash      storage.Hash
	PeerID        storage.PeerID
	Downloaded    int64
	Left          int64
	Uploaded      int64
	Event         event
	IP            uint32
	Key           uint32
	NumWant       int32
	Port          uint16
}

BitTorrent UDP tracker announce

func (*Announce) Marshall

func (a *Announce) Marshall() ([]byte, error)

Marshall encodes an Announce to a byte slice.

func (*Announce) Unmarshall

func (a *Announce) Unmarshall(data []byte) error

Unmarshall decodes a byte slice into an Announce.

type AnnounceResp

type AnnounceResp struct {
	Action        Action
	TransactionID int32
	Interval      int32
	Leechers      int32
	Seeders       int32
	Peers         []byte
}

BitTorrent UDP tracker announce response

func (*AnnounceResp) Marshall

func (ar *AnnounceResp) Marshall() ([]byte, error)

Marshall encodes an AnnounceResp to a byte slice.

func (*AnnounceResp) Unmarshall

func (ar *AnnounceResp) Unmarshall(data []byte) error

Unmarshall decodes a byte slice into an AnnounceResp.

type Connect

type Connect struct {
	ProtcolID     int64
	Action        Action
	TransactionID int32
}

BitTorrent UDP tracker connect

func (*Connect) Marshall

func (c *Connect) Marshall() ([]byte, error)

Marshall encodes a Connect to a byte slice.

func (*Connect) Unmarshall

func (c *Connect) Unmarshall(data []byte) error

Unmarshall decodes a byte slice into a Connect.

type ConnectResp

type ConnectResp struct {
	Action        Action
	TransactionID int32
	ConnectionID  int64
}

BitTorrent UDP tracker connect response

func (*ConnectResp) Marshall

func (cr *ConnectResp) Marshall() ([]byte, error)

Marshall encodes a ConnectResp to a byte slice.

func (*ConnectResp) Unmarshall

func (cr *ConnectResp) Unmarshall(data []byte) error

Unmarshall decodes a byte slice into a ConnectResp.

type Error

type Error struct {
	Action        Action
	TransactionID int32
	ErrorString   []uint8
}

BitTorrent UDP tracker server error

func (*Error) Marshall

func (e *Error) Marshall() ([]byte, error)

Marshall encodes an Error to a byte slice.

func (*Error) Unmarshall

func (e *Error) Unmarshall(data []byte) error

Unmarshall decodes a byte slice into an Error.

type Scrape

type Scrape struct {
	ConnectionID  int64
	Action        Action
	TransactionID int32
	InfoHashes    []storage.Hash
}

BitTorrent UDP tracker announce

func (*Scrape) Unmarshall

func (s *Scrape) Unmarshall(data []byte) error

Unmarshall decodes a byte slice into a Scrape.

type ScrapeInfo

type ScrapeInfo struct {
	Complete   int32
	Incomplete int32
	Downloaded int32
}

ScrapeInfo holds the information for each infohash in the scrape response

type ScrapeResp

type ScrapeResp struct {
	Action        Action
	TransactionID int32
	Info          []ScrapeInfo
}

BitTorrent UDP tracker scrape response

func (*ScrapeResp) Marshall

func (sr *ScrapeResp) Marshall() ([]byte, error)

Marshall encodes a ScrapeResp to a byte slice.

Jump to

Keyboard shortcuts

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