karma

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHateLimit = -4

DefaultHateLimit defines how many bad things client can do until transaction will be marked as bad

View Source
const DefaultInitialHate = 10

DefaultInitialHate shows how much we respect 1st Law of Moses by hating strangers

View Source
const DefaultKarmaLimit = -5

DefaultKarmaLimit is difference between good and bad connections to allow client to connect

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// InitialHate is negative karma given to new connections, if client issued commands properly, karma is improved
	InitialHate uint
	// HateLimit is how low karma can fall before we mark this transaction as bad
	HateLimit int

	// KarmaLimit is difference between number of good and bad connections. If KarmaLimit is -3, and client performed
	// 15 good connections and 17 bad connections, current karma will be 15-17=-2 and connection will be allowed
	KarmaLimit int

	// Storage defines interface for persistent (mainly) storage for Karma
	Storage Storage
}

Handler is struct exposing Checkers for karma

func (*Handler) CloseHandler

func (kh *Handler) CloseHandler(tr *msmtpd.Transaction) (err error)

CloseHandler saves Transaction Karma into Storage after connection is finished

func (*Handler) ConnectionChecker

func (kh *Handler) ConnectionChecker(tr *msmtpd.Transaction) (err error)

ConnectionChecker checks karma of remote IP address using data from Storage

type Storage

type Storage interface {
	// Ping ensures Storage works
	Ping(ctx context.Context) error
	// Close closes storage, it should be called before application exits
	Close() error
	// SaveGood saves transaction remote address history as good memory
	SaveGood(*msmtpd.Transaction) error
	// SaveBad saves transaction remote address history as bad memory
	SaveBad(*msmtpd.Transaction) error
	// Get gets karma score for transaction IP address
	Get(*msmtpd.Transaction) (int, error)
}

Storage is interface to abstract away saving\retrieving Result with remote IP address karma in it

Directories

Path Synopsis
storage

Jump to

Keyboard shortcuts

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