services

package
v0.0.0-...-40033ae Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClickhouseDSNFlag = "clickhouse-dsn"
)

Variables

This section is empty.

Functions

func GetBaseURL

func GetBaseURL() string

func MakeJobID

func MakeJobID(cfg *JobConfig, params *InitParams) string

func RegisterClickHouseDBFlags

func RegisterClickHouseDBFlags(f []cli.Flag) []cli.Flag

func RegisterClickHouseFlags

func RegisterClickHouseFlags(f []cli.Flag) []cli.Flag

func RegisterCommonFlags

func RegisterCommonFlags(f []cli.Flag) []cli.Flag

func RegisterConnectionConfigFlags

func RegisterConnectionConfigFlags(f []cli.Flag) []cli.Flag

func RegisterEndpointsFlags

func RegisterEndpointsFlags(f []cli.Flag) []cli.Flag

func RegisterGRPCFlags

func RegisterGRPCFlags(f []cli.Flag) []cli.Flag

func RegisterGRPCProxyFlags

func RegisterGRPCProxyFlags(f []cli.Flag) []cli.Flag

func RegisterHTTPProxyFlags

func RegisterHTTPProxyFlags(f []cli.Flag) []cli.Flag

func RegisterJobFlags

func RegisterJobFlags(f []cli.Flag) []cli.Flag

func RegisterNodesStatFlags

func RegisterNodesStatFlags(f []cli.Flag) []cli.Flag

func RegisterPromClientFlags

func RegisterPromClientFlags(f []cli.Flag) []cli.Flag

func RegisterSubdomainsFlags

func RegisterSubdomainsFlags(f []cli.Flag) []cli.Flag

func RegisterWebFlags

func RegisterWebFlags(f []cli.Flag) []cli.Flag

Types

type AccessHistory

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

func NewAccessHistory

func NewAccessHistory() *AccessHistory

func (*AccessHistory) Store

func (s *AccessHistory) Store(oip string, oua string, nip string, nua string) (bool, int)

type AccessLock

type AccessLock struct {
	C chan error
	// contains filtered or unexported fields
}

func NewAccessLock

func NewAccessLock() *AccessLock

func (*AccessLock) Unlock

func (al *AccessLock) Unlock()

func (*AccessLock) Unlocked

func (al *AccessLock) Unlocked() chan error

type BucketPool

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

func NewBucketPool

func NewBucketPool() *BucketPool

func (*BucketPool) Get

func (s *BucketPool) Get(mc jwt.MapClaims) (*ratelimit.Bucket, error)

type Claims

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

func NewClaims

func NewClaims(cs *Clients) *Claims

func (*Claims) Get

func (s *Claims) Get(tokenString string, apiKey string) (jwt.MapClaims, *Client, error)

func (*Claims) Set

func (s *Claims) Set(apiKey string, claims jwt.Claims) (string, error)

type ClickHouse

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

func NewClickHouse

func NewClickHouse(c *cli.Context, db DBProvider) *ClickHouse

func (*ClickHouse) Add

func (s *ClickHouse) Add(sr *StatRecord) error

func (*ClickHouse) Close

func (s *ClickHouse) Close()

type ClickHouseDB

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

func NewClickHouseDB

func NewClickHouseDB(c *cli.Context) *ClickHouseDB

func (*ClickHouseDB) Close

func (s *ClickHouseDB) Close()

func (*ClickHouseDB) Get

func (s *ClickHouseDB) Get() (*sql.DB, error)

type Client

type Client struct {
	Name   string `yaml:"name"`
	ApiKey string `yaml:"apiKey"`
	Secret string `yaml:"secret"`
}

type Clients

type Clients []Client

func NewClients

func NewClients() (*Clients, error)

func (Clients) Empty

func (s Clients) Empty() bool

func (Clients) Get

func (s Clients) Get(apiKey string) *Client

type ConnectionConfig

type ConnectionConfig struct {
	ServiceConfig
	JobConfig
	Name           string
	ConnectionType ConnectionType
	Mod            bool
}

type ConnectionType

type ConnectionType int
const (
	ConnectionTypeService ConnectionType = 0
	ConnectionTypeJob     ConnectionType = 1
)

type ConnectionsConfig

type ConnectionsConfig map[string]*ConnectionConfig

func NewConnectionsConfig

func NewConnectionsConfig(c *cli.Context) *ConnectionsConfig

func (ConnectionsConfig) GetDefault

func (s ConnectionsConfig) GetDefault() *ConnectionConfig

func (ConnectionsConfig) GetMod

func (s ConnectionsConfig) GetMod(name string) *ConnectionConfig

func (ConnectionsConfig) GetMods

func (s ConnectionsConfig) GetMods() []string

type DBProvider

type DBProvider interface {
	Get() (*sql.DB, error)
}

type DISTRIBUTION

type DISTRIBUTION int
const (
	Hash DISTRIBUTION = iota
	NodeHash
)

type Endpoints

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

func NewEndpoints

func NewEndpoints(c *cli.Context, cl *K8SClient, name string) *Endpoints

func (*Endpoints) Get

func (s *Endpoints) Get() (*corev1.Endpoints, error)

type EndpointsPool

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

func NewEndpointsPool

func NewEndpointsPool(c *cli.Context, cl *K8SClient) *EndpointsPool

func (*EndpointsPool) Get

func (s *EndpointsPool) Get(name string) (*corev1.Endpoints, error)

type GRPCProxy

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

func NewGRPCProxy

func NewGRPCProxy(c *cli.Context, bu string, claims *Claims, r *Resolver, src *Source, parser *URLParser, logger *logrus.Entry) *GRPCProxy

func (*GRPCProxy) Close

func (s *GRPCProxy) Close()

func (*GRPCProxy) Connect

func (s *GRPCProxy) Connect(ctx context.Context, method string) (context.Context, *grpc.ClientConn, error)

func (*GRPCProxy) Get

func (s *GRPCProxy) Get() *grpc.Server

func (*GRPCProxy) Release

func (s *GRPCProxy) Release(ctx context.Context, conn *grpc.ClientConn)

type GRPCServer

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

func NewGRPCServer

func NewGRPCServer(c *cli.Context, p *GRPCProxy) *GRPCServer

func (*GRPCServer) Close

func (s *GRPCServer) Close()

func (*GRPCServer) Serve

func (s *GRPCServer) Serve() error

type HTTPGRPCProxy

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

func NewHTTPGRPCProxy

func NewHTTPGRPCProxy(p *GRPCProxy) *HTTPGRPCProxy

func (*HTTPGRPCProxy) Close

func (s *HTTPGRPCProxy) Close()

func (*HTTPGRPCProxy) Get

type HTTPGRPCProxyPool

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

func NewHTTPGRPCProxyPool

func NewHTTPGRPCProxyPool(c *cli.Context, bu string, claims *Claims, r *Resolver) *HTTPGRPCProxyPool

func (*HTTPGRPCProxyPool) Get

type HTTPProxy

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

func NewHTTPProxy

func NewHTTPProxy(c *cli.Context, r *Resolver, src *Source, logger *logrus.Entry, invoke bool, cl *Client) *HTTPProxy

func (*HTTPProxy) Get

func (s *HTTPProxy) Get() (*httputil.ReverseProxy, error)

type HTTPProxyPool

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

func NewHTTPProxyPool

func NewHTTPProxyPool(c *cli.Context, r *Resolver) *HTTPProxyPool

func (*HTTPProxyPool) Get

func (s *HTTPProxyPool) Get(src *Source, logger *logrus.Entry, invoke bool, cl *Client) (*httputil.ReverseProxy, error)

type Init

type Init struct {
	InitParams       *InitParams
	ConnectionConfig *ConnectionConfig
}

type InitParams

type InitParams struct {
	InfoHash       string
	OriginPath     string
	SourceURL      string
	Path           string
	Extra          string
	RunIfNotExists bool
}

type JobConfig

type JobConfig struct {
	Type                               JobType
	Name                               string
	Image                              string
	CPURequests                        string
	CPULimits                          string
	MemoryRequests                     string
	MemoryLimits                       string
	Grace                              int
	IgnoredPaths                       []string
	UseSnapshot                        string
	ToCompletion                       bool
	SnapshotStartFullDownloadThreshold float64
	SnapshotStartThreshold             float64
	SnapshotDownloadRatio              float64
	SnapshotTorrentSizeLimit           int64
	AWSAccessKeyID                     string
	AWSSecretAccessKey                 string
	AWSEndpoint                        string
	AWSRegion                          string
	AWSBucket                          string
	AWSBucketSpread                    string
	AWSNoSSL                           string
	RequestAffinity                    bool
	AffinityKey                        string
	AffinityValue                      string
	Env                                map[string]string
	Labels                             map[string]string
	HTTPProxy                          string
}

func (*JobConfig) CheckIgnorePaths

func (s *JobConfig) CheckIgnorePaths(name string) bool

type JobLocation

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

func NewJobLocation

func NewJobLocation(c *cli.Context, cfg *JobConfig, params *InitParams, cl *K8SClient, logger *logrus.Entry, l *Locker, acl *Client) *JobLocation

func (*JobLocation) Get

func (s *JobLocation) Get() (*Location, error)

func (*JobLocation) Invoke

func (s *JobLocation) Invoke(purge bool) (*Location, error)

func (*JobLocation) Wait

func (s *JobLocation) Wait() (*Location, error)

type JobLocationPool

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

func NewJobLocationPool

func NewJobLocationPool(c *cli.Context, cl *K8SClient, l *Locker) *JobLocationPool

func (*JobLocationPool) Get

func (s *JobLocationPool) Get(cfg *JobConfig, params *InitParams, logger *logrus.Entry, purge bool, invoke bool, cl *Client) (*Location, error)

type JobType

type JobType string
const (
	JobTypeTranscoder JobType = "transcoder"
)

type K8SClient

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

func NewK8SClient

func NewK8SClient() *K8SClient

func (*K8SClient) Get

func (s *K8SClient) Get() (*kubernetes.Clientset, error)

type Location

type Location struct {
	Ports
	IP          net.IP
	Unavailable bool
	Expire      chan bool
}

type Locker

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

func NewLocker

func NewLocker(r *cs.RedisClient) *Locker

func (*Locker) Get

func (s *Locker) Get() *redislock.Client

type Mod

type Mod struct {
	Type  string `json:"type"`
	Path  string `json:"path"`
	Extra string `json:"extra"`
	Name  string `json:"name"`
}

Mod struct represents modification of source file.

type NodeBandwidth

type NodeBandwidth struct {
	High    uint64
	Low     uint64
	Current uint64
}

type NodeCPU

type NodeCPU struct {
	High    float64
	Low     float64
	Current float64
}

type NodeStat

type NodeStat struct {
	Name string
	IP   string
	NodeBandwidth
	NodeCPU
	Pool []string
}

type NodeStatWithScore

type NodeStatWithScore struct {
	NodeStat
	Score    float64
	Distance int
}

type NodesStat

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

func NewNodesStat

func NewNodesStat(c *cli.Context, pcl *PromClient, kcl *K8SClient) *NodesStat

func (*NodesStat) Get

func (s *NodesStat) Get() ([]NodeStat, error)

type NodesStatPool

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

func NewNodesStatPool

func NewNodesStatPool(c *cli.Context, pcl *PromClient, kcl *K8SClient) *NodesStatPool

func (*NodesStatPool) Get

func (s *NodesStatPool) Get() ([]NodeStat, error)

type Ports

type Ports struct {
	GRPC  int
	HTTP  int
	Probe int
}

type PromClient

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

func NewPromClient

func NewPromClient(c *cli.Context) *PromClient

func (*PromClient) Get

func (s *PromClient) Get() (v1.API, error)

type Resolver

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

func NewResolver

func NewResolver(baseURL string, cfg *ConnectionsConfig, svcLocPool *ServiceLocationPool, jobLocPool *JobLocationPool) *Resolver

func (*Resolver) Resolve

func (s *Resolver) Resolve(src *Source, logger *logrus.Entry, purge bool, invoke bool, cl *Client) (*Location, error)

type ResponseWriterInterceptor

type ResponseWriterInterceptor struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWrtierInterceptor

func NewResponseWrtierInterceptor(w http.ResponseWriter) *ResponseWriterInterceptor

func (*ResponseWriterInterceptor) Flush

func (w *ResponseWriterInterceptor) Flush()

func (*ResponseWriterInterceptor) GroupedStatusCode

func (w *ResponseWriterInterceptor) GroupedStatusCode() int

func (*ResponseWriterInterceptor) Hijack

func (*ResponseWriterInterceptor) Write

func (w *ResponseWriterInterceptor) Write(p []byte) (int, error)

func (*ResponseWriterInterceptor) WriteHeader

func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)

type ServiceConfig

type ServiceConfig struct {
	Name            string
	Distribution    DISTRIBUTION
	PreferLocalNode bool
	Headers         map[string]string
}

type ServiceLocation

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

func NewServiceLocation

func NewServiceLocation(c *cli.Context, cfg *ServiceConfig, params *InitParams, ep *EndpointsPool) *ServiceLocation

func (*ServiceLocation) Get

func (s *ServiceLocation) Get(purge bool) (*Location, error)

type ServiceLocationPool

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

func NewServiceLocationPool

func NewServiceLocationPool(c *cli.Context, ep *EndpointsPool) *ServiceLocationPool

func (*ServiceLocationPool) Get

func (s *ServiceLocationPool) Get(cfg *ServiceConfig, params *InitParams, purge bool) (*Location, error)

type Source

type Source struct {
	Type       string `json:"type"`
	Name       string `json:"name"`
	InfoHash   string `json:"info_hash"`
	Path       string `json:"path"`
	OriginPath string `json:"origin_path"`
	Token      string `json:"token"`
	ApiKey     string `json:"api_key"`
	Query      string `json:"query"`
	Mod        *Mod
}

Source struct represents torrent file source. Source may have additional modification.

func (*Source) GetEdgeName

func (s *Source) GetEdgeName() string

func (*Source) GetEdgeType

func (s *Source) GetEdgeType() string

func (*Source) GetKey

func (s *Source) GetKey() string

type SourceType

type SourceType string
const (
	Internal SourceType = "internal"
	External SourceType = "external"
)

type StandardClaims

type StandardClaims struct {
	Grace  int    `json:"grace"`
	Preset string `json:"preset"`
	Rate   string `json:"rate"`
	Role   string `json:"role"`
	jwt.StandardClaims
}

type StatRecord

type StatRecord struct {
	Timestamp     time.Time
	ApiKey        string
	Client        string
	BytesWritten  uint64
	TTFB          uint64
	Duration      uint64
	Path          string
	InfoHash      string
	OriginalPath  string
	SessionID     string
	Domain        string
	Status        uint64
	GroupedStatus uint64
	Edge          string
	Source        string
	Role          string
	Ads           bool
}

type Subdomains

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

func NewSubdomains

func NewSubdomains(c *cli.Context, k8s *K8SClient, nsp *NodesStatPool, infoHash string, skipActiveJobSearch bool, useCPU bool, useBandwidth bool, pools []string) *Subdomains

func (*Subdomains) Get

func (s *Subdomains) Get() ([]NodeStatWithScore, []string, error)

type SubdomainsPool

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

func NewSubdomainsPool

func NewSubdomainsPool(c *cli.Context, k8s *K8SClient, nsp *NodesStatPool) *SubdomainsPool

func (*SubdomainsPool) Get

func (s *SubdomainsPool) Get(infoHash string, skipActiveJobSearch bool, useCPU bool, useBandwidth bool, pools []string) ([]NodeStatWithScore, []string, error)

type ThrottledResponseWriter

type ThrottledResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ThrottledResponseWriter) Flush

func (w *ThrottledResponseWriter) Flush()

func (*ThrottledResponseWriter) Hijack

func (*ThrottledResponseWriter) Write

func (w *ThrottledResponseWriter) Write(p []byte) (int, error)

func (*ThrottledResponseWriter) WriteHeader

func (w *ThrottledResponseWriter) WriteHeader(statusCode int)

type URLParser

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

func NewURLParser

func NewURLParser(c *ConnectionsConfig) *URLParser

func (*URLParser) Parse

func (s *URLParser) Parse(url *url.URL) (*Source, error)

Parse extracts information about source and additional modifiacation of it

type Web

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

func NewWeb

func NewWeb(c *cli.Context, baseURL string, parser *URLParser, r *Resolver, pr *HTTPProxyPool, grpc *HTTPGRPCProxyPool, claims *Claims, subs *SubdomainsPool, bp *BucketPool, ch *ClickHouse, cfg *ConnectionsConfig, ah *AccessHistory) *Web

func (*Web) Close

func (s *Web) Close()

func (*Web) Serve

func (s *Web) Serve() error

Jump to

Keyboard shortcuts

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