dbl

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinDao

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

func (*BinDao) Delete

func (d *BinDao) Delete(bin *ds.Bin) (err error)

func (*BinDao) GenerateId

func (d *BinDao) GenerateId() string

func (*BinDao) GetAll

func (d *BinDao) GetAll() (bins []ds.Bin, err error)

func (*BinDao) GetByBytes

func (d *BinDao) GetByBytes(limit int) (bins []ds.Bin, err error)

func (*BinDao) GetByCreated

func (d *BinDao) GetByCreated(limit int) (bins []ds.Bin, err error)

func (*BinDao) GetByDownloads

func (d *BinDao) GetByDownloads(limit int) (bins []ds.Bin, err error)

func (*BinDao) GetByFiles

func (d *BinDao) GetByFiles(limit int) (bins []ds.Bin, err error)

func (*BinDao) GetByID

func (d *BinDao) GetByID(id string) (bin ds.Bin, found bool, err error)

func (*BinDao) GetLastUpdated

func (d *BinDao) GetLastUpdated(limit int) (bins []ds.Bin, err error)

func (*BinDao) GetPendingDelete

func (d *BinDao) GetPendingDelete() (bins []ds.Bin, err error)

func (*BinDao) Insert

func (d *BinDao) Insert(bin *ds.Bin) (err error)

func (*BinDao) RegisterDownload

func (d *BinDao) RegisterDownload(bin *ds.Bin) (err error)

func (*BinDao) RegisterUpdate

func (d *BinDao) RegisterUpdate(bin *ds.Bin) (err error)

func (*BinDao) Update

func (d *BinDao) Update(bin *ds.Bin) (err error)

func (*BinDao) Upsert

func (d *BinDao) Upsert(bin *ds.Bin) (err error)

func (*BinDao) ValidateInput

func (d *BinDao) ValidateInput(bin *ds.Bin) error

type ClientDao

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

func (*ClientDao) Ban

func (c *ClientDao) Ban(IPsToBan []string, banByRemoteAddr string) (err error)

func (*ClientDao) Cleanup

func (c *ClientDao) Cleanup(days uint64) (count int64, err error)

func (*ClientDao) GetASNWithStats

func (c *ClientDao) GetASNWithStats(limit int) (asns []ds.AutonomousSystem, err error)

func (*ClientDao) GetAll

func (c *ClientDao) GetAll() (clients []ds.Client, err error)

func (*ClientDao) GetByBannedAt

func (c *ClientDao) GetByBannedAt(limit int) (clients []ds.Client, err error)

func (*ClientDao) GetByBytesUploaded

func (c *ClientDao) GetByBytesUploaded(limit int) (clients []ds.Client, err error)

func (*ClientDao) GetByCountry

func (c *ClientDao) GetByCountry(limit int) (countries []ds.ClientByCountry, err error)

func (*ClientDao) GetByFilesUploaded

func (c *ClientDao) GetByFilesUploaded(limit int) (clients []ds.Client, err error)

func (*ClientDao) GetByIP

func (c *ClientDao) GetByIP(ip net.IP) (client ds.Client, found bool, err error)

func (*ClientDao) GetByLastActiveAt

func (c *ClientDao) GetByLastActiveAt(limit int) (clients []ds.Client, err error)

func (*ClientDao) GetByNetwork

func (c *ClientDao) GetByNetwork(limit int) (networks []ds.ClientByNetwork, err error)

func (*ClientDao) GetByRemoteAddr

func (c *ClientDao) GetByRemoteAddr(remoteAddr string) (client ds.Client, found bool, err error)

func (*ClientDao) GetByRequests

func (c *ClientDao) GetByRequests(limit int) (clients []ds.Client, err error)

func (*ClientDao) Update

func (c *ClientDao) Update(client *ds.Client) (err error)

type DAO

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

func Init

func Init(cfg DBConfig) (DAO, error)

func (DAO) Bin

func (dao DAO) Bin() *BinDao

func (DAO) Client

func (dao DAO) Client() *ClientDao

func (DAO) Close

func (dao DAO) Close() error

func (DAO) CreateSchema

func (dao DAO) CreateSchema() error

func (DAO) File

func (dao DAO) File() *FileDao

func (DAO) FileContent

func (dao DAO) FileContent() *FileContentDao

func (DAO) Metrics

func (dao DAO) Metrics() *MetricsDao

func (DAO) ResetDB

func (dao DAO) ResetDB() error

func (*DAO) SetMetrics added in v0.0.3

func (dao *DAO) SetMetrics(m DBMetricsObserver)

SetMetrics sets the metrics observer for database operations.

func (DAO) Stats

func (dao DAO) Stats() sql.DBStats

func (DAO) Status

func (dao DAO) Status() bool

func (DAO) Transaction

func (dao DAO) Transaction() *TransactionDao

type DBConfig added in v0.0.3

type DBConfig struct {
	Host            string
	Port            int
	Name            string
	Username        string
	Password        string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

type DBMetricsObserver added in v0.0.3

type DBMetricsObserver interface {
	ObserveDBQuery(operation string, duration time.Duration)
	IncrDBQueryError(operation string)
}

DBMetricsObserver allows DAO to report metrics without importing the ds package.

type FileContentDao

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

func (*FileContentDao) BlockContent

func (d *FileContentDao) BlockContent(sha256 string) (retErr error)

BlockContent marks content as blocked and soft-deletes all file references

func (*FileContentDao) Delete

func (d *FileContentDao) Delete(sha256 string) error

Delete removes a file content record from the database

func (*FileContentDao) DeleteFileReferences

func (d *FileContentDao) DeleteFileReferences(sha256 string) error

DeleteFileReferences soft-deletes all file references for a given SHA256 without blocking the content

func (*FileContentDao) GetAll

func (d *FileContentDao) GetAll() ([]ds.FileContent, error)

GetAll returns all file content records

func (*FileContentDao) GetBlocked

func (d *FileContentDao) GetBlocked(limit int) (contents []ds.FileByChecksum, err error)

func (*FileContentDao) GetByCreated

func (d *FileContentDao) GetByCreated(limit int) (contents []ds.FileByChecksum, err error)

func (*FileContentDao) GetBySHA256

func (d *FileContentDao) GetBySHA256(sha256 string) (*ds.FileContent, error)

GetBySHA256 retrieves a file content record by its SHA256 hash

func (*FileContentDao) GetPendingDelete

func (d *FileContentDao) GetPendingDelete() ([]ds.FileContent, error)

GetPendingDelete returns file content records that have zero active references (active = file exists AND file not deleted AND bin not deleted AND bin not expired) and still in storage

func (*FileContentDao) InsertOrIncrement

func (d *FileContentDao) InsertOrIncrement(content *ds.FileContent) error

InsertOrIncrement inserts a new file content record or updates last_referenced_at if it already exists

func (*FileContentDao) UnblockContent

func (d *FileContentDao) UnblockContent(sha256 string) error

UnblockContent unblocks content by setting blocked = false

func (*FileContentDao) Update

func (d *FileContentDao) Update(content *ds.FileContent) error

Update modifies an existing file content record

type FileDao

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

func (*FileDao) CountBySHA256

func (d *FileDao) CountBySHA256(sha256 string) (int, error)

CountBySHA256 returns the count of active file references with the given SHA256 (active = file not deleted AND bin not deleted AND bin not expired)

func (*FileDao) Delete

func (d *FileDao) Delete(file *ds.File) (err error)

func (*FileDao) FileByChecksum

func (d *FileDao) FileByChecksum(sha256 string) (files []ds.File, err error)

func (*FileDao) FilesByBytes

func (d *FileDao) FilesByBytes(limit int) (files []ds.FileByChecksum, err error)

func (*FileDao) FilesByBytesTotal

func (d *FileDao) FilesByBytesTotal(limit int) (files []ds.FileByChecksum, err error)

func (*FileDao) FilesByChecksum

func (d *FileDao) FilesByChecksum(limit int) (files []ds.FileByChecksum, err error)

func (*FileDao) GetAll

func (d *FileDao) GetAll(available bool) (files []ds.File, err error)

func (*FileDao) GetByBin

func (d *FileDao) GetByBin(id string, inStorage bool) (files []ds.File, err error)

func (*FileDao) GetByBytes

func (d *FileDao) GetByBytes(limit int) (files []ds.File, err error)

func (*FileDao) GetByCreated

func (d *FileDao) GetByCreated(limit int) (files []ds.File, err error)

func (*FileDao) GetByID

func (d *FileDao) GetByID(id int) (file ds.File, found bool, err error)

func (*FileDao) GetByName

func (d *FileDao) GetByName(bin string, filename string) (file ds.File, found bool, err error)

func (*FileDao) GetByUpdated

func (d *FileDao) GetByUpdated(limit int) (files []ds.File, err error)

func (*FileDao) GetByUpdates

func (d *FileDao) GetByUpdates(limit int) (files []ds.File, err error)

func (*FileDao) GetTopDownloads

func (d *FileDao) GetTopDownloads(limit int) (files []ds.File, err error)

func (*FileDao) Insert

func (d *FileDao) Insert(file *ds.File) (err error)

func (*FileDao) IsAvailableForDownload

func (d *FileDao) IsAvailableForDownload(fileId int) (bool, error)

IsAvailableForDownload checks if a file is available for download by verifying: - The file is not deleted - The bin is not deleted - The bin has not expired - The file content exists in storage

func (*FileDao) RegisterDownload

func (d *FileDao) RegisterDownload(file *ds.File) (err error)

func (*FileDao) Update

func (d *FileDao) Update(file *ds.File) (err error)

func (*FileDao) ValidateInput

func (d *FileDao) ValidateInput(file *ds.File) error

type MetricsDao

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

func (*MetricsDao) PostgresStats added in v0.0.3

func (d *MetricsDao) PostgresStats() (stats PostgresStats, retErr error)

func (*MetricsDao) StorageBytesAllocated

func (d *MetricsDao) StorageBytesAllocated() (totalBytes uint64)

func (*MetricsDao) UpdateMetrics

func (d *MetricsDao) UpdateMetrics(metrics *ds.Metrics) (retErr error)

type PostgresStats added in v0.0.3

type PostgresStats struct {
	Version                string    `json:"version"`
	ServerStartedAt        time.Time `json:"server_started_at"`
	ServerUptime           string    `json:"server_uptime"`
	DatabaseSize           uint64    `json:"database_size"`
	DatabaseSizeReadable   string    `json:"database_size_readable"`
	ActiveConnections      int       `json:"active_connections"`
	TxCommitted            int64     `json:"tx_committed"`
	TxRolledBack           int64     `json:"tx_rolled_back"`
	CacheHitRatio          float64   `json:"cache_hit_ratio"`
	CacheHitRatioReadable  string    `json:"cache_hit_ratio_readable"`
	TotalLiveTuples        int64     `json:"total_live_tuples"`
	TotalDeadTuples        int64     `json:"total_dead_tuples"`
	DeadTupleRatio         float64   `json:"dead_tuple_ratio"`
	DeadTupleRatioReadable string    `json:"dead_tuple_ratio_readable"`
	TransactionIDAge       int64     `json:"transaction_id_age"`
}

type TransactionDao

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

func (*TransactionDao) Cleanup

func (d *TransactionDao) Cleanup(retention uint64) (count int64, err error)

func (*TransactionDao) GetByBin

func (d *TransactionDao) GetByBin(bin string) (transactions []ds.Transaction, err error)

func (*TransactionDao) GetByIP

func (d *TransactionDao) GetByIP(ip string) (transactions []ds.Transaction, err error)

func (*TransactionDao) Insert

func (d *TransactionDao) Insert(t *ds.Transaction) (err error)

func (*TransactionDao) Register

func (d *TransactionDao) Register(r *http.Request, bin string, filename string, timestamp time.Time, completed time.Time, status int, size int64) (transaction *ds.Transaction, err error)

func (*TransactionDao) Update

func (d *TransactionDao) Update(t *ds.Transaction) (err error)

Jump to

Keyboard shortcuts

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