common

package
v0.5.17 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 35 Imported by: 9

Documentation

Index

Constants

View Source
const DEBUG = 5
View Source
const SHORT = 4
View Source
const VERBOSE = 6
View Source
const VideoProfileIDBytes = 4
View Source
const VideoProfileIDSize = 8

Variables

View Source
var (
	ErrParseBigInt = fmt.Errorf("failed to parse big integer")
	ErrProfile     = fmt.Errorf("failed to parse profile")

	ErrFormatProto = fmt.Errorf("unknown VideoProfile format for protobufs")
	ErrFormatMime  = fmt.Errorf("unknown VideoProfile format for mime type")
	ErrFormatExt   = fmt.Errorf("unknown VideoProfile format for extension")
	ErrProfProto   = fmt.Errorf("unknown VideoProfile profile for protobufs")
	ErrProfName    = fmt.Errorf("unknown VideoProfile profile name")
)
View Source
var ErrDBTooNew = errors.New("DB Too New")
View Source
var HTTPTimeout = 8 * time.Second

HTTPTimeout timeout used in HTTP connections between nodes

View Source
var LivepeerDBVersion = 1
View Source
var MaxDuration = (5 * time.Minute)

Max Segment Duration

View Source
var MaxSegSize = int(MaxDuration.Seconds()) * (maxInputBitrate / 8)

Max Segment Size in bytes (cap reading HTTP response body at this size)

View Source
var RandomBytesGenerator = func(length uint) []byte {
	x := make([]byte, length, length)
	for i := 0; i < len(x); i++ {
		x[i] = byte(rand.Uint32())
	}
	return x
}
View Source
var RandomIDGenerator = func(length uint) string {
	return hex.EncodeToString(RandomBytesGenerator(length))
}

RandomIDGenerator generates random hexadecimal string of specified length defined as variable for unit tests

View Source
var VideoProfileByteLookup = makeVideoProfileByteMap()
View Source
var VideoProfileNameLookup = map[string]string{
	"a7ac137a": "P720p60fps16x9",
	"49d54ea9": "P720p30fps16x9",
	"e4a64019": "P720p25fps16x9",
	"79332fe7": "P720p30fps4x3",
	"5ecf4b52": "P576p30fps16x9",
	"8b1843d6": "P576p25fps16x9",
	"93c717e7": "P360p30fps16x9",
	"7cd40fc7": "P360p25fps16x9",
	"b60382a0": "P360p30fps4x3",
	"c0a6517a": "P240p30fps16x9",
	"1301a7d0": "P240p25fps16x9",
	"d435c53a": "P240p30fps4x3",
	"fca40bf9": "P144p30fps16x9",
	"03f01d1f": "P144p25fps16x9",
}

Functions

func BaseTokenAmountToFixed added in v0.5.2

func BaseTokenAmountToFixed(baseAmount *big.Int) (int64, error)

BaseTokenAmountToFixed converts the base amount of a token (i.e. ETH/LPT) represented as a big.Int into a fixed point number represented as a int64 using a scalingFactor of 100000 resulting in max decimal places of 5

func BytesToVideoProfile added in v0.5.0

func BytesToVideoProfile(txData []byte) ([]ffmpeg.VideoProfile, error)

func DefaultProfileName added in v0.5.2

func DefaultProfileName(width int, height int, bitrate int) string

func EncoderProfileNameToValue added in v0.5.9

func EncoderProfileNameToValue(profile string) (ffmpeg.Profile, error)

func FFmpegProfiletoNetProfile added in v0.5.2

func FFmpegProfiletoNetProfile(ffmpegProfiles []ffmpeg.VideoProfile) ([]*net.VideoProfile, error)

func FixedToPrice added in v0.5.5

func FixedToPrice(price int64) *big.Rat

FixedToPrice converts an fixed point number with 3 decimal places represented as in int64 into a big.Rat

func GenErrRegex added in v0.5.0

func GenErrRegex(errStrings []string) *regexp.Regexp

GenErrRegex generates a regexp `(err1)|(err2)|(err3)` given a list of error strings [err1, err2, err3]

func GetConnectionAddr added in v0.5.0

func GetConnectionAddr(ctx context.Context) string

func GetPass added in v0.5.2

func GetPass(s string) (string, error)

GetPass attempts to read a file for a password at the supplied location. If it fails, then the original supplied string will be returned to the caller. A valid string will always be returned, regardless of whether an error occurred.

func IgnoreRoutines added in v0.5.12

func IgnoreRoutines() []goleak.Option

IgnoreRoutines goroutines to ignore in tests

func JoinURL added in v0.5.13

func JoinURL(url, path string) string

func MaxUint256OrFatal added in v0.5.0

func MaxUint256OrFatal(t *testing.T) *big.Int

func ParseBigInt added in v0.3.3

func ParseBigInt(num string) (*big.Int, error)

func PriceToFixed added in v0.5.0

func PriceToFixed(price *big.Rat) (int64, error)

PriceToFixed converts a big.Rat into a fixed point number represented as int64 using a scaleFactor of 1000 resulting in max decimal places of 3

func ProfileExtensionFormat added in v0.5.6

func ProfileExtensionFormat(ext string) ffmpeg.Format

func ProfileFormatExtension added in v0.5.6

func ProfileFormatExtension(f ffmpeg.Format) (string, error)

func ProfileFormatMimeType added in v0.5.6

func ProfileFormatMimeType(f ffmpeg.Format) (string, error)

func ProfilesNames added in v0.5.0

func ProfilesNames(profiles []ffmpeg.VideoProfile) string

func ProfilesToHex added in v0.5.0

func ProfilesToHex(profiles []ffmpeg.VideoProfile) string

func ProfilesToTranscodeOpts added in v0.3.3

func ProfilesToTranscodeOpts(profiles []ffmpeg.VideoProfile) []byte

func RandName added in v0.5.0

func RandName() string

RandName generates random hexadecimal string

func RatPriceInfo added in v0.5.5

func RatPriceInfo(priceInfo *net.PriceInfo) (*big.Rat, error)

func ReadAtMost added in v0.5.17

func ReadAtMost(r io.Reader, n int) ([]byte, error)

Read at most n bytes from an io.Reader

func Retry

func Retry(attempts int, sleep time.Duration, fn func() error) error

func ToInt64 added in v0.5.4

func ToInt64(val *big.Int) int64

func TxDataToVideoProfile added in v0.3.3

func TxDataToVideoProfile(txData string) ([]ffmpeg.VideoProfile, error)

func TypeByExtension added in v0.5.13

func TypeByExtension(ext string) (string, error)

func WaitAssert

func WaitAssert(t *testing.T, waitTime time.Duration, condition func() bool, msg string)

func WaitUntil

func WaitUntil(waitTime time.Duration, condition func() bool)

Types

type Broadcaster added in v0.5.1

type Broadcaster interface {
	Address() ethcommon.Address
	Sign([]byte) ([]byte, error)
}

type CapabilityComparator added in v0.5.10

type CapabilityComparator interface {
	CompatibleWith(*net.Capabilities) bool
	LegacyOnly() bool
}

type DB added in v0.3.3

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

DB is an initialized DB driver with prepared statements

func InitDB added in v0.3.3

func InitDB(dbPath string) (*DB, error)

func TempDB added in v0.3.3

func TempDB(t *testing.T) (*DB, *sql.DB, error)

func (*DB) ChainID added in v0.5.0

func (db *DB) ChainID() (*big.Int, error)

func (*DB) Close added in v0.3.3

func (db *DB) Close()

func (*DB) DeleteMiniHeader added in v0.5.0

func (db *DB) DeleteMiniHeader(hash ethcommon.Hash) error

DeleteMiniHeader deletes a MiniHeader from the DB and takes in the blockhash of the block to be deleted as an argument

func (*DB) DeleteUnbondingLock added in v0.5.0

func (db *DB) DeleteUnbondingLock(id *big.Int, delegator ethcommon.Address) error

DeleteUnbondingLock deletes an unbonding lock from the DB with the given ID and delegator address. This method will return nil for non-existent unbonding locks

func (*DB) FindAllMiniHeadersSortedByNumber added in v0.5.0

func (db *DB) FindAllMiniHeadersSortedByNumber() ([]*blockwatch.MiniHeader, error)

FindAllMiniHeadersSortedByNumber returns all MiniHeaders in the DB sorting in descending order by block number

func (*DB) FindLatestMiniHeader added in v0.5.0

func (db *DB) FindLatestMiniHeader() (*blockwatch.MiniHeader, error)

FindLatestMiniHeader returns the MiniHeader with the highest blocknumber in the DB

func (*DB) InsertMiniHeader added in v0.5.0

func (db *DB) InsertMiniHeader(header *blockwatch.MiniHeader) error

InsertMiniHeader inserts a MiniHeader into the database

func (*DB) InsertUnbondingLock added in v0.3.3

func (db *DB) InsertUnbondingLock(id *big.Int, delegator ethcommon.Address, amount, withdrawRound *big.Int) error

func (*DB) LastSeenBlock added in v0.3.3

func (db *DB) LastSeenBlock() (*big.Int, error)

LastSeenBlock returns the last block number stored by the DB

func (*DB) MarkWinningTicketRedeemed added in v0.5.9

func (db *DB) MarkWinningTicketRedeemed(ticket *pm.SignedTicket, txHash ethcommon.Hash) error

MarkWinningTicketRedeemed stores the on-chain transaction hash and timestamp of redemption This marks the ticket as being 'redeemed'

func (*DB) OrchCount added in v0.5.1

func (db *DB) OrchCount(filter *DBOrchFilter) (int, error)

func (*DB) RemoveWinningTicket added in v0.5.9

func (db *DB) RemoveWinningTicket(ticket *pm.SignedTicket) error

RemoveWinningTicket removes a ticket

func (*DB) SelectEarliestWinningTicket added in v0.5.9

func (db *DB) SelectEarliestWinningTicket(sender ethcommon.Address, minCreationRound int64) (*pm.SignedTicket, error)

SelectEarliestWinningTicket selects the earliest stored winning ticket for a 'sender' that is not expired and not yet redeemed

func (*DB) SelectOrchs added in v0.5.0

func (db *DB) SelectOrchs(filter *DBOrchFilter) ([]*DBOrch, error)

func (*DB) SetChainID added in v0.5.0

func (db *DB) SetChainID(id *big.Int) error

func (*DB) StoreWinningTicket added in v0.5.0

func (db *DB) StoreWinningTicket(ticket *pm.SignedTicket) error

StoreWinningTicket stores a signed ticket

func (*DB) UnbondingLockIDs added in v0.3.3

func (db *DB) UnbondingLockIDs() ([]*big.Int, error)

func (*DB) UnbondingLocks added in v0.3.3

func (db *DB) UnbondingLocks(currentRound *big.Int) ([]*DBUnbondingLock, error)

func (*DB) UpdateOrch added in v0.5.0

func (db *DB) UpdateOrch(orch *DBOrch) error

func (*DB) UseUnbondingLock added in v0.3.3

func (db *DB) UseUnbondingLock(id *big.Int, delegator ethcommon.Address, usedBlock *big.Int) error

UseUnbondingLock sets an unbonding lock in the DB as used by setting the lock's used block. If usedBlock is nil this method will set the lock's used block to NULL

func (*DB) WinningTicketCount added in v0.5.9

func (db *DB) WinningTicketCount(sender ethcommon.Address, minCreationRound int64) (int, error)

WinningTicketCount returns the amount of non-redeemed winning tickets for a 'sender'

type DBOrch added in v0.5.0

type DBOrch struct {
	ServiceURI        string
	EthereumAddr      string
	PricePerPixel     int64
	ActivationRound   int64
	DeactivationRound int64
	Stake             int64 // Stored as a fixed point number
}

DBOrch is the type binding for a row result from the orchestrators table

func NewDBOrch added in v0.5.0

func NewDBOrch(ethereumAddr string, serviceURI string, pricePerPixel int64, activationRound int64, deactivationRound int64, stake int64) *DBOrch

type DBOrchFilter added in v0.5.0

type DBOrchFilter struct {
	MaxPrice     *big.Rat
	CurrentRound *big.Int
	Addresses    []ethcommon.Address
}

DBOrchFilter is an object used to attach a filter to a selectOrch query

type DBUnbondingLock added in v0.3.3

type DBUnbondingLock struct {
	ID            int64
	Delegator     ethcommon.Address
	Amount        *big.Int
	WithdrawRound int64
}

DBOrch is the type binding for a row result from the unbondingLocks table

type OrchestratorPool added in v0.5.1

type OrchestratorPool interface {
	GetURLs() []*url.URL
	GetOrchestrators(int, Suspender, CapabilityComparator) ([]*net.OrchestratorInfo, error)
	Size() int
}

type OrchestratorStore added in v0.5.1

type OrchestratorStore interface {
	OrchCount(filter *DBOrchFilter) (int, error)
	SelectOrchs(filter *DBOrchFilter) ([]*DBOrch, error)
	UpdateOrch(orch *DBOrch) error
}

type RoundsManager added in v0.5.4

type RoundsManager interface {
	LastInitializedRound() *big.Int
}

type StubServerStream added in v0.5.0

type StubServerStream struct {
}

func (*StubServerStream) Context added in v0.5.0

func (s *StubServerStream) Context() context.Context

func (*StubServerStream) RecvMsg added in v0.5.0

func (s *StubServerStream) RecvMsg(m interface{}) error

func (*StubServerStream) Send added in v0.5.0

func (*StubServerStream) SendHeader added in v0.5.0

func (s *StubServerStream) SendHeader(md metadata.MD) error

func (*StubServerStream) SendMsg added in v0.5.0

func (s *StubServerStream) SendMsg(m interface{}) error

func (*StubServerStream) SetHeader added in v0.5.0

func (s *StubServerStream) SetHeader(md metadata.MD) error

func (*StubServerStream) SetTrailer added in v0.5.0

func (s *StubServerStream) SetTrailer(md metadata.MD)

type Suspender added in v0.5.6

type Suspender interface {
	Suspended(orch string) int
}

type VideoProfileByteMap added in v0.5.0

type VideoProfileByteMap map[[VideoProfileIDBytes]byte]string

Jump to

Keyboard shortcuts

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