activitystreams

package module
v0.0.0-...-6c5c415 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

== Go ActivityStreams ==

Standard compliant ActivityStreams implementation in Go.

Documentation

Index

Constants

View Source
const (
	CSListAppend
	CSListRemove
	CSAddField
	CSUpdateField
	CSRemoveField
	CSAddObject
	CSUpdateObject
	CSRemoveObject
	CSColAdd
	CSColRM
	CSColSet
	CSColRMAll
)
View Source
const RECURSE_MAX = 1

Variables

View Source
var Activities = []string{"Accept", "Add", "Announce", "Arrive", "Block",
	"Create", "Delete", "Dislike", "Flag", "Follow", "Ignore", "Invite",
	"Join", "Leave", "Like", "Listen", "Move", "Offer", "Question", "Reject",
	"Read", "Remove", "TentativeReject", "TentativeAccept", "Travel", "Undo",
	"Update", "View"}
View Source
var ActivityNoTarget = errors.New("Activity does not have a valid target")
View Source
var ActorProtectedFields = []string{"outbox", "inbox", "liked", "followers",
	"following"}
View Source
var BadActorConstruction = errors.New("Actor is borked yo!")
View Source
var BadChangeset = errors.New("Invalid changeset action")
View Source
var BadPropagationTarget = errors.New("Propagation target does not exist")
View Source
var BadQuestion = errors.New("Questions must have either oneOf xor anyOf")
View Source
var BlockedActor = errors.New("Source Actor blocked by Target actor")
View Source
var ClosedStorage = errors.New("Database closed")
View Source
var DuplicateItem = errors.New("Item already exists in this location")
View Source
var InvalidDeleteTarget = errors.New("Deletion target is invalid")
View Source
var InvalidOutbox = errors.New("Invalid Outbox ID")
View Source
var InvalidTargetType = errors.New("Target object is not the correct type")
View Source
var InvalidTransaction = errors.New("Invalid transaction")

Errors

View Source
var NoChangeset = errors.New("No changeset under that ID")
View Source
var ObjectNotInOrigin = errors.New("Object not present in Origin collection")
View Source
var ProtectedFields = []string{"@id", "id", "@type", "type", "attributedTo"}
View Source
var ProtectedObject = errors.New("Object is protected")
View Source
var UnownedTarget = errors.New("Object of Update not owned by Actor")

Functions

func CarveTombstone

func CarveTombstone(cadaver map[string]interface{}) (tombstone map[string]interface{})

Constructs the Tombstone for an object that is being deleted.

func CreateWrap

func CreateWrap(object map[string]interface{}) (activity map[string]interface{})

Wrap a bare object in a Create activity.

func ExtractCorePropagation

func ExtractCorePropagation(obj map[string]interface{}, sourceActor object.LocalID, host string, port uint16) (targets []interface{})

Extracts propagation targets from the standard locations of an object.

func GlobalizeList

func GlobalizeList(list []interface{}, hostname string, port uint16)

Recursively trawls a list and replaces all LocalIDs with globalIDs.

func GlobalizeLocal

func GlobalizeLocal(value object.LocalID, hostname string, port uint16) string

Converts a LocalID to a global ID, taking ports or lack therof into account.

func GlobalizeObject

func GlobalizeObject(obj map[string]interface{}, hostname string, port uint16)

Recursively trawls an object and replaces all LocalIDs with global IDs.

func HasGhostTargets

func HasGhostTargets(tx Transaction, activity map[string]interface{}, host string, port uint16, recursion uint) (hasTargets bool)

Checks if this server owns anything in the target fields.

func HasGhostTos

func HasGhostTos(activity map[string]interface{}, host string, port uint16) (localTargets []object.LocalID)

Checks if this server owns anything that is in the propagation fields.

func IsActivity

func IsActivity(objType string) (activity bool)

func IsActor

func IsActor(objType string) (actor bool)

func IsBlocked

func IsBlocked(blockList []interface{}, source string) (blocked bool)

func IsCollection

func IsCollection(objType string) (collection bool)

func MakeNowTimestamp

func MakeNowTimestamp() (datetime string)

func SlicifyScalar

func SlicifyScalar(data interface{}) []interface{}

Forces data to be a list. Used to simplify code that wants to deal with lists and may be passed single items.

func SyncFields

func SyncFields(objA map[string]interface{}, objB map[string]interface{}, fieldName string)

Synchronizes a field between two objects.

func UpdateActor

func UpdateActor(actor map[string]interface{}, diff map[string]interface{}) (updated map[string]interface{})

Update non-protected fields of an actor from a diff.

func UpdateNormalObject

func UpdateNormalObject(obj map[string]interface{}, diff map[string]interface{}) (updated map[string]interface{})

Update non-protected fields of an object from a diff.

Types

type Account

type Account struct {
	User         string
	Salt         [16]byte
	Time         uint32
	Memory       uint32
	KeyLen       uint32
	HashPW       []byte
	ActorID      object.LocalID
	ActorURL     string
	CreationDate string // RFC3339
}

Account data

type Change

type Change struct {
	Action    int // The action to perform in reversing
	ObjectID  object.LocalID
	FieldName string
	Value     interface{}
}

type Core

type Core struct {
	Hostname      string
	SubserverName string
	Port          uint16
	Prefix        string
	// contains filtered or unexported fields
}

server core

func NewCore

func NewCore() (c *Core)

func (*Core) AddActor

func (c *Core) AddActor(actorID object.LocalID, actorType string) (err error)

Creates an Actor and it's supporting objects.

func (*Core) DeleteAccount

func (c *Core) DeleteAccount(user string) (err error)

func (*Core) GenerateObjectID

func (c *Core) GenerateObjectID(actorID object.LocalID) (objectID object.LocalID)

Generates object IDs for newly created objects and activities that are not special objects.

func (*Core) Get

func (c *Core) Get(objectID object.LocalID, authActor object.LocalID) (gotObj map[string]interface{}, err error)

func (*Core) GetLocal

func (c *Core) GetLocal(objectID object.LocalID, authActor object.LocalID) (gotObj map[string]interface{}, err error)

func (*Core) InboxAccept

func (c *Core) InboxAccept(tx Transaction, targetID object.LocalID, activity map[string]interface{}) (err error)

func (*Core) InboxLike

func (c *Core) InboxLike(tx Transaction, inboxActor object.LocalID, activity map[string]interface{}) (err error)

func (*Core) IsSubserver

func (c *Core) IsSubserver() (issub bool)

func (*Core) LoadAccount

func (c *Core) LoadAccount(user string) (acct Account, err error)

func (*Core) NativeObjectOwner

func (c *Core) NativeObjectOwner(tx Transaction, objectID object.LocalID) (actorID object.LocalID, err error)

Returns the owning actor of a native object.

func (*Core) NewAccount

func (c *Core) NewAccount(acct Account) (err error)

func (*Core) OutboxAccept

func (c *Core) OutboxAccept(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxAdd

func (c *Core) OutboxAdd(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxBlock

func (c *Core) OutboxBlock(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxCreate

func (c *Core) OutboxCreate(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxDelete

func (c *Core) OutboxDelete(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxFollow

func (c *Core) OutboxFollow(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxLike

func (c *Core) OutboxLike(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxMove

func (c *Core) OutboxMove(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxNonSpecialActivity

func (c *Core) OutboxNonSpecialActivity(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxQuestion

func (c *Core) OutboxQuestion(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxRemove

func (c *Core) OutboxRemove(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxUndo

func (c *Core) OutboxUndo(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) OutboxUpdate

func (c *Core) OutboxUpdate(tx Transaction, actorID object.LocalID, outboxID object.LocalID, activity map[string]interface{}) (activityID object.LocalID, prop []interface{}, changes []Change, err error)

func (*Core) PendingPropagations

func (c *Core) PendingPropagations() (objects map[object.LocalID]map[string]interface{}, props map[object.LocalID][]PropRetryTarget, err error)

func (*Core) PostInboxLocal

func (c *Core) PostInboxLocal(inboxID object.LocalID, activity map[string]interface{}) (err error)

func (*Core) PostInboxRemote

func (c *Core) PostInboxRemote(inboxID object.LocalID, activity map[string]interface{}) (err error)

func (*Core) PostOutbox

func (c *Core) PostOutbox(outboxID object.LocalID, activity map[string]interface{}) (activityIDStr string, err error)

PostOutbox handles all of the generally applicable tasks for activities a client posts to an actor's outbox. Tasks specific to an activity are performed by the outbox handlers. PostOutbox handles: * Object sanity checking TODO * Actor / Outbox matching * Create wrapping of non-activity objects * Storing the incoming objects and adding them to the actor's outbox * Distributing replies and propagation

func (*Core) SetDatabase

func (c *Core) SetDatabase(s Storage)

func (*Core) UpdateAccount

func (c *Core) UpdateAccount(user string, acct Account) (err error)

func (*Core) UpdatePropagation

func (c *Core) UpdatePropagation(updates map[object.LocalID][]PropRetryTarget, removals map[object.LocalID][]string) (err error)

type DummyStorage

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

func NewDummyStorage

func NewDummyStorage() (d *DummyStorage)

func (*DummyStorage) Close

func (d *DummyStorage) Close() (err error)

func (*DummyStorage) StartTransaction

func (d *DummyStorage) StartTransaction() (t Transaction, err error)

type PropRetryTarget

type PropRetryTarget struct {
	Url      string
	Cluster  bool // Is this a cluster-local propagation?
	TryCount uint
	LastTry  string // RFC3339 timestamp
}

func NewPropRetryCluster

func NewPropRetryCluster(url object.LocalID) (p PropRetryTarget)

func NewPropRetryGlobal

func NewPropRetryGlobal(url string) (p PropRetryTarget)

type Storage

type Storage interface {
	// Storage utility / management
	Close() error
	StartTransaction() (Transaction, error)
}

type Transaction

type Transaction interface {
	RevertTransaction() error
	EndTransaction(errIn *error) error
	// Primary object store -- object level
	StoreObject(obj map[string]interface{}) error
	LoadObject(objectID object.LocalID) (map[string]interface{}, error)
	RemoveObject(objectID object.LocalID) error
	SetProtected(objectID object.LocalID, protected bool) error
	IsProtected(objectID object.LocalID) (bool, error)
	BasicObjectData(objectID object.LocalID) (string, object.LocalID, error)
	Exists(objectID object.LocalID) (bool, error)
	// Primary object store -- field level
	LoadObjectField(objectID object.LocalID, fieldName string) (interface{}, error)
	ListAppend(objectID object.LocalID, fieldName string, data interface{}) error
	ListRemove(objectID object.LocalID, fieldName string, data interface{}) error
	AddField(objectID object.LocalID, fieldName string, data interface{}) error
	UpdateField(objectID object.LocalID, fieldName string, data interface{}) error
	RemoveField(objectID object.LocalID, fieldName string) error
	ValueInObject(objectID object.LocalID, fieldName string, data interface{}) (bool, error)
	// Object ancillary collection handling
	ObjcolAdd(objectID object.LocalID, fieldName string, value interface{}) error
	ObjcolRM(objectID object.LocalID, fieldName string, value interface{}) error
	ObjcolGetAllField(objectID object.LocalID, fieldName string) ([]interface{}, error)
	ObjcolGetFields(objectID object.LocalID) ([]string, error)
	ObjcolSet(objectID object.LocalID, data map[string][]interface{}) error
	ObjcolRMAll(objectID object.LocalID) error
	ObjcolGetAll(objectID object.LocalID) (map[string][]interface{}, error)
	// Changeset handling
	StoreChangeset(changeID string, changeset []Change) error
	LoadChangeset(changeID string) ([]Change, error)
	// Cached object store
	StoreCache(obj map[string]interface{}) error
	LoadCache(objID string) (map[string]interface{}, error)
	// Propagation holding
	StoreProp(obj map[string]interface{}, targets []PropRetryTarget) error
	GetPropIDs() ([]object.LocalID, error)
	GetPropObject(objectID object.LocalID) (map[string]interface{}, error)
	GetPropTargets(objectID object.LocalID) ([]PropRetryTarget, error)
	UpdatePropTarget(objectID object.LocalID, target PropRetryTarget) error
	RemovePropTarget(objectID object.LocalID, targetURL string) error
	// Account data
	StoreAccount(acct Account) error
	LoadAccount(user string) (Account, error)
	UpdateAccount(user string, acct Account) error
	DeleteAccount(user string) error
}

Storage interface

type UpperLevel

type UpperLevel interface {
	SendObject(object map[string]interface{}, toServer string) error
}

Upper system interface This interface is what the server provides to the AP core, so that it can

send data to other servers without needing to know about TLS or other
complications.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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