Documentation
¶
Index ¶
- Constants
- func CheckConsistency(api, cookie *time.Time) string
- func TimeFromUnix(sec int64) *time.Time
- type Clock
- type FakeClock
- type HTTPTransport
- type ProbeResult
- func ClassifyUserInfo(def *v2.SiteDefinition, info v2.UserInfo, err error, clock Clock) *ProbeResult
- func Probe(ctx context.Context, def *v2.SiteDefinition, site v2.Site, clock Clock) (*ProbeResult, error)
- func ProbeGazelle(ctx context.Context, site sitev2.Site, clock Clock) (*ProbeResult, error)
- func ProbeMTorrent(ctx context.Context, site v2.Site, clock Clock) (*ProbeResult, error)
- func ProbeNexusPHP(ctx context.Context, site v2.Site, clock Clock, source ProbeSource) (*ProbeResult, error)
- func ProbeUnit3D(ctx context.Context, site v2.Site, clock Clock) (*ProbeResult, error)
- func ProbeWithFallback(ctx context.Context, def *v2.SiteDefinition, site v2.Site, clock Clock, ...) (*ProbeResult, error)
- type ProbeSource
- type ProbeStatus
- type RealClock
- type Transport
- type UserInfoFetcher
- type UserInfoServiceTransport
Constants ¶
const ConsistencyDrift = "drift"
ConsistencyDrift is the sentinel string written into SiteLoginState.LastConsistencyCheck when the API and cookie last-login timestamps disagree by more than the threshold.
Variables ¶
This section is empty.
Functions ¶
func CheckConsistency ¶
CheckConsistency compares two last-login timestamps after UTC normalization. Returns "drift" only when both pointers are non-nil and the absolute delta exceeds 24h; returns "" in all other cases (including either side being nil).
func TimeFromUnix ¶
TimeFromUnix converts a positive Unix timestamp to a UTC-normalized time pointer. UTC normalization prevents timezone drift bugs (Metis EC-9).
Types ¶
type FakeClock ¶
type FakeClock struct {
// contains filtered or unexported fields
}
func NewFakeClock ¶
type HTTPTransport ¶
type HTTPTransport struct{}
HTTPTransport delegates to the existing schema-specific probe functions.
func (HTTPTransport) FetchUserInfo ¶
func (HTTPTransport) FetchUserInfo(ctx context.Context, def *v2.SiteDefinition, site v2.Site, clock Clock) (*ProbeResult, error)
func (HTTPTransport) Name ¶
func (HTTPTransport) Name() string
type ProbeResult ¶
type ProbeResult struct {
Status ProbeStatus
LastLoginAt *time.Time
LastAccessAt *time.Time
// FallbackNote 记录后备通道没有成功时的说明(保留主通道结果时附带),写进 LastProbeError。
FallbackNote string
Source ProbeSource
RawError error
Diagnostic string
}
func ClassifyUserInfo ¶ added in v1.0.0
func ClassifyUserInfo(def *v2.SiteDefinition, info v2.UserInfo, err error, clock Clock) *ProbeResult
ClassifyUserInfo 按站点架构把一次用户信息获取的结果归类,HTTP 主通道与 UserInfoService 主通道共用。
func Probe ¶
func Probe(ctx context.Context, def *v2.SiteDefinition, site v2.Site, clock Clock) (*ProbeResult, error)
Probe routes the request to the schema-specific probe function based on def.Schema. All I/O is performed through site.GetUserInfo, which inherits the project's circuit breaker and rate limiter from site/v2/http_client.go; dispatcher.go itself MUST NOT issue raw HTTP requests.
Panics raised by individual probes are recovered and surfaced as a ProbeResult with Status=UNKNOWN so that a single misbehaving probe cannot crash the LoginReminderMonitor goroutine and stop progress for other sites.
HDDolby, Rousi, IPTorrents, FireFly and PigGo schemas share the NexusPHP probe implementation because their drivers expose the same UserInfo shape (LastAccess + LastLogin).
func ProbeGazelle ¶
func ProbeMTorrent ¶
func ProbeNexusPHP ¶
func ProbeNexusPHP(ctx context.Context, site v2.Site, clock Clock, source ProbeSource) (*ProbeResult, error)
ProbeNexusPHP wraps Site.GetUserInfo() for NexusPHP-schema sites. All I/O is delegated to the driver; this function performs only classification.
func ProbeUnit3D ¶
ProbeUnit3D wraps a Unit3D Site.GetUserInfo call and classifies any error into the 8-status ProbeStatus taxonomy. It never issues raw HTTP requests; all transport flows through the underlying driver (which inherits circuit breaking and rate limiting from site/v2/http_client.go).
func ProbeWithFallback ¶
func ProbeWithFallback(ctx context.Context, def *v2.SiteDefinition, site v2.Site, clock Clock, primary, fallback Transport) (*ProbeResult, error)
ProbeWithFallback runs the primary transport first and invokes fallback only for statuses that indicate transport-level blocking rather than invalid user credentials. It never runs both transports concurrently.
后备只在返回 OK 时替换主通道的结果;后备返回其他状态(包括 NOT_APPLICABLE)或出错时, 保留主通道的状态,只把后备的说明记进 FallbackNote。所以 NOT_APPLICABLE 不会成为站点状态。
type ProbeSource ¶
type ProbeSource string
ProbeSource identifies which authentication path produced a probe's last-login timestamp. The caller (LoginReminderMonitor) uses this to dispatch the timestamp into either ApiLastLoginAt (API key) or CookieLastLoginAt (cookie session).
const ( ProbeSourceHTTPCookie ProbeSource = "http_cookie" ProbeSourceHTTPAPIKey ProbeSource = "http_api_key" ProbeSourceCloak ProbeSource = "cloak" )
type ProbeStatus ¶
type ProbeStatus string
const ( OK ProbeStatus = "OK" SESSION_EXPIRED ProbeStatus = "SESSION_EXPIRED" CHALLENGE ProbeStatus = "CHALLENGE" RATE_LIMITED ProbeStatus = "RATE_LIMITED" NETWORK_ERROR ProbeStatus = "NETWORK_ERROR" PARSE_ERROR ProbeStatus = "PARSE_ERROR" KEY_ERROR ProbeStatus = "KEY_ERROR" UNKNOWN ProbeStatus = "UNKNOWN" // NOT_APPLICABLE marks a probe path that was deliberately skipped // (e.g. mTorrent CloakBrowser cookie path when no cookie is configured). // No Manager call is made and no error is recorded. NOT_APPLICABLE ProbeStatus = "NOT_APPLICABLE" // NOT_CONFIGURED 表示站点缺少其认证方式要求的凭证,本次没有向站点发请求,不计失败、不提醒。 NOT_CONFIGURED ProbeStatus = "NOT_CONFIGURED" // UNSUPPORTED 表示站点没有内置定义(动态站点),无法构造探测,不发请求、不计失败、不提醒。 UNSUPPORTED ProbeStatus = "UNSUPPORTED" )
func (ProbeStatus) IsCredentialFailure ¶ added in v1.0.0
func (s ProbeStatus) IsCredentialFailure() bool
IsCredentialFailure 报告该状态是否说明凭证本身失效(需要用户重新同步),而不是暂时性故障。
func (ProbeStatus) IsFailure ¶ added in v1.0.0
func (s ProbeStatus) IsFailure() bool
IsFailure 报告该状态是否计入失败连续段。OK、NOT_CONFIGURED、UNSUPPORTED、NOT_APPLICABLE 都不算。
func (ProbeStatus) String ¶
func (s ProbeStatus) String() string
type Transport ¶
type Transport interface {
Name() string
FetchUserInfo(ctx context.Context, def *v2.SiteDefinition, site v2.Site, clock Clock) (*ProbeResult, error)
}
Transport abstracts how a probe fetches user info from a PT site.
Metis AP-3: dispatcher uses a transport-pluggable single probe, not parallel dual probes. ProbeWithFallback selects at most one fallback after the primary result is classified as fallback-eligible.
type UserInfoFetcher ¶ added in v1.0.0
type UserInfoFetcher interface {
FetchAndSave(ctx context.Context, siteID string) (v2.UserInfo, error)
}
UserInfoFetcher 取回并保存站点的用户信息,即 v2.UserInfoService 的 FetchAndSave。
type UserInfoServiceTransport ¶ added in v1.0.0
type UserInfoServiceTransport struct {
Service UserInfoFetcher
SiteID string
}
UserInfoServiceTransport 经 UserInfoService 探测:用与搜索共用的站点实例和限速器取用户信息, 取到的数据同时写入用户统计。它忽略 FetchUserInfo 的 site 参数,按 SiteID 取已注册的实例。
func (UserInfoServiceTransport) FetchUserInfo ¶ added in v1.0.0
func (t UserInfoServiceTransport) FetchUserInfo(ctx context.Context, def *v2.SiteDefinition, _ v2.Site, clock Clock) (*ProbeResult, error)
func (UserInfoServiceTransport) Name ¶ added in v1.0.0
func (UserInfoServiceTransport) Name() string