Package storage

import "github.com/byte-mug/fastnntp-backend2/storage"

Overview

Storage methods, modeled after the venerable INN usenet server.

NOTE: All interfaces are WIP. Expect breaking changes.

Index

Variables

var ENotInitialized = errors.New("SM not Initialized")

-

func Bzero

func Bzero(bs []byte)

-

func RegisterHisLoader

func RegisterHisLoader(name string, ldr CfgHisLoader)

-

func RegisterOverviewLoader

func RegisterOverviewLoader(name string, ldr CfgOverviewLoader)

-

func RegisterStorageLoader

func RegisterStorageLoader(name string, ldr CfgStorageLoader)

-

type Article_MD

type Article_MD struct {
	Arrival time.Time
}

-

type Article_R

type Article_R interface {
	Releaser
	io.WriterTo
}

-

type Article_W

type Article_W interface {
	Releaser
	io.Reader
	io.WriterTo
}

-

type CfgBaseInfo

type CfgBaseInfo struct {
	Spool string `inn:"$spool"`
}

-

type CfgHisLoader

type CfgHisLoader func(cfg *CfgMaster) (HisMethod, error)

-

type CfgMaster

type CfgMaster struct {
	OvMethod	string	`inn:"$ovmethod"`
	HisMethod	string	`inn:"$hismethod"`
	Spool		string	`inn:"$pathspool"`
}

General-Config.

func (*CfgMaster) BaseInfo

func (cfg *CfgMaster) BaseInfo() *CfgBaseInfo

-

type CfgOverviewLoader

type CfgOverviewLoader func(cfg *CfgMaster) (OverviewMethod, error)

-

type CfgStorage

type CfgStorage struct {
	Methods []*CfgStorageMethod `inn:"@method"`
}

Storage-Config.

type CfgStorageLoader

type CfgStorageLoader func(cfg *CfgStorageMethod, bi *CfgBaseInfo) (StorageMethod, error)

-

type CfgStorageMethod

type CfgStorageMethod struct {
	Method		string	`inn:"$method"`
	Class		int	`inn:"$class"`
	Newsgroups	string	`inn:"$newsgroup"`
	Size		int64	`inn:"$size"`
	MaxSize		int64	`inn:"$max-size" json:"max-size"`
	Options		string	`inn:"$options"`
	ExactMatch	bool	`inn:"$exactmatch"`
}

-

type Cursor

type Cursor interface {
	Releaser
	Next() bool
}

-

type GroupElement

type GroupElement struct {
	Group		[]byte
	Status		byte
	Description	[]byte
}

-

type GroupMethod

type GroupMethod interface {
	FetchGroups(status, descr bool, ge *GroupElement) (cur Cursor, err error)
}

-

type HisMethod

type HisMethod interface {
	HisWrite(msgid []byte, md *Article_MD, t *TOKEN) (err error)
	HisLookup(msgid []byte, t *TOKEN) (err error)
	HisCancel(msgid []byte) (err error)
}

Inspired by INN's HIS(history) database. Maps message-ids to storage tokens.

func OpenHisMethod

func OpenHisMethod(cfg *CfgMaster) (HisMethod, error)

-

type OverviewElement

type OverviewElement struct {
	Num					int64
	Subject, From, Date, MsgId, Refs	[]byte
	Lng, Lines				int64
}

-

func (*OverviewElement) Debug

func (ove *OverviewElement) Debug() string

-

type OverviewMethod

type OverviewMethod interface {
	FetchOne(grp []byte, num int64, tk *TOKEN, ove *OverviewElement) (rel Releaser, err error)
	FetchAll(grp []byte, num, lastnum int64, tk *TOKEN, ove *OverviewElement) (cur Cursor, err error)
	SeekOne(grp []byte, num int64, back bool, tk *TOKEN, ove *OverviewElement) (rel Releaser, err error)
	GroupStat(grp []byte) (num, low, high int64, err error)

	// Writes a new Overview line into the database.
	GroupWriteOv(grp []byte, autonum bool, md *Article_MD, tk *TOKEN, ove *OverviewElement) (err error)

	// Initializes a group in the overview-database.
	InitGroup(grp []byte) (err error)
}

-

func OpenOverviewMethod

func OpenOverviewMethod(cfg *CfgMaster) (OverviewMethod, error)

-

type Releaser

type Releaser interface {
	Release()
}

-

type RiElement

type RiElement struct {
	Group	[]byte
	Num	int64
}

-

type RiHistory

type RiHistory struct {
	// IF Group != nil THEN expire a group.
	Group	[]byte
	Num	int64

	// IF MessageID != nil THEN expire an article.
	MessageId	[]byte
}

-

type RiMethod

type RiMethod interface {
	// Called for the first group/number-pair associated to the article
	RiWrite(msgid []byte, md *Article_MD, rie *RiElement) (err error)

	// Called for the remaining group/number-pair associated to the article
	RiWriteMore(msgid []byte, md *Article_MD, rie *RiElement) (err error)

	// Performs a reverse index lookup: message-id to the first group/number pair.
	RiLookup(msgid []byte, rie *RiElement) (rel Releaser, err error)

	// Query Expired articles. SHOULD return message-ids after their group/number counterparts.
	RiQueryExpired(ow *time.Time, rih *RiHistory) (cur Cursor, err error)

	// Expires an article using the message-id.
	RiExpire(msgid []byte) (err error)
}

Reverse Index. Maps message-ids to group/number-pairs.

type SMFlags

type SMFlags uint

-

Constants

const (
	SM_Expensivestat	SMFlags	= 1 << iota
	SM_Selfexpire
)

-

type SMLevel

type SMLevel uint

-

Constants

const (
	SM_Stat	SMLevel	= iota
	SM_Head
	SM_All
)

-

type StorageManager

type StorageManager struct {
	Classes	[256]StorageMethod
	Methods	[256]*CfgStorageMethod

	/*
		Used by the Posting backend.
		Will hold *fastnntp.WildMat objects.
	*/
	Wildmat	[256]interface{}
}

-

func (*StorageManager) Open

func (s *StorageManager) Open(bi *CfgBaseInfo) (err error)

-

func (*StorageManager) Retrieve

func (s *StorageManager) Retrieve(t *TOKEN, sl SMLevel) (a Article_R, rs SMLevel, err error)

-

func (*StorageManager) SetMethods

func (s *StorageManager) SetMethods(cfg *CfgStorage)

-

type StorageMethod

type StorageMethod interface {
	io.Closer

	Store(md *Article_MD, a Article_W, t *TOKEN) (err error)
	Retrieve(t *TOKEN, s SMLevel) (a Article_R, rs SMLevel, err error)
	Cancel(t *TOKEN) (err error)
}

-

type TOKEN

type TOKEN [34]byte

-

func (*TOKEN) Bytes

func (t *TOKEN) Bytes() []byte

-

func (*TOKEN) Class

func (t *TOKEN) Class() byte

-

func (*TOKEN) Debug

func (t *TOKEN) Debug() string

-

Dependencies

Directories

PathSynopsis
hisldb/
ovldb/Stores overview data into a LevelDB database.
tradgroup/Implements a traditional newsgroup-listing solution.
timehash/Implements a traditional storage method, where each article is stored in a separate file.