Documentation ¶
Index ¶
- Constants
- Variables
- func CopyN(dst io.Writer, src io.Reader, n int64) (written int64, err error)
- func Error(w http.ResponseWriter, error string, code int)
- func GetBlobStore() *peer.Store
- func InstallRoutes(r *mux.Router)
- func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, ...)
- type ChunkCache
- type ChunkCalculator
- type FSCacheOpts
- type Opts
- type Player
- type ReadableChunk
- type RequestHandler
- type Stream
Constants ¶
const ( // ChunkSize is a size of decrypted blob. ChunkSize = stream.MaxBlobSize - 1 // DefaultPrefetchLen is how many blobs we should prefetch ahead. // 3 should be enough to deliver 2 x 4 = 8MB/s streams. DefaultPrefetchLen = 3 // RetrieverSourceL2Cache is for labeling cache speed sourced from level 2 chunk cache (LFU) RetrieverSourceL2Cache = "l2_cache" // RetrieverSourceReflector is for labeling cache speed sourced from reflector RetrieverSourceReflector = "reflector" )
const ParamDownload = "download"
Variables ¶
var CacheLogger = localLogger{monitor.NewModuleLogger("player_cache")}
CacheLogger is for caching operations only.
var Logger = localLogger{monitor.NewModuleLogger("player")}
Logger is a package-wide logger. Warning: will generate a lot of output if DEBUG loglevel is enabled. Logger variables here are made public so logging can be disabled on the spot when needed (in tests etc).
var RetLogger = localLogger{monitor.NewModuleLogger("player_retriever")}
RetLogger is for blob/chunk retrieval operations logging.
Functions ¶
func CopyN ¶
CopyN copies n bytes (or until an error) from src to dst. It returns the number of bytes copied and the earliest error encountered while copying. On return, written == n if and only if err == nil.
If dst implements the ReaderFrom interface, the copy is implemented using it.
func Error ¶
func Error(w http.ResponseWriter, error string, code int)
Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.
func GetBlobStore ¶ added in v0.11.0
GetBlobStore returns default pre-configured blob store.
func InstallRoutes ¶ added in v0.11.0
func ServeContent ¶
func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker)
ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.
If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.
If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.
The content's Seek method must work: ServeContent uses a seek to the end of the content to determine its size.
If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.
Note that *os.File implements the io.ReadSeeker interface.
Types ¶
type ChunkCache ¶ added in v0.11.1
type ChunkCache interface { Has(string) bool Get(string) (ReadableChunk, bool) Set(string, []byte) (ReadableChunk, error) Remove(string) Size() uint64 }
ChunkCache can save and retrieve readable chunks.
func InitFSCache ¶ added in v0.11.1
func InitFSCache(opts *FSCacheOpts) (ChunkCache, error)
InitFSCache initializes disk cache for chunks. All chunk-sized files inside `dir` will be removed on initialization, if `dir` does not exist, it will be created. In other words, os.TempDir() should not be passed as a `dir`.
type ChunkCalculator ¶ added in v0.11.1
type ChunkCalculator struct { Offset int64 ReadLen int FirstChunkIdx int LastChunkIdx int FirstChunkOffset int LastChunkReadLen int LastChunkOffset int }
ChunkCalculator provides handy blob calculations for a requested stream range.
func NewChunkCalculator ¶ added in v0.11.1
func NewChunkCalculator(size, offset int64, readLen int) ChunkCalculator
NewChunkCalculator initializes ChunkCalculator with provided stream size, start offset and reader buffer length.
func (ChunkCalculator) String ¶ added in v0.11.1
func (c ChunkCalculator) String() string
type FSCacheOpts ¶ added in v0.11.1
FSCacheOpts contains options for filesystem cache. Size is max size in bytes
type Player ¶ added in v0.7.0
type Player struct {
// contains filtered or unexported fields
}
Player is an entry-point object to the new player package.
func (*Player) Play ¶ added in v0.11.0
Play delivers requested URI onto the supplied http.ResponseWriter.
func (*Player) ResolveStream ¶ added in v0.11.0
ResolveStream resolves provided URI by calling the SDK.
func (*Player) RetrieveStream ¶ added in v0.11.0
RetrieveStream downloads stream description from the reflector and tries to determine stream size using several methods, including legacy ones for streams that do not have metadata.
type ReadableChunk ¶ added in v0.11.1
ReadableChunk interface describes generic chunk object that Stream can Read() from.
type RequestHandler ¶ added in v0.11.0
type RequestHandler struct {
// contains filtered or unexported fields
}
RequestHandler is a HTTP request handler for player package.
func NewRequestHandler ¶ added in v0.11.0
func NewRequestHandler(p *Player) *RequestHandler
NewRequestHandler initializes a HTTP request handler with the provided Player instance.
func (*RequestHandler) Handle ¶ added in v0.11.0
func (h *RequestHandler) Handle(w http.ResponseWriter, r *http.Request)
Handle is responsible for all HTTP media delivery via player module.
func (*RequestHandler) HandleHead ¶ added in v0.11.1
func (h *RequestHandler) HandleHead(w http.ResponseWriter, r *http.Request)
HandleHead handlers OPTIONS requests for media.
type Stream ¶ added in v0.11.0
type Stream struct { URI string Hash string Size int64 ContentType string Claim *ljsonrpc.Claim // contains filtered or unexported fields }
Stream provides an io.ReadSeeker interface to a stream of blobs to be used by standard http library for range requests, as well as some stream metadata.
func (*Stream) Read ¶ added in v0.11.0
Read implements io.ReadSeeker interface and is meant to be called by http.ServeContent. Actual chunk retrieval and delivery happens in s.readFromChunks().