ap

package
v0.0.0-...-7cc0ef5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FedAdminProtocol

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

Inspired by go-fed classes like Database and SocialProtocol, this struct contains methods for running administrator task on the instance.

func (*FedAdminProtocol) AuthenticateAdmin

func (f *FedAdminProtocol) AuthenticateAdmin(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed bool, err error)

func (*FedAdminProtocol) CreateUser

func (f *FedAdminProtocol) CreateUser(c context.Context, username string) (*db.FedUser, error)

func (*FedAdminProtocol) Handle

type FedClock

type FedClock struct{}

Implements the go-fed/activity/pub/Clock interface (version 1.0)

func (*FedClock) Now

func (f *FedClock) Now() time.Time

Return current server time

type FedCommonBehavior

type FedCommonBehavior struct{}

Implements the go-fed/activity/pub/Datbase interface (version 1.0)

func (*FedCommonBehavior) AuthenticateGetInbox

func (f *FedCommonBehavior) AuthenticateGetInbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed 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 (*FedCommonBehavior) AuthenticateGetOutbox

func (f *FedCommonBehavior) AuthenticateGetOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed 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 (*FedCommonBehavior) 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 (*FedCommonBehavior) NewTransport

func (f *FedCommonBehavior) NewTransport(c context.Context, actorBoxIRI *url.URL, gofedAgent string) (pub.Transport, 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.

type FedDatabase

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

Implements the go-fed/activity/pub/Datbase interface (version 1.0)

func (*FedDatabase) ActorForInbox

func (f *FedDatabase) ActorForInbox(c context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error)

ActorForInbox fetches the actor's IRI for the given inbox IRI.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) ActorForOutbox

func (f *FedDatabase) ActorForOutbox(c context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error)

ActorForOutbox fetches the actor's IRI for the given outbox IRI.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Create

func (f *FedDatabase) Create(c context.Context, asType vocab.Type) error

Create adds a new entry to the database which must be able to be keyed by its id.

Note that Activity values received from federated peers may also be created in the database this way if the Federating Protocol is enabled. The client may freely decide to store only the id instead of the entire value.

The library makes this call only after acquiring a lock first.

Under certain conditions and network activities, Create may be called multiple times for the same ActivityStreams object.

func (*FedDatabase) Delete

func (f *FedDatabase) Delete(c context.Context, id *url.URL) error

Delete removes the entry with the given id.

Delete is only called for federated objects. Deletes from the Social Protocol instead call Update to create a Tombstone.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Exists

func (f *FedDatabase) Exists(c context.Context, id *url.URL) (exists bool, err error)

Exists returns true if the database has an entry for the specified id. It may not be owned by this application instance.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Followers

func (f *FedDatabase) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error)

Followers obtains the Followers Collection for an actor with the given id.

If modified, the library will then call Update.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Following

func (f *FedDatabase) Following(c context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error)

Following obtains the Following Collection for an actor with the given id.

If modified, the library will then call Update.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Get

func (f *FedDatabase) Get(c context.Context, addr *url.URL) (value vocab.Type, err error)

Get returns the database entry for the specified id.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) GetInbox

GetInbox returns the first ordered collection page of the outbox at the specified IRI, for prepending new items.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) GetOutbox

func (f *FedDatabase) GetOutbox(c context.Context, outboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error)

GetOutbox returns the first ordered collection page of the outbox at the specified IRI, for prepending new items.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) InboxContains

func (f *FedDatabase) InboxContains(c context.Context, inbox, id *url.URL) (contains bool, err error)

InboxContains returns true if the OrderedCollection at 'inbox' contains the specified 'id'.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Liked

func (f *FedDatabase) Liked(c context.Context, actorIRI *url.URL) (liked vocab.ActivityStreamsCollection, err error)

Liked obtains the Liked Collection for an actor with the given id.

If modified, the library will then call Update.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Lock

func (f *FedDatabase) Lock(c context.Context, id *url.URL) error

Lock takes a lock for the object at the specified id. If an error is returned, the lock must not have been taken.

The lock must be able to succeed for an id that does not exist in the database. This means acquiring the lock does not guarantee the entry exists in the database.

Locks are encouraged to be lightweight and in the Go layer, as some processes require tight loops acquiring and releasing locks.

Used to ensure race conditions in multiple requests do not occur.

func (*FedDatabase) NewId

func (f *FedDatabase) NewId(c context.Context, t vocab.Type) (id *url.URL, err error)

NewId creates a new IRI id for the provided activity or object. The implementation does not need to set the 'id' property and simply needs to determine the value.

The go-fed library will handle setting the 'id' property on the activity or object provided with the value returned.

func (*FedDatabase) OutboxForInbox

func (f *FedDatabase) OutboxForInbox(c context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error)

OutboxForInbox fetches the corresponding actor's outbox IRI for the actor's inbox IRI.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Owns

func (f *FedDatabase) Owns(c context.Context, id *url.URL) (owns bool, err error)

Owns returns true if the database has an entry for the IRI and it exists in the database.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) SetInbox

SetInbox saves the inbox value given from GetInbox, with new items prepended. Note that the new items must not be added as independent database entries. Separate calls to Create will do that.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) SetOutbox

SetOutbox saves the outbox value given from GetOutbox, with new items prepended. Note that the new items must not be added as independent database entries. Separate calls to Create will do that.

The library makes this call only after acquiring a lock first.

func (*FedDatabase) Unlock

func (f *FedDatabase) Unlock(c context.Context, id *url.URL) error

Unlock makes the lock for the object at the specified id available. If an error is returned, the lock must have still been freed.

Used to ensure race conditions in multiple requests do not occur.

func (*FedDatabase) Update

func (f *FedDatabase) Update(c context.Context, asType vocab.Type) error

Update sets an existing entry to the database based on the value's id.

Note that Activity values received from federated peers may also be updated in the database this way if the Federating Protocol is enabled. The client may freely decide to store only the id instead of the entire value.

The library makes this call only after acquiring a lock first.

type FedFederatingProtocol

type FedFederatingProtocol struct{}

Implements the go-fed/activity/pub/FederatingProtocol interface (version 1.0)

func (*FedFederatingProtocol) AuthenticatePostInbox

func (f *FedFederatingProtocol) AuthenticatePostInbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed 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 (*FedFederatingProtocol) Blocked

func (f *FedFederatingProtocol) 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 (*FedFederatingProtocol) Callbacks

func (f *FedFederatingProtocol) 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 (*FedFederatingProtocol) DefaultCallback

func (f *FedFederatingProtocol) 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 (*FedFederatingProtocol) FilterForwarding

func (f *FedFederatingProtocol) 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 (*FedFederatingProtocol) 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 (*FedFederatingProtocol) MaxDeliveryRecursionDepth

func (f *FedFederatingProtocol) 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 (*FedFederatingProtocol) MaxInboxForwardingRecursionDepth

func (f *FedFederatingProtocol) 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 (*FedFederatingProtocol) PostInboxRequestBodyHook

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

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.

type FedSocialProtocol

type FedSocialProtocol struct{}

Implements the go-fed/activity/pub/SocialProtocol interface (version 1.0)

func (*FedSocialProtocol) AuthenticatePostOutbox

func (f *FedSocialProtocol) AuthenticatePostOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed bool, err error)

AuthenticatePostOutbox delegates the authentication of a POST to an outbox.

Only called if the Social API is enabled.

If an error is returned, it is passed back to the caller of PostOutbox. 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 (*FedSocialProtocol) Callbacks

func (f *FedSocialProtocol) Callbacks(c context.Context) (wrapped pub.SocialWrappedCallbacks, other []interface{}, err error)

Callbacks returns the application logic that handles ActivityStreams received from C2S clients.

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 SocialWrappedCallbacks 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 (*FedSocialProtocol) DefaultCallback

func (f *FedSocialProtocol) 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 (*FedSocialProtocol) PostOutboxRequestBodyHook

func (f *FedSocialProtocol) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error)

Hook callback after parsing the request body for a client request to the Actor's outbox.

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

Only called if the Social API 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 PostOutbox. In this case, the DelegateActor implementation must not write a response to the ResponseWriter as is expected that the caller to PostOutbox will do so when handling the error.

type FedTransport

type FedTransport struct {
	Context   context.Context
	Target    *url.URL // TODO: use for authentication
	UserAgent string
}

Implements the go-fed/activity/pub/FedTransport interface (version 1.0)

func (*FedTransport) BatchDeliver

func (f *FedTransport) BatchDeliver(c context.Context, b []byte, recipients []*url.URL) error

BatchDeliver sends an ActivityStreams object to multiple recipients.

func (*FedTransport) Deliver

func (f *FedTransport) Deliver(c context.Context, b []byte, to *url.URL) (err error)

Deliver sends an ActivityStreams object.

func (*FedTransport) Dereference

func (f *FedTransport) Dereference(c context.Context, iri *url.URL) ([]byte, error)

Dereference fetches the ActivityStreams object located at this IRI with a GET request.

Jump to

Keyboard shortcuts

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