services

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RobotsTxtPublicRooms is matrix federation public rooms endpoint
	RobotsTxtPublicRooms = "/_matrix/federation/v1/publicRooms"
	// RobotsTxtPublicRoom is made up endpoint of a specific matrix room, as there is no better option
	RobotsTxtPublicRoom = "/_matrix/federation/v1/publicRooms/%s"
)
View Source
const (
	// MaxCacheAge to be used on immutable resources
	MaxCacheAge = "31536000"
)

Variables

View Source
var SearchFieldsBoost = map[string]float64{
	"language": 100,
	"name":     10,
	"server":   10,
	"alias":    5,
}

SearchFieldsBoost field name => boost

Functions

This section is empty.

Types

type Blocklist

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

Blocklist service

func NewBlocklist

func NewBlocklist(cfg ConfigService) *Blocklist

NewBlocklist creates new blocklist service

func (*Blocklist) Add

func (b *Blocklist) Add(server string)

Add server to blocklist

func (*Blocklist) ByID

func (b *Blocklist) ByID(matrixID string) bool

ByID checks if server of matrixID is present in the blocklist

func (*Blocklist) ByServer

func (b *Blocklist) ByServer(server string) bool

ByServer checks if server is present in the blocklist

func (*Blocklist) Len

func (b *Blocklist) Len() int

Len of the blocklist

func (*Blocklist) Reset

func (b *Blocklist) Reset()

Reset dynamic part of the blocklist

func (*Blocklist) Slice

func (b *Blocklist) Slice() []string

Slice returns slice of the static+dynamic blocklist

type BlocklistService

type BlocklistService interface {
	Add(server string)
	ByID(matrixID string) bool
	ByServer(server string) bool
	Slice() []string
	Reset()
}

type Cache

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

Cache service

func NewCache

func NewCache(cfg ConfigService, stats cacheStats) *Cache

NewCache service

func (*Cache) IsBunny

func (cache *Cache) IsBunny(ip string) bool

IsBunny returns true if the IP is a BunnyCDN IP

func (*Cache) Middleware

func (cache *Cache) Middleware() echo.MiddlewareFunc

Middleware returns cache middleware

func (*Cache) MiddlewareImmutable

func (cache *Cache) MiddlewareImmutable() echo.MiddlewareFunc

MiddlewareImmutable returns echo middleware with immutable in cache-control

func (*Cache) MiddlewareSearch

func (cache *Cache) MiddlewareSearch() echo.MiddlewareFunc

MiddlewareSearch returns cache middleware for search endpoints

func (*Cache) Purge

func (cache *Cache) Purge(ctx context.Context)

Purge cache. At this moment works with BunnyCDN only

type Config

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

Config service

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig creates new config service and loads the config

func (*Config) Get

func (c *Config) Get() *model.Config

Get config

func (*Config) Read

func (c *Config) Read(ctx context.Context)

Read config

func (*Config) Write

func (c *Config) Write(cfg *model.Config) error

Write config

type ConfigService

type ConfigService interface {
	Get() *model.Config
}

type Crawler

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

func NewCrawler

func NewCrawler(cfg ConfigService, fedSvc FederationService, v ValidatorService, block BlocklistService, data DataRepository, detector lingua.LanguageDetector) *Crawler

NewCrawler service

func (*Crawler) AddServer

func (m *Crawler) AddServer(ctx context.Context, name string) int

AddServer by name, intended for HTTP API returns http status code to send to the reporter

func (*Crawler) AddServers

func (m *Crawler) AddServers(ctx context.Context, names []string, workers int)

AddServers by name in bulk, intended for HTTP API

func (*Crawler) DiscoverServers

func (m *Crawler) DiscoverServers(ctx context.Context, workers int, overrideList ...*utils.List[string, string])

DiscoverServers across federation and remove invalid ones

func (*Crawler) EachRoom

func (m *Crawler) EachRoom(ctx context.Context, handler func(roomID string, data *model.MatrixRoom) bool)

EachRoom allows to work with each known room

func (*Crawler) GetServersRoomsCount

func (m *Crawler) GetServersRoomsCount(ctx context.Context) map[string]int

func (*Crawler) IndexableServers

func (m *Crawler) IndexableServers(ctx context.Context) []string

IndexableServers returns all known indexable servers

func (*Crawler) OnlineServers

func (m *Crawler) OnlineServers(ctx context.Context) []string

OnlineServers returns all known online servers

func (*Crawler) ParseRooms

func (m *Crawler) ParseRooms(ctx context.Context, workers int)

ParseRooms across all discovered servers

type DataFacade

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

DataFacade wraps all data-related services to provide reusable API across all components of the system

func NewDataFacade

func NewDataFacade(
	crawler dataCrawlerService,
	index dataIndexService,
	stats dataStatsService,
	cache dataCacheService,
) *DataFacade

NewDataFacade creates new data facade service

func (*DataFacade) AddServer

func (df *DataFacade) AddServer(ctx context.Context, name string) int

AddServer by name, intended for HTTP API returns http status code to send to the reporter

func (*DataFacade) AddServers

func (df *DataFacade) AddServers(ctx context.Context, names []string, workers int)

AddServers by name in bulk, intended for HTTP API

func (*DataFacade) DiscoverServers

func (df *DataFacade) DiscoverServers(ctx context.Context, workers int)

DiscoverServers matrix servers

func (*DataFacade) Full

func (df *DataFacade) Full(ctx context.Context, discoveryWorkers, parsingWorkers int)

Full data pipeline (discovery, parsing, indexing)

func (*DataFacade) GetServersRoomsCount

func (df *DataFacade) GetServersRoomsCount(ctx context.Context) map[string]int

func (*DataFacade) Ingest

func (df *DataFacade) Ingest(ctx context.Context)

Ingest data into search index

func (*DataFacade) ParseRooms

func (df *DataFacade) ParseRooms(ctx context.Context, workers int)

ParseRooms from discovered servers

type DataRepository

type DataRepository interface {
	AddServer(context.Context, *model.MatrixServer) error
	HasServer(context.Context, string) bool
	GetServerInfo(context.Context, string) (*model.MatrixServer, error)
	FilterServers(context.Context, func(server *model.MatrixServer) bool) map[string]*model.MatrixServer
	BatchServers(context.Context, []string) error
	MarkServersOffline(context.Context, []string)
	RemoveServer(context.Context, string) error
	RemoveServers(context.Context, []string)
	AddRoomBatch(context.Context, *model.MatrixRoom)
	FlushRoomBatch(context.Context)
	GetRoom(context.Context, string) (*model.MatrixRoom, error)
	EachRoom(context.Context, func(string, *model.MatrixRoom) bool)
	SetBiggestRooms(context.Context, []string) error
	SetServersRoomsCount(ctx context.Context, data map[string]int) error
	SaveServersRooms(ctx context.Context, data map[string][]string) error
	GetServersRoomsCount(ctx context.Context) map[string]int
	GetBannedRooms(context.Context, ...string) ([]string, error)
	RemoveRooms(context.Context, []string)
	BanRoom(context.Context, string) error
	UnbanRoom(context.Context, string) error
	GetReportedRooms(context.Context, ...string) (map[string]string, error)
	ReportRoom(context.Context, string, string) error
	UnreportRoom(context.Context, string) error
	IsReported(context.Context, string) bool
}

type Email

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

Email service

func NewEmail

func NewEmail(cfg ConfigService) *Email

NewEmail creates new email service

func (*Email) SendModReport

func (e *Email) SendModReport(message, email string) error

SendModReport sends report email to MRS instance's moderators

func (*Email) SendReport

func (e *Email) SendReport(ctx context.Context, room *model.MatrixRoom, server *model.MatrixServer, reason string, emails []string) error

SendReport sends report email

type EmailService

type EmailService interface {
	SendReport(ctx context.Context, room *model.MatrixRoom, server *model.MatrixServer, reason string, emails []string) error
	SendModReport(text, email string) error
}

type FederationService

type FederationService interface {
	QueryPublicRooms(ctx context.Context, serverName, limit, since string) (*model.RoomDirectoryResponse, error)
	QueryServerName(ctx context.Context, serverName string) (string, error)
	QueryVersion(ctx context.Context, serverName string) (string, string, error)
	QueryCSURL(ctx context.Context, serverName string) string
}

type Index

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

func NewIndex

func NewIndex(cfg ConfigService, index IndexRepository) *Index

NewIndex creates new index service

func (*Index) EmptyIndex

func (i *Index) EmptyIndex(ctx context.Context) error

EmptyIndex creates new empty index

func (*Index) IndexBatch

func (i *Index) IndexBatch(ctx context.Context) error

IndexBatch performs indexing of the current batch

func (*Index) RoomsBatch

func (i *Index) RoomsBatch(ctx context.Context, roomID string, data *model.Entry) error

RoomsBatch indexes rooms in batches

type IndexRepository

type IndexRepository interface {
	Index(roomID string, data *model.Entry) error
	Delete(roomID string) error
	Swap(ctx context.Context) error
	IndexBatch(*bleve.Batch) error
	NewBatch() *bleve.Batch
}

type Lenable

type Lenable interface {
	Len() int
}

type Moderation

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

Moderation service

func NewModeration

func NewModeration(cfg ConfigService, data DataRepository, index IndexRepository, mail EmailService) *Moderation

NewModeration service

func (*Moderation) Ban

func (m *Moderation) Ban(ctx context.Context, roomID string) error

Ban a room

func (*Moderation) List

func (m *Moderation) List(ctx context.Context, serverName ...string) ([]string, error)

List returns full list of the banned rooms (optionally from specific server)

func (*Moderation) Report

func (m *Moderation) Report(ctx context.Context, roomID, reason string) error

Report a room

func (*Moderation) Unban

func (m *Moderation) Unban(ctx context.Context, roomID string) error

Unban a room

type Plausible

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

Plausible - plausible analytics service

func NewPlausible

func NewPlausible(cfg ConfigService) *Plausible

func (*Plausible) Enabled

func (p *Plausible) Enabled() bool

func (*Plausible) TrackSearch

func (p *Plausible) TrackSearch(ctx context.Context, incomingReq *http.Request, ip, query string)

TrackSearch - track search event

type Robots

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

Robots - robots.txt parsing Deprecated: This service is deprecated and will be removed in future versions

func NewRobots

func NewRobots() *Robots

NewRobots creates robots.txt parsing service

func (*Robots) Allowed

func (r *Robots) Allowed(ctx context.Context, serverName, endpoint string) bool

Allowed checks if endpoint is allowed by robots.txt of the serverName Deprecated: This service is deprecated and will be removed in future versions

type RobotsService

type RobotsService interface {
	// Deprecated: use ValidatorService instead
	Allowed(ctx context.Context, serverName, endpoint string) bool
}
type Search struct {
	// contains filtered or unexported fields
}

Search service

func NewSearch

func NewSearch(cfg ConfigService, data searchDataRepository, repo SearchRepository, block BlocklistService, stats StatsService) *Search

NewSearch creates new search service

func (*Search) Search

func (s *Search) Search(ctx context.Context, q, sortBy string, limit, offset int) ([]*model.Entry, int, error)

Search things ref: https://blevesearch.com/docs/Query-String-Query/

type SearchRepository

type SearchRepository interface {
	Search(ctx context.Context, searchQuery query.Query, limit, offset int, sortBy []string) ([]*model.Entry, int, error)
}

SearchRepository interface

type Stats

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

Stats service

func NewStats

func NewStats(cfg ConfigService, data StatsRepository, index, blocklist Lenable) *Stats

NewStats service

func (*Stats) Collect

func (s *Stats) Collect(ctx context.Context)

Collect all stats from repository

func (*Stats) CollectServers

func (s *Stats) CollectServers(ctx context.Context, reload bool)

CollectServers stats only

func (*Stats) Get

func (s *Stats) Get() *model.IndexStats

Get stats

func (*Stats) GetTL

func (s *Stats) GetTL(ctx context.Context) map[time.Time]*model.IndexStats

GetTL stats timeline

func (*Stats) SetFinishedAt

func (s *Stats) SetFinishedAt(ctx context.Context, process string, finishedAt time.Time)

SetFinishedAt of the process

func (*Stats) SetStartedAt

func (s *Stats) SetStartedAt(ctx context.Context, process string, startedAt time.Time)

SetStartedAt of the process

type StatsRepository

type StatsRepository interface {
	DataRepository
	GetIndexStatsTL(ctx context.Context, prefix string) (map[time.Time]*model.IndexStats, error)
	SetIndexStatsTL(ctx context.Context, calculatedAt time.Time, stats *model.IndexStats) error
	GetIndexStats(ctx context.Context) *model.IndexStats
	SetIndexOnlineServers(ctx context.Context, servers int) error
	SetIndexIndexableServers(ctx context.Context, servers int) error
	SetIndexBlockedServers(ctx context.Context, servers int) error
	SetIndexParsedRooms(ctx context.Context, rooms int) error
	SetIndexIndexedRooms(ctx context.Context, rooms int) error
	SetIndexBannedRooms(ctx context.Context, rooms int) error
	SetIndexReportedRooms(ctx context.Context, rooms int) error
	SetStartedAt(ctx context.Context, process string, startedAt time.Time) error
	SetFinishedAt(ctx context.Context, process string, finishedAt time.Time) error
}

type StatsService

type StatsService interface {
	Get() *model.IndexStats
}

type Validator

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

Validator is matrix validation service

func NewValidator

func NewValidator(cfg ConfigService, block BlocklistService, matrix FederationService, robots RobotsService) *Validator

NewValidator creates new validation service

func (*Validator) Domain

func (v *Validator) Domain(server string) bool

Domain checks if domain name is valid

func (*Validator) IsIndexable

func (v *Validator) IsIndexable(ctx context.Context, server string) bool

IsIndexable check if server is indexable

func (*Validator) IsOnline

func (v *Validator) IsOnline(ctx context.Context, server string) (string, bool)

IsOnline checks if matrix server is online and federatable

func (*Validator) IsRoomAllowed

func (v *Validator) IsRoomAllowed(ctx context.Context, server string, room *model.MatrixRoom) bool

IsRoomAllowed checks if room is allowed

type ValidatorService

type ValidatorService interface {
	Domain(server string) bool
	IsOnline(ctx context.Context, server string) (string, bool)
	IsIndexable(ctx context.Context, server string) bool
	IsRoomAllowed(ctx context.Context, server string, room *model.MatrixRoom) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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