nntpcli

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package nntpcli is a generated GoMock package.

Package nntp provides base NNTP definitions.

Package nntpcli is a generated GoMock package.

Index

Constants

View Source
const (
	// 2xx - Positive Completion
	StatusReady          = 200 // Service available, posting allowed
	StatusReadyNoPosting = 201 // Service available, posting prohibited
	StatusQuit           = 205 // Connection closing
	StatusGroupSelected  = 211 // Group selected
	StatusBodyFollows    = 222 // Body article retrieved
	StatusStatSuccess    = 223 // Article exists
	StatusArticlePosted  = 240 // Article posted successfully
	StatusAuthenticated  = 281 // Authentication successful

	// 3xx - Positive Intermediate
	StatusPasswordRequired     = 340 // Password required
	StatusMoreAuthInfoRequired = 381 // More authentication information required

	// 4xx - Transient Negative Completion
	StatusNoSuchGroup         = 411 // No such newsgroup
	StatusNoArticleSelected   = 420 // No article selected
	StatusNoSuchArticleNumber = 423 // No article with that number
	StatusNoSuchArticle       = 430 // No article with that message-id

	// 5xx - Permanent Negative Completion
	StatusCommandUnknown     = 500 // Command not recognized
	StatusCommandSyntaxError = 501 // Command syntax error
	StatusPermissionDenied   = 502 // Permission denied / Too many connections
	StatusProgramFault       = 503 // Program fault
)

NNTP response codes as defined in RFC 3977

View Source
const (
	Unknown             = PostingStatus(0)
	PostingPermitted    = PostingStatus('y')
	PostingNotPermitted = PostingStatus('n')
	PostingModerated    = PostingStatus('m')
)

PostingStatus values.

View Source
const (
	SegmentAlreadyExistsErrCode = 441
	TooManyConnectionsErrCode   = 502
	CanNotJoinGroup             = 411
	ArticleNotFoundErrCode      = 430
)
View Source
const (
	NumberOfStatResParams = 3
)

Legacy constants for backward compatibility

Variables

View Source
var (
	ErrCapabilitiesUnpopulated = errors.New("capabilities unpopulated")
	ErrNoSuchCapability        = errors.New("no such capability")
	ErrNilNttpConn             = errors.New("nil nntp connection")
	ErrArticleNotFound         = errors.New("article not found")
	ErrSegmentAlreadyExists    = errors.New("segment already exists")
)

Functions

func IsArticleNotFoundError

func IsArticleNotFoundError(err error) bool

func IsSegmentAlreadyExistsError

func IsSegmentAlreadyExistsError(err error) bool

Types

type Article

type Article struct {
	// The article's headers
	Header textproto.MIMEHeader
	// The article's body
	Body io.Reader
	// Number of bytes in the article body (used by OVER/XOVER)
	Bytes int
	// Number of lines in the article body (used by OVER/XOVER)
	Lines int
}

An Article that may appear in one or more groups.

func (*Article) MessageID

func (a *Article) MessageID() string

MessageID provides convenient access to the article's Message ID.

func (*Article) String

func (a *Article) String() string

type ArticleBodyReader

type ArticleBodyReader interface {
	io.ReadCloser
	GetYencHeaders() (YencHeaders, error)
}

type Client

type Client interface {
	Dial(
		ctx context.Context,
		host string,
		port int,
		config ...DialConfig,
	) (Connection, error)
	DialTLS(
		ctx context.Context,
		host string,
		port int,
		insecureSSL bool,
		config ...DialConfig,
	) (Connection, error)
}

func New

func New(
	c ...Config,
) Client

New creates a new NNTP client

If no config is provided, the default config will be used

type Config

type Config struct {
	// KeepAliveTime is the time that the client will keep the connection alive.
	KeepAliveTime time.Duration
	// OperationTimeout is the timeout for NNTP operations.
	// Set to 0 to disable timeouts.
	OperationTimeout time.Duration
}

type Connection

type Connection interface {
	io.Closer
	Authenticate(username, password string) (err error)
	JoinGroup(name string) error
	BodyDecoded(msgID string, w io.Writer, discard int64) (int64, error)
	BodyReader(msgID string) (ArticleBodyReader, error)
	// BodyPipelined sends multiple BODY commands in a pipeline and returns results in order.
	// This method sends all BODY commands before reading any responses, which can significantly
	// improve throughput on high-latency connections.
	// If requests is empty, returns an empty slice.
	// If requests has only one element, falls back to sequential BodyDecoded for simplicity.
	BodyPipelined(requests []PipelineRequest) []PipelineResult
	// TestPipelineSupport tests if the server supports pipelining by sending multiple
	// STAT commands for the same message ID and verifying all responses are received correctly.
	// Returns true if pipelining is supported, along with a suggested pipeline depth based on
	// measured round-trip latency.
	// Suggested depth ranges: 2-4 for <50ms latency, 4-6 for 50-100ms, 6-10 for >100ms.
	TestPipelineSupport(testMsgID string) (supported bool, suggestedDepth int, err error)
	Post(r io.Reader) (int64, error)
	Ping() error
	CurrentJoinedGroup() string
	MaxAgeTime() time.Time
	Stat(msgID string) (int, error)
	Capabilities() ([]string, error)
}

type ContextDialer added in v2.3.0

type ContextDialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

ContextDialer is a dialer that supports context. Use this for proxy connections or custom dialing behavior.

type DialConfig

type DialConfig struct {
	KeepAliveTime time.Duration
	DialTimeout   time.Duration
	// Dialer is an optional custom dialer. If nil, net.Dialer is used.
	// Use this for proxy connections.
	Dialer ContextDialer
}

type Group

type Group struct {
	Name        string
	Description string
	Count       int64
	High        int64
	Low         int64
	Posting     PostingStatus
}

Group represents a usenet newsgroup.

type MockClient

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

MockClient is a mock of Client interface.

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) Dial

func (m *MockClient) Dial(ctx context.Context, host string, port int, config ...DialConfig) (Connection, error)

Dial mocks base method.

func (*MockClient) DialTLS

func (m *MockClient) DialTLS(ctx context.Context, host string, port int, insecureSSL bool, config ...DialConfig) (Connection, error)

DialTLS mocks base method.

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) Dial

func (mr *MockClientMockRecorder) Dial(ctx, host, port any, config ...any) *gomock.Call

Dial indicates an expected call of Dial.

func (*MockClientMockRecorder) DialTLS

func (mr *MockClientMockRecorder) DialTLS(ctx, host, port, insecureSSL any, config ...any) *gomock.Call

DialTLS indicates an expected call of DialTLS.

type MockConnection

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

MockConnection is a mock of Connection interface.

func NewMockConnection

func NewMockConnection(ctrl *gomock.Controller) *MockConnection

NewMockConnection creates a new mock instance.

func (*MockConnection) Authenticate

func (m *MockConnection) Authenticate(username, password string) error

Authenticate mocks base method.

func (*MockConnection) BodyDecoded

func (m *MockConnection) BodyDecoded(msgID string, w io.Writer, discard int64) (int64, error)

BodyDecoded mocks base method.

func (*MockConnection) BodyPipelined added in v2.3.0

func (m *MockConnection) BodyPipelined(requests []PipelineRequest) []PipelineResult

BodyPipelined mocks base method.

func (*MockConnection) BodyReader

func (m *MockConnection) BodyReader(msgID string) (ArticleBodyReader, error)

BodyReader mocks base method.

func (*MockConnection) Capabilities

func (m *MockConnection) Capabilities() ([]string, error)

Capabilities mocks base method.

func (*MockConnection) Close

func (m *MockConnection) Close() error

Close mocks base method.

func (*MockConnection) CurrentJoinedGroup

func (m *MockConnection) CurrentJoinedGroup() string

CurrentJoinedGroup mocks base method.

func (*MockConnection) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockConnection) JoinGroup

func (m *MockConnection) JoinGroup(name string) error

JoinGroup mocks base method.

func (*MockConnection) MaxAgeTime

func (m *MockConnection) MaxAgeTime() time.Time

MaxAgeTime mocks base method.

func (*MockConnection) Ping

func (m *MockConnection) Ping() error

Ping mocks base method.

func (*MockConnection) Post

func (m *MockConnection) Post(r io.Reader) (int64, error)

Post mocks base method.

func (*MockConnection) Stat

func (m *MockConnection) Stat(msgID string) (int, error)

Stat mocks base method.

func (*MockConnection) TestPipelineSupport added in v2.3.0

func (m *MockConnection) TestPipelineSupport(testMsgID string) (bool, int, error)

TestPipelineSupport mocks base method.

type MockConnectionMockRecorder

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

MockConnectionMockRecorder is the mock recorder for MockConnection.

func (*MockConnectionMockRecorder) Authenticate

func (mr *MockConnectionMockRecorder) Authenticate(username, password any) *gomock.Call

Authenticate indicates an expected call of Authenticate.

func (*MockConnectionMockRecorder) BodyDecoded

func (mr *MockConnectionMockRecorder) BodyDecoded(msgID, w, discard any) *gomock.Call

BodyDecoded indicates an expected call of BodyDecoded.

func (*MockConnectionMockRecorder) BodyPipelined added in v2.3.0

func (mr *MockConnectionMockRecorder) BodyPipelined(requests any) *gomock.Call

BodyPipelined indicates an expected call of BodyPipelined.

func (*MockConnectionMockRecorder) BodyReader

func (mr *MockConnectionMockRecorder) BodyReader(msgID any) *gomock.Call

BodyReader indicates an expected call of BodyReader.

func (*MockConnectionMockRecorder) Capabilities

func (mr *MockConnectionMockRecorder) Capabilities() *gomock.Call

Capabilities indicates an expected call of Capabilities.

func (*MockConnectionMockRecorder) Close

func (mr *MockConnectionMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockConnectionMockRecorder) CurrentJoinedGroup

func (mr *MockConnectionMockRecorder) CurrentJoinedGroup() *gomock.Call

CurrentJoinedGroup indicates an expected call of CurrentJoinedGroup.

func (*MockConnectionMockRecorder) JoinGroup

func (mr *MockConnectionMockRecorder) JoinGroup(name any) *gomock.Call

JoinGroup indicates an expected call of JoinGroup.

func (*MockConnectionMockRecorder) MaxAgeTime

func (mr *MockConnectionMockRecorder) MaxAgeTime() *gomock.Call

MaxAgeTime indicates an expected call of MaxAgeTime.

func (*MockConnectionMockRecorder) Ping

Ping indicates an expected call of Ping.

func (*MockConnectionMockRecorder) Post

Post indicates an expected call of Post.

func (*MockConnectionMockRecorder) Stat

func (mr *MockConnectionMockRecorder) Stat(msgID any) *gomock.Call

Stat indicates an expected call of Stat.

func (*MockConnectionMockRecorder) TestPipelineSupport added in v2.3.0

func (mr *MockConnectionMockRecorder) TestPipelineSupport(testMsgID any) *gomock.Call

TestPipelineSupport indicates an expected call of TestPipelineSupport.

type MockContextDialer added in v2.3.0

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

MockContextDialer is a mock of ContextDialer interface.

func NewMockContextDialer added in v2.3.0

func NewMockContextDialer(ctrl *gomock.Controller) *MockContextDialer

NewMockContextDialer creates a new mock instance.

func (*MockContextDialer) DialContext added in v2.3.0

func (m *MockContextDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext mocks base method.

func (*MockContextDialer) EXPECT added in v2.3.0

EXPECT returns an object that allows the caller to indicate expected use.

type MockContextDialerMockRecorder added in v2.3.0

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

MockContextDialerMockRecorder is the mock recorder for MockContextDialer.

func (*MockContextDialerMockRecorder) DialContext added in v2.3.0

func (mr *MockContextDialerMockRecorder) DialContext(ctx, network, address any) *gomock.Call

DialContext indicates an expected call of DialContext.

type NNTPError added in v2.3.2

type NNTPError struct {
	Code int
	Msg  string
}

NNTPError represents a numeric error response from an NNTP server. It replaces textproto.Error to remove the dependency on net/textproto.

func (*NNTPError) Error added in v2.3.2

func (e *NNTPError) Error() string

type Option

type Option func(*Config)

type PipelineRequest added in v2.3.0

type PipelineRequest struct {
	// MessageID is the article message ID to retrieve.
	MessageID string
	// Writer is the destination for the decoded body content.
	Writer io.Writer
	// Discard is the number of bytes to discard from the beginning of the body.
	// Use 0 for full download.
	Discard int64
}

PipelineRequest represents a single body request in a pipeline.

type PipelineResult added in v2.3.0

type PipelineResult struct {
	// MessageID is the article message ID that was requested.
	MessageID string
	// BytesWritten is the number of bytes written to the writer.
	BytesWritten int64
	// Error is any error that occurred during the request.
	// nil indicates success.
	Error error
}

PipelineResult represents the result of a pipelined body request.

type PostingStatus

type PostingStatus byte

PostingStatus type for groups.

func (PostingStatus) String

func (ps PostingStatus) String() string

type YencHeaders

type YencHeaders struct {
	FileName   string
	FileSize   int64
	PartNumber int64
	TotalParts int64
	Offset     int64
	PartSize   int64
	Hash       uint32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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