Documentation
¶
Overview ¶
Package hath client/server side impl
Index ¶
- Constants
- Variables
- type Action
- type Certificate
- type Client
- func (c *Client) FetchRemoteSettings(isRunning bool) (*RPCResponse, error)
- func (c *Client) GetRPCHost() string
- func (c *Client) GetRPCURL(act Action, add string) *url.URL
- func (c *Client) GetRawPKCS12() ([]byte, error)
- func (c *Client) GetStaticRangeFetchURL(fileIndex, xres, fileID string) ([]string, error)
- func (c *Client) GetTLSCertificate() (*tls.Certificate, error)
- func (c *Client) NotifyShutdown() error
- func (c *Client) NotifyStarted() error
- func (c *Client) RPCRawRequest(uri *url.URL) (*RPCResponse, error)
- func (c *Client) RPCRequest(act Action, add string) (*RPCResponse, error)
- func (c *Client) SyncTimeDelta() error
- type Config
- type Downloader
- type HTTPErr
- type HVFile
- type RPCPayload
- type RPCResponse
- type RPCServers
- type RPCStatus
- type RemoteSettings
- type Server
- func (s *Server) Addr() int
- func (s *Server) HandleHV(fileID string, addStr string, fileName string) (*HVFile, error)
- func (s *Server) HandleHathCmd(serverIP, cmd, add, serverTime, key string) ([]byte, error)
- func (s *Server) HandleTest(sizeStr, timeStr, key string) ([]byte, error)
- func (s *Server) ParseRPCRequest(req *http.Request) (interface{}, error)
- func (s *Server) TLSConfig() (*tls.Config, error)
- type Settings
- type Storage
- type StorageConf
Constants ¶
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 ¶
var ( // ErrRespIsNull server error ErrRespIsNull = errors.New("obb response") 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") )
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 (*Client) FetchRemoteSettings ¶
func (c *Client) FetchRemoteSettings(isRunning bool) (*RPCResponse, error)
FetchRemoteSettings fetch client settings from h@h, priority more than local config
func (*Client) GetRawPKCS12 ¶
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 ¶
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 ¶
NotifyShutdown notify h@h server we are shutdown
func (*Client) NotifyStarted ¶
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 ¶
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 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 ¶
NewHVFileFromFileID ...
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.
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 ¶
RPCServers multi-server for rpc call, using weighted round-robin aglo
to load balancing.
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 (*Server) HandleHathCmd ¶
HandleHathCmd ... TODO translate into general struct, to support Fiber web framework.
form: /servercmd/$command/$additional/$time/$key
func (*Server) ParseRPCRequest ¶
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.
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 ...
type StorageConf ¶
type StorageConf struct {
DBFile string `mapstructure:"db_file"`
}
StorageConf ...