Documentation ¶
Index ¶
- Constants
- Variables
- type BlockSourceBase
- func NewBlockSourceBase(requester BlockSourceRequester, resolver BlockSourceOffsetResolver, ...) *BlockSourceBase
- func NewHttpBlockSource(url string, concurrentRequests int, resolver BlockSourceOffsetResolver, ...) *BlockSourceBase
- func NewReadSeekerBlockSource(r ReadSeeker, resolver BlockSourceOffsetResolver) *BlockSourceBase
- type BlockSourceOffsetResolver
- type BlockSourceRequester
- type BlockVerifier
- type FixedSizeBlockResolver
- type HttpRequester
- type PendingResponses
- type QueuedRequest
- type QueuedRequestList
- type ReadSeeker
- type ReadSeekerRequester
- type URLNotFoundError
- type UintSlice
Constants ¶
const ( STATE_RUNNING = iota STATE_EXITING )
const MB = 1024 * 1024
Variables ¶
var BlockSourceAlreadyClosedError = errors.New("Block source was already closed")
var ClientNoCompression = &http.Client{ Transport: &http.Transport{}, }
var RangedRequestNotSupportedError = errors.New("Ranged request not supported (Server did not respond with 206 Status)")
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 ¶
Checks blocks against their expected checksum
type FixedSizeBlockResolver ¶
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 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 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