processing

package module
v0.0.0-...-a7d3ba1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 26 Imported by: 13

README

About GoActivityPub: Processing

MIT Licensed Build Status Test Coverage Go Report Card

This project is part of the GoActivityPub library which helps with creating ActivityPub applications using the Go programming language.

It provides basic functionality for processing and validation of generic ActivityPub activities.

It uses the concepts detailed in the 5.8.1 Content Management section of the ActivityStreams vocabulary specification for logic separation between groups of activities.

For the actual processing it uses the 6. Client to Server Interactions and 7. Server to Server Interactions sections of the ActivityPub specification.

You can find an expanded documentation about the whole library on SourceHut.

For discussions about the projects you can write to the discussions mailing list: ~mariusor/go-activitypub-discuss@lists.sr.ht

For patches and bug reports please use the dev mailing list: ~mariusor/go-activitypub-dev@lists.sr.ht

Documentation

Index

Constants

View Source
const BlockedCollection = vocab.CollectionPath("blocked")
View Source
const IgnoredCollection = vocab.CollectionPath("ignored")
View Source
const OAuthOOBRedirectURN = "urn:ietf:wg:oauth:2.0:oob:auto"

Variables

View Source
var ErrDuplicateObject = func(s string, p ...interface{}) errDuplicateKey {
	return errDuplicateKey{wrapErr(nil, fmt.Sprintf("Duplicate key: %s", s), p...)}
}
View Source
var InvalidActivity = func(s string, p ...interface{}) error {
	return ValidationError(fmt.Sprintf("Activity is not valid: %s", s), p...)
}
View Source
var InvalidActivityActor = func(s string, p ...interface{}) error {
	return ValidationError(fmt.Sprintf("Actor is not valid: %s", s), p...)
}
View Source
var InvalidActivityObject = func(s string, p ...interface{}) error {
	return ValidationError(fmt.Sprintf("Object is not valid: %s", s), p...)
}
View Source
var InvalidIRI = func(s string, p ...interface{}) error {
	return ValidationError(fmt.Sprintf("IRI is not valid: %s", s), p...)
}
View Source
var InvalidTarget = func(s string, p ...interface{}) error {
	return ValidationError(fmt.Sprintf("Target is not valid: %s", s), p...)
}
View Source
var MissingActivityActor = func(s string, p ...interface{}) error {
	return ValidationError(fmt.Sprintf("Missing actor %s", s), p...)
}
View Source
var NotModified = errors.NotModified("from cache")
View Source
var ValidationError = errors.BadRequestf

Functions

func AcceptActivity

func AcceptActivity(p P, act *vocab.Activity, receivedIn vocab.IRI) (*vocab.Activity, error)

AcceptActivity

In Inbox: https://www.w3.org/TR/activitypub/#follow-activity-inbox

The side effect of receiving this in an inbox is determined by the type of the object received, and it is possible to accept types not described in this document (for example, an Offer).

If the object of an Accept received to an inbox is a Follow activity previously sent by the receiver, the server SHOULD add the actor to the receiver's Following Collection.

func AppreciationActivity

func AppreciationActivity(p P, act *vocab.Activity) (*vocab.Activity, error)

AppreciationActivity The Like(and Dislike) activity indicates the actor likes the object. The side effect of receiving this in an outbox is that the server SHOULD add the object to the actor's liked Collection.

func BlockActivity

func BlockActivity(p P, act *vocab.Activity, receivedIn vocab.IRI) (*vocab.Activity, error)

BlockActivity

https://www.w3.org/TR/activitypub/#block-activity-outbox

The Block activity is used to indicate that the posting actor does not want another actor (defined in the object property) to be able to interact with objects posted by the actor posting the Block activity. The server SHOULD prevent the blocked user from interacting with any object posted by the actor.

Servers SHOULD NOT deliver Block Activities to their object.

func CollectionManagementActivity

func CollectionManagementActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

CollectionManagementActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-collections

The Collection Management use case primarily deals with activities involving the management of content within collections. Examples of collections include things like folders, albums, friend lists, etc. This includes, for instance, activities such as "Sally added a file to Folder A", "John moved the file from Folder A to Folder B", etc.

func ContentExperienceActivity

func ContentExperienceActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

ContentExperienceActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-experience

The Content Experience use case primarily deals with describing activities involving listening to, reading, or viewing content. For instance, "Sally read the article", "Joe listened to the song".

func ContentManagementActivityFromClient

func ContentManagementActivityFromClient(p P, act *vocab.Activity) (*vocab.Activity, error)

ContentManagementActivityFromClient processes matching activities.

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-crud

The Content Management use case primarily deals with activities that involve the creation, modification or deletion of content. This includes, for instance, activities such as "John created a new note", "Sally updated an article", and "Joe deleted the photo".

func CreateActivityFromClient

func CreateActivityFromClient(p P, act *vocab.Activity) (*vocab.Activity, error)

CreateActivityFromClient

https://www.w3.org/TR/activitypub/#create-activity-outbox

The Create activity is used when posting a new object. This has the side effect that the object embedded within the Activity (in the object property) is created. When a Create activity is posted, the actor of the activity SHOULD be copied onto the object's attributedTo field. A mismatch between addressing of the Create activity and its object is likely to lead to confusion. As such, a server SHOULD copy any recipients of the Create activity to its object upon initial distribution, and likewise with copying recipients from the object to the wrapping Create activity. Note that it is acceptable for the object's addressing to be changed later without changing the Create's addressing (for example via an Update activity).

https://www.w3.org/TR/activitypub/#create-activity-inbox

Receiving a Create activity in an inbox has surprisingly few side effects; the activity should appear in the actor's inbox, and it is likely that the server will want to locally store a representation of this activity and its accompanying object. However, this mostly happens in general with processing activities delivered to an inbox anyway.

func CreateActivityFromServer

func CreateActivityFromServer(p P, act *vocab.Activity) (*vocab.Activity, error)

func DeleteActivity

func DeleteActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

DeleteActivity

https://www.w3.org/TR/activitypub/#delete-activity-outbox

The Delete activity is used to delete an already existing object. The side effect of this is that the server MAY replace the object with a Tombstone of the object that will be displayed in activities which reference the deleted object. If the deleted object is requested the server SHOULD respond with either the HTTP 410 Gone status code if a Tombstone object is presented as the response body, otherwise respond with a HTTP 404 Not Found.

https://www.w3.org/TR/activitypub/#delete-activity-inbox

The side effect of receiving this is that (assuming the object is owned by the sending actor / server) the server receiving the delete activity SHOULD remove its representation of the object with the same id, and MAY replace that representation with a Tombstone object.

Note: that after an activity has been transmitted from an origin server to a remote server, there is nothing in the

ActivityPub protocol that can enforce remote deletion of an object's representation.

func EventRSVPActivity

func EventRSVPActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

EventRSVPActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-rsvp

The Event RSVP use case primarily deals with invitations to events and RSVP type responses.

func FilterItem

func FilterItem(i vocab.Item) itemFilter

func FlagActivity

func FlagActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

FlagActivity There isn't any side effect to this activity except delivering it to the inboxes of its recipients. From the list of recipients we remove the Object itself if it represents an Actor being flagged, or its author if it's another type of object.

func FollowActivity

func FollowActivity(p P, act *vocab.Activity, receivedIn vocab.IRI) (*vocab.Activity, error)

FollowActivity is used when following an actor.

https://www.w3.org/TR/activitypub/#follow-activity-outbox

The Follow activity is used to subscribe to the activities of another actor. The side effect of receiving this in an outbox is that the server SHOULD add the object to the actor's following Collection when and only if an Accept activity is subsequently received with this Follow activity as its object.

https://www.w3.org/TR/activitypub/#follow-activity-inbox

The side effect of receiving this in an inbox is that the server SHOULD generate either an Accept or Reject activity with the Follow as the object and deliver it to the actor of the Follow. The Accept or Reject MAY be generated automatically, or MAY be the result of user input (possibly after some delay in which the user reviews). Servers MAY choose to not explicitly send a Reject in response to a Follow, though implementors ought to be aware that the server sending the request could be left in an intermediate state. For example, a server might not send a Reject to protect a user's privacy. In the case of receiving an "Accept" referencing this Follow as the object, the server SHOULD add the actor to the object actor's Followers Collection. In the case of a Reject, the server MUST NOT add the actor to the object actor's Followers Collection.

NOTE: Sometimes a successful Follow subscription may occur but at some future point delivery to the follower fails for an extended period of time. Implementations should be aware that there is no guarantee that actors on the network will remain reachable and should implement accordingly. For instance, if attempting to deliver to an actor for perhaps six months while the follower remains unreachable, it is reasonable that the delivering server remove the subscriber from the followers list. Timeframes and behavior for dealing with unreachable actors are left to the discretion of the delivering server.

func GeoSocialEventsActivity

func GeoSocialEventsActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

GeoSocialEventsActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-geo

The Geo-Social Events use case primarily deals with activities involving geo-tagging type activities. For instance, it can include activities such as "Joe arrived at work", "Sally left work", and "John is travel from home to work".

func GeoSocialEventsIntransitiveActivity

func GeoSocialEventsIntransitiveActivity(l WriteStore, act *vocab.IntransitiveActivity) (*vocab.IntransitiveActivity, error)

GeoSocialEventsIntransitiveActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-geo

The Geo-Social Events use case primarily deals with activities involving geo-tagging type activities. For instance, it can include activities such as "Joe arrived at work", "Sally left work", and "John is travel from home to work".

func GroupManagementActivity

func GroupManagementActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

GroupManagementActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-group

The Group Management use case primarily deals with management of groups. It can include, for instance, activities such as "John added Sally to Group A", "Sally joined Group A", "Joe left Group A", etc.

func IRIBelongsToActor

func IRIBelongsToActor(iri vocab.IRI, actor vocab.Actor) bool

IRIBelongsToActor checks if the search iri represents any of the collections associated with the actor.

func IgnoreActivity

func IgnoreActivity(p P, act *vocab.Activity) (*vocab.Activity, error)

IgnoreActivity This relies on custom behavior for the repository, which would allow for an ignored collection, where we save these

func IsInbox

func IsInbox(i vocab.IRI) bool

func IsOutbox

func IsOutbox(i vocab.IRI) bool

func NegatingActivity

func NegatingActivity(l Store, act *vocab.Activity) (*vocab.Activity, error)

NegatingActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-undo

The Negating Activity use case primarily deals with the ability to redact previously completed activities. See 5.5 Inverse Activities and "Undo" for more information: https://www.w3.org/TR/activitystreams-vocabulary/#inverse

func NotificationActivity

func NotificationActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

NotificationActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-notification

The Notification use case primarily deals with calling attention to particular objects or notifications.

func ObjectNotUpdatedSince

func ObjectNotUpdatedSince(h http.Header, it vocab.Item) bool

func OffersActivity

func OffersActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

OffersActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-offer

The Offers use case deals with activities involving offering one object to another. It can include, for instance, activities such as "Company A is offering a discount on purchase of Product Z to Sally", "Sally is offering to add a File to Folder A", etc.

func QuestionActivity

func QuestionActivity(l WriteStore, q *vocab.Question) (*vocab.Question, error)

QuestionActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-questions

The Questions use case primarily deals with representing inquiries of any type. See 5.4 Representing Questions for more information: https://www.w3.org/TR/activitystreams-vocabulary/#questions

func ReactionsActivity

func ReactionsActivity(p P, act *vocab.Activity, receivedIn vocab.IRI) (*vocab.Activity, error)

ReactionsActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-respond

The Reactions use case primarily deals with reactions to content. This can include activities such as liking or disliking content, ignoring updates, flagging content as being inappropriate, accepting or rejecting objects, etc.

func RejectActivity

func RejectActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

func RelationshipManagementActivity

func RelationshipManagementActivity(p P, act *vocab.Activity, receivedIn vocab.IRI) (*vocab.Activity, error)

RelationshipManagementActivity processes matching activities

https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-relationships

The Relationship Management use case primarily deals with representing activities involving the management of interpersonal and social relationships (e.g. friend requests, management of social network, etc). See 5.2 Representing Relationships Between Entities for more information: https://www.w3.org/TR/activitystreams-vocabulary/#connections

func SetIDIfMissing

func SetIDIfMissing(it vocab.Item, partOf vocab.Item, parentActivity vocab.Item) error

func UndoActivity

func UndoActivity(r Store, act *vocab.Activity) (*vocab.Activity, error)

UndoActivity

https://www.w3.org/TR/activitypub/#undo-activity-outbox

The Undo activity is used to undo a previous activity. See the Activity Vocabulary documentation on Inverse Activities and "Undo". For example, Undo may be used to undo a previous Like, Follow, or Block. The undo activity and the activity being undone MUST both have the same actor. Side effects should be undone, to the extent possible. For example, if undoing a Like, any counter that had been incremented previously should be decremented appropriately. There are some exceptions where there is an existing and explicit "inverse activity" which should be used instead. Create based activities should instead use Delete, and Add activities should use Remove.

https://www.w3.org/TR/activitypub/#undo-activity-inbox

The Undo activity is used to undo the side effects of previous activities. See the ActivityStreams documentation on Inverse Activities and "Undo". The scope and restrictions of the Undo activity are the same as for the Undo activity in the context of client to server interactions, but applied to a federated context.

func UndoAppreciationActivity

func UndoAppreciationActivity(r Store, act *vocab.Activity) (*vocab.Activity, error)

UndoAppreciationActivity

Removes the side effects of an existing Appreciation activity (Like or Dislike) Currently this means only removal of the Liked/Disliked object from the actor's `liked` collection and removal of the Like/Dislike Activity from the object's `likes` collection

func UndoRelationshipManagementActivity

func UndoRelationshipManagementActivity(r WriteStore, act *vocab.Activity) (*vocab.Activity, error)

UndoRelationshipManagementActivity

Removes the side effects of an existing RelationshipActivity activity (Follow, Block, Ignore, Flag) Currently this means the removal of the objet from the collection corresponding to the original Activity type. Follow - removes the original object from the actor's followers collection. Block - removes the original object from the actor's blocked collection. Ignore - removes the original object from the actor's ignored collection. Flag - is a special case where there isn't a specific collection that needs to be operated on.

func UpdateActivity

func UpdateActivity(l WriteStore, act *vocab.Activity) (*vocab.Activity, error)

UpdateActivity

https://www.w3.org/TR/activitypub/#update-activity-outbox

The Update activity is used when updating an already existing object. The side effect of this is that the object MUST be modified to reflect the new structure as defined in the update activity, assuming the actor has permission to update this object.

https://www.w3.org/TR/activitypub/#update-activity-inbox

For server to server interactions, an Update activity means that the receiving server SHOULD update its copy of the object of the same id to the copy supplied in the Update activity. Unlike the client to server handling of the Update activity, this is not a partial update but a complete replacement of the object. The receiving server MUST take care to be sure that the Update is authorized to modify its object. At minimum, this may be done by ensuring that the Update and its object are of same origin.

func ValidateClientCollectionManagementActivity

func ValidateClientCollectionManagementActivity(l ReadStore, act *vocab.Activity) error

ValidateClientCollectionManagementActivity

func ValidateClientContentExperienceActivity

func ValidateClientContentExperienceActivity(l ReadStore, act *vocab.Activity) error

ValidateClientContentExperienceActivity

func ValidateClientContentManagementActivity

func ValidateClientContentManagementActivity(l ReadStore, act *vocab.Activity) error

ValidateClientContentManagementActivity

func ValidateClientEventRSVPActivity

func ValidateClientEventRSVPActivity(l ReadStore, act *vocab.Activity) error

ValidateClientEventRSVPActivity

func ValidateClientGeoSocialEventsActivity

func ValidateClientGeoSocialEventsActivity(l ReadStore, act *vocab.Activity) error

ValidateClientGeoSocialEventsActivity

func ValidateClientGroupManagementActivity

func ValidateClientGroupManagementActivity(l ReadStore, act *vocab.Activity) error

ValidateClientGroupManagementActivity

func ValidateClientNegatingActivity

func ValidateClientNegatingActivity(l ReadStore, act *vocab.Activity) error

ValidateClientNegatingActivity

func ValidateClientNotificationActivity

func ValidateClientNotificationActivity(l ReadStore, act *vocab.Activity) error

ValidateClientNotificationActivity

func ValidateClientOffersActivity

func ValidateClientOffersActivity(l ReadStore, act *vocab.Activity) error

ValidateClientOffersActivity

func ValidateClientQuestionActivity

func ValidateClientQuestionActivity(l ReadStore, act *vocab.Question) error

ValidateClientQuestionActivity

func ValidateClientReactionsActivity

func ValidateClientReactionsActivity(l ReadStore, act *vocab.Activity) error

ValidateClientReactionsActivity

func ValidateClientRelationshipManagementActivity

func ValidateClientRelationshipManagementActivity(l ReadStore, act *vocab.Activity) error

ValidateClientRelationshipManagementActivity

Types

type ActivityHandlerFn

type ActivityHandlerFn func(vocab.IRI, *http.Request) (vocab.Item, int, error)

ActivityHandlerFn is the type that we're using to represent handlers that process requests containing an ActivityStreams Activity. It needs to implement the http.Handler interface.

It is considered that following the execution of the handler, we return a pair formed of an HTTP status together with an IRI representing a new Object - in the case of transitive activities that had a side effect, or an error. In the case of intransitive activities the iri will always be empty.

func (ActivityHandlerFn) ServeHTTP

func (a ActivityHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for the ActivityHandlerFn type

func (ActivityHandlerFn) ValidMethod

func (a ActivityHandlerFn) ValidMethod(r *http.Request) bool

ValidMethod validates if the current handler can process the current request

func (ActivityHandlerFn) ValidateRequest

func (a ActivityHandlerFn) ValidateRequest(r *http.Request) (int, error)

ValidateRequest validates if the current handler can process the current request

type ActivityValidator

type ActivityValidator interface {
	ClientActivityValidator
	ServerActivityValidator
}

ActivityValidator is an interface used for validating activity objects.

type ActorValidator

type ActorValidator interface {
	ValidActor(vocab.Item) error
}

ActorValidator is an interface used for validating actor objects

type C2SProcessor

type C2SProcessor interface {
	ProcessClientActivity(vocab.Item, vocab.IRI) (vocab.Item, error)
}

C2SProcessor

type ClientActivityValidator

type ClientActivityValidator interface {
	ValidateClientActivity(vocab.Item, vocab.IRI) error
	ValidateClientObject(vocab.Item) error
	ValidateClientActor(vocab.Item) error
}

type CollectionHandlerFn

type CollectionHandlerFn func(vocab.CollectionPath, *http.Request) (vocab.CollectionInterface, error)

CollectionHandlerFn is the type that we're using to represent handlers that will return ActivityStreams Collection or OrderedCollection objects. It needs to implement the http.Handler interface.

func (CollectionHandlerFn) ServeHTTP

func (c CollectionHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for the CollectionHandlerFn type

func (CollectionHandlerFn) ValidMethod

func (c CollectionHandlerFn) ValidMethod(r *http.Request) bool

ValidMethod validates if the current handler can process the current request

func (CollectionHandlerFn) ValidateRequest

func (c CollectionHandlerFn) ValidateRequest(r *http.Request) (int, error)

ValidateRequest validates if the current handler can process the current request

type CollectionStore

type CollectionStore interface {
	// Create creates the "col" collection.
	Create(col vocab.CollectionInterface) (vocab.CollectionInterface, error)
	// AddTo adds "it" element to the "col" collection.
	AddTo(col vocab.IRI, it vocab.Item) error
	// RemoveFrom removes "it" item from "col" collection
	RemoveFrom(col vocab.IRI, it vocab.Item) error
}

CollectionStore allows operations on ActivityStreams collections

type CollectionTyper

type CollectionTyper interface {
	Type(r *http.Request) vocab.CollectionPath
}

CollectionTyper allows external packages to tell us which CollectionPath the current HTTP request addresses

var Typer CollectionTyper = pathTyper{}

Typer is the static package variable that determines a CollectionPath type for a particular request It can be overloaded from outside packages. @TODO(marius): This should be moved as a property on an instantiable package object, instead of keeping it here

type Filterable

type Filterable interface {
	GetLink() vocab.IRI
}

Filterable can filter objects by Type and ID This should be the minimal interface a filter object should implement for the storage layer to work. It also allows for an activitypub.IRI to be used as a filter.

type FilterableActivity

type FilterableActivity interface {
	FilterableObject
	Actors() vocab.IRIs
	Objects() vocab.IRIs
	Targets() vocab.IRIs
}

FilterableActivity can filter activities

type FilterableCollection

type FilterableCollection interface {
	FilterableObject
	TotalItemsGt() uint
	TotalItemsLt() uint
	TotalItemsEq() uint
	TotalItemsGtE() uint
	TotalItemsLtE() uint
	Contains() vocab.IRIs
}

FilterableCollection can filter collections

type FilterableItems

type FilterableItems interface {
	Filterable
	Types() vocab.ActivityVocabularyTypes
	IRIs() vocab.IRIs
}

type FilterableObject

type FilterableObject interface {
	FilterableItems
	AttributedTo() vocab.IRIs
	InReplyTo() vocab.IRIs
	MediaTypes() []vocab.MimeType
	Names() []string
	Content() []string
	//PublishedBefore() time.Time
	//PublishedAfter() time.Time
	URLs() vocab.IRIs
	// Audience returns the list of IRIs to check against full Audience targeting for the object
	// It should include all relevant fields: To, CC, BTo, BCC, and Audience
	// ---
	// An element of the Audience is used to get its Inbox end-point and then disseminate the current Activity
	// to it.
	Audience() vocab.IRIs
	// Context returns the list of IRIs to check against an Object's Context property.
	Context() vocab.IRIs
	// Generator returns the list of IRIs to check against an Object's Generator property.
	Generator() vocab.IRIs
}

FilterableObject can filter objects

type IDGenerator

type IDGenerator func(it vocab.Item, receivedIn vocab.Item, byActivity vocab.Item) (vocab.ID, error)

IDGenerator takes an ActivityStreams object, a collection to store it in, and the activity that has it as object:

"it" is the object we want to generate the ID for.
"partOf" represents the IRI of the Collection that it is a part of.
"by" represents the Activity that generated the object

type IRIValidator

type IRIValidator func(i vocab.IRI) bool

IRIValidator designates the type for a function that can validate an IRI It's currently used as the type for var isLocalIRI

type ItemHandlerFn

type ItemHandlerFn func(*http.Request) (vocab.Item, error)

ItemHandlerFn is the type that we're using to represent handlers that return ActivityStreams objects. It needs to implement the http.Handler interface

func (ItemHandlerFn) ServeHTTP

func (i ItemHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for the ItemHandlerFn type

func (ItemHandlerFn) ValidMethod

func (i ItemHandlerFn) ValidMethod(r *http.Request) bool

ValidMethod validates if the current handler can process the current request

func (ItemHandlerFn) ValidateRequest

func (i ItemHandlerFn) ValidateRequest(r *http.Request) (int, error)

ValidateRequest validates if the current handler can process the current request

type KeyLoader

type KeyLoader interface {
	LoadKey(vocab.IRI) (crypto.PrivateKey, error)
}

type Metadata

type Metadata struct {
	Pw         []byte `jsonld:"pw,omitempty"`
	PrivateKey []byte `jsonld:"key,omitempty"`
}

type MethodValidator

type MethodValidator interface {
	ValidMethod(r *http.Request) bool
}

MethodValidator is the interface need to be implemented to specify if an HTTP request's method is supported by the implementor object

type ObjectValidator

type ObjectValidator interface {
	ValidateObject(vocab.Item) error
}

ObjectValidator is an interface used for validating generic objects

type OptionFn

type OptionFn func(s *P)

func WithActorKeyGenerator

func WithActorKeyGenerator(genFn vocab.WithActorFn) OptionFn

func WithClient

func WithClient(c c.Basic) OptionFn

func WithIDGenerator

func WithIDGenerator(genFn IDGenerator) OptionFn

func WithIRI

func WithIRI(i ...vocab.IRI) OptionFn

func WithLocalIRIChecker

func WithLocalIRIChecker(isLocalFn IRIValidator) OptionFn

func WithLogger

func WithLogger(l lw.Logger) OptionFn

func WithStorage

func WithStorage(s Store) OptionFn

type P

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

func New

func New(o ...OptionFn) P

func (P) AddItemToCollection

func (p P) AddItemToCollection(col vocab.IRI, it vocab.Item) error

AddItemToCollection attempts to append "it" to collection "col"

If the collection is not local, it doesn't do anything If the item is a non-local IRI, it tries to dereference it, and then save a local representation of it.

func (P) AddToLocalCollections

func (p P) AddToLocalCollections(it vocab.Item, recipients ...vocab.Item) error

AddToLocalCollections handles the dissemination of the received it Activity to the local collections, it is addressed to:

  • the author's Outbox
  • the recipients' Inboxes

func (P) AddToRemoteCollections

func (p P) AddToRemoteCollections(it vocab.Item, recipients ...vocab.Item) error

AddToRemoteCollections handles the dissemination of the received it Activity to the local collections, it is addressed to:

  • the recipients' Inboxes

func (P) BuildInboxRecipientsList

func (p P) BuildInboxRecipientsList(it vocab.Item, receivedIn vocab.IRI) (vocab.ItemCollection, error)

BuildInboxRecipientsList builds the recipients list of the received 'it' Activity is addressed to:

  • the author's Outbox
  • the recipients' Inboxes

func (P) BuildOutboxRecipientsList

func (p P) BuildOutboxRecipientsList(it vocab.Item, receivedIn vocab.IRI) (vocab.ItemCollection, error)

BuildOutboxRecipientsList builds the recipients list of the received 'it' Activity is addressed to:

  • the author's Outbox
  • the recipients' Inboxes

func (P) BuildReplyToCollections

func (p P) BuildReplyToCollections(it vocab.Item) (vocab.ItemCollection, error)

BuildReplyToCollections builds the list of objects that it is inReplyTo

func (P) CreateCollectionsForObject

func (p P) CreateCollectionsForObject(it vocab.Item) error

CreateCollectionsForObject creates the objects corresponding to each collection that an Actor has set.

func (P) IsLocal

func (p P) IsLocal(i vocab.Item) bool

IsLocal shows if the received IRI belongs to the current instance

func (P) IsLocalIRI

func (p P) IsLocalIRI(i vocab.IRI) bool

IsLocalIRI shows if the received IRI belongs to the current instance

func (P) ProcessActivity

func (p P) ProcessActivity(it vocab.Item, author vocab.Actor, receivedIn vocab.IRI) (vocab.Item, error)

ProcessActivity processes an Activity received

func (P) ProcessClientActivity

func (p P) ProcessClientActivity(it vocab.Item, author vocab.Actor, receivedIn vocab.IRI) (vocab.Item, error)

ProcessClientActivity processes an Activity received in a client to server request

https://www.w3.org/TR/activitypub/#client-to-server-interactions

Activities as defined by [ActivityStreams] are the core mechanism for creating, modifying and sharing content within the social graph.

Client to server interaction takes place through clients posting Activities to an actor's outbox. To do this, clients MUST discover the URL of the actor's outbox from their profile and then MUST make an HTTP POST request to this URL with the Content-Type of 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'. Servers MAY interpret a Content-Type or Accept header of application/activity+json as equivalent to 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' for client-to-server interactions. The request MUST be authenticated with the credentials of the user to whom the outbox belongs. The body of the POST request MUST contain a single Activity (which MAY contain embedded objects), or a single non-Activity object which will be wrapped in a Create activity by the server.

If an Activity is submitted with a value in the id property, servers MUST ignore this and generate a new id for the Activity. Servers MUST return a 201 Created HTTP code, and unless the activity is transient, MUST include the new id in the Location header.

The server MUST remove the bto and/or bcc properties, if they exist, from the ActivityStreams object before delivery, but MUST utilize the addressing originally stored on the bto / bcc properties for determining recipients in delivery.

The server MUST then add this new Activity to the outbox collection. Depending on the type of Activity, servers may then be required to carry out further side effects. (However, there is no guarantee that time the Activity may appear in the outbox. The Activity might appear after a delay or disappear at any period). These are described per individual Activity below.

Attempts to submit objects to servers not implementing client to server support SHOULD result in a 405 Method Not Allowed response.

HTTP caching mechanisms [RFC7234] SHOULD be respected when appropriate, both in clients receiving responses from servers as well as servers sending responses to clients.

func (P) ProcessOutboxDelivery

func (p P) ProcessOutboxDelivery(it vocab.Item, receivedIn vocab.IRI) error

ProcessOutboxDelivery

Outbox Delivery Requirements for Server to Server

https://www.w3.org/TR/activitypub/#outbox-delivery

When objects are received in the outbox (for servers which support both Client to Server interactions and Server to Server Interactions), the server MUST target and deliver to:

The to, bto, cc, bcc or audience fields if their values are individuals or Collections owned by the actor. These fields will have been populated appropriately by the client which posted the Activity to the outbox.

Additional recommendation from the ActivityPub mailing list: Activities addressed to `Public` usually appear only in the inboxes of actors that follow the activity's `actor` property.

func (P) ProcessServerActivity

func (p P) ProcessServerActivity(it vocab.Item, author vocab.Actor, receivedIn vocab.IRI) (vocab.Item, error)

ProcessServerActivity processes an Activity received in a server to server request

https://www.w3.org/TR/activitypub/#server-to-server-interactions

Servers communicate with other servers and propagate information across the social graph by posting activities to actors' inbox endpoints. An Activity sent over the network SHOULD have an id, unless it is intended to be transient (in which case it MAY omit the id).

POST requests (eg. to the inbox) MUST be made with a Content-Type of 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' and GET requests (see also 3.2 Retrieving objects) with an Accept header of 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'. Servers SHOULD interpret a Content-Type or Accept header of 'application/activity+json' as equivalent to application/ld+json; profile="https://www.w3.org/ns/activitystreams" for server-to-server interactions.

In order to propagate updates throughout the social graph, Activities are sent to the appropriate recipients. First, these recipients are determined through following the appropriate links between objects until you reach an actor, and then the Activity is inserted into the actor's inbox (delivery). This allows recipient servers to:

conduct any side effects related to the Activity (for example, notification that an actor has liked an object is used to update the object's like count); deliver the Activity to recipients of the original object, to ensure updates are propagated to the whole social graph (see inbox delivery).

Delivery is usually triggered by one of:

* an Activity being created in an actor's outbox with their Followers Collection as the recipient. * an Activity being created in an actor's outbox with directly addressed recipients. * an Activity being created in an actor's outbox with user-curated collections as recipients. * an Activity being created in an actor's outbox or inbox which references another object.

Servers performing delivery to the inbox or sharedInbox properties of actors on other servers MUST provide the object property in the activity: Create, Update, Delete, Follow, Add, Remove, Like, Block, Undo. Additionally, servers performing server to server delivery of the following activities MUST also provide the target property: Add, Remove.

HTTP caching mechanisms [RFC7234] SHOULD be respected when appropriate, both when receiving responses from other servers and when sending responses to other servers.

func (P) ProcessServerInboxDelivery

func (p P) ProcessServerInboxDelivery(it vocab.Item, receivedIn vocab.IRI) error

ProcessServerInboxDelivery processes an incoming activity received in an actor's Inbox collection

Forwarding from Inbox

https://www.w3.org/TR/activitypub/#inbox-forwarding

NOTE: Forwarding to avoid the ghost replies problem The following section is to mitigate the "ghost replies" problem which occasionally causes problems on federated networks. This problem is best demonstrated with an example.

Alyssa makes a post about her having successfully presented a paper at a conference and sends it to her followers collection, which includes her friend Ben. Ben replies to Alyssa's message congratulating her and includes her followers collection on the recipients. However, Ben has no access to see the members of Alyssa's followers collection, so his server does not forward his messages to their inbox. Without the following mechanism, if Alyssa were then to reply to Ben, her followers would see Alyssa replying to Ben without having ever seen Ben interacting. This would be very confusing!

When Activities are received in the inbox, the server needs to forward these to recipients that the origin was unable to deliver them to. To do this, the server MUST target and deliver to the values of to, cc, and/or audience if and only if all of the following are true:

* This is the first time the server has seen this Activity. * The values of to, cc, and/or audience contain a Collection owned by the server. * The values of inReplyTo, object, target and/or tag are objects owned by the server. * The server SHOULD recurse through these values to look for linked objects owned by the server, and SHOULD set a maximum limit for recursion (ie. the point at which the thread is so deep the recipients followers may not mind if they are no longer getting updates that don't directly involve the recipient). The server MUST only target the values of to, cc, and/or audience on the original object being forwarded, and not pick up any new addressees whilst recursing through the linked objects (in case these addressees were purposefully amended by or via the client).

The server MAY filter its delivery targets according to implementation-specific rules (for example, spam filtering).

func (P) ValidateActivity

func (p P) ValidateActivity(a vocab.Item, author vocab.Actor, receivedIn vocab.IRI) error

func (P) ValidateActor

func (p P) ValidateActor(a vocab.Item, expected vocab.Actor) (vocab.Item, error)

func (P) ValidateAudience

func (p P) ValidateAudience(audience ...vocab.ItemCollection) error

func (P) ValidateClientActivity

func (p P) ValidateClientActivity(a vocab.Item, author vocab.Actor, outbox vocab.IRI) error

func (P) ValidateClientActor

func (p P) ValidateClientActor(a vocab.Item, expected vocab.Actor) (vocab.Item, error)

func (P) ValidateClientObject

func (p P) ValidateClientObject(o vocab.Item) (vocab.Item, error)

func (P) ValidateIRI

func (p P) ValidateIRI(i vocab.IRI) error

func (P) ValidateServerActivity

func (p P) ValidateServerActivity(a vocab.Item, author vocab.Actor, inbox vocab.IRI) error

func (P) ValidateServerActor

func (p P) ValidateServerActor(a vocab.Item, expected vocab.Actor) (vocab.Item, error)

func (P) ValidateServerObject

func (p P) ValidateServerObject(o vocab.Item) (vocab.Item, error)

func (P) ValidateTarget

func (p P) ValidateTarget(t vocab.Item) error

type ReadStore

type ReadStore interface {
	// Load returns an Item or an ItemCollection from an IRI
	// after filtering it through the FilterFn list of filtering functions. Eg ANY()
	Load(vocab.IRI, ...filters.Check) (vocab.Item, error)
}

type RequestValidator

type RequestValidator interface {
	ValidateRequest(r *http.Request) (int, error)
}

RequestValidator is the interface need to be implemented to specify if the whole HTTP request is valid in the context of the implementor object

type S2SProcessor

type S2SProcessor interface {
	ProcessServerActivity(vocab.Item, vocab.IRI) (vocab.Item, error)
}

type ServerActivityValidator

type ServerActivityValidator interface {
	ValidateServerActivity(vocab.Item, vocab.IRI) error
	ValidateServerObject(vocab.Item) error
	ValidateServerActor(vocab.Item) error
}

type Store

type Store interface {
	ReadStore
	WriteStore
	CollectionStore
}

type Validator

type Validator interface {
	ValidateClientActivity(vocab.Item, vocab.IRI) error
}

type WriteStore

type WriteStore interface {
	// Save saves the incoming ActivityStreams Object, and returns it together with any properties
	// populated by the method's side effects. (eg, Published property can point to the current time, etc.).
	Save(vocab.Item) (vocab.Item, error)
	// Delete deletes completely from storage the ActivityStreams Object
	Delete(vocab.Item) error
}

WriteStore saves ActivityStreams objects.

Jump to

Keyboard shortcuts

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