enn

package module
v0.0.0-...-0f44469 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 9 Imported by: 0

README

go nntp

I needed a way to gate some web services into traditional readers. I wrote an NNTP client and server.

I'm still working on coming up with the exact right interfaces, but take a look at the couchserver example to see what it takes to build a custom NNTP server with your own backend.

Documentation

Index

Constants

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

PostingStatus values.

Variables

View Source
var ErrAuthRejected = &NNTPError{452, "authorization rejected"}

ErrAuthRejected is returned for invalid authentication.

View Source
var ErrAuthRequired = &NNTPError{450, "authorization required"}

ErrAuthRequired is returned to indicate authentication is required to proceed.

View Source
var ErrInvalidArticleNumber = &NNTPError{423, "No article with that number"}

ErrInvalidArticleNumber is returned when an article is requested that can't be found.

View Source
var ErrInvalidMessageID = &NNTPError{430, "No article with that message-id"}

ErrInvalidMessageID is returned when a message is requested that can't be found.

View Source
var ErrNoCurrentArticle = &NNTPError{420, "Current article number is invalid"}

ErrNoCurrentArticle is returned when a command is executed that requires a current article when one has not been selected.

View Source
var ErrNoGroupSelected = &NNTPError{412, "No newsgroup selected"}

ErrNoSuchGroup is returned for a request that requires a current group when none has been selected.

View Source
var ErrNoSuchGroup = &NNTPError{411, "No such newsgroup"}

ErrNoSuchGroup is returned for a request for a group that can't be found.

View Source
var ErrNotAuthenticated = &NNTPError{480, "authentication required"}

ErrNotAuthenticated is returned when a command is issued that requires authentication, but authentication was not provided.

View Source
var ErrNotMod = &NNTPError{Code: 441, Msg: "Not moderator"}
View Source
var ErrNotWanted = &NNTPError{435, "Article not wanted"}

ErrNotWanted is returned when an attempt to post an article is rejected due the server not wanting the article.

View Source
var ErrPostingFailed = &NNTPError{441, "posting failed"}

ErrPostingFailed is returned when an attempt to post an article fails.

View Source
var ErrPostingNotPermitted = &NNTPError{440, "Posting not permitted"}

ErrPostingNotPermitted is returned as the response to an attempt to post an article where posting is not permitted.

View Source
var ErrPostingTooLarge = &NNTPError{441, "posting large article"}
View Source
var ErrServerBad = &NNTPError{500, "Server bad"}
View Source
var ErrSyntax = &NNTPError{501, "not supported, or syntax error"}

ErrSyntax is returned when a command can't be parsed.

View Source
var ErrUnknownCommand = &NNTPError{500, "Unknown command"}

ErrUnknownCommand is returned for unknown comands.

Functions

This section is empty.

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
	RemoteAddr net.Addr
}

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.

type Backend

type Backend interface {
	ListGroups(max int) ([]*Group, error)
	GetGroup(name string) (*Group, error)
	GetArticle(group *Group, id string, headerOnly bool) (*Article, error)
	GetArticles(group *Group, from, to int64, headerOnly bool) ([]NumberedArticle, error)
	// Authorized() bool
	// Authenticate and optionally swap out the backend for this session.
	// You may return nil to continue using the same backend.
	Authenticate(user, pass string) (Backend, error)
	AllowPost() bool
	Post(article *Article) error
}

The Backend that provides the things and does the stuff.

type Group

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

Group represents a usenet newsgroup.

type Handler

type Handler func(args []string, s *session, c *textproto.Conn) error

Handler is a low-level protocol handler

type NNTPError

type NNTPError struct {
	Code int
	Msg  string
}

An NNTPError is a coded NNTP error message.

func (*NNTPError) Error

func (e *NNTPError) Error() string

type NumberedArticle

type NumberedArticle struct {
	Num     int64
	Article *Article
}

A NumberedArticle provides local sequence nubers to articles When listing articles in a group.

type PostingStatus

type PostingStatus byte

PostingStatus type for groups.

func (PostingStatus) String

func (ps PostingStatus) String() string

type Server

type Server struct {
	// Handlers are dispatched by command name.
	Handlers map[string]Handler
	// The backend (your code) that provides data
	Backend Backend

	ThrotCmdInterval time.Duration
	ThrotCmdWindow   time.Duration
	// contains filtered or unexported fields
}

The Server handle.

func NewServer

func NewServer(backend Backend) *Server

NewServer builds a new server handle request to a backend.

func (*Server) Process

func (s *Server) Process(nc net.Conn)

Process an NNTP session.

Directories

Path Synopsis
common/dateparse
Package dateparse parses date-strings without knowing the format in advance, using a fast lex based approach to eliminate shotgun attempts.
Package dateparse parses date-strings without knowing the format in advance, using a fast lex based approach to eliminate shotgun attempts.

Jump to

Keyboard shortcuts

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