piece

package
v0.0.0-...-8cd3384 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

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 NewBlock

func NewBlock(blockIdx int, pieceIdx int, begin uint32,
	length uint32, buff []byte) *Block

func NewBlockFromFile

func NewBlockFromFile(pieceIdx int, begin uint32, payloadFilePath string) *Block

func NewRandomBlock

func NewRandomBlock(pieceIdx, blockIdx, maxBuffSize int) *Block

func (*Block) String

func (self *Block) String() string

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

func CalculateNewPiece(pieceIdx int, pieceLength int64,
	blockLength int, isSeeding bool) Piece

func NewPiece

func NewPiece(idx int, length int64, status PieceStatus) Piece

type PieceImpl

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

func NewPieceWithBlocks

func NewPieceWithBlocks(idx int, length int64,
	blocks []*Block) *PieceImpl

func (*PieceImpl) BlockCount

func (self *PieceImpl) BlockCount() int

func (*PieceImpl) Blocks

func (self *PieceImpl) Blocks() []*Block

func (*PieceImpl) Downloaded

func (self *PieceImpl) Downloaded() bool

func (*PieceImpl) Downloader

func (self *PieceImpl) Downloader() string

func (*PieceImpl) GetBlockFromOffset

func (self *PieceImpl) GetBlockFromOffset(blockBegin uint32,
	blockLength uint32) *Block

func (*PieceImpl) Idx

func (self *PieceImpl) Idx() int

func (*PieceImpl) LastPiece

func (self *PieceImpl) LastPiece() bool

func (*PieceImpl) Len

func (self *PieceImpl) Len() int64

func (*PieceImpl) Put

func (self *PieceImpl) Put(b *Block)

func (*PieceImpl) SetAsLastPiece

func (self *PieceImpl) SetAsLastPiece()

func (*PieceImpl) SetBlocks

func (self *PieceImpl) SetBlocks(blocks []*Block)

func (*PieceImpl) SetDownloader

func (self *PieceImpl) SetDownloader(peerId string)

func (*PieceImpl) SetIdx

func (self *PieceImpl) SetIdx(i int)

func (*PieceImpl) SetLength

func (self *PieceImpl) SetLength(i int64)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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