Documentation ¶
Index ¶
- func DialPeerTCP(peerInfo PeerInfoExt) (net.Conn, error)
- func DownloadTorrentFile(tf TorrentFile, peerCount int)
- func PeerHandshake(conn net.Conn, infoHash []byte, myPeerID string) (handshake, error)
- func PeerWorker(infoHash []byte, ownPeerID string, peerInfo PeerInfoExt, ...)
- func ReadMessage(buf io.Reader) (message torrentMessage, err error)
- func WriteMessage(buf io.Writer, message torrentMessage) (err error)
- type Bitfield
- type Choke
- type ChunkPersister
- type DataFileInfo
- type Interested
- type PeerConnectionInfo
- type PeerInfoExt
- type PeerState
- type PeerWorkerJob
- type PeerWorkerResult
- type Piece
- type Request
- type SparseFileDiskChunkPersister
- type TorrentFile
- type TrackerResponce
- type Unchoke
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadTorrentFile ¶
func DownloadTorrentFile(tf TorrentFile, peerCount int)
func PeerHandshake ¶
PeerHandshake ...
func PeerWorker ¶
func PeerWorker(infoHash []byte, ownPeerID string, peerInfo PeerInfoExt, jobs chan PeerWorkerJob, results chan<- PeerWorkerResult)
func ReadMessage ¶
ReadMessage reads all other messages which are not handshake
func WriteMessage ¶
WriteMessage ...
Types ¶
type ChunkPersister ¶
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 { }
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 PeerWorkerResult ¶
type PeerWorkerResult struct { Job PeerWorkerJob Status bool Chunk []byte }
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
Click to show internal directories.
Click to hide internal directories.