trust

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

Developer notes: Trust Sources

Trust Sources (trust.Source implementations) are expected to be able to be created randomly and with minimal context, unlike filters which require a known community state. This is primarily so that API endpoints can be used to populate the trust data in the source: instead of having the API layer track down an already-created source, it can just create a new one, run the new data through it, and then discard the object for the garbage collector.

It's incredibly important that trust sources do not assume that they only have a single instance running, or that their lifespan is long. Sources which need to persist data across objects must have a management layer they plug into rather than create.

Trust sources can store data in the database using storage.PersistentStorage.[Get/Set]TrustData. This data is keyed by the source's "name" (arbitrary string - pick something unique for the source) and a "key". The key is arbitrary and intended to be used for stuff like a room/community ID. The key may be an empty string if the source doesn't scope its data. Note that the data is stored as JSON in the database.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability

type Capability string
const CapabilityMedia Capability = "media"

type CreatorSource

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

CreatorSource - trusts v12+ room creators as high power level users

func NewCreatorSource

func NewCreatorSource(db storage.PersistentStorage) (*CreatorSource, error)

func (*CreatorSource) GetCreators

func (s *CreatorSource) GetCreators(ctx context.Context, roomId string) ([]string, error)

func (*CreatorSource) HasCapability

func (s *CreatorSource) HasCapability(ctx context.Context, userId string, roomId string, capability Capability) (Tristate, error)

func (*CreatorSource) ImportData

func (s *CreatorSource) ImportData(ctx context.Context, roomId string, createEvent gomatrixserverlib.PDU) error

type MuninnHallMemberDirectory

type MuninnHallMemberDirectory map[string][]string

type MuninnHallSource

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

MuninnHallSource - uses the Muninn Hall member directory to determine which servers have higher trust levels in communities.

func NewMuninnHallSource

func NewMuninnHallSource(db storage.PersistentStorage) (*MuninnHallSource, error)

func (*MuninnHallSource) GetServers

func (s *MuninnHallSource) GetServers(ctx context.Context) ([]string, error)

func (*MuninnHallSource) HasCapability

func (s *MuninnHallSource) HasCapability(ctx context.Context, userId string, roomId string, capability Capability) (Tristate, error)

func (*MuninnHallSource) ImportData

func (s *MuninnHallSource) ImportData(ctx context.Context, directory MuninnHallMemberDirectory) error

type MuninnMemberDirectoryEvent

type MuninnMemberDirectoryEvent struct {
	Content struct {
		MemberDirectory MuninnHallMemberDirectory `json:"com.muninn-hall.member_directory"`
	} `json:"content"`
}

type PowerLevelsSource

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

PowerLevelsSource - uses the room's power levels to determine trust levels. Above-default power levels are trusted.

func NewPowerLevelsSource

func NewPowerLevelsSource(db storage.PersistentStorage) (*PowerLevelsSource, error)

func (*PowerLevelsSource) HasCapability

func (s *PowerLevelsSource) HasCapability(ctx context.Context, userId string, roomId string, capability Capability) (Tristate, error)

func (*PowerLevelsSource) ImportData

func (s *PowerLevelsSource) ImportData(ctx context.Context, roomId string, powerLevelsEvent gomatrixserverlib.PDU) error

func (*PowerLevelsSource) IsUserAboveDefault

func (s *PowerLevelsSource) IsUserAboveDefault(ctx context.Context, roomId string, userId string) (bool, error)

type SelfDirectedSource

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

SelfDirectedSource - trusts user IDs matching the allowed globs list, and doesn't trust those matching the denied globs list. Note that the denied globs list takes precedence over the allowed globs list.

func NewSelfDirectedSource

func NewSelfDirectedSource(db storage.PersistentStorage, allowedGlobs []string, deniedGlobs []string) (*SelfDirectedSource, error)

func (*SelfDirectedSource) HasCapability

func (s *SelfDirectedSource) HasCapability(ctx context.Context, userId string, roomId string, capability Capability) (Tristate, error)

type Source

type Source interface {
	// HasCapability returns TristateTrue if the given user has the given capability in the given room under this source of trust,
	// TristateFalse if they explicitly do not, and TristateDefault if the source of trust doesn't have an opinion.
	HasCapability(ctx context.Context, userId string, roomId string, capability Capability) (Tristate, error)
}

Source - represents a source of trust. "Trust" is arbitrarily defined as a set of capabilities applied to users in a room. This trust may be global, or it may be scoped to a community. Trust may also change over time.

type Tristate

type Tristate byte
const TristateDefault Tristate = 0
const TristateFalse Tristate = 2
const TristateTrue Tristate = 1

func (Tristate) Is

func (t Tristate) Is(val bool) bool

Jump to

Keyboard shortcuts

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