activitypub

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserAgentString is used to identify exlibris in http requests.
	UserAgentString = "exlibris-fed" // TODO version number
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityPub

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

ActivityPub represents the federating server connection.

func New

func New(db *gorm.DB) *ActivityPub

New returns a new ActiityPub object.

func (*ActivityPub) AuthenticateGetInbox

func (ap *ActivityPub) AuthenticateGetInbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authenticated bool, err error)

AuthenticateGetInbox delegates the authentication of a GET to an inbox.

Always called, regardless whether the Federated Protocol or Social API is enabled.

If an error is returned, it is passed back to the caller of GetInbox. In this case, the implementation must not write a response to the ResponseWriter as is expected that the client will do so when handling the error. The 'authenticated' is ignored.

If no error is returned, but authentication or authorization fails, then authenticated must be false and error nil. It is expected that the implementation handles writing to the ResponseWriter in this case.

Finally, if the authentication and authorization succeeds, then authenticated must be true and error nil. The request will continue to be processed.

func (*ActivityPub) AuthenticateGetOutbox

func (ap *ActivityPub) AuthenticateGetOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authenticated bool, err error)

AuthenticateGetOutbox delegates the authentication of a GET to an outbox.

Always called, regardless whether the Federated Protocol or Social API is enabled.

If an error is returned, it is passed back to the caller of GetOutbox. In this case, the implementation must not write a response to the ResponseWriter as is expected that the client will do so when handling the error. The 'authenticated' is ignored.

If no error is returned, but authentication or authorization fails, then authenticated must be false and error nil. It is expected that the implementation handles writing to the ResponseWriter in this case.

Finally, if the authentication and authorization succeeds, then authenticated must be true and error nil. The request will continue to be processed.

func (*ActivityPub) AuthenticatePostInbox

func (ap *ActivityPub) AuthenticatePostInbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authenticated bool, err error)

AuthenticatePostInbox delegates the authentication of a POST to an inbox.

If an error is returned, it is passed back to the caller of PostInbox. In this case, the implementation must not write a response to the ResponseWriter as is expected that the client will do so when handling the error. The 'authenticated' is ignored.

If no error is returned, but authentication or authorization fails, then authenticated must be false and error nil. It is expected that the implementation handles writing to the ResponseWriter in this case.

Finally, if the authentication and authorization succeeds, then authenticated must be true and error nil. The request will continue to be processed.

func (*ActivityPub) Blocked

func (ap *ActivityPub) Blocked(c context.Context, actorIRIs []*url.URL) (blocked bool, err error)

Blocked should determine whether to permit a set of actors given by their ids are able to interact with this particular end user due to being blocked or other application-specific logic.

If an error is returned, it is passed back to the caller of PostInbox.

If no error is returned, but authentication or authorization fails, then blocked must be true and error nil. An http.StatusForbidden will be written in the wresponse.

Finally, if the authentication and authorization succeeds, then blocked must be false and error nil. The request will continue to be processed.

func (*ActivityPub) Callbacks

func (ap *ActivityPub) Callbacks(c context.Context) (wrapped pub.FederatingWrappedCallbacks, other []interface{}, err error)

Callbacks returns the application logic that handles ActivityStreams received from federating peers.

Note that certain types of callbacks will be 'wrapped' with default behaviors supported natively by the library. Other callbacks compatible with streams.TypeResolver can be specified by 'other'.

For example, setting the 'Create' field in the FederatingWrappedCallbacks lets an application dependency inject additional behaviors they want to take place, including the default behavior supplied by this library. This is guaranteed to be compliant with the ActivityPub Social protocol.

To override the default behavior, instead supply the function in 'other', which does not guarantee the application will be compliant with the ActivityPub Social Protocol.

Applications are not expected to handle every single ActivityStreams type and extension. The unhandled ones are passed to DefaultCallback.

func (*ActivityPub) DefaultCallback

func (ap *ActivityPub) DefaultCallback(c context.Context, activity pub.Activity) error

DefaultCallback is called for types that go-fed can deserialize but are not handled by the application's callbacks returned in the Callbacks method.

Applications are not expected to handle every single ActivityStreams type and extension, so the unhandled ones are passed to DefaultCallback.

func (*ActivityPub) Federate

func (ap *ActivityPub) Federate(c context.Context, user model.User, f model.Federater)

Federate performs the actions necessary to take a newly created object or action and deliver it to the users' followers. It handles its own errors and retries, if necessary.

NOTE: It doesn't actually retry right now.

func (*ActivityPub) FilterForwarding

func (ap *ActivityPub) FilterForwarding(c context.Context, potentialRecipients []*url.URL, a pub.Activity) (filteredRecipients []*url.URL, err error)

FilterForwarding allows the implementation to apply business logic such as blocks, spam filtering, and so on to a list of potential Collections and OrderedCollections of recipients when inbox forwarding has been triggered.

The activity is provided as a reference for more intelligent logic to be used, but the implementation must not modify it.

func (*ActivityPub) GetInbox

GetInbox returns the OrderedCollection inbox of the actor for this context. It is up to the implementation to provide the correct collection for the kind of authorization given in the request.

AuthenticateGetInbox will be called prior to this.

Always called, regardless whether the Federated Protocol or Social API is enabled.

func (*ActivityPub) GetOutbox

GetOutbox returns the OrderedCollection inbox of the actor for this context. It is up to the implementation to provide the correct collection for the kind of authorization given in the request.

AuthenticateGetOutbox will be called prior to this.

Always called, regardless whether the Federated Protocol or Social API is enabled.

func (*ActivityPub) MaxDeliveryRecursionDepth

func (ap *ActivityPub) MaxDeliveryRecursionDepth(c context.Context) int

MaxDeliveryRecursionDepth determines how deep to search within collections owned by peers when they are targeted to receive a delivery.

Zero or negative numbers indicate infinite recursion.

func (*ActivityPub) MaxInboxForwardingRecursionDepth

func (ap *ActivityPub) MaxInboxForwardingRecursionDepth(c context.Context) int

MaxInboxForwardingRecursionDepth determines how deep to search within an activity to determine if inbox forwarding needs to occur.

Zero or negative numbers indicate infinite recursion.

func (*ActivityPub) NewFederatingActor

func (ap *ActivityPub) NewFederatingActor() pub.FederatingActor

func (*ActivityPub) NewTransport

func (ap *ActivityPub) NewTransport(c context.Context, actorBoxIRI *url.URL, gofedAgent string) (t pub.Transport, err error)

NewTransport returns a new Transport on behalf of a specific actor.

The actorBoxIRI will be either the inbox or outbox of an actor who is attempting to do the dereferencing or delivery. Any authentication scheme applied on the request must be based on this actor. The request must contain some sort of credential of the user, such as a HTTP Signature.

The gofedAgent passed in should be used by the Transport implementation in the User-Agent, as well as the application-specific user agent string. The gofedAgent will indicate this library's use as well as the library's version number.

Any server-wide rate-limiting that needs to occur should happen in a Transport implementation. This factory function allows this to be created, so peer servers are not DOS'd.

Any retry logic should also be handled by the Transport implementation.

Note that the library will not maintain a long-lived pointer to the returned Transport so that any private credentials are able to be garbage collected.

func (*ActivityPub) PostInboxRequestBodyHook

func (ap *ActivityPub) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity pub.Activity) (context.Context, error)

----- FederatingProtocol ----- // Hook callback after parsing the request body for a federated request to the Actor's inbox.

Can be used to set contextual information based on the Activity received.

Only called if the Federated Protocol is enabled.

Warning: Neither authentication nor authorization has taken place at this time. Doing anything beyond setting contextual information is strongly discouraged.

If an error is returned, it is passed back to the caller of PostInbox. In this case, the DelegateActor implementation must not write a response to the ResponseWriter as is expected that the caller to PostInbox will do so when handling the error.

Directories

Path Synopsis
Package database implements the go-fed/activity/Database interface.
Package database implements the go-fed/activity/Database interface.

Jump to

Keyboard shortcuts

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