Documentation ¶
Index ¶
- Variables
- type APDB
- func (p *APDB) ActorForInbox(c context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error)
- func (p *APDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error)
- func (p *APDB) Create(ctx context.Context, asType vocab.Type) error
- func (p *APDB) Delete(ctx context.Context, id *url.URL) error
- func (p *APDB) Exists(ctx context.Context, id *url.URL) (bool, error)
- func (p *APDB) Followers(ctx context.Context, actorURL *url.URL) (followers vocab.ActivityStreamsCollection, err error)
- func (p *APDB) Following(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error)
- func (p *APDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error)
- func (p *APDB) GetInbox(c context.Context, inboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error)
- func (p *APDB) GetOutbox(ctx context.Context, outboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error)
- func (p *APDB) InboxContains(c context.Context, inbox *url.URL, id *url.URL) (contains bool, err error)
- func (p *APDB) Liked(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error)
- func (p *APDB) Lock(c context.Context, id *url.URL) error
- func (p *APDB) NewID(c context.Context, t vocab.Type) (id *url.URL, err error)
- func (p *APDB) OutboxForInbox(c context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error)
- func (p *APDB) Owns(c context.Context, id *url.URL) (owns bool, err error)
- func (p *APDB) SetInbox(ctx context.Context, inbox vocab.ActivityStreamsOrderedCollectionPage) error
- func (p *APDB) SetOutbox(ctx context.Context, outbox vocab.ActivityStreamsOrderedCollectionPage) error
- func (p *APDB) Unlock(c context.Context, id *url.URL) error
- func (p *APDB) Update(ctx context.Context, asType vocab.Type) error
- type Service
- func (*Service) AuthenticateGetInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed bool, err error)
- func (*Service) AuthenticateGetOutbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authed bool, err error)
- func (s *Service) AuthenticatePostInbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authenticated bool, err error)
- func (s *Service) Blocked(c context.Context, actorIRIs []*url.URL) (blocked bool, err error)
- func (s *Service) DefaultCallback(c context.Context, activity pub.Activity) error
- func (s *Service) FederatingCallbacks(c context.Context) (wrapped pub.FederatingWrappedCallbacks, other []interface{}, err error)
- func (s *Service) FilterForwarding(c context.Context, potentialRecipients []*url.URL, a pub.Activity) (filteredRecipients []*url.URL, err error)
- func (s *Service) GetInbox(c context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error)
- func (s *Service) GetOutbox(c context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error)
- func (s *Service) MaxDeliveryRecursionDepth(c context.Context) int
- func (s *Service) MaxInboxForwardingRecursionDepth(c context.Context) int
- func (*Service) NewTransport(ctx context.Context, boxIRI *url.URL, goFedAgent string) (t pub.Transport, err error)
- func (*Service) Now() time.Time
- func (s *Service) PostInbox(c context.Context, w http.ResponseWriter, r *http.Request) (bool, error)
- func (s *Service) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity pub.Activity) (context.Context, error)
- func (s *Service) PostOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (bool, error)
- func (s *Service) Send(c context.Context, outbox *url.URL, t vocab.Type) (pub.Activity, error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type APDB ¶
type APDB struct { Host string // fqdn of the server DB *ent.Client // contains filtered or unexported fields }
APDB implements github.com/go-fed/activity/pub.Database
func (*APDB) ActorForInbox ¶
ActorForInbox fetches the actor's IRI for the given outbox IRI.
The library makes this call only after acquiring a lock first.
func (*APDB) ActorForOutbox ¶
ActorForOutbox fetches the actor's IRI for the given outbox IRI.
The library makes this call only after acquiring a lock first.
func (*APDB) Create ¶
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 (*APDB) Delete ¶
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 (*APDB) Exists ¶
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 (*APDB) Followers ¶
func (p *APDB) Followers(ctx context.Context, actorURL *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 (*APDB) Following ¶
func (p *APDB) Following(c context.Context, actorIRI *url.URL) (followers 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 (*APDB) Get ¶
Get returns the database entry for the specified id.
The library makes this call only after acquiring a lock first.
func (*APDB) GetInbox ¶
func (p *APDB) GetInbox(c context.Context, inboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error)
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 (*APDB) GetOutbox ¶
func (p *APDB) GetOutbox(ctx 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 (*APDB) InboxContains ¶
func (p *APDB) InboxContains(c context.Context, inbox *url.URL, 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 (*APDB) Liked ¶
func (p *APDB) Liked(c context.Context, actorIRI *url.URL) (followers 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 (*APDB) Lock ¶
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 (*APDB) NewID ¶
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 (*APDB) OutboxForInbox ¶
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 (*APDB) Owns ¶
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 (*APDB) SetInbox ¶
func (p *APDB) SetInbox(ctx context.Context, inbox vocab.ActivityStreamsOrderedCollectionPage) error
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 (*APDB) SetOutbox ¶
func (p *APDB) SetOutbox(ctx context.Context, outbox vocab.ActivityStreamsOrderedCollectionPage) error
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 (*APDB) Unlock ¶
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 (*APDB) Update ¶
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 Service ¶
type Service struct{}
func (*Service) AuthenticateGetInbox ¶
func (*Service) AuthenticateGetOutbox ¶
func (*Service) AuthenticatePostInbox ¶
func (s *Service) 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 (*Service) Blocked ¶
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 (*Service) DefaultCallback ¶
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 (*Service) FederatingCallbacks ¶
func (s *Service) FederatingCallbacks(c context.Context) (wrapped pub.FederatingWrappedCallbacks, other []interface{}, err error)
FederatingCallbacks 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 (*Service) FilterForwarding ¶
func (s *Service) 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 (*Service) GetInbox ¶
func (s *Service) GetInbox(c context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error)
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 (*Service) GetOutbox ¶
func (s *Service) GetOutbox(c context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error)
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 (*Service) MaxDeliveryRecursionDepth ¶
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 (*Service) MaxInboxForwardingRecursionDepth ¶
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 (*Service) NewTransport ¶
func (*Service) PostInbox ¶
func (s *Service) PostInbox(c context.Context, w http.ResponseWriter, r *http.Request) (bool, error)
PostInbox returns true if the request was handled as an ActivityPub POST to an actor's inbox. If false, the request was not an ActivityPub request and may still be handled by the caller in another way, such as serving a web page.
If the error is nil, then the ResponseWriter's headers and response has already been written. If a non-nil error is returned, then no response has been written.
If the Actor was constructed with the Federated Protocol enabled, side effects will occur.
If the Federated Protocol is not enabled, writes the http.StatusMethodNotAllowed status code in the response. No side effects occur.
func (*Service) PostInboxRequestBodyHook ¶
func (s *Service) 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.
func (*Service) PostOutbox ¶
func (s *Service) PostOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (bool, error)
PostOutbox returns true if the request was handled as an ActivityPub POST to an actor's outbox. If false, the request was not an ActivityPub request and may still be handled by the caller in another way, such as serving a web page.
If the error is nil, then the ResponseWriter's headers and response has already been written. If a non-nil error is returned, then no response has been written.
If the Actor was constructed with the Social Protocol enabled, side effects will occur.
If the Social Protocol is not enabled, writes the http.StatusMethodNotAllowed status code in the response. No side effects occur.
If the Social and Federated Protocol are both enabled, it will handle the side effects of receiving an ActivityStream Activity, and then federate the Activity to peers.
func (*Service) Send ¶
Send a federated activity.
The provided url must be the outbox of the sender. All processing of the activity occurs similarly to the C2S flow:
- If t is not an Activity, it is wrapped in a Create activity.
- A new ID is generated for the activity.
- The activity is added to the specified outbox.
- The activity is prepared and delivered to recipients.
Note that this function will only behave as expected if the implementation has been constructed to support federation. This method will guaranteed work for non-custom Actors. For custom actors, care should be used to not call this method if only C2S is supported.