storage

package
v0.0.0-...-7e6ab84 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Storage methods, modeled after the venerable INN usenet server.

NOTE: All interfaces are WIP. Expect breaking changes.

Index

Constants

This section is empty.

Variables

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

Functions

func Bzero

func Bzero(bs []byte)

func RegisterHisLoader

func RegisterHisLoader(name string, ldr CfgHisLoader)

func RegisterOverviewLoader

func RegisterOverviewLoader(name string, ldr CfgOverviewLoader)

func RegisterRiLoader

func RegisterRiLoader(name string, ldr CfgRiLoader)

func RegisterStorageLoader

func RegisterStorageLoader(name string, ldr CfgStorageLoader)

Types

type Article_MD

type Article_MD struct {
	Arrival time.Time
	Expires 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"`
	RiMethod  string `inn:"$rimethod"`
	Spool     string `inn:"$pathspool"`
}

General-Config.

func (*CfgMaster) BaseInfo

func (cfg *CfgMaster) BaseInfo() *CfgBaseInfo

type CfgOverviewLoader

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

type CfgRiLoader

type CfgRiLoader func(cfg *CfgMaster) (RiMethod, 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)

	// Deletes an Overview line from the database.
	CancelOv(grp []byte, num int64) (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 a sequence of group/number-pairs associated to the article
	// This method may return <nil>!
	RiBegin(msgid []byte) RiWriter

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

	// Performs a reverse index lookup: message-id to all first group/number pairs.
	RiLookupAll(msgid []byte, rie *RiElement) (rel Cursor, 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.

func OpenRiMethod

func OpenRiMethod(cfg *CfgMaster) (RiMethod, error)

type RiWriter

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

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

	// Called at after all group/number-pair have been associated.
	RiCommit() (err error)
}

type SMFlags

type SMFlags uint
const (
	SM_Expensivestat SMFlags = 1 << iota
	SM_Selfexpire
)

type SMLevel

type SMLevel uint
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) Cancel

func (s *StorageManager) Cancel(t *TOKEN) (err error)

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

Directories

Path Synopsis
Stores overview data into a LevelDB database.
Stores overview data into a LevelDB database.
Stores reverse index data into a LevelDB database.
Stores reverse index data into a LevelDB database.
Implements a traditional storage method, where each article is stored in a separate file.
Implements a traditional storage method, where each article is stored in a separate file.
Implements a traditional newsgroup-listing solution.
Implements a traditional newsgroup-listing solution.

Jump to

Keyboard shortcuts

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