Torrent

package module
v0.0.0-...-84c1799 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2016 License: MIT Imports: 15 Imported by: 0

README

Torrent

Torrent Client written in Golang

Documentation

Index

Constants

View Source
const (
	DOWNLOADEDPIECE = iota
	UPLOADEDPIECE
	FAILEDPIECE
	AVAILABLE_PIECES
	ADD_ACTIVE_PEER
	DELETE_ACTIVE_PEER
	ADD_PEER
	DELETE_PEER
)
View Source
const (
	RETRYCOUNT = 1
	BLOCKSIZE  = 65536
	MAXMEMORY  = 1024 * 1024 * 10
)
View Source
const (
	CHOKED = iota
	UNCHOKED
	INTERESTED
	UNINTERESTED
	HAVE
	BITFIELD
	REQUEST
	PIECE
)
View Source
const (
	KB   = 1024
	MB   = 1024 * 1024
	MIN  = 60
	HOUR = 3600
)
View Source
const (
	TIMEOUT = 20
)

Variables

This section is empty.

Functions

func Address

func Address(ip int32, port uint16) string

func Init

func Init(meta *MetaData.MetaInfo)

Types

type BitArray

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

func (*BitArray) GetArray

func (this *BitArray) GetArray() []byte

func (*BitArray) GetByte

func (this *BitArray) GetByte(index int) byte

func (*BitArray) IsLocked

func (this *BitArray) IsLocked(index int) bool

func (*BitArray) LockPiece

func (this *BitArray) LockPiece(index int) bool

func (*BitArray) Set

func (this *BitArray) Set(data []byte)

func (*BitArray) UnlockPiece

func (this *BitArray) UnlockPiece(index int)

type BlobStorage

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

func (*BlobStorage) GetBlock

func (this *BlobStorage) GetBlock(index, offset, size int) []byte

func (*BlobStorage) Init

func (this *BlobStorage) Init(meta *MetaData.MetaInfo) bool

Returns status if file created

func (*BlobStorage) PutBlock

func (this *BlobStorage) PutBlock(data *[]byte, index int)

type FileStorage

type FileStorage struct {
	MultipleFiles bool
	// contains filtered or unexported fields
}

func (*FileStorage) GetBlock

func (this *FileStorage) GetBlock(index, offset, size int) []byte

func (*FileStorage) Init

func (this *FileStorage) Init(meta *MetaData.MetaInfo) bool

func (*FileStorage) PutBlock

func (this *FileStorage) PutBlock(data *[]byte, index int)

type HandshakeData

type HandshakeData struct {
	NameLength byte
	Protocol   [19]byte
	Reserved   [8]byte
	Infohash   [20]byte
	PeerId     [20]byte
}

type Manager

type Manager struct {
	MetaData *MetaData.MetaInfo
	Blocks   PiecesInfo
	InfoHash [20]byte
	PeerId   [20]byte
	PeerMap  map[[20]byte]*PeerClient
	MapLock  sync.Mutex
	Storage  storage
	Stats    TorrentStats
}

func (*Manager) StorePiece

func (this *Manager) StorePiece(index int, data *[]byte)

type PeerClient

type PeerClient struct {
	Conn   net.Conn
	PeerId [20]byte
	// contains filtered or unexported fields
}

func (*PeerClient) BitField

func (this *PeerClient) BitField(size int)

func (*PeerClient) Close

func (this *PeerClient) Close()

func (*PeerClient) Connect

func (this *PeerClient) Connect(peer tracker.Peer)

func (*PeerClient) HandleResponse

func (this *PeerClient) HandleResponse()

Handles all the Peer Wire protocol messages

func (*PeerClient) Have

func (this *PeerClient) Have()

func (*PeerClient) Init

func (this *PeerClient) Init()

func (*PeerClient) Piece

func (this *PeerClient) Piece(size int)

func (*PeerClient) Request

func (this *PeerClient) Request()

Incomplete function Receives 12 byte piece info

func (*PeerClient) SendChoked

func (this *PeerClient) SendChoked()

func (*PeerClient) SendInterested

func (this *PeerClient) SendInterested()

func (*PeerClient) SendPiece

func (this *PeerClient) SendPiece(index, offset, size int)

func (*PeerClient) SendPieceRquest

func (this *PeerClient) SendPieceRquest()

func (*PeerClient) SendUnchoked

func (this *PeerClient) SendUnchoked()

func (*PeerClient) SendUninterested

func (this *PeerClient) SendUninterested()

type Piece

type Piece struct {
	Id        int           //Index of the piece
	BlockSize int           //Size  of the block
	PieceSize int           //Size  of the piece
	Offset    int           //Offset in the piece
	Data      *bytes.Buffer //Downloaded piece
	Stamp     time.Time
	Lock      sync.Mutex
}

type PieceRequest

type PieceRequest struct {
	Id     int32 //Index of the piece
	Offset int32 //Offset of the piece
	Size   int32 //Block size to be downloaded or uploaded
}

type PiecesInfo

type PiecesInfo struct {
	AvailablePieces BitArray //Pieces already downloaded
	LockedPieces    BitArray //Pieces being downloaded
	Lock            sync.Mutex
	// contains filtered or unexported fields
}

type TorrentStats

type TorrentStats struct {
	DownloadedPieces     int
	UploadedPieces       int
	FailedPieces         int
	AvailablePieces      int
	TotalBytesDownloaded int
	TotalBytesUploaded   int
	ActivePeers          int
	TotalPeers           int
	TimeStart            time.Time
	TimeElapsed          int
	PieceChan            chan int
	DownloadChan         chan int
	UploadChan           chan int
}

func (*TorrentStats) Init

func (this *TorrentStats) Init()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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