hath

package
v0.0.0-...-757ae40 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package hath client/server side impl

Index

Constants

View Source
const (
	ClientVersion = "1.6.1#go"
	// ClientBuild is among other things used by the server to determine the client's capabilities. any forks should use the build number as an indication of compatibility with mainline, rather than an internal build number.
	ClientBuild       = 154
	ClientKeyLength   = 20
	MaxKeyTimeDrift   = 300
	MaxConnectionBase = 20
	TCPPacketSize     = 1460

	ClientRPCProtocol   = "http"
	ClientRPCHost       = "rpc.hentaiathome.net"
	ClientRPCFile       = "15/rpc"
	ClientLoginFilename = "CLIENT_LOGIN_FILENAME"

	ContentTypeDefault = "text/html; charset=ISO-8859-1"
	ContentTypeOctet   = "application/octet-stream"
	ContentTypeJPG     = "image/jpeg"
	ContentTypePNG     = "image/png"
	ContentTypeGIF     = "image/gif"
	ContentTypeWEBM    = "video/webm"
)

Variables

View Source
var (
	// ErrRespIsNull server error
	ErrRespIsNull = errors.New("obb response")
	// ErrTemporarilyUnavailable another server error
	ErrTemporarilyUnavailable = errors.New("temporarily unavailable")
	// ErrConnectTestFailed The server failed to verify that this client is online and available from the Internet.
	ErrConnectTestFailed = errors.New("failed external connection test")
	// ErrIPAddressInUse The server detected that another client was already connected from this computer or local network.
	// 	You can only have one client running per public IP address.
	ErrIPAddressInUse = errors.New("another client was already connected")
	// ErrClientIDInUse The server detected that another client is already using this client ident.
	//	If you want to run more than one client, you have to apply for additional idents.
	ErrClientIDInUse = errors.New("another client is already using this client ident")
)
View Source
var ErrNotFound = leveldb.ErrNotFound

ErrNotFound ...

Functions

This section is empty.

Types

type Action

type Action string
var (
	ActionServerStat           Action = "server_stat"
	ActionGetBlacklist         Action = "get_blacklist"
	ActionGetCertificate       Action = "get_cert"
	ActionClientLogin          Action = "client_login"
	ActionClientSettings       Action = "client_settings"
	ActionClientStart          Action = "client_start"
	ActionClientSuspend        Action = "client_suspend"
	ActionClientResume         Action = "client_resume"
	ActionClientStop           Action = "client_stop"
	ActionStillAlive           Action = "still_alive"
	ActionStaticRangeFetch     Action = "srfetch"
	ActionDownloaderFetch      Action = "dlfetch"
	ActionDownloaderFailreport Action = "dlfails"
	ActionOverload             Action = "overload"
)

type Certificate

type Certificate struct {
	*tls.Certificate
	// contains filtered or unexported fields
}

Certificate tls cert for multi-goroutine

func (*Certificate) GetCertificate

func (c *Certificate) GetCertificate() (*tls.Certificate, error)

GetCertificate get cert

func (*Certificate) StoreCertificate

func (c *Certificate) StoreCertificate(cert *tls.Certificate)

StoreCertificate store cert

type Client

type Client struct {
	Settings
	RemoteSettings RemoteSettings

	RPCServers RPCServers

	Certificate *Certificate
	// contains filtered or unexported fields
}

Client connects to hath server.

func NewClient

func NewClient(config Settings) (*Client, error)

NewClient creates new client.

func (*Client) FetchRemoteSettings

func (c *Client) FetchRemoteSettings(isRunning bool) (*RPCResponse, error)

FetchRemoteSettings fetch client settings from h@h, priority more than local config

func (*Client) GetRPCHost

func (c *Client) GetRPCHost() string

GetRPCHost wrr load balancer

func (*Client) GetRPCURL

func (c *Client) GetRPCURL(act Action, add string) *url.URL

GetRPCURL url query string holds params.

func (*Client) GetRawPKCS12

func (c *Client) GetRawPKCS12() ([]byte, error)

GetRawPKCS12 raw pkck12 file from hath server, including 2 certs and 1 priv key,

2 certs for workload cert and intermediate cert. We need adition setps to handle.

func (*Client) GetStaticRangeFetchURL

func (c *Client) GetStaticRangeFetchURL(fileIndex, xres, fileID string) ([]string, error)

GetStaticRangeFetchURL ...

func (*Client) GetTLSCertificate

func (c *Client) GetTLSCertificate() (*tls.Certificate, error)

GetTLSCertificate the server returns pkcs12 package,

to server contents from HTTPS we need tls.Certificate
to provide digital encrypt and verification.

func (*Client) NotifyShutdown

func (c *Client) NotifyShutdown() error

NotifyShutdown notify h@h server we are shutdown

func (*Client) NotifyStarted

func (c *Client) NotifyStarted() error

NotifyStarted notify h@h server we are ready to receive requests

func (*Client) RPCRawRequest

func (c *Client) RPCRawRequest(uri *url.URL) (*RPCResponse, error)

RPCRawRequest will retry 3 times when failed, then downgrade rpc severs

TODO improve load balancer for less RTT

func (*Client) RPCRequest

func (c *Client) RPCRequest(act Action, add string) (*RPCResponse, error)

RPCRequest general rpc call.

func (*Client) SyncTimeDelta

func (c *Client) SyncTimeDelta() error

SyncTimeDelta sync clock with hath server

type Config

type Config struct {
	Settings    `mapstructure:",squash"`
	StorageConf `mapstructure:",squash"`
}

Config ...

type Downloader

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

Downloader ...

func NewDownloader

func NewDownloader() *Downloader

func (*Downloader) DiscardDownload

func (d *Downloader) DiscardDownload(uri string) (time.Duration, error)

DiscardDownload ...

func (*Downloader) DummyDownload

func (d *Downloader) DummyDownload(uri string) ([]byte, error)

DummyDownload ...

func (*Downloader) MultipleSourcesDownload

func (d *Downloader) MultipleSourcesDownload(sources []string, hv *HVFile) ([]byte, error)

MultipleSourcesDownload download from multi sources

func (*Downloader) ProxyDownload

func (d *Downloader) ProxyDownload(uri string) (io.Reader, error)

ProxyDownload ... TODO

type HTTPErr

type HTTPErr struct {
	Status int
	Err    error
}

HTTPErr contains http status code

func NewHTTPErr

func NewHTTPErr(status int, err error) *HTTPErr

NewHTTPErr ...

func (*HTTPErr) Error

func (err *HTTPErr) Error() string

type HVFile

type HVFile struct {
	Hash string `json:"hash"`
	Type string `json:"type"`
	Size int    `json:"size"`
	Xres int    `json:"xres"`
	Yres int    `json:"yres"`

	Data []byte `json:"-"`
}

HVFile ...

func NewHVFileFromFileID

func NewHVFileFromFileID(fileID string) (*HVFile, error)

NewHVFileFromFileID ...

func (*HVFile) FileID

func (f *HVFile) FileID() string

FileID main key

func (*HVFile) MIMEType

func (f *HVFile) MIMEType() string

MIMEType MIME Type

type RPCPayload

type RPCPayload []string

RPCPayload rpc payload data.

There might be 2 forms of respopnse,
1. key and value pairs
2. line data

func (RPCPayload) KeyValues

func (p RPCPayload) KeyValues() map[string]string

KeyValues kvs for settings.

func (RPCPayload) URLs

func (p RPCPayload) URLs() []*url.URL

URLs each line contains one url

type RPCResponse

type RPCResponse struct {
	Status  RPCStatus  `json:"status"`
	Payload RPCPayload `json:"payload"`
	Host    string     `json:"host"`
}

RPCResponse general hath response from server

type RPCServers

type RPCServers struct {
	sync.RWMutex

	Hosts    map[string]int
	Balancer wrr.WRR
}

RPCServers multi-server for rpc call, using weighted round-robin aglo

to load balancing.

type RPCStatus

type RPCStatus int
var (
	ResponseStatusNull RPCStatus = 0
	ResponseStatusOK   RPCStatus = 1
	ResponseStatusFail RPCStatus = -1
)

type RemoteSettings

type RemoteSettings struct {
	sync.RWMutex

	ServerPort   int `yaml:"server-port" mapstructure:"server-port"`
	StaticRanges map[string]int

	RawSettings map[string]string
}

RemoteSettings config from remote server, overwrite local config.

it can be modified from server side, so it can be hot reload.

type Server

type Server struct {
	HC *Client
	DL *Downloader

	Stor *Storage
	// contains filtered or unexported fields
}

Server p2p server

func NewServer

func NewServer(config Config) (*Server, error)

NewServer ...

func (*Server) Addr

func (s *Server) Addr() int

Addr ...

func (*Server) HandleHV

func (s *Server) HandleHV(fileID string, addStr string, fileName string) (*HVFile, error)

HandleHV ...

form: /h/$fileid/$additional/$filename

func (*Server) HandleHathCmd

func (s *Server) HandleHathCmd(serverIP, cmd, add, serverTime, key string) ([]byte, error)

HandleHathCmd ... TODO translate into general struct, to support Fiber web framework.

form: /servercmd/$command/$additional/$time/$key

func (*Server) HandleTest

func (s *Server) HandleTest(sizeStr, timeStr, key string) ([]byte, error)

HandleTest ...

form: /t/$testsize/$testtime/$testkey

func (*Server) ParseRPCRequest

func (s *Server) ParseRPCRequest(req *http.Request) (interface{}, error)

ParseRPCRequest only GET/HEAD methods avaliable on rpc call,

we will receive request from h@h server,
params are included in HTTP path.
ps: the original JAVA server parse raw HTTP line protocol,
using regex to match HTTP method, manauly split first line,
just like "GET /u/18544?s=48&v=4 HTTP/2", it's not elegant.

func (*Server) TLSConfig

func (s *Server) TLSConfig() (*tls.Config, error)

TLSConfig ...

type Settings

type Settings struct {
	ClientID  string `mapstructure:"client_id"`
	ClientKey string `mapstructure:"client_key"`
}

Settings stands for client side config.

type Storage

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

Storage ...

func NewStorage

func NewStorage(conf StorageConf) (*Storage, error)

NewStorage ...

func (*Storage) GetHVFile

func (s *Storage) GetHVFile(hv *HVFile) (*HVFile, error)

GetHVFile content of hvfile

func (*Storage) PutHVFile

func (s *Storage) PutHVFile(hv *HVFile, data []byte) error

PutHVFile store file

type StorageConf

type StorageConf struct {
	DBFile string `mapstructure:"db_file"`
}

StorageConf ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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