database

package
v0.0.0-...-27b812d Latest Latest
Warning

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

Go to latest
Published: May 29, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

database driver

Index

Constants

View Source
const (
	ARTICLE_PREFIX               = APP_PREFIX + "Article::"
	ARTICLE_POST_PREFIX          = APP_PREFIX + "ArticlePost::"
	ARTICLE_KEY_PREFIX           = APP_PREFIX + "ArticleKey::"
	ARTICLE_NUMBERS_PREFIX       = APP_PREFIX + "ArticleNumbers::"
	HASH_MESSAGEID_PREFIX        = APP_PREFIX + "HashMessageID::"
	ATTACHMENT_PREFIX            = APP_PREFIX + "Attachment::"
	BANNED_GROUP_PREFIX          = APP_PREFIX + "BannedGroup::"
	BANNED_ARTICLE_PREFIX        = APP_PREFIX + "BannedArticle::"
	MOD_KEY_PREFIX               = APP_PREFIX + "ModKey::"
	NNTP_LOGIN_PREFIX            = APP_PREFIX + "Login::"
	ENCRYPTED_ADDRS_PREFIX       = APP_PREFIX + "EncryptedAddrs::"
	ADDRS_ENCRYPTED_ADDRS_PREFIX = APP_PREFIX + "AddrsEncryptedAddrs::"
	ENCRYPTED_IP_BAN_PREFIX      = APP_PREFIX + "EncIPBan::"
	IP_BAN_PREFIX                = APP_PREFIX + "IPBan::"
	IP_RANGE_BAN_PREFIX          = APP_PREFIX + "IPRangeBan::"
)
View Source
const (
	GROUP_POSTTIME_WKR                = APP_PREFIX + "GroupPostTimeWKR"
	GROUP_ARTICLE_POSTTIME_WKR_PREFIX = APP_PREFIX + "GroupArticlePostTimeWKR::"
	GROUP_THREAD_POSTTIME_WKR_PREFIX  = APP_PREFIX + "GroupThreadPostTimeWKR::"
	GROUP_THREAD_BUMPTIME_WKR_PREFIX  = APP_PREFIX + "GroupThreadBumpTimeWKR::"
	GROUP_MOD_KEY_REVERSE_KR_PREFIX   = APP_PREFIX + "GroupModKeysKR::"
	THREAD_POST_WKR                   = APP_PREFIX + "ThreadPostsWKR::"
	ARTICLE_WKR                       = APP_PREFIX + "ArticleWKR"
	THREAD_BUMPTIME_WKR               = APP_PREFIX + "ThreadBumpTimeWKR"
	HEADER_KR_PREFIX                  = APP_PREFIX + "HeaderKR::"
	MESSAGEID_HEADER_KR_PREFIX        = APP_PREFIX + "MessageIDHeaderKR::"
	ARTICLE_ATTACHMENT_KR_PREFIX      = APP_PREFIX + "ArticleAttachmentsKR::"
	ATTACHMENT_ARTICLE_KR_PREFIX      = APP_PREFIX + "AttachmentArticlesKR::"
	IP_RANGE_BAN_KR                   = APP_PREFIX + "IPRangeBanKR"
	IP_ARTICLE_KR_PREFIX              = APP_PREFIX + "AddrArticle::"
	IP_WKR                            = APP_PREFIX + "AddrWKR"
)
View Source
const APP_PREFIX = "NNTP::"
View Source
const MIN_REDIS_VERSION = "3.0"

Variables

This section is empty.

Functions

func RedisEnabled

func RedisEnabled() bool

Types

type DB

type DB interface {
	// finalize all transactions and close connection
	// after calling this db driver can no longer be used
	Close()
	// ensire database is well formed
	Ensure() error
	// do we have a newsgroup locally?
	HasNewsgroup(group string) (bool, error)
	// have we seen an article with message-id before?
	SeenArticle(message_id string) (bool, error)
	// do we have an article locally given message-id?
	HasArticle(message_id string) (bool, error)
	// register a newsgroup with database
	RegisterNewsgroup(group string) error
	// register an article
	RegisterArticle(a *model.Article) error
	// get all articles in a newsgroup
	// send entries down a channel
	// return error if one happens while fetching
	GetAllArticlesInGroup(group string, send chan model.ArticleEntry) error
	// count all the articles in a newsgroup
	CountAllArticlesInGroup(group string) (int64, error)
	// get all articles locally known
	GetAllArticles() ([]model.ArticleEntry, error)

	// check if a newsgroup is banned
	NewsgroupBanned(group string) (bool, error)

	// ban newsgroup
	BanNewsgroup(group string) error
	// unban newsgroup
	UnbanNewsgroup(group string) error

	// return true if this is root post has expired
	IsExpired(root_message_id string) (bool, error)

	// get an article's MessageID given the hash of the MessageID
	// return an article entry or nil when it doesn't exist + and error if it happened
	GetMessageIDByHash(hash string) (model.ArticleEntry, error)

	// get root message_id, newsgroup, pageno for a post regardless if it's rootpost or not
	GetInfoForMessage(msgid string) (string, string, int64, error)

	// what page is the thread with this root post on?
	// return newsgroup, pageno
	GetPageForRootMessage(root_message_id string) (string, int64, error)

	// record that a message given a message id was posted signed by this pubkey
	RegisterSigned(message_id, pubkey string) error

	// get the number of articles we have in all groups
	ArticleCount() (int64, error)

	// return true if a thread with given root post with message-id has any replies
	ThreadHasReplies(root_message_id string) (bool, error)

	// get the number of posts in a certain newsgroup since N seconds ago
	// if N <= 0 then count all we have now
	CountPostsInGroup(group string, time_frame int64) (int64, error)

	// get all replies' message-id to a thread
	// if last > 0 then get that many of the last replies
	// start at reply number start
	GetThreadReplies(root_message_id string, start, last int) ([]string, error)

	// get a thread model given root post's message id
	GetThread(root_message_id string) (model.Thread, error)

	// count the number of replies to this thread
	CountThreadReplies(root_message_id string) (int64, error)

	// get all attachments for a message given its message-id
	GetPostAttachments(message_id string) ([]*model.Attachment, error)

	// return true if this newsgroup has posts
	GroupHasPosts(newsgroup string) (bool, error)

	// get all active threads on a board
	// send each thread's ArticleEntry down a channel
	// return error if one happens while fetching
	GetGroupThreads(newsgroup string, send chan model.ArticleEntry) error

	// get every message id for root posts that need to be expired in a newsgroup
	// threadcount is the upperbound limit to how many root posts we keep
	GetRootPostsForExpiration(newsgroup string, threadcount int) ([]string, error)

	// get the number of pages a board has
	GetGroupPageCount(newsgroup string) (int64, error)

	// get board page number N
	// fully loads all models
	GetGroupForPage(newsgroup string, pageno, perpage int) (*model.BoardPage, error)

	// get the threads for ukko page
	GetUkkoThreads(threadcount int) ([]*model.Thread, error)

	// get a post model for a single post
	GetPost(messageID string) (*model.Post, error)

	// add a public key to the database
	AddModPubkey(pubkey string) error

	// mark that a mod with this pubkey can act on all boards
	MarkModPubkeyGlobal(pubkey string) error

	// revoke mod with this pubkey the privilege of being able to act on all boards
	UnMarkModPubkeyGlobal(pubkey string) error

	// check if this mod pubkey can moderate at a global level
	CheckModPubkeyGlobal(pubkey string) bool

	// check if a mod with this pubkey has permission to moderate at all
	CheckModPubkey(pubkey string) (bool, error)

	// check if a mod with this pubkey can moderate on the given newsgroup
	CheckModPubkeyCanModGroup(pubkey, newsgroup string) (bool, error)

	// add a pubkey to be able to mod a newsgroup
	MarkModPubkeyCanModGroup(pubkey, newsgroup string) error

	// remote a pubkey to they can't mod a newsgroup
	UnMarkModPubkeyCanModGroup(pubkey, newsgroup string) error

	// ban an article
	BanArticle(messageID, reason string) error

	// check if an article is banned or not
	ArticleBanned(messageID string) (bool, error)

	// Get ip address given the encrypted version
	// return emtpy string if we don't have it
	GetIPAddress(encAddr string) (string, error)

	// check if an ip is banned from our local
	CheckIPBanned(addr string) (bool, error)

	// check if an encrypted ip is banned from our local
	CheckEncIPBanned(encAddr string) (bool, error)

	// ban an ip address from the local
	BanAddr(addr string) error

	// unban an ip address from the local
	UnbanAddr(addr string) error

	// ban an encrypted ip address from the remote
	BanEncAddr(encAddr string) error

	// return the encrypted version of an IPAddress
	// if it's not already there insert it into the database
	GetEncAddress(addr string) (string, error)

	// get the decryption key for an encrypted address
	// return empty string if we don't have it
	GetEncKey(encAddr string) (string, error)

	// delete an article from the database
	// if the article is a root post then all replies are also deleted
	DeleteArticle(msg_id string) error

	// forget that we tracked an article given the messgae-id
	ForgetArticle(msg_id string) error

	// get threads per page for a newsgroup
	GetThreadsPerPage(group string) (int, error)

	// get pages per board for a newsgroup
	GetPagesPerBoard(group string) (int, error)

	// get every newsgroup we current carry
	GetAllNewsgroups() ([]string, error)

	// get the numerical id of the last , first article for a given group
	GetLastAndFirstForGroup(group string) (int64, int64, error)

	// get a message id give a newsgroup and the nntp id
	GetMessageIDForNNTPID(group string, id int64) (string, error)

	// get nntp id for a given message-id
	GetNNTPIDForMessageID(group, msgid string) (int64, error)

	// get the last N days post count in decending order
	GetLastDaysPosts(n int64) ([]model.PostEntry, error)

	// get the last N days post count in decending order
	GetLastDaysPostsForGroup(newsgroup string, n int64) ([]model.PostEntry, error)

	// get post history per month since beginning of time
	GetMonthlyPostHistory() ([]model.PostEntry, error)

	// check if an nntp login cred is correct
	CheckNNTPLogin(username, passwd string) (bool, error)

	// add an nntp login credential
	AddNNTPLogin(username, passwd string) error

	// remove an nntp login credential
	RemoveNNTPLogin(username string) error

	// check if an nntp login credential given a user exists
	CheckNNTPUserExists(username string) (bool, error)

	// get the message ids of an article that has this header with the given value
	GetMessageIDByHeader(name, value string) ([]string, error)

	// get the header for a message given its message-id
	GetHeadersForMessage(msgid string) (model.ArticleHeader, error)

	// get all message-ids posted by posters in this cidr
	GetMessageIDByCIDR(cidr *net.IPNet) ([]string, error)

	// get all message-ids posted by poster with encrypted ip
	GetMessageIDByEncryptedIP(encaddr string) ([]string, error)
}

generic database driver

func New

func New(db_type, schema, host, port, user, password string) (DB, error)

func NewRedisDatabase

func NewRedisDatabase(host, port, password string) DB

type RedisDB

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

func (RedisDB) AddModPubkey

func (self RedisDB) AddModPubkey(pubkey string) error

func (RedisDB) AddNNTPLogin

func (self RedisDB) AddNNTPLogin(username, passwd string) (err error)

func (RedisDB) ArticleBanned

func (self RedisDB) ArticleBanned(messageID string) (result bool, err error)

func (RedisDB) ArticleCount

func (self RedisDB) ArticleCount() (count int64, err error)

count articles we have

func (RedisDB) BanAddr

func (self RedisDB) BanAddr(addr string) (err error)

func (RedisDB) BanArticle

func (self RedisDB) BanArticle(messageID, reason string) error

func (RedisDB) BanEncAddr

func (self RedisDB) BanEncAddr(encaddr string) (err error)

func (RedisDB) BanNewsgroup

func (self RedisDB) BanNewsgroup(group string) (err error)

func (RedisDB) CheckEncIPBanned

func (self RedisDB) CheckEncIPBanned(encaddr string) (banned bool, err error)

func (RedisDB) CheckIPBanned

func (self RedisDB) CheckIPBanned(addr string) (banned bool, err error)

func (RedisDB) CheckModPubkey

func (self RedisDB) CheckModPubkey(pubkey string) (bool, error)

func (RedisDB) CheckModPubkeyCanModGroup

func (self RedisDB) CheckModPubkeyCanModGroup(pubkey, newsgroup string) (bool, error)

func (RedisDB) CheckModPubkeyGlobal

func (self RedisDB) CheckModPubkeyGlobal(pubkey string) bool

func (RedisDB) CheckNNTPLogin

func (self RedisDB) CheckNNTPLogin(username, passwd string) (valid bool, err error)

func (RedisDB) CheckNNTPUserExists

func (self RedisDB) CheckNNTPUserExists(username string) (exists bool, err error)

func (RedisDB) Close

func (self RedisDB) Close()

finalize all transactions close database connections

func (RedisDB) CountAllArticlesInGroup

func (self RedisDB) CountAllArticlesInGroup(group string) (count int64, err error)

func (RedisDB) CountPostsInGroup

func (self RedisDB) CountPostsInGroup(newsgroup string, time_frame int64) (result int64, err error)

func (RedisDB) CountThreadReplies

func (self RedisDB) CountThreadReplies(root_message_id string) (repls int64, err error)

func (RedisDB) DeleteArticle

func (self RedisDB) DeleteArticle(msgid string) error

func (RedisDB) DeleteThread

func (self RedisDB) DeleteThread(msgid string) error

func (RedisDB) Ensure

func (self RedisDB) Ensure() error

func (RedisDB) ForgetArticle

func (self RedisDB) ForgetArticle(msgid string) (err error)

func (RedisDB) GetAllArticles

func (self RedisDB) GetAllArticles() (articles []model.ArticleEntry, err error)

get all articles

func (RedisDB) GetAllArticlesInGroup

func (self RedisDB) GetAllArticlesInGroup(group string, recv chan model.ArticleEntry) error

get all articles in a newsgroup send result down a channel

func (RedisDB) GetAllNewsgroups

func (self RedisDB) GetAllNewsgroups() (groups []string, err error)

func (RedisDB) GetEncAddress

func (self RedisDB) GetEncAddress(addr string) (encaddr string, err error)

func (RedisDB) GetEncKey

func (self RedisDB) GetEncKey(encAddr string) (enckey string, err error)

func (RedisDB) GetGroupForMessage

func (self RedisDB) GetGroupForMessage(message_id string) (group string, err error)

func (RedisDB) GetGroupForPage

func (self RedisDB) GetGroupForPage(newsgroup string, pageno, perpage int) (*model.BoardPage, error)

only fetches root posts does not update the thread contents

func (RedisDB) GetGroupPageCount

func (self RedisDB) GetGroupPageCount(newsgroup string) (int64, error)

func (RedisDB) GetGroupThreads

func (self RedisDB) GetGroupThreads(group string, recv chan model.ArticleEntry) error

func (RedisDB) GetHeadersForMessage

func (self RedisDB) GetHeadersForMessage(msgid string) (hdr model.ArticleHeader, err error)

func (RedisDB) GetIPAddress

func (self RedisDB) GetIPAddress(encaddr string) (addr string, err error)

func (RedisDB) GetInfoForMessage

func (self RedisDB) GetInfoForMessage(msgid string) (root string, newsgroup string, page int64, err error)

func (RedisDB) GetLastAndFirstForGroup

func (self RedisDB) GetLastAndFirstForGroup(group string) (last, first int64, err error)

func (RedisDB) GetLastDaysPosts

func (self RedisDB) GetLastDaysPosts(n int64) (posts []model.PostEntry, err error)

func (RedisDB) GetLastDaysPostsForGroup

func (self RedisDB) GetLastDaysPostsForGroup(newsgroup string, n int64) (posts []model.PostEntry, err error)

func (RedisDB) GetMessageIDByCIDR

func (self RedisDB) GetMessageIDByCIDR(cidr *net.IPNet) (msgids []string, err error)

func (RedisDB) GetMessageIDByEncryptedIP

func (self RedisDB) GetMessageIDByEncryptedIP(encip string) (msgids []string, err error)

func (RedisDB) GetMessageIDByHash

func (self RedisDB) GetMessageIDByHash(hash string) (article model.ArticleEntry, err error)

func (RedisDB) GetMessageIDByHeader

func (self RedisDB) GetMessageIDByHeader(name, val string) (msgids []string, err error)

get message ids of articles with this header name and value

func (RedisDB) GetMessageIDForNNTPID

func (self RedisDB) GetMessageIDForNNTPID(group string, id int64) (msgid string, err error)

func (RedisDB) GetMonthlyPostHistory

func (self RedisDB) GetMonthlyPostHistory() (posts []model.PostEntry, err error)

func (RedisDB) GetNNTPIDForMessageID

func (self RedisDB) GetNNTPIDForMessageID(group, msgid string) (id int64, err error)

func (RedisDB) GetPageForRootMessage

func (self RedisDB) GetPageForRootMessage(root_message_id string) (group string, page int64, err error)

func (RedisDB) GetPagesPerBoard

func (self RedisDB) GetPagesPerBoard(group string) (int, error)

func (RedisDB) GetPost

func (self RedisDB) GetPost(messageID string) (*model.Post, error)

func (RedisDB) GetPostAttachments

func (self RedisDB) GetPostAttachments(messageID string) ([]*model.Attachment, error)

func (RedisDB) GetRootPostsForExpiration

func (self RedisDB) GetRootPostsForExpiration(newsgroup string, threadcount int) (roots []string, err error)

func (RedisDB) GetThread

func (self RedisDB) GetThread(rootpost string) (model.Thread, error)

func (RedisDB) GetThreadReplies

func (self RedisDB) GetThreadReplies(rootpost string, start, limit int) (repls []string, err error)

func (RedisDB) GetThreadsPerPage

func (self RedisDB) GetThreadsPerPage(group string) (int, error)

func (RedisDB) GetUkkoThreads

func (self RedisDB) GetUkkoThreads(max int) ([]*model.Thread, error)

func (RedisDB) GroupHasPosts

func (self RedisDB) GroupHasPosts(group string) (bool, error)

func (RedisDB) HasArticle

func (self RedisDB) HasArticle(message_id string) (bool, error)

check if an article exists locally

func (RedisDB) HasNewsgroup

func (self RedisDB) HasNewsgroup(group string) (bool, error)

check if a newsgroup exists

func (RedisDB) IsExpired

func (self RedisDB) IsExpired(root_message_id string) (bool, error)

func (RedisDB) MarkModPubkeyCanModGroup

func (self RedisDB) MarkModPubkeyCanModGroup(pubkey, group string) (err error)

func (RedisDB) MarkModPubkeyGlobal

func (self RedisDB) MarkModPubkeyGlobal(pubkey string) (err error)

func (RedisDB) NewsgroupBanned

func (self RedisDB) NewsgroupBanned(group string) (banned bool, err error)

func (RedisDB) RegisterArticle

func (self RedisDB) RegisterArticle(message *model.Article) (err error)

register a message with the database

func (RedisDB) RegisterNewsgroup

func (self RedisDB) RegisterNewsgroup(group string) error

register a new newsgroup

func (RedisDB) RegisterSigned

func (self RedisDB) RegisterSigned(message_id, pubkey string) (err error)

func (RedisDB) RemoveNNTPLogin

func (self RedisDB) RemoveNNTPLogin(username string) (err error)

func (RedisDB) SeenArticle

func (self RedisDB) SeenArticle(message_id string) (bool, error)

check if an article exists

func (RedisDB) ThreadHasReplies

func (self RedisDB) ThreadHasReplies(rootpost string) (bool, error)

func (RedisDB) UnMarkModPubkeyCanModGroup

func (self RedisDB) UnMarkModPubkeyCanModGroup(pubkey, group string) (err error)

func (RedisDB) UnMarkModPubkeyGlobal

func (self RedisDB) UnMarkModPubkeyGlobal(pubkey string) (err error)

func (RedisDB) UnbanAddr

func (self RedisDB) UnbanAddr(addr string) (err error)

func (RedisDB) UnbanNewsgroup

func (self RedisDB) UnbanNewsgroup(group string) (err error)

Jump to

Keyboard shortcuts

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