server

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 74 Imported by: 1

Documentation

Overview

Package server is the place we integrate the Livepeer node with the LPMS media server.

Index

Constants

View Source
const (
	// Staged indicates that the update has been created but the credit
	// has not been spent yet
	Staged = iota
	// CreditSpent indicates that the update's credit has been spent
	// but the debit has not been processed yet
	CreditSpent
	// ReceivedChange indicates that the update's credit has been spent
	// and a debit was processed such that there was "change" (net of credit/debit)
	ReceivedChange
)
View Source
const BroadcastRetry = 15 * time.Second
View Source
const GRPCConnectTimeout = 3 * time.Second
View Source
const GRPCTimeout = 8 * time.Second
View Source
const HLSBufferCap = uint(43200) //12 hrs assuming 1s segment
View Source
const HLSBufferWindow = uint(5)
View Source
const HLSWaitInterval = time.Second
View Source
const HTTPIdleTimeout = 10 * time.Minute
View Source
const LIVERPEER_TRANSCODE_CONFIG_HEADER = "Livepeer-Transcode-Configuration"
View Source
const MainnetChainId = 1
View Source
const RinkebyChainId = 4
View Source
const SELECTOR_LATENCY_SCORE_THRESHOLD = 1.0
View Source
const SegLen = 2 * time.Second
View Source
const StreamKeyBytes = 6

Variables

View Source
var AuthWebhookURL *url.URL
View Source
var BroadcastCfg = &BroadcastConfig{}
View Source
var MaxAttempts = 3
View Source
var MetadataPublishTimeout = 1 * time.Second
View Source
var MetadataQueue event.SimpleProducer
View Source
var NonRetryableErrMap = nonRetryableErrMapInit()
View Source
var StreamPrefix = regexp.MustCompile(`^[ /]*(stream/)?|(live/)?`) // test carefully!

StreamPrefix match all leading spaces, slashes and optionally `stream/`

Functions

func CheckOrchestratorAvailability added in v0.5.0

func CheckOrchestratorAvailability(orch Orchestrator) bool

CheckOrchestratorAvailability - the broadcaster calls CheckOrchestratorAvailability which invokes Ping on the orchestrator

func EndTranscodingSession added in v0.5.35

func EndTranscodingSession(ctx context.Context, sess *BroadcastSession) error

EndSession - the broadcaster calls EndTranscodingSession to tear down sessions used for verification only once

func GetOrchestratorInfo added in v0.5.0

func GetOrchestratorInfo(ctx context.Context, bcast common.Broadcaster, orchestratorServer *url.URL) (*net.OrchestratorInfo, error)

GetOrchestratorInfo - the broadcaster calls GetOrchestratorInfo which invokes GetOrchestrator on the orchestrator

func PixelFormatNone added in v0.5.30

func PixelFormatNone() ffmpeg.PixelFormat

func RunTranscoder added in v0.5.0

func RunTranscoder(n *core.LivepeerNode, orchAddr string, capacity int, caps []core.Capability)

RunTranscoder is main routing of standalone transcoder Exiting it will terminate executable

func StartTranscodeServer added in v0.3.3

func StartTranscodeServer(orch Orchestrator, bind string, mux *http.ServeMux, workDir string, acceptRemoteTranscoders bool, n *core.LivepeerNode) error

XXX do something about the implicit start of the http mux? this smells

Types

type Balance added in v0.5.0

type Balance interface {
	Credit(amount *big.Rat)
	StageUpdate(minCredit *big.Rat, ev *big.Rat) (int, *big.Rat, *big.Rat)
}

Balance describes methods for a session's balance maintenance

type BalanceUpdate added in v0.5.0

type BalanceUpdate struct {
	// ExistingCredit is the existing credit reserved for the update
	ExistingCredit *big.Rat

	// NewCredit is the new credit for the update provided by a payment
	NewCredit *big.Rat

	// NumTickets is the number of tickets in the payment for the update
	NumTickets int

	// Debit is the amount to debit for the update
	Debit *big.Rat

	// Status is the current status of the update
	Status BalanceUpdateStatus
}

BalanceUpdate describes an update to be performed on the balance of a session

type BalanceUpdateStatus added in v0.5.0

type BalanceUpdateStatus int

BalanceUpdateStatus indicates the current status of a balance update

type BlockGetter added in v0.5.0

type BlockGetter interface {
	LastSeenBlock() (*big.Int, error)
}

type BreakOperation added in v0.5.30

type BreakOperation bool

type BroadcastConfig added in v0.5.0

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

func (*BroadcastConfig) MaxPrice added in v0.5.0

func (cfg *BroadcastConfig) MaxPrice() *big.Rat

func (*BroadcastConfig) SetMaxPrice added in v0.5.0

func (cfg *BroadcastConfig) SetMaxPrice(price *core.AutoConvertedPrice)

type BroadcastSession added in v0.5.0

type BroadcastSession struct {
	Broadcaster              common.Broadcaster
	Params                   *core.StreamParameters
	BroadcasterOS            drivers.OSSession
	Sender                   pm.Sender
	Balances                 *core.AddressBalances
	OrchestratorScore        float32
	VerifiedByPerceptualHash bool

	// access these fields under the lock
	SegsInFlight     []SegFlightMetadata
	LatencyScore     float64
	OrchestratorInfo *net.OrchestratorInfo
	OrchestratorOS   drivers.OSSession
	PMSessionID      string
	Balance          Balance
	InitialPrice     *net.PriceInfo
	// contains filtered or unexported fields
}

BroadcastSession - session-specific state for broadcasters

func (*BroadcastSession) Address added in v0.5.23

func (bs *BroadcastSession) Address() string

func (*BroadcastSession) Clone added in v0.5.23

func (bs *BroadcastSession) Clone() *BroadcastSession

func (*BroadcastSession) IsTrusted added in v0.5.23

func (bs *BroadcastSession) IsTrusted() bool

func (*BroadcastSession) Transcoder added in v0.5.23

func (bs *BroadcastSession) Transcoder() string

type BroadcastSessionsManager added in v0.5.0

type BroadcastSessionsManager struct {
	VerificationFreq uint
	// contains filtered or unexported fields
}

type BroadcastSessionsSelector added in v0.5.2

type BroadcastSessionsSelector interface {
	Add(sessions []*BroadcastSession)
	Complete(sess *BroadcastSession)
	Select(ctx context.Context) *BroadcastSession
	Size() int
	Clear()
}

BroadcastSessionsSelector selects the next BroadcastSession to use

type BroadcastSessionsSelectorFactory added in v0.5.23

type BroadcastSessionsSelectorFactory func() BroadcastSessionsSelector

type ChainIdGetter added in v0.5.30

type ChainIdGetter interface {
	ChainID() (*big.Int, error)
}

type LIFOSelector added in v0.5.2

type LIFOSelector []*BroadcastSession

LIFOSelector selects the next BroadcastSession in LIFO order now used only in tests

func (*LIFOSelector) Add added in v0.5.2

func (s *LIFOSelector) Add(sessions []*BroadcastSession)

Add adds the sessions to the front of the selector's list

func (*LIFOSelector) Clear added in v0.5.2

func (s *LIFOSelector) Clear()

Clear resets the selector's state

func (*LIFOSelector) Complete added in v0.5.2

func (s *LIFOSelector) Complete(sess *BroadcastSession)

Complete adds the session to the end of the selector's list

func (*LIFOSelector) Select added in v0.5.2

func (s *LIFOSelector) Select(ctx context.Context) *BroadcastSession

Select returns the last session in the selector's list

func (*LIFOSelector) Size added in v0.5.2

func (s *LIFOSelector) Size() int

Size returns the number of sessions stored by the selector

type LivepeerServer

type LivepeerServer struct {
	RTMPSegmenter         lpmscore.RTMPSegmenter
	LPMS                  *lpmscore.LPMS
	LivepeerNode          *core.LivepeerNode
	HTTPMux               *http.ServeMux
	ExposeCurrentManifest bool
	// contains filtered or unexported fields
}

func NewLivepeerServer

func NewLivepeerServer(rtmpAddr string, lpNode *core.LivepeerNode, httpIngest bool, transcodingOptions string) (*LivepeerServer, error)

func (*LivepeerServer) GetNodeStatus added in v0.5.0

func (s *LivepeerServer) GetNodeStatus() *common.NodeStatus

func (*LivepeerServer) HandlePush added in v0.5.0

func (s *LivepeerServer) HandlePush(w http.ResponseWriter, r *http.Request)

HandlePush processes request for HTTP ingest

func (*LivepeerServer) HandleRecordings added in v0.5.13

func (s *LivepeerServer) HandleRecordings(w http.ResponseWriter, r *http.Request)

HandleRecordings handle requests to /recordings/ endpoint

func (*LivepeerServer) LastHLSStreamID added in v0.5.0

func (s *LivepeerServer) LastHLSStreamID() core.StreamID

func (*LivepeerServer) LastManifestID added in v0.5.0

func (s *LivepeerServer) LastManifestID() core.ManifestID

func (*LivepeerServer) LatestPlaylist added in v0.5.0

func (s *LivepeerServer) LatestPlaylist() core.PlaylistManager

Debug helpers

func (*LivepeerServer) SetContextFromUnitTest added in v0.5.30

func (s *LivepeerServer) SetContextFromUnitTest(c context.Context)

func (*LivepeerServer) StartCliWebserver added in v0.5.0

func (s *LivepeerServer) StartCliWebserver(srv *http.Server)

StartCliWebserver starts web server for CLI blocks until exit

func (*LivepeerServer) StartMediaServer

func (s *LivepeerServer) StartMediaServer(ctx context.Context, httpAddr string) error

StartMediaServer starts the LPMS server

type MinLSSelector added in v0.5.2

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

MinLSSelector selects the next BroadcastSession with the lowest latency score if it is good enough. Otherwise, it selects a session that does not have a latency score yet MinLSSelector is not concurrency safe so the caller is responsible for ensuring safety for concurrent method calls

func NewMinLSSelector added in v0.5.2

func NewMinLSSelector(stakeRdr stakeReader, minLS float64, selectionAlgorithm common.SelectionAlgorithm, perfScore *common.PerfScore) *MinLSSelector

NewMinLSSelector returns an instance of MinLSSelector configured with a good enough latency score

func (*MinLSSelector) Add added in v0.5.2

func (s *MinLSSelector) Add(sessions []*BroadcastSession)

Add adds the sessions to the selector's list of sessions without a latency score

func (*MinLSSelector) Clear added in v0.5.2

func (s *MinLSSelector) Clear()

Clear resets the selector's state

func (*MinLSSelector) Complete added in v0.5.2

func (s *MinLSSelector) Complete(sess *BroadcastSession)

Complete adds the session to the selector's list sessions with a latency score

func (*MinLSSelector) Select added in v0.5.2

Select returns the session with the lowest latency score if it is good enough. Otherwise, a session without a latency score yet is returned

func (*MinLSSelector) Size added in v0.5.2

func (s *MinLSSelector) Size() int

Size returns the number of sessions stored by the selector

type Orchestrator added in v0.3.3

type Orchestrator interface {
	ServiceURI() *url.URL
	Address() ethcommon.Address
	TranscoderSecret() string
	Sign([]byte) ([]byte, error)
	VerifySig(ethcommon.Address, string, []byte) bool
	CheckCapacity(core.ManifestID) error
	TranscodeSeg(context.Context, *core.SegTranscodingMetadata, *stream.HLSSegment) (*core.TranscodeResult, error)
	ServeTranscoder(stream net.Transcoder_RegisterTranscoderServer, capacity int, capabilities *net.Capabilities)
	TranscoderResults(job int64, res *core.RemoteTranscoderResult)
	ProcessPayment(ctx context.Context, payment net.Payment, manifestID core.ManifestID) error
	TicketParams(sender ethcommon.Address, priceInfo *net.PriceInfo) (*net.TicketParams, error)
	PriceInfo(sender ethcommon.Address, manifestID core.ManifestID) (*net.PriceInfo, error)
	SufficientBalance(addr ethcommon.Address, manifestID core.ManifestID) bool
	DebitFees(addr ethcommon.Address, manifestID core.ManifestID, price *net.PriceInfo, pixels int64)
	Capabilities() *net.Capabilities
	AuthToken(sessionID string, expiration int64) *net.AuthToken
}

type ProbabilitySelectionAlgorithm added in v0.7.0

type ProbabilitySelectionAlgorithm struct {
	MinPerfScore float64

	StakeWeight float64
	PriceWeight float64
	RandWeight  float64

	PriceExpFactor float64
}

func (ProbabilitySelectionAlgorithm) Select added in v0.7.0

type ReceivedTranscodeResult added in v0.5.2

type ReceivedTranscodeResult struct {
	*net.TranscodeData
	Info         *net.OrchestratorInfo
	LatencyScore float64
}

ReceivedTranscodeResult contains received transcode result data and related metadata

func SubmitSegment added in v0.3.3

func SubmitSegment(ctx context.Context, sess *BroadcastSession, seg *stream.HLSSegment, segPar *core.SegmentParameters,
	nonce uint64, calcPerceptualHash, verified bool) (*ReceivedTranscodeResult, error)

type Redeemer added in v0.5.9

type Redeemer struct {
	net.UnimplementedTicketRedeemerServer
	// contains filtered or unexported fields
}

func NewRedeemer added in v0.5.9

func NewRedeemer(recipient ethcommon.Address, eth eth.LivepeerEthClient, sm *pm.LocalSenderMonitor) (*Redeemer, error)

NewRedeemer creates a new ticket redemption service instance

func (*Redeemer) MaxFloat added in v0.5.9

func (r *Redeemer) MaxFloat(ctx context.Context, req *net.MaxFloatReq) (*net.MaxFloatUpdate, error)

MaxFloat is a unary RPC method to request the max float value for a sender

func (*Redeemer) MonitorMaxFloat added in v0.5.9

func (r *Redeemer) MonitorMaxFloat(req *net.MaxFloatReq, stream net.TicketRedeemer_MonitorMaxFloatServer) error

MonitorMaxFloat starts a server-side stream to the client to send max float updates for sender specified in the request

func (*Redeemer) QueueTicket added in v0.5.9

func (r *Redeemer) QueueTicket(ctx context.Context, ticket *net.Ticket) (*net.QueueTicketRes, error)

QueueTicket adds a ticket to the ticket queue

func (*Redeemer) Start added in v0.5.9

func (r *Redeemer) Start(url *url.URL, workDir string) error

Start starts a Redeemer server This method will block

func (*Redeemer) Stop added in v0.5.9

func (r *Redeemer) Stop()

Stop stops the Redeemer server

type RedeemerClient added in v0.5.9

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

func NewRedeemerClient added in v0.5.9

func NewRedeemerClient(uri string, sm pm.SenderManager, tm pm.TimeManager) (*RedeemerClient, error)

NewRedeemerClient instantiates a new client for the ticket redemption service The client implements the pm.SenderMonitor interface

func (*RedeemerClient) MaxFloat added in v0.5.9

func (r *RedeemerClient) MaxFloat(sender ethcommon.Address) (*big.Int, error)

MaxFloat returns the max float for 'sender' If no local cache is available this method will remotely request max float from the Redeemer server and start watching for subsequent updates from the Redeemer server

func (*RedeemerClient) QueueTicket added in v0.5.9

func (r *RedeemerClient) QueueTicket(ticket *pm.SignedTicket) error

QueueTicket sends a winning ticket to the Redeemer

func (*RedeemerClient) Start added in v0.5.9

func (r *RedeemerClient) Start()

func (*RedeemerClient) Stop added in v0.5.9

func (r *RedeemerClient) Stop()

Stop stops the Redeemer client

func (*RedeemerClient) ValidateSender added in v0.5.9

func (r *RedeemerClient) ValidateSender(sender ethcommon.Address) error

ValidateSender checks whether a sender has not recently unlocked its deposit and reserve

type Router added in v0.5.15

type Router struct {
	net.UnimplementedOrchestratorServer
	// contains filtered or unexported fields
}

func NewRouter added in v0.5.15

func NewRouter(uris []*url.URL) *Router

func (*Router) EndTranscodingSession added in v0.5.35

func (r *Router) EndTranscodingSession(ctx context.Context, request *net.EndTranscodingSessionRequest) (*net.EndTranscodingSessionResponse, error)

func (*Router) GetOrchestrator added in v0.5.15

func (r *Router) GetOrchestrator(ctx context.Context, req *net.OrchestratorRequest) (*net.OrchestratorInfo, error)

func (*Router) Ping added in v0.5.15

func (r *Router) Ping(ctx context.Context, req *net.PingPong) (*net.PingPong, error)

func (*Router) Start added in v0.5.15

func (r *Router) Start(uri *url.URL, serviceURI *url.URL, workDir string) error

func (*Router) Stop added in v0.5.15

func (r *Router) Stop()

type SegFlightMetadata added in v0.5.14

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

type SessionPool added in v0.5.23

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

func NewSessionPool added in v0.5.23

func NewSessionPool(mid core.ManifestID, poolSize, numOrchs int, sus *suspender, createSession sessionsCreator,
	sel BroadcastSessionsSelector) *SessionPool

type SubmitResult added in v0.5.23

type SubmitResult struct {
	Session         *BroadcastSession
	TranscodeResult *ReceivedTranscodeResult
	Err             error
}

Jump to

Keyboard shortcuts

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