Documentation
¶
Index ¶
- Variables
- func IsArticleNotFound(err error) bool
- type ArticleNotFoundError
- type Auth
- type Client
- func (c *Client) AddProvider(provider *Provider, tier ProviderType) error
- func (c *Client) Article(ctx context.Context, id string, w io.Writer) error
- func (c *Client) Body(ctx context.Context, id string, w io.Writer) error
- func (c *Client) BodyAt(ctx context.Context, id string, w io.WriterAt) error
- func (c *Client) BodyReader(ctx context.Context, id string) (YencReader, error)
- func (c *Client) Close()
- func (c *Client) Date(ctx context.Context) error
- func (c *Client) Group(ctx context.Context, group string) (*Response, error)
- func (c *Client) Head(ctx context.Context, id string) (*Response, error)
- func (c *Client) Metrics() map[string]ProviderMetrics
- func (c *Client) Post(ctx context.Context, headers map[string]string, body io.Reader) (*Response, error)
- func (c *Client) PostYenc(ctx context.Context, headers map[string]string, body io.Reader, ...) (*Response, error)
- func (c *Client) RemoveProvider(provider *Provider) error
- func (c *Client) Send(ctx context.Context, payload []byte, bodyWriter io.Writer) <-chan Response
- func (c *Client) SpeedTest(ctx context.Context, articleIDs []string) (SpeedTestStats, error)
- func (c *Client) Stat(ctx context.Context, id string) (*Response, error)
- type ConnFactory
- type NNTPClient
- type NNTPConnection
- type NNTPResponse
- type Provider
- func (c *Provider) Close() error
- func (c *Provider) Date(ctx context.Context) error
- func (c *Provider) Metrics() ProviderMetrics
- func (c *Provider) Send(ctx context.Context, payload []byte, bodyWriter io.Writer) <-chan Response
- func (c *Provider) SendRequest(req *Request) <-chan Response
- func (c *Provider) ThrottleConnections()
- type ProviderConfig
- type ProviderMetrics
- type ProviderType
- type Request
- type Response
- type SpeedTestStats
- type YencHeader
- type YencOptions
- type YencReader
Constants ¶
This section is empty.
Variables ¶
var ErrProviderClosed = errors.New("provider closed")
ErrProviderClosed is returned when a request is made to a closed provider.
ErrProviderUnavailable is returned when all connections to a provider have failed. This error is retryable - the client should try other providers or retry later.
Functions ¶
func IsArticleNotFound ¶ added in v3.1.1
IsArticleNotFound checks if an error is an ArticleNotFoundError. Returns true if the error (or any error in the chain) indicates an article was not found.
Types ¶
type ArticleNotFoundError ¶ added in v3.1.1
ArticleNotFoundError indicates an article was not found (NNTP 430 status).
func (*ArticleNotFoundError) Error ¶ added in v3.1.1
func (e *ArticleNotFoundError) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddProvider ¶
func (c *Client) AddProvider(provider *Provider, tier ProviderType) error
func (*Client) BodyAt ¶
BodyAt retrieves the body of an article by its message ID, writing to an io.WriterAt.
func (*Client) BodyReader ¶
BodyReader retrieves the body of an article by its message ID as a stream. It returns a reader that provides access to yEnc headers as soon as they are parsed.
func (*Client) Group ¶
Group selects a newsgroup. Note: In a connection pool, this selection only applies to the specific connection used for this request and is not guaranteed to persist for subsequent requests.
func (*Client) Metrics ¶
func (c *Client) Metrics() map[string]ProviderMetrics
Metrics returns metrics for all active providers.
func (*Client) Post ¶ added in v3.1.0
func (c *Client) Post(ctx context.Context, headers map[string]string, body io.Reader) (*Response, error)
Post posts an article to the NNTP server with the given headers and body. The headers map should contain standard NNTP headers like "From", "Newsgroups", "Subject", etc. The body reader provides the article content which will be transmitted with proper dot-stuffing.
NNTP response codes:
- 240: Article posted successfully
- 340: Send article to be posted (intermediate response)
- 440: Posting not allowed
- 441: Posting failed
func (*Client) PostYenc ¶ added in v3.1.0
func (c *Client) PostYenc(ctx context.Context, headers map[string]string, body io.Reader, opts *YencOptions) (*Response, error)
PostYenc posts an article with automatic yEnc encoding. The body reader provides the raw binary content which will be yEnc encoded before posting. The opts parameter specifies yEnc encoding options including filename, file size, and part information.
For single-part files, set opts.Part to 0 or 1 and opts.Total to 0 or 1. For multi-part files, set opts.Part and opts.Total appropriately, along with PartBegin and PartEnd.
NNTP response codes:
- 240: Article posted successfully
- 340: Send article to be posted (intermediate response)
- 440: Posting not allowed
- 441: Posting failed
func (*Client) RemoveProvider ¶
type ConnFactory ¶
ConnFactory is used by Client to create connections.
type NNTPClient ¶
type NNTPClient interface {
// Provider management
AddProvider(provider *Provider, tier ProviderType) error
RemoveProvider(provider *Provider) error
Close()
// Article retrieval methods
Body(ctx context.Context, id string, w io.Writer) error
BodyReader(ctx context.Context, id string) (YencReader, error)
BodyAt(ctx context.Context, id string, w io.WriterAt) error
Article(ctx context.Context, id string, w io.Writer) error
Head(ctx context.Context, id string) (*Response, error)
Stat(ctx context.Context, id string) (*Response, error)
Group(ctx context.Context, group string) (*Response, error)
// Article posting methods
Post(ctx context.Context, headers map[string]string, body io.Reader) (*Response, error)
PostYenc(ctx context.Context, headers map[string]string, body io.Reader, opts *YencOptions) (*Response, error)
// Advanced methods
Send(ctx context.Context, payload []byte, bodyWriter io.Writer) <-chan Response
Metrics() map[string]ProviderMetrics
SpeedTest(ctx context.Context, articleIDs []string) (SpeedTestStats, error)
Date(ctx context.Context) error
}
NNTPClient defines the public API for NNTP operations. The Client type implements this interface.
type NNTPConnection ¶
type NNTPConnection struct {
Greeting NNTPResponse
// contains filtered or unexported fields
}
func NewNNTPConnection ¶
func (*NNTPConnection) Close ¶
func (c *NNTPConnection) Close() error
func (*NNTPConnection) Done ¶
func (c *NNTPConnection) Done() <-chan struct{}
func (*NNTPConnection) Ready ¶ added in v3.2.0
func (c *NNTPConnection) Ready() <-chan struct{}
func (*NNTPConnection) Run ¶
func (c *NNTPConnection) Run()
type NNTPResponse ¶
type NNTPResponse struct {
BytesDecoded int
BytesConsumed int
Lines []string
Format rapidyenc.Format
FileName string
FileSize int64
Part int64
PartBegin int64
PartSize int64
EndSize int64
Total int64
ExpectedCRC uint32
Message string
State rapidyenc.State
StatusCode int
CRC uint32
OnYencHeader func(*YencHeader)
// contains filtered or unexported fields
}
type Provider ¶
type Provider struct {
Host string
// contains filtered or unexported fields
}
func NewProvider ¶
func NewProvider(ctx context.Context, config ProviderConfig) (*Provider, error)
func (*Provider) Close ¶
Close cancels the provider, closes its request channel, and waits for all connections to stop.
func (*Provider) Metrics ¶
func (c *Provider) Metrics() ProviderMetrics
func (*Provider) SendRequest ¶
func (*Provider) ThrottleConnections ¶ added in v3.2.0
func (c *Provider) ThrottleConnections()
ThrottleConnections temporarily reduces max connections to current active count. Called when the server returns a "max connections exceeded" error.
type ProviderConfig ¶
type ProviderConfig struct {
Address string
MaxConnections int
InitialConnections int
InflightPerConnection int
MaxConnIdleTime time.Duration
MaxConnLifetime time.Duration
// HealthCheckPeriod is how often the centralized health monitor scans connections
// for idle/lifetime expiration. Default: 1s. Set to 0 to disable health checks
// (connections will then manage their own timeouts via timers).
HealthCheckPeriod time.Duration
Auth Auth
TLSConfig *tls.Config
ConnFactory ConnFactory
// ProxyURL configures SOCKS proxy connection (e.g., "socks5://host:port" or "socks5://user:pass@host:port").
// Supports socks4, socks4a, and socks5 protocols.
// Only used when ConnFactory is nil.
ProxyURL string
}
type ProviderMetrics ¶
type ProviderType ¶
type ProviderType int
const ( ProviderPrimary ProviderType = iota ProviderBackup )
type Response ¶
type Response struct {
StatusCode int
Status string
// For non-body multiline responses (CAPABILITIES, etc).
Lines []string
// Decoded payload bytes (only if Request.BodyWriter == nil).
Body bytes.Buffer
// Decoder metadata/status gathered while parsing.
Meta NNTPResponse
Err error
Request *Request
}
type SpeedTestStats ¶
type SpeedTestStats struct {
TotalBytes int64
Duration time.Duration
BytesPerSecond float64
SuccessCount int32
FailureCount int32
}
SpeedTestStats contains metrics from a speed test run.
type YencHeader ¶
type YencOptions ¶ added in v3.1.0
type YencOptions struct {
FileName string // Required: Name of the file being encoded
FileSize int64 // Required: Total size of the original file
Part int64 // For multi-part files (1-based), 0 or 1 means single-part
Total int64 // For multi-part files, total number of parts
PartBegin int64 // For multi-part files, beginning byte offset (1-based)
PartEnd int64 // For multi-part files, ending byte offset (1-based, inclusive)
}
YencOptions contains options for yEnc encoding when posting articles.
type YencReader ¶
type YencReader interface {
io.ReadCloser
YencHeaders() *YencHeader
}