core

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2017 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Core contains the main functionality of the Livepeer node.

Index

Constants

View Source
const (
	HashLength   = 32
	NodeIDLength = 68
)
View Source
const HLSStreamWinSize = uint(3)
View Source
const HLSWaitTime = time.Second * 10

Variables

View Source
var BroadcastTimeout = time.Second * 30
View Source
var ConnFileWriteFreq = time.Duration(60) * time.Second
View Source
var DefaultJobLength = int64(5760) //Avg 1 day in 15 sec blocks
View Source
var DefaultMasterPlaylistWaitTime = 60 * time.Second
View Source
var ErrBroadcast = errors.New("ErrBroadcast")
View Source
var ErrBroadcastJob = errors.New("ErrBroadcastJob")
View Source
var ErrBroadcastTimeout = errors.New("ErrBroadcastTimeout")
View Source
var ErrClaim = errors.New("ErrClaim")
View Source
var ErrClaimManager = errors.New("ErrClaimManager")
View Source
var ErrEOF = errors.New("ErrEOF")
View Source
var ErrLivepeerNode = errors.New("ErrLivepeerNode")
View Source
var ErrManifestID = errors.New("ErrManifestID")
View Source
var ErrNotFound = errors.New("NotFound")
View Source
var ErrStreamID = errors.New("ErrStreamID")
View Source
var ErrTranscode = errors.New("ErrTranscode")
View Source
var ErrVideoDB = errors.New("ErrVideoDB")
View Source
var EthEventTimeout = 5 * time.Second
View Source
var EthMinedTxTimeout = 60 * time.Second
View Source
var EthRpcTimeout = 5 * time.Second
View Source
var PlusOneBlockRetry = 5
View Source
var PlusOneBlockSleepInterval = time.Second * 3 //Max of 96 sec wait time

Functions

func RandomVideoID

func RandomVideoID() []byte

func SignedSegmentToBytes

func SignedSegmentToBytes(ss SignedSegment) ([]byte, error)

Convenience function to convert between SignedSegments and byte slices to put on the wire.

Types

type BasicClaimManager

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

BasicClaimManager manages the claim process for a Livepeer transcoder. Check the Livepeer protocol for more details.

func NewBasicClaimManager

func NewBasicClaimManager(sid string, jid *big.Int, broadcaster common.Address, pricePerSegment *big.Int, p []lpmscore.VideoProfile, c eth.LivepeerEthClient, ipfs ipfs.IpfsApi) *BasicClaimManager

NewBasicClaimManager creates a new claim manager.

func (*BasicClaimManager) AddReceipt

func (c *BasicClaimManager) AddReceipt(seqNo int64, data []byte, tDataHash []byte, bSig []byte, profile lpmscore.VideoProfile) error

AddReceipt adds a claim for a given video segment.

func (*BasicClaimManager) Claim

func (c *BasicClaimManager) Claim() (claimCount int, rc chan types.Receipt, ec chan error)

Claim creates the onchain claim for all the claims added through AddReceipt

func (*BasicClaimManager) DistributeFees

func (c *BasicClaimManager) DistributeFees() error

func (*BasicClaimManager) SufficientBroadcasterDeposit

func (c *BasicClaimManager) SufficientBroadcasterDeposit() (bool, error)

func (*BasicClaimManager) Verify

func (c *BasicClaimManager) Verify() error

type ClaimManager

type ClaimManager interface {
	AddReceipt(seqNo int64, data []byte, tDataHash []byte, bSig []byte, profile lpmscore.VideoProfile) error
	SufficientBroadcasterDeposit() (bool, error)
	Claim() (claimCount int, rc chan types.Receipt, ec chan error)
	Verify() error
	DistributeFees() error
}

type LivepeerNode

type LivepeerNode struct {
	Identity     NodeID
	Addrs        []string
	VideoNetwork net.VideoNetwork
	VideoDB      *VideoDB
	Eth          eth.LivepeerEthClient
	EthAccount   string
	EthPassword  string
	Ipfs         ipfs.IpfsApi
	WorkDir      string
	PeerConns    []PeerConn
}

LivepeerNode handles videos going in and coming out of the Livepeer network.

func NewLivepeerNode

func NewLivepeerNode(e eth.LivepeerEthClient, vn net.VideoNetwork, nodeId NodeID, addrs []string, wd string) (*LivepeerNode, error)

NewLivepeerNode creates a new Livepeer Node. Eth can be nil.

func (*LivepeerNode) BroadcastFinishMsg

func (n *LivepeerNode) BroadcastFinishMsg(strmID string) error

func (*LivepeerNode) BroadcastManifestToNetwork

func (n *LivepeerNode) BroadcastManifestToNetwork(manifest stream.HLSVideoManifest) error

func (*LivepeerNode) BroadcastStreamToNetwork

func (n *LivepeerNode) BroadcastStreamToNetwork(strm stream.HLSVideoStream) error

BroadcastToNetwork is called when a new broadcast stream is available. It lets the network decide how to deal with the stream.

func (*LivepeerNode) ClaimVerifyAndDistributeFees

func (n *LivepeerNode) ClaimVerifyAndDistributeFees(cm ClaimManager) error

func (*LivepeerNode) CreateTranscodeJob

func (n *LivepeerNode) CreateTranscodeJob(strmID StreamID, profiles []lpmscore.VideoProfile, price uint64) error

CreateTranscodeJob creates the on-chain transcode job.

func (*LivepeerNode) GetMasterPlaylistFromNetwork

func (n *LivepeerNode) GetMasterPlaylistFromNetwork(mid ManifestID) *m3u8.MasterPlaylist

GetMasterPlaylistFromNetwork blocks until it gets the playlist, or it times out.

func (*LivepeerNode) NotifyBroadcaster

func (n *LivepeerNode) NotifyBroadcaster(nid NodeID, strmID StreamID, transcodeStrmIDs map[StreamID]lpmscore.VideoProfile) error

NotifyBroadcaster sends a messages to the broadcaster of the video stream, containing the new streamIDs of the transcoded video streams.

func (*LivepeerNode) Start

func (n *LivepeerNode) Start(ctx context.Context, bootID, bootAddr string) error

Start sets up the Livepeer protocol and connects the node to the network

func (*LivepeerNode) SubscribeFromNetwork

func (n *LivepeerNode) SubscribeFromNetwork(ctx context.Context, strmID StreamID, strm stream.HLSVideoStream) error

SubscribeFromNetwork subscribes to a stream on the network. Returns the stream as a reference.

func (*LivepeerNode) TranscodeAndBroadcast

func (n *LivepeerNode) TranscodeAndBroadcast(config net.TranscodeConfig, cm ClaimManager, t transcoder.Transcoder) ([]StreamID, error)

TranscodeAndBroadcast transcodes one stream into multiple streams (specified by TranscodeConfig), broadcasts the streams, and returns a list of streamIDs.

func (*LivepeerNode) UnsubscribeFromNetwork

func (n *LivepeerNode) UnsubscribeFromNetwork(strmID StreamID) error

UnsubscribeFromNetwork unsubscribes to a stream on the network.

type ManifestID

type ManifestID string

ManifestID is NodeID|VideoID

func MakeManifestID

func MakeManifestID(nodeID NodeID, id []byte) (ManifestID, error)

func (*ManifestID) GetNodeID

func (id *ManifestID) GetNodeID() NodeID

func (*ManifestID) GetVideoID

func (id *ManifestID) GetVideoID() []byte

func (*ManifestID) IsValid

func (id *ManifestID) IsValid() bool

func (ManifestID) String

func (id ManifestID) String() string

type NodeID

type NodeID string

NodeID can be converted from libp2p PeerID.

type PeerConn

type PeerConn struct {
	NodeID   string
	NodeAddr string
}

type RewardManager

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

RewardManager manages the transcoder's reward-calling cycle.

func NewRewardManager

func NewRewardManager(checkFreq time.Duration, client eth.LivepeerEthClient) *RewardManager

NewRewardManager creates a new reward manager with a given checkFrequency.

func (*RewardManager) Start

func (r *RewardManager) Start(ctx context.Context)

Start repeatedly calls reward.

type SignedSegment

type SignedSegment struct {
	Seg stream.HLSSegment
	Sig []byte
}

Segment and its signature by the broadcaster

func BytesToSignedSegment

func BytesToSignedSegment(data []byte) (SignedSegment, error)

Convenience function to convert between SignedSegments and byte slices to put on the wire.

type SortUint64

type SortUint64 []int64

func (SortUint64) Len

func (a SortUint64) Len() int

func (SortUint64) Less

func (a SortUint64) Less(i, j int) bool

func (SortUint64) Swap

func (a SortUint64) Swap(i, j int)

type StreamID

type StreamID string

StreamID is NodeID|VideoID|Rendition

func MakeStreamID

func MakeStreamID(nodeID NodeID, id []byte, rendition string) (StreamID, error)

func (*StreamID) GetNodeID

func (id *StreamID) GetNodeID() NodeID

func (*StreamID) GetRendition

func (id *StreamID) GetRendition() string

func (*StreamID) GetVideoID

func (id *StreamID) GetVideoID() []byte

func (*StreamID) IsValid

func (id *StreamID) IsValid() bool

func (StreamID) String

func (id StreamID) String() string

type VideoDB

type VideoDB struct {
	SelfNodeID string
	// contains filtered or unexported fields
}

VideoDB stores the video streams, the video buffers, and related information in memory. Note that HLS streams may have many streamIDs, each representing a ABS rendition, so there may be multiple streamIDs that map to the same HLS stream in the streams map.

func NewVideoDB

func NewVideoDB(selfNodeID string) *VideoDB

NewVideo Create a new VideoDB with the node's network address

func (*VideoDB) AddJid

func (s *VideoDB) AddJid(strmID StreamID, jid *big.Int)

func (*VideoDB) AddNewHLSManifest

func (s *VideoDB) AddNewHLSManifest(manifestID ManifestID) (stream.HLSVideoManifest, error)

func (*VideoDB) AddNewHLSStream

func (s *VideoDB) AddNewHLSStream(strmID StreamID) (strm stream.HLSVideoStream, err error)

AddNewHLSStream creates a new HLS video stream in the VideoDB

func (*VideoDB) AddNewRTMPStream

func (s *VideoDB) AddNewRTMPStream(strmID StreamID) (strm stream.RTMPVideoStream, err error)

AddNewRTMPStream creates a new RTMP video stream in the VideoDB

func (*VideoDB) AddStream

func (s *VideoDB) AddStream(strmID StreamID, strm stream.VideoStream) (err error)

AddStream adds an existing video stream.

func (*VideoDB) DeleteHLSManifest

func (s *VideoDB) DeleteHLSManifest(mid ManifestID)

func (*VideoDB) DeleteStream

func (s *VideoDB) DeleteStream(strmID StreamID)

func (*VideoDB) GetHLSManifest

func (s *VideoDB) GetHLSManifest(mid ManifestID) stream.HLSVideoManifest

func (*VideoDB) GetHLSManifestFromStreamID

func (s *VideoDB) GetHLSManifestFromStreamID(strmID StreamID) (stream.HLSVideoManifest, error)

func (*VideoDB) GetHLSStream

func (s *VideoDB) GetHLSStream(id StreamID) stream.HLSVideoStream

GetHLSStream gets a HLS video stream stored in the VideoDB

func (*VideoDB) GetJidByStreamID

func (s *VideoDB) GetJidByStreamID(strmID StreamID) *big.Int

func (*VideoDB) GetRTMPStream

func (s *VideoDB) GetRTMPStream(id StreamID) stream.RTMPVideoStream

GetRTMPStream gets a RTMP video stream stored in the VideoDB

func (*VideoDB) GetStreamIDs

func (s *VideoDB) GetStreamIDs(format stream.VideoFormat) []StreamID

func (VideoDB) String

func (s VideoDB) String() string

Jump to

Keyboard shortcuts

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