blocksources

package
v0.0.0-...-8931874 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE_RUNNING = iota
	STATE_EXITING
)
View Source
const MB = 1024 * 1024

Variables

View Source
var BlockSourceAlreadyClosedError = errors.New("Block source was already closed")
View Source
var ClientNoCompression = &http.Client{
	Transport: &http.Transport{},
}
View Source
var RangedRequestNotSupportedError = errors.New("Ranged request not supported (Server did not respond with 206 Status)")
View Source
var ResponseFromServerWasGZiped = errors.New("HTTP response was gzip encoded. Ranges may not match those requested.")

Functions

This section is empty.

Types

type BlockSourceBase

type BlockSourceBase struct {
	Requester           BlockSourceRequester
	BlockSourceResolver BlockSourceOffsetResolver
	Verifier            BlockVerifier

	// The number of requests that BlockSourceBase may service at once
	ConcurrentRequests int

	// The number of bytes that BlockSourceBase may have in-flight
	// (requested + pending delivery)
	ConcurrentBytes int64
	// contains filtered or unexported fields
}

BlockSourceBase provides an implementation of blocksource that takes care of everything except for the actual asyncronous request this makes blocksources easier and faster to build reliably BlockSourceBase implements patcher.BlockSource, and if it's good enough, perhaps nobody else ever will have to.

func NewBlockSourceBase

func NewBlockSourceBase(
	requester BlockSourceRequester,
	resolver BlockSourceOffsetResolver,
	verifier BlockVerifier,
	concurrentRequestCount int,
	concurrentBytes int64,
) *BlockSourceBase

func NewHttpBlockSource

func NewHttpBlockSource(
	url string,
	concurrentRequests int,
	resolver BlockSourceOffsetResolver,
	verifier BlockVerifier,
) *BlockSourceBase

func NewReadSeekerBlockSource

func NewReadSeekerBlockSource(
	r ReadSeeker,
	resolver BlockSourceOffsetResolver,
) *BlockSourceBase

func (*BlockSourceBase) Close

func (s *BlockSourceBase) Close() (err error)

func (*BlockSourceBase) EncounteredError

func (s *BlockSourceBase) EncounteredError() <-chan error

If the block source encounters an unsurmountable problem

func (*BlockSourceBase) GetResultChannel

func (s *BlockSourceBase) GetResultChannel() <-chan patcher.BlockReponse

func (*BlockSourceBase) ReadBytes

func (s *BlockSourceBase) ReadBytes() int64

func (*BlockSourceBase) RequestBlocks

func (s *BlockSourceBase) RequestBlocks(block patcher.MissingBlockSpan) error

type BlockSourceOffsetResolver

type BlockSourceOffsetResolver interface {
	GetBlockStartOffset(blockID uint) int64
	GetBlockEndOffset(blockID uint) int64
	SplitBlockRangeToDesiredSize(startBlockID, endBlockID uint) []QueuedRequest
}

A BlockSourceOffsetResolver resolves a blockID to a start offset and and end offset in a file it also handles splitting up ranges of blocks into multiple requests, allowing requests to be split down to the block size, and handling of compressed blocks (given a resolver that can work out the correct range to query for, and a BlockSourceRequester that will decompress the result into a full sized block)

func MakeFileSizedBlockResolver

func MakeFileSizedBlockResolver(blockSize uint64, filesize int64) BlockSourceOffsetResolver

func MakeNullFixedSizeResolver

func MakeNullFixedSizeResolver(blockSize uint64) BlockSourceOffsetResolver

type BlockSourceRequester

type BlockSourceRequester interface {
	// This method is called on multiple goroutines, and must
	// support simultaneous requests
	DoRequest(startOffset int64, endOffset int64) (data []byte, err error)

	// If an error raised by DoRequest should cause BlockSourceBase
	// to give up, return true
	IsFatal(err error) bool
}

BlockSourceRequester does synchronous requests on a remote source of blocks concurrency is handled by the BlockSourceBase. This provides a simple way of implementing a particular

type BlockVerifier

type BlockVerifier interface {
	VerifyBlockRange(startBlockID uint, data []byte) bool
}

Checks blocks against their expected checksum

type FixedSizeBlockResolver

type FixedSizeBlockResolver struct {
	BlockSize             uint64
	FileSize              int64
	MaxDesiredRequestSize uint64
}

func (*FixedSizeBlockResolver) GetBlockEndOffset

func (r *FixedSizeBlockResolver) GetBlockEndOffset(blockID uint) int64

func (*FixedSizeBlockResolver) GetBlockStartOffset

func (r *FixedSizeBlockResolver) GetBlockStartOffset(blockID uint) int64

func (*FixedSizeBlockResolver) SplitBlockRangeToDesiredSize

func (r *FixedSizeBlockResolver) SplitBlockRangeToDesiredSize(startBlockID, endBlockID uint) []QueuedRequest

Split blocks into chunks of the desired size, or less. This implementation assumes a fixed block size at the source.

type HttpRequester

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

This class provides the implementation of BlockSourceRequester for BlockSourceBase this simplifies creating new BlockSources that satisfy the requirements down to writing a request function

func (*HttpRequester) DoRequest

func (r *HttpRequester) DoRequest(startOffset int64, endOffset int64) (data []byte, err error)

func (*HttpRequester) IsFatal

func (r *HttpRequester) IsFatal(err error) bool

type PendingResponses

type PendingResponses []patcher.BlockReponse

func (PendingResponses) Len

func (r PendingResponses) Len() int

func (PendingResponses) Less

func (r PendingResponses) Less(i, j int) bool

func (PendingResponses) Swap

func (r PendingResponses) Swap(i, j int)

type QueuedRequest

type QueuedRequest struct {
	StartBlockID uint
	EndBlockID   uint
}

type QueuedRequestList

type QueuedRequestList []QueuedRequest

func (QueuedRequestList) Len

func (r QueuedRequestList) Len() int

func (QueuedRequestList) Less

func (r QueuedRequestList) Less(i, j int) bool

func (QueuedRequestList) Swap

func (r QueuedRequestList) Swap(i, j int)

type ReadSeeker

type ReadSeeker interface {
	Read(b []byte) (n int, err error)
	Seek(offset int64, whence int) (int64, error)
}

type ReadSeekerRequester

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

func (*ReadSeekerRequester) DoRequest

func (r *ReadSeekerRequester) DoRequest(startOffset int64, endOffset int64) (data []byte, err error)

func (*ReadSeekerRequester) IsFatal

func (r *ReadSeekerRequester) IsFatal(err error) bool

type URLNotFoundError

type URLNotFoundError string

func (URLNotFoundError) Error

func (url URLNotFoundError) Error() string

type UintSlice

type UintSlice []uint

func (UintSlice) Len

func (r UintSlice) Len() int

func (UintSlice) Less

func (r UintSlice) Less(i, j int) bool

func (UintSlice) Swap

func (r UintSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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