Documentation
¶
Index ¶
- Constants
- Variables
- func CopyPieceData(index int, buf []byte, msg *PeerMsg) (int, error)
- func GetHaveIndex(msg *PeerMsg) (int, error)
- type Bitfield
- type Peer
- type PeerConn
- type PeerMsg
- type PeerMsgTyep
- type Process
- type TMF_TYPE
- type Task
- type TaskState
- type TorrentFile
- type TorrentInfo
- type TorrentMutiFile
- type TrackerResp
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 GetHaveIndex ¶
Types ¶
type PeerConn ¶
type PeerConn struct { net.Conn Choked bool PiecesMap Bitfield // contains filtered or unexported fields }
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 ¶
func NewProcess ¶
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 ¶
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 ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.