nntp

package
v3.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

nntp client/server

Index

Constants

View Source
const (
	// accepted article
	ARTICLE_ACCEPT = iota
	// reject article, don't send again
	ARTICLE_REJECT
	// defer article, send later
	ARTICLE_DEFER
	// reject + ban
	ARTICLE_BAN
)
View Source
const CMD_Capabilities = Command("CAPABILITIES")
View Source
const CMD_Newsgroups = Command("NEWSGROUPS 0 0 GMT")

command to list newsgroups

View Source
const CMD_XOver = Command("XOVER 0")
View Source
const LinePrefix_Mode = "MODE "

line prefix for mode

View Source
const Line_InvalidMode = RPL_SyntaxError + " Invalid Mode Selected"

line sent on invalid mode

View Source
const Line_PostingAllowed = RPL_PostingAllowed + " Posting Allowed"

line sent for posting allowed

View Source
const Line_PostingNotAllowed = RPL_PostingNotAllowed + " Posting Not Allowed"

line sent for posting not allowed

View Source
const Line_RPLQuit = RPL_Quit + " bai"

send this when we handle a QUIT command

View Source
const Line_StreamingAllowed = RPL_PostingStreaming + " aw yeh streamit brah"

line sent on successful streaming

View Source
const MODE_READER = Mode("reader")

reader mode

View Source
const MODE_STREAM = Mode("stream")

streaming mode

View Source
const MODE_UNSET = Mode("")

mode is not set

View Source
const ModeReader = ModeCommand("mode reader")

reader mode command

View Source
const ModeStream = ModeCommand("mode stream")

streaming mode command

View Source
const PolicyAccept = PolicyStatus(ARTICLE_ACCEPT)
View Source
const PolicyBan = PolicyStatus(ARTICLE_BAN)
View Source
const PolicyDefer = PolicyStatus(ARTICLE_DEFER)
View Source
const PolicyReject = PolicyStatus(ARTICLE_REJECT)
View Source
const RPL_Article = "220"

article follows

View Source
const RPL_ArticleBody = "222"

article body follows

View Source
const RPL_ArticleHeaders = "221"

article headers follows

View Source
const RPL_ArticleSelectedExists = "223"

selected article exists

View Source
const RPL_AuthAccepted = "281"

authentication creds have been accepted

View Source
const RPL_AuthInfoAccepted = "250"

AUTHINFO SIMPLE accepted

View Source
const RPL_AuthenticateRejected = "482"

authentication creds rejected

View Source
const RPL_AuthenticateRequired = "480"

command unavaibale until client has authenticated

View Source
const RPL_AuthorizeRejected = "452"

authorization rejected

View Source
const RPL_AuthorizeRequired = "450"

authorization required

View Source
const RPL_Binary = "288"

binary content follows

View Source
const RPL_Capabilities = "101"

capabilities info follows

View Source
const RPL_ContinueAuthorization = "350"

continue with authorization

View Source
const RPL_Date = "111"

server date time follows

View Source
const RPL_EncodingError = "504"

message encoding is bad

View Source
const RPL_EncryptionRequired = "483"

command unavailable until connection is encrypted

View Source
const RPL_FeatureNotSupported = "503"

feature is not supported

View Source
const RPL_GenericError = "403"

generic fault prevent action from being taken

View Source
const RPL_GenericFatal = "502"

fatal error happened and connection will close

View Source
const RPL_Group = "211"

reply for GROUP and LISTGROUP commands

View Source
const RPL_HeadersList = "225"

list of article heards follows

View Source
const RPL_Help = "100"

help info follows

View Source
const RPL_Index = "218"

index follows

View Source
const RPL_List = "215"

info list follows

View Source
const RPL_MoreAuth = "381"

more authentication info required

View Source
const RPL_NewArticles = "230"

list of new articles follows

View Source
const RPL_NewsgroupList = "231"

list of newsgroups followes

View Source
const RPL_NoArticleMsgID = "430"

no article with that message-id

View Source
const RPL_NoArticleNum = "420"

current article number is invalid

View Source
const RPL_NoArticleRange = "423"

no article in specified range

View Source
const RPL_NoGroupSelected = "412"

no newsgroup has been selected

View Source
const RPL_NoIndex = "418"

no tin style index available

View Source
const RPL_NoNextArticle = "421"

no next article in this group (NEXT)

View Source
const RPL_NoPrevArticle = "422"

no previous article in this group (LAST)

View Source
const RPL_NoSuchGroup = "411"

newsgroup does not exist

View Source
const RPL_NotAvaiable = "400"

server says servive is not avaiable on initial connection

View Source
const RPL_Overview = "224"

overview info follows

View Source
const RPL_PostAccepted = "340"

article was accepted via POST

View Source
const RPL_PostReceived = "240"

article was transfered by POST command successfully

View Source
const RPL_PostingAllowed = "200"

posting is allowed

View Source
const RPL_PostingFailed = "441"

posting failed (2nd stage of POST command)

View Source
const RPL_PostingNotAllowed = "201"

posting is not allowed

View Source
const RPL_PostingNotPermitted = "440"

posting not permitted (1st stage of POST command)

View Source
const RPL_PostingStreaming = "203"

streaming mode enabled

View Source
const RPL_Quit = "205"

reply to QUIT command, we will close the connection

View Source
const RPL_StreamingAccept = "238"

article is not found by CHECK and we want it

View Source
const RPL_StreamingDefer = "431"

defer article asked by CHECK comamnd

View Source
const RPL_StreamingFailed = "439"

article transfer via streaming failed (TAKETHIS)

View Source
const RPL_StreamingReject = "438"

reject article and don't ask again (CHECK command)

View Source
const RPL_StreamingTransfered = "239"

article was transfered via TAKETHIS successfully

View Source
const RPL_SyntaxError = "501"

got a command with invalid syntax

View Source
const RPL_TLSContinue = "382"

continue with tls handshake

View Source
const RPL_TLSRejected = "580"

starttls can not be done

View Source
const RPL_TransferAccepted = "335"

article is accepted via IHAVE

View Source
const RPL_TransferDefer = "436"

article was not sent defer sending (either stage of IHAVE)

View Source
const RPL_TransferNotWanted = "435"

article is not wanted (1st stage of IHAVE)

View Source
const RPL_TransferOkay = "235"

article was transfered okay by IHAVE command

View Source
const RPL_TransferReject = "437"

reject transfer do not retry (2nd stage IHAVE)

View Source
const RPL_UnknownCommand = "500"

got an unknown command

View Source
const RPL_WrongMode = "401"

server is in the wrong mode

Variables

View Source
var DefaultFeedPolicy = &FeedPolicy{
	Whitelist:            []string{"ctl", "overchan.test"},
	Blacklist:            []string{`!^overchan\.`},
	AllowAnonPosts:       true,
	AllowAnonAttachments: false,
	UntrustedRequiresPoW: true,
	AllowAttachments:     true,
}

default feed policy to be used if not configured explicitly

View Source
var ErrInvalidMode = errors.New("invalid mode set")

Functions

This section is empty.

Types

type ArticleAcceptor

type ArticleAcceptor interface {
	// check article given an article header
	CheckHeader(hdr message.Header) PolicyStatus
	// check article given a message id
	CheckMessageID(msgid MessageID) PolicyStatus
	// get max article size in bytes
	MaxArticleSize() int64
}

type defining a policy that determines if we want to accept/reject/defer an incoming article

type ArticleEntry

type ArticleEntry [2]string

(message-id, newsgroup) tuple

func (ArticleEntry) MessageID

func (e ArticleEntry) MessageID() MessageID

func (ArticleEntry) Newsgroup

func (e ArticleEntry) Newsgroup() Newsgroup

type ArticleFilter

type ArticleFilter interface {
	// filter the article header
	// returns the modified Header and an error if one occurs
	FilterHeader(hdr message.Header) (message.Header, error)

	// reads the article's body and write the filtered version to an io.Writer
	// returns the number of bytes written to the io.Writer, true if the body was
	// modifed (or false if body is unchanged) and an error if one occurs
	FilterAndWriteBody(body io.Reader, wr io.Writer) (int64, bool, error)
}

defines interface for filtering an nntp article filters can (and does) modify the article it operates on

type Command

type Command string

func CMD_Article

func CMD_Article(msgid MessageID) Command

func CMD_Group

func CMD_Group(g Newsgroup) Command

create group command for a newsgroup

func CMD_Head

func CMD_Head(msgid MessageID) Command

func (Command) String

func (c Command) String() string

type Conn

type Conn interface {

	// negotiate an nntp session on this connection
	// returns nil if we negitated successfully
	// returns ErrAuthRejected if the remote server rejected any authentication
	// we sent or another error if one occured while negotiating
	Negotiate(stream bool) error

	// obtain connection state
	GetState() *ConnState

	// retutrn true if posting is allowed
	// return false if posting is not allowed
	PostingAllowed() bool

	// handle inbound non-streaming connection
	// call event hooks on event
	ProcessInbound(hooks EventHooks)

	// does this connection want to do nntp streaming?
	WantsStreaming() bool

	// what mode are we in?
	// returns mode in all caps
	Mode() Mode

	// initiate nntp streaming
	// after calling this the caller MUST call StreamAndQuit()
	// returns a channel for message ids, true if caller sends on the channel or
	// returns nil and ErrStreamingNotAllowed if streaming is not allowed on this
	// connection or another error if one occurs while trying to start streaming
	StartStreaming() (chan ArticleEntry, error)

	// stream articles and quit when the channel obtained by StartStreaming() is
	// closed, after which this nntp connection is no longer open
	StreamAndQuit()

	// is this nntp connection open?
	IsOpen() bool

	// send quit command and close connection
	Quit()

	// download all articles in a newsgroup
	// returns error if a network error occurs
	DownloadGroup(g Newsgroup) error

	// get list of active newsgroups
	ListNewsgroups() ([]Newsgroup, error)
}

an nntp connection

type ConnState

type ConnState struct {
	// name of parent feed
	FeedName string `json:"feedname"`
	// name of the connection
	ConnName string `json:"connname"`
	// hostname of remote connection
	HostName string `json:"hostname"`
	// current nntp mode
	Mode Mode `json:"mode"`
	// current selected nntp newsgroup
	Group Newsgroup `json:"newsgroup"`
	// current selected nntp article
	Article string `json:"article"`
	// parent feed's policy
	Policy *FeedPolicy `json:"feedpolicy"`
	// is this connection open?
	Open bool `json:"open"`
}

state of an nntp connection

type Dialer

type Dialer interface {
	// dial out with a dialer
	// if cfg is not nil, try to establish a tls connection with STARTTLS
	// returns a new nntp connection and nil on successful handshake and login
	// returns nil and an error if an error happened
	Dial(d network.Dialer, cfg *tls.Config) (*Conn, error)
}

establishes an outbound nntp connection to a remote server

type EventHooks

type EventHooks interface {
	// called when we have obtained an article given its message-id
	GotArticle(msgid MessageID, group Newsgroup)
	// called when we have sent an article to a single remote feed
	SentArticleVia(msgid MessageID, feedname string)
}

callback hooks fired on certain events

type FeedPolicy

type FeedPolicy struct {
	// list of whitelist regexps for newsgorups
	Whitelist []string `json:"whitelist"`
	// list of blacklist regexps for newsgroups
	Blacklist []string `json:"blacklist"`
	// are anon posts of any kind allowed?
	AllowAnonPosts bool `json:"anon"`
	// are anon posts with attachments allowed?
	AllowAnonAttachments bool `json:"anon_attachments"`
	// are any attachments allowed?
	AllowAttachments bool `json:"attachments"`
	// do we require Proof Of Work for untrusted connections?
	UntrustedRequiresPoW bool `json:"pow"`
}

a policy that governs whether we federate an article via a feed

type FlatfileAuth

type FlatfileAuth string

func (FlatfileAuth) CheckLogin

func (fname FlatfileAuth) CheckLogin(username, passwd string) (found bool, err error)

type Hook

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

func NewHook

func NewHook(cfg *config.NNTPHookConfig) *Hook

func (*Hook) GotArticle

func (h *Hook) GotArticle(msgid MessageID, group Newsgroup)

func (*Hook) SentArticleVia

func (*Hook) SentArticleVia(msgid MessageID, feedname string)

type MessageID

type MessageID string

func GenMessageID

func GenMessageID(name string) MessageID

generate a new message id given name of server

func (MessageID) Blake2Hash

func (msgid MessageID) Blake2Hash() string

compute blake2 hash of message id

func (MessageID) LongHash

func (msgid MessageID) LongHash() string

compute long form hash of message id

func (MessageID) ShortHash

func (msgid MessageID) ShortHash() string

compute truncated form of message id hash

func (MessageID) String

func (msgid MessageID) String() string

get message id as string

func (MessageID) Valid

func (msgid MessageID) Valid() bool

return true if this message id is well formed, otherwise return false

type Mode

type Mode string

a mode set by an nntp client

func (Mode) Is

func (m Mode) Is(other Mode) bool

is this mode equal to another mode

func (Mode) String

func (m Mode) String() string

get as string

func (Mode) Valid

func (m Mode) Valid() bool

is this a valid mode of operation?

type ModeCommand

type ModeCommand string

a switch mode command

func (ModeCommand) Is

func (m ModeCommand) Is(cmd ModeCommand) bool

check if this mode command is equal to an existing one

func (ModeCommand) Mode

func (m ModeCommand) Mode() Mode

get the mode selected in this mode command

func (ModeCommand) String

func (m ModeCommand) String() string

get as string

func (ModeCommand) Valid

func (m ModeCommand) Valid() bool

is this mode command well formed? does not check the actual mode sent.

type MulitHook

type MulitHook []EventHooks

multiplexed event hook

func (MulitHook) GotArticle

func (m MulitHook) GotArticle(msgid MessageID, group Newsgroup)

func (MulitHook) SentArticleVia

func (m MulitHook) SentArticleVia(msgid MessageID, feedname string)

type Newsgroup

type Newsgroup string

an nntp newsgroup

func (Newsgroup) String

func (g Newsgroup) String() string

get newsgroup as string

func (Newsgroup) Valid

func (g Newsgroup) Valid() bool

return true if this newsgroup is well formed otherwise false

type PolicyStatus

type PolicyStatus int

func (PolicyStatus) Accept

func (s PolicyStatus) Accept() bool

is this an accept code?

func (PolicyStatus) Ban

func (s PolicyStatus) Ban() bool

is this a ban code

func (PolicyStatus) Defer

func (s PolicyStatus) Defer() bool

is this a defer code?

func (PolicyStatus) Reject

func (s PolicyStatus) Reject() bool

is this a reject code?

func (PolicyStatus) String

func (s PolicyStatus) String() string

type Server

type Server struct {
	// user callback
	Hooks EventHooks
	// filters to apply
	Filters []ArticleFilter
	// global article acceptor
	Acceptor ArticleAcceptor
	// article storage
	Storage store.Storage
	// nntp config
	Config *config.NNTPServerConfig
	// outfeeds to connect to
	Feeds []*config.FeedConfig
	// inbound authentiaction mechanism
	Auth ServerAuth
	// contains filtered or unexported fields
}

an nntp server

func NewServer

func NewServer() *Server

func (*Server) GotArticle

func (s *Server) GotArticle(msgid MessageID, group Newsgroup)

func (*Server) Name

func (s *Server) Name() string

func (*Server) PersistFeeds

func (s *Server) PersistFeeds()

persist all outbound feeds

func (*Server) ReloadFeeds

func (s *Server) ReloadFeeds(feeds []*config.FeedConfig)

reload feeds

func (*Server) ReloadServer

func (s *Server) ReloadServer(c *config.NNTPServerConfig)

reload server configuration

func (*Server) ReloadStorage

func (s *Server) ReloadStorage(c *config.StoreConfig)

reload storage configuration

func (*Server) SentArticleVia

func (s *Server) SentArticleVia(msgid MessageID, feedname string)

func (*Server) Serve

func (s *Server) Serve(l net.Listener) (err error)

serve connections from listener

type ServerAuth

type ServerAuth interface {
	// check plaintext login
	// returns nil on success otherwise error if one occurs during authentication
	// returns true if authentication was successful and an error if a network io error happens
	CheckLogin(username, passwd string) (bool, error)
}

defines server side authentication mechanism

type StreamEvent

type StreamEvent string

an nntp stream event these are pipelined between nntp servers

func (StreamEvent) Command

func (ev StreamEvent) Command() string

func (StreamEvent) MessageID

func (ev StreamEvent) MessageID() MessageID

func (StreamEvent) String

func (ev StreamEvent) String() string

func (StreamEvent) Valid

func (ev StreamEvent) Valid() bool

Directories

Path Synopsis
package for parsing, packing, signing, verifying nntp articles
package for parsing, packing, signing, verifying nntp articles

Jump to

Keyboard shortcuts

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