Documentation
¶
Index ¶
- type BinDao
- func (d *BinDao) Delete(bin *ds.Bin) (err error)
- func (d *BinDao) GenerateId() string
- func (d *BinDao) GetAll() (bins []ds.Bin, err error)
- func (d *BinDao) GetByBytes(limit int) (bins []ds.Bin, err error)
- func (d *BinDao) GetByCreated(limit int) (bins []ds.Bin, err error)
- func (d *BinDao) GetByDownloads(limit int) (bins []ds.Bin, err error)
- func (d *BinDao) GetByFiles(limit int) (bins []ds.Bin, err error)
- func (d *BinDao) GetByID(id string) (bin ds.Bin, found bool, err error)
- func (d *BinDao) GetLastUpdated(limit int) (bins []ds.Bin, err error)
- func (d *BinDao) GetPendingDelete() (bins []ds.Bin, err error)
- func (d *BinDao) Insert(bin *ds.Bin) (inserted bool, err error)
- func (d *BinDao) RegisterDownload(bin *ds.Bin) (err error)
- func (d *BinDao) RegisterUpdate(bin *ds.Bin) (err error)
- func (d *BinDao) Touch(bin *ds.Bin) (updated bool, err error)
- func (d *BinDao) Update(bin *ds.Bin) (err error)
- func (d *BinDao) ValidateInput(bin *ds.Bin) error
- type ClientDao
- func (c *ClientDao) Ban(IPsToBan []string, banByRemoteAddr string) (err error)
- func (c *ClientDao) Cleanup(days uint64) (count int64, err error)
- func (c *ClientDao) GetASNWithStats(limit int) (asns []ds.AutonomousSystem, err error)
- func (c *ClientDao) GetAll() (clients []ds.Client, err error)
- func (c *ClientDao) GetByBannedAt(limit int) (clients []ds.Client, err error)
- func (c *ClientDao) GetByBytesUploaded(limit int) (clients []ds.Client, err error)
- func (c *ClientDao) GetByCountry(limit int) (countries []ds.ClientByCountry, err error)
- func (c *ClientDao) GetByFilesUploaded(limit int) (clients []ds.Client, err error)
- func (c *ClientDao) GetByIP(ip net.IP) (client ds.Client, found bool, err error)
- func (c *ClientDao) GetByLastActiveAt(limit int) (clients []ds.Client, err error)
- func (c *ClientDao) GetByNetwork(limit int) (networks []ds.ClientByNetwork, err error)
- func (c *ClientDao) GetByRemoteAddr(remoteAddr string) (client ds.Client, found bool, err error)
- func (c *ClientDao) GetByRequests(limit int) (clients []ds.Client, err error)
- func (c *ClientDao) Update(client *ds.Client) (err error)
- type DAO
- func (dao DAO) Bin() *BinDao
- func (dao DAO) Client() *ClientDao
- func (dao DAO) Close() error
- func (dao DAO) CreateSchema() error
- func (dao DAO) File() *FileDao
- func (dao DAO) FileContent() *FileContentDao
- func (dao DAO) Metrics() *MetricsDao
- func (dao DAO) ResetDB() error
- func (dao *DAO) SetMetrics(m DBMetricsObserver)
- func (dao DAO) Stats() sql.DBStats
- func (dao DAO) Status() bool
- func (dao DAO) Transaction() *TransactionDao
- type DBConfig
- type DBMetricsObserver
- type FileContentDao
- func (d *FileContentDao) BlockContent(sha256 string) (retErr error)
- func (d *FileContentDao) ClaimForDeletion(sha256 string) (bool, error)
- func (d *FileContentDao) Delete(sha256 string) error
- func (d *FileContentDao) DeleteFileReferences(sha256 string) error
- func (d *FileContentDao) GetAll() ([]ds.FileContent, error)
- func (d *FileContentDao) GetBlocked(limit int) (contents []ds.FileByChecksum, err error)
- func (d *FileContentDao) GetByCreated(limit int) (contents []ds.FileByChecksum, err error)
- func (d *FileContentDao) GetBySHA256(sha256 string) (*ds.FileContent, error)
- func (d *FileContentDao) GetPendingDelete() ([]ds.FileContent, error)
- func (d *FileContentDao) InsertOrIncrement(content *ds.FileContent) error
- func (d *FileContentDao) SetInStorage(sha256 string, inStorage bool) error
- func (d *FileContentDao) UnblockContent(sha256 string) error
- func (d *FileContentDao) Update(content *ds.FileContent) error
- type FileDao
- func (d *FileDao) CountBySHA256(sha256 string) (int, error)
- func (d *FileDao) Delete(file *ds.File) (err error)
- func (d *FileDao) FileByChecksum(sha256 string) (files []ds.File, err error)
- func (d *FileDao) FilesByBytes(limit int) (files []ds.FileByChecksum, err error)
- func (d *FileDao) FilesByBytesTotal(limit int) (files []ds.FileByChecksum, err error)
- func (d *FileDao) FilesByChecksum(limit int) (files []ds.FileByChecksum, err error)
- func (d *FileDao) GetAll(available bool) (files []ds.File, err error)
- func (d *FileDao) GetByBin(id string, inStorage bool) (files []ds.File, err error)
- func (d *FileDao) GetByBinAll(id string) (files []ds.File, err error)
- func (d *FileDao) GetByBytes(limit int) (files []ds.File, err error)
- func (d *FileDao) GetByCreated(limit int) (files []ds.File, err error)
- func (d *FileDao) GetByID(id int) (file ds.File, found bool, err error)
- func (d *FileDao) GetByName(bin string, filename string) (file ds.File, found bool, err error)
- func (d *FileDao) GetByUpdated(limit int) (files []ds.File, err error)
- func (d *FileDao) GetByUpdates(limit int) (files []ds.File, err error)
- func (d *FileDao) GetDistinctMimeTypes(hours int) (mimeTypes []string, err error)
- func (d *FileDao) GetRecentUploads(mime string, hours int) (files []ds.File, err error)
- func (d *FileDao) GetTopDownloads(limit int) (files []ds.File, err error)
- func (d *FileDao) GetUploaderIPsByBin(id string) (ips []string, err error)
- func (d *FileDao) Insert(file *ds.File) (bool, error)
- func (d *FileDao) IsAvailableForDownload(fileId int) (bool, error)
- func (d *FileDao) RegisterDownload(file *ds.File) (err error)
- func (d *FileDao) Update(file *ds.File) (err error)
- func (d *FileDao) ValidateInput(file *ds.File) error
- type MetricsDao
- type PostgresStats
- type TransactionDao
- func (d *TransactionDao) Cleanup(retention uint64) (count int64, err error)
- func (d *TransactionDao) GetByBin(bin string) (transactions []ds.Transaction, err error)
- func (d *TransactionDao) GetByIP(ip string) (transactions []ds.Transaction, err error)
- func (d *TransactionDao) GetDownloaderIPsByBin(bin string) (ips []string, err error)
- func (d *TransactionDao) Insert(t *ds.Transaction) (err error)
- func (d *TransactionDao) Register(r *http.Request, bin string, filename string, timestamp time.Time, ...) (transaction *ds.Transaction, err error)
- func (d *TransactionDao) Update(t *ds.Transaction) (err error)
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) GenerateId ¶
func (*BinDao) GetByDownloads ¶
func (*BinDao) GetLastUpdated ¶
func (*BinDao) Touch ¶ added in v1.1.1
Touch refreshes the bin's updated_at and expired_at timestamps without touching the moderation fields (readonly, approved_at, deleted_at). It only affects bins that are still writable (not deleted and not readonly), so a slow, in-flight upload cannot resurrect or un-moderate a bin that an admin or the lurker changed concurrently while the upload was running. Returns false if no matching writable row was found (i.e. the bin was deleted or locked during the upload).
type ClientDao ¶
type ClientDao struct {
// contains filtered or unexported fields
}
func (*ClientDao) GetASNWithStats ¶
func (c *ClientDao) GetASNWithStats(limit int) (asns []ds.AutonomousSystem, err error)
func (*ClientDao) GetByBannedAt ¶
func (*ClientDao) GetByBytesUploaded ¶
func (*ClientDao) GetByCountry ¶
func (c *ClientDao) GetByCountry(limit int) (countries []ds.ClientByCountry, err error)
func (*ClientDao) GetByFilesUploaded ¶
func (*ClientDao) GetByLastActiveAt ¶
func (*ClientDao) GetByNetwork ¶
func (c *ClientDao) GetByNetwork(limit int) (networks []ds.ClientByNetwork, err error)
func (*ClientDao) GetByRemoteAddr ¶
func (*ClientDao) GetByRequests ¶
type DAO ¶
type DAO struct {
// contains filtered or unexported fields
}
func (DAO) CreateSchema ¶
func (DAO) FileContent ¶
func (dao DAO) FileContent() *FileContentDao
func (DAO) Metrics ¶
func (dao DAO) Metrics() *MetricsDao
func (*DAO) SetMetrics ¶ added in v0.0.3
func (dao *DAO) SetMetrics(m DBMetricsObserver)
SetMetrics sets the metrics observer for database operations.
func (DAO) Transaction ¶
func (dao DAO) Transaction() *TransactionDao
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) ClaimForDeletion ¶ added in v1.1.1
func (d *FileContentDao) ClaimForDeletion(sha256 string) (bool, error)
ClaimForDeletion atomically marks content as no longer in storage, but only if it still has zero active file references (active = file not deleted AND bin not deleted AND bin not expired). It returns true if the claim succeeded, meaning the caller now owns deleting the corresponding S3 object.
This must be called before the S3 object is removed: by committing in_storage=false first, a concurrent deduplicated upload that reads this row observes in_storage=false and re-uploads the content instead of incorrectly skipping the upload and leaving a dangling reference to a deleted object. The NOT EXISTS guard also makes the claim fail if an upload created an active reference in the meantime, so referenced content is never deleted.
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) SetInStorage ¶ added in v1.1.1
func (d *FileContentDao) SetInStorage(sha256 string, inStorage bool) error
SetInStorage updates only the in_storage flag for a content record. It is used to roll back a deletion claim if the subsequent S3 delete fails, so the object (which is still present in S3) is retried on a later run rather than being leaked as an orphan.
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 ¶
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) FileByChecksum ¶
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) GetByBinAll ¶ added in v1.0.1
func (*FileDao) GetByCreated ¶
func (*FileDao) GetByUpdated ¶
func (*FileDao) GetByUpdates ¶
func (*FileDao) GetDistinctMimeTypes ¶ added in v1.0.0
GetDistinctMimeTypes returns the set of unique MIME types seen across non-deleted files uploaded in the last N hours, sorted alphabetically.
func (*FileDao) GetRecentUploads ¶ added in v1.0.0
GetRecentUploads returns files uploaded in the last N hours. If mime is non-empty, only files matching that MIME type are returned.
func (*FileDao) GetTopDownloads ¶
func (*FileDao) GetUploaderIPsByBin ¶ added in v1.0.1
func (*FileDao) IsAvailableForDownload ¶
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 - The file content is not blocked
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) GetDownloaderIPsByBin ¶ added in v1.0.1
func (d *TransactionDao) GetDownloaderIPsByBin(bin string) (ips []string, err error)
func (*TransactionDao) Insert ¶
func (d *TransactionDao) Insert(t *ds.Transaction) (err error)
func (*TransactionDao) Update ¶
func (d *TransactionDao) Update(t *ds.Transaction) (err error)