Documentation ¶
Index ¶
- Constants
- type Block
- type Piece
- type PieceImpl
- func (self *PieceImpl) BlockCount() int
- func (self *PieceImpl) Blocks() []*Block
- func (self *PieceImpl) Downloaded() bool
- func (self *PieceImpl) Downloader() string
- func (self *PieceImpl) GetBlockFromOffset(blockBegin uint32, blockLength uint32) *Block
- func (self *PieceImpl) Idx() int
- func (self *PieceImpl) LastPiece() bool
- func (self *PieceImpl) Len() int64
- func (self *PieceImpl) Put(b *Block)
- func (self *PieceImpl) SetAsLastPiece()
- func (self *PieceImpl) SetBlocks(blocks []*Block)
- func (self *PieceImpl) SetDownloader(peerId string)
- func (self *PieceImpl) SetIdx(i int)
- func (self *PieceImpl) SetLength(i int64)
- func (self *PieceImpl) SetStatus(status PieceStatus)
- func (self *PieceImpl) Status() PieceStatus
- type PieceStatus
- type SafePieces
- type SafePiecesImpl
- func (self *SafePiecesImpl) AllBlocks() []*Block
- func (self *SafePiecesImpl) AsIntSlice() []int
- func (self *SafePiecesImpl) Data() map[int]Piece
- func (self *SafePiecesImpl) DownloadedPieceIndices() []int
- func (self *SafePiecesImpl) First() Piece
- func (self *SafePiecesImpl) Get(pieceIdx int) Piece
- func (self *SafePiecesImpl) Last() Piece
- func (self *SafePiecesImpl) Len() int
- func (self *SafePiecesImpl) MarkAsDone(pieceIdx int)
- func (self *SafePiecesImpl) MaxPieceIdx() int
- func (self *SafePiecesImpl) Put(p Piece)
- func (self *SafePiecesImpl) SetAsLastPiece(idx int)
- func (self *SafePiecesImpl) TotalBlocksInAllPiecesCount() int
- func (self *SafePiecesImpl) TotalUndonePiecesLeft() int
- func (self *SafePiecesImpl) TryToReserve(pieceIdx int, peerId string) bool
Constants ¶
View Source
const BLOCK_LENGTH = 0x4000
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { // XXX Idx is not really something in the specs, but a construct I made to // simplify categorizing blocks Idx int PieceIdx int Begin uint32 Buff []byte Length uint32 DownloaderPeerId []byte IsLastBlock bool }
func NewBlockFromFile ¶
func NewRandomBlock ¶
type Piece ¶
type Piece interface { SetStatus(PieceStatus) SetDownloader(string) Downloader() string Status() PieceStatus Blocks() []*Block BlockCount() int Downloaded() bool Len() int64 Idx() int GetBlockFromOffset(uint32, uint32) *Block Put(*Block) LastPiece() bool SetAsLastPiece() }
func CalculateNewPiece ¶
type PieceImpl ¶
type PieceImpl struct {
// contains filtered or unexported fields
}
func NewPieceWithBlocks ¶
func (*PieceImpl) BlockCount ¶
func (*PieceImpl) Downloaded ¶
func (*PieceImpl) Downloader ¶
func (*PieceImpl) GetBlockFromOffset ¶
func (*PieceImpl) SetAsLastPiece ¶
func (self *PieceImpl) SetAsLastPiece()
func (*PieceImpl) SetDownloader ¶
func (*PieceImpl) SetStatus ¶
func (self *PieceImpl) SetStatus(status PieceStatus)
func (*PieceImpl) Status ¶
func (self *PieceImpl) Status() PieceStatus
type PieceStatus ¶
type PieceStatus int
const ( PIECESTATUS_IDLE PieceStatus = 0 PIECESTATUS_DOWNLOADING PieceStatus = iota PIECESTATUS_DONE PieceStatus = iota )
type SafePieces ¶
type SafePieces interface { TryToReserve(int, string) bool Get(int) Piece First() Piece Last() Piece MaxPieceIdx() int Put(Piece) Data() map[int]Piece Len() int TotalBlocksInAllPiecesCount() int MarkAsDone(int) AsIntSlice() []int TotalUndonePiecesLeft() int AllBlocks() []*Block DownloadedPieceIndices() []int SetAsLastPiece(int) }
func NewRandomPieces ¶
func NewRandomPieces(pieceCount int, pieceLength int64, blockLength int) SafePieces
func NewSafePieces ¶
func NewSafePieces() SafePieces
type SafePiecesImpl ¶
type SafePiecesImpl struct {
// contains filtered or unexported fields
}
func (*SafePiecesImpl) AllBlocks ¶
func (self *SafePiecesImpl) AllBlocks() []*Block
func (*SafePiecesImpl) AsIntSlice ¶
func (self *SafePiecesImpl) AsIntSlice() []int
func (*SafePiecesImpl) Data ¶
func (self *SafePiecesImpl) Data() map[int]Piece
func (*SafePiecesImpl) DownloadedPieceIndices ¶
func (self *SafePiecesImpl) DownloadedPieceIndices() []int
func (*SafePiecesImpl) First ¶
func (self *SafePiecesImpl) First() Piece
func (*SafePiecesImpl) Get ¶
func (self *SafePiecesImpl) Get(pieceIdx int) Piece
TODO Return error or nil if piece was not found
func (*SafePiecesImpl) Last ¶
func (self *SafePiecesImpl) Last() Piece
func (*SafePiecesImpl) Len ¶
func (self *SafePiecesImpl) Len() int
func (*SafePiecesImpl) MarkAsDone ¶
func (self *SafePiecesImpl) MarkAsDone(pieceIdx int)
func (*SafePiecesImpl) MaxPieceIdx ¶
func (self *SafePiecesImpl) MaxPieceIdx() int
func (*SafePiecesImpl) Put ¶
func (self *SafePiecesImpl) Put(p Piece)
func (*SafePiecesImpl) SetAsLastPiece ¶
func (self *SafePiecesImpl) SetAsLastPiece(idx int)
func (*SafePiecesImpl) TotalBlocksInAllPiecesCount ¶
func (self *SafePiecesImpl) TotalBlocksInAllPiecesCount() int
func (*SafePiecesImpl) TotalUndonePiecesLeft ¶
func (self *SafePiecesImpl) TotalUndonePiecesLeft() int
func (*SafePiecesImpl) TryToReserve ¶
func (self *SafePiecesImpl) TryToReserve(pieceIdx int, peerId string) bool
Click to show internal directories.
Click to hide internal directories.